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

Commit 95615e04 authored by Matías Hernández's avatar Matías Hernández
Browse files

Simplify cookie usage in allowlist token serialization

We don't actually need to store the whole root notification, the token itself is enough.

Test: atest NotificationManagerServiceTest + manually
Bug: 320659371
Bug: 322326520
Bug: 322819634
Bug: 305695605
Change-Id: Ia5f54b309569fb807a8613fae2c3f95bd310232e
parent 41f15711
Loading
Loading
Loading
Loading
+7 −11
Original line number Original line Diff line number Diff line
@@ -3256,8 +3256,9 @@ public class Notification implements Parcelable
                boolean mustClearCookie = false;
                boolean mustClearCookie = false;
                if (!parcel.hasClassCookie(Notification.class)) {
                if (!parcel.hasClassCookie(Notification.class)) {
                    // This is the "root" notification, and not an "inner" notification (including
                    // This is the "root" notification, and not an "inner" notification (including
                    // publicVersion or anything else that might be embedded in extras).
                    // publicVersion or anything else that might be embedded in extras). So we want
                    parcel.setClassCookie(Notification.class, this);
                    // to use its token for every inner notification (might be null).
                    parcel.setClassCookie(Notification.class, mAllowlistToken);
                    mustClearCookie = true;
                    mustClearCookie = true;
                }
                }
                try {
                try {
@@ -3266,7 +3267,7 @@ public class Notification implements Parcelable
                    writeToParcelImpl(parcel, flags);
                    writeToParcelImpl(parcel, flags);
                } finally {
                } finally {
                    if (mustClearCookie) {
                    if (mustClearCookie) {
                        parcel.removeClassCookie(Notification.class, this);
                        parcel.removeClassCookie(Notification.class, mAllowlistToken);
                    }
                    }
                }
                }
            } else {
            } else {
@@ -3290,14 +3291,9 @@ public class Notification implements Parcelable
        parcel.writeInt(1);
        parcel.writeInt(1);
        if (Flags.secureAllowlistToken()) {
        if (Flags.secureAllowlistToken()) {
            Notification rootNotification = (Notification) parcel.getClassCookie(
            // Always use the same token as the root notification (might be null).
                    Notification.class);
            IBinder rootNotificationToken = (IBinder) parcel.getClassCookie(Notification.class);
            if (rootNotification != null && rootNotification != this) {
            parcel.writeStrongBinder(rootNotificationToken);
                // Always use the same token as the root notification
                parcel.writeStrongBinder(rootNotification.mAllowlistToken);
            } else {
                parcel.writeStrongBinder(mAllowlistToken);
            }
        } else {
        } else {
            parcel.writeStrongBinder(mAllowlistToken);
            parcel.writeStrongBinder(mAllowlistToken);
        }
        }