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

Commit e82e8a5e authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Add NotificationDelegate API to rebundle notification

 Allow notifications that were bundled (classified) and then unbundled to be rebundled
   => restored to their bundle channel.

Flag: android.service.notification.notification_regroup_on_classification
Test: atest NotificationManagerServiceTest
Test: atest GroupHelperTest

Bug: 382047364
Change-Id: I65deccab2738126a0af4a549adc892a2346eb889
parent 271ede58
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -239,4 +239,7 @@ interface IStatusBarService

    /** Unbundle a categorized notification */
    void unbundleNotification(String key);

    /** Rebundle an (un)categorized notification */
    void rebundleNotification(String key);
}
+2 −0
Original line number Diff line number Diff line
@@ -435,6 +435,8 @@ class FakeStatusBarService : IStatusBarService.Stub() {

    override fun unbundleNotification(key: String) {}

    override fun rebundleNotification(key: String) {}

    companion object {
        const val DEFAULT_DISPLAY_ID = Display.DEFAULT_DISPLAY
        const val SECONDARY_DISPLAY_ID = 2
+5 −0
Original line number Diff line number Diff line
@@ -107,4 +107,9 @@ public interface NotificationDelegate {
     * @param key the notification key
     */
    void unbundleNotification(String key);
    /**
     *  Called when the notification should be rebundled.
     * @param key the notification key
     */
    void rebundleNotification(String key);
}
+31 −0
Original line number Diff line number Diff line
@@ -1888,6 +1888,36 @@ public class NotificationManagerService extends SystemService {
                }
            }
        }
        @Override
        public void rebundleNotification(String key) {
            if (!(notificationClassification() && notificationRegroupOnClassification())) {
                return;
            }
            synchronized (mNotificationLock) {
                NotificationRecord r = mNotificationsByKey.get(key);
                if (r == null) {
                    return;
                }
                if (DBG) {
                    Slog.v(TAG, "rebundleNotification: " + r);
                }
                if (r.getBundleType() != Adjustment.TYPE_OTHER) {
                    final Bundle classifBundle = new Bundle();
                    classifBundle.putInt(KEY_TYPE, r.getBundleType());
                    Adjustment adj = new Adjustment(r.getSbn().getPackageName(), r.getKey(),
                            classifBundle, "rebundle", r.getUserId());
                    applyAdjustmentLocked(r, adj, /* isPosted= */ true);
                    mRankingHandler.requestSort();
                } else {
                    if (DBG) {
                        Slog.w(TAG, "Can't rebundle. No valid bundle type for: " + r);
                    }
                }
            }
        }
    };
    NotificationManagerPrivate mNotificationManagerPrivate = new NotificationManagerPrivate() {
@@ -7129,6 +7159,7 @@ public class NotificationManagerService extends SystemService {
                    adjustments.putParcelable(KEY_TYPE, newChannel);
                    logClassificationChannelAdjustmentReceived(r, isPosted, classification);
                    r.setBundleType(classification);
                }
            }
            r.addAdjustment(adjustment);
+15 −0
Original line number Diff line number Diff line
@@ -226,6 +226,9 @@ public final class NotificationRecord {
    // lifetime extended.
    private boolean mCanceledAfterLifetimeExtension = false;

    // type of the bundle if the notification was classified
    private @Adjustment.Types int mBundleType = Adjustment.TYPE_OTHER;

    public NotificationRecord(Context context, StatusBarNotification sbn,
            NotificationChannel channel) {
        this.sbn = sbn;
@@ -471,6 +474,10 @@ public final class NotificationRecord {
            }
        }

        if (android.service.notification.Flags.notificationClassification()) {
            mBundleType = previous.mBundleType;
        }

        // Don't copy importance information or mGlobalSortKey, recompute them.
    }

@@ -1689,6 +1696,14 @@ public final class NotificationRecord {
        mCanceledAfterLifetimeExtension = canceledAfterLifetimeExtension;
    }

    public @Adjustment.Types int getBundleType() {
        return mBundleType;
    }

    public void setBundleType(@Adjustment.Types int bundleType) {
        mBundleType = bundleType;
    }

    /**
     * Whether this notification is a conversation notification.
     */
Loading