/* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.devicestate; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.TestApi; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.concurrent.Executor; /** * A request to alter the state of the device managed by {@link DeviceStateManager}. *
* Once constructed, a {@link DeviceStateRequest request} can be submitted with a call to * {@link DeviceStateManager#requestState(DeviceStateRequest, Executor, * DeviceStateRequest.Callback)}. *
* By default, the request is kept active until a call to * {@link DeviceStateManager#cancelStateRequest} or until one of the following occurs: *
* Guaranteed to be called after a call to * {@link DeviceStateManager.DeviceStateCallback#onDeviceStateChanged(DeviceState)} with a * state matching the requested state. */ default void onRequestActivated(@NonNull DeviceStateRequest request) {} /** * Called to indicate the request has been temporarily suspended. *
* Guaranteed to be called before a call to * {@link DeviceStateManager.DeviceStateCallback#onDeviceStateChanged(DeviceState)}. */ default void onRequestSuspended(@NonNull DeviceStateRequest request) {} /** * Called to indicate the request has been canceled. The request can be resubmitted with * another call to {@link DeviceStateManager#requestState(DeviceStateRequest, Executor, * DeviceStateRequest.Callback)}. *
* Guaranteed to be called before a call to * {@link DeviceStateManager.DeviceStateCallback#onDeviceStateChanged(DeviceState)}. *
* Note: A call to {@link #onRequestSuspended(DeviceStateRequest)} is not guaranteed to * occur before this method. */ default void onRequestCanceled(@NonNull DeviceStateRequest request) {} } private final int mRequestedState; @RequestFlags private final int mFlags; private DeviceStateRequest(int requestedState, @RequestFlags int flags) { mRequestedState = requestedState; mFlags = flags; } public int getState() { return mRequestedState; } @RequestFlags public int getFlags() { return mFlags; } }