diff options
| author | 2021-05-05 21:08:58 +0000 | |
|---|---|---|
| committer | 2021-05-06 16:32:06 +0100 | |
| commit | 5ffc60dfbe6e51ab93d934b47e059352319dc337 (patch) | |
| tree | 8b108d1bcb76f343c605ffd7cff58d9c1fd79b02 | |
| parent | 19943bde4bc6dce8afb8e17ce615e473a503f031 (diff) | |
Store PeopleSpaceTile in-memory
Bug: 187306509
Test: PeopleSpaceWidgetManagerTest
Change-Id: Ib15ba0b134fe13d359455cc5aaf2608a99469568
5 files changed, 45 insertions, 224 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/AppWidgetOptionsHelper.java b/packages/SystemUI/src/com/android/systemui/people/widget/AppWidgetOptionsHelper.java index 73c43ebfdaf0..b49533eed219 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/AppWidgetOptionsHelper.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/AppWidgetOptionsHelper.java @@ -16,7 +16,6 @@ package com.android.systemui.people.widget; -import static com.android.systemui.people.PeopleSpaceUtils.DEBUG; import static com.android.systemui.people.PeopleSpaceUtils.EMPTY_KEY; import static com.android.systemui.people.PeopleSpaceUtils.EMPTY_STRING; import static com.android.systemui.people.PeopleSpaceUtils.INVALID_USER_ID; @@ -24,38 +23,13 @@ import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME; import static com.android.systemui.people.PeopleSpaceUtils.SHORTCUT_ID; import static com.android.systemui.people.PeopleSpaceUtils.USER_ID; -import android.app.people.PeopleSpaceTile; import android.appwidget.AppWidgetManager; import android.os.Bundle; -import android.util.Log; /** Helper class encapsulating AppWidgetOptions for People Tile. */ public class AppWidgetOptionsHelper { private static final String TAG = "AppWidgetOptionsHelper"; - /** Key to store {@link PeopleSpaceTile} in AppWidgetOptions Bundle. */ - public static final String OPTIONS_PEOPLE_TILE = "options_people_tile"; - - /** Sets {@link PeopleSpaceTile} in AppWidgetOptions. */ - public static Bundle setPeopleTile(AppWidgetManager appWidgetManager, int appWidgetId, - PeopleSpaceTile tile) { - Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); - if (tile == null) { - if (DEBUG) Log.w(TAG, "Requested to store null tile"); - return options; - } - options.putParcelable(OPTIONS_PEOPLE_TILE, tile); - appWidgetManager.updateAppWidgetOptions(appWidgetId, options); - return options; - } - - /** Gets {@link PeopleSpaceTile} from AppWidgetOptions. */ - public static PeopleSpaceTile getPeopleTile(AppWidgetManager appWidgetManager, - int appWidgetId) { - Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); - return options != null ? options.getParcelable(OPTIONS_PEOPLE_TILE) : null; - } - /** Sets {@link PeopleTileKey} in AppWidgetOptions. */ public static void setPeopleTileKey(AppWidgetManager appWidgetManager, int appWidgetId, PeopleTileKey key) { @@ -66,16 +40,6 @@ public class AppWidgetOptionsHelper { appWidgetManager.updateAppWidgetOptions(appWidgetId, options); } - /** Gets {@link PeopleTileKey} from AppWidgetOptions. */ - public static PeopleTileKey getPeopleTileKey(AppWidgetManager appWidgetManager, - int appWidgetId) { - Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); - if (options == null) { - return EMPTY_KEY; - } - return getPeopleTileKeyFromBundle(options); - } - /** Gets {@link PeopleTileKey} from Bundle {@code options}. */ public static PeopleTileKey getPeopleTileKeyFromBundle(Bundle options) { String pkg = options.getString(PACKAGE_NAME, EMPTY_STRING); diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java index ea1724f96669..9e0dd72e77f5 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -136,6 +136,9 @@ public class PeopleSpaceWidgetManager { private Map<String, Set<String>> mNotificationKeyToWidgetIdsMatchedByUri = new HashMap<>(); private boolean mRegisteredReceivers; + @GuardedBy("mLock") + public static Map<Integer, PeopleSpaceTile> mTiles = new HashMap<>(); + @Inject public PeopleSpaceWidgetManager(Context context, LauncherApps launcherApps, NotificationEntryManager notificationEntryManager, @@ -252,8 +255,7 @@ public class PeopleSpaceWidgetManager { if (tile == null) { Log.e(TAG, "Matching conversation not found for shortcut ID"); } - Bundle options = mAppWidgetManager.getAppWidgetOptions(appWidgetId); - updateAppWidgetViews(appWidgetId, tile, options); + updateAppWidgetOptionsAndView(appWidgetId, tile); widgetIdToTile.put(appWidgetId, tile); if (tile != null) { registerConversationListenerIfNeeded(appWidgetId, @@ -289,7 +291,14 @@ public class PeopleSpaceWidgetManager { /** Updates tile in app widget options and the current view. */ public void updateAppWidgetOptionsAndView(int appWidgetId, PeopleSpaceTile tile) { - Bundle options = AppWidgetOptionsHelper.setPeopleTile(mAppWidgetManager, appWidgetId, tile); + if (tile == null) { + if (DEBUG) Log.w(TAG, "Requested to store null tile"); + return; + } + synchronized (mTiles) { + mTiles.put(appWidgetId, tile); + } + Bundle options = mAppWidgetManager.getAppWidgetOptions(appWidgetId); updateAppWidgetViews(appWidgetId, tile, options); } @@ -299,8 +308,11 @@ public class PeopleSpaceWidgetManager { */ @Nullable public PeopleSpaceTile getTileForExistingWidget(int appWidgetId) { - // First, check if tile is cached in AppWidgetOptions. - PeopleSpaceTile tile = AppWidgetOptionsHelper.getPeopleTile(mAppWidgetManager, appWidgetId); + // First, check if tile is cached in memory. + PeopleSpaceTile tile; + synchronized (mTiles) { + tile = mTiles.get(appWidgetId); + } if (tile != null) { if (DEBUG) Log.d(TAG, "People Tile is cached for widget: " + appWidgetId); return tile; @@ -781,7 +793,6 @@ public class PeopleSpaceWidgetManager { } catch (Exception e) { Log.w(TAG, "Exception caching shortcut:" + e); } - updateAppWidgetOptionsAndView(appWidgetId, tile); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java index 0dd1f6816787..8983ff8dd30f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java @@ -17,7 +17,6 @@ package com.android.systemui.people; import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME; -import static com.android.systemui.people.widget.AppWidgetOptionsHelper.OPTIONS_PEOPLE_TILE; import static com.google.common.truth.Truth.assertThat; @@ -200,7 +199,6 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT, WIDGET_ID_WITHOUT_SHORTCUT}; mOptions = new Bundle(); - mOptions.putParcelable(OPTIONS_PEOPLE_TILE, PERSON_TILE); when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); when(mAppWidgetManager.getAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT))) diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java index 228e5e8d481d..5c70a4ef2076 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java @@ -29,7 +29,6 @@ import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH; import static com.android.systemui.people.PeopleSpaceUtils.STARRED_CONTACT; import static com.android.systemui.people.PeopleSpaceUtils.VALID_CONTACT; -import static com.android.systemui.people.widget.AppWidgetOptionsHelper.OPTIONS_PEOPLE_TILE; import static com.google.common.truth.Truth.assertThat; @@ -140,7 +139,6 @@ public class PeopleTileViewHelperTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); mOptions = new Bundle(); - mOptions.putParcelable(OPTIONS_PEOPLE_TILE, PERSON_TILE); when(mMockContext.getString(R.string.birthday_status)).thenReturn( mContext.getString(R.string.birthday_status)); diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java index f31f326c0c45..f2cae3c37e39 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java @@ -51,7 +51,6 @@ import static com.android.systemui.people.PeopleSpaceUtils.EMPTY_STRING; import static com.android.systemui.people.PeopleSpaceUtils.INVALID_USER_ID; import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME; import static com.android.systemui.people.PeopleSpaceUtils.USER_ID; -import static com.android.systemui.people.widget.AppWidgetOptionsHelper.OPTIONS_PEOPLE_TILE; import static com.google.common.truth.Truth.assertThat; @@ -474,8 +473,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, never()) - .updateAppWidgetOptions(anyInt(), any()); verify(mAppWidgetManager, never()).updateAppWidget(anyInt(), any()); } @@ -495,8 +492,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, never()) - .updateAppWidgetOptions(anyInt(), any()); verify(mAppWidgetManager, never()).updateAppWidget(anyInt(), any()); } @@ -515,8 +510,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1b = mNoMan.retractNotif(notif1.sbn, 0); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, never()) - .updateAppWidgetOptions(anyInt(), any()); verify(mAppWidgetManager, never()).updateAppWidget(anyInt(), any()); } @@ -538,8 +531,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1b = mNoMan.retractNotif(notif1.sbn, 0); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, never()) - .updateAppWidgetOptions(anyInt(), any()); verify(mAppWidgetManager, never()).updateAppWidget(anyInt(), any()); } @@ -559,8 +550,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsWithConversationChanged(conversationChannel); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, never()) - .updateAppWidgetOptions(anyInt(), any()); verify(mAppWidgetManager, never()).updateAppWidget(anyInt(), any()); } @@ -578,11 +567,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsWithConversationChanged(conversationChannel); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getStatuses()).containsExactly(status); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); @@ -599,14 +584,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsWithConversationChanged(conversationChannel); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - any()); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(SECOND_WIDGET_ID_WITH_SHORTCUT), - any()); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(SECOND_WIDGET_ID_WITH_SHORTCUT), any()); } @@ -626,11 +605,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1 = mNoMan.postNotif(builder); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tile.getNotificationContent()).isEqualTo(NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), @@ -647,14 +622,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - any()); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(SECOND_WIDGET_ID_WITH_SHORTCUT), - any()); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(SECOND_WIDGET_ID_WITH_SHORTCUT), any()); } @@ -672,14 +641,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - any()); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); - verify(mAppWidgetManager, never()) - .updateAppWidgetOptions(eq(SECOND_WIDGET_ID_WITH_SHORTCUT), - any()); verify(mAppWidgetManager, never()).updateAppWidget(eq(SECOND_WIDGET_ID_WITH_SHORTCUT), any()); } @@ -700,12 +663,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1 = mNoMan.postNotif(builder); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); - - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tile.getNotificationContent()) .isEqualTo(mContext.getString(R.string.missed_call)); @@ -729,12 +687,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1 = mNoMan.postNotif(builder); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); - - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tile.getNotificationContent()).isEqualTo(NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), @@ -758,21 +711,13 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1 = mNoMan.postNotif(builder); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithMissedCallOrigin = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithMissedCallOrigin = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tileWithMissedCallOrigin.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tileWithMissedCallOrigin.getNotificationContent()).isEqualTo( NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SAME_URI), - mBundleArgumentCaptor.capture()); - Bundle bundleForSameUriTile = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithSameUri = bundleForSameUriTile.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithSameUri = mManager.mTiles.get(WIDGET_ID_WITH_SAME_URI); assertThat(tileWithSameUri.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tileWithSameUri.getNotificationContent()).isEqualTo(NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SAME_URI), @@ -801,19 +746,12 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1b = mNoMan.retractNotif(notif1.sbn.cloneLight(), 0); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(2)).updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - PeopleSpaceTile tileWithMissedCallOrigin = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithMissedCallOrigin = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tileWithMissedCallOrigin.getNotificationKey()).isEqualTo(null); assertThat(tileWithMissedCallOrigin.getNotificationContent()).isEqualTo(null); verify(mAppWidgetManager, times(2)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); - verify(mAppWidgetManager, times(2)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SAME_URI), - mBundleArgumentCaptor.capture()); - Bundle bundleForSameUriTile = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithSameUri = bundleForSameUriTile.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithSameUri = mManager.mTiles.get(WIDGET_ID_WITH_SAME_URI); assertThat(tileWithSameUri.getNotificationKey()).isEqualTo(null); assertThat(tileWithSameUri.getNotificationContent()).isEqualTo(null); verify(mAppWidgetManager, times(2)).updateAppWidget(eq(WIDGET_ID_WITH_SAME_URI), @@ -847,21 +785,13 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1 = mNoMan.postNotif(builder); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithMissedCallOrigin = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithMissedCallOrigin = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tileWithMissedCallOrigin.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tileWithMissedCallOrigin.getNotificationContent()).isEqualTo( NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SAME_URI), - mBundleArgumentCaptor.capture()); - Bundle bundleForSameUriTile = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithSameUri = bundleForSameUriTile.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithSameUri = mManager.mTiles.get(WIDGET_ID_WITH_SAME_URI); assertThat(tileWithSameUri.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tileWithSameUri.getNotificationContent()).isEqualTo(NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SAME_URI), @@ -900,20 +830,13 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithMissedCallOrigin = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithMissedCallOrigin = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tileWithMissedCallOrigin.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tileWithMissedCallOrigin.getNotificationContent()).isEqualTo( NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); // Do not update since notification doesn't include a Person reference. - verify(mAppWidgetManager, times(0)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SAME_URI), - any()); verify(mAppWidgetManager, times(0)).updateAppWidget(eq(WIDGET_ID_WITH_SAME_URI), any()); } @@ -939,20 +862,13 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1 = mNoMan.postNotif(builder); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithMissedCallOrigin = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithMissedCallOrigin = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tileWithMissedCallOrigin.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tileWithMissedCallOrigin.getNotificationContent()).isEqualTo( NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); // Do not update since missing permission to read contacts. - verify(mAppWidgetManager, times(0)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_DIFFERENT_URI), - any()); verify(mAppWidgetManager, times(0)).updateAppWidget(eq(WIDGET_ID_WITH_DIFFERENT_URI), any()); } @@ -977,23 +893,14 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1 = mNoMan.postNotif(builder); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileWithMissedCallOrigin = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileWithMissedCallOrigin = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tileWithMissedCallOrigin.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tileWithMissedCallOrigin.getNotificationContent()).isEqualTo( NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); // Do not update since missing permission to read contacts. - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SAME_URI), - mBundleArgumentCaptor.capture()); - Bundle noNotificationBundle = requireNonNull(mBundleArgumentCaptor.getValue()); - PeopleSpaceTile tileNoNotification = - noNotificationBundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tileNoNotification = mManager.mTiles.get(WIDGET_ID_WITH_SAME_URI); assertThat(tileNoNotification.getNotificationKey()).isNull(); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SAME_URI), any()); @@ -1013,10 +920,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { NotifEvent notif1b = mNoMan.retractNotif(notif1.sbn, 0); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(2)).updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(null); assertThat(tile.getNotificationContent()).isEqualTo(null); assertThat(tile.getNotificationDataUri()).isEqualTo(null); @@ -1131,7 +1035,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { @Test public void testOnAppWidgetOptionsChangedNoWidgetAdded() { Bundle newOptions = new Bundle(); - newOptions.putParcelable(OPTIONS_PEOPLE_TILE, PERSON_TILE); mManager.onAppWidgetOptionsChanged(SECOND_WIDGET_ID_WITH_SHORTCUT, newOptions); @@ -1166,10 +1069,9 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.onAppWidgetOptionsChanged(SECOND_WIDGET_ID_WITH_SHORTCUT, newOptions); - verify(mAppWidgetManager, times(2)).updateAppWidgetOptions( + verify(mAppWidgetManager, times(1)).updateAppWidgetOptions( eq(SECOND_WIDGET_ID_WITH_SHORTCUT), mBundleArgumentCaptor.capture()); - List<Bundle> bundles = mBundleArgumentCaptor.getAllValues(); - Bundle first = bundles.get(0); + Bundle first = mBundleArgumentCaptor.getValue(); assertThat(first.getString(PeopleSpaceUtils.SHORTCUT_ID, EMPTY_STRING)) .isEqualTo(EMPTY_STRING); assertThat(first.getInt(USER_ID, INVALID_USER_ID)).isEqualTo(INVALID_USER_ID); @@ -1177,21 +1079,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { verify(mLauncherApps, times(1)).cacheShortcuts(eq(TEST_PACKAGE_A), eq(Arrays.asList(SHORTCUT_ID)), eq(UserHandle.of(0)), eq(LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS)); - - Bundle second = bundles.get(1); - PeopleSpaceTile tile = second.getParcelable(OPTIONS_PEOPLE_TILE); - assertThat(tile.getId()).isEqualTo(SHORTCUT_ID); - - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - assertThat(sp.getStringSet(KEY.toString(), new HashSet<>())).contains( - String.valueOf(SECOND_WIDGET_ID_WITH_SHORTCUT)); - SharedPreferences widgetSp = mContext.getSharedPreferences( - String.valueOf(SECOND_WIDGET_ID_WITH_SHORTCUT), - Context.MODE_PRIVATE); - assertThat(widgetSp.getString(PACKAGE_NAME, EMPTY_STRING)).isEqualTo(TEST_PACKAGE_A); - assertThat(widgetSp.getString(PeopleSpaceUtils.SHORTCUT_ID, EMPTY_STRING)) - .isEqualTo(SHORTCUT_ID); - assertThat(widgetSp.getInt(USER_ID, INVALID_USER_ID)).isEqualTo(0); } @Test @@ -1306,11 +1193,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { public void testUpdateWidgetsOnStateChange() { mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.isPackageSuspended()).isFalse(); assertThat(tile.isUserQuieted()).isFalse(); assertThat(tile.canBypassDnd()).isFalse(); @@ -1325,11 +1208,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.isPackageSuspended()).isFalse(); assertThat(tile.isUserQuieted()).isTrue(); assertThat(tile.getNotificationPolicyState()).isEqualTo(SHOW_CONVERSATIONS); @@ -1341,11 +1220,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(ACTION_PACKAGES_SUSPENDED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - Bundle bundle = mBundleArgumentCaptor.getValue(); - PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.isPackageSuspended()).isTrue(); assertThat(tile.isUserQuieted()).isFalse(); assertThat(tile.getNotificationPolicyState()).isEqualTo(SHOW_CONVERSATIONS); @@ -1357,10 +1232,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(NotificationManager .ACTION_INTERRUPTION_FILTER_CHANGED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_CONVERSATIONS); } @@ -1375,10 +1247,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(NotificationManager .ACTION_INTERRUPTION_FILTER_CHANGED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_CONVERSATIONS); } @@ -1394,10 +1263,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(NotificationManager .ACTION_INTERRUPTION_FILTER_CHANGED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo( expected | SHOW_IMPORTANT_CONVERSATIONS); } @@ -1412,10 +1278,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(NotificationManager .ACTION_INTERRUPTION_FILTER_CHANGED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | BLOCK_CONVERSATIONS); } @@ -1430,10 +1293,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_CONTACTS); } @@ -1448,10 +1308,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_STARRED_CONTACTS); } @@ -1464,10 +1321,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(NotificationManager .ACTION_INTERRUPTION_FILTER_CHANGED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | BLOCK_CONVERSATIONS); } @@ -1482,10 +1336,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { mManager.updateWidgetsOnStateChange(ACTION_BOOT_COMPLETED); - verify(mAppWidgetManager, times(1)) - .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), - mBundleArgumentCaptor.capture()); - PeopleSpaceTile tile = mBundleArgumentCaptor.getValue().getParcelable(OPTIONS_PEOPLE_TILE); + PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationPolicyState()).isEqualTo(expected | SHOW_CONVERSATIONS); } @@ -1513,7 +1364,6 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { private void addTileForWidget(PeopleSpaceTile tile, int widgetId) throws Exception { setStorageForTile(tile.getId(), tile.getPackageName(), widgetId, tile.getContactUri()); Bundle options = new Bundle(); - options.putParcelable(OPTIONS_PEOPLE_TILE, tile); ConversationChannel channel = getConversationWithShortcutId(new PeopleTileKey(tile)); when(mAppWidgetManager.getAppWidgetOptions(eq(widgetId))) .thenReturn(options); |