Introduces flag for states that are emulated only

Introduces new flag on DeviceStates that are only
emulatable and don't correspond to a physical
device configuration.

Bug: 207686851
Test: Build && Test
Change-Id: Ic9fbd904250c678c302ef29c1430f7c27e074c4d
This commit is contained in:
Kenneth Ford
2022-11-12 00:25:33 +00:00
parent 6296e1121f
commit dc078773aa
2 changed files with 20 additions and 2 deletions

View File

@@ -18,11 +18,11 @@ package com.android.server.devicestate;
import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE;
import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE;
import static android.view.Display.DEFAULT_DISPLAY;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.hardware.devicestate.DeviceStateManager;
import com.android.internal.util.Preconditions;
@@ -55,6 +55,15 @@ public final class DeviceState {
*/
public static final int FLAG_APP_INACCESSIBLE = 1 << 1;
/**
* Some device states can be both entered through a physical configuration as well as emulation
* through {@link DeviceStateManager#requestState}, while some states can only be entered
* through emulation and have no physical configuration to match.
*
* This flag indicates that the corresponding state can only be entered through emulation.
*/
public static final int FLAG_EMULATED_ONLY = 1 << 2;
/** @hide */
@IntDef(prefix = {"FLAG_"}, flag = true, value = {
FLAG_CANCEL_OVERRIDE_REQUESTS,

View File

@@ -96,6 +96,7 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
private static final String CONFIG_FILE_NAME = "device_state_configuration.xml";
private static final String FLAG_CANCEL_OVERRIDE_REQUESTS = "FLAG_CANCEL_OVERRIDE_REQUESTS";
private static final String FLAG_APP_INACCESSIBLE = "FLAG_APP_INACCESSIBLE";
private static final String FLAG_EMULATED_ONLY = "FLAG_EMULATED_ONLY";
/** Interface that allows reading the device state configuration. */
interface ReadableConfig {
@@ -149,6 +150,8 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
case FLAG_APP_INACCESSIBLE:
flags |= DeviceState.FLAG_APP_INACCESSIBLE;
break;
case FLAG_EMULATED_ONLY:
flags |= DeviceState.FLAG_EMULATED_ONLY;
default:
Slog.w(TAG, "Parsed unknown flag with name: "
+ configFlagString);
@@ -225,7 +228,13 @@ public final class DeviceStateProviderImpl implements DeviceStateProvider,
}
final Conditions conditions = stateConditions.get(i);
if (conditions == null) {
mStateConditions.put(state, TRUE_BOOLEAN_SUPPLIER);
// If this state has the FLAG_EMULATED_ONLY flag on it, it should never be triggered
// by a physical hardware change, and should always return false for it's conditions
if (deviceStates.get(i).hasFlag(DeviceState.FLAG_EMULATED_ONLY)) {
mStateConditions.put(state, FALSE_BOOLEAN_SUPPLIER);
} else {
mStateConditions.put(state, TRUE_BOOLEAN_SUPPLIER);
}
continue;
}