Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3af45bd2 authored by Daniel Sandler's avatar Daniel Sandler Committed by Android (Google) Code Review
Browse files

Merge "Allow system apps to substitute a different app name in notifications." into nyc-dev

parents cd8f2737 732bd6cb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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";
+39 −7
Original line number Diff line number Diff line
@@ -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());
        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);
                }
            }
            if (TextUtils.isEmpty(name)) {
                name = pm.getApplicationLabel(mContext.getApplicationInfo());
            }
            if (TextUtils.isEmpty(name)) {
                // still nothing?
                return null;
            }

            if (TextUtils.isEmpty(appName)) {
                return;
            return String.valueOf(name);
        }
            contentView.setTextViewText(R.id.app_name_text, appName);
        private void bindHeaderAppName(RemoteViews contentView) {
            contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName());
            contentView.setTextColor(R.id.app_name_text, resolveContrastColor());
        }

+6 −0
Original line number Diff line number Diff line
@@ -3008,6 +3008,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"
+5 −1
Original line number Diff line number Diff line
@@ -1575,7 +1575,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 {