summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2016-06-13 16:52:22 -0700
committerd34d <clark@cyngn.com>2016-06-14 16:34:04 -0700
commit9153396acb31fe956c3c7200c376ccbaeb6ce170 (patch)
tree8f4f34fadd69f96e527adf20c575ac6354b2ca2c /packages
parent5f8d3f813d6d580b060a783c8271b6cec3794d30 (diff)
downloadframeworks_base-9153396acb31fe956c3c7200c376ccbaeb6ce170.zip
frameworks_base-9153396acb31fe956c3c7200c376ccbaeb6ce170.tar.gz
frameworks_base-9153396acb31fe956c3c7200c376ccbaeb6ce170.tar.bz2
SysUI: Don't let rogue themes ruin notifications
If we encounter an exception when inflating a notification's views, and a theme is applied, we should make a second attempt at inflating the notification without a theme applied in case the theme cause the issue. If the exception still occurs, we treat it like we normally do and allow the app to be killed for posting a bad notification. Change-Id: I444cf6c78ee43e2978201880957c53eb08e6966d TICKET: CYNGNOS-2892
Diffstat (limited to 'packages')
-rwxr-xr-xpackages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java48
1 files changed, 43 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index 26dc7ac..e958ee1 100755
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -1296,6 +1296,20 @@ public abstract class BaseStatusBar extends SystemUI implements
}
protected boolean inflateViews(Entry entry, ViewGroup parent) {
+ final StatusBarNotification sbn = entry.notification;
+ String themePackageName = mCurrentTheme != null
+ ? mCurrentTheme.getOverlayPkgNameForApp(sbn.getPackageName()) : null;
+ boolean inflated = inflateViews(entry, parent, true);
+ if (!inflated && themePackageName != null
+ && !ThemeConfig.SYSTEM_DEFAULT.equals(themePackageName)) {
+ Log.w(TAG, "Couldn't expand themed RemoteViews, trying unthemed for: " + sbn);
+ inflated = inflateViews(entry, mStackScroller, false);
+ }
+
+ return inflated;
+ }
+
+ protected boolean inflateViews(Entry entry, ViewGroup parent, boolean isThemeable) {
PackageManager pmUser = getPackageManagerForUser(
entry.notification.getUser().getIdentifier());
@@ -1372,10 +1386,12 @@ public abstract class BaseStatusBar extends SystemUI implements
View contentViewLocal = null;
View bigContentViewLocal = null;
View headsUpContentViewLocal = null;
- String themePackageName = mCurrentTheme != null
- ? mCurrentTheme.getOverlayPkgNameForApp(sbn.getPackageName()) : null;
- String statusBarThemePackageName = mCurrentTheme != null
- ? mCurrentTheme.getOverlayForStatusBar() : null;
+ String themePackageName = (isThemeable && mCurrentTheme != null)
+ ? mCurrentTheme.getOverlayPkgNameForApp(sbn.getPackageName())
+ : ThemeConfig.SYSTEM_DEFAULT;
+ String statusBarThemePackageName = (isThemeable && mCurrentTheme != null)
+ ? mCurrentTheme.getOverlayForStatusBar()
+ : ThemeConfig.SYSTEM_DEFAULT;
try {
contentViewLocal = contentView.apply(
@@ -1466,8 +1482,10 @@ public abstract class BaseStatusBar extends SystemUI implements
}
if (publicViewLocal == null) {
+ final Context layoutContext = isThemeable ? mContext
+ : maybeGetThemedContext(mContext, ThemeConfig.SYSTEM_DEFAULT);
// Add a basic notification template
- publicViewLocal = LayoutInflater.from(mContext).inflate(
+ publicViewLocal = LayoutInflater.from(layoutContext).inflate(
R.layout.notification_public_default,
contentContainerPublic, false);
publicViewLocal.setIsRootNamespace(true);
@@ -2324,4 +2342,24 @@ public abstract class BaseStatusBar extends SystemUI implements
mAssistManager.startAssist(args);
}
}
+
+ /**
+ * Returns a context with the given theme applied or the original context if we fail to get a
+ * themed context.
+ */
+ private Context maybeGetThemedContext(Context context, String themePkg) {
+ Context themedContext;
+ try {
+ ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
+ context.getPackageName(), 0);
+ themedContext = context.createApplicationContext(ai, themePkg,
+ 0);
+ } catch (PackageManager.NameNotFoundException e) {
+ themedContext = null;
+ }
+ if (themedContext == null) {
+ themedContext = context;
+ }
+ return themedContext;
+ }
}