Merge "Replace KeyguardBypassEnabledProvider with push-based field" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-07-13 21:24:43 +00:00
committed by Android (Google) Code Review
5 changed files with 67 additions and 26 deletions

View File

@@ -155,7 +155,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
* gap is drawn between them). In this case we don't want to round their corners. * gap is drawn between them). In this case we don't want to round their corners.
*/ */
private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1; private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1;
private KeyguardBypassEnabledProvider mKeyguardBypassEnabledProvider; private boolean mKeyguardBypassEnabled;
private ExpandHelper mExpandHelper; private ExpandHelper mExpandHelper;
private NotificationSwipeHelper mSwipeHelper; private NotificationSwipeHelper mSwipeHelper;
@@ -649,13 +649,21 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
inflateFooterView(); inflateFooterView();
} }
/**
* Sets whether keyguard bypass is enabled. If true, this layout will be rendered in bypass
* mode when it is on the keyguard.
*/
public void setKeyguardBypassEnabled(boolean isEnabled) {
mKeyguardBypassEnabled = isEnabled;
}
/** /**
* @return the height at which we will wake up when pulsing * @return the height at which we will wake up when pulsing
*/ */
public float getWakeUpHeight() { public float getWakeUpHeight() {
ExpandableView firstChild = getFirstChildWithBackground(); ExpandableView firstChild = getFirstChildWithBackground();
if (firstChild != null) { if (firstChild != null) {
if (mKeyguardBypassEnabledProvider.getBypassEnabled()) { if (mKeyguardBypassEnabled) {
return firstChild.getHeadsUpHeightWithoutHeader(); return firstChild.getHeadsUpHeightWithoutHeader();
} else { } else {
return firstChild.getCollapsedHeight(); return firstChild.getCollapsedHeight();
@@ -783,7 +791,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
} }
} }
boolean shouldDrawBackground; boolean shouldDrawBackground;
if (mKeyguardBypassEnabledProvider.getBypassEnabled() && onKeyguard()) { if (mKeyguardBypassEnabled && onKeyguard()) {
shouldDrawBackground = isPulseExpanding(); shouldDrawBackground = isPulseExpanding();
} else { } else {
shouldDrawBackground = !mAmbientState.isDozing() || anySectionHasVisibleChild; shouldDrawBackground = !mAmbientState.isDozing() || anySectionHasVisibleChild;
@@ -898,15 +906,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
} }
private void reinitView() { private void reinitView() {
initView(getContext(), mKeyguardBypassEnabledProvider, mSwipeHelper); initView(getContext(), mSwipeHelper);
} }
@ShadeViewRefactor(RefactorComponent.SHADE_VIEW) @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
void initView(Context context, void initView(Context context, NotificationSwipeHelper swipeHelper) {
KeyguardBypassEnabledProvider keyguardBypassEnabledProvider,
NotificationSwipeHelper swipeHelper) {
mScroller = new OverScroller(getContext()); mScroller = new OverScroller(getContext());
mKeyguardBypassEnabledProvider = keyguardBypassEnabledProvider;
mSwipeHelper = swipeHelper; mSwipeHelper = swipeHelper;
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
@@ -1346,7 +1351,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
private void notifyAppearChangedListeners() { private void notifyAppearChangedListeners() {
float appear; float appear;
float expandAmount; float expandAmount;
if (mKeyguardBypassEnabledProvider.getBypassEnabled() && onKeyguard()) { if (mKeyguardBypassEnabled && onKeyguard()) {
appear = calculateAppearFractionBypass(); appear = calculateAppearFractionBypass();
expandAmount = getPulseHeight(); expandAmount = getPulseHeight();
} else { } else {
@@ -2384,8 +2389,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
minTopPosition = firstVisibleSection.getBounds().top; minTopPosition = firstVisibleSection.getBounds().top;
} }
boolean shiftPulsingWithFirst = mNumHeadsUp <= 1 boolean shiftPulsingWithFirst = mNumHeadsUp <= 1
&& (mAmbientState.isDozing() && (mAmbientState.isDozing() || (mKeyguardBypassEnabled && onKeyguard));
|| (mKeyguardBypassEnabledProvider.getBypassEnabled() && onKeyguard));
for (NotificationSection section : mSections) { for (NotificationSection section : mSections) {
int minBottomPosition = minTopPosition; int minBottomPosition = minTopPosition;
if (section == lastSection) { if (section == lastSection) {
@@ -2528,7 +2532,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
} else { } else {
mTopPaddingOverflow = 0; mTopPaddingOverflow = 0;
} }
setTopPadding(topPadding, animate && !mKeyguardBypassEnabledProvider.getBypassEnabled()); setTopPadding(topPadding, animate && !mKeyguardBypassEnabled);
setExpandedHeight(mExpandedHeight); setExpandedHeight(mExpandedHeight);
} }
@@ -3092,7 +3096,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
boolean performDisappearAnimation = !mIsExpanded boolean performDisappearAnimation = !mIsExpanded
// Only animate if we still have pinned heads up, otherwise we just have the // Only animate if we still have pinned heads up, otherwise we just have the
// regular collapse animation of the lock screen // regular collapse animation of the lock screen
|| (mKeyguardBypassEnabledProvider.getBypassEnabled() && onKeyguard() || (mKeyguardBypassEnabled && onKeyguard()
&& mInHeadsUpPinnedMode); && mInHeadsUpPinnedMode);
if (performDisappearAnimation && !isHeadsUp) { if (performDisappearAnimation && !isHeadsUp) {
type = row.wasJustClicked() type = row.wasJustClicked()
@@ -4315,7 +4319,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
// Since we are clipping to the outline we need to make sure that the shadows aren't // Since we are clipping to the outline we need to make sure that the shadows aren't
// clipped when pulsing // clipped when pulsing
float ownTranslationZ = 0; float ownTranslationZ = 0;
if (mKeyguardBypassEnabledProvider.getBypassEnabled() && mAmbientState.isHiddenAtAll()) { if (mKeyguardBypassEnabled && mAmbientState.isHiddenAtAll()) {
ExpandableView firstChildNotGone = getFirstChildNotGone(); ExpandableView firstChildNotGone = getFirstChildNotGone();
if (firstChildNotGone != null && firstChildNotGone.showingPulsing()) { if (firstChildNotGone != null && firstChildNotGone.showingPulsing()) {
ownTranslationZ = firstChildNotGone.getTranslationZ(); ownTranslationZ = firstChildNotGone.getTranslationZ();
@@ -5138,7 +5142,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
*/ */
public float setPulseHeight(float height) { public float setPulseHeight(float height) {
mAmbientState.setPulseHeight(height); mAmbientState.setPulseHeight(height);
if (mKeyguardBypassEnabledProvider.getBypassEnabled()) { if (mKeyguardBypassEnabled) {
notifyAppearChangedListeners(); notifyAppearChangedListeners();
} }
requestChildrenUpdate(); requestChildrenUpdate();
@@ -6069,10 +6073,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
/** Only rows where entry.isHighPriority() is false. */ /** Only rows where entry.isHighPriority() is false. */
public static final int ROWS_GENTLE = 2; public static final int ROWS_GENTLE = 2;
interface KeyguardBypassEnabledProvider {
boolean getBypassEnabled();
}
interface DismissListener { interface DismissListener {
void onDismiss(@SelectedRows int selectedRows); void onDismiss(@SelectedRows int selectedRows);
} }

View File

@@ -708,8 +708,10 @@ public class NotificationStackScrollLayoutController {
}); });
} }
mView.initView(mView.getContext(), mKeyguardBypassController::getBypassEnabled, mView.initView(mView.getContext(), mSwipeHelper);
mSwipeHelper); mView.setKeyguardBypassEnabled(mKeyguardBypassController.getBypassEnabled());
mKeyguardBypassController
.registerOnBypassStateChangedListener(mView::setKeyguardBypassEnabled);
mHeadsUpManager.addListener(mOnHeadsUpChangedListener); mHeadsUpManager.addListener(mOnHeadsUpChangedListener);
mHeadsUpManager.setAnimationStateHandler(mView::setHeadsUpGoingAwayAnimationsAllowed); mHeadsUpManager.setAnimationStateHandler(mView::setHeadsUpGoingAwayAnimationsAllowed);

View File

@@ -43,6 +43,11 @@ open class KeyguardBypassController : Dumpable, StackScrollAlgorithm.BypassContr
@BypassOverride private val bypassOverride: Int @BypassOverride private val bypassOverride: Int
private var hasFaceFeature: Boolean private var hasFaceFeature: Boolean
private var pendingUnlock: PendingUnlock? = null private var pendingUnlock: PendingUnlock? = null
private val listeners = mutableListOf<OnBypassStateChangedListener>()
private val faceAuthEnabledChangedCallback = object : KeyguardStateController.Callback {
override fun onFaceAuthEnabledChanged() = notifyListeners()
}
@IntDef( @IntDef(
FACE_UNLOCK_BYPASS_NO_OVERRIDE, FACE_UNLOCK_BYPASS_NO_OVERRIDE,
@@ -83,7 +88,10 @@ open class KeyguardBypassController : Dumpable, StackScrollAlgorithm.BypassContr
} }
return enabled && mKeyguardStateController.isFaceAuthEnabled return enabled && mKeyguardStateController.isFaceAuthEnabled
} }
private set private set(value) {
field = value
notifyListeners()
}
var bouncerShowing: Boolean = false var bouncerShowing: Boolean = false
var altBouncerShowing: Boolean = false var altBouncerShowing: Boolean = false
@@ -140,6 +148,8 @@ open class KeyguardBypassController : Dumpable, StackScrollAlgorithm.BypassContr
}) })
} }
private fun notifyListeners() = listeners.forEach { it.onBypassStateChanged(bypassEnabled) }
/** /**
* Notify that the biometric unlock has happened. * Notify that the biometric unlock has happened.
* *
@@ -223,6 +233,32 @@ open class KeyguardBypassController : Dumpable, StackScrollAlgorithm.BypassContr
pw.println(" hasFaceFeature: $hasFaceFeature") pw.println(" hasFaceFeature: $hasFaceFeature")
} }
/** Registers a listener for bypass state changes. */
fun registerOnBypassStateChangedListener(listener: OnBypassStateChangedListener) {
val start = listeners.isEmpty()
listeners.add(listener)
if (start) {
mKeyguardStateController.addCallback(faceAuthEnabledChangedCallback)
}
}
/**
* Unregisters a listener for bypass state changes, previous registered with
* [registerOnBypassStateChangedListener]
*/
fun unregisterOnBypassStateChangedListener(listener: OnBypassStateChangedListener) {
listeners.remove(listener)
if (listeners.isEmpty()) {
mKeyguardStateController.removeCallback(faceAuthEnabledChangedCallback)
}
}
/** Listener for bypass state change events. */
interface OnBypassStateChangedListener {
/** Invoked when bypass becomes enabled or disabled. */
fun onBypassStateChanged(isEnabled: Boolean)
}
companion object { companion object {
const val BYPASS_FADE_DURATION = 67 const val BYPASS_FADE_DURATION = 67

View File

@@ -245,5 +245,11 @@ public interface KeyguardStateController extends CallbackController<Callback> {
* animation. * animation.
*/ */
default void onKeyguardDismissAmountChanged() {} default void onKeyguardDismissAmountChanged() {}
/**
* Triggered when face auth becomes available or unavailable. Value should be queried with
* {@link KeyguardStateController#isFaceAuthEnabled()}.
*/
default void onFaceAuthEnabledChanged() {}
} }
} }

