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

Commit 3da3c787 authored by Ned Burns's avatar Ned Burns
Browse files

Move "alerted recently" logic out of NEM

Test: manual
Change-Id: I22c0d28fc347c55cb87f0dac7f5d11ca47ebbf5a
parent 59a7bc04
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.notification;
import android.annotation.Nullable;
import android.app.Notification;
import android.content.Context;
import android.os.Handler;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
@@ -51,7 +50,6 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * NotificationEntryManager is responsible for the adding, removing, and updating of notifications.
@@ -66,8 +64,6 @@ public class NotificationEntryManager implements
    private static final String TAG = "NotificationEntryMgr";
    protected static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    public static final long RECENTLY_ALERTED_THRESHOLD_MS = TimeUnit.SECONDS.toMillis(30);

    protected final Context mContext;
    protected final HashMap<String, NotificationEntry> mPendingNotifications = new HashMap<>();

@@ -80,9 +76,6 @@ public class NotificationEntryManager implements
    private NotificationRemoteInputManager mRemoteInputManager;
    private NotificationRowBinder mNotificationRowBinder;

    private final Handler mDeferredNotificationViewUpdateHandler;
    private Runnable mUpdateNotificationViewsCallback;

    private NotificationPresenter mPresenter;
    private NotificationListenerService.RankingMap mLatestRankingMap;
    protected NotificationData mNotificationData;
@@ -121,7 +114,6 @@ public class NotificationEntryManager implements
    public NotificationEntryManager(Context context) {
        mContext = context;
        mNotificationData = new NotificationData();
        mDeferredNotificationViewUpdateHandler = new Handler();
    }

    /** Adds a {@link NotificationEntryListener}. */
@@ -156,7 +148,6 @@ public class NotificationEntryManager implements
            NotificationListContainer listContainer,
            HeadsUpManager headsUpManager) {
        mPresenter = presenter;
        mUpdateNotificationViewsCallback = mPresenter::updateNotificationViews;
        mNotificationData.setHeadsUpManager(headsUpManager);
        mListContainer = listContainer;

@@ -229,15 +220,6 @@ public class NotificationEntryManager implements
        }
    }

    private void maybeScheduleUpdateNotificationViews(NotificationEntry entry) {
        long audibleAlertTimeout = RECENTLY_ALERTED_THRESHOLD_MS
                - (System.currentTimeMillis() - entry.lastAudiblyAlertedMs);
        if (audibleAlertTimeout > 0) {
            mDeferredNotificationViewUpdateHandler.postDelayed(
                    mUpdateNotificationViewsCallback, audibleAlertTimeout);
        }
    }

    @Override
    public void onAsyncInflationFinished(NotificationEntry entry,
            @InflationFlag int inflatedFlags) {
@@ -256,7 +238,6 @@ public class NotificationEntryManager implements
                for (NotificationEntryListener listener : mNotificationEntryListeners) {
                    listener.onNotificationAdded(entry);
                }
                maybeScheduleUpdateNotificationViews(entry);
            } else {
                for (NotificationEntryListener listener : mNotificationEntryListeners) {
                    listener.onEntryReinflated(entry);
@@ -463,8 +444,6 @@ public class NotificationEntryManager implements
        for (NotificationEntryListener listener : mNotificationEntryListeners) {
            listener.onPostEntryUpdated(entry);
        }

        maybeScheduleUpdateNotificationViews(entry);
    }

    @Override
+23 −8
Original line number Diff line number Diff line
@@ -86,7 +86,6 @@ import com.android.systemui.statusbar.RemoteInputController;
import com.android.systemui.statusbar.StatusBarIconView;
import com.android.systemui.statusbar.notification.AboveShelfChangedListener;
import com.android.systemui.statusbar.notification.ActivityLaunchAnimator;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -106,6 +105,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;

@@ -122,6 +122,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private static final int MENU_VIEW_INDEX = 0;
    private static final String TAG = "ExpandableNotifRow";
    public static final float DEFAULT_HEADER_VISIBLE_AMOUNT = 1.0f;
    private static final long RECENTLY_ALERTED_THRESHOLD_MS = TimeUnit.SECONDS.toMillis(30);
    private boolean mUpdateBackgroundOnUpdate;

    /**
@@ -1693,15 +1694,29 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    /** Sets the last time the notification being displayed audibly alerted the user. */
    public void setLastAudiblyAlertedMs(long lastAudiblyAlertedMs) {
        if (NotificationUtils.useNewInterruptionModel(mContext)) {
            boolean recentlyAudiblyAlerted = System.currentTimeMillis() - lastAudiblyAlertedMs
                    < NotificationEntryManager.RECENTLY_ALERTED_THRESHOLD_MS;
            if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() != null) {
                mChildrenContainer.getHeaderView().setRecentlyAudiblyAlerted(
                        recentlyAudiblyAlerted);
            long timeSinceAlertedAudibly = System.currentTimeMillis() - lastAudiblyAlertedMs;
            boolean alertedRecently =
                    timeSinceAlertedAudibly < RECENTLY_ALERTED_THRESHOLD_MS;

            applyAudiblyAlertedRecently(alertedRecently);

            removeCallbacks(mExpireRecentlyAlertedFlag);
            if (alertedRecently) {
                long timeUntilNoLongerRecent =
                        RECENTLY_ALERTED_THRESHOLD_MS - timeSinceAlertedAudibly;
                postDelayed(mExpireRecentlyAlertedFlag, timeUntilNoLongerRecent);
            }
        }
            mPrivateLayout.setRecentlyAudiblyAlerted(recentlyAudiblyAlerted);
            mPublicLayout.setRecentlyAudiblyAlerted(recentlyAudiblyAlerted);
    }

    private final Runnable mExpireRecentlyAlertedFlag = () -> applyAudiblyAlertedRecently(false);

    private void applyAudiblyAlertedRecently(boolean audiblyAlertedRecently) {
        if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() != null) {
            mChildrenContainer.getHeaderView().setRecentlyAudiblyAlerted(audiblyAlertedRecently);
        }
        mPrivateLayout.setRecentlyAudiblyAlerted(audiblyAlertedRecently);
        mPublicLayout.setRecentlyAudiblyAlerted(audiblyAlertedRecently);
    }

    public View.OnClickListener getAppOpsOnClickListener() {