Fixes 'no ripple effect' issue for screen attention setting

Preferences shouldn't be initialized at onAttach() because the settings
style hasn't been loaded yet. This change defers the preferences
initialization so that they comply with the settings style.

The change ag/14114425 is reverted due to b/186904496. This change
includes a fix for that issue.

Test: manually
Test: make RunSettingsRoboTests
ROBOTEST_FILTER=com.android.settings.display
Bug: 183909540
Bug: 186904496

Change-Id: I317ce251f4d11e62c6592ee587c2919da4d45db3
This commit is contained in:
Yi Jiang
2021-05-03 17:56:15 -07:00
parent 08b7833120
commit 18c97b595f
5 changed files with 61 additions and 38 deletions

View File

@@ -84,6 +84,7 @@ public class AdaptiveSleepPreferenceControllerTest {
eq(UserManager.DISALLOW_CONFIG_SCREEN_TIMEOUT))).thenReturn(null);
mController = new AdaptiveSleepPreferenceController(mContext, mRestrictionUtils);
mController.initializePreference();
when(mController.isCameraLocked()).thenReturn(false);
}

View File

@@ -60,8 +60,6 @@ public class ScreenTimeoutSettingsTest {
private ScreenTimeoutSettings mSettings;
private Context mContext;
private ContentResolver mContentResolver;
@Mock
private Resources mResources;
@Mock
@@ -85,7 +83,9 @@ public class ScreenTimeoutSettingsTest {
FakeFeatureFactory.setupForTest();
mContext = spy(getApplicationContext());
mSettings = spy(new ScreenTimeoutSettings());
mSettings.mContext = mContext;
mContentResolver = mContext.getContentResolver();
mResources = spy(mContext.getResources());
doReturn(TIMEOUT_ENTRIES).when(mResources).getStringArray(R.array.screen_timeout_entries);
doReturn(TIMEOUT_VALUES).when(mResources).getStringArray(R.array.screen_timeout_entries);