View File

@@ -63,7 +63,6 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy; import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.FooterView; import com.android.systemui.statusbar.notification.row.FooterView;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.KeyguardBypassEnabledProvider;
import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.phone.StatusBar;
@@ -101,7 +100,6 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
@Mock private NotificationRemoteInputManager mRemoteInputManager; @Mock private NotificationRemoteInputManager mRemoteInputManager;
@Mock private RemoteInputController mRemoteInputController; @Mock private RemoteInputController mRemoteInputController;
@Mock private NotificationRoundnessManager mNotificationRoundnessManager; @Mock private NotificationRoundnessManager mNotificationRoundnessManager;
@Mock private KeyguardBypassEnabledProvider mKeyguardBypassEnabledProvider;
@Mock private KeyguardBypassController mBypassController; @Mock private KeyguardBypassController mBypassController;
@Mock private NotificationSectionsManager mNotificationSectionsManager; @Mock private NotificationSectionsManager mNotificationSectionsManager;
@Mock private NotificationSection mNotificationSection; @Mock private NotificationSection mNotificationSection;
@@ -150,8 +148,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
mAmbientState, mAmbientState,
mFeatureFlags, mFeatureFlags,
mUnlockedScreenOffAnimationController); mUnlockedScreenOffAnimationController);
mStackScrollerInternal.initView(getContext(), mKeyguardBypassEnabledProvider, mStackScrollerInternal.initView(getContext(), mNotificationSwipeHelper);
mNotificationSwipeHelper);
mStackScroller = spy(mStackScrollerInternal); mStackScroller = spy(mStackScrollerInternal);
mStackScroller.setShelfController(notificationShelfController); mStackScroller.setShelfController(notificationShelfController);
mStackScroller.setStatusBar(mBar); mStackScroller.setStatusBar(mBar);