Merge changes I5887c0b0,Iae05381b into udc-dev

* changes:
  Replace NSSLController usage in NotifShelf w/ NSSL
  Remove StatusBarStateListener from NotifShelf
This commit is contained in:
Steve Elliott
2023-04-11 21:30:12 +00:00
committed by Android (Google) Code Review
11 changed files with 248 additions and 40 deletions

View File

@@ -3333,7 +3333,10 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
mGestureRecorder = recorder;
mHideExpandedRunnable = hideExpandedRunnable;
mNotificationStackScrollLayoutController.setShelfController(notificationShelfController);
if (!mFeatureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR)) {
mNotificationStackScrollLayoutController.setShelfController(
notificationShelfController);
}
mNotificationShelfController = notificationShelfController;
mLockscreenShadeTransitionController.bindController(notificationShelfController);
updateMaxDisplayedNotifications(true);

View File

@@ -53,6 +53,8 @@ import com.android.systemui.statusbar.notification.row.ExpandableView;
import com.android.systemui.statusbar.notification.stack.AmbientState;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
import com.android.systemui.statusbar.notification.stack.NotificationRoundnessManager;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController;
import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm;
import com.android.systemui.statusbar.notification.stack.ViewState;
@@ -99,6 +101,9 @@ public class NotificationShelf extends ActivatableNotificationView implements St
private boolean mSensitiveRevealAnimEndabled;
private boolean mShelfRefactorFlagEnabled;
private boolean mCanModifyColorOfNotifications;
private boolean mCanInteract;
private NotificationStackScrollLayout mHostLayout;
private NotificationRoundnessManager mRoundnessManager;
public NotificationShelf(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -135,6 +140,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St
public void bind(AmbientState ambientState,
NotificationStackScrollLayoutController hostLayoutController) {
assertRefactorFlagDisabled();
mAmbientState = ambientState;
mHostLayoutController = hostLayoutController;
hostLayoutController.setOnNotificationRemovedListener((child, isTransferInProgress) -> {
@@ -142,6 +148,14 @@ public class NotificationShelf extends ActivatableNotificationView implements St
});
}
public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout,
NotificationRoundnessManager roundnessManager) {
if (!checkRefactorFlagEnabled()) return;
mAmbientState = ambientState;
mHostLayout = hostLayout;
mRoundnessManager = roundnessManager;
}
private void updateResources() {
Resources res = getResources();
mStatusBarHeight = SystemBarUtils.getStatusBarHeight(mContext);
@@ -233,7 +247,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St
} else {
viewState.setAlpha(1f - ambientState.getHideAmount());
}
viewState.belowSpeedBump = mHostLayoutController.getSpeedBumpIndex() == 0;
viewState.belowSpeedBump = getSpeedBumpIndex() == 0;
viewState.hideSensitive = false;
viewState.setXTranslation(getTranslationX());
viewState.hasItemsInStableShelf = lastViewState.inShelf;
@@ -276,6 +290,14 @@ public class NotificationShelf extends ActivatableNotificationView implements St
}
}
private int getSpeedBumpIndex() {
if (mShelfRefactorFlagEnabled) {
return mHostLayout.getSpeedBumpIndex();
} else {
return mHostLayoutController.getSpeedBumpIndex();
}
}
/**
* @param fractionToShade Fraction of lockscreen to shade transition
* @param shortestWidth Shortest width to use for lockscreen shelf
@@ -388,8 +410,8 @@ public class NotificationShelf extends ActivatableNotificationView implements St
int baseZHeight = mAmbientState.getBaseZHeight();
int clipTopAmount = 0;
for (int i = 0; i < mHostLayoutController.getChildCount(); i++) {
ExpandableView child = mHostLayoutController.getChildAt(i);
for (int i = 0; i < getHostLayoutChildCount(); i++) {
ExpandableView child = getHostLayoutChildAt(i);
if (!child.needsClippingToShelf() || child.getVisibility() == GONE) {
continue;
}
@@ -474,11 +496,11 @@ public class NotificationShelf extends ActivatableNotificationView implements St
// TODO(b/172289889) transition last icon in shelf to notification icon and vice versa.
setVisibility(isHidden ? View.INVISIBLE : View.VISIBLE);
mShelfIcons.setSpeedBumpIndex(mHostLayoutController.getSpeedBumpIndex());
mShelfIcons.setSpeedBumpIndex(getSpeedBumpIndex());
mShelfIcons.calculateIconXTranslations();
mShelfIcons.applyIconStates();
for (int i = 0; i < mHostLayoutController.getChildCount(); i++) {
View child = mHostLayoutController.getChildAt(i);
for (int i = 0; i < getHostLayoutChildCount(); i++) {
View child = getHostLayoutChildAt(i);
if (!(child instanceof ExpandableNotificationRow)
|| child.getVisibility() == GONE) {
continue;
@@ -493,6 +515,22 @@ public class NotificationShelf extends ActivatableNotificationView implements St
}
}
private ExpandableView getHostLayoutChildAt(int index) {
if (mShelfRefactorFlagEnabled) {
return (ExpandableView) mHostLayout.getChildAt(index);
} else {
return mHostLayoutController.getChildAt(index);
}
}
private int getHostLayoutChildCount() {
if (mShelfRefactorFlagEnabled) {
return mHostLayout.getChildCount();
} else {
return mHostLayoutController.getChildCount();
}
}
private boolean canModifyColorOfNotifications() {
if (mShelfRefactorFlagEnabled) {
return mCanModifyColorOfNotifications && mAmbientState.isShadeExpanded();
@@ -515,7 +553,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St
&& anv == mAmbientState.getTrackedHeadsUpRow();
final boolean shouldUpdateCornerRoundness = viewStart < shelfStart
&& !mHostLayoutController.isViewAffectedBySwipe(anv)
&& !isViewAffectedBySwipe(anv)
&& !isUnlockedHeadsUp
&& !isHunGoingToShade
&& !anv.isAboveShelf()
@@ -567,6 +605,14 @@ public class NotificationShelf extends ActivatableNotificationView implements St
anv.requestBottomRoundness(bottomValue, sourceType, /* animate = */ false);
}
private boolean isViewAffectedBySwipe(ExpandableView expandableView) {
if (!mShelfRefactorFlagEnabled) {
return mHostLayoutController.isViewAffectedBySwipe(expandableView);
} else {
return mRoundnessManager.isViewAffectedBySwipe(expandableView);
}
}
/**
* Clips transient views to the top of the shelf - Transient views are only used for
* disappearing views/animations and need to be clipped correctly by the shelf to ensure they
@@ -574,8 +620,8 @@ public class NotificationShelf extends ActivatableNotificationView implements St
* swipes quickly.
*/
private void clipTransientViews() {
for (int i = 0; i < mHostLayoutController.getTransientViewCount(); i++) {
View transientView = mHostLayoutController.getTransientView(i);
for (int i = 0; i < getHostLayoutTransientViewCount(); i++) {
View transientView = getHostLayoutTransientView(i);
if (transientView instanceof ExpandableView) {
ExpandableView transientExpandableView = (ExpandableView) transientView;
updateNotificationClipHeight(transientExpandableView, getTranslationY(), -1);
@@ -583,6 +629,22 @@ public class NotificationShelf extends ActivatableNotificationView implements St
}
}
private View getHostLayoutTransientView(int index) {
if (mShelfRefactorFlagEnabled) {
return mHostLayout.getTransientView(index);
} else {
return mHostLayoutController.getTransientView(index);
}
}
private int getHostLayoutTransientViewCount() {
if (mShelfRefactorFlagEnabled) {
return mHostLayout.getTransientViewCount();
} else {
return mHostLayoutController.getTransientViewCount();
}
}
private void updateIconClipAmount(ExpandableNotificationRow row) {
float maxTop = row.getTranslationY();
if (getClipTopAmount() != 0) {
@@ -922,18 +984,27 @@ public class NotificationShelf extends ActivatableNotificationView implements St
@Override
public void onStateChanged(int newState) {
assertRefactorFlagDisabled();
mStatusBarState = newState;
updateInteractiveness();
}
private void updateInteractiveness() {
mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf;
mInteractive = canInteract() && mHasItemsInStableShelf;
setClickable(mInteractive);
setFocusable(mInteractive);
setImportantForAccessibility(mInteractive ? View.IMPORTANT_FOR_ACCESSIBILITY_YES
: View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
}
private boolean canInteract() {
if (mShelfRefactorFlagEnabled) {
return mCanInteract;
} else {
return mStatusBarState == StatusBarState.KEYGUARD;
}
}
@Override
protected boolean isInteractive() {
return mInteractive;
@@ -972,8 +1043,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St
private void assertRefactorFlagDisabled() {
if (mShelfRefactorFlagEnabled) {
throw new IllegalStateException(
"Code path not supported when Flags.NOTIFICATION_SHELF_REFACTOR is enabled.");
NotificationShelfController.throwIllegalFlagStateError(false);
}
}
@@ -995,8 +1065,22 @@ public class NotificationShelf extends ActivatableNotificationView implements St
mCanModifyColorOfNotifications = canModifyColorOfNotifications;
}
public void setCanInteract(boolean canInteract) {
if (!checkRefactorFlagEnabled()) return;
mCanInteract = canInteract;
updateInteractiveness();
}
public void setIndexOfFirstViewInShelf(ExpandableView firstViewInShelf) {
mIndexOfFirstViewInShelf = mHostLayoutController.indexOfChild(firstViewInShelf);
mIndexOfFirstViewInShelf = getIndexOfViewInHostLayout(firstViewInShelf);
}
private int getIndexOfViewInHostLayout(ExpandableView child) {
if (mShelfRefactorFlagEnabled) {
return mHostLayout.indexOfChild(child);
} else {
return mHostLayoutController.indexOfChild(child);
}
}
/**
@@ -1011,6 +1095,11 @@ public class NotificationShelf extends ActivatableNotificationView implements St
mShelfRefactorFlagEnabled = enabled;
}
public void requestRoundnessResetFor(ExpandableView child) {
if (!checkRefactorFlagEnabled()) return;
child.requestRoundnessReset(SHELF_SCROLL);
}
/**
* This method resets the OnScroll roundness of a view to 0f
* <p>

View File

@@ -16,8 +16,11 @@
package com.android.systemui.statusbar
import android.util.Log
import android.view.View
import android.view.View.OnClickListener
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView.OnActivatedListener
import com.android.systemui.statusbar.notification.row.ExpandableView
@@ -51,4 +54,29 @@ interface NotificationShelfController {
/** @see View.setOnClickListener */
fun setOnClickListener(listener: OnClickListener)
companion object {
@JvmStatic
fun assertRefactorFlagDisabled(featureFlags: FeatureFlags) {
if (featureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR)) {
throwIllegalFlagStateError(expected = false)
}
}
@JvmStatic
fun checkRefactorFlagEnabled(featureFlags: FeatureFlags): Boolean =
featureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR).also { enabled ->
if (!enabled) {
Log.wtf("NotifShelf", getErrorMessage(expected = true))
}
}
@JvmStatic
fun throwIllegalFlagStateError(expected: Boolean): Nothing =
error(getErrorMessage(expected))
private fun getErrorMessage(expected: Boolean): String =
"Code path not supported when Flags.NOTIFICATION_SHELF_REFACTOR is " +
if (expected) "disabled" else "enabled"
}
}

View File

@@ -32,6 +32,10 @@ constructor(
private val keyguardRepository: KeyguardRepository,
private val deviceEntryFaceAuthRepository: DeviceEntryFaceAuthRepository,
) {
/** Is the shelf showing on the keyguard? */
val isShowingOnKeyguard: Flow<Boolean>
get() = keyguardRepository.isKeyguardShowing
/** Is the system in a state where the shelf is just a static display of notification icons? */
val isShelfStatic: Flow<Boolean>
get() =

View File

@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.notification.shelf.ui.viewbinder
import android.view.View
import android.view.View.OnAttachStateChangeListener
import android.view.accessibility.AccessibilityManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
@@ -29,7 +28,6 @@ import com.android.systemui.plugins.FalsingManager
import com.android.systemui.statusbar.LegacyNotificationShelfControllerImpl
import com.android.systemui.statusbar.NotificationShelf
import com.android.systemui.statusbar.NotificationShelfController
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView
import com.android.systemui.statusbar.notification.row.ActivatableNotificationViewController
import com.android.systemui.statusbar.notification.row.ExpandableOutlineViewController
@@ -40,9 +38,11 @@ import com.android.systemui.statusbar.notification.stack.NotificationStackScroll
import com.android.systemui.statusbar.phone.NotificationIconContainer
import com.android.systemui.statusbar.phone.NotificationTapHelper
import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent.CentralSurfacesScope
import com.android.systemui.util.kotlin.getValue
import dagger.Lazy
import javax.inject.Inject
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import javax.inject.Inject
/**
* Controller class for [NotificationShelf]. This implementation serves as a temporary wrapper
@@ -61,11 +61,13 @@ constructor(
private val a11yManager: AccessibilityManager,
private val falsingManager: FalsingManager,
private val falsingCollector: FalsingCollector,
private val statusBarStateController: SysuiStatusBarStateController,
hostControllerLazy: Lazy<NotificationStackScrollLayoutController>,
) : NotificationShelfController {
private val hostController: NotificationStackScrollLayoutController by hostControllerLazy
override val view: NotificationShelf
get() = shelf
get() = unsupported
init {
shelf.apply {
@@ -87,22 +89,9 @@ constructor(
falsingCollector,
)
.init()
val onAttachStateListener =
object : OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
statusBarStateController.addCallback(
shelf,
SysuiStatusBarStateController.RANK_SHELF,
)
}
override fun onViewDetachedFromWindow(v: View) {
statusBarStateController.removeCallback(shelf)
}
}
shelf.addOnAttachStateChangeListener(onAttachStateListener)
if (shelf.isAttachedToWindow) {
onAttachStateListener.onViewAttachedToWindow(shelf)
hostController.setShelf(shelf)
hostController.setOnNotificationRemovedListener { child, _ ->
view.requestRoundnessResetFor(child)
}
}
@@ -121,16 +110,14 @@ constructor(
override fun bind(
ambientState: AmbientState,
notificationStackScrollLayoutController: NotificationStackScrollLayoutController,
) {
shelf.bind(ambientState, notificationStackScrollLayoutController)
}
) = unsupported
override fun setOnClickListener(listener: View.OnClickListener) {
shelf.setOnClickListener(listener)
}
private val unsupported: Nothing
get() = error("Code path not supported when Flags.NOTIFICATION_SHELF_REFACTOR is enabled")
get() = NotificationShelfController.throwIllegalFlagStateError(expected = true)
}
/** Binds a [NotificationShelf] to its backend. */
@@ -141,6 +128,7 @@ object NotificationShelfViewBinder {
viewModel.canModifyColorOfNotifications
.onEach(shelf::setCanModifyColorOfNotifications)
.launchIn(this)
viewModel.isClickable.onEach(shelf::setCanInteract).launchIn(this)
}
}
}

View File

@@ -30,6 +30,10 @@ class NotificationShelfViewModel
constructor(
private val interactor: NotificationShelfInteractor,
) {
/** Is the shelf allowed to be clickable when it has content? */
val isClickable: Flow<Boolean>
get() = interactor.isShowingOnKeyguard
/** Is the shelf allowed to modify the color of notifications in the host layout? */
val canModifyColorOfNotifications: Flow<Boolean>
get() = interactor.isShelfStatic.map { static -> !static }

View File

@@ -5137,8 +5137,26 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
requestChildrenUpdate();
}
public void setShelf(NotificationShelf shelf) {
if (!NotificationShelfController.checkRefactorFlagEnabled(
mAmbientState.getFeatureFlags())) {
return;
}
int index = -1;
if (mShelf != null) {
index = indexOfChild(mShelf);
removeView(mShelf);
}
mShelf = shelf;
addView(mShelf, index);
mAmbientState.setShelf(mShelf);
mStateAnimator.setShelf(mShelf);
shelf.bind(mAmbientState, this, mController.getNotificationRoundnessManager());
}
@ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
public void setShelfController(NotificationShelfController notificationShelfController) {
NotificationShelfController.assertRefactorFlagDisabled(mAmbientState.getFeatureFlags());
int index = -1;
if (mShelf != null) {
index = indexOfChild(mShelf);

View File

@@ -73,6 +73,7 @@ import com.android.systemui.statusbar.LockscreenShadeTransitionController;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationLockscreenUserManager.UserChangedListener;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationShelf;
import com.android.systemui.statusbar.NotificationShelfController;
import com.android.systemui.statusbar.RemoteInputController;
import com.android.systemui.statusbar.StatusBarState;
@@ -1382,6 +1383,7 @@ public class NotificationStackScrollLayoutController {
}
public void setShelfController(NotificationShelfController notificationShelfController) {
NotificationShelfController.assertRefactorFlagDisabled(mFeatureFlags);
mView.setShelfController(notificationShelfController);
}
@@ -1593,6 +1595,11 @@ public class NotificationStackScrollLayoutController {
mView.setOnNotificationRemovedListener(listener);
}
public void setShelf(NotificationShelf shelf) {
if (!NotificationShelfController.checkRefactorFlagEnabled(mFeatureFlags)) return;
mView.setShelf(shelf);
}
/**
* Enum for UiEvent logged from this class
*/

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2023 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.util.kotlin
import dagger.Lazy
import kotlin.reflect.KProperty
/**
* Extension operator that allows developers to use [dagger.Lazy] as a property delegate:
* ```kotlin
* class MyClass @Inject constructor(
* lazyDependency: dagger.Lazy<Foo>,
* ) {
* val dependency: Foo by lazyDependency
* }
* ```
*/
operator fun <T> Lazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T = get()

View File

@@ -24,7 +24,6 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeDeviceEntryFaceAuthRepository
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.statusbar.notification.shelf.domain.interactor.NotificationShelfInteractor
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
@@ -68,4 +67,22 @@ class NotificationShelfInteractorTest : SysuiTestCase() {
assertThat(shelfStatic).isTrue()
}
@Test
fun shelfOnKeyguard_whenKeyguardShowing() = runTest {
val onKeyguard by collectLastValue(underTest.isShowingOnKeyguard)
keyguardRepository.setKeyguardShowing(true)
assertThat(onKeyguard).isTrue()
}
@Test
fun shelfNotOnKeyguard_whenKeyguardNotShowing() = runTest {
val onKeyguard by collectLastValue(underTest.isShowingOnKeyguard)
keyguardRepository.setKeyguardShowing(false)
assertThat(onKeyguard).isFalse()
}
}

View File

@@ -69,4 +69,22 @@ class NotificationShelfViewModelTest : SysuiTestCase() {
assertThat(canModifyNotifColor).isFalse()
}
@Test
fun isClickable_whenKeyguardShowing() = runTest {
val isClickable by collectLastValue(underTest.isClickable)
keyguardRepository.setKeyguardShowing(true)
assertThat(isClickable).isTrue()
}
@Test
fun isNotClickable_whenKeyguardNotShowing() = runTest {
val isClickable by collectLastValue(underTest.isClickable)
keyguardRepository.setKeyguardShowing(false)
assertThat(isClickable).isFalse()
}
}