diff options
| author | 2019-04-08 17:07:14 -0400 | |
|---|---|---|
| committer | 2019-04-09 16:06:45 -0400 | |
| commit | 372e13ff25c640fc31db3270f047eb0f43fc191c (patch) | |
| tree | 63d8d045916ad7bbc7866c49ceb65e3b692aa1d5 | |
| parent | ac54e30fe5f0421fa69c2333d49fd415da141e0b (diff) | |
Handle additional users settings custom clock faces.
Fixes: 128607948
Test: Switched user and checked clock face.
Change-Id: I2dc895f2b82cfa39f64588215a535ade4c90054e
4 files changed, 51 insertions, 26 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java index b738b576ef2f..70366a839da5 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java @@ -138,6 +138,7 @@ public class KeyguardClockSwitch extends RelativeLayout { ClockManager clockManager) { super(context, attrs); mStatusBarStateController = statusBarStateController; + mStatusBarState = mStatusBarStateController.getState(); mSysuiColorExtractor = colorExtractor; mClockManager = clockManager; mTransition = new ClockBoundsTransition(); diff --git a/packages/SystemUI/src/com/android/keyguard/clock/ClockManager.java b/packages/SystemUI/src/com/android/keyguard/clock/ClockManager.java index 64e56f955058..bc00b5cf9a45 100644 --- a/packages/SystemUI/src/com/android/keyguard/clock/ClockManager.java +++ b/packages/SystemUI/src/com/android/keyguard/clock/ClockManager.java @@ -20,8 +20,10 @@ import android.content.ContentResolver; import android.content.Context; import android.content.res.Resources; import android.database.ContentObserver; +import android.net.Uri; import android.os.Handler; import android.os.Looper; +import android.os.UserHandle; import android.provider.Settings; import android.util.ArrayMap; import android.util.DisplayMetrics; @@ -35,6 +37,7 @@ import com.android.systemui.dock.DockManager; import com.android.systemui.dock.DockManager.DockEventListener; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.PluginListener; +import com.android.systemui.settings.CurrentUserTracker; import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.util.InjectionInflationController; @@ -61,6 +64,7 @@ public final class ClockManager { private final ContentResolver mContentResolver; private final SettingsWrapper mSettingsWrapper; private final Handler mMainHandler = new Handler(Looper.getMainLooper()); + private final CurrentUserTracker mCurrentUserTracker; /** * Observe settings changes to know when to switch the clock face. @@ -68,9 +72,11 @@ public final class ClockManager { private final ContentObserver mContentObserver = new ContentObserver(mMainHandler) { @Override - public void onChange(boolean selfChange) { - super.onChange(selfChange); - reload(); + public void onChange(boolean selfChange, Uri uri, int userId) { + super.onChange(selfChange, uri, userId); + if (userId == mCurrentUserTracker.getCurrentUserId()) { + reload(); + } } }; @@ -123,6 +129,12 @@ public final class ClockManager { mPluginManager = pluginManager; mContentResolver = contentResolver; mSettingsWrapper = settingsWrapper; + mCurrentUserTracker = new CurrentUserTracker(context) { + @Override + public void onUserSwitched(int newUserId) { + reload(); + } + }; mPreviewClocks = new AvailableClocks(); Resources res = context.getResources(); @@ -203,10 +215,11 @@ public final class ClockManager { mPluginManager.addPluginListener(mPreviewClocks, ClockPlugin.class, true); mContentResolver.registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE), - false, mContentObserver); + false, mContentObserver, UserHandle.USER_ALL); mContentResolver.registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.DOCKED_CLOCK_FACE), - false, mContentObserver); + false, mContentObserver, UserHandle.USER_ALL); + mCurrentUserTracker.startTracking(); if (mDockManager == null) { mDockManager = SysUiServiceProvider.getComponent(mContext, DockManager.class); } @@ -218,6 +231,7 @@ public final class ClockManager { private void unregister() { mPluginManager.removePluginListener(mPreviewClocks); mContentResolver.unregisterContentObserver(mContentObserver); + mCurrentUserTracker.stopTracking(); if (mDockManager != null) { mDockManager.removeListener(mDockEventListener); } @@ -334,7 +348,8 @@ public final class ClockManager { private ClockPlugin getClockPlugin() { ClockPlugin plugin = null; if (ClockManager.this.isDocked()) { - final String name = mSettingsWrapper.getDockedClockFace(); + final String name = mSettingsWrapper.getDockedClockFace( + mCurrentUserTracker.getCurrentUserId()); if (name != null) { plugin = mClocks.get(name); if (plugin != null) { @@ -342,7 +357,8 @@ public final class ClockManager { } } } - final String name = mSettingsWrapper.getLockScreenCustomClockFace(); + final String name = mSettingsWrapper.getLockScreenCustomClockFace( + mCurrentUserTracker.getCurrentUserId()); if (name != null) { plugin = mClocks.get(name); } diff --git a/packages/SystemUI/src/com/android/keyguard/clock/SettingsWrapper.java b/packages/SystemUI/src/com/android/keyguard/clock/SettingsWrapper.java index 58e11553af9d..e1c658be4c26 100644 --- a/packages/SystemUI/src/com/android/keyguard/clock/SettingsWrapper.java +++ b/packages/SystemUI/src/com/android/keyguard/clock/SettingsWrapper.java @@ -34,15 +34,19 @@ public class SettingsWrapper { /** * Gets the value stored in settings for the custom clock face. + * + * @param userId ID of the user. */ - public String getLockScreenCustomClockFace() { - return Settings.Secure.getString(mContentResolver, CUSTOM_CLOCK_FACE); + public String getLockScreenCustomClockFace(int userId) { + return Settings.Secure.getStringForUser(mContentResolver, CUSTOM_CLOCK_FACE, userId); } /** * Gets the value stored in settings for the clock face to use when docked. + * + * @param userId ID of the user. */ - public String getDockedClockFace() { - return Settings.Secure.getString(mContentResolver, DOCKED_CLOCK_FACE); + public String getDockedClockFace(int userId) { + return Settings.Secure.getStringForUser(mContentResolver, DOCKED_CLOCK_FACE, userId); } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/clock/ClockManagerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/clock/ClockManagerTest.java index f2ad958c57ab..17fbe09e07b3 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/clock/ClockManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/clock/ClockManagerTest.java @@ -18,12 +18,14 @@ package com.android.keyguard.clock; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.database.ContentObserver; +import android.net.Uri; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; @@ -52,6 +54,8 @@ public final class ClockManagerTest extends SysuiTestCase { private static final String BUBBLE_CLOCK = BubbleClockController.class.getName(); private static final Class<?> BUBBLE_CLOCK_CLASS = BubbleClockController.class; + private static final int USER_ID = 0; + private static final Uri SETTINGS_URI = null; private ClockManager mClockManager; private ContentObserver mContentObserver; @@ -106,10 +110,10 @@ public final class ClockManagerTest extends SysuiTestCase { @Test public void getCurrentClock_default() { // GIVEN that settings doesn't contain any values - when(mMockSettingsWrapper.getLockScreenCustomClockFace()).thenReturn(null); - when(mMockSettingsWrapper.getDockedClockFace()).thenReturn(null); + when(mMockSettingsWrapper.getLockScreenCustomClockFace(anyInt())).thenReturn(null); + when(mMockSettingsWrapper.getDockedClockFace(anyInt())).thenReturn(null); // WHEN settings change event is fired - mContentObserver.onChange(false); + mContentObserver.onChange(false, SETTINGS_URI, USER_ID); // THEN the result is null, indicated the default clock face should be used. assertThat(mClockManager.getCurrentClock()).isNull(); } @@ -117,9 +121,9 @@ public final class ClockManagerTest extends SysuiTestCase { @Test public void getCurrentClock_customClock() { // GIVEN that settings is set to the bubble clock face - when(mMockSettingsWrapper.getLockScreenCustomClockFace()).thenReturn(BUBBLE_CLOCK); + when(mMockSettingsWrapper.getLockScreenCustomClockFace(anyInt())).thenReturn(BUBBLE_CLOCK); // WHEN settings change event is fired - mContentObserver.onChange(false); + mContentObserver.onChange(false, SETTINGS_URI, USER_ID); // THEN the plugin is the bubble clock face. assertThat(mClockManager.getCurrentClock()).isInstanceOf(BUBBLE_CLOCK_CLASS); } @@ -127,9 +131,9 @@ public final class ClockManagerTest extends SysuiTestCase { @Test public void onClockChanged_customClock() { // GIVEN that settings is set to the bubble clock face - when(mMockSettingsWrapper.getLockScreenCustomClockFace()).thenReturn(BUBBLE_CLOCK); + when(mMockSettingsWrapper.getLockScreenCustomClockFace(anyInt())).thenReturn(BUBBLE_CLOCK); // WHEN settings change event is fired - mContentObserver.onChange(false); + mContentObserver.onChange(false, SETTINGS_URI, USER_ID); // THEN the plugin is the bubble clock face. ArgumentCaptor<ClockPlugin> captor = ArgumentCaptor.forClass(ClockPlugin.class); verify(mMockListener1).onClockChanged(captor.capture()); @@ -139,9 +143,9 @@ public final class ClockManagerTest extends SysuiTestCase { @Test public void onClockChanged_uniqueInstances() { // GIVEN that settings is set to the bubble clock face - when(mMockSettingsWrapper.getLockScreenCustomClockFace()).thenReturn(BUBBLE_CLOCK); + when(mMockSettingsWrapper.getLockScreenCustomClockFace(anyInt())).thenReturn(BUBBLE_CLOCK); // WHEN settings change event is fired - mContentObserver.onChange(false); + mContentObserver.onChange(false, SETTINGS_URI, USER_ID); // THEN the listeners receive separate instances of the Bubble clock plugin. ArgumentCaptor<ClockPlugin> captor1 = ArgumentCaptor.forClass(ClockPlugin.class); ArgumentCaptor<ClockPlugin> captor2 = ArgumentCaptor.forClass(ClockPlugin.class); @@ -156,9 +160,9 @@ public final class ClockManagerTest extends SysuiTestCase { public void getCurrentClock_badSettingsValue() { // GIVEN that settings contains a value that doesn't correspond to a // custom clock face. - when(mMockSettingsWrapper.getLockScreenCustomClockFace()).thenReturn("bad value"); + when(mMockSettingsWrapper.getLockScreenCustomClockFace(anyInt())).thenReturn("bad value"); // WHEN settings change event is fired - mContentObserver.onChange(false); + mContentObserver.onChange(false, SETTINGS_URI, USER_ID); // THEN the result is null. assertThat(mClockManager.getCurrentClock()).isNull(); } @@ -174,7 +178,7 @@ public final class ClockManagerTest extends SysuiTestCase { @Test public void getCurrentClock_dockedCustomClock() { // GIVEN settings is set to the bubble clock face - when(mMockSettingsWrapper.getDockedClockFace()).thenReturn(BUBBLE_CLOCK); + when(mMockSettingsWrapper.getDockedClockFace(anyInt())).thenReturn(BUBBLE_CLOCK); // WHEN dock event fires mFakeDockManager.setDockEvent(DockManager.STATE_DOCKED); // THEN the plugin is the bubble clock face. @@ -184,7 +188,7 @@ public final class ClockManagerTest extends SysuiTestCase { @Test public void getCurrentClock_badDockedSettingsValue() { // GIVEN settings contains a value that doesn't correspond to an available clock face. - when(mMockSettingsWrapper.getDockedClockFace()).thenReturn("bad value"); + when(mMockSettingsWrapper.getDockedClockFace(anyInt())).thenReturn("bad value"); // WHEN dock event fires mFakeDockManager.setDockEvent(DockManager.STATE_DOCKED); // THEN the result is null. @@ -195,8 +199,8 @@ public final class ClockManagerTest extends SysuiTestCase { public void getCurrentClock_badDockedSettingsFallback() { // GIVEN settings contains a value that doesn't correspond to an available clock face, but // locked screen settings is set to bubble clock. - when(mMockSettingsWrapper.getDockedClockFace()).thenReturn("bad value"); - when(mMockSettingsWrapper.getLockScreenCustomClockFace()).thenReturn(BUBBLE_CLOCK); + when(mMockSettingsWrapper.getDockedClockFace(anyInt())).thenReturn("bad value"); + when(mMockSettingsWrapper.getLockScreenCustomClockFace(anyInt())).thenReturn(BUBBLE_CLOCK); // WHEN dock event is fired mFakeDockManager.setDockEvent(DockManager.STATE_DOCKED); // THEN the plugin is the bubble clock face. |