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

Commit aafc56bc authored by Koushik Dutta's avatar Koushik Dutta
Browse files

Notification cancellation fixes:

Permission should only allow cancellation of other app notifications, not enqueueing.
Fix checkapi breakage.

Change-Id: Idbcfd4617057984250dc4d4fa32ff55bfbb155e2
parent fc94a474
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1943,7 +1943,7 @@
        android:protectionLevel="signature" />

    <!-- Allows an application to cancel notifications from other apps
         -->
         @hide -->
    <permission android:name="android.permission.CANCEL_NOTIFICATIONS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="signature|system"
+7 −3
Original line number Diff line number Diff line
@@ -1554,7 +1554,7 @@ public class NotificationManagerService extends INotificationManager.Stub
    }

    public void cancelNotificationWithTag(String pkg, String tag, int id, int userId) {
        checkCallerIsSystemOrSameApp(pkg);
        checkCallerCanCancelNotification(pkg);
        userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
                Binder.getCallingUid(), userId, true, false, "cancelNotificationWithTag", pkg);
        // Don't allow client applications to cancel foreground service notis.
@@ -1564,7 +1564,7 @@ public class NotificationManagerService extends INotificationManager.Stub
    }

    public void cancelAllNotifications(String pkg, int userId) {
        checkCallerIsSystemOrSameApp(pkg);
        checkCallerCanCancelNotification(pkg);

        userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
                Binder.getCallingUid(), userId, true, false, "cancelAllNotifications", pkg);
@@ -1582,11 +1582,15 @@ public class NotificationManagerService extends INotificationManager.Stub
        throw new SecurityException("Disallowed call for uid " + uid);
    }

    void checkCallerIsSystemOrSameApp(String pkg) {
    void checkCallerCanCancelNotification(String pkg) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.CANCEL_NOTIFICATIONS)
                == PackageManager.PERMISSION_GRANTED) {
            return;
        }
        checkCallerIsSystemOrSameApp(pkg);
    }

    void checkCallerIsSystemOrSameApp(String pkg) {
        int uid = Binder.getCallingUid();
        if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
            return;