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. Only one 36 * 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 * 42 * @throws SecurityException if a callback is already registered for the calling process. 43 */ registerCallback(in IDeviceStateManagerCallback callback)44 void registerCallback(in IDeviceStateManagerCallback callback); 45 46 /** 47 * Requests that the device enter the supplied {@code state}. A callback <b>MUST</b> have been 48 * previously registered with {@link #registerCallback(IDeviceStateManagerCallback)} before a 49 * call to this method. 50 * 51 * Requesting a state does not cancel a base state override made through 52 * {@link #requestBaseStateOverride}, but will still attempt to put the device into the 53 * supplied {@code state}. 54 * 55 * @param token the request token provided 56 * @param state the state of device the request is asking for 57 * @param flags any flags that correspond to the request 58 * 59 * @throws IllegalStateException if a callback has not yet been registered for the calling 60 * process. 61 * @throws IllegalStateException if the supplied {@code token} has already been registered. 62 * @throws IllegalArgumentException if the supplied {@code state} is not supported. 63 */ 64 @JavaPassthrough(annotation= 65 "@android.annotation.RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true)") requestState(IBinder token, int state, int flags)66 void requestState(IBinder token, int state, int flags); 67 68 /** 69 * Cancels the active request previously submitted with a call to 70 * {@link #requestState(IBinder, int, int)}. Will have no effect on any base state override that 71 * was previously requested with {@link #requestBaseStateOverride}. 72 * 73 * @throws IllegalStateException if a callback has not yet been registered for the calling 74 * process. 75 */ 76 @JavaPassthrough(annotation= 77 "@android.annotation.RequiresPermission(value=android.Manifest.permission.CONTROL_DEVICE_STATE, conditional=true)") cancelStateRequest()78 void cancelStateRequest(); 79 80 /** 81 * Requests that the device's base state be overridden to the supplied {@code state}. A callback 82 * <b>MUST</b> have been previously registered with 83 * {@link #registerCallback(IDeviceStateManagerCallback)} before a call to this method. 84 * 85 * This method should only be used for testing, when you want to simulate the device physically 86 * changing states. If you are looking to change device state for a feature, where the system 87 * should still be aware that the physical state is different than the emulated state, use 88 * {@link #requestState}. 89 * 90 * @param token the request token provided 91 * @param state the state of device the request is asking for 92 * @param flags any flags that correspond to the request 93 * 94 * @throws IllegalStateException if a callback has not yet been registered for the calling 95 * process. 96 * @throws IllegalStateException if the supplied {@code token} has already been registered. 97 * @throws IllegalArgumentException if the supplied {@code state} is not supported. 98 */ 99 @JavaPassthrough(annotation= 100 "@android.annotation.RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE)") requestBaseStateOverride(IBinder token, int state, int flags)101 void requestBaseStateOverride(IBinder token, int state, int flags); 102 103 /** 104 * Cancels the active base state request previously submitted with a call to 105 * {@link #overrideBaseState(IBinder, int, int)}. 106 * 107 * @throws IllegalStateException if a callback has not yet been registered for the calling 108 * process. 109 */ 110 @JavaPassthrough(annotation= 111 "@android.annotation.RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE)") cancelBaseStateOverride()112 void cancelBaseStateOverride(); 113 114 /** 115 * Notifies the system service that the educational overlay that was launched 116 * before entering a requested state was dismissed or closed, and provides 117 * the system information on if the pairing mode should be canceled or not. 118 * 119 * This should only be called from the overlay itself. 120 */ 121 @JavaPassthrough(annotation= 122 "@android.annotation.RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE)") onStateRequestOverlayDismissed(boolean shouldCancelRequest)123 void onStateRequestOverlayDismissed(boolean shouldCancelRequest); 124 } 125