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

Commit 7c7f18b9 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Add API for checking paused packages."

parents c6a4af09 b40cd09d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5777,6 +5777,7 @@ package android.app {
    method public String addAutomaticZenRule(android.app.AutomaticZenRule);
    method public boolean areBubblesAllowed();
    method public boolean areNotificationsEnabled();
    method public boolean areNotificationsPaused();
    method public boolean canNotifyAsPackage(String);
    method public void cancel(int);
    method public void cancel(String, int);
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ interface INotificationManager
    boolean areChannelsBypassingDnd();
    int getAppsBypassingDndCount(int uid);
    ParceledListSlice getNotificationChannelsBypassingDnd(String pkg, int userId);
    boolean isPackagePaused(String pkg);

    // TODO: Remove this when callers have been migrated to the equivalent
    // INotificationListener method.
+16 −0
Original line number Diff line number Diff line
@@ -1093,6 +1093,22 @@ public class NotificationManager {
        }
    }

    /**
     * Returns whether notifications from this package are temporarily hidden. This
     * could be done because the package was marked as distracting to the user via
     * {@code PackageManager#setDistractingPackageRestrictions(String[], int)} or because the
     * package is {@code PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
     * PersistableBundle, SuspendDialogInfo) suspended}.
     */
    public boolean areNotificationsPaused() {
        INotificationManager service = getService();
        try {
            return service.isPackagePaused(mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Checks the ability to modify notification do not disturb policy for the calling package.
     *
+19 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
import android.content.res.Resources;
@@ -3859,6 +3860,24 @@ public class NotificationManagerService extends SystemService {
            return mLockScreenAllowSecureNotifications;
        }

        @Override
        public boolean isPackagePaused(String pkg) {
            Preconditions.checkNotNull(pkg);
            checkCallerIsSameApp(pkg);

            boolean isPaused;

            final PackageManagerInternal pmi = LocalServices.getService(
                    PackageManagerInternal.class);
            int flags = pmi.getDistractingPackageRestrictions(
                    pkg, Binder.getCallingUserHandle().getIdentifier());
            isPaused = ((flags & PackageManager.RESTRICTION_HIDE_NOTIFICATIONS) != 0);

            isPaused |= isPackageSuspendedForUser(pkg, Binder.getCallingUid());

            return isPaused;
        }

        private void verifyPrivilegedListener(INotificationListener token, UserHandle user,
                boolean assistantAllowed) {
            ManagedServiceInfo info;