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

Commit 47fd15fa authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Require a permission for Q apps using full screen intents

Test: cts
Bug: 119489430
Change-Id: I812669bb53fe8ddf501760fea22fd88175e49a01
parent 8ce7d1d9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ package android {
    field public static final java.lang.String UPDATE_DEVICE_STATS = "android.permission.UPDATE_DEVICE_STATS";
    field public static final java.lang.String USE_BIOMETRIC = "android.permission.USE_BIOMETRIC";
    field public static final deprecated java.lang.String USE_FINGERPRINT = "android.permission.USE_FINGERPRINT";
    field public static final java.lang.String USE_FULL_SCREEN_INTENT = "android.permission.USE_FULL_SCREEN_INTENT";
    field public static final java.lang.String USE_SIP = "android.permission.USE_SIP";
    field public static final java.lang.String VIBRATE = "android.permission.VIBRATE";
    field public static final java.lang.String WAKE_LOCK = "android.permission.WAKE_LOCK";
+3 −0
Original line number Diff line number Diff line
@@ -3848,6 +3848,9 @@ public class Notification implements Parcelable
         * The system UI may choose to display a heads-up notification, instead of
         * launching this intent, while the user is using the device.
         * </p>
         * <p>Apps targeting {@link Build.VERSION_CODES#Q} and above will have to request
         * a permission ({@link android.Manifest.permission#USE_FULL_SCREEN_INTENT}) in order to
         * use full screen intents.</p>
         *
         * @param intent The pending intent to launch.
         * @param highPriority Passing true will cause this notification to be sent
+6 −0
Original line number Diff line number Diff line
@@ -4206,6 +4206,12 @@
    <permission android:name="android.permission.SMS_FINANCIAL_TRANSACTIONS"
        android:protectionLevel="signature|appop" />

    <!-- Required for apps targeting {@link android.os.Build.VERSION_CODES#P} that want to use
         {@link android.app.Notification.Builder#setFullScreenIntent notification full screen
         intents}.  -->
    <permission android:name="android.permission.USE_FULL_SCREEN_INTENT"
                android:protectionLevel="normal" />

    <!-- @SystemApi Allows requesting the framework broadcast the
         {@link Intent#ACTION_DEVICE_CUSTOMIZATION_READY} intent.
         @hide -->
+28 −12
Original line number Diff line number Diff line
@@ -4247,18 +4247,7 @@ public class NotificationManagerService extends SystemService {

        // Fix the notification as best we can.
        try {
            final ApplicationInfo ai = mPackageManagerClient.getApplicationInfoAsUser(
                    pkg, PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                    (userId == UserHandle.USER_ALL) ? USER_SYSTEM : userId);
            Notification.addFieldsFromContext(ai, notification);

            int canColorize = mPackageManagerClient.checkPermission(
                    android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, pkg);
            if (canColorize == PERMISSION_GRANTED) {
                notification.flags |= Notification.FLAG_CAN_COLORIZE;
            } else {
                notification.flags &= ~Notification.FLAG_CAN_COLORIZE;
            }
            fixNotification(notification, pkg, userId);

        } catch (NameNotFoundException e) {
            Slog.e(TAG, "Cannot create a context for sending app", e);
@@ -4359,6 +4348,33 @@ public class NotificationManagerService extends SystemService {
        mHandler.post(new EnqueueNotificationRunnable(userId, r));
    }

    @VisibleForTesting
    protected void fixNotification(Notification notification, String pkg, int userId)
            throws NameNotFoundException {
        final ApplicationInfo ai = mPackageManagerClient.getApplicationInfoAsUser(
                pkg, PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                (userId == UserHandle.USER_ALL) ? USER_SYSTEM : userId);
        Notification.addFieldsFromContext(ai, notification);

        int canColorize = mPackageManagerClient.checkPermission(
                android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, pkg);
        if (canColorize == PERMISSION_GRANTED) {
            notification.flags |= Notification.FLAG_CAN_COLORIZE;
        } else {
            notification.flags &= ~Notification.FLAG_CAN_COLORIZE;
        }

        if (ai.targetSdkVersion >= Build.VERSION_CODES.Q) {
            int fullscreenIntentPermission = mPackageManagerClient.checkPermission(
                    android.Manifest.permission.USE_FULL_SCREEN_INTENT, pkg);
            if (fullscreenIntentPermission != PERMISSION_GRANTED) {
                notification.fullScreenIntent = null;
                Log.w(TAG, "Package " + pkg +
                        ": Use of fullScreenIntent requires the USE_FULL_SCREEN_INTENT permission");
            }
        }
    }

    private void doChannelWarningToast(CharSequence toastText) {
        Binder.withCleanCallingIdentity(() -> {
            final int defaultWarningEnabled = Build.IS_DEBUGGABLE ? 1 : 0;