1 /** 2 * Copyright (c) 2020, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.devicestate; 18 19 import android.hardware.devicestate.DeviceStateInfo; 20 import android.hardware.devicestate.IDeviceStateManagerCallback; 21 22 /** @hide */ 23 interface IDeviceStateManager { 24 /** 25 * Returns the current device state info. This {@link DeviceStateInfo} object will always 26 * include the list of supported states. If there has been no base state or committed state 27 * provided yet to the system server, this {@link DeviceStateInfo} object will include 28 * {@link DeviceStateManager#INVALID_DEVICE_STATE} for each respectively. 29 * 30 * This method should not be used to notify callback clients. 31 */ getDeviceStateInfo()32 DeviceStateInfo getDeviceStateInfo(); 33 34 /** 35 * Registers a callback to receive notifications from the device state manager and returns the 36 * current {@link DeviceStateInfo}. Only one callback can be registered per-process. 37 * <p> 38 * As the callback mechanism is used to alert the caller of changes to request status a callback 39 * <b>MUST</b> be registered before calling {@link #requestState(IBinder, int, int)} or 40 * {@link #cancelRequest(IBinder)}, otherwise an exception will be thrown. 41 * <p> 42 * Upon successful registration, this method returns the committed {@link DeviceStateInfo} if 43 * available, ensuring the availability of the device state after the callback is registered. 44 * This guarantees that the client will have access to the latest device state immediately upon 45 * completion of the two-way IPC call. 46 * 47 * @param callback the callback to register for device state notifications. 48 * @return DeviceStateInfo the current device state information including the committed state 49 * or null if no state has been committed by the {@link DeviceStateProvider} yet. 50 * @throws SecurityException if a callback is already registered for the calling process. 51 */ registerCallback(in IDeviceStateManagerCallback callback)52 @nullable DeviceStateInfo registerCallback(in IDeviceStateManagerCallback callback); 53 54 /** 55 * Requests that the device enter the supplied {@code state}. A callback <b>MUST</b> have been 56 * previously registered with {@link #registerCallback(IDeviceStateManagerCallback)} before a 57 * call to this method. 58 * 59 * Requesting a state does not cancel a base state override made through 60 * {@link #requestBaseStateOverride}, but will still attempt to put the device into the 61 * supplied {@code state}. 62 * 63 * @param token the request token provided 64 * @param state the state of device the request is asking for 65 * @param flags any flags that correspond to the request 66 * 67 * @throws IllegalStateException if a callback has not yet been registered for the calling 68 * process. 69 * @throws IllegalStateException if the supplied {@code token} has already been registered. 70 * @throws IllegalArgumentException if the supplied {@code state} is not supported. 71 */ 72 @JavaPassthrough(annotation= 73 "@android.annotation.RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true)") requestState(IBinder token, int state, int flags)74 void requestState(IBinder token, int state, int flags); 75 76 /** 77 * Cancels the active request previously submitted with a call to 78 * {@link #requestState(IBinder, int, int)}. Will have no effect on any base state override that 79 * was previously requested with {@link #requestBaseStateOverride}. 80 * 81 * @throws IllegalStateException if a callback has not yet been registered for the calling 82 * process. 83 */ 84 @JavaPassthrough(annotation= 85 "@android.annotation.RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true)") cancelStateRequest()86 void cancelStateRequest(); 87 88 /** 89 * Requests that the device's base state be overridden to the supplied {@code state}. A callback 90 * <b>MUST</b> have been previously registered with 91 * {@link #registerCallback(IDeviceStateManagerCallback)} before a call to this method. 92 * 93 * This method should only be used for testing, when you want to simulate the device physically 94 * changing states. If you are looking to change device state for a feature, where the system 95 * should still be aware that the physical state is different than the emulated state, use 96 * {@link #requestState}. 97 * 98 * @param token the request token provided 99 * @param state the state of device the request is asking for 100 * @param flags any flags that correspond to the request 101 * 102 * @throws IllegalStateException if a callback has not yet been registered for the calling 103 * process. 104 * @throws IllegalStateException if the supplied {@code token} has already been registered. 105 * @throws IllegalArgumentException if the supplied {@code state} is not supported. 106 */ 107 @JavaPassthrough(annotation= 108 "@android.annotation.RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE)") requestBaseStateOverride(IBinder token, int state, int flags)109 void requestBaseStateOverride(IBinder token, int state, int flags); 110 111 /** 112 * Cancels the active base state request previously submitted with a call to 113 * {@link #overrideBaseState(IBinder, int, int)}. 114 * 115 * @throws IllegalStateException if a callback has not yet been registered for the calling 116 * process. 117 */ 118 @JavaPassthrough(annotation= 119 "@android.annotation.RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE)") cancelBaseStateOverride()120 void cancelBaseStateOverride(); 121 122 /** 123 * Notifies the system service that the educational overlay that was launched 124 * before entering a requested state was dismissed or closed, and provides 125 * the system information on if the pairing mode should be canceled or not. 126 * 127 * This should only be called from the overlay itself. 128 */ 129 @EnforcePermission("CONTROL_DEVICE_STATE") 130 @JavaPassthrough(annotation= 131 "@android.annotation.RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE)") onStateRequestOverlayDismissed(boolean shouldCancelRequest)132 void onStateRequestOverlayDismissed(boolean shouldCancelRequest); 133 } 134