Loading packages/SettingsProvider/Android.bp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ android_app { ], ], static_libs: [ static_libs: [ "junit", "junit", "SettingsLibDeviceStateRotationLock", "SettingsLibDisplayDensityUtils", "SettingsLibDisplayDensityUtils", ], ], platform_apis: true, platform_apis: true, Loading @@ -55,6 +56,7 @@ android_test { static_libs: [ static_libs: [ "androidx.test.rules", "androidx.test.rules", "mockito-target-minus-junit4", "mockito-target-minus-junit4", "SettingsLibDeviceStateRotationLock", "SettingsLibDisplayDensityUtils", "SettingsLibDisplayDensityUtils", "platform-test-annotations", "platform-test-annotations", "truth-prebuilt", "truth-prebuilt", Loading packages/SettingsProvider/src/android/provider/settings/backup/DeviceSpecificSettings.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -32,5 +32,6 @@ public class DeviceSpecificSettings { */ */ public static final String[] DEVICE_SPECIFIC_SETTINGS_TO_BACKUP = { public static final String[] DEVICE_SPECIFIC_SETTINGS_TO_BACKUP = { Settings.Secure.DISPLAY_DENSITY_FORCED, Settings.Secure.DISPLAY_DENSITY_FORCED, Settings.Secure.DEVICE_STATE_ROTATION_LOCK }; }; } } packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.util.ArraySet; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.LocalePicker; import com.android.internal.app.LocalePicker; import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager; import java.util.ArrayList; import java.util.ArrayList; import java.util.HashMap; import java.util.HashMap; Loading Loading @@ -200,6 +201,9 @@ public class SettingsHelper { } else if (Settings.Global.POWER_BUTTON_LONG_PRESS.equals(name)) { } else if (Settings.Global.POWER_BUTTON_LONG_PRESS.equals(name)) { setLongPressPowerBehavior(cr, value); setLongPressPowerBehavior(cr, value); return; return; } else if (Settings.System.ACCELEROMETER_ROTATION.equals(name) && shouldSkipAutoRotateRestore()) { return; } } // Default case: write the restored value to settings // Default case: write the restored value to settings Loading Loading @@ -236,6 +240,12 @@ public class SettingsHelper { } } } } private boolean shouldSkipAutoRotateRestore() { // When device state based auto rotation settings are available, let's skip the restoring // of the standard auto rotation settings to avoid conflicting setting values. return DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(mContext); } public String onBackupValue(String name, String value) { public String onBackupValue(String name, String value) { // Special processing for backing up ringtones & notification sounds // Special processing for backing up ringtones & notification sounds if (Settings.System.RINGTONE.equals(name) if (Settings.System.RINGTONE.equals(name) Loading packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java +59 −0 Original line number Original line Diff line number Diff line Loading @@ -73,6 +73,8 @@ public class SettingsHelperTest { when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn( when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn( mTelephonyManager); mTelephonyManager); when(mContext.getResources()).thenReturn(mResources); when(mContext.getResources()).thenReturn(mResources); when(mContext.getApplicationContext()).thenReturn(mContext); when(mContext.getContentResolver()).thenReturn(getContentResolver()); mSettingsHelper = spy(new SettingsHelper(mContext)); mSettingsHelper = spy(new SettingsHelper(mContext)); } } Loading Loading @@ -305,6 +307,63 @@ public class SettingsHelperTest { new String[] { "he-IL", "id-ID", "yi" })); // supported new String[] { "he-IL", "id-ID", "yi" })); // supported } } @Test public void restoreValue_autoRotation_deviceStateAutoRotationDisabled_restoresValue() { when(mResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults)) .thenReturn(new String[]{}); int previousValue = 0; int newValue = 1; setAutoRotationSettingValue(previousValue); restoreAutoRotationSetting(newValue); assertThat(getAutoRotationSettingValue()).isEqualTo(newValue); } @Test public void restoreValue_autoRotation_deviceStateAutoRotationEnabled_doesNotRestoreValue() { when(mResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults)) .thenReturn(new String[]{"0:1", "1:1"}); int previousValue = 0; int newValue = 1; setAutoRotationSettingValue(previousValue); restoreAutoRotationSetting(newValue); assertThat(getAutoRotationSettingValue()).isEqualTo(previousValue); } private int getAutoRotationSettingValue() { return Settings.System.getInt( getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, /* default= */ -1); } private void setAutoRotationSettingValue(int value) { Settings.System.putInt( getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, value ); } private void restoreAutoRotationSetting(int newValue) { mSettingsHelper.restoreValue( mContext, getContentResolver(), new ContentValues(), /* destination= */ Settings.System.CONTENT_URI, /* name= */ Settings.System.ACCELEROMETER_ROTATION, /* value= */ String.valueOf(newValue), /* restoredFromSdkInt= */ 0); } private ContentResolver getContentResolver() { return InstrumentationRegistry.getInstrumentation().getTargetContext() .getContentResolver(); } private void clearLongPressPowerValues() { private void clearLongPressPowerValues() { ContentResolver cr = InstrumentationRegistry.getInstrumentation().getTargetContext() ContentResolver cr = InstrumentationRegistry.getInstrumentation().getTargetContext() .getContentResolver(); .getContentResolver(); Loading Loading
packages/SettingsProvider/Android.bp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ android_app { ], ], static_libs: [ static_libs: [ "junit", "junit", "SettingsLibDeviceStateRotationLock", "SettingsLibDisplayDensityUtils", "SettingsLibDisplayDensityUtils", ], ], platform_apis: true, platform_apis: true, Loading @@ -55,6 +56,7 @@ android_test { static_libs: [ static_libs: [ "androidx.test.rules", "androidx.test.rules", "mockito-target-minus-junit4", "mockito-target-minus-junit4", "SettingsLibDeviceStateRotationLock", "SettingsLibDisplayDensityUtils", "SettingsLibDisplayDensityUtils", "platform-test-annotations", "platform-test-annotations", "truth-prebuilt", "truth-prebuilt", Loading
packages/SettingsProvider/src/android/provider/settings/backup/DeviceSpecificSettings.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -32,5 +32,6 @@ public class DeviceSpecificSettings { */ */ public static final String[] DEVICE_SPECIFIC_SETTINGS_TO_BACKUP = { public static final String[] DEVICE_SPECIFIC_SETTINGS_TO_BACKUP = { Settings.Secure.DISPLAY_DENSITY_FORCED, Settings.Secure.DISPLAY_DENSITY_FORCED, Settings.Secure.DEVICE_STATE_ROTATION_LOCK }; }; } }
packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.util.ArraySet; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.LocalePicker; import com.android.internal.app.LocalePicker; import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager; import java.util.ArrayList; import java.util.ArrayList; import java.util.HashMap; import java.util.HashMap; Loading Loading @@ -200,6 +201,9 @@ public class SettingsHelper { } else if (Settings.Global.POWER_BUTTON_LONG_PRESS.equals(name)) { } else if (Settings.Global.POWER_BUTTON_LONG_PRESS.equals(name)) { setLongPressPowerBehavior(cr, value); setLongPressPowerBehavior(cr, value); return; return; } else if (Settings.System.ACCELEROMETER_ROTATION.equals(name) && shouldSkipAutoRotateRestore()) { return; } } // Default case: write the restored value to settings // Default case: write the restored value to settings Loading Loading @@ -236,6 +240,12 @@ public class SettingsHelper { } } } } private boolean shouldSkipAutoRotateRestore() { // When device state based auto rotation settings are available, let's skip the restoring // of the standard auto rotation settings to avoid conflicting setting values. return DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(mContext); } public String onBackupValue(String name, String value) { public String onBackupValue(String name, String value) { // Special processing for backing up ringtones & notification sounds // Special processing for backing up ringtones & notification sounds if (Settings.System.RINGTONE.equals(name) if (Settings.System.RINGTONE.equals(name) Loading
packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java +59 −0 Original line number Original line Diff line number Diff line Loading @@ -73,6 +73,8 @@ public class SettingsHelperTest { when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn( when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn( mTelephonyManager); mTelephonyManager); when(mContext.getResources()).thenReturn(mResources); when(mContext.getResources()).thenReturn(mResources); when(mContext.getApplicationContext()).thenReturn(mContext); when(mContext.getContentResolver()).thenReturn(getContentResolver()); mSettingsHelper = spy(new SettingsHelper(mContext)); mSettingsHelper = spy(new SettingsHelper(mContext)); } } Loading Loading @@ -305,6 +307,63 @@ public class SettingsHelperTest { new String[] { "he-IL", "id-ID", "yi" })); // supported new String[] { "he-IL", "id-ID", "yi" })); // supported } } @Test public void restoreValue_autoRotation_deviceStateAutoRotationDisabled_restoresValue() { when(mResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults)) .thenReturn(new String[]{}); int previousValue = 0; int newValue = 1; setAutoRotationSettingValue(previousValue); restoreAutoRotationSetting(newValue); assertThat(getAutoRotationSettingValue()).isEqualTo(newValue); } @Test public void restoreValue_autoRotation_deviceStateAutoRotationEnabled_doesNotRestoreValue() { when(mResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults)) .thenReturn(new String[]{"0:1", "1:1"}); int previousValue = 0; int newValue = 1; setAutoRotationSettingValue(previousValue); restoreAutoRotationSetting(newValue); assertThat(getAutoRotationSettingValue()).isEqualTo(previousValue); } private int getAutoRotationSettingValue() { return Settings.System.getInt( getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, /* default= */ -1); } private void setAutoRotationSettingValue(int value) { Settings.System.putInt( getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, value ); } private void restoreAutoRotationSetting(int newValue) { mSettingsHelper.restoreValue( mContext, getContentResolver(), new ContentValues(), /* destination= */ Settings.System.CONTENT_URI, /* name= */ Settings.System.ACCELEROMETER_ROTATION, /* value= */ String.valueOf(newValue), /* restoredFromSdkInt= */ 0); } private ContentResolver getContentResolver() { return InstrumentationRegistry.getInstrumentation().getTargetContext() .getContentResolver(); } private void clearLongPressPowerValues() { private void clearLongPressPowerValues() { ContentResolver cr = InstrumentationRegistry.getInstrumentation().getTargetContext() ContentResolver cr = InstrumentationRegistry.getInstrumentation().getTargetContext() .getContentResolver(); .getContentResolver(); Loading