• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 mRequestedState;
35     @DeviceStateRequest.RequestFlags
36     private final int mFlags;
37     @OverrideRequestType
38     private final int mRequestType;
39 
40     /**
41      * Denotes that the request is meant to override the emulated state of the device. This will
42      * not change the base (physical) state of the device.
43      *
44      * This request type should be used if you are looking to emulate a device state for a feature
45      * but want the system to be aware of the physical state of the device.
46      */
47     public static final int OVERRIDE_REQUEST_TYPE_EMULATED_STATE = 0;
48 
49     /**
50      * Denotes that the request is meant to override the base (physical) state of the device.
51      * Overriding the base state may not change the emulated state of the device if there is also an
52      * override request active for that property.
53      *
54      * This request type should only be used for testing, where you want to simulate the physical
55      * state of the device changing.
56      */
57     public static final int OVERRIDE_REQUEST_TYPE_BASE_STATE = 1;
58 
59     /**
60      * Flags for signifying the type of {@link OverrideRequest}.
61      *
62      * @hide
63      */
64     @IntDef(flag = true, prefix = { "REQUEST_TYPE_" }, value = {
65             OVERRIDE_REQUEST_TYPE_BASE_STATE,
66             OVERRIDE_REQUEST_TYPE_EMULATED_STATE
67     })
68     @Retention(RetentionPolicy.SOURCE)
69     public @interface OverrideRequestType {}
70 
OverrideRequest(IBinder token, int pid, int requestedState, @DeviceStateRequest.RequestFlags int flags, @OverrideRequestType int requestType)71     OverrideRequest(IBinder token, int pid, int requestedState,
72             @DeviceStateRequest.RequestFlags int flags, @OverrideRequestType int requestType) {
73         mToken = token;
74         mPid = pid;
75         mRequestedState = requestedState;
76         mFlags = flags;
77         mRequestType = requestType;
78     }
79 
getToken()80     IBinder getToken() {
81         return mToken;
82     }
83 
getPid()84     int getPid() {
85         return mPid;
86     }
87 
getRequestedState()88     int getRequestedState() {
89         return mRequestedState;
90     }
91 
92     @DeviceStateRequest.RequestFlags
getFlags()93     int getFlags() {
94         return mFlags;
95     }
96 
97     @OverrideRequestType
getRequestType()98     int getRequestType() {
99         return mRequestType;
100     }
101 }
102