Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb84df6c authored by Kenneth Ford's avatar Kenneth Ford
Browse files

Removes deprecated DeviceStateManager API's

Bug: 327182261
Bug: 293636629
Test: DeviceStateManagerGlobalTest
Test: DeviceStateManagerTests
Change-Id: Iadeb933fb5e5be1ef255fb2ca9fcc69c12147d7d
parent a114eff4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5006,7 +5006,7 @@ package android.hardware.devicestate {
  }
  public static interface DeviceStateManager.DeviceStateCallback {
    method public default void onDeviceStateChanged(@NonNull android.hardware.devicestate.DeviceState);
    method public void onDeviceStateChanged(@NonNull android.hardware.devicestate.DeviceState);
    method public default void onSupportedStatesChanged(@NonNull java.util.List<android.hardware.devicestate.DeviceState>);
  }
+19 −7
Original line number Diff line number Diff line
@@ -1625,25 +1625,37 @@ package android.hardware.camera2.params {
package android.hardware.devicestate {

  @FlaggedApi("android.hardware.devicestate.feature.flags.device_state_property_api") public final class DeviceState {
    ctor public DeviceState(@NonNull android.hardware.devicestate.DeviceState.Configuration);
    field public static final int PROPERTY_POLICY_AVAILABLE_FOR_APP_REQUEST = 8; // 0x8
  }

  public static final class DeviceState.Configuration implements android.os.Parcelable {
    method public int describeContents();
    method public int getIdentifier();
    method @NonNull public String getName();
    method @NonNull public java.util.Set<java.lang.Integer> getPhysicalProperties();
    method @NonNull public java.util.Set<java.lang.Integer> getSystemProperties();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.devicestate.DeviceState.Configuration> CREATOR;
  }

  public static final class DeviceState.Configuration.Builder {
    ctor public DeviceState.Configuration.Builder(int, @NonNull String);
    method @NonNull public android.hardware.devicestate.DeviceState.Configuration build();
    method @NonNull public android.hardware.devicestate.DeviceState.Configuration.Builder setPhysicalProperties(@NonNull java.util.Set<java.lang.Integer>);
    method @NonNull public android.hardware.devicestate.DeviceState.Configuration.Builder setSystemProperties(@NonNull java.util.Set<java.lang.Integer>);
  }

  @FlaggedApi("android.hardware.devicestate.feature.flags.device_state_property_api") public final class DeviceStateManager {
    method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE) public void cancelBaseStateOverride();
    method @RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true) public void cancelStateRequest();
    method @Deprecated @NonNull public int[] getSupportedStates();
    method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE) public void requestBaseStateOverride(@NonNull android.hardware.devicestate.DeviceStateRequest, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.devicestate.DeviceStateRequest.Callback);
    method @RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true) public void requestState(@NonNull android.hardware.devicestate.DeviceStateRequest, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.devicestate.DeviceStateRequest.Callback);
    field public static final int INVALID_DEVICE_STATE_IDENTIFIER = -1; // 0xffffffff
    field public static final int MAXIMUM_DEVICE_STATE_IDENTIFIER = 10000; // 0x2710
    field public static final int MINIMUM_DEVICE_STATE_IDENTIFIER = 0; // 0x0
  }

  public static interface DeviceStateManager.DeviceStateCallback {
    method @Deprecated public default void onBaseStateChanged(int);
    method @Deprecated public void onStateChanged(int);
    method @Deprecated public default void onSupportedStatesChanged(@NonNull int[]);
  }

  public final class DeviceStateRequest {
    method public int getFlags();
    method public int getState();
+13 −129
Original line number Diff line number Diff line
@@ -51,78 +51,6 @@ import java.util.Set;
@SystemApi
@FlaggedApi(android.hardware.devicestate.feature.flags.Flags.FLAG_DEVICE_STATE_PROPERTY_API)
public final class DeviceState {
    /**
     * Flag that indicates override requests should be cancelled when this device state becomes the
     * base device state.
     * @hide
     * @deprecated use {@link #PROPERTY_POLICY_CANCEL_OVERRIDE_REQUESTS}
     */
    @Deprecated
    public static final int FLAG_CANCEL_OVERRIDE_REQUESTS = 1 << 0;

    /**
     * Flag that indicates this device state is inaccessible for applications to be placed in. This
     * could be a device-state where the {@link Display#DEFAULT_DISPLAY} is not enabled.
     * @hide
     * @deprecated use {@link #PROPERTY_APP_INACCESSIBLE}
     */
    @Deprecated
    public static final int FLAG_APP_INACCESSIBLE = 1 << 1;

    /**
     * Some device states can be both entered through a physical configuration as well as emulation
     * through {@link DeviceStateManager#requestState}, while some states can only be entered
     * through emulation and have no physical configuration to match.
     *
     * This flag indicates that the corresponding state can only be entered through emulation.
     * @hide
     * @deprecated use {@link #PROPERTY_EMULATED_ONLY}
     */
    @Deprecated
    public static final int FLAG_EMULATED_ONLY = 1 << 2;

    /**
     * This flag indicates that the corresponding state should be automatically canceled when the
     * requesting app is no longer on top. The app is considered not on top when (1) the top
     * activity in the system is from a different app, (2) the device is in sleep mode, or
     * (3) the keyguard shows up.
     * @hide
     * @deprecated use {@link #PROPERTY_POLICY_CANCEL_WHEN_REQUESTER_NOT_ON_TOP}
     */
    @Deprecated
    public static final int FLAG_CANCEL_WHEN_REQUESTER_NOT_ON_TOP = 1 << 3;

    /**
     * This flag indicates that the corresponding state should be disabled when the device is
     * overheating and reaching the critical status.
     * @hide
     * @deprecated use {@link #PROPERTY_POLICY_UNSUPPORTED_WHEN_THERMAL_STATUS_CRITICAL}
     */
    @Deprecated
    public static final int FLAG_UNSUPPORTED_WHEN_THERMAL_STATUS_CRITICAL = 1 << 4;

    /**
     * This flag indicates that the corresponding state should be disabled when power save mode
     * is enabled.
     * @hide
     * @deprecated use {@link #PROPERTY_POLICY_UNSUPPORTED_WHEN_POWER_SAVE_MODE}
     */
    @Deprecated
    public static final int FLAG_UNSUPPORTED_WHEN_POWER_SAVE_MODE = 1 << 5;

    /** @hide */
    @IntDef(prefix = {"FLAG_"}, flag = true, value = {
            FLAG_CANCEL_OVERRIDE_REQUESTS,
            FLAG_APP_INACCESSIBLE,
            FLAG_EMULATED_ONLY,
            FLAG_CANCEL_WHEN_REQUESTER_NOT_ON_TOP,
            FLAG_UNSUPPORTED_WHEN_THERMAL_STATUS_CRITICAL,
            FLAG_UNSUPPORTED_WHEN_POWER_SAVE_MODE
    })
    @Deprecated
    @Retention(RetentionPolicy.SOURCE)
    public @interface DeviceStateFlags {}

    /**
     * Property that indicates that a fold-in style foldable device is currently in a fully closed
     * configuration.
@@ -302,42 +230,11 @@ public final class DeviceState {
    @NonNull
    private final DeviceState.Configuration mDeviceStateConfiguration;

    @DeviceStateFlags
    private final int mFlags;

    /** @hide */
    @TestApi
    public DeviceState(@NonNull DeviceState.Configuration deviceStateConfiguration) {
        Objects.requireNonNull(deviceStateConfiguration, "Device StateConfiguration is null");
        mDeviceStateConfiguration = deviceStateConfiguration;
        mFlags = 0;
    }

    /** @hide */
    public DeviceState(
            @IntRange(from = MINIMUM_DEVICE_STATE_IDENTIFIER, to =
                    MAXIMUM_DEVICE_STATE_IDENTIFIER) int identifier,
            @NonNull String name,
            @NonNull Set<@DeviceStateProperties Integer> properties) {
        mDeviceStateConfiguration = new DeviceState.Configuration(identifier, name, properties,
                Collections.emptySet());
        mFlags = 0;
    }

    /**
     * @deprecated Deprecated in favor of {@link #DeviceState(int, String, Set)}
     * @hide
     */
    // TODO(b/325124054): Make non-default and remove deprecated callback methods.
    @Deprecated
    public DeviceState(
            @IntRange(from = MINIMUM_DEVICE_STATE_IDENTIFIER, to =
                    MAXIMUM_DEVICE_STATE_IDENTIFIER) int identifier,
            @NonNull String name,
            @DeviceStateFlags int flags) {

        mDeviceStateConfiguration = new DeviceState.Configuration(identifier, name,
                Collections.emptySet(), Collections.emptySet());
        mFlags = flags;
    }

    /** Returns the unique identifier for the device state. */
@@ -352,17 +249,6 @@ public final class DeviceState {
        return mDeviceStateConfiguration.getName();
    }

    /**
     * @hide
     * @deprecated in favor of {@link #hasProperty(int)} method
     */
    // TODO(b/325124054): Make non-default and remove deprecated callback methods.
    @Deprecated
    @DeviceStateFlags
    public int getFlags() {
        return mFlags;
    }

    @Override
    public String toString() {
        return "DeviceState{" + "identifier=" + mDeviceStateConfiguration.getIdentifier()
@@ -388,16 +274,6 @@ public final class DeviceState {
        return Objects.hash(mDeviceStateConfiguration);
    }

    /** Checks if a specific flag is set
     * @hide
     * @deprecated in favor of {@link #hasProperty(int)}
     */
    // TODO(b/325124054): Make non-default and remove deprecated callback methods.
    @Deprecated
    public boolean hasFlag(int flagToCheckFor) {
        return (mFlags & flagToCheckFor) == flagToCheckFor;
    }

    /**
     * Checks if a specific property is set on this state
     */
@@ -438,6 +314,7 @@ public final class DeviceState {
     * @see DeviceStateManager
     * @hide
     */
    @TestApi
    public static final class Configuration implements Parcelable {
        /** Unique identifier for the device state. */
        @IntRange(from = MINIMUM_DEVICE_STATE_IDENTIFIER, to = MAXIMUM_DEVICE_STATE_IDENTIFIER)
@@ -563,29 +440,35 @@ public final class DeviceState {
        };

        /** @hide */
        public static class Builder {
        @TestApi
        public static final class Builder {
            private final int mIdentifier;
            @NonNull
            private final String mName;
            @NonNull
            private Set<@SystemDeviceStateProperties Integer> mSystemProperties =
                    Collections.emptySet();
            @NonNull
            private Set<@PhysicalDeviceStateProperties Integer> mPhysicalProperties =
                    Collections.emptySet();

            public Builder(int identifier, String name) {
            public Builder(int identifier, @NonNull String name) {
                mIdentifier = identifier;
                mName = name;
            }

            /** Sets the system properties for this {@link DeviceState.Configuration.Builder} */
            @NonNull
            public Builder setSystemProperties(
                    Set<@SystemDeviceStateProperties Integer> systemProperties) {
                    @NonNull Set<@SystemDeviceStateProperties Integer> systemProperties) {
                mSystemProperties = systemProperties;
                return this;
            }

            /** Sets the system properties for this {@link DeviceState.Configuration.Builder} */
            @NonNull
            public Builder setPhysicalProperties(
                    Set<@PhysicalDeviceStateProperties Integer> physicalProperties) {
                    @NonNull Set<@PhysicalDeviceStateProperties Integer> physicalProperties) {
                mPhysicalProperties = physicalProperties;
                return this;
            }
@@ -594,6 +477,7 @@ public final class DeviceState {
             * Returns a new {@link DeviceState.Configuration} whose values match the values set on
             * the builder.
             */
            @NonNull
            public DeviceState.Configuration build() {
                return new DeviceState.Configuration(mIdentifier, mName, mSystemProperties,
                        mPhysicalProperties);
+2 −72
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public final class DeviceStateManager {
     *
     * @hide
     */
    @TestApi
    public static final int INVALID_DEVICE_STATE_IDENTIFIER = -1;

    /**
@@ -93,20 +94,6 @@ public final class DeviceStateManager {
        mGlobal = global;
    }

    /**
     * Returns the list of device states that are supported and can be requested with
     * {@link #requestState(DeviceStateRequest, Executor, DeviceStateRequest.Callback)}.
     * @deprecated use {@link #getSupportedDeviceStates()}
     * @hide
     */
    // TODO(b/325124054): Make non-default and remove deprecated callback methods.
    @TestApi
    @Deprecated
    @NonNull
    public int[] getSupportedStates() {
        return mGlobal.getSupportedStates();
    }

    /**
     * Returns the list of device states that are supported and can be requested with
     * {@link #requestState(DeviceStateRequest, Executor, DeviceStateRequest.Callback)}.
@@ -233,23 +220,6 @@ public final class DeviceStateManager {

    /** Callback to receive notifications about changes in device state. */
    public interface DeviceStateCallback {
        /**
         * Called in response to a change in the states supported by the device.
         * <p>
         * Guaranteed to be called once on registration of the callback with the initial value and
         * then on every subsequent change in the supported states.
         *
         * @param supportedStates the new supported states.
         *
         * @see DeviceStateManager#getSupportedStates()
         * @deprecated use {@link #onSupportedStatesChanged(List)}
         * @hide
         */
        // TODO(b/325124054): Make non-default and remove deprecated callback methods.
        @TestApi
        @Deprecated
        default void onSupportedStatesChanged(@NonNull int[] supportedStates) {}

        /**
         * Called in response to a change in the states supported by the device.
         * <p>
@@ -266,42 +236,6 @@ public final class DeviceStateManager {
         */
        default void onSupportedStatesChanged(@NonNull List<DeviceState> supportedStates) {}

        /**
         * Called in response to a change in the base device state.
         * <p>
         * The base state is the state of the device without considering any requests made through
         * calls to {@link #requestState(DeviceStateRequest, Executor, DeviceStateRequest.Callback)}
         * from any client process. The base state is guaranteed to match the state provided with a
         * call to {@link #onStateChanged(int)} when there are no active requests from any process.
         * <p>
         * Guaranteed to be called once on registration of the callback with the initial value and
         * then on every subsequent change in the non-override state.
         *
         * @param state the new base device state.
         * @deprecated use {@link #onDeviceStateChanged(DeviceState)} and query for physical
         * properties that are relevant to your needs.
         * @hide
         */
        // TODO(b/325124054): Make non-default and remove deprecated callback methods.
        @TestApi
        @Deprecated
        default void onBaseStateChanged(int state) {}

        /**
         * Called in response to device state changes.
         * <p>
         * Guaranteed to be called once on registration of the callback with the initial value and
         * then on every subsequent change in device state.
         *
         * @param state the new device state.
         * @deprecated use {@link #onDeviceStateChanged(DeviceState)}
         * @hide
         */
        // TODO(b/325124054): Make non-default and remove deprecated callback methods.
        @TestApi
        @Deprecated
        void onStateChanged(int state);

        /**
         * Called in response to device state changes.
         * <p>
@@ -310,8 +244,7 @@ public final class DeviceStateManager {
         *
         * @param state the new device state.
         */
        // TODO(b/325124054): Make non-default and remove deprecated callback methods.
        default void onDeviceStateChanged(@NonNull DeviceState state) {}
        void onDeviceStateChanged(@NonNull DeviceState state);
    }

    /**
@@ -339,9 +272,6 @@ public final class DeviceStateManager {
            mFeatureFlags = new android.hardware.devicestate.feature.flags.FeatureFlagsImpl();
        }

        @Override
        public final void onStateChanged(int state) {}

        @Override
        public final void onDeviceStateChanged(@NonNull DeviceState deviceState) {
            final boolean folded;
+0 −66
Original line number Diff line number Diff line
@@ -89,33 +89,6 @@ public final class DeviceStateManagerGlobal {
        registerCallbackIfNeededLocked();
    }

    /**
     * Returns the set of supported device states.
     *
     * @see DeviceStateManager#getSupportedStates()
     */
    // TODO(b/325124054): Remove unused methods when clients are migrated.
    public int[] getSupportedStates() {
        synchronized (mLock) {
            final DeviceStateInfo currentInfo;
            if (mLastReceivedInfo != null) {
                // If we have mLastReceivedInfo a callback is registered for this instance and it
                // is receiving the most recent info from the server. Use that info here.
                currentInfo = mLastReceivedInfo;
            } else {
                // If mLastReceivedInfo is null there is no registered callback so we manually
                // fetch the current info.
                try {
                    currentInfo = mDeviceStateManager.getDeviceStateInfo();
                } catch (RemoteException ex) {
                    throw ex.rethrowFromSystemServer();
                }
            }

            return getSupportedStateIdentifiersLocked(currentInfo.supportedStates);
        }
    }

    /**
     * Returns {@link List} of supported {@link DeviceState}s.
     *
@@ -264,14 +237,8 @@ public final class DeviceStateManagerGlobal {
            mCallbacks.add(wrapper);

            if (mLastReceivedInfo != null) {
                // Copy the array to prevent the callback from modifying the internal state.
                final int[] supportedStates = getSupportedStateIdentifiersLocked(
                        mLastReceivedInfo.supportedStates);
                wrapper.notifySupportedStatesChanged(supportedStates);
                wrapper.notifySupportedDeviceStatesChanged(
                        List.copyOf(mLastReceivedInfo.supportedStates));
                wrapper.notifyBaseStateChanged(mLastReceivedInfo.baseState.getIdentifier());
                wrapper.notifyStateChanged(mLastReceivedInfo.currentState.getIdentifier());
                wrapper.notifyDeviceStateChanged(mLastReceivedInfo.currentState);
            }
        }
@@ -330,15 +297,6 @@ public final class DeviceStateManagerGlobal {
        return -1;
    }

    @GuardedBy("mLock")
    private int[] getSupportedStateIdentifiersLocked(List<DeviceState> states) {
        int[] identifiers = new int[states.size()];
        for (int i = 0; i < states.size(); i++) {
            identifiers[i] = states.get(i).getIdentifier();
        }
        return identifiers;
    }

    @Nullable
    private IBinder findRequestTokenLocked(@NonNull DeviceStateRequest request) {
        for (int i = 0; i < mRequests.size(); i++) {
@@ -353,12 +311,10 @@ public final class DeviceStateManagerGlobal {
    private void handleDeviceStateInfoChanged(@NonNull DeviceStateInfo info) {
        ArrayList<DeviceStateCallbackWrapper> callbacks;
        DeviceStateInfo oldInfo;
        int[] supportedStateIdentifiers;
        synchronized (mLock) {
            oldInfo = mLastReceivedInfo;
            mLastReceivedInfo = info;
            callbacks = new ArrayList<>(mCallbacks);
            supportedStateIdentifiers = getSupportedStateIdentifiersLocked(info.supportedStates);
        }

        final int diff = oldInfo == null ? ~0 : info.diff(oldInfo);
@@ -366,18 +322,11 @@ public final class DeviceStateManagerGlobal {
            for (int i = 0; i < callbacks.size(); i++) {
                callbacks.get(i).notifySupportedDeviceStatesChanged(
                        List.copyOf(info.supportedStates));
                callbacks.get(i).notifySupportedStatesChanged(supportedStateIdentifiers);
            }
        }
        if ((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0) {
            for (int i = 0; i < callbacks.size(); i++) {
                callbacks.get(i).notifyBaseStateChanged(info.baseState.getIdentifier());
            }
        }
        if ((diff & DeviceStateInfo.CHANGED_CURRENT_STATE) > 0) {
            for (int i = 0; i < callbacks.size(); i++) {
                callbacks.get(i).notifyDeviceStateChanged(info.currentState);
                callbacks.get(i).notifyStateChanged(info.currentState.getIdentifier());
            }
        }
    }
@@ -439,26 +388,11 @@ public final class DeviceStateManagerGlobal {
            mExecutor = executor;
        }

        void notifySupportedStatesChanged(int[] newSupportedStates) {
            mExecutor.execute(() ->
                    mDeviceStateCallback.onSupportedStatesChanged(newSupportedStates));
        }

        void notifySupportedDeviceStatesChanged(List<DeviceState> newSupportedDeviceStates) {
            mExecutor.execute(() ->
                    mDeviceStateCallback.onSupportedStatesChanged(newSupportedDeviceStates));
        }

        void notifyBaseStateChanged(int newBaseState) {
            execute("notifyBaseStateChanged",
                    () -> mDeviceStateCallback.onBaseStateChanged(newBaseState));
        }

        void notifyStateChanged(int newDeviceState) {
            execute("notifyStateChanged",
                    () -> mDeviceStateCallback.onStateChanged(newDeviceState));
        }

        void notifyDeviceStateChanged(DeviceState newDeviceState) {
            execute("notifyDeviceStateChanged",
                    () -> mDeviceStateCallback.onDeviceStateChanged(newDeviceState));
Loading