From 012bc7bb9fa1d0731be7b094a3d0631e01b03fbe Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 11 Apr 2016 16:30:27 -0600 Subject: [PATCH] Fix notifications that are sent for USER_ALL. Also avoid creating a heavy LoadedApk object which will be cached around in the long-lived system process. Bug: 28116427 Change-Id: I1a5fc43e6d559a09088636b2fe4b5c76f08d3413 --- core/java/android/app/Notification.java | 13 ++++++++++--- .../notification/NotificationManagerService.java | 10 ++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 4bf1aa38fc135..784872cedaa24 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -1955,9 +1955,16 @@ public class Notification implements Parcelable * @hide */ public static void addFieldsFromContext(Context context, Notification notification) { - notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, - context.getApplicationInfo()); - notification.extras.putInt(EXTRA_ORIGINATING_USERID, context.getUserId()); + addFieldsFromContext(context.getApplicationInfo(), context.getUserId(), notification); + } + + /** + * @hide + */ + public static void addFieldsFromContext(ApplicationInfo ai, int userId, + Notification notification) { + notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); + notification.extras.putInt(EXTRA_ORIGINATING_USERID, userId); } @Override diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 3cd194b73a8df..2765578a7c3de 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2459,12 +2459,10 @@ public class NotificationManagerService extends SystemService { // Fix the notification as best we can. try { - if (!"android".equals(pkg) && !"system".equals(pkg)) { - Notification.addFieldsFromContext(getContext().createApplicationContext( - getContext().getPackageManager().getApplicationInfoAsUser( - pkg, PackageManager.MATCH_UNINSTALLED_PACKAGES, userId), - Context.CONTEXT_RESTRICTED), notification); - } + final ApplicationInfo ai = getContext().getPackageManager().getApplicationInfoAsUser( + pkg, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, + (userId == UserHandle.USER_ALL) ? UserHandle.USER_SYSTEM : userId); + Notification.addFieldsFromContext(ai, userId, notification); } catch (NameNotFoundException e) { Slog.e(TAG, "Cannot create a context for sending app", e); return;