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

Commit 4d9517dd authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Let apps know if they are promotable

Test: NotificationManagerTest
Bug: 367741426
Flag: android.app.api_rich_ongoing
Change-Id: I9aeaedf9b6cc144672db1029c4dc434148c41b2e
parent c5d91e7a
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -7009,6 +7009,7 @@ package android.app {
    method public boolean areNotificationsEnabled();
    method public boolean areNotificationsEnabled();
    method public boolean areNotificationsPaused();
    method public boolean areNotificationsPaused();
    method public boolean canNotifyAsPackage(@NonNull String);
    method public boolean canNotifyAsPackage(@NonNull String);
    method @FlaggedApi("android.app.api_rich_ongoing") public boolean canPostPromotedNotifications();
    method public boolean canUseFullScreenIntent();
    method public boolean canUseFullScreenIntent();
    method public void cancel(int);
    method public void cancel(int);
    method public void cancel(@Nullable String, int);
    method public void cancel(@Nullable String, int);
+1 −0
Original line number Original line Diff line number Diff line
@@ -398,6 +398,7 @@ package android.app {
    method public android.content.ComponentName getEffectsSuppressor();
    method public android.content.ComponentName getEffectsSuppressor();
    method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String);
    method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String);
    method @FlaggedApi("android.app.modes_api") public boolean removeAutomaticZenRule(@NonNull String, boolean);
    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_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 @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);
    method @FlaggedApi("android.app.modes_api") public boolean updateAutomaticZenRule(@NonNull String, @NonNull android.app.AutomaticZenRule, boolean);
+2 −1
Original line number Original line Diff line number Diff line
@@ -259,5 +259,6 @@ interface INotificationManager
    void unregisterCallNotificationEventListener(String packageName, in UserHandle userHandle, in ICallNotificationEventCallback listener);
    void unregisterCallNotificationEventListener(String packageName, in UserHandle userHandle, in ICallNotificationEventCallback listener);


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