From dfa968d4025330986d5161484f705deb67a4613a Mon Sep 17 00:00:00 2001 From: Gustav Sennton Date: Fri, 13 Sep 2019 12:00:50 +0100 Subject: [PATCH] SSIN: Use the application's context to load icon resources. SSIN = Smart Suggestions in Notifications. When posting a notification with contextual/smart actions app developers supply their own icons for their actions. These icons can reference resources from within the application package. Therefore we need to use a Context from that package to load icon resources. Before this CL we were using the SystemUi context which doesn't have access to the same resources as the app context - meaning we were not able to load the icon the app developer was providing us (unless they provided an Icon instance rather than just a resource ID for their icon). Bug: 137044913 Test: atest SmartReplyViewTest Test: manual - create a notification with a contextual action whose icon is referenced through a resource ID (not an Icon instance). Ensure the icon is shown correctly in the notification. Change-Id: Ia6d7b3689c46b65558437e00a947ba3cd330e4ca --- .../row/NotificationContentInflater.java | 15 ++++++++------- .../statusbar/policy/InflatedSmartReplies.java | 7 ++++--- .../statusbar/policy/SmartReplyView.java | 16 +++++++++------- .../statusbar/policy/SmartReplyViewTest.java | 4 +++- 4 files changed, 24 insertions(+), 18 deletions(-) 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 48a82957bf1ef..a612a1721c41f 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 @@ -264,7 +264,7 @@ public class NotificationContentInflater { mIsChildInGroup, mUsesIncreasedHeight, mUsesIncreasedHeadsUpHeight, packageContext); result = inflateSmartReplyViews(result, reInflateFlags, mRow.getEntry(), - mRow.getContext(), mRow.getHeadsUpManager(), + mRow.getContext(), packageContext, mRow.getHeadsUpManager(), mRow.getExistingSmartRepliesAndActions()); apply( inflateSynchronously, @@ -311,20 +311,21 @@ public class NotificationContentInflater { private static InflationProgress inflateSmartReplyViews(InflationProgress result, @InflationFlag int reInflateFlags, NotificationEntry entry, Context context, - HeadsUpManager headsUpManager, SmartRepliesAndActions previousSmartRepliesAndActions) { + Context packageContext, HeadsUpManager headsUpManager, + SmartRepliesAndActions previousSmartRepliesAndActions) { SmartReplyConstants smartReplyConstants = Dependency.get(SmartReplyConstants.class); SmartReplyController smartReplyController = Dependency.get(SmartReplyController.class); if ((reInflateFlags & FLAG_CONTENT_VIEW_EXPANDED) != 0 && result.newExpandedView != null) { result.expandedInflatedSmartReplies = InflatedSmartReplies.inflate( - context, entry, smartReplyConstants, smartReplyController, - headsUpManager, previousSmartRepliesAndActions); + context, packageContext, entry, smartReplyConstants, + smartReplyController, headsUpManager, previousSmartRepliesAndActions); } if ((reInflateFlags & FLAG_CONTENT_VIEW_HEADS_UP) != 0 && result.newHeadsUpView != null) { result.headsUpInflatedSmartReplies = InflatedSmartReplies.inflate( - context, entry, smartReplyConstants, smartReplyController, - headsUpManager, previousSmartRepliesAndActions); + context, packageContext, entry, smartReplyConstants, + smartReplyController, headsUpManager, previousSmartRepliesAndActions); } return result; } @@ -817,7 +818,7 @@ public class NotificationContentInflater { recoveredBuilder, mIsLowPriority, mIsChildInGroup, mUsesIncreasedHeight, mUsesIncreasedHeadsUpHeight, packageContext); return inflateSmartReplyViews(inflationProgress, mReInflateFlags, mRow.getEntry(), - mRow.getContext(), mRow.getHeadsUpManager(), + mRow.getContext(), packageContext, mRow.getHeadsUpManager(), mRow.getExistingSmartRepliesAndActions()); } catch (Exception e) { mError = e; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/InflatedSmartReplies.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/InflatedSmartReplies.java index ee78a723a49c6..ea93193ca7289 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/InflatedSmartReplies.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/InflatedSmartReplies.java @@ -80,6 +80,7 @@ public class InflatedSmartReplies { */ public static InflatedSmartReplies inflate( Context context, + Context packageContext, NotificationEntry entry, SmartReplyConstants smartReplyConstants, SmartReplyController smartReplyController, @@ -108,9 +109,9 @@ public class InflatedSmartReplies { } if (newSmartRepliesAndActions.smartActions != null) { suggestionButtons.addAll( - smartReplyView.inflateSmartActions(newSmartRepliesAndActions.smartActions, - smartReplyController, entry, headsUpManager, - delayOnClickListener)); + smartReplyView.inflateSmartActions(packageContext, + newSmartRepliesAndActions.smartActions, smartReplyController, entry, + headsUpManager, delayOnClickListener)); } return new InflatedSmartReplies(smartReplyView, suggestionButtons, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java index 282d28c3b20c3..ed0b9d9294660 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java @@ -235,17 +235,17 @@ public class SmartReplyView extends ViewGroup { * Add smart actions to be shown next to smart replies. Only the actions that fit into the * notification are shown. */ - public List