1 /* 2 * Copyright (C) 2021 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 com.android.server.devicestate; 18 19 import android.annotation.IntDef; 20 import android.hardware.devicestate.DeviceStateRequest; 21 import android.os.IBinder; 22 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** 27 * A request to override the state managed by {@link DeviceStateManagerService}. 28 * 29 * @see OverrideRequestController 30 */ 31 final class OverrideRequest { 32 private final IBinder mToken; 33 private final int mPid; 34 private final int mUid; 35 private final int mRequestedState; 36 @DeviceStateRequest.RequestFlags 37 private final int mFlags; 38 @OverrideRequestType 39 private final int mRequestType; 40 41 /** 42 * Denotes that the request is meant to override the emulated state of the device. This will 43 * not change the base (physical) state of the device. 44 * 45 * This request type should be used if you are looking to emulate a device state for a feature 46 * but want the system to be aware of the physical state of the device. 47 */ 48 public static final int OVERRIDE_REQUEST_TYPE_EMULATED_STATE = 0; 49 50 /** 51 * Denotes that the request is meant to override the base (physical) state of the device. 52 * Overriding the base state may not change the emulated state of the device if there is also an 53 * override request active for that property. 54 * 55 * This request type should only be used for testing, where you want to simulate the physical 56 * state of the device changing. 57 */ 58 public static final int OVERRIDE_REQUEST_TYPE_BASE_STATE = 1; 59 60 /** 61 * Flags for signifying the type of {@link OverrideRequest}. 62 * 63 * @hide 64 */ 65 @IntDef(flag = true, prefix = { "REQUEST_TYPE_" }, value = { 66 OVERRIDE_REQUEST_TYPE_BASE_STATE, 67 OVERRIDE_REQUEST_TYPE_EMULATED_STATE 68 }) 69 @Retention(RetentionPolicy.SOURCE) 70 public @interface OverrideRequestType {} 71 OverrideRequest(IBinder token, int pid, int uid, int requestedState, @DeviceStateRequest.RequestFlags int flags, @OverrideRequestType int requestType)72 OverrideRequest(IBinder token, int pid, int uid, int requestedState, 73 @DeviceStateRequest.RequestFlags int flags, @OverrideRequestType int requestType) { 74 mToken = token; 75 mPid = pid; 76 mUid = uid; 77 mRequestedState = requestedState; 78 mFlags = flags; 79 mRequestType = requestType; 80 } 81 getToken()82 IBinder getToken() { 83 return mToken; 84 } 85 getPid()86 int getPid() { 87 return mPid; 88 } 89 getUid()90 int getUid() { 91 return mUid; 92 } 93 getRequestedState()94 int getRequestedState() { 95 return mRequestedState; 96 } 97 98 @DeviceStateRequest.RequestFlags getFlags()99 int getFlags() { 100 return mFlags; 101 } 102 103 @OverrideRequestType getRequestType()104 int getRequestType() { 105 return mRequestType; 106 } 107 } 108