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

Commit b40cd09d authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add API for checking paused packages.

Test: gts
Change-Id: I00e057791c7430505386b6d9e6d488368d5bf3df
Fixes: 112558358
parent 0e5a343d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5771,6 +5771,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;
@@ -3854,6 +3855,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;