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

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

Rename cancelRequest API to cancelStateRequest and remove the

request parameter

With the change to only having one override request at a time,
we can simplify the cancelRequest API in DeviceStateManager
to not require a request object and have the current
override request canceled. This API is still gated
around having the CONTROL_DEVICE_STATE permission or being the
top level app.

Bug: 215400374
Test: DeviceStateManagerGlobalTest, DeviceStateManagerServiceTest &&
 OverrideRequestControllerTest
Change-Id: I565b608372c21384d401db502b16553ed85b86ee
parent cda48cdc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1092,7 +1092,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 −9
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();
            }
+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