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

Commit fac5da2f authored by Jeff DeCew's avatar Jeff DeCew
Browse files

New Pipeline: Remote Input 2/4: Add ability to internally update notifications

Fixes: 204127880
Bug: 203938360
Test: atest NotifCollectionTest
Merged-In: Ie15f7565b76e7314221d18e540d2ed8a5ce3e4a4
Change-Id: Ie15f7565b76e7314221d18e540d2ed8a5ce3e4a4
parent d4e9cfb0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -689,8 +689,9 @@ public class NotificationEntryManager implements
        for (NotificationEntryListener listener : mNotificationEntryListeners) {
            listener.onPreEntryUpdated(entry);
        }
        final boolean fromSystem = ranking != null;
        for (NotifCollectionListener listener : mNotifCollectionListeners) {
            listener.onEntryUpdated(entry);
            listener.onEntryUpdated(entry, fromSystem);
        }

        if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
+52 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.annotation.MainThread;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.Notification;
import android.os.Handler;
import android.os.RemoteException;
import android.os.Trace;
import android.os.UserHandle;
@@ -62,6 +63,7 @@ import androidx.annotation.NonNull;
import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.Dumpable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.dump.LogBufferEulogizer;
import com.android.systemui.flags.FeatureFlags;
@@ -76,6 +78,7 @@ import com.android.systemui.statusbar.notification.collection.notifcollection.En
import com.android.systemui.statusbar.notification.collection.notifcollection.EntryRemovedEvent;
import com.android.systemui.statusbar.notification.collection.notifcollection.EntryUpdatedEvent;
import com.android.systemui.statusbar.notification.collection.notifcollection.InitEntryEvent;
import com.android.systemui.statusbar.notification.collection.notifcollection.InternalNotifUpdater;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionLogger;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifDismissInterceptor;
@@ -131,6 +134,7 @@ public class NotifCollection implements Dumpable {
    private final SystemClock mClock;
    private final FeatureFlags mFeatureFlags;
    private final NotifCollectionLogger mLogger;
    private final Handler mMainHandler;
    private final LogBufferEulogizer mEulogizer;

    private final Map<String, NotificationEntry> mNotificationSet = new ArrayMap<>();
@@ -154,6 +158,7 @@ public class NotifCollection implements Dumpable {
            SystemClock clock,
            FeatureFlags featureFlags,
            NotifCollectionLogger logger,
            @Main Handler mainHandler,
            LogBufferEulogizer logBufferEulogizer,
            DumpManager dumpManager) {
        Assert.isMainThread();
@@ -161,6 +166,7 @@ public class NotifCollection implements Dumpable {
        mClock = clock;
        mFeatureFlags = featureFlags;
        mLogger = logger;
        mMainHandler = mainHandler;
        mEulogizer = logBufferEulogizer;

        dumpManager.registerDumpable(TAG, this);
@@ -442,7 +448,7 @@ public class NotifCollection implements Dumpable {
            mEventQueue.add(new BindEntryEvent(entry, sbn));

            mLogger.logNotifUpdated(sbn.getKey());
            mEventQueue.add(new EntryUpdatedEvent(entry));
            mEventQueue.add(new EntryUpdatedEvent(entry, true /* fromSystem */));
        }
    }

@@ -791,6 +797,51 @@ public class NotifCollection implements Dumpable {

    private static final String TAG = "NotifCollection";

    /**
     * Get an object which can be used to update a notification (internally to the pipeline)
     * in response to a user action.
     *
     * @param name the name of the component that will update notifiations
     * @return an updater
     */
    public InternalNotifUpdater getInternalNotifUpdater(String name) {
        return (sbn, reason) -> mMainHandler.post(
                () -> updateNotificationInternally(sbn, name, reason));
    }

    /**
     * Provide an updated StatusBarNotification for an existing entry.  If no entry exists for the
     * given notification key, this method does nothing.
     *
     * @param sbn the updated notification
     * @param name the component which is updating the notification
     * @param reason the reason the notification is being updated
     */
    private void updateNotificationInternally(StatusBarNotification sbn, String name,
            String reason) {
        Assert.isMainThread();
        checkForReentrantCall();

        // Make sure we have the notification to update
        NotificationEntry entry = mNotificationSet.get(sbn.getKey());
        if (entry == null) {
            mLogger.logNotifInternalUpdateFailed(sbn.getKey(), name, reason);
            return;
        }
        mLogger.logNotifInternalUpdate(sbn.getKey(), name, reason);

        // First do the pieces of postNotification which are not about assuming the notification
        // was sent by the app
        entry.setSbn(sbn);
        mEventQueue.add(new BindEntryEvent(entry, sbn));

        mLogger.logNotifUpdated(sbn.getKey());
        mEventQueue.add(new EntryUpdatedEvent(entry, false /* fromSystem */));

        // Skip the applyRanking step and go straight to dispatching the events
        dispatchEventsAndRebuildList();
    }

    @IntDef(prefix = { "REASON_" }, value = {
            REASON_NOT_CANCELED,
            REASON_UNKNOWN,
+14 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.notification.collection;

import android.os.Handler;

import androidx.annotation.Nullable;

import com.android.systemui.dagger.SysUISingleton;
@@ -30,6 +32,7 @@ import com.android.systemui.statusbar.notification.collection.listbuilder.plugga
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifStabilityManager;
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
import com.android.systemui.statusbar.notification.collection.notifcollection.InternalNotifUpdater;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifDismissInterceptor;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender;
@@ -222,6 +225,17 @@ public class NotifPipeline implements CommonNotifCollection {
        mShadeListBuilder.addPreRenderInvalidator(invalidator);
    }

    /**
     * Get an object which can be used to update a notification (internally to the pipeline)
     * in response to a user action.
     *
     * @param name the name of the component that will update notifiations
     * @return an updater
     */
    public InternalNotifUpdater getInternalNotifUpdater(String name) {
        return mNotifCollection.getInternalNotifUpdater(name);
    }

    /**
     * Returns a read-only view in to the current shade list, i.e. the list of notifications that
     * are currently present in the shade. If this method is called during pipeline execution it
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.collection.notifcollection;

import android.service.notification.StatusBarNotification;

/**
 * An object that allows Coordinators to update notifications internally to SystemUI.
 * This is used when part of the UI involves updating the underlying appearance of a notification
 * on behalf of an app, such as to add a spinner or remote input history.
 */
public interface InternalNotifUpdater {
    /**
     * Called when an already-existing notification needs to be updated to a new temporary
     * appearance.
     * This update is local to the SystemUI process.
     * This has no effect if no notification with the given key exists in the pipeline.
     *
     * @param sbn a notification to update
     * @param reason a debug reason for the update
     */
    void onInternalNotificationUpdate(StatusBarNotification sbn, String reason);
}
+11 −0
Original line number Diff line number Diff line
@@ -53,6 +53,17 @@ public interface NotifCollectionListener {
    default void onEntryAdded(@NonNull NotificationEntry entry) {
    }

    /**
     * Called whenever a notification with the same key as an existing notification is posted. By
     * the time this listener is called, the entry's SBN and Ranking will already have been updated.
     * This delegates to {@link #onEntryUpdated(NotificationEntry)} by default.
     * @param fromSystem If true, this update came from the NotificationManagerService.
     *                   If false, the notification update is an internal change within systemui.
     */
    default void onEntryUpdated(@NonNull NotificationEntry entry, boolean fromSystem) {
        onEntryUpdated(entry);
    }

    /**
     * Called whenever a notification with the same key as an existing notification is posted. By
     * the time this listener is called, the entry's SBN and Ranking will already have been updated.
Loading