summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kenneth Ford <kennethford@google.com> 2024-07-19 04:47:51 +0000
committer Kenneth Ford <kennethford@google.com> 2024-10-16 18:25:13 +0000
commit4ba1a4de27823876ac6bc06206c1ad220236673a (patch)
tree0611d277939939015ce24bd82602f1bc8d8dbcae
parentff75fcf37bdf4f3ba41f6142825245ac91da39d4 (diff)
Update PosturesHelper to use DeviceStateManager API's
PosturesHelper updated to use the DeviceStateManager API's to determine what states map to being folded/unfolded etc instead of using the config overlay values Bug: 336640888 Test: PosturesHelperTest Test: DeviceStateRotationLockSettingControllerTest Test: DeviceStateRotationLockSettingsManagerTest Flag: android.hardware.devicestate.feature.flags.device_state_property_migration Change-Id: I6280934063e49658b129d0405f8d5feb71ff4901
-rw-r--r--packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java14
-rw-r--r--packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/PosturesHelper.kt81
-rw-r--r--packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java42
-rw-r--r--packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/PosturesHelperTest.kt126
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java87
5 files changed, 282 insertions, 68 deletions
diff --git a/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java b/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java
index ea4ac2c928ce..635f6905e4f0 100644
--- a/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java
+++ b/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java
@@ -20,10 +20,13 @@ import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_IGNORE
import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED;
import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_UNLOCKED;
+import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.ContentObserver;
+import android.hardware.devicestate.DeviceStateManager;
+import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
@@ -67,7 +70,8 @@ public final class DeviceStateRotationLockSettingsManager {
@VisibleForTesting
DeviceStateRotationLockSettingsManager(Context context, SecureSettings secureSettings) {
mSecureSettings = secureSettings;
- mPosturesHelper = new PosturesHelper(context);
+
+ mPosturesHelper = new PosturesHelper(context, getDeviceStateManager(context));
mPostureRotationLockDefaults =
context.getResources()
.getStringArray(R.array.config_perDeviceStateRotationLockDefaults);
@@ -76,6 +80,14 @@ public final class DeviceStateRotationLockSettingsManager {
listenForSettingsChange();
}
+ @Nullable
+ private DeviceStateManager getDeviceStateManager(Context context) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ return context.getSystemService(DeviceStateManager.class);
+ }
+ return null;
+ }
+
/** Returns a singleton instance of this class */
public static synchronized DeviceStateRotationLockSettingsManager getInstance(Context context) {
if (sSingleton == null) {
diff --git a/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/PosturesHelper.kt b/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/PosturesHelper.kt
index 6a13eb8c3907..14d59f2e416c 100644
--- a/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/PosturesHelper.kt
+++ b/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/PosturesHelper.kt
@@ -17,6 +17,12 @@
package com.android.settingslib.devicestate
import android.content.Context
+import android.hardware.devicestate.DeviceState
+import android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN
+import android.hardware.devicestate.DeviceStateManager
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_HALF_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY
@@ -24,37 +30,68 @@ import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_UNFOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_UNKNOWN
import android.provider.Settings.Secure.DeviceStateRotationLockKey
import com.android.internal.R
+import android.hardware.devicestate.feature.flags.Flags as DeviceStateManagerFlags
/** Helps to convert between device state and posture. */
-class PosturesHelper(context: Context) {
+class PosturesHelper(context: Context, deviceStateManager: DeviceStateManager?) {
- private val foldedDeviceStates =
- context.resources.getIntArray(R.array.config_foldedDeviceStates)
- private val halfFoldedDeviceStates =
- context.resources.getIntArray(R.array.config_halfFoldedDeviceStates)
- private val unfoldedDeviceStates =
- context.resources.getIntArray(R.array.config_openDeviceStates)
- private val rearDisplayDeviceStates =
- context.resources.getIntArray(R.array.config_rearDisplayDeviceStates)
+ private val postures: Map<Int, List<Int>>
+
+ init {
+ if (deviceStateManager != null && DeviceStateManagerFlags.deviceStatePropertyMigration()) {
+ postures =
+ deviceStateManager.supportedDeviceStates.groupBy { it.toPosture() }
+ .filterKeys { it != DEVICE_STATE_ROTATION_KEY_UNKNOWN }
+ .mapValues { it.value.map { it.identifier }}
+ } else {
+ val foldedDeviceStates =
+ context.resources.getIntArray(R.array.config_foldedDeviceStates).toList()
+ val halfFoldedDeviceStates =
+ context.resources.getIntArray(R.array.config_halfFoldedDeviceStates).toList()
+ val unfoldedDeviceStates =
+ context.resources.getIntArray(R.array.config_openDeviceStates).toList()
+ val rearDisplayDeviceStates =
+ context.resources.getIntArray(R.array.config_rearDisplayDeviceStates).toList()
+
+ postures =
+ mapOf(
+ DEVICE_STATE_ROTATION_KEY_FOLDED to foldedDeviceStates,
+ DEVICE_STATE_ROTATION_KEY_HALF_FOLDED to halfFoldedDeviceStates,
+ DEVICE_STATE_ROTATION_KEY_UNFOLDED to unfoldedDeviceStates,
+ DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY to rearDisplayDeviceStates
+ )
+ }
+ }
@DeviceStateRotationLockKey
fun deviceStateToPosture(deviceState: Int): Int {
- return when (deviceState) {
- in foldedDeviceStates -> DEVICE_STATE_ROTATION_KEY_FOLDED
- in halfFoldedDeviceStates -> DEVICE_STATE_ROTATION_KEY_HALF_FOLDED
- in unfoldedDeviceStates -> DEVICE_STATE_ROTATION_KEY_UNFOLDED
- in rearDisplayDeviceStates -> DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY
- else -> DEVICE_STATE_ROTATION_KEY_UNKNOWN
- }
+ return postures.filterValues { it.contains(deviceState) }.keys.firstOrNull()
+ ?: DEVICE_STATE_ROTATION_KEY_UNKNOWN
}
fun postureToDeviceState(@DeviceStateRotationLockKey posture: Int): Int? {
- return when (posture) {
- DEVICE_STATE_ROTATION_KEY_FOLDED -> foldedDeviceStates.firstOrNull()
- DEVICE_STATE_ROTATION_KEY_HALF_FOLDED -> halfFoldedDeviceStates.firstOrNull()
- DEVICE_STATE_ROTATION_KEY_UNFOLDED -> unfoldedDeviceStates.firstOrNull()
- DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY -> rearDisplayDeviceStates.firstOrNull()
- else -> null
+ return postures[posture]?.firstOrNull()
+ }
+
+ /**
+ * Maps a [DeviceState] to the corresponding [DeviceStateRotationLockKey] value based on the
+ * properties of the state.
+ */
+ @DeviceStateRotationLockKey
+ private fun DeviceState.toPosture(): Int {
+ return if (hasProperty(PROPERTY_FEATURE_REAR_DISPLAY)) {
+ DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY
+ } else if (hasProperty(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)) {
+ DEVICE_STATE_ROTATION_KEY_FOLDED
+ } else if (hasProperties(
+ PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY,
+ PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN
+ )) {
+ DEVICE_STATE_ROTATION_KEY_HALF_FOLDED
+ } else if (hasProperty(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)) {
+ DEVICE_STATE_ROTATION_KEY_UNFOLDED
+ } else {
+ DEVICE_STATE_ROTATION_KEY_UNKNOWN
}
}
}
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java
index 52c2a87cc961..9f9aaf5ff83a 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java
@@ -16,13 +16,22 @@
package com.android.settingslib.devicestate;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
+import android.annotation.NonNull;
import android.content.Context;
import android.content.res.Resources;
import android.database.ContentObserver;
+import android.hardware.devicestate.DeviceState;
+import android.hardware.devicestate.DeviceStateManager;
import android.os.UserHandle;
import android.provider.Settings;
@@ -42,7 +51,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -53,6 +65,8 @@ public class DeviceStateRotationLockSettingsManagerTest {
@Mock private Context mMockContext;
@Mock private Resources mMockResources;
+ @Mock private DeviceStateManager mDeviceStateManager;
+
private DeviceStateRotationLockSettingsManager mManager;
private int mNumSettingsChanges = 0;
private final ContentObserver mContentObserver = new ContentObserver(null) {
@@ -70,6 +84,9 @@ public class DeviceStateRotationLockSettingsManagerTest {
when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
when(mMockContext.getResources()).thenReturn(mMockResources);
when(mMockContext.getContentResolver()).thenReturn(context.getContentResolver());
+ when(mMockContext.getSystemService(DeviceStateManager.class)).thenReturn(
+ mDeviceStateManager);
+ when(mDeviceStateManager.getSupportedDeviceStates()).thenReturn(createDeviceStateList());
when(mMockResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults))
.thenReturn(new String[]{"0:1", "1:0:2", "2:2"});
when(mMockResources.getIntArray(R.array.config_foldedDeviceStates))
@@ -180,4 +197,29 @@ public class DeviceStateRotationLockSettingsManagerTest {
value,
UserHandle.USER_CURRENT);
}
+
+ private List<DeviceState> createDeviceStateList() {
+ List<DeviceState> deviceStates = new ArrayList<>();
+ deviceStates.add(createDeviceState(0 /* identifier */, "folded",
+ new HashSet<>(List.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)),
+ new HashSet<>(List.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))));
+ deviceStates.add(createDeviceState(1 /* identifier */, "half_folded",
+ new HashSet<>(List.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)),
+ new HashSet<>(
+ List.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN))));
+ deviceStates.add(createDeviceState(2, "unfolded",
+ new HashSet<>(List.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)),
+ new HashSet<>(List.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN))));
+
+ return deviceStates;
+ }
+
+ private DeviceState createDeviceState(int identifier, @NonNull String name,
+ @NonNull Set<@DeviceState.SystemDeviceStateProperties Integer> systemProperties,
+ @NonNull Set<@DeviceState.PhysicalDeviceStateProperties Integer> physicalProperties) {
+ DeviceState.Configuration deviceStateConfiguration = new DeviceState.Configuration.Builder(
+ identifier, name).setPhysicalProperties(systemProperties).setPhysicalProperties(
+ physicalProperties).build();
+ return new DeviceState(deviceStateConfiguration);
+ }
}
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/PosturesHelperTest.kt b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/PosturesHelperTest.kt
index d91c2fa66ca8..7a905cba491d 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/PosturesHelperTest.kt
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/PosturesHelperTest.kt
@@ -18,6 +18,16 @@ package com.android.settingslib.devicestate
import android.content.Context
import android.content.res.Resources
+import android.hardware.devicestate.DeviceState
+import android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN
+import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN
+import android.hardware.devicestate.DeviceStateManager
+import android.platform.test.annotations.RequiresFlagsDisabled
+import android.platform.test.annotations.RequiresFlagsEnabled
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_HALF_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY
@@ -32,14 +42,40 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
-import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations
+import android.hardware.devicestate.feature.flags.Flags as DeviceStateManagerFlags
+import org.mockito.Mockito.`when` as whenever
private const val DEVICE_STATE_UNKNOWN = 0
-private const val DEVICE_STATE_CLOSED = 1
-private const val DEVICE_STATE_HALF_FOLDED = 2
-private const val DEVICE_STATE_OPEN = 3
-private const val DEVICE_STATE_REAR_DISPLAY = 4
+private val DEVICE_STATE_CLOSED = DeviceState(
+ DeviceState.Configuration.Builder(/* identifier= */ 1, "CLOSED")
+ .setSystemProperties(setOf(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY))
+ .setPhysicalProperties(setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
+ .build()
+)
+private val DEVICE_STATE_HALF_FOLDED = DeviceState(
+ DeviceState.Configuration.Builder(/* identifier= */ 2, "HALF_FOLDED")
+ .setSystemProperties(setOf(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
+ .setPhysicalProperties(setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN))
+ .build()
+)
+private val DEVICE_STATE_OPEN = DeviceState(
+ DeviceState.Configuration.Builder(/* identifier= */ 3, "OPEN")
+ .setSystemProperties(setOf(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
+ .setPhysicalProperties(setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN))
+ .build()
+)
+private val DEVICE_STATE_REAR_DISPLAY = DeviceState(
+ DeviceState.Configuration.Builder(/* identifier= */ 4, "REAR_DISPLAY")
+ .setSystemProperties(
+ setOf(
+ PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY,
+ PROPERTY_FEATURE_REAR_DISPLAY
+ )
+ )
+ .setPhysicalProperties(setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
+ .build()
+)
@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -51,6 +87,8 @@ class PosturesHelperTest {
@Mock private lateinit var resources: Resources
+ @Mock private lateinit var deviceStateManager: DeviceStateManager
+
private lateinit var posturesHelper: PosturesHelper
@Before
@@ -59,30 +97,39 @@ class PosturesHelperTest {
whenever(context.resources).thenReturn(resources)
whenever(resources.getIntArray(R.array.config_foldedDeviceStates))
- .thenReturn(intArrayOf(DEVICE_STATE_CLOSED))
+ .thenReturn(intArrayOf(DEVICE_STATE_CLOSED.identifier))
whenever(resources.getIntArray(R.array.config_halfFoldedDeviceStates))
- .thenReturn(intArrayOf(DEVICE_STATE_HALF_FOLDED))
+ .thenReturn(intArrayOf(DEVICE_STATE_HALF_FOLDED.identifier))
whenever(resources.getIntArray(R.array.config_openDeviceStates))
- .thenReturn(intArrayOf(DEVICE_STATE_OPEN))
+ .thenReturn(intArrayOf(DEVICE_STATE_OPEN.identifier))
whenever(resources.getIntArray(R.array.config_rearDisplayDeviceStates))
- .thenReturn(intArrayOf(DEVICE_STATE_REAR_DISPLAY))
+ .thenReturn(intArrayOf(DEVICE_STATE_REAR_DISPLAY.identifier))
+ whenever(deviceStateManager.supportedDeviceStates).thenReturn(
+ listOf(
+ DEVICE_STATE_CLOSED,
+ DEVICE_STATE_HALF_FOLDED,
+ DEVICE_STATE_OPEN,
+ DEVICE_STATE_REAR_DISPLAY
+ )
+ )
- posturesHelper = PosturesHelper(context)
+ posturesHelper = PosturesHelper(context, deviceStateManager)
}
@Test
- fun deviceStateToPosture_mapsCorrectly() {
+ @RequiresFlagsDisabled(DeviceStateManagerFlags.FLAG_DEVICE_STATE_PROPERTY_MIGRATION)
+ fun deviceStateToPosture_mapsCorrectly_overlayConfigurationValues() {
expect
- .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_CLOSED))
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_CLOSED.identifier))
.isEqualTo(DEVICE_STATE_ROTATION_KEY_FOLDED)
expect
- .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_HALF_FOLDED))
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_HALF_FOLDED.identifier))
.isEqualTo(DEVICE_STATE_ROTATION_KEY_HALF_FOLDED)
expect
- .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_OPEN))
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_OPEN.identifier))
.isEqualTo(DEVICE_STATE_ROTATION_KEY_UNFOLDED)
expect
- .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_REAR_DISPLAY))
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_REAR_DISPLAY.identifier))
.isEqualTo(DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY)
expect
.that(posturesHelper.deviceStateToPosture(DEVICE_STATE_UNKNOWN))
@@ -90,19 +137,58 @@ class PosturesHelperTest {
}
@Test
- fun postureToDeviceState_mapsCorrectly() {
+ @RequiresFlagsEnabled(DeviceStateManagerFlags.FLAG_DEVICE_STATE_PROPERTY_MIGRATION)
+ fun deviceStateToPosture_mapsCorrectly_deviceStateManager() {
+ expect
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_CLOSED.identifier))
+ .isEqualTo(DEVICE_STATE_ROTATION_KEY_FOLDED)
+ expect
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_HALF_FOLDED.identifier))
+ .isEqualTo(DEVICE_STATE_ROTATION_KEY_HALF_FOLDED)
+ expect
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_OPEN.identifier))
+ .isEqualTo(DEVICE_STATE_ROTATION_KEY_UNFOLDED)
+ expect
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_REAR_DISPLAY.identifier))
+ .isEqualTo(DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY)
+ expect
+ .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_UNKNOWN))
+ .isEqualTo(DEVICE_STATE_ROTATION_KEY_UNKNOWN)
+ }
+
+ @Test
+ @RequiresFlagsDisabled(DeviceStateManagerFlags.FLAG_DEVICE_STATE_PROPERTY_MIGRATION)
+ fun postureToDeviceState_mapsCorrectly_overlayConfigurationValues() {
+ expect
+ .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_FOLDED))
+ .isEqualTo(DEVICE_STATE_CLOSED.identifier)
+ expect
+ .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_HALF_FOLDED))
+ .isEqualTo(DEVICE_STATE_HALF_FOLDED.identifier)
+ expect
+ .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_UNFOLDED))
+ .isEqualTo(DEVICE_STATE_OPEN.identifier)
+ expect
+ .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY))
+ .isEqualTo(DEVICE_STATE_REAR_DISPLAY.identifier)
+ expect.that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_UNKNOWN)).isNull()
+ }
+
+ @Test
+ @RequiresFlagsEnabled(DeviceStateManagerFlags.FLAG_DEVICE_STATE_PROPERTY_MIGRATION)
+ fun postureToDeviceState_mapsCorrectly_deviceStateManager() {
expect
.that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_FOLDED))
- .isEqualTo(DEVICE_STATE_CLOSED)
+ .isEqualTo(DEVICE_STATE_CLOSED.identifier)
expect
.that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_HALF_FOLDED))
- .isEqualTo(DEVICE_STATE_HALF_FOLDED)
+ .isEqualTo(DEVICE_STATE_HALF_FOLDED.identifier)
expect
.that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_UNFOLDED))
- .isEqualTo(DEVICE_STATE_OPEN)
+ .isEqualTo(DEVICE_STATE_OPEN.identifier)
expect
.that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY))
- .isEqualTo(DEVICE_STATE_REAR_DISPLAY)
+ .isEqualTo(DEVICE_STATE_REAR_DISPLAY.identifier)
expect.that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_UNKNOWN)).isNull()
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java
index f6e07d3d621e..3247a1ab6eb0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java
@@ -16,6 +16,11 @@
package com.android.systemui.statusbar.policy;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN;
+import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN;
import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_IGNORED;
import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED;
import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_UNLOCKED;
@@ -24,7 +29,9 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import android.annotation.NonNull;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
import android.os.UserHandle;
@@ -51,14 +58,37 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
@RunWith(AndroidJUnit4.class)
@SmallTest
public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase {
+ private static final DeviceState DEFAULT_FOLDED_STATE = createDeviceState(0 /* identifier */,
+ "folded", Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY),
+ Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED));
+ private static final DeviceState DEFAULT_HALF_FOLDED_STATE = createDeviceState(
+ 2 /* identifier */, "half_folded",
+ Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY),
+ Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN));
+ private static final DeviceState DEFAULT_UNFOLDED_STATE = createDeviceState(1 /* identifier */,
+ "unfolded",
+ Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY),
+ Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN));
+ private static final DeviceState UNKNOWN_DEVICE_STATE = createDeviceState(8 /* identifier */,
+ "unknown", Collections.emptySet(), Collections.emptySet());
+ private static final List<DeviceState> DEVICE_STATE_LIST = List.of(DEFAULT_FOLDED_STATE,
+ DEFAULT_HALF_FOLDED_STATE, DEFAULT_UNFOLDED_STATE);
+
private static final String[] DEFAULT_SETTINGS = new String[]{"0:1", "2:0:1", "1:2"};
- private static final int[] DEFAULT_FOLDED_STATES = new int[]{0};
- private static final int[] DEFAULT_HALF_FOLDED_STATES = new int[]{2};
- private static final int[] DEFAULT_UNFOLDED_STATES = new int[]{1};
+ private static final int[] DEFAULT_FOLDED_STATE_IDENTIFIERS =
+ new int[]{DEFAULT_FOLDED_STATE.getIdentifier()};
+ private static final int[] DEFAULT_HALF_FOLDED_STATE_IDENTIFIERS =
+ new int[]{DEFAULT_HALF_FOLDED_STATE.getIdentifier()};
+ private static final int[] DEFAULT_UNFOLDED_STATE_IDENTIFIERS =
+ new int[]{DEFAULT_UNFOLDED_STATE.getIdentifier()};
@Mock private DeviceStateManager mDeviceStateManager;
@Mock private DeviceStateRotationLockSettingControllerLogger mLogger;
@@ -77,10 +107,12 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
MockitoAnnotations.initMocks(/* testClass= */ this);
TestableResources resources = mContext.getOrCreateTestableResources();
resources.addOverride(R.array.config_perDeviceStateRotationLockDefaults, DEFAULT_SETTINGS);
- resources.addOverride(R.array.config_foldedDeviceStates, DEFAULT_FOLDED_STATES);
- resources.addOverride(R.array.config_halfFoldedDeviceStates, DEFAULT_HALF_FOLDED_STATES);
- resources.addOverride(R.array.config_openDeviceStates, DEFAULT_UNFOLDED_STATES);
-
+ resources.addOverride(R.array.config_foldedDeviceStates, DEFAULT_FOLDED_STATE_IDENTIFIERS);
+ resources.addOverride(R.array.config_halfFoldedDeviceStates,
+ DEFAULT_HALF_FOLDED_STATE_IDENTIFIERS);
+ resources.addOverride(R.array.config_openDeviceStates, DEFAULT_UNFOLDED_STATE_IDENTIFIERS);
+ when(mDeviceStateManager.getSupportedDeviceStates()).thenReturn(DEVICE_STATE_LIST);
+ mContext.addMockSystemService(DeviceStateManager.class, mDeviceStateManager);
ArgumentCaptor<DeviceStateManager.DeviceStateCallback> deviceStateCallbackArgumentCaptor =
ArgumentCaptor.forClass(DeviceStateManager.DeviceStateCallback.class);
@@ -120,11 +152,11 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
0, DEVICE_STATE_ROTATION_LOCK_UNLOCKED, 1, DEVICE_STATE_ROTATION_LOCK_UNLOCKED);
mFakeRotationPolicy.setRotationLock(true);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(1));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_UNFOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
// Settings only exist for state 0 and 1
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(2));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_HALF_FOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
}
@@ -135,10 +167,10 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
0, DEVICE_STATE_ROTATION_LOCK_UNLOCKED, 1, DEVICE_STATE_ROTATION_LOCK_LOCKED);
mFakeRotationPolicy.setRotationLock(true);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(0));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_FOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(1));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_UNFOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isTrue();
}
@@ -148,7 +180,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
mFakeRotationPolicy.setRotationLock(true);
// State 2 -> Ignored -> Fall back to state 1 which is unlocked
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(2));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_HALF_FOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
}
@@ -162,7 +194,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
mFakeRotationPolicy.setRotationLock(false);
// State 2 -> Ignored -> Fall back to state 1 which is locked
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(2));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_HALF_FOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isTrue();
}
@@ -174,7 +206,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
mSettingsManager.onPersistedSettingsChanged();
mFakeRotationPolicy.setRotationLock(true);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(0));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_FOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isTrue();
mDeviceStateRotationLockSettingController.onRotationLockStateChanged(
@@ -190,10 +222,10 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
@Test
public void whenDeviceStateSwitchedToIgnoredState_useFallbackSetting() {
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(0));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_FOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isTrue();
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(2));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_UNFOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
}
@@ -203,10 +235,10 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
8, DEVICE_STATE_ROTATION_LOCK_IGNORED, 1, DEVICE_STATE_ROTATION_LOCK_UNLOCKED);
mFakeRotationPolicy.setRotationLock(true);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(1));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_UNFOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(8));
+ mDeviceStateCallback.onDeviceStateChanged(UNKNOWN_DEVICE_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
mDeviceStateRotationLockSettingController.onRotationLockStateChanged(
@@ -226,7 +258,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
0, DEVICE_STATE_ROTATION_LOCK_UNLOCKED,
1, DEVICE_STATE_ROTATION_LOCK_UNLOCKED);
mFakeRotationPolicy.setRotationLock(false);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(0));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_FOLDED_STATE);
assertThat(mFakeRotationPolicy.isRotationLocked()).isFalse();
@@ -242,7 +274,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
initializeSettingsWith(
0, DEVICE_STATE_ROTATION_LOCK_LOCKED,
1, DEVICE_STATE_ROTATION_LOCK_UNLOCKED);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(0));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_FOLDED_STATE);
mDeviceStateRotationLockSettingController.onRotationLockStateChanged(
/* rotationLocked= */ false,
@@ -263,7 +295,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
0, DEVICE_STATE_ROTATION_LOCK_LOCKED,
1, DEVICE_STATE_ROTATION_LOCK_UNLOCKED,
2, DEVICE_STATE_ROTATION_LOCK_IGNORED);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(2));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_HALF_FOLDED_STATE);
mDeviceStateRotationLockSettingController.onRotationLockStateChanged(
/* rotationLocked= */ true,
@@ -284,8 +316,8 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
0, DEVICE_STATE_ROTATION_LOCK_LOCKED,
1, DEVICE_STATE_ROTATION_LOCK_UNLOCKED,
8, DEVICE_STATE_ROTATION_LOCK_IGNORED);
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(1));
- mDeviceStateCallback.onDeviceStateChanged(createDeviceStateForIdentifier(8));
+ mDeviceStateCallback.onDeviceStateChanged(DEFAULT_UNFOLDED_STATE);
+ mDeviceStateCallback.onDeviceStateChanged(UNKNOWN_DEVICE_STATE);
mDeviceStateRotationLockSettingController.onRotationLockStateChanged(
/* rotationLocked= */ true,
@@ -321,8 +353,13 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
mSettingsManager.onPersistedSettingsChanged();
}
- private DeviceState createDeviceStateForIdentifier(int id) {
- return new DeviceState(new DeviceState.Configuration.Builder(id, "" /* name */).build());
+ private static DeviceState createDeviceState(int identifier, @NonNull String name,
+ @NonNull Set<@DeviceState.SystemDeviceStateProperties Integer> systemProperties,
+ @NonNull Set<@DeviceState.PhysicalDeviceStateProperties Integer> physicalProperties) {
+ DeviceState.Configuration deviceStateConfiguration = new DeviceState.Configuration.Builder(
+ identifier, name).setSystemProperties(systemProperties).setPhysicalProperties(
+ physicalProperties).build();
+ return new DeviceState(deviceStateConfiguration);
}
private static class FakeRotationPolicy implements RotationPolicyWrapper {