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

Commit 3523eab7 authored by Kenneth Ford's avatar Kenneth Ford Committed by Android (Google) Code Review
Browse files

Merge changes from topic "device_state_manager"

* changes:
  Rename cancelRequest API to cancelStateRequest and remove the request parameter
  Updates OverrideRequestController to allow for one override request at max
parents e1d6e207 f18a8b85
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1104,7 +1104,7 @@ package android.hardware.camera2 {
package android.hardware.devicestate {

  public final class DeviceStateManager {
    method @RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true) public void cancelRequest(@NonNull android.hardware.devicestate.DeviceStateRequest);
    method @RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true) public void cancelStateRequest();
    method @NonNull public int[] getSupportedStates();
    method public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.devicestate.DeviceStateManager.DeviceStateCallback);
    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);
+6 −7
Original line number Diff line number Diff line
@@ -79,9 +79,9 @@ public final class DeviceStateManager {
     * <ul>
     *     <li>The system deems the request can no longer be honored, for example if the requested
     *     state becomes unsupported.
     *     <li>A call to {@link #cancelRequest(DeviceStateRequest)}.
     *     <li>A call to {@link #cancelStateRequest}.
     *     <li>Another processes submits a request succeeding this request in which case the request
     *     will be suspended until the interrupting request is canceled.
     *     will be canceled.
     * </ul>
     * However, this behavior can be changed by setting flags on the {@link DeviceStateRequest}.
     *
@@ -100,19 +100,18 @@ public final class DeviceStateManager {
    }

    /**
     * Cancels a {@link DeviceStateRequest request} previously submitted with a call to
     * Cancels the active {@link DeviceStateRequest} previously submitted with a call to
     * {@link #requestState(DeviceStateRequest, Executor, DeviceStateRequest.Callback)}.
     * <p>
     * This method is noop if the {@code request} has not been submitted with a call to
     * {@link #requestState(DeviceStateRequest, Executor, DeviceStateRequest.Callback)}.
     * This method is noop if there is no request currently active.
     *
     * @throws SecurityException if the caller is neither the current top-focused activity nor if
     * the {@link android.Manifest.permission#CONTROL_DEVICE_STATE} permission is held.
     */
    @RequiresPermission(value = android.Manifest.permission.CONTROL_DEVICE_STATE,
            conditional = true)
    public void cancelRequest(@NonNull DeviceStateRequest request) {
        mGlobal.cancelRequest(request);
    public void cancelStateRequest() {
        mGlobal.cancelStateRequest();
    }

    /**
+3 −36
Original line number Diff line number Diff line
@@ -151,20 +151,14 @@ public final class DeviceStateManagerGlobal {
     * Cancels a {@link DeviceStateRequest request} previously submitted with a call to
     * {@link #requestState(DeviceStateRequest, Executor, DeviceStateRequest.Callback)}.
     *
     * @see DeviceStateManager#cancelRequest(DeviceStateRequest)
     * @see DeviceStateManager#cancelStateRequest
     */
    public void cancelRequest(@NonNull DeviceStateRequest request) {
    public void cancelStateRequest() {
        synchronized (mLock) {
            registerCallbackIfNeededLocked();

            final IBinder token = findRequestTokenLocked(request);
            if (token == null) {
                // This request has not been submitted.
                return;
            }

            try {
                mDeviceStateManager.cancelRequest(token);
                mDeviceStateManager.cancelStateRequest();
            } catch (RemoteException ex) {
                throw ex.rethrowFromSystemServer();
            }
@@ -297,20 +291,6 @@ public final class DeviceStateManagerGlobal {
        }
    }

    /**
     * Handles a call from the server that a request for the supplied {@code token} has become
     * suspended.
     */
    private void handleRequestSuspended(IBinder token) {
        DeviceStateRequestWrapper request;
        synchronized (mLock) {
            request = mRequests.get(token);
        }
        if (request != null) {
            request.notifyRequestSuspended();
        }
    }

    /**
     * Handles a call from the server that a request for the supplied {@code token} has become
     * canceled.
@@ -336,11 +316,6 @@ public final class DeviceStateManagerGlobal {
            handleRequestActive(token);
        }

        @Override
        public void onRequestSuspended(IBinder token) {
            handleRequestSuspended(token);
        }

        @Override
        public void onRequestCanceled(IBinder token) {
            handleRequestCanceled(token);
@@ -395,14 +370,6 @@ public final class DeviceStateManagerGlobal {
            mExecutor.execute(() -> mCallback.onRequestActivated(mRequest));
        }

        void notifyRequestSuspended() {
            if (mCallback == null) {
                return;
            }

            mExecutor.execute(() -> mCallback.onRequestSuspended(mRequest));
        }

        void notifyRequestCanceled() {
            if (mCallback == null) {
                return;
+1 −2
Original line number Diff line number Diff line
@@ -32,8 +32,7 @@ import java.util.concurrent.Executor;
 * DeviceStateRequest.Callback)}.
 * <p>
 * By default, the request is kept active until a call to
 * {@link DeviceStateManager#cancelRequest(DeviceStateRequest)} or until one of the following
 * occurs:
 * {@link DeviceStateManager#cancelStateRequest} or until one of the following occurs:
 * <ul>
 *     <li>Another processes submits a request succeeding this request in which case the request
 *     will be suspended until the interrupting request is canceled.
+7 −9
Original line number Diff line number Diff line
@@ -41,8 +41,9 @@ interface IDeviceStateManager {
     * previously registered with {@link #registerCallback(IDeviceStateManagerCallback)} before a
     * call to this method.
     *
     * @param token the request token previously registered with
     *        {@link #requestState(IBinder, int, int)}
     * @param token the request token provided
     * @param state the state of device the request is asking for
     * @param flags any flags that correspond to the request
     *
     * @throws IllegalStateException if a callback has not yet been registered for the calling
     *         process.
@@ -52,14 +53,11 @@ interface IDeviceStateManager {
    void requestState(IBinder token, int state, int flags);

    /**
     * Cancels a request previously submitted with a call to
     * Cancels the active request previously submitted with a call to
     * {@link #requestState(IBinder, int, int)}.
     *
     * @param token the request token previously registered with
     *        {@link #requestState(IBinder, int, int)}
     *
     * @throws IllegalStateException if the supplied {@code token} has not been previously
     *         requested.
     * @throws IllegalStateException if a callback has not yet been registered for the calling
     *         process.
     */
    void cancelRequest(IBinder token);
    void cancelStateRequest();
}
Loading