Loading packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +2 −47 Original line number Original line Diff line number Diff line Loading @@ -21,9 +21,6 @@ import static android.app.NotificationManager.INTERRUPTION_FILTER_ALARMS; import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL; import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL; import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE; import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE; import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY; import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY; import static android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN; import static android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD; import static android.appwidget.flags.Flags.generatedPreviews; import static android.content.Intent.ACTION_BOOT_COMPLETED; import static android.content.Intent.ACTION_BOOT_COMPLETED; import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; Loading Loading @@ -83,15 +80,12 @@ import android.service.notification.StatusBarNotification; import android.service.notification.ZenModeConfig; import android.service.notification.ZenModeConfig; import android.text.TextUtils; import android.text.TextUtils; import android.util.Log; import android.util.Log; import android.util.SparseBooleanArray; import android.widget.RemoteViews; import android.widget.RemoteViews; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLoggerImpl; import com.android.internal.logging.UiEventLoggerImpl; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.Dumpable; import com.android.systemui.Dumpable; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.SysUISingleton; Loading @@ -102,8 +96,6 @@ import com.android.systemui.people.PeopleBackupFollowUpJob; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.PeopleTileViewHelper; import com.android.systemui.people.PeopleTileViewHelper; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.res.R; import com.android.systemui.settings.UserTracker; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntry; Loading Loading @@ -168,27 +160,13 @@ public class PeopleSpaceWidgetManager implements Dumpable { @GuardedBy("mLock") @GuardedBy("mLock") public static Map<Integer, PeopleSpaceTile> mTiles = new HashMap<>(); public static Map<Integer, PeopleSpaceTile> mTiles = new HashMap<>(); @NonNull private final UserTracker mUserTracker; @NonNull private final SparseBooleanArray mUpdatedPreviews = new SparseBooleanArray(); @NonNull private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback = new KeyguardUpdateMonitorCallback() { @Override public void onUserUnlocked() { if (DEBUG) { Log.d(TAG, "onUserUnlocked " + mUserTracker.getUserId()); } updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); } }; @Inject @Inject public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps, public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps, CommonNotifCollection notifCollection, CommonNotifCollection notifCollection, PackageManager packageManager, Optional<Bubbles> bubblesOptional, PackageManager packageManager, Optional<Bubbles> bubblesOptional, UserManager userManager, NotificationManager notificationManager, UserManager userManager, NotificationManager notificationManager, BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor, BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor, DumpManager dumpManager, @NonNull UserTracker userTracker, DumpManager dumpManager) { @NonNull KeyguardUpdateMonitor keyguardUpdateMonitor) { if (DEBUG) Log.d(TAG, "constructor"); if (DEBUG) Log.d(TAG, "constructor"); mContext = context; mContext = context; mAppWidgetManager = AppWidgetManager.getInstance(context); mAppWidgetManager = AppWidgetManager.getInstance(context); Loading @@ -209,8 +187,6 @@ public class PeopleSpaceWidgetManager implements Dumpable { mBroadcastDispatcher = broadcastDispatcher; mBroadcastDispatcher = broadcastDispatcher; mBgExecutor = bgExecutor; mBgExecutor = bgExecutor; dumpManager.registerNormalDumpable(TAG, this); dumpManager.registerNormalDumpable(TAG, this); mUserTracker = userTracker; keyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback); } } /** Initializes {@PeopleSpaceWidgetManager}. */ /** Initializes {@PeopleSpaceWidgetManager}. */ Loading Loading @@ -270,7 +246,7 @@ public class PeopleSpaceWidgetManager implements Dumpable { CommonNotifCollection notifCollection, PackageManager packageManager, CommonNotifCollection notifCollection, PackageManager packageManager, Optional<Bubbles> bubblesOptional, UserManager userManager, BackupManager backupManager, Optional<Bubbles> bubblesOptional, UserManager userManager, BackupManager backupManager, INotificationManager iNotificationManager, NotificationManager notificationManager, INotificationManager iNotificationManager, NotificationManager notificationManager, @Background Executor executor, UserTracker userTracker) { @Background Executor executor) { mContext = context; mContext = context; mAppWidgetManager = appWidgetManager; mAppWidgetManager = appWidgetManager; mIPeopleManager = iPeopleManager; mIPeopleManager = iPeopleManager; Loading @@ -286,7 +262,6 @@ public class PeopleSpaceWidgetManager implements Dumpable { mManager = this; mManager = this; mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); mBgExecutor = executor; mBgExecutor = executor; mUserTracker = userTracker; } } /** /** Loading Loading @@ -1432,24 +1407,4 @@ public class PeopleSpaceWidgetManager implements Dumpable { Trace.traceEnd(Trace.TRACE_TAG_APP); Trace.traceEnd(Trace.TRACE_TAG_APP); } } @VisibleForTesting void updateGeneratedPreviewForUser(UserHandle user) { if (!generatedPreviews() || mUpdatedPreviews.get(user.getIdentifier()) || !mUserManager.isUserUnlocked(user)) { return; } if (DEBUG) { Log.d(TAG, "Updating People Space widget preview for user " + user.getIdentifier()); } boolean success = mAppWidgetManager.setWidgetPreview( new ComponentName(mContext, PeopleSpaceWidgetProvider.class), WIDGET_CATEGORY_HOME_SCREEN | WIDGET_CATEGORY_KEYGUARD, new RemoteViews(mContext.getPackageName(), R.layout.people_space_placeholder_layout)); if (DEBUG && !success) { Log.d(TAG, "Failed to update generated preview for user " + user.getIdentifier()); } mUpdatedPreviews.put(user.getIdentifier(), success); } } } packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +2 −42 Original line number Original line Diff line number Diff line Loading @@ -101,12 +101,11 @@ import android.text.TextUtils; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; import com.android.systemui.res.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase; import com.android.systemui.people.PeopleBackupFollowUpJob; import com.android.systemui.people.PeopleBackupFollowUpJob; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.res.R; import com.android.systemui.settings.FakeUserTracker; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.SbnBuilder; import com.android.systemui.statusbar.SbnBuilder; Loading Loading @@ -266,8 +265,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { private final FakeExecutor mFakeExecutor = new FakeExecutor(mClock); private final FakeExecutor mFakeExecutor = new FakeExecutor(mClock); private final FakeUserTracker mUserTracker = new FakeUserTracker(); @Before @Before public void setUp() throws Exception { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); Loading @@ -275,7 +272,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager, mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager, mPeopleManager, mLauncherApps, mNotifCollection, mPackageManager, mPeopleManager, mLauncherApps, mNotifCollection, mPackageManager, Optional.of(mBubbles), mUserManager, mBackupManager, mINotificationManager, Optional.of(mBubbles), mUserManager, mBackupManager, mINotificationManager, mNotificationManager, mFakeExecutor, mUserTracker); mNotificationManager, mFakeExecutor); mManager.attach(mListenerService); mManager.attach(mListenerService); verify(mListenerService).addNotificationHandler(mListenerCaptor.capture()); verify(mListenerService).addNotificationHandler(mListenerCaptor.capture()); Loading Loading @@ -1565,43 +1562,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { String.valueOf(WIDGET_ID_WITH_KEY_IN_OPTIONS)); String.valueOf(WIDGET_ID_WITH_KEY_IN_OPTIONS)); } } @Test public void testUpdateGeneratedPreview_flagDisabled() { mSetFlagsRule.disableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(0)).setWidgetPreview(any(), anyInt(), any()); } @Test public void testUpdateGeneratedPreview_userLocked() { mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(false); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(0)).setWidgetPreview(any(), anyInt(), any()); } @Test public void testUpdateGeneratedPreview_userUnlocked() { mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(true); when(mAppWidgetManager.setWidgetPreview(any(), anyInt(), any())).thenReturn(true); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(1)).setWidgetPreview(any(), anyInt(), any()); } @Test public void testUpdateGeneratedPreview_doesNotSetTwice() { mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(true); when(mAppWidgetManager.setWidgetPreview(any(), anyInt(), any())).thenReturn(true); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(1)).setWidgetPreview(any(), anyInt(), any()); } private void setFinalField(String fieldName, int value) { private void setFinalField(String fieldName, int value) { try { try { Field field = NotificationManager.Policy.class.getDeclaredField(fieldName); Field field = NotificationManager.Policy.class.getDeclaredField(fieldName); Loading Loading
packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +2 −47 Original line number Original line Diff line number Diff line Loading @@ -21,9 +21,6 @@ import static android.app.NotificationManager.INTERRUPTION_FILTER_ALARMS; import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL; import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL; import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE; import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE; import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY; import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY; import static android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN; import static android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD; import static android.appwidget.flags.Flags.generatedPreviews; import static android.content.Intent.ACTION_BOOT_COMPLETED; import static android.content.Intent.ACTION_BOOT_COMPLETED; import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; Loading Loading @@ -83,15 +80,12 @@ import android.service.notification.StatusBarNotification; import android.service.notification.ZenModeConfig; import android.service.notification.ZenModeConfig; import android.text.TextUtils; import android.text.TextUtils; import android.util.Log; import android.util.Log; import android.util.SparseBooleanArray; import android.widget.RemoteViews; import android.widget.RemoteViews; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLoggerImpl; import com.android.internal.logging.UiEventLoggerImpl; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.Dumpable; import com.android.systemui.Dumpable; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.SysUISingleton; Loading @@ -102,8 +96,6 @@ import com.android.systemui.people.PeopleBackupFollowUpJob; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.PeopleTileViewHelper; import com.android.systemui.people.PeopleTileViewHelper; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.res.R; import com.android.systemui.settings.UserTracker; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntry; Loading Loading @@ -168,27 +160,13 @@ public class PeopleSpaceWidgetManager implements Dumpable { @GuardedBy("mLock") @GuardedBy("mLock") public static Map<Integer, PeopleSpaceTile> mTiles = new HashMap<>(); public static Map<Integer, PeopleSpaceTile> mTiles = new HashMap<>(); @NonNull private final UserTracker mUserTracker; @NonNull private final SparseBooleanArray mUpdatedPreviews = new SparseBooleanArray(); @NonNull private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback = new KeyguardUpdateMonitorCallback() { @Override public void onUserUnlocked() { if (DEBUG) { Log.d(TAG, "onUserUnlocked " + mUserTracker.getUserId()); } updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); } }; @Inject @Inject public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps, public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps, CommonNotifCollection notifCollection, CommonNotifCollection notifCollection, PackageManager packageManager, Optional<Bubbles> bubblesOptional, PackageManager packageManager, Optional<Bubbles> bubblesOptional, UserManager userManager, NotificationManager notificationManager, UserManager userManager, NotificationManager notificationManager, BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor, BroadcastDispatcher broadcastDispatcher, @Background Executor bgExecutor, DumpManager dumpManager, @NonNull UserTracker userTracker, DumpManager dumpManager) { @NonNull KeyguardUpdateMonitor keyguardUpdateMonitor) { if (DEBUG) Log.d(TAG, "constructor"); if (DEBUG) Log.d(TAG, "constructor"); mContext = context; mContext = context; mAppWidgetManager = AppWidgetManager.getInstance(context); mAppWidgetManager = AppWidgetManager.getInstance(context); Loading @@ -209,8 +187,6 @@ public class PeopleSpaceWidgetManager implements Dumpable { mBroadcastDispatcher = broadcastDispatcher; mBroadcastDispatcher = broadcastDispatcher; mBgExecutor = bgExecutor; mBgExecutor = bgExecutor; dumpManager.registerNormalDumpable(TAG, this); dumpManager.registerNormalDumpable(TAG, this); mUserTracker = userTracker; keyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback); } } /** Initializes {@PeopleSpaceWidgetManager}. */ /** Initializes {@PeopleSpaceWidgetManager}. */ Loading Loading @@ -270,7 +246,7 @@ public class PeopleSpaceWidgetManager implements Dumpable { CommonNotifCollection notifCollection, PackageManager packageManager, CommonNotifCollection notifCollection, PackageManager packageManager, Optional<Bubbles> bubblesOptional, UserManager userManager, BackupManager backupManager, Optional<Bubbles> bubblesOptional, UserManager userManager, BackupManager backupManager, INotificationManager iNotificationManager, NotificationManager notificationManager, INotificationManager iNotificationManager, NotificationManager notificationManager, @Background Executor executor, UserTracker userTracker) { @Background Executor executor) { mContext = context; mContext = context; mAppWidgetManager = appWidgetManager; mAppWidgetManager = appWidgetManager; mIPeopleManager = iPeopleManager; mIPeopleManager = iPeopleManager; Loading @@ -286,7 +262,6 @@ public class PeopleSpaceWidgetManager implements Dumpable { mManager = this; mManager = this; mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); mBgExecutor = executor; mBgExecutor = executor; mUserTracker = userTracker; } } /** /** Loading Loading @@ -1432,24 +1407,4 @@ public class PeopleSpaceWidgetManager implements Dumpable { Trace.traceEnd(Trace.TRACE_TAG_APP); Trace.traceEnd(Trace.TRACE_TAG_APP); } } @VisibleForTesting void updateGeneratedPreviewForUser(UserHandle user) { if (!generatedPreviews() || mUpdatedPreviews.get(user.getIdentifier()) || !mUserManager.isUserUnlocked(user)) { return; } if (DEBUG) { Log.d(TAG, "Updating People Space widget preview for user " + user.getIdentifier()); } boolean success = mAppWidgetManager.setWidgetPreview( new ComponentName(mContext, PeopleSpaceWidgetProvider.class), WIDGET_CATEGORY_HOME_SCREEN | WIDGET_CATEGORY_KEYGUARD, new RemoteViews(mContext.getPackageName(), R.layout.people_space_placeholder_layout)); if (DEBUG && !success) { Log.d(TAG, "Failed to update generated preview for user " + user.getIdentifier()); } mUpdatedPreviews.put(user.getIdentifier(), success); } } }
packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +2 −42 Original line number Original line Diff line number Diff line Loading @@ -101,12 +101,11 @@ import android.text.TextUtils; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; import com.android.systemui.res.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase; import com.android.systemui.people.PeopleBackupFollowUpJob; import com.android.systemui.people.PeopleBackupFollowUpJob; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.PeopleSpaceUtils; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.people.SharedPreferencesHelper; import com.android.systemui.res.R; import com.android.systemui.settings.FakeUserTracker; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.SbnBuilder; import com.android.systemui.statusbar.SbnBuilder; Loading Loading @@ -266,8 +265,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { private final FakeExecutor mFakeExecutor = new FakeExecutor(mClock); private final FakeExecutor mFakeExecutor = new FakeExecutor(mClock); private final FakeUserTracker mUserTracker = new FakeUserTracker(); @Before @Before public void setUp() throws Exception { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); Loading @@ -275,7 +272,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager, mManager = new PeopleSpaceWidgetManager(mContext, mAppWidgetManager, mIPeopleManager, mPeopleManager, mLauncherApps, mNotifCollection, mPackageManager, mPeopleManager, mLauncherApps, mNotifCollection, mPackageManager, Optional.of(mBubbles), mUserManager, mBackupManager, mINotificationManager, Optional.of(mBubbles), mUserManager, mBackupManager, mINotificationManager, mNotificationManager, mFakeExecutor, mUserTracker); mNotificationManager, mFakeExecutor); mManager.attach(mListenerService); mManager.attach(mListenerService); verify(mListenerService).addNotificationHandler(mListenerCaptor.capture()); verify(mListenerService).addNotificationHandler(mListenerCaptor.capture()); Loading Loading @@ -1565,43 +1562,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { String.valueOf(WIDGET_ID_WITH_KEY_IN_OPTIONS)); String.valueOf(WIDGET_ID_WITH_KEY_IN_OPTIONS)); } } @Test public void testUpdateGeneratedPreview_flagDisabled() { mSetFlagsRule.disableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(0)).setWidgetPreview(any(), anyInt(), any()); } @Test public void testUpdateGeneratedPreview_userLocked() { mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(false); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(0)).setWidgetPreview(any(), anyInt(), any()); } @Test public void testUpdateGeneratedPreview_userUnlocked() { mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(true); when(mAppWidgetManager.setWidgetPreview(any(), anyInt(), any())).thenReturn(true); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(1)).setWidgetPreview(any(), anyInt(), any()); } @Test public void testUpdateGeneratedPreview_doesNotSetTwice() { mSetFlagsRule.enableFlags(android.appwidget.flags.Flags.FLAG_GENERATED_PREVIEWS); when(mUserManager.isUserUnlocked(mUserTracker.getUserHandle())).thenReturn(true); when(mAppWidgetManager.setWidgetPreview(any(), anyInt(), any())).thenReturn(true); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); mManager.updateGeneratedPreviewForUser(mUserTracker.getUserHandle()); verify(mAppWidgetManager, times(1)).setWidgetPreview(any(), anyInt(), any()); } private void setFinalField(String fieldName, int value) { private void setFinalField(String fieldName, int value) { try { try { Field field = NotificationManager.Policy.class.getDeclaredField(fieldName); Field field = NotificationManager.Policy.class.getDeclaredField(fieldName); Loading