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

Commit ec36b511 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Play turbulence noise only when it triggers playing music." into udc-dev am: 5b506be7

parents 4ceab125 5b506be7
Loading
Loading
Loading
Loading
+34 −17
Original line number Original line Diff line number Diff line
@@ -248,9 +248,9 @@ public class MediaControlPanel {
    private final FeatureFlags mFeatureFlags;
    private final FeatureFlags mFeatureFlags;
    private final GlobalSettings mGlobalSettings;
    private final GlobalSettings mGlobalSettings;


    // TODO(b/281032715): Consider making this as a final variable. For now having a null check
    //  due to unit test failure. (Perhaps missing some setup)
    private TurbulenceNoiseAnimationConfig mTurbulenceNoiseAnimationConfig;
    private TurbulenceNoiseAnimationConfig mTurbulenceNoiseAnimationConfig;
    private boolean mWasPlaying = false;
    private boolean mButtonClicked = false;


    private ContentObserver mAnimationScaleObserver = new ContentObserver(null) {
    private ContentObserver mAnimationScaleObserver = new ContentObserver(null) {
        @Override
        @Override
@@ -582,6 +582,25 @@ public class MediaControlPanel {
        if (!mMetadataAnimationHandler.isRunning()) {
        if (!mMetadataAnimationHandler.isRunning()) {
            mMediaViewController.refreshState();
            mMediaViewController.refreshState();
        }
        }

        // Turbulence noise
        if (shouldPlayTurbulenceNoise()) {
            if (mTurbulenceNoiseAnimationConfig == null) {
                mTurbulenceNoiseAnimationConfig =
                        createTurbulenceNoiseAnimation();
            }
            // Color will be correctly updated in ColorSchemeTransition.
            mTurbulenceNoiseController.play(
                    mTurbulenceNoiseAnimationConfig
            );
            mMainExecutor.executeDelayed(
                    mTurbulenceNoiseController::finish,
                    TURBULENCE_NOISE_PLAY_DURATION
            );
        }
        mButtonClicked = false;
        mWasPlaying = isPlaying();

        Trace.endSection();
        Trace.endSection();
    }
    }


@@ -1155,21 +1174,14 @@ public class MediaControlPanel {
                    if (!mFalsingManager.isFalseTap(FalsingManager.MODERATE_PENALTY)) {
                    if (!mFalsingManager.isFalseTap(FalsingManager.MODERATE_PENALTY)) {
                        mLogger.logTapAction(button.getId(), mUid, mPackageName, mInstanceId);
                        mLogger.logTapAction(button.getId(), mUid, mPackageName, mInstanceId);
                        logSmartspaceCardReported(SMARTSPACE_CARD_CLICK_EVENT);
                        logSmartspaceCardReported(SMARTSPACE_CARD_CLICK_EVENT);
                        // Used to determine whether to play turbulence noise.
                        mWasPlaying = isPlaying();
                        mButtonClicked = true;

                        action.run();
                        action.run();

                        if (mFeatureFlags.isEnabled(Flags.UMO_SURFACE_RIPPLE)) {
                        if (mFeatureFlags.isEnabled(Flags.UMO_SURFACE_RIPPLE)) {
                            mMultiRippleController.play(createTouchRippleAnimation(button));
                            mMultiRippleController.play(createTouchRippleAnimation(button));
                            if (mFeatureFlags.isEnabled(Flags.UMO_TURBULENCE_NOISE)) {
                                if (mTurbulenceNoiseAnimationConfig == null) {
                                    mTurbulenceNoiseAnimationConfig =
                                            createTurbulenceNoiseAnimation();
                                }
                                // Color will be correctly updated in ColorSchemeTransition.
                                mTurbulenceNoiseController.play(mTurbulenceNoiseAnimationConfig);
                                mMainExecutor.executeDelayed(
                                        mTurbulenceNoiseController::finish,
                                        TURBULENCE_NOISE_PLAY_DURATION
                                );
                            }
                        }
                        }


                        if (icon instanceof Animatable) {
                        if (icon instanceof Animatable) {
@@ -1208,6 +1220,11 @@ public class MediaControlPanel {
        );
        );
    }
    }


    private boolean shouldPlayTurbulenceNoise() {
        return mFeatureFlags.isEnabled(Flags.UMO_TURBULENCE_NOISE) && mButtonClicked && !mWasPlaying
                && isPlaying();
    }

    private TurbulenceNoiseAnimationConfig createTurbulenceNoiseAnimation() {
    private TurbulenceNoiseAnimationConfig createTurbulenceNoiseAnimation() {
        return new TurbulenceNoiseAnimationConfig(
        return new TurbulenceNoiseAnimationConfig(
                /* gridCount= */ 2.14f,
                /* gridCount= */ 2.14f,
@@ -1218,12 +1235,12 @@ public class MediaControlPanel {
                /* color= */ mColorSchemeTransition.getAccentPrimary().getCurrentColor(),
                /* color= */ mColorSchemeTransition.getAccentPrimary().getCurrentColor(),
                /* backgroundColor= */ Color.BLACK,
                /* backgroundColor= */ Color.BLACK,
                /* opacity= */ 51,
                /* opacity= */ 51,
                /* width= */ mMediaViewHolder.getMultiRippleView().getWidth(),
                /* width= */ mMediaViewHolder.getTurbulenceNoiseView().getWidth(),
                /* height= */ mMediaViewHolder.getMultiRippleView().getHeight(),
                /* height= */ mMediaViewHolder.getTurbulenceNoiseView().getHeight(),
                TurbulenceNoiseAnimationConfig.DEFAULT_MAX_DURATION_IN_MILLIS,
                TurbulenceNoiseAnimationConfig.DEFAULT_MAX_DURATION_IN_MILLIS,
                /* easeInDuration= */ 1350f,
                /* easeInDuration= */ 1350f,
                /* easeOutDuration= */ 1350f,
                /* easeOutDuration= */ 1350f,
                this.getContext().getResources().getDisplayMetrics().density,
                getContext().getResources().getDisplayMetrics().density,
                BlendMode.SCREEN,
                BlendMode.SCREEN,
                /* onAnimationEnd= */ null,
                /* onAnimationEnd= */ null,
                /* lumaMatteBlendFactor= */ 0.26f,
                /* lumaMatteBlendFactor= */ 0.26f,
+23 −1
Original line number Original line Diff line number Diff line
@@ -2420,7 +2420,6 @@ public class MediaControlPanelTest : SysuiTestCase() {


    @Test
    @Test
    fun playTurbulenceNoise_finishesAfterDuration() {
    fun playTurbulenceNoise_finishesAfterDuration() {
        fakeFeatureFlag.set(Flags.UMO_SURFACE_RIPPLE, true)
        fakeFeatureFlag.set(Flags.UMO_TURBULENCE_NOISE, true)
        fakeFeatureFlag.set(Flags.UMO_TURBULENCE_NOISE, true)


        val semanticActions =
        val semanticActions =
@@ -2451,6 +2450,29 @@ public class MediaControlPanelTest : SysuiTestCase() {
        }
        }
    }
    }


    @Test
    fun playTurbulenceNoise_whenPlaybackStateIsNotPlaying_doesNotPlayTurbulence() {
        fakeFeatureFlag.set(Flags.UMO_TURBULENCE_NOISE, true)

        val semanticActions =
            MediaButton(
                custom0 =
                    MediaAction(
                        icon = null,
                        action = {},
                        contentDescription = "custom0",
                        background = null
                    ),
            )
        val data = mediaData.copy(semanticActions = semanticActions)
        player.attachPlayer(viewHolder)
        player.bindPlayer(data, KEY)

        viewHolder.action0.callOnClick()

        assertThat(turbulenceNoiseView.visibility).isEqualTo(View.INVISIBLE)
    }

    @Test
    @Test
    fun outputSwitcher_hasCustomIntent_openOverLockscreen() {
    fun outputSwitcher_hasCustomIntent_openOverLockscreen() {
        // When the device for a media player has an intent that opens over lockscreen
        // When the device for a media player has an intent that opens over lockscreen