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

Commit cec677ac authored by Evan Laird's avatar Evan Laird
Browse files

DO NOT MERGE: Create a shim for StatusBarManager click methods

`StatusBarManager#onNotificationClick` and
`StatusBarManager#onNotificationActionClick` are signals we send to
system server about notification clicks. This CL adds a shim so that we
can have an in-process callback about the exact same events.

This CL also adds NotificationInteractionTracker, which basically just
merges the NotificationClickNotifier callbacks with the notification
collection and will be able to answer the question "has the user
interacted with this notification"

Lastly, this modifies the logic in ForegroundServiceLifetimeExtender
which now checks the interaction flag for notifications. So if a user
tapped on a notification action (for instance) which _then_ triggers a
notification cancel, it will succeed. It _does not_ as of yet release
the notification from lifetime extension upon interaction. So if a
notification is canceled and then interacted with, it will still live
the full amount of time.

Test: atest SystemUITests
Bug: 144324894
Bug: 119041698
Change-Id: I42201d6e7b7ffe9ad4f19c774b638a36a51750ef
(cherry picked from commit 9b2a480c)
parent 5f1b131c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import com.android.systemui.shared.system.DevicePolicyManagerWrapper;
import com.android.systemui.shared.system.PackageManagerWrapper;
import com.android.systemui.statusbar.AmbientPulseManager;
import com.android.systemui.statusbar.NavigationBarController;
import com.android.systemui.statusbar.NotificationClickNotifier;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationMediaManager;
@@ -302,6 +303,7 @@ public class Dependency extends SystemUI {
    @Inject Lazy<ChannelEditorDialogController> mChannelEditorDialogController;
    @Inject Lazy<INotificationManager> mINotificationManager;
    @Inject Lazy<FalsingManager> mFalsingManager;
    @Inject Lazy<NotificationClickNotifier> mClickNotifier;

    @Inject
    public Dependency() {
@@ -479,6 +481,7 @@ public class Dependency extends SystemUI {
        mProviders.put(ChannelEditorDialogController.class, mChannelEditorDialogController::get);
        mProviders.put(INotificationManager.class, mINotificationManager::get);
        mProviders.put(FalsingManager.class, mFalsingManager::get);
        mProviders.put(NotificationClickNotifier.class, mClickNotifier::get);

        // TODO(b/118592525): to support multi-display , we start to add something which is
        //                    per-display, while others may be global. I think it's time to add
+7 −0
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerServiceImpl;
import com.android.systemui.util.time.SystemClock;
import com.android.systemui.util.time.SystemClockImpl;
import com.android.systemui.volume.VolumeDialogControllerImpl;

import dagger.Binds;
@@ -241,4 +243,9 @@ public abstract class DependencyBinder {
     */
    @Binds
    public abstract FalsingManager provideFalsingmanager(FalsingManagerProxy falsingManagerImpl);

    /**
     */
    @Binds
    public abstract SystemClock provideSystemClock(SystemClockImpl systemClock);
}
+16 −4
Original line number Diff line number Diff line
@@ -23,8 +23,12 @@ import android.os.Looper;
import android.util.ArraySet;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.statusbar.NotificationInteractionTracker;
import com.android.systemui.statusbar.NotificationLifetimeExtender;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.util.time.SystemClock;

import javax.inject.Inject;

/**
 * Extends the lifetime of foreground notification services such that they show for at least
@@ -39,8 +43,15 @@ public class ForegroundServiceLifetimeExtender implements NotificationLifetimeEx
    private NotificationSafeToRemoveCallback mNotificationSafeToRemoveCallback;
    private ArraySet<NotificationEntry> mManagedEntries = new ArraySet<>();
    private Handler mHandler = new Handler(Looper.getMainLooper());
    private final SystemClock mSystemClock;
    private final NotificationInteractionTracker mInteractionTracker;

    public ForegroundServiceLifetimeExtender() {
    @Inject
    public ForegroundServiceLifetimeExtender(
            NotificationInteractionTracker interactionTracker,
            SystemClock systemClock) {
        mSystemClock = systemClock;
        mInteractionTracker = interactionTracker;
    }

    @Override
@@ -55,8 +66,9 @@ public class ForegroundServiceLifetimeExtender implements NotificationLifetimeEx
            return false;
        }

        long currentTime = System.currentTimeMillis();
        return currentTime - entry.notification.getPostTime() < MIN_FGS_TIME_MS;
        boolean hasInteracted = mInteractionTracker.hasUserInteractedWith(entry.key);
        long aliveTime = mSystemClock.uptimeMillis() - entry.getCreationTime();
        return aliveTime < MIN_FGS_TIME_MS && !hasInteracted;
    }

    @Override
@@ -84,7 +96,7 @@ public class ForegroundServiceLifetimeExtender implements NotificationLifetimeEx
            }
        };
        long delayAmt = MIN_FGS_TIME_MS
                - (System.currentTimeMillis() - entry.notification.getPostTime());
                - (mSystemClock.uptimeMillis() - entry.getCreationTime());
        mHandler.postDelayed(r, delayAmt);
    }
}
+3 −4
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ public class ForegroundServiceNotificationListener {
    @Inject
    public ForegroundServiceNotificationListener(Context context,
            ForegroundServiceController foregroundServiceController,
            NotificationEntryManager notificationEntryManager) {
            NotificationEntryManager notificationEntryManager,
            ForegroundServiceLifetimeExtender fgsLifetimeExtender) {
        mContext = context;
        mForegroundServiceController = foregroundServiceController;
        notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
@@ -66,9 +67,7 @@ public class ForegroundServiceNotificationListener {
                removeNotification(entry.notification);
            }
        });

        notificationEntryManager.addNotificationLifetimeExtender(
                new ForegroundServiceLifetimeExtender());
        notificationEntryManager.addNotificationLifetimeExtender(fgsLifetimeExtender);
    }

    /**
+4 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.power.EnhancedEstimates;
import com.android.systemui.power.EnhancedEstimatesImpl;
import com.android.systemui.statusbar.KeyguardIndicationController;
import com.android.systemui.statusbar.NotificationClickNotifier;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl;
@@ -167,8 +168,9 @@ public class SystemUIFactory {
    @Singleton
    @Provides
    public NotificationLockscreenUserManager provideNotificationLockscreenUserManager(
            Context context) {
        return new NotificationLockscreenUserManagerImpl(context);
            Context context,
            NotificationClickNotifier clickNotifier) {
        return new NotificationLockscreenUserManagerImpl(context, clickNotifier);
    }

    @Singleton
Loading