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

Commit bd142939 authored by Kevin Han's avatar Kevin Han
Browse files

Remove setInflationCallback

The current use cases for NotificationRowBinderImpl and NotifInflater's
API don't really need a persistent inflation callback stored as opposed
to a one-shot callback. By explicitly putting the callback in the
inflate methods, it also makes it more clear which calls inflate and
expect a callback to be called.

Bug: 145749521
Test: atest SystemUITests
Test: smoke test (add, update, remove notification)
Change-Id: I001413f17b7472ea2ef637be21d9d454ee17015e
parent 3742322d
Loading
Loading
Loading
Loading
+37 −34
Original line number Diff line number Diff line
@@ -88,14 +88,11 @@ import dagger.Lazy;
 * @see #getActiveNotificationUnfiltered(String) to check if a key exists
 * @see #getPendingNotificationsIterator() for an iterator over the pending notifications
 * @see #getPendingOrActiveNotif(String) to find a notification exists for that key in any list
 * @see #getPendingAndActiveNotifications() to get the entire set of Notifications that we're
 * aware of
 * @see #getActiveNotificationsForCurrentUser() to see every notification that the current user owns
 */
public class NotificationEntryManager implements
        CommonNotifCollection,
        Dumpable,
        InflationCallback,
        VisualStabilityManager.Callback {
    private static final String TAG = "NotificationEntryMgr";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -309,12 +306,7 @@ public class NotificationEntryManager implements
     *
     * WARNING: this will call back into us.  Don't hold any locks.
     */
    @Override
    public void handleInflationException(NotificationEntry n, Exception e) {
        handleInflationException(n.getSbn(), e);
    }

    public void handleInflationException(StatusBarNotification n, Exception e) {
    private void handleInflationException(StatusBarNotification n, Exception e) {
        removeNotificationInternal(
                n.getKey(), null, null, true /* forceRemove */, false /* removedByUser */,
                REASON_ERROR);
@@ -323,6 +315,12 @@ public class NotificationEntryManager implements
        }
    }

    private final InflationCallback mInflationCallback = new InflationCallback() {
        @Override
        public void handleInflationException(NotificationEntry entry, Exception e) {
            NotificationEntryManager.this.handleInflationException(entry.getSbn(), e);
        }

        @Override
        public void onAsyncInflationFinished(NotificationEntry entry) {
            mPendingNotifications.remove(entry.getKey());
@@ -347,6 +345,7 @@ public class NotificationEntryManager implements
                }
            }
        }
    };

    private final NotificationHandler mNotifListener = new NotificationHandler() {
        @Override
@@ -572,8 +571,10 @@ public class NotificationEntryManager implements
        // Construct the expanded view.
        if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            mNotificationRowBinderLazy.get()
                    .inflateViews(entry, () -> performRemoveNotification(notification,
                            REASON_CANCEL));
                    .inflateViews(
                            entry,
                            () -> performRemoveNotification(notification, REASON_CANCEL),
                            mInflationCallback);
        }

        abortExistingInflation(key, "addNotification");
@@ -630,8 +631,10 @@ public class NotificationEntryManager implements

        if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            mNotificationRowBinderLazy.get()
                    .inflateViews(entry, () -> performRemoveNotification(notification,
                            REASON_CANCEL));
                    .inflateViews(
                            entry,
                            () -> performRemoveNotification(notification, REASON_CANCEL),
                            mInflationCallback);
        }

        updateNotifications("updateNotificationInternal");
