Merge "Remove BypassHeadsUpNotifier and NotificationEntry.isAutoHeadsUp"

This commit is contained in:
Jeff DeCew
2022-01-25 14:32:00 +00:00
committed by Android (Google) Code Review
9 changed files with 6 additions and 238 deletions

View File

@@ -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();
}

View File

@@ -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 */

View File

@@ -1,143 +0,0 @@
/*
* 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
}
}

View File

@@ -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 */);
}

View File

@@ -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()) {

View File

@@ -211,7 +211,6 @@ import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator
import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager;
import com.android.systemui.statusbar.notification.collection.render.NotifShadeEventSource;
import com.android.systemui.statusbar.notification.init.NotificationsController;
import com.android.systemui.statusbar.notification.interruption.BypassHeadsUpNotifier;
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
@@ -482,7 +481,6 @@ public class StatusBar extends CoreStartable implements
private final HeadsUpManagerPhone mHeadsUpManager;
private final StatusBarTouchableRegionManager mStatusBarTouchableRegionManager;
private final DynamicPrivacyController mDynamicPrivacyController;
private final BypassHeadsUpNotifier mBypassHeadsUpNotifier;
private final FalsingCollector mFalsingCollector;
private final FalsingManager mFalsingManager;
private final BroadcastDispatcher mBroadcastDispatcher;
@@ -703,7 +701,6 @@ public class StatusBar extends CoreStartable implements
KeyguardStateController keyguardStateController,
HeadsUpManagerPhone headsUpManagerPhone,
DynamicPrivacyController dynamicPrivacyController,
BypassHeadsUpNotifier bypassHeadsUpNotifier,
FalsingManager falsingManager,
FalsingCollector falsingCollector,
BroadcastDispatcher broadcastDispatcher,
@@ -800,7 +797,6 @@ public class StatusBar extends CoreStartable implements
mKeyguardIndicationController = keyguardIndicationController;
mStatusBarTouchableRegionManager = statusBarTouchableRegionManager;
mDynamicPrivacyController = dynamicPrivacyController;
mBypassHeadsUpNotifier = bypassHeadsUpNotifier;
mFalsingCollector = falsingCollector;
mFalsingManager = falsingManager;
mBroadcastDispatcher = broadcastDispatcher;
@@ -917,7 +913,6 @@ public class StatusBar extends CoreStartable implements
mScreenLifecycle.addObserver(mScreenObserver);
mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
mUiModeManager = mContext.getSystemService(UiModeManager.class);
mBypassHeadsUpNotifier.setUp();
if (mBubblesOptional.isPresent()) {
mBubblesOptional.get().setExpandListener(mBubbleExpandListener);
}
@@ -3581,7 +3576,6 @@ public class StatusBar extends CoreStartable implements
maybeEscalateHeadsUp();
dismissVolumeDialog();
mWakeUpCoordinator.setFullyAwake(false);
mBypassHeadsUpNotifier.setFullyAwake(false);
mKeyguardBypassController.onStartedGoingToSleep();
// The unlocked screen off and fold to aod animations might use our LightRevealScrim -
@@ -3623,7 +3617,6 @@ public class StatusBar extends CoreStartable implements
@Override
public void onFinishedWakingUp() {
mWakeUpCoordinator.setFullyAwake(true);
mBypassHeadsUpNotifier.setFullyAwake(true);
mWakeUpCoordinator.setWakingUp(false);
if (mLaunchCameraWhenFinishedWaking) {
mNotificationPanelViewController.launchCamera(

View File

@@ -71,7 +71,6 @@ import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator
import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager;
import com.android.systemui.statusbar.notification.collection.render.NotifShadeEventSource;
import com.android.systemui.statusbar.notification.init.NotificationsController;
import com.android.systemui.statusbar.notification.interruption.BypassHeadsUpNotifier;
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
@@ -152,7 +151,6 @@ public interface StatusBarPhoneModule {
KeyguardStateController keyguardStateController,
HeadsUpManagerPhone headsUpManagerPhone,
DynamicPrivacyController dynamicPrivacyController,
BypassHeadsUpNotifier bypassHeadsUpNotifier,
FalsingManager falsingManager,
FalsingCollector falsingCollector,
BroadcastDispatcher broadcastDispatcher,
@@ -250,7 +248,6 @@ public interface StatusBarPhoneModule {
keyguardStateController,
headsUpManagerPhone,
dynamicPrivacyController,
bypassHeadsUpNotifier,
falsingManager,
falsingCollector,
broadcastDispatcher,

View File

@@ -378,10 +378,6 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
public void onDensityOrFontScaleChanged() {
}
public boolean isEntryAutoHeadsUpped(String key) {
return false;
}
/**
* Determines if the notification is for a critical call that must display on top of an active
* input notification.

View File

@@ -129,7 +129,6 @@ import com.android.systemui.statusbar.notification.collection.legacy.VisualStabi
import com.android.systemui.statusbar.notification.collection.render.NotifShadeEventSource;
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
import com.android.systemui.statusbar.notification.init.NotificationsController;
import com.android.systemui.statusbar.notification.interruption.BypassHeadsUpNotifier;
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.logging.NotificationPanelLoggerFake;
@@ -226,7 +225,6 @@ public class StatusBarTest extends SysuiTestCase {
@Mock private NotificationMediaManager mNotificationMediaManager;
@Mock private NavigationBarController mNavigationBarController;
@Mock private AccessibilityFloatingMenuController mAccessibilityFloatingMenuController;
@Mock private BypassHeadsUpNotifier mBypassHeadsUpNotifier;
@Mock private SysuiColorExtractor mColorExtractor;
@Mock private ColorExtractor.GradientColors mGradientColors;
@Mock private PulseExpansionHandler mPulseExpansionHandler;
@@ -394,7 +392,6 @@ public class StatusBarTest extends SysuiTestCase {
mKeyguardStateController,
mHeadsUpManager,
mDynamicPrivacyController,
mBypassHeadsUpNotifier,
new FalsingManagerFake(),
new FalsingCollectorFake(),
mBroadcastDispatcher,