From 2645b3ef8b5254ccf00661fcbf758071813c5767 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Tue, 16 Mar 2021 12:59:23 -0400 Subject: [PATCH] Fix notification colors on theme change. Causes: * The theme is implemented with RROs * RRO state is stored in the ApplicationInfo's overlayPaths * Notification.extras contains the ApplicationInfo from when the notification was posted The fix here is to fetch and inject the latest ApplicationInfo (using a method which has a correctly-invalidated cache) right before recovering the builder from the notification to bind content. Also, because this codepath is operating on the background thread, there are no SystemUI jank risks during the overlay change. Fixes: 182662365 Test: change theme; notifications change color Change-Id: Ibdfaf811155d64e0ecb7c70075e3ba4429c6d920 --- .../row/NotificationContentInflater.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java index fdd8f347c248a..58b87cd2f4927 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java @@ -27,8 +27,10 @@ import android.app.Notification; import android.content.Context; import android.content.ContextWrapper; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.os.AsyncTask; import android.os.CancellationSignal; +import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.util.Log; import android.view.View; @@ -768,10 +770,26 @@ public class NotificationContentInflater implements NotificationRowContentBinder return mReInflateFlags; } + void updateApplicationInfo(StatusBarNotification sbn) { + String packageName = sbn.getPackageName(); + int userId = UserHandle.getUserId(sbn.getUid()); + final ApplicationInfo appInfo; + try { + // This method has an internal cache, so we don't need to add our own caching here. + appInfo = mContext.getPackageManager().getApplicationInfoAsUser(packageName, + PackageManager.MATCH_UNINSTALLED_PACKAGES, userId); + } catch (PackageManager.NameNotFoundException e) { + return; + } + Notification.addFieldsFromContext(appInfo, sbn.getNotification()); + } + @Override protected InflationProgress doInBackground(Void... params) { try { final StatusBarNotification sbn = mEntry.getSbn(); + // Ensure the ApplicationInfo is updated before a builder is recovered. + updateApplicationInfo(sbn); final Notification.Builder recoveredBuilder = Notification.Builder.recoverBuilder(mContext, sbn.getNotification());