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

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

Merge "Let apps know if they are promotable" into main

parents 50e83ba8 4d9517dd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7015,6 +7015,7 @@ package android.app {
    method public boolean areNotificationsEnabled();
    method public boolean areNotificationsPaused();
    method public boolean canNotifyAsPackage(@NonNull String);
    method @FlaggedApi("android.app.api_rich_ongoing") public boolean canPostPromotedNotifications();
    method public boolean canUseFullScreenIntent();
    method public void cancel(int);
    method public void cancel(@Nullable String, int);
+1 −0
Original line number Diff line number Diff line
@@ -398,6 +398,7 @@ package android.app {
    method public android.content.ComponentName getEffectsSuppressor();
    method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String);
    method @FlaggedApi("android.app.modes_api") public boolean removeAutomaticZenRule(@NonNull String, boolean);
    method @FlaggedApi("android.app.api_rich_ongoing") public void setCanPostPromotedNotifications(@NonNull String, int, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted(@NonNull android.content.ComponentName, boolean, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_TOAST_RATE_LIMITING) public void setToastRateLimitingEnabled(boolean);
    method @FlaggedApi("android.app.modes_api") public boolean updateAutomaticZenRule(@NonNull String, @NonNull android.app.AutomaticZenRule, boolean);
+2 −1
Original line number Diff line number Diff line
@@ -259,5 +259,6 @@ interface INotificationManager
    void unregisterCallNotificationEventListener(String packageName, in UserHandle userHandle, in ICallNotificationEventCallback listener);

    void setCanBePromoted(String pkg, int uid, boolean promote);
    boolean canBePromoted(String pkg, int uid);
    boolean appCanBePromoted(String pkg, int uid);
    boolean canBePromoted(String pkg);
}
+30 −0
Original line number Diff line number Diff line
@@ -952,6 +952,36 @@ public class NotificationManager {
        }
    }

    /**
     * Returns whether the calling app's properly formatted notifications can appear in a promoted
     * format, which may result in higher ranking, appearances on additional surfaces, and richer
     * presentation.
     */
    @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
    public boolean canPostPromotedNotifications() {
        INotificationManager service = getService();
        try {
            return service.canBePromoted(mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Setter for {@link #canPostPromotedNotifications()}. Only callable by the OS.
     * @hide
     */
    @TestApi
    @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
    public void setCanPostPromotedNotifications(@NonNull String pkg, int uid, boolean allowed) {
        INotificationManager service = getService();
        try {
            service.setCanBePromoted(pkg, uid, allowed);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Creates a group container for {@link NotificationChannel} objects.
     *
+18 −7
Original line number Diff line number Diff line
@@ -4116,20 +4116,31 @@ public class NotificationManagerService extends SystemService {
        }
        @Override
        @FlaggedApi(android.app.Flags.FLAG_UI_RICH_ONGOING)
        public boolean canBePromoted(String pkg, int uid) {
        @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
        public boolean appCanBePromoted(String pkg, int uid) {
            checkCallerIsSystemOrSystemUiOrShell();
            if (!android.app.Flags.uiRichOngoing()) {
            if (!android.app.Flags.apiRichOngoing()) {
                return false;
            }
            return mPreferencesHelper.canBePromoted(pkg, uid);
        }
        @Override
        @FlaggedApi(android.app.Flags.FLAG_UI_RICH_ONGOING)
        @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
        public boolean canBePromoted(String callingPkg) {
            checkCallerIsSameApp(callingPkg);
            if (!android.app.Flags.apiRichOngoing()) {
                return false;
            }
            return mPreferencesHelper.canBePromoted(callingPkg, Binder.getCallingUid());
        }
        @Override
        @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
        public void setCanBePromoted(String pkg, int uid, boolean promote) {
            checkCallerIsSystemOrSystemUiOrShell();
            if (!android.app.Flags.uiRichOngoing()) {
            if (!android.app.Flags.apiRichOngoing()) {
                return;
            }
            boolean changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote);
@@ -7776,7 +7787,7 @@ public class NotificationManagerService extends SystemService {
            return false;
        }
        if (android.app.Flags.uiRichOngoing()) {
        if (android.app.Flags.apiRichOngoing()) {
            // This would normally be done in fixNotification(), but we need the channel info so
            // it's done a little late
            if (mPreferencesHelper.canBePromoted(pkg, notificationUid)
@@ -10740,7 +10751,7 @@ public class NotificationManagerService extends SystemService {
    }
    @GuardedBy("mNotificationLock")
    @FlaggedApi(android.app.Flags.FLAG_UI_RICH_ONGOING)
    @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
    private @NonNull List<NotificationRecord> findAppNotificationByListLocked(
            ArrayList<NotificationRecord> list, String pkg, int userId) {
        List<NotificationRecord> records = new ArrayList<>();
Loading