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

Commit 955804d2 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Remove BypassHeadsUpNotifier and NotificationEntry.isAutoHeadsUp

Fixes: 216207506
Test: atest StatusBarTest
Change-Id: I7211db5595e2064b5998a418c4bf083749b04bbd
parent b60f95be
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -638,22 +638,6 @@ public final class NotificationEntry extends ListEntry {
        if (row != null) row.setHeadsUpAnimatingAway(animatingAway);
    }

    /**
     * Set that this notification was automatically heads upped. This happens for example when
     * the user bypasses the lockscreen and media is playing.
     */
    public void setAutoHeadsUp(boolean autoHeadsUp) {
        mAutoHeadsUp = autoHeadsUp;
    }

    /**
     * @return if this notification was automatically heads upped. This happens for example when
     *      * the user bypasses the lockscreen and media is playing.
     */
    public boolean isAutoHeadsUp() {
        return mAutoHeadsUp;
    }

    public boolean mustStayOnScreen() {
        return row != null && row.mustStayOnScreen();
    }
+1 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ class HeadsUpCoordinator @Inject constructor(
            if (wasHeadsUp) {
                if (shouldHeadsUp) {
                    mHeadsUpManager.updateNotification(entry.key, hunAgain)
                } else if (!mHeadsUpManager.isEntryAutoHeadsUpped(entry.key)) {
                } else {
                    // We don't want this to be interrupting anymore, let's remove it
                    mHeadsUpManager.removeNotification(
                        entry.key, false /* removeImmediately */
+0 −143
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.interruption

import android.content.Context
import android.media.MediaMetadata
import android.provider.Settings
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.NotificationLockscreenUserManager
import com.android.systemui.statusbar.NotificationMediaManager
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
import com.android.systemui.statusbar.phone.HeadsUpManagerPhone
import com.android.systemui.statusbar.phone.KeyguardBypassController
import com.android.systemui.tuner.TunerService
import javax.inject.Inject

/**
 * A class that automatically creates heads up for important notification when bypassing the
 * lockscreen
 */
@SysUISingleton
class BypassHeadsUpNotifier @Inject constructor(
    private val context: Context,
    private val bypassController: KeyguardBypassController,
    private val statusBarStateController: StatusBarStateController,
    private val headsUpManager: HeadsUpManagerPhone,
    private val notificationLockscreenUserManager: NotificationLockscreenUserManager,
    private val mediaManager: NotificationMediaManager,
    private val commonNotifCollection: CommonNotifCollection,
    tunerService: TunerService
) : StatusBarStateController.StateListener, NotificationMediaManager.MediaListener {

    private var currentMediaEntry: NotificationEntry? = null
    private var enabled = true

    var fullyAwake = false
        set(value) {
            field = value
            if (value) {
                updateAutoHeadsUp(currentMediaEntry)
            }
        }

    init {
        statusBarStateController.addCallback(this)
        tunerService.addTunable(
                TunerService.Tunable { _, _ ->
                    enabled = Settings.Secure.getIntForUser(
                            context.contentResolver,
                            Settings.Secure.SHOW_MEDIA_WHEN_BYPASSING,
                            0 /* default */,
                            KeyguardUpdateMonitor.getCurrentUser()) != 0
                }, Settings.Secure.SHOW_MEDIA_WHEN_BYPASSING)
    }

    fun setUp() {
        mediaManager.addCallback(this)
    }

    override fun onPrimaryMetadataOrStateChanged(metadata: MediaMetadata?, state: Int) {
        val previous = currentMediaEntry
        val mediaNotificationKey = mediaManager.mediaNotificationKey
        currentMediaEntry =
            if (mediaNotificationKey != null && NotificationMediaManager.isPlayingState(state))
                commonNotifCollection.getEntry(mediaNotificationKey)
            else null
        updateAutoHeadsUp(previous)
        updateAutoHeadsUp(currentMediaEntry)
    }

    private fun updateAutoHeadsUp(entry: NotificationEntry?) {
        entry?.let {
            val autoHeadsUp = it == currentMediaEntry && canAutoHeadsUp(it)
            it.isAutoHeadsUp = autoHeadsUp
            if (autoHeadsUp) {
                headsUpManager.showNotification(it)
            }
        }
    }

    /**
     * @return {@code true} if this entry be autoHeadsUpped right now.
     */
    private fun canAutoHeadsUp(entry: NotificationEntry): Boolean {
        if (!isAutoHeadsUpAllowed()) {
            return false
        }
        if (entry.isSensitive) {
            // filter sensitive notifications
            return false
        }
        if (!notificationLockscreenUserManager.shouldShowOnKeyguard(entry)) {
            // filter notifications invisible on Keyguard
            return false
        }
        if (commonNotifCollection.getEntry(entry.key) != null) {
            // filter notifications not the active list currently
            return false
        }
        return true
    }

    override fun onStatePostChange() {
        updateAutoHeadsUp(currentMediaEntry)
    }

    /**
     * @return {@code true} if autoHeadsUp is possible right now.
     */
    private fun isAutoHeadsUpAllowed(): Boolean {
        if (!enabled) {
            return false
        }
        if (!bypassController.bypassEnabled) {
            return false
        }
        if (statusBarStateController.state != StatusBarState.KEYGUARD) {
            return false
        }
        if (!fullyAwake) {
            return false
        }
        return true
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class HeadsUpController {
        if (wasHeadsUp) {
            if (shouldHeadsUp) {
                mHeadsUpManager.updateNotification(entry.getKey(), hunAgain);
            } else if (!mHeadsUpManager.isEntryAutoHeadsUpped(entry.getKey())) {
            } else {
                // We don't want this to be interrupting anymore, let's remove it
                mHeadsUpManager.removeNotification(entry.getKey(), false /* removeImmediately */);
            }
+4 −60
Original line number Diff line number Diff line
@@ -60,16 +60,14 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
    private final KeyguardBypassController mBypassController;
    private final GroupMembershipManager mGroupMembershipManager;
    private final List<OnHeadsUpPhoneListenerChange> mHeadsUpPhoneListeners = new ArrayList<>();
    private final int mAutoHeadsUpNotificationDecay;
    // TODO (b/162832756): remove visual stability manager when migrating to new pipeline
    private VisualStabilityManager mVisualStabilityManager;
    private boolean mReleaseOnExpandFinish;

    private boolean mTrackingHeadsUp;
    private HashSet<String> mSwipedOutKeys = new HashSet<>();
    private HashSet<NotificationEntry> mEntriesToRemoveAfterExpand = new HashSet<>();
    private HashSet<String> mKeysToRemoveWhenLeavingKeyguard = new HashSet<>();
    private ArraySet<NotificationEntry> mEntriesToRemoveWhenReorderingAllowed
    private final HashSet<String> mSwipedOutKeys = new HashSet<>();
    private final HashSet<NotificationEntry> mEntriesToRemoveAfterExpand = new HashSet<>();
    private final ArraySet<NotificationEntry> mEntriesToRemoveWhenReorderingAllowed
            = new ArraySet<>();
    private boolean mIsExpanded;
    private boolean mHeadsUpGoingAway;
@@ -110,8 +108,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
        super(context, logger);
        Resources resources = mContext.getResources();
        mExtensionTime = resources.getInteger(R.integer.ambient_notification_extension_time);
        mAutoHeadsUpNotificationDecay = resources.getInteger(
                R.integer.auto_heads_up_notification_decay);
        statusBarStateController.addCallback(mStatusBarStateListener);
        mBypassController = bypassController;
        mGroupMembershipManager = groupMembershipManager;
@@ -234,15 +230,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
        }
    }

    @Override
    public boolean isEntryAutoHeadsUpped(String key) {
        HeadsUpEntryPhone headsUpEntryPhone = getHeadsUpEntryPhone(key);
        if (headsUpEntryPhone == null) {
            return false;
        }
        return headsUpEntryPhone.isAutoHeadsUp();
    }

    /**
     * Set that we are exiting the headsUp pinned mode, but some notifications might still be
     * animating out. This is used to keep the touchable regions in a reasonable state.
@@ -375,7 +362,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,

    @Override
    protected void onAlertEntryRemoved(AlertEntry alertEntry) {
        mKeysToRemoveWhenLeavingKeyguard.remove(alertEntry.mEntry.getKey());
        super.onAlertEntryRemoved(alertEntry);
        mEntryPool.release((HeadsUpEntryPhone) alertEntry);
    }
@@ -437,11 +423,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
         */
        private boolean extended;

        /**
         * Was this entry received while on keyguard
         */
        private boolean mIsAutoHeadsUp;


        @Override
        public boolean isSticky() {
@@ -459,8 +440,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
                            false  /* persistent */);
                } else if (mTrackingHeadsUp) {
                    mEntriesToRemoveAfterExpand.add(entry);
                } else if (mIsAutoHeadsUp && mStatusBarState == StatusBarState.KEYGUARD) {
                    mKeysToRemoveWhenLeavingKeyguard.add(entry.getKey());
                } else {
                    removeAlertEntry(entry.getKey());
                }
@@ -471,7 +450,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,

        @Override
        public void updateEntry(boolean updatePostTime) {
            mIsAutoHeadsUp = mEntry.isAutoHeadsUp();
            super.updateEntry(updatePostTime);

            if (mEntriesToRemoveAfterExpand.contains(mEntry)) {
@@ -480,7 +458,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
            if (mEntriesToRemoveWhenReorderingAllowed.contains(mEntry)) {
                mEntriesToRemoveWhenReorderingAllowed.remove(mEntry);
            }
            mKeysToRemoveWhenLeavingKeyguard.remove(mEntry.getKey());
        }

        @Override
@@ -515,7 +492,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
            super.reset();
            mMenuShownPinned = false;
            extended = false;
            mIsAutoHeadsUp = false;
        }

        private void extendPulse() {
@@ -525,34 +501,9 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
            }
        }

        @Override
        public int compareTo(AlertEntry alertEntry) {
            HeadsUpEntryPhone headsUpEntry = (HeadsUpEntryPhone) alertEntry;
            boolean autoShown = isAutoHeadsUp();
            boolean otherAutoShown = headsUpEntry.isAutoHeadsUp();
            if (autoShown && !otherAutoShown) {
                return 1;
            } else if (!autoShown && otherAutoShown) {
                return -1;
            }
            return super.compareTo(alertEntry);
        }

        @Override
        protected long calculateFinishTime() {
            return mPostTime + getDecayDuration() + (extended ? mExtensionTime : 0);
        }

        private int getDecayDuration() {
            if (isAutoHeadsUp()) {
                return getRecommendedHeadsUpTimeoutMs(mAutoHeadsUpNotificationDecay);
            } else {
                return getRecommendedHeadsUpTimeoutMs(mAutoDismissNotificationDecay);
            }
        }

        private boolean isAutoHeadsUp() {
            return mIsAutoHeadsUp;
            return super.calculateFinishTime() + (extended ? mExtensionTime : 0);
        }
    }

@@ -577,13 +528,6 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
            boolean wasKeyguard = mStatusBarState == StatusBarState.KEYGUARD;
            boolean isKeyguard = newState == StatusBarState.KEYGUARD;
            mStatusBarState = newState;
            if (wasKeyguard && !isKeyguard && mKeysToRemoveWhenLeavingKeyguard.size() != 0) {
                String[] keys = mKeysToRemoveWhenLeavingKeyguard.toArray(new String[0]);
                for (String key : keys) {
                    removeAlertEntry(key);
                }
                mKeysToRemoveWhenLeavingKeyguard.clear();
            }
            if (wasKeyguard && !isKeyguard && mBypassController.getBypassEnabled()) {
                ArrayList<String> keysToRemove = new ArrayList<>();
                for (AlertEntry entry : mAlertEntries.values()) {
Loading