diff options
3 files changed, 40 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 7bc1a39dfff5..7067bc1ba1bf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -80,6 +80,7 @@ import com.android.systemui.statusbar.stack.StackScrollState; import java.util.ArrayList; import java.util.List; +import java.util.function.BooleanSupplier; public class ExpandableNotificationRow extends ActivatableNotificationView implements PluginListener<NotificationMenuRowPlugin> { @@ -93,6 +94,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView } private LayoutListener mLayoutListener; + private boolean mDark; private boolean mLowPriorityStateUpdated; private final NotificationInflater mNotificationInflater; private int mIconTransformContentShift; @@ -175,6 +177,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView private boolean mGroupExpansionChanging; /** + * A supplier that returns true if keyguard is secure. + */ + private BooleanSupplier mSecureStateProvider; + + /** * Whether or not a notification that is not part of a group of notifications can be manually * expanded by the user. */ @@ -395,6 +402,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView mAboveShelfChangedListener = aboveShelfChangedListener; } + /** + * Sets a supplier that can determine whether the keyguard is secure or not. + * @param secureStateProvider A function that returns true if keyguard is secure. + */ + public void setSecureStateProvider(BooleanSupplier secureStateProvider) { + mSecureStateProvider = secureStateProvider; + } + @Override public boolean isDimmable() { if (!getShowingLayout().isDimmable()) { @@ -1454,6 +1469,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView @Override public void setDark(boolean dark, boolean fade, long delay) { super.setDark(dark, fade, delay); + mDark = dark; if (!mIsHeadsUp) { // Only fade the showing view of the pulsing notification. fade = false; @@ -1468,6 +1484,17 @@ public class ExpandableNotificationRow extends ActivatableNotificationView updateShelfIconColor(); } + /** + * Tap sounds should not be played when we're unlocking. + * Doing so would cause audio collision and the system would feel unpolished. + */ + @Override + public boolean isSoundEffectsEnabled() { + final boolean mute = mDark && mSecureStateProvider != null && + !mSecureStateProvider.getAsBoolean(); + return !mute && super.isSoundEffectsEnabled(); + } + public boolean isExpandable() { if (mIsSummaryWithChildren && !mShowingPublic) { return !mChildrenExpanded; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 7c6e886ad0a6..77959f09d1c2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -6809,6 +6809,7 @@ public class StatusBar extends SystemUI implements DemoMode, row.setOnExpandClickListener(this); row.setRemoteViewClickHandler(mOnClickHandler); row.setInflationCallback(this); + row.setSecureStateProvider(this::isKeyguardCurrentlySecure); // Get the app name. // Note that Notification.Builder#bindHeaderAppName has similar logic diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java index 2f6511c8481e..58ff46ad54ee 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java @@ -134,4 +134,16 @@ public class ExpandableNotificationRowTest extends SysuiTestCase { row.setAboveShelf(false); verify(listener).onAboveShelfStateChanged(false); } + + @Test + public void testClickSound() throws Exception { + Assert.assertTrue("Should play sounds by default.", mGroup.isSoundEffectsEnabled()); + mGroup.setDark(true /* dark */, false /* fade */, 0 /* delay */); + mGroup.setSecureStateProvider(()-> false); + Assert.assertFalse("Shouldn't play sounds when dark and trusted.", + mGroup.isSoundEffectsEnabled()); + mGroup.setSecureStateProvider(()-> true); + Assert.assertTrue("Should always play sounds when not trusted.", + mGroup.isSoundEffectsEnabled()); + } } |