From dc078773aa8e01e1f4e03965f364eda5a8a0d604 Mon Sep 17 00:00:00 2001 From: Kenneth Ford Date: Sat, 12 Nov 2022 00:25:33 +0000 Subject: [PATCH] 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 --- .../com/android/server/devicestate/DeviceState.java | 11 ++++++++++- .../server/policy/DeviceStateProviderImpl.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/devicestate/DeviceState.java b/services/core/java/com/android/server/devicestate/DeviceState.java index f8d4b8fffd032..42fe9d88825b9 100644 --- a/services/core/java/com/android/server/devicestate/DeviceState.java +++ b/services/core/java/com/android/server/devicestate/DeviceState.java @@ -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, diff --git a/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java b/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java index 9b7d19a725d1f..f867808890741 100644 --- a/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java +++ b/services/core/java/com/android/server/policy/DeviceStateProviderImpl.java @@ -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; }