Merge "Do not play sounds when unlocking from AoD." into oc-mr1-dev

This commit is contained in:
TreeHugger Robot
2017-09-13 02:24:50 +00:00
committed by Android (Google) Code Review
3 changed files with 40 additions and 0 deletions

View File

@@ -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;
@@ -174,6 +176,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
private OnExpandClickListener mOnExpandClickListener;
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;

View File

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

View File

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