+28 −30
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ public class NotifInflaterImpl implements NotifInflater {
    private final NotifPipeline mNotifPipeline;

    private NotificationRowBinderImpl mNotificationRowBinder;
    private InflationCallback mExternalInflationCallback;

    @Inject
    public NotifInflaterImpl(
@@ -66,17 +65,11 @@ public class NotifInflaterImpl implements NotifInflater {
     */
    public void setRowBinder(NotificationRowBinderImpl rowBinder) {
        mNotificationRowBinder = rowBinder;
        mNotificationRowBinder.setInflationCallback(mInflationCallback);
    }

    @Override
    public void setInflationCallback(InflationCallback callback) {
        mExternalInflationCallback = callback;
    }

    @Override
    public void rebindViews(NotificationEntry entry) {
        inflateViews(entry);
    public void rebindViews(NotificationEntry entry, InflationCallback callback) {
        inflateViews(entry, callback);
    }

    /**
@@ -84,11 +77,14 @@ public class NotifInflaterImpl implements NotifInflater {
     * views are bound.
     */
    @Override
    public void inflateViews(NotificationEntry entry) {
    public void inflateViews(NotificationEntry entry, InflationCallback callback) {
        try {
            requireBinder().inflateViews(entry, getDismissCallback(entry));
            requireBinder().inflateViews(
                    entry,
                    getDismissCallback(entry),
                    wrapInflationCallback(callback));
        } catch (InflationException e) {
            // logged in mInflationCallback.handleInflationException
            mNotifErrorManager.setInflationError(entry, e);
        }
    }

@@ -121,16 +117,9 @@ public class NotifInflaterImpl implements NotifInflater {
        };
    }

    private NotificationRowBinderImpl requireBinder() {
        if (mNotificationRowBinder == null) {
            throw new RuntimeException("NotificationRowBinder must be attached before using "
                    + "NotifInflaterImpl.");
        }
        return mNotificationRowBinder;
    }

    private final NotificationContentInflater.InflationCallback mInflationCallback =
            new NotificationContentInflater.InflationCallback() {
    private NotificationContentInflater.InflationCallback wrapInflationCallback(
            InflationCallback callback) {
        return new NotificationContentInflater.InflationCallback() {
            @Override
            public void handleInflationException(
                    NotificationEntry entry,
@@ -141,9 +130,18 @@ public class NotifInflaterImpl implements NotifInflater {
            @Override
            public void onAsyncInflationFinished(NotificationEntry entry) {
                mNotifErrorManager.clearInflationError(entry);
                    if (mExternalInflationCallback != null) {
                        mExternalInflationCallback.onInflationFinished(entry);
                if (callback != null) {
                    callback.onInflationFinished(entry);
                }
            }
        };
    }

    private NotificationRowBinderImpl requireBinder() {
        if (mNotificationRowBinder == null) {
            throw new RuntimeException("NotificationRowBinder must be attached before using "
                    + "NotifInflaterImpl.");
        }
        return mNotificationRowBinder;
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ public class PreparationCoordinator implements Coordinator {
    ) {
        mLogger = logger;
        mNotifInflater = notifInflater;
        mNotifInflater.setInflationCallback(mInflationCallback);
        mNotifErrorManager = errorManager;
        mNotifErrorManager.addInflationErrorListener(mInflationErrorListener);
        mViewBarn = viewBarn;
@@ -218,11 +217,11 @@ public class PreparationCoordinator implements Coordinator {

    private void inflateEntry(NotificationEntry entry, String reason) {
        abortInflation(entry, reason);
        mNotifInflater.inflateViews(entry);
        mNotifInflater.inflateViews(entry, mInflationCallback);
    }

    private void rebind(NotificationEntry entry, String reason) {
        mNotifInflater.rebindViews(entry);
        mNotifInflater.rebindViews(entry, mInflationCallback);
    }

    private void abortInflation(NotificationEntry entry, String reason) {
+6 −8
Original line number Diff line number Diff line
@@ -24,22 +24,20 @@ import com.android.systemui.statusbar.notification.collection.coordinator.Prepar
 * main thread. When the inflation is finished, NotifInflater will trigger its InflationCallback.
 */
public interface NotifInflater {

    /**
     * Callback used when inflation is finished.
     */
    void setInflationCallback(InflationCallback callback);

    /**
     * Called to rebind the entry's views.
     *
     * @param callback callback called after inflation finishes
     */
    void rebindViews(NotificationEntry entry);
    void rebindViews(NotificationEntry entry, InflationCallback callback);

    /**
     * Called to inflate the views of an entry.  Views are not considered inflated until all of its
     * views are bound. Once all views are inflated, the InflationCallback is triggered.
     *
     * @param callback callback called after inflation finishes
     */
    void inflateViews(NotificationEntry entry);
    void inflateViews(NotificationEntry entry, InflationCallback callback);

    /**
     * Request to stop the inflation of an entry.  For example, called when a notification is
+3 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.statusbar.NotificationUiAdjustment;
import com.android.systemui.statusbar.notification.InflationException;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder;

/**
 * Used by the {@link NotificationEntryManager}. When notifications are added or updated, the binder
@@ -37,7 +38,8 @@ public interface NotificationRowBinder {
     */
    void inflateViews(
            NotificationEntry entry,
            Runnable onDismissRunnable)
            Runnable onDismissRunnable,
            NotificationRowContentBinder.InflationCallback callback)
            throws InflationException;

    /**
Loading