From 4417aa08edffe695b2990b21b3dc2add1e5f6c9b Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 5 Jun 2023 16:21:03 -0400 Subject: [PATCH] Fix people widget crash The widgets manager is not direct boot aware, but notifications are. This code already updates all widgets when the user is unlocked, so updates will not be lost. Test: PeopleSpaceWidgetManagerTest Fixes: 237848569 Change-Id: I6a9a24dc8cef770b7bfefed78e0894a24d88a89a --- .../widget/PeopleSpaceWidgetManager.java | 10 +++++--- .../widget/PeopleSpaceWidgetManagerTest.java | 23 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) 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 18be0aa6580d0..8d3b7451c90b9 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -775,9 +775,13 @@ public class PeopleSpaceWidgetManager { NotificationChannel channel, int modificationType) { if (channel.isConversation()) { - updateWidgets(mAppWidgetManager.getAppWidgetIds( - new ComponentName(mContext, PeopleSpaceWidgetProvider.class) - )); + mBgExecutor.execute(() -> { + if (mUserManager.isUserUnlocked(user)) { + updateWidgets(mAppWidgetManager.getAppWidgetIds( + new ComponentName(mContext, PeopleSpaceWidgetProvider.class) + )); + } + }); } } }; 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 e0f27de1a6de6..e669d06970047 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 @@ -481,6 +481,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { int[] widgetIdsArray = {1}; when(mAppWidgetManager.getAppWidgetIds(any())).thenReturn(widgetIdsArray); + when(mUserManager.isUserUnlocked(any())).thenReturn(true); + NotificationChannel channel = new NotificationChannel(TEST_CHANNEL_ID, TEST_CHANNEL_NAME, IMPORTANCE_DEFAULT); channel.setConversationId(TEST_PARENT_CHANNEL_ID, TEST_CONVERSATION_ID); @@ -489,8 +491,25 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { UserHandle.getUserHandleForUid(0), channel, IMPORTANCE_HIGH); mClock.advanceTime(MIN_LINGER_DURATION); - verify(mAppWidgetManager, times(1)).updateAppWidget(anyInt(), - any()); + verify(mAppWidgetManager, times(1)).updateAppWidget(anyInt(), any()); + } + + @Test + public void testOnNotificationChannelModified_userLocked() { + int[] widgetIdsArray = {1}; + when(mAppWidgetManager.getAppWidgetIds(any())).thenReturn(widgetIdsArray); + + when(mUserManager.isUserUnlocked(any())).thenReturn(false); + + NotificationChannel channel = + new NotificationChannel(TEST_CHANNEL_ID, TEST_CHANNEL_NAME, IMPORTANCE_DEFAULT); + channel.setConversationId(TEST_PARENT_CHANNEL_ID, TEST_CONVERSATION_ID); + + mNoMan.issueChannelModification(TEST_PACKAGE_A, + UserHandle.getUserHandleForUid(0), channel, IMPORTANCE_HIGH); + mClock.advanceTime(MIN_LINGER_DURATION); + + verify(mAppWidgetManager, never()).updateAppWidget(anyInt(), any()); } @Test