Merge "Allow system apps to substitute a different app name in notifications." into nyc-dev am: 3af45bd
am: 73a694b
* commit '73a694b486b8b37d7e61e5ad53b3c9b139b783e9':
Allow system apps to substitute a different app name in notifications.
Change-Id: Id47615712e65e8a11edd68dcd729824c9c37c85a
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -3009,6 +3009,12 @@
|
||||
<permission android:name="android.permission.UPDATE_LOCK_TASK_PACKAGES"
|
||||
android:protectionLevel="signature|setup" />
|
||||
|
||||
<!-- @SystemApi Allows an application to replace the app name displayed alongside notifications
|
||||
in the N-release and later.
|
||||
@hide <p>Not for use by third-party applications.</p> -->
|
||||
<permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME"
|
||||
android:protectionLevel="signature|privileged" />
|
||||
|
||||
<application android:process="system"
|
||||
android:persistent="true"
|
||||
android:hasCode="false"
|
||||
|
||||
@@ -1579,7 +1579,11 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
row.setRemoteInputController(mRemoteInputController);
|
||||
row.setOnExpandClickListener(this);
|
||||
|
||||
// Get the app name
|
||||
// Get the app name.
|
||||
// Note that Notification.Builder#bindHeaderAppName has similar logic
|
||||
// but since this field is used in the guts, it must be accurate.
|
||||
// Therefore we will only show the application label, or, failing that, the
|
||||
// package name. No substitutions.
|
||||
final String pkg = sbn.getPackageName();
|
||||
String appname = pkg;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user