From ad1a153a63e883f25d4ce123f0743e28adbfcd32 Mon Sep 17 00:00:00 2001 From: Anna Zappone Date: Thu, 8 Apr 2021 18:10:59 +0100 Subject: [PATCH] Update user profiles on user unavailable Fix crash calling into ShortcutService when user 10 is locked. Change-Id: Id5c35a8af52b4645cbe0296d77b7beb6da50ebde Test: none Bug: 182575662 --- .../android/server/notification/ManagedServices.java | 11 +++++++++-- .../notification/NotificationManagerService.java | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java index c4a59c2655a25..73c71d2f51d5c 100644 --- a/services/core/java/com/android/server/notification/ManagedServices.java +++ b/services/core/java/com/android/server/notification/ManagedServices.java @@ -1770,10 +1770,17 @@ abstract public class ManagedServices { UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); if (userManager != null) { int currentUserId = ActivityManager.getCurrentUser(); - List profiles = userManager.getProfiles(currentUserId); + List unlockedProfiles = new ArrayList<>(); + for (UserInfo user : userManager.getProfiles(currentUserId)) { + // Dependencies throw if we call APIs on a locked user. Only include + // unlocked users. + if (userManager.isUserUnlocked(user.id)) { + unlockedProfiles.add(user); + } + } synchronized (mCurrentProfiles) { mCurrentProfiles.clear(); - for (UserInfo user : profiles) { + for (UserInfo user : unlockedProfiles) { mCurrentProfiles.put(user.id, user); } } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 2f4cbd558fb90..7792bc06edd59 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1695,6 +1695,8 @@ public class NotificationManagerService extends SystemService { } } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) { int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); + // Work profile user may now be locked. Refresh cache. + mUserProfiles.updateCache(context); if (userHandle >= 0) { cancelAllNotificationsInt(MY_UID, MY_PID, null, null, 0, 0, true, userHandle, REASON_PROFILE_TURNED_OFF, null);