Introduce OverrideRequest type property

Adding a property to denote what type of
OverrideRequest is being made, allows us
to provide different behaviors depending
on if the request is to override the
emulated state of the device or the base
state.

Bug: 234336979
Test: OverrideRequestControllerTest
Change-Id: I63fb6c040c8a7116d18657e5cb041b5f67a7fb90
This commit is contained in:
Kenneth Ford
2022-08-16 19:17:30 +00:00
parent 24fdd1fc95
commit 8997144bba
3 changed files with 57 additions and 11 deletions

View File

@@ -617,7 +617,8 @@ public final class DeviceStateManagerService extends SystemService {
+ " is not supported.");
}
OverrideRequest request = new OverrideRequest(token, callingPid, state, flags);
OverrideRequest request = new OverrideRequest(token, callingPid, state, flags,
OverrideRequest.OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
mOverrideRequestController.addRequest(request);
}
}

View File

@@ -16,9 +16,13 @@
package com.android.server.devicestate;
import android.annotation.IntDef;
import android.hardware.devicestate.DeviceStateRequest;
import android.os.IBinder;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* A request to override the state managed by {@link DeviceStateManagerService}.
*
@@ -30,13 +34,47 @@ final class OverrideRequest {
private final int mRequestedState;
@DeviceStateRequest.RequestFlags
private final int mFlags;
@OverrideRequestType
private final int mRequestType;
/**
* Denotes that the request is meant to override the emulated state of the device. This will
* not change the base (physical) state of the device.
*
* This request type should be used if you are looking to emulate a device state for a feature
* but want the system to be aware of the physical state of the device.
*/
public static final int OVERRIDE_REQUEST_TYPE_EMULATED_STATE = 0;
/**
* Denotes that the request is meant to override the base (physical) state of the device.
* Overriding the base state may not change the emulated state of the device if there is also an
* override request active for that property.
*
* This request type should only be used for testing, where you want to simulate the physical
* state of the device changing.
*/
public static final int OVERRIDE_REQUEST_TYPE_BASE_STATE = 1;
/**
* Flags for signifying the type of {@link OverrideRequest}.
*
* @hide
*/
@IntDef(flag = true, prefix = { "REQUEST_TYPE_" }, value = {
OVERRIDE_REQUEST_TYPE_BASE_STATE,
OVERRIDE_REQUEST_TYPE_EMULATED_STATE
})
@Retention(RetentionPolicy.SOURCE)
public @interface OverrideRequestType {}
OverrideRequest(IBinder token, int pid, int requestedState,
@DeviceStateRequest.RequestFlags int flags) {
@DeviceStateRequest.RequestFlags int flags, @OverrideRequestType int requestType) {
mToken = token;
mPid = pid;
mRequestedState = requestedState;
mFlags = flags;
mRequestType = requestType;
}
IBinder getToken() {
@@ -55,4 +93,9 @@ final class OverrideRequest {
int getFlags() {
return mFlags;
}
@OverrideRequestType
int getRequestType() {
return mRequestType;
}
}

View File

@@ -16,6 +16,7 @@
package com.android.server.devicestate;
import static com.android.server.devicestate.OverrideRequest.OVERRIDE_REQUEST_TYPE_EMULATED_STATE;
import static com.android.server.devicestate.OverrideRequestController.STATUS_ACTIVE;
import static com.android.server.devicestate.OverrideRequestController.STATUS_CANCELED;
@@ -57,7 +58,7 @@ public final class OverrideRequestControllerTest {
@Test
public void addRequest() {
OverrideRequest request = new OverrideRequest(new Binder(), 0 /* pid */,
0 /* requestedState */, 0 /* flags */);
0 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
assertNull(mStatusListener.getLastStatus(request));
mController.addRequest(request);
@@ -67,14 +68,14 @@ public final class OverrideRequestControllerTest {
@Test
public void addRequest_cancelExistingRequestThroughNewRequest() {
OverrideRequest firstRequest = new OverrideRequest(new Binder(), 0 /* pid */,
0 /* requestedState */, 0 /* flags */);
0 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
assertNull(mStatusListener.getLastStatus(firstRequest));
mController.addRequest(firstRequest);
assertEquals(mStatusListener.getLastStatus(firstRequest).intValue(), STATUS_ACTIVE);
OverrideRequest secondRequest = new OverrideRequest(new Binder(), 0 /* pid */,
1 /* requestedState */, 0 /* flags */);
1 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
assertNull(mStatusListener.getLastStatus(secondRequest));
mController.addRequest(secondRequest);
@@ -85,7 +86,7 @@ public final class OverrideRequestControllerTest {
@Test
public void addRequest_cancelActiveRequest() {
OverrideRequest firstRequest = new OverrideRequest(new Binder(), 0 /* pid */,
0 /* requestedState */, 0 /* flags */);
0 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
mController.addRequest(firstRequest);
@@ -100,7 +101,8 @@ public final class OverrideRequestControllerTest {
public void handleBaseStateChanged() {
OverrideRequest firstRequest = new OverrideRequest(new Binder(), 0 /* pid */,
0 /* requestedState */,
DeviceStateRequest.FLAG_CANCEL_WHEN_BASE_CHANGES /* flags */);
DeviceStateRequest.FLAG_CANCEL_WHEN_BASE_CHANGES /* flags */,
OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
mController.addRequest(firstRequest);
@@ -114,7 +116,7 @@ public final class OverrideRequestControllerTest {
@Test
public void handleProcessDied() {
OverrideRequest firstRequest = new OverrideRequest(new Binder(), 0 /* pid */,
0 /* requestedState */, 0 /* flags */);
0 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
mController.addRequest(firstRequest);
assertEquals(mStatusListener.getLastStatus(firstRequest).intValue(), STATUS_ACTIVE);
@@ -128,7 +130,7 @@ public final class OverrideRequestControllerTest {
mController.setStickyRequestsAllowed(true);
OverrideRequest firstRequest = new OverrideRequest(new Binder(), 0 /* pid */,
0 /* requestedState */, 0 /* flags */);
0 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
mController.addRequest(firstRequest);
assertEquals(mStatusListener.getLastStatus(firstRequest).intValue(), STATUS_ACTIVE);
@@ -143,7 +145,7 @@ public final class OverrideRequestControllerTest {
@Test
public void handleNewSupportedStates() {
OverrideRequest firstRequest = new OverrideRequest(new Binder(), 0 /* pid */,
1 /* requestedState */, 0 /* flags */);
1 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
mController.addRequest(firstRequest);
assertEquals(mStatusListener.getLastStatus(firstRequest).intValue(), STATUS_ACTIVE);
@@ -158,7 +160,7 @@ public final class OverrideRequestControllerTest {
@Test
public void cancelOverrideRequestsTest() {
OverrideRequest firstRequest = new OverrideRequest(new Binder(), 0 /* pid */,
1 /* requestedState */, 0 /* flags */);
1 /* requestedState */, 0 /* flags */, OVERRIDE_REQUEST_TYPE_EMULATED_STATE);
mController.addRequest(firstRequest);
assertEquals(mStatusListener.getLastStatus(firstRequest).intValue(), STATUS_ACTIVE);