From 706274f7ff9e1e7eb01f93ae80f7189de7fe6694 Mon Sep 17 00:00:00 2001 From: Dan Sandler Date: Thu, 30 Jul 2015 22:32:54 -0400 Subject: [PATCH 1/2] Make the RemoteViews context safe for Icons. Icon needs the RemoteViews' internal context to reflect not just the Resources of the originating application, but its package name as well. Bug: 22840771 Bug: 22852700 Change-Id: I1164cd38d99283982b00daadcf927c7cf63539b3 --- core/java/android/widget/RemoteViews.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index d1583136c4088..7ca3339479183 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -2746,6 +2746,10 @@ public class RemoteViews implements Parcelable, Filter { public Resources.Theme getTheme() { return contextForResources.getTheme(); } + @Override + public String getPackageName() { + return contextForResources.getPackageName(); + } }; LayoutInflater inflater = (LayoutInflater) From 4b67713709342dfa6d0059637aed49b457d2c62a Mon Sep 17 00:00:00 2001 From: Dan Sandler Date: Thu, 30 Jul 2015 22:33:12 -0400 Subject: [PATCH 2/2] Make DateTimeView more robust to weird contexts. In particular, some clients (*ahem* SystemUI) have been known to inflate RemoteViews with unusual derived contexts that may not have valid application contexts. DateTimeView can now resist this. Bug: 22852700 Change-Id: I5e91ae0e66859f5f5efd7b19c0ae6dfbc26bcc54 --- core/java/android/widget/DateTimeView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/DateTimeView.java b/core/java/android/widget/DateTimeView.java index dcb243760cd0c..d20b9244a4b2b 100644 --- a/core/java/android/widget/DateTimeView.java +++ b/core/java/android/widget/DateTimeView.java @@ -16,6 +16,7 @@ package android.widget; +import android.app.ActivityThread; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -259,7 +260,7 @@ public class DateTimeView extends TextView { static final Context getApplicationContextIfAvailable(Context context) { final Context ac = context.getApplicationContext(); - return ac != null ? ac : context; + return ac != null ? ac : ActivityThread.currentApplication().getApplicationContext(); } void register(Context context) {