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;
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;
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.
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();
+ }
}
};
mPluginManager = pluginManager;
mContentResolver = contentResolver;
mSettingsWrapper = settingsWrapper;
+ mCurrentUserTracker = new CurrentUserTracker(context) {
+ @Override
+ public void onUserSwitched(int newUserId) {
+ reload();
+ }
+ };
mPreviewClocks = new AvailableClocks();
Resources res = context.getResources();
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);
}
private void unregister() {
mPluginManager.removePluginListener(mPreviewClocks);
mContentResolver.unregisterContentObserver(mContentObserver);
+ mCurrentUserTracker.stopTracking();
if (mDockManager != null) {
mDockManager.removeListener(mDockEventListener);
}
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) {
}
}
}
- final String name = mSettingsWrapper.getLockScreenCustomClockFace();
+ final String name = mSettingsWrapper.getLockScreenCustomClockFace(
+ mCurrentUserTracker.getCurrentUserId());
if (name != null) {
plugin = mClocks.get(name);
}
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;
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;
@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();
}
@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);
}
@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());
@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);
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();
}
@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.
@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.
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.