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

Commit 787a981e authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Add an extra for opting in to show the small icon

This allows special apps like with the PACKAGE_VERIFICATION_AGENT
permission to show the small icon if they want.

Fix: 433509926
Bug: 364325566
Flag: EXEMPT BUGFIX
Test: NotificationManagerServiceTest + CTS test

Change-Id: I94254fae6a728eba58009bd04a32a9f8ba4bf215
parent af8c054d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1077,6 +1077,7 @@ package android.app {
    field public static final String CATEGORY_CAR_WARNING = "car_warning";
    field @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup";
    field @FlaggedApi("android.app.hide_status_bar_notification") @RequiresPermission("android.Manifest.permission.HIDE_STATUS_BAR_NOTIFICATION") public static final String EXTRA_HIDE_STATUS_BAR_NOTIFICATION = "android.hideStatusBarNotification";
    field @RequiresPermission(android.Manifest.permission.PACKAGE_VERIFICATION_AGENT) public static final String EXTRA_PREFER_SMALL_ICON = "android.app.preferSmallIcon";
    field @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName";
    field public static final int FLAG_AUTOGROUP_SUMMARY = 1024; // 0x400
  }
+2 −0
Original line number Diff line number Diff line
@@ -1987,6 +1987,8 @@ UnflaggedApi: android.app.ActivityManager#getExternalHistoricalProcessStartReaso
    New API must be flagged with @FlaggedApi: method android.app.ActivityManager.getExternalHistoricalProcessStartReasons(String,int)
UnflaggedApi: android.app.AppOpsManager#OPSTR_RECEIVE_SANDBOX_TRIGGER_AUDIO:
    New API must be flagged with @FlaggedApi: field android.app.AppOpsManager.OPSTR_RECEIVE_SANDBOX_TRIGGER_AUDIO
UnflaggedApi: android.app.Notification#EXTRA_PREFER_SMALL_ICON:
    New API must be flagged with @FlaggedApi: field android.app.Notification.EXTRA_PREFER_SMALL_ICON
UnflaggedApi: android.companion.virtual.VirtualDeviceManager.VirtualDevice#getPersistentDeviceId():
    New API must be flagged with @FlaggedApi: method android.companion.virtual.VirtualDeviceManager.VirtualDevice.getPersistentDeviceId()
UnflaggedApi: android.content.Context#THREAD_NETWORK_SERVICE:
+9 −0
Original line number Diff line number Diff line
@@ -315,6 +315,15 @@ public class Notification implements Parcelable
     */
    public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft";
    /**
     * A boolean indicating that the notification card should show the small icon instead of the
     * launcher app icon.
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.PACKAGE_VERIFICATION_AGENT)
    public static final String EXTRA_PREFER_SMALL_ICON = "android.app.preferSmallIcon";
    /**
     * The call to WearableExtender#setBackground(Bitmap) will have no effect and the passed
     * Bitmap will not be retained in memory.
+7 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.row.icon

import android.annotation.WorkerThread
import android.app.Flags
import android.app.Notification
import android.content.Context
import android.content.pm.ApplicationInfo
import android.os.UserManager
@@ -73,10 +74,15 @@ constructor(
    override fun shouldShowAppIcon(notification: StatusBarNotification, context: Context): Boolean {
        return cache.getOrFetch(notification.packageName) {
            val packageContext = notification.getPackageContext(context)
            !prefersSmallIcon(notification.notification) &&
                !belongsToHeadlessSystemApp(packageContext)
        }
    }

    private fun prefersSmallIcon(notification: Notification): Boolean {
        return notification.extras.getBoolean(Notification.EXTRA_PREFER_SMALL_ICON)
    }

    @WorkerThread
    private fun belongsToHeadlessSystemApp(context: Context): Boolean {
        val info = context.applicationInfo
+13 −0
Original line number Diff line number Diff line
@@ -9072,6 +9072,19 @@ public class NotificationManagerService extends SystemService {
            }
        }
        if (notification.extras.getBoolean(Notification.EXTRA_PREFER_SMALL_ICON, false)) {
            int hasPackageVerifierAgentPerm = getContext().checkPermission(
                    Manifest.permission.PACKAGE_VERIFICATION_AGENT, -1, notificationUid);
            if (hasPackageVerifierAgentPerm != PERMISSION_GRANTED) {
                notification.extras.remove(Notification.EXTRA_PREFER_SMALL_ICON);
                if (DBG) {
                    Slog.w(TAG, "warning: pkg " + pkg + " attempting to show small icon"
                            + " without holding perm "
                            + Manifest.permission.PACKAGE_VERIFICATION_AGENT);
                }
            }
        }
        notification.flags &= ~FLAG_FSI_REQUESTED_BUT_DENIED;
        // Apps cannot post notifications that are lifetime extended.
Loading