From 732bd6cb2736c9ae091f2b5b136570fc5d579224 Mon Sep 17 00:00:00 2001 From: Dan Sandler Date: Tue, 12 Apr 2016 14:20:32 -0400 Subject: [PATCH] Allow system apps to substitute a different app name in notifications. This is a privileged permission and is only to be used by the core OS and related packages whose names are confusing or misleading when shown in notifications. The user will always be able to see the true package name by accessing the notification inspector (longpress or swipe gesture on the notification row in SystemUI). Fixes: 26517701 Change-Id: I2b021c9da0757b99df76399666af263668d88070 --- api/system-current.txt | 1 + core/java/android/app/Notification.java | 46 ++++++++++++++++--- core/res/AndroidManifest.xml | 6 +++ .../systemui/statusbar/BaseStatusBar.java | 6 ++- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 7779f0b5581c4..9a39b4cd74c25 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -217,6 +217,7 @@ package android { field public static final java.lang.String SIGNAL_PERSISTENT_PROCESSES = "android.permission.SIGNAL_PERSISTENT_PROCESSES"; field public static final java.lang.String STATUS_BAR = "android.permission.STATUS_BAR"; field public static final java.lang.String STOP_APP_SWITCHES = "android.permission.STOP_APP_SWITCHES"; + field public static final java.lang.String SUBSTITUTE_NOTIFICATION_APP_NAME = "android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME"; field public static final java.lang.String SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW"; field public static final java.lang.String TETHER_PRIVILEGED = "android.permission.TETHER_PRIVILEGED"; field public static final java.lang.String TRANSMIT_IR = "android.permission.TRANSMIT_IR"; diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 052874f77ce67..bf72d7be263a8 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -25,6 +25,8 @@ import android.annotation.SystemApi; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.ColorStateList; import android.graphics.Bitmap; @@ -960,6 +962,12 @@ public class Notification implements Parcelable */ public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; + /** + * @SystemApi + * @hide + */ + public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; + private Icon mSmallIcon; private Icon mLargeIcon; @@ -3269,14 +3277,38 @@ public class Notification implements Parcelable } } - private void bindHeaderAppName(RemoteViews contentView) { - CharSequence appName = mContext.getPackageManager() - .getApplicationLabel(mContext.getApplicationInfo()); - - if (TextUtils.isEmpty(appName)) { - return; + private String loadHeaderAppName() { + CharSequence name = null; + final PackageManager pm = mContext.getPackageManager(); + if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { + // only system packages which lump together a bunch of unrelated stuff + // may substitute a different name to make the purpose of the + // notification more clear. the correct package label should always + // be accessible via SystemUI. + final String pkg = mContext.getPackageName(); + final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); + if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { + name = subName; + } else { + Log.w(TAG, "warning: pkg " + + pkg + " attempting to substitute app name '" + subName + + "' without holding perm " + + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); + } } - contentView.setTextViewText(R.id.app_name_text, appName); + if (TextUtils.isEmpty(name)) { + name = pm.getApplicationLabel(mContext.getApplicationInfo()); + } + if (TextUtils.isEmpty(name)) { + // still nothing? + return null; + } + + return String.valueOf(name); + } + private void bindHeaderAppName(RemoteViews contentView) { + contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); contentView.setTextColor(R.id.app_name_text, resolveContrastColor()); } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 778f797614415..1ed93ccfc34b4 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -3008,6 +3008,12 @@ + + +