Update Settings tests to new DeviceStateManager API
Updates tests that use PosturesHelper to return both the correct configuration values as well as the values returned through the DeviceStateManager APIs Flag: android.hardware.devicestate.feature.flags.device_state_property_migration Bug: 336640888 Test: atest SettingsRoboTests Change-Id: I23e7446de719f11c99a4f747e189e11405b203ef
This commit is contained in:
@@ -16,16 +16,26 @@
|
|||||||
|
|
||||||
package com.android.settings.display;
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import static android.hardware.devicestate.DeviceState.PROPERTY_EMULATED_ONLY;
|
||||||
|
import static android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY;
|
||||||
|
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_LOCKED;
|
import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.hardware.devicestate.DeviceState;
|
||||||
|
import android.hardware.devicestate.DeviceStateManager;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
@@ -34,29 +44,61 @@ import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManage
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class DeviceStateAutoRotateDetailsFragmentTest {
|
public class DeviceStateAutoRotateDetailsFragmentTest {
|
||||||
private static final int FOLDED_STATE = 0;
|
private static final DeviceState DEVICE_STATE_FOLDED = new DeviceState(
|
||||||
private static final int HALF_FOLDED_STATE = 1;
|
new DeviceState.Configuration.Builder(/* identifier= */ 0, "FOLDED")
|
||||||
private static final int UNFOLDED_STATE = 2;
|
.setSystemProperties(Set.of(
|
||||||
private static final int REAR_DISPLAY_STATE = 3;
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
|
||||||
|
.build());
|
||||||
|
private static final DeviceState DEVICE_STATE_HALF_FOLDED = new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(/* identifier= */ 1, "HALF_FOLDED")
|
||||||
|
.setSystemProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN))
|
||||||
|
.build());
|
||||||
|
private static final DeviceState DEVICE_STATE_UNFOLDED = new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(/* identifier= */ 2, "UNFOLDED")
|
||||||
|
.setSystemProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN))
|
||||||
|
.build());
|
||||||
|
private static final DeviceState DEVICE_STATE_REAR_DISPLAY = new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(/* identifier= */ 3, "REAR_DISPLAY")
|
||||||
|
.setSystemProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY,
|
||||||
|
PROPERTY_FEATURE_REAR_DISPLAY, PROPERTY_EMULATED_ONLY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
|
||||||
|
.build());
|
||||||
|
|
||||||
private final DeviceStateAutoRotateDetailsFragment mFragment =
|
private final DeviceStateAutoRotateDetailsFragment mFragment =
|
||||||
spy(new DeviceStateAutoRotateDetailsFragment());
|
spy(new DeviceStateAutoRotateDetailsFragment());
|
||||||
private final Context mContext = spy(RuntimeEnvironment.application);
|
private final Context mContext = spy(RuntimeEnvironment.application);
|
||||||
private final Resources mResources = spy(mContext.getResources());
|
private final Resources mResources = spy(mContext.getResources());
|
||||||
|
@Mock
|
||||||
|
private DeviceStateManager mDeviceStateManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
when(mFragment.getContext()).thenReturn(mContext);
|
when(mFragment.getContext()).thenReturn(mContext);
|
||||||
when(mFragment.getResources()).thenReturn(mResources);
|
when(mFragment.getResources()).thenReturn(mResources);
|
||||||
|
doReturn(mDeviceStateManager).when(mContext).getSystemService(DeviceStateManager.class);
|
||||||
setUpPostureMappings();
|
setUpPostureMappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +117,10 @@ public class DeviceStateAutoRotateDetailsFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
|
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
|
||||||
enableDeviceStateSettableRotationStates(
|
enableDeviceStateSettableRotationStates(
|
||||||
new String[]{FOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED,
|
new String[]{DEVICE_STATE_FOLDED.getIdentifier() + ":"
|
||||||
UNFOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED},
|
+ DEVICE_STATE_ROTATION_LOCK_LOCKED,
|
||||||
|
DEVICE_STATE_UNFOLDED.getIdentifier() + ":"
|
||||||
|
+ DEVICE_STATE_ROTATION_LOCK_LOCKED},
|
||||||
new String[]{"Folded", "Unfolded"});
|
new String[]{"Folded", "Unfolded"});
|
||||||
|
|
||||||
List<AbstractPreferenceController> preferenceControllers =
|
List<AbstractPreferenceController> preferenceControllers =
|
||||||
@@ -112,18 +156,22 @@ public class DeviceStateAutoRotateDetailsFragmentTest {
|
|||||||
.resetStateForTesting(mResources);
|
.resetStateForTesting(mResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets up posture mappings for PosturesHelper
|
||||||
private void setUpPostureMappings() {
|
private void setUpPostureMappings() {
|
||||||
when(mResources.getIntArray(
|
when(mResources.getIntArray(
|
||||||
com.android.internal.R.array.config_foldedDeviceStates)).thenReturn(
|
com.android.internal.R.array.config_foldedDeviceStates)).thenReturn(
|
||||||
new int[]{FOLDED_STATE});
|
new int[]{DEVICE_STATE_FOLDED.getIdentifier()});
|
||||||
when(mResources.getIntArray(
|
when(mResources.getIntArray(
|
||||||
com.android.internal.R.array.config_halfFoldedDeviceStates)).thenReturn(
|
com.android.internal.R.array.config_halfFoldedDeviceStates)).thenReturn(
|
||||||
new int[]{HALF_FOLDED_STATE});
|
new int[]{DEVICE_STATE_HALF_FOLDED.getIdentifier()});
|
||||||
when(mResources.getIntArray(
|
when(mResources.getIntArray(
|
||||||
com.android.internal.R.array.config_openDeviceStates)).thenReturn(
|
com.android.internal.R.array.config_openDeviceStates)).thenReturn(
|
||||||
new int[]{UNFOLDED_STATE});
|
new int[]{DEVICE_STATE_UNFOLDED.getIdentifier()});
|
||||||
when(mResources.getIntArray(
|
when(mResources.getIntArray(
|
||||||
com.android.internal.R.array.config_rearDisplayDeviceStates)).thenReturn(
|
com.android.internal.R.array.config_rearDisplayDeviceStates)).thenReturn(
|
||||||
new int[]{REAR_DISPLAY_STATE});
|
new int[]{DEVICE_STATE_REAR_DISPLAY.getIdentifier()});
|
||||||
|
when(mDeviceStateManager.getSupportedDeviceStates()).thenReturn(
|
||||||
|
List.of(DEVICE_STATE_FOLDED, DEVICE_STATE_HALF_FOLDED, DEVICE_STATE_UNFOLDED,
|
||||||
|
DEVICE_STATE_REAR_DISPLAY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,10 +21,13 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.hardware.devicestate.DeviceState;
|
||||||
|
import android.hardware.devicestate.DeviceStateManager;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
@@ -41,6 +44,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
@@ -56,15 +60,16 @@ import java.util.List;
|
|||||||
})
|
})
|
||||||
public class DeviceStateAutoRotateSettingControllerTest {
|
public class DeviceStateAutoRotateSettingControllerTest {
|
||||||
|
|
||||||
private static final int DEFAULT_DEVICE_STATE = 1;
|
private static final DeviceState DEFAULT_DEVICE_STATE = new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(/* identifier= */ 1, "DEFAULT").build());
|
||||||
private static final String DEFAULT_DEVICE_STATE_DESCRIPTION = "Device state description";
|
private static final String DEFAULT_DEVICE_STATE_DESCRIPTION = "Device state description";
|
||||||
private static final int DEFAULT_ORDER = -10;
|
private static final int DEFAULT_ORDER = -10;
|
||||||
|
|
||||||
private final Context mContext = RuntimeEnvironment.application;
|
private final Context mContext = Mockito.spy(RuntimeEnvironment.application);
|
||||||
private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager =
|
private DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager;
|
||||||
DeviceStateRotationLockSettingsManager.getInstance(mContext);
|
|
||||||
|
|
||||||
@Mock private MetricsFeatureProvider mMetricsFeatureProvider;
|
@Mock private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
@Mock private DeviceStateManager mDeviceStateManager;
|
||||||
|
|
||||||
private DeviceStateAutoRotateSettingController mController;
|
private DeviceStateAutoRotateSettingController mController;
|
||||||
|
|
||||||
@@ -72,9 +77,15 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
doReturn(mContext).when(mContext).getApplicationContext();
|
||||||
|
doReturn(mDeviceStateManager).when(mContext).getSystemService(DeviceStateManager.class);
|
||||||
|
doReturn(List.of(DEFAULT_DEVICE_STATE)).when(
|
||||||
|
mDeviceStateManager).getSupportedDeviceStates();
|
||||||
|
mAutoRotateSettingsManager =
|
||||||
|
DeviceStateRotationLockSettingsManager.getInstance(mContext);
|
||||||
mController = new DeviceStateAutoRotateSettingController(
|
mController = new DeviceStateAutoRotateSettingController(
|
||||||
mContext,
|
mContext,
|
||||||
DEFAULT_DEVICE_STATE,
|
DEFAULT_DEVICE_STATE.getIdentifier(),
|
||||||
DEFAULT_DEVICE_STATE_DESCRIPTION,
|
DEFAULT_DEVICE_STATE_DESCRIPTION,
|
||||||
DEFAULT_ORDER,
|
DEFAULT_ORDER,
|
||||||
mMetricsFeatureProvider
|
mMetricsFeatureProvider
|
||||||
@@ -128,20 +139,22 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
|||||||
public void getPreferenceKey_returnsKeyBasedOnDeviceState() {
|
public void getPreferenceKey_returnsKeyBasedOnDeviceState() {
|
||||||
String key = mController.getPreferenceKey();
|
String key = mController.getPreferenceKey();
|
||||||
|
|
||||||
String expectedKey = "auto_rotate_device_state_" + DEFAULT_DEVICE_STATE;
|
String expectedKey = "auto_rotate_device_state_" + DEFAULT_DEVICE_STATE.getIdentifier();
|
||||||
assertThat(key).isEqualTo(expectedKey);
|
assertThat(key).isEqualTo(expectedKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_settingForStateIsUnlocked_returnsTrue() {
|
public void isChecked_settingForStateIsUnlocked_returnsTrue() {
|
||||||
mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ false);
|
mAutoRotateSettingsManager.updateSetting(
|
||||||
|
DEFAULT_DEVICE_STATE.getIdentifier(), /* rotationLocked= */ false);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
assertThat(mController.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_settingForStateIsLocked_returnsFalse() {
|
public void isChecked_settingForStateIsLocked_returnsFalse() {
|
||||||
mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ true);
|
mAutoRotateSettingsManager.updateSetting(
|
||||||
|
DEFAULT_DEVICE_STATE.getIdentifier(), /* rotationLocked= */ true);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
assertThat(mController.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -150,7 +163,8 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
|||||||
public void setChecked_true_deviceStateSettingIsUnlocked() {
|
public void setChecked_true_deviceStateSettingIsUnlocked() {
|
||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
|
|
||||||
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
|
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(
|
||||||
|
DEFAULT_DEVICE_STATE.getIdentifier());
|
||||||
|
|
||||||
assertThat(rotationLocked).isFalse();
|
assertThat(rotationLocked).isFalse();
|
||||||
}
|
}
|
||||||
@@ -159,7 +173,8 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
|||||||
public void setChecked_false_deviceStateSettingIsLocked() {
|
public void setChecked_false_deviceStateSettingIsLocked() {
|
||||||
mController.setChecked(false);
|
mController.setChecked(false);
|
||||||
|
|
||||||
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
|
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(
|
||||||
|
DEFAULT_DEVICE_STATE.getIdentifier());
|
||||||
|
|
||||||
assertThat(rotationLocked).isTrue();
|
assertThat(rotationLocked).isTrue();
|
||||||
}
|
}
|
||||||
@@ -169,7 +184,8 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
|||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
|
|
||||||
verify(mMetricsFeatureProvider).action(mContext,
|
verify(mMetricsFeatureProvider).action(mContext,
|
||||||
SettingsEnums.ACTION_ENABLE_AUTO_ROTATION_DEVICE_STATE, DEFAULT_DEVICE_STATE);
|
SettingsEnums.ACTION_ENABLE_AUTO_ROTATION_DEVICE_STATE,
|
||||||
|
DEFAULT_DEVICE_STATE.getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -177,7 +193,8 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
|||||||
mController.setChecked(false);
|
mController.setChecked(false);
|
||||||
|
|
||||||
verify(mMetricsFeatureProvider).action(mContext,
|
verify(mMetricsFeatureProvider).action(mContext,
|
||||||
SettingsEnums.ACTION_DISABLE_AUTO_ROTATION_DEVICE_STATE, DEFAULT_DEVICE_STATE);
|
SettingsEnums.ACTION_DISABLE_AUTO_ROTATION_DEVICE_STATE,
|
||||||
|
DEFAULT_DEVICE_STATE.getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -33,6 +33,8 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.hardware.devicestate.DeviceState;
|
||||||
|
import android.hardware.devicestate.DeviceStateManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
@@ -56,6 +58,8 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadow.api.Shadow;
|
import org.robolectric.shadow.api.Shadow;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowSensorPrivacyManager.class, ShadowSystemSettings.class})
|
@Config(shadows = {ShadowSensorPrivacyManager.class, ShadowSystemSettings.class})
|
||||||
public class SmartAutoRotateControllerTest {
|
public class SmartAutoRotateControllerTest {
|
||||||
@@ -67,21 +71,30 @@ public class SmartAutoRotateControllerTest {
|
|||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
@Mock
|
||||||
|
private DeviceStateManager mDeviceStateManager;
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager =
|
private DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager;
|
||||||
DeviceStateRotationLockSettingsManager.getInstance(RuntimeEnvironment.application);
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
final Context context = Mockito.spy(RuntimeEnvironment.application);
|
final Context context = Mockito.spy(RuntimeEnvironment.application);
|
||||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||||
|
|
||||||
when(context.getPackageManager()).thenReturn(mPackageManager);
|
when(context.getPackageManager()).thenReturn(mPackageManager);
|
||||||
when(context.getContentResolver()).thenReturn(mContentResolver);
|
when(context.getContentResolver()).thenReturn(mContentResolver);
|
||||||
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
|
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
|
||||||
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
|
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
|
||||||
Manifest.permission.CAMERA, PACKAGE_NAME);
|
Manifest.permission.CAMERA, PACKAGE_NAME);
|
||||||
|
// Necessary for the DeviceStateRotationLockSettingsManager setup
|
||||||
|
doReturn(context).when(context).getApplicationContext();
|
||||||
|
doReturn(mDeviceStateManager).when(context).getSystemService(DeviceStateManager.class);
|
||||||
|
doReturn(getDeviceStateList()).when(mDeviceStateManager).getSupportedDeviceStates();
|
||||||
|
mDeviceStateAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(
|
||||||
|
context);
|
||||||
mController = Mockito.spy(new SmartAutoRotateController(context, "test_key"));
|
mController = Mockito.spy(new SmartAutoRotateController(context, "test_key"));
|
||||||
|
|
||||||
when(mController.isCameraLocked()).thenReturn(false);
|
when(mController.isCameraLocked()).thenReturn(false);
|
||||||
when(mController.isPowerSaveMode()).thenReturn(false);
|
when(mController.isPowerSaveMode()).thenReturn(false);
|
||||||
doReturn(mController.getPreferenceKey()).when(mPreference).getKey();
|
doReturn(mController.getPreferenceKey()).when(mPreference).getKey();
|
||||||
@@ -183,4 +196,13 @@ public class SmartAutoRotateControllerTest {
|
|||||||
Shadow.extract(mDeviceStateAutoRotateSettingsManager);
|
Shadow.extract(mDeviceStateAutoRotateSettingsManager);
|
||||||
shadowManager.setRotationLockedForAllStates(false);
|
shadowManager.setRotationLockedForAllStates(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list that includes a singular default {@link DeviceState}. To be returned when
|
||||||
|
* {@link DeviceStateManager#getSupportedDeviceStates()} is called.
|
||||||
|
*/
|
||||||
|
private List<DeviceState> getDeviceStateList() {
|
||||||
|
return List.of(new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(0 /* identifier */, "DEFAULT").build()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,13 @@
|
|||||||
|
|
||||||
package com.android.settings.display;
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import static android.hardware.devicestate.DeviceState.PROPERTY_EMULATED_ONLY;
|
||||||
|
import static android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY;
|
||||||
|
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_LOCKED;
|
import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED;
|
||||||
|
|
||||||
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY;
|
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY;
|
||||||
@@ -39,6 +46,8 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.hardware.devicestate.DeviceState;
|
||||||
|
import android.hardware.devicestate.DeviceStateManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -61,6 +70,7 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
@@ -70,10 +80,35 @@ import java.util.List;
|
|||||||
})
|
})
|
||||||
public class SmartAutoRotatePreferenceFragmentTest {
|
public class SmartAutoRotatePreferenceFragmentTest {
|
||||||
|
|
||||||
private static final int STATE_FOLDED = 0;
|
private static final DeviceState DEVICE_STATE_FOLDED = new DeviceState(
|
||||||
private static final int STATE_HALF_FOLDED = 1;
|
new DeviceState.Configuration.Builder(/* identifier= */ 0, "FOLDED")
|
||||||
private static final int STATE_UNFOLDED = 2;
|
.setSystemProperties(Set.of(
|
||||||
private static final int STATE_REAR_DISPLAY = 3;
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
|
||||||
|
.build());
|
||||||
|
private static final DeviceState DEVICE_STATE_HALF_FOLDED = new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(/* identifier= */ 1, "HALF_FOLDED")
|
||||||
|
.setSystemProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN))
|
||||||
|
.build());
|
||||||
|
private static final DeviceState DEVICE_STATE_UNFOLDED = new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(/* identifier= */ 2, "UNFOLDED")
|
||||||
|
.setSystemProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN))
|
||||||
|
.build());
|
||||||
|
private static final DeviceState DEVICE_STATE_REAR_DISPLAY = new DeviceState(
|
||||||
|
new DeviceState.Configuration.Builder(/* identifier= */ 3, "REAR_DISPLAY")
|
||||||
|
.setSystemProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY,
|
||||||
|
PROPERTY_FEATURE_REAR_DISPLAY, PROPERTY_EMULATED_ONLY))
|
||||||
|
.setPhysicalProperties(Set.of(
|
||||||
|
PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
|
||||||
|
.build());
|
||||||
|
|
||||||
private static final String PACKAGE_NAME = "package_name";
|
private static final String PACKAGE_NAME = "package_name";
|
||||||
|
|
||||||
@@ -96,6 +131,9 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Preference mRotateMainSwitchPreference;
|
private Preference mRotateMainSwitchPreference;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DeviceStateManager mDeviceStateManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
@@ -105,6 +143,7 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
|||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
|
doReturn(mDeviceStateManager).when(mContext).getSystemService(DeviceStateManager.class);
|
||||||
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
|
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
|
||||||
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
|
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
|
||||||
Manifest.permission.CAMERA, PACKAGE_NAME);
|
Manifest.permission.CAMERA, PACKAGE_NAME);
|
||||||
@@ -130,14 +169,7 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
|||||||
when(mFragment.findPreference(AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY))
|
when(mFragment.findPreference(AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY))
|
||||||
.thenReturn(mRotateMainSwitchPreference);
|
.thenReturn(mRotateMainSwitchPreference);
|
||||||
|
|
||||||
when(mResources.getIntArray(com.android.internal.R.array.config_foldedDeviceStates))
|
setUpPostureMappings();
|
||||||
.thenReturn(new int[] {STATE_FOLDED});
|
|
||||||
when(mResources.getIntArray(com.android.internal.R.array.config_halfFoldedDeviceStates))
|
|
||||||
.thenReturn(new int[] {STATE_HALF_FOLDED});
|
|
||||||
when(mResources.getIntArray(com.android.internal.R.array.config_openDeviceStates))
|
|
||||||
.thenReturn(new int[] {STATE_UNFOLDED});
|
|
||||||
when(mResources.getIntArray(com.android.internal.R.array.config_rearDisplayDeviceStates))
|
|
||||||
.thenReturn(new int[] {STATE_REAR_DISPLAY});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -195,8 +227,8 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
|||||||
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
|
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
|
||||||
enableDeviceStateSettableRotationStates(
|
enableDeviceStateSettableRotationStates(
|
||||||
new String[] {
|
new String[] {
|
||||||
STATE_FOLDED + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED,
|
DEVICE_STATE_FOLDED.getIdentifier() + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED,
|
||||||
STATE_UNFOLDED + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED
|
DEVICE_STATE_UNFOLDED.getIdentifier() + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED
|
||||||
},
|
},
|
||||||
new String[] {"Folded", "Unfolded"});
|
new String[] {"Folded", "Unfolded"});
|
||||||
|
|
||||||
@@ -236,4 +268,23 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
|||||||
DeviceStateRotationLockSettingsManager.getInstance(mContext)
|
DeviceStateRotationLockSettingsManager.getInstance(mContext)
|
||||||
.resetStateForTesting(mResources);
|
.resetStateForTesting(mResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets up posture mappings for PosturesHelper
|
||||||
|
private void setUpPostureMappings() {
|
||||||
|
when(mResources.getIntArray(
|
||||||
|
com.android.internal.R.array.config_foldedDeviceStates)).thenReturn(
|
||||||
|
new int[]{DEVICE_STATE_FOLDED.getIdentifier()});
|
||||||
|
when(mResources.getIntArray(
|
||||||
|
com.android.internal.R.array.config_halfFoldedDeviceStates)).thenReturn(
|
||||||
|
new int[]{DEVICE_STATE_HALF_FOLDED.getIdentifier()});
|
||||||
|
when(mResources.getIntArray(
|
||||||
|
com.android.internal.R.array.config_openDeviceStates)).thenReturn(
|
||||||
|
new int[]{DEVICE_STATE_UNFOLDED.getIdentifier()});
|
||||||
|
when(mResources.getIntArray(
|
||||||
|
com.android.internal.R.array.config_rearDisplayDeviceStates)).thenReturn(
|
||||||
|
new int[]{DEVICE_STATE_REAR_DISPLAY.getIdentifier()});
|
||||||
|
when(mDeviceStateManager.getSupportedDeviceStates()).thenReturn(
|
||||||
|
List.of(DEVICE_STATE_FOLDED, DEVICE_STATE_HALF_FOLDED, DEVICE_STATE_UNFOLDED,
|
||||||
|
DEVICE_STATE_REAR_DISPLAY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user