From ec34667c5428a8e81fbd7dc72ca567286f1dd940 Mon Sep 17 00:00:00 2001 From: Peter Kalauskas Date: Wed, 17 Nov 2021 12:08:42 -0800 Subject: [PATCH] 1/2 Rename SecureSetting to SettingObserver Only renames the class and adds two javadoc comments to satisfy linter. Test: com.android.systemui.qs.SettingObserverTest Bug: 201567807 Change-Id: I65d3cd77ef41fcca0ab7d55e82f598f2d9fff1d4 --- .../com/android/systemui/ScreenDecorations.java | 6 +++--- .../{SecureSetting.java => SettingObserver.java} | 16 ++++++++++++---- .../systemui/qs/tiles/BatterySaverTile.java | 6 +++--- .../systemui/qs/tiles/ColorInversionTile.java | 6 +++--- .../com/android/systemui/qs/tiles/DndTile.java | 6 +++--- .../systemui/qs/tiles/OneHandedModeTile.java | 6 +++--- .../statusbar/phone/AutoTileManager.java | 8 ++++---- ...cureSettingTest.kt => SettingObserverTest.kt} | 6 +++--- .../statusbar/phone/AutoTileManagerTest.java | 6 +++--- 9 files changed, 37 insertions(+), 29 deletions(-) rename packages/SystemUI/src/com/android/systemui/qs/{SecureSetting.java => SettingObserver.java} (84%) rename packages/SystemUI/tests/src/com/android/systemui/qs/{SecureSettingTest.kt => SettingObserverTest.kt} (97%) diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java index e84024d4f88fd..33538ec25fcd0 100644 --- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java @@ -87,7 +87,7 @@ import com.android.systemui.animation.Interpolators; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Main; -import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.SettingObserver; import com.android.systemui.settings.UserTracker; import com.android.systemui.statusbar.events.PrivacyDotViewController; import com.android.systemui.tuner.TunerService; @@ -155,7 +155,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable { private float mDensity; private WindowManager mWindowManager; private int mRotation; - private SecureSetting mColorInversionSetting; + private SettingObserver mColorInversionSetting; private DelayableExecutor mExecutor; private Handler mHandler; private boolean mPendingRotationChange; @@ -346,7 +346,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable { // Watch color inversion and invert the overlay as needed. if (mColorInversionSetting == null) { - mColorInversionSetting = new SecureSetting(mSecureSettings, mHandler, + mColorInversionSetting = new SettingObserver(mSecureSettings, mHandler, Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, mUserTracker.getUserId()) { @Override diff --git a/packages/SystemUI/src/com/android/systemui/qs/SecureSetting.java b/packages/SystemUI/src/com/android/systemui/qs/SettingObserver.java similarity index 84% rename from packages/SystemUI/src/com/android/systemui/qs/SecureSetting.java rename to packages/SystemUI/src/com/android/systemui/qs/SettingObserver.java index d2bc38edd3375..9a184d52134eb 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/SecureSetting.java +++ b/packages/SystemUI/src/com/android/systemui/qs/SettingObserver.java @@ -24,7 +24,7 @@ import com.android.systemui.statusbar.policy.Listenable; import com.android.systemui.util.settings.SecureSettings; /** Helper for managing a secure setting. **/ -public abstract class SecureSetting extends ContentObserver implements Listenable { +public abstract class SettingObserver extends ContentObserver implements Listenable { private final SecureSettings mSecureSettings; private final String mSettingName; private final int mDefaultValue; @@ -35,16 +35,16 @@ public abstract class SecureSetting extends ContentObserver implements Listenabl protected abstract void handleValueChanged(int value, boolean observedChange); - public SecureSetting(SecureSettings secureSettings, Handler handler, String settingName, + public SettingObserver(SecureSettings secureSettings, Handler handler, String settingName, int userId) { this(secureSettings, handler, settingName, userId, 0); } - public SecureSetting(SecureSettings secureSetting, Handler handler, String settingName) { + public SettingObserver(SecureSettings secureSetting, Handler handler, String settingName) { this(secureSetting, handler, settingName, ActivityManager.getCurrentUser()); } - public SecureSetting(SecureSettings secureSettings, Handler handler, String settingName, + public SettingObserver(SecureSettings secureSettings, Handler handler, String settingName, int userId, int defaultValue) { super(handler); mSecureSettings = secureSettings; @@ -57,6 +57,11 @@ public abstract class SecureSetting extends ContentObserver implements Listenabl return mListening ? mObservedValue : getValueFromProvider(); } + /** + * Set the value of the observed setting. + * + * @param value The new value for the setting. + */ public void setValue(int value) { mSecureSettings.putIntForUser(mSettingName, value, mUserId); } @@ -87,6 +92,9 @@ public abstract class SecureSetting extends ContentObserver implements Listenabl handleValueChanged(value, changed); } + /** + * Set user handle for which to observe the setting. + */ public void setUserId(int userId) { mUserId = userId; if (mListening) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java index e3024fa0eddc4..b8ef3128f9ea8 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java @@ -36,7 +36,7 @@ import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.qs.QSTile.BooleanState; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.qs.QSHost; -import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.SettingObserver; import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.tileimpl.QSTileImpl; import com.android.systemui.statusbar.policy.BatteryController; @@ -49,7 +49,7 @@ public class BatterySaverTile extends QSTileImpl implements private final BatteryController mBatteryController; @VisibleForTesting - protected final SecureSetting mSetting; + protected final SettingObserver mSetting; private int mLevel; private boolean mPowerSave; @@ -76,7 +76,7 @@ public class BatterySaverTile extends QSTileImpl implements mBatteryController = batteryController; mBatteryController.observe(getLifecycle(), this); int currentUser = host.getUserContext().getUserId(); - mSetting = new SecureSetting( + mSetting = new SettingObserver( secureSettings, mHandler, Secure.LOW_POWER_WARNING_ACKNOWLEDGED, diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java index 5e502cc72c80f..38d90514d10a2 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java @@ -39,7 +39,7 @@ import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.qs.QSTile.BooleanState; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.qs.QSHost; -import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.SettingObserver; import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.tileimpl.QSTileImpl; import com.android.systemui.settings.UserTracker; @@ -55,7 +55,7 @@ public class ColorInversionTile extends QSTileImpl { private static final String COLOR_INVERSION_PREFERENCE_KEY = "toggle_inversion_preference"; private final Icon mIcon = ResourceIcon.get(drawable.ic_invert_colors); - private final SecureSetting mSetting; + private final SettingObserver mSetting; private boolean mListening; @@ -75,7 +75,7 @@ public class ColorInversionTile extends QSTileImpl { super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger, statusBarStateController, activityStarter, qsLogger); - mSetting = new SecureSetting(secureSettings, mHandler, + mSetting = new SettingObserver(secureSettings, mHandler, Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, userTracker.getUserId()) { @Override protected void handleValueChanged(int value, boolean observedChange) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java index b1cd68e5185c8..99cb700a324dd 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java @@ -61,7 +61,7 @@ import com.android.systemui.plugins.qs.DetailAdapter; import com.android.systemui.plugins.qs.QSTile.BooleanState; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.qs.QSHost; -import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.SettingObserver; import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.tileimpl.QSTileImpl; import com.android.systemui.statusbar.phone.SystemUIDialog; @@ -83,7 +83,7 @@ public class DndTile extends QSTileImpl { private final ZenModeController mController; private final DndDetailAdapter mDetailAdapter; private final SharedPreferences mSharedPreferences; - private final SecureSetting mSettingZenDuration; + private final SettingObserver mSettingZenDuration; private boolean mListening; private boolean mShowingDetail; @@ -108,7 +108,7 @@ public class DndTile extends QSTileImpl { mSharedPreferences = sharedPreferences; mDetailAdapter = new DndDetailAdapter(); mController.observe(getLifecycle(), mZenCallback); - mSettingZenDuration = new SecureSetting(secureSettings, mUiHandler, + mSettingZenDuration = new SettingObserver(secureSettings, mUiHandler, Settings.Secure.ZEN_DURATION, getHost().getUserId()) { @Override protected void handleValueChanged(int value, boolean observedChange) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/OneHandedModeTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/OneHandedModeTile.java index c8d2cdc1e4784..42d059152eb92 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/OneHandedModeTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/OneHandedModeTile.java @@ -36,7 +36,7 @@ import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.qs.QSTile.BooleanState; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.qs.QSHost; -import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.SettingObserver; import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.tileimpl.QSTileImpl; import com.android.systemui.settings.UserTracker; @@ -49,7 +49,7 @@ import javax.inject.Inject; public class OneHandedModeTile extends QSTileImpl { private final Icon mIcon = ResourceIcon.get( com.android.internal.R.drawable.ic_qs_one_handed_mode); - private final SecureSetting mSetting; + private final SettingObserver mSetting; @Inject public OneHandedModeTile( @@ -65,7 +65,7 @@ public class OneHandedModeTile extends QSTileImpl { SecureSettings secureSettings) { super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger, statusBarStateController, activityStarter, qsLogger); - mSetting = new SecureSetting(secureSettings, mHandler, + mSetting = new SettingObserver(secureSettings, mHandler, Settings.Secure.ONE_HANDED_MODE_ENABLED, userTracker.getUserId()) { @Override protected void handleValueChanged(int value, boolean observedChange) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java index fa326203b1829..244103cf419e1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java @@ -31,7 +31,7 @@ import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.qs.AutoAddTracker; import com.android.systemui.qs.QSTileHost; import com.android.systemui.qs.ReduceBrightColorsController; -import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.SettingObserver; import com.android.systemui.qs.external.CustomTile; import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.CastController.CastDevice; @@ -383,8 +383,8 @@ public class AutoTileManager implements UserAwareController { }; @VisibleForTesting - protected SecureSetting getSecureSettingForKey(String key) { - for (SecureSetting s : mAutoAddSettingList) { + protected SettingObserver getSecureSettingForKey(String key) { + for (SettingObserver s : mAutoAddSettingList) { if (Objects.equals(key, s.getKey())) { return s; } @@ -398,7 +398,7 @@ public class AutoTileManager implements UserAwareController { * When the setting changes to a value different from 0, if the tile has not been auto added * before, it will be added and the listener will be stopped. */ - private class AutoAddSetting extends SecureSetting { + private class AutoAddSetting extends SettingObserver { private final String mSpec; AutoAddSetting( diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/SecureSettingTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/SettingObserverTest.kt similarity index 97% rename from packages/SystemUI/tests/src/com/android/systemui/qs/SecureSettingTest.kt rename to packages/SystemUI/tests/src/com/android/systemui/qs/SettingObserverTest.kt index 6af8402d8aff9..4be689065d3f4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/SecureSettingTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/SettingObserverTest.kt @@ -35,7 +35,7 @@ private typealias Callback = (Int, Boolean) -> Unit @SmallTest @RunWith(AndroidTestingRunner::class) @TestableLooper.RunWithLooper -class SecureSettingTest : SysuiTestCase() { +class SettingObserverTest : SysuiTestCase() { companion object { private const val TEST_SETTING = "setting" @@ -46,7 +46,7 @@ class SecureSettingTest : SysuiTestCase() { } private lateinit var testableLooper: TestableLooper - private lateinit var setting: SecureSetting + private lateinit var setting: SettingObserver private lateinit var secureSettings: SecureSettings private lateinit var callback: Callback @@ -56,7 +56,7 @@ class SecureSettingTest : SysuiTestCase() { testableLooper = TestableLooper.get(this) secureSettings = FakeSettings() - setting = object : SecureSetting( + setting = object : SettingObserver( secureSettings, Handler(testableLooper.looper), TEST_SETTING, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java index 3f5d220957cd0..22899367afce9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java @@ -51,7 +51,7 @@ import com.android.systemui.SysuiTestCase; import com.android.systemui.qs.AutoAddTracker; import com.android.systemui.qs.QSTileHost; import com.android.systemui.qs.ReduceBrightColorsController; -import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.SettingObserver; import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.CastController.CastDevice; import com.android.systemui.statusbar.policy.DataSaverController; @@ -249,7 +249,7 @@ public class AutoTileManagerTest extends SysuiTestCase { verify(mWalletController, times(2)).getWalletPosition(); - SecureSetting setting = mAutoTileManager.getSecureSettingForKey(TEST_SETTING); + SettingObserver setting = mAutoTileManager.getSecureSettingForKey(TEST_SETTING); assertEquals(USER + 1, setting.getCurrentUser()); assertTrue(setting.isListening()); } @@ -299,7 +299,7 @@ public class AutoTileManagerTest extends SysuiTestCase { verify(mWalletController, times(2)).getWalletPosition(); - SecureSetting setting = mAutoTileManager.getSecureSettingForKey(TEST_SETTING); + SettingObserver setting = mAutoTileManager.getSecureSettingForKey(TEST_SETTING); assertEquals(USER + 1, setting.getCurrentUser()); assertFalse(setting.isListening()); }