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

Commit 7b593ace authored by Alexander Roederer's avatar Alexander Roederer Committed by Android (Google) Code Review
Browse files

Merge "Escalate permissions when get package importance" into main

parents 8aa74c68 5c9a5828
Loading
Loading
Loading
Loading
+24 −18
Original line number Diff line number Diff line
@@ -1879,11 +1879,11 @@ public class NotificationManagerService extends SystemService {
                                true, record.getUserId(), REASON_TIMEOUT, null);
                        // If cancellation will be prevented due to lifetime extension, we send an
                        // update to system UI.
                        final int packageImportance = getPackageImportanceWithIdentity(
                                record.getSbn().getPackageName());
                        synchronized (mNotificationLock) {
                            maybeNotifySystemUiListenerLifetimeExtendedLocked(record,
                                    record.getSbn().getPackageName(),
                                    mActivityManager.getPackageImportance(
                                            record.getSbn().getPackageName()));
                                    record.getSbn().getPackageName(), packageImportance);
                        }
                    } else {
                        cancelNotification(record.getSbn().getUid(),
@@ -3852,7 +3852,7 @@ public class NotificationManagerService extends SystemService {
                // If cancellation will be prevented due to lifetime extension, we send an update to
                // system UI.
                NotificationRecord record = null;
                final int packageImportance = mActivityManager.getPackageImportance(pkg);
                final int packageImportance = getPackageImportanceWithIdentity(pkg);
                synchronized (mNotificationLock) {
                    record = findNotificationLocked(pkg, tag, id, userId);
                    maybeNotifySystemUiListenerLifetimeExtendedLocked(record, pkg,
@@ -3877,10 +3877,9 @@ public class NotificationManagerService extends SystemService {
                        pkg, null, 0, FLAG_FOREGROUND_SERVICE | FLAG_USER_INITIATED_JOB
                                | FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY,
                        userId, REASON_APP_CANCEL_ALL);
                final int packageImportance = getPackageImportanceWithIdentity(pkg);
                // If cancellation will be prevented due to lifetime extension, we send updates
                // to system UI.
                // In this case, we need to hold the lock to access these lists.
                final int packageImportance = mActivityManager.getPackageImportance(pkg);
                synchronized (mNotificationLock) {
                    notifySystemUiListenerLifetimeExtendedListLocked(mNotificationList,
                            packageImportance);
@@ -5029,7 +5028,7 @@ public class NotificationManagerService extends SystemService {
                    pkg = info.component.getPackageName();
                }
                if (lifetimeExtensionRefactor()) {
                    packageImportance = mActivityManager.getPackageImportance(pkg);
                    packageImportance = getPackageImportanceWithIdentity(pkg);
                } else {
                    packageImportance = IMPORTANCE_NONE;
                }
@@ -5348,7 +5347,7 @@ public class NotificationManagerService extends SystemService {
            final int packageImportance;
            try {
                if (lifetimeExtensionRefactor()) {
                    packageImportance = mActivityManager.getPackageImportance(pkg);
                    packageImportance = getPackageImportanceWithIdentity(pkg);
                } else {
                    packageImportance = IMPORTANCE_NONE;
                }
@@ -7609,14 +7608,9 @@ public class NotificationManagerService extends SystemService {
            }
        }
        // Need escalated privileges to get package importance
        final long token = Binder.clearCallingIdentity();
        boolean isAppForeground;
        try {
            isAppForeground = mActivityManager.getPackageImportance(pkg) == IMPORTANCE_FOREGROUND;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        // Need escalated privileges to get package importance.
        final int packageImportance = getPackageImportanceWithIdentity(pkg);
        boolean isAppForeground = packageImportance == IMPORTANCE_FOREGROUND;
        mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, tracker));
        return true;
    }
@@ -7944,9 +7938,9 @@ public class NotificationManagerService extends SystemService {
                        NotificationRecord r = mNotificationsByKey.get(key);
                        packageName = r != null ? r.getSbn().getPackageName() : null;
                    }
                    final int packageImportance = getPackageImportanceWithIdentity(packageName);
                    boolean isAppForeground = packageName != null
                            && mActivityManager.getPackageImportance(packageName)
                            == IMPORTANCE_FOREGROUND;
                            && packageImportance == IMPORTANCE_FOREGROUND;
                    synchronized (mNotificationLock) {
                        NotificationRecord r = mNotificationsByKey.get(key);
                        if (r != null) {
@@ -11867,6 +11861,18 @@ public class NotificationManagerService extends SystemService {
        }
    }
    @FlaggedApi(FLAG_LIFETIME_EXTENSION_REFACTOR)
    private int getPackageImportanceWithIdentity(String pkg) {
        final long token = Binder.clearCallingIdentity();
        final int packageImportance;
        try {
            packageImportance = mActivityManager.getPackageImportance(pkg);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        return packageImportance;
    }
    public class NotificationListeners extends ManagedServices {
        static final String TAG_ENABLED_NOTIFICATION_LISTENERS = "enabled_listeners";
        static final String TAG_REQUESTED_LISTENERS = "request_listeners";