Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd68a88a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 953a464d cecc7c23
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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
+12 −0
Original line number Diff line number Diff line
@@ -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());
    }
}