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

Commit 7d633f32 authored by Xiaowen Lei's avatar Xiaowen Lei Committed by Automerger Merge Worker
Browse files

Merge "Tapping dream media chip opens media instead of UMO if flag is set."...

Merge "Tapping dream media chip opens media instead of UMO if flag is set." into tm-qpr-dev am: b18a6841 am: d7889cf8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19957222



Change-Id: Id1189e32a20648b8edb5c75de2c5f71dff5d063f
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 052676c9 d7889cf8
Loading
Loading
Loading
Loading
+56 −1
Original line number Diff line number Diff line
@@ -18,13 +18,21 @@ package com.android.systemui.dreams.complication;

import static com.android.systemui.dreams.complication.dagger.DreamMediaEntryComplicationComponent.DreamMediaEntryModule.DREAM_MEDIA_ENTRY_VIEW;
import static com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule.DREAM_MEDIA_ENTRY_LAYOUT_PARAMS;
import static com.android.systemui.flags.Flags.DREAM_MEDIA_TAP_TO_OPEN;

import android.app.PendingIntent;
import android.util.Log;
import android.view.View;

import com.android.systemui.ActivityIntentHelper;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.dreams.complication.dagger.DreamMediaEntryComplicationComponent;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.media.MediaCarouselController;
import com.android.systemui.media.dream.MediaDreamComplication;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.ViewController;

import javax.inject.Inject;
@@ -87,6 +95,15 @@ public class DreamMediaEntryComplication implements Complication {

        private final DreamOverlayStateController mDreamOverlayStateController;
        private final MediaDreamComplication mMediaComplication;
        private final MediaCarouselController mMediaCarouselController;

        private final ActivityStarter mActivityStarter;
        private final ActivityIntentHelper mActivityIntentHelper;
        private final KeyguardStateController mKeyguardStateController;
        private final NotificationLockscreenUserManager mLockscreenUserManager;

        private final FeatureFlags mFeatureFlags;
        private boolean mIsTapToOpenEnabled;

        private boolean mMediaComplicationAdded;

@@ -94,15 +111,28 @@ public class DreamMediaEntryComplication implements Complication {
        DreamMediaEntryViewController(
                @Named(DREAM_MEDIA_ENTRY_VIEW) View view,
                DreamOverlayStateController dreamOverlayStateController,
                MediaDreamComplication mediaComplication) {
                MediaDreamComplication mediaComplication,
                MediaCarouselController mediaCarouselController,
                ActivityStarter activityStarter,
                ActivityIntentHelper activityIntentHelper,
                KeyguardStateController keyguardStateController,
                NotificationLockscreenUserManager lockscreenUserManager,
                FeatureFlags featureFlags) {
            super(view);
            mDreamOverlayStateController = dreamOverlayStateController;
            mMediaComplication = mediaComplication;
            mMediaCarouselController = mediaCarouselController;
            mActivityStarter = activityStarter;
            mActivityIntentHelper = activityIntentHelper;
            mKeyguardStateController = keyguardStateController;
            mLockscreenUserManager = lockscreenUserManager;
            mFeatureFlags = featureFlags;
            mView.setOnClickListener(this::onClickMediaEntry);
        }

        @Override
        protected void onViewAttached() {
            mIsTapToOpenEnabled = mFeatureFlags.isEnabled(DREAM_MEDIA_TAP_TO_OPEN);
        }

        @Override
@@ -113,6 +143,31 @@ public class DreamMediaEntryComplication implements Complication {
        private void onClickMediaEntry(View v) {
            if (DEBUG) Log.d(TAG, "media entry complication tapped");

            if (mIsTapToOpenEnabled) {
                final PendingIntent clickIntent =
                        mMediaCarouselController.getCurrentVisibleMediaContentIntent();

                if (clickIntent == null) {
                    return;
                }

                // See StatusBarNotificationActivityStarter#onNotificationClicked
                final boolean showOverLockscreen = mKeyguardStateController.isShowing()
                        && mActivityIntentHelper.wouldShowOverLockscreen(clickIntent.getIntent(),
                        mLockscreenUserManager.getCurrentUserId());

                if (showOverLockscreen) {
                    mActivityStarter.startActivity(clickIntent.getIntent(),
                            /* dismissShade */ true,
                            /* animationController */ null,
                            /* showOverLockscreenWhenLocked */ true);
                } else {
                    mActivityStarter.postStartActivityDismissingKeyguard(clickIntent, null);
                }

                return;
            }

            if (!mMediaComplicationAdded) {
                addMediaComplication();
            } else {
+2 −1
Original line number Diff line number Diff line
@@ -200,7 +200,8 @@ public class Flags {
    public static final UnreleasedFlag MEDIA_SESSION_ACTIONS = new UnreleasedFlag(901);
    public static final ReleasedFlag MEDIA_NEARBY_DEVICES = new ReleasedFlag(903);
    public static final ReleasedFlag MEDIA_MUTE_AWAIT = new ReleasedFlag(904);
    public static final UnreleasedFlag MEDIA_DREAM_COMPLICATION = new UnreleasedFlag(905);
    public static final UnreleasedFlag DREAM_MEDIA_COMPLICATION = new UnreleasedFlag(905);
    public static final UnreleasedFlag DREAM_MEDIA_TAP_TO_OPEN = new UnreleasedFlag(906);

    // 1000 - dock
    public static final ReleasedFlag SIMULATE_DOCK_THROUGH_CHARGING =
+6 −0
Original line number Diff line number Diff line
package com.android.systemui.media

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
@@ -945,6 +946,11 @@ class MediaCarouselController @Inject constructor(
        mediaManager.onSwipeToDismiss()
    }

    fun getCurrentVisibleMediaContentIntent(): PendingIntent? {
        return MediaPlayerData.playerKeys()
                .elementAtOrNull(mediaCarouselScrollHandler.visibleMediaIndex)?.data?.clickIntent
    }

    override fun dump(pw: PrintWriter, args: Array<out String>) {
        pw.apply {
            println("keysNeedRemoval: $keysNeedRemoval")
+2 −2
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.systemui.media.dream;

import static com.android.systemui.flags.Flags.MEDIA_DREAM_COMPLICATION;
import static com.android.systemui.flags.Flags.DREAM_MEDIA_COMPLICATION;

import android.content.Context;
import android.util.Log;
@@ -77,7 +77,7 @@ public class MediaDreamSentinel extends CoreStartable {
        public void onMediaDataLoaded(@NonNull String key, @Nullable String oldKey,
                @NonNull MediaData data, boolean immediately, int receivedSmartspaceCardLatency,
                boolean isSsReactivated) {
            if (!mFeatureFlags.isEnabled(MEDIA_DREAM_COMPLICATION)) {
            if (!mFeatureFlags.isEnabled(DREAM_MEDIA_COMPLICATION)) {
                return;
            }

+125 −3
Original line number Diff line number Diff line
@@ -16,17 +16,28 @@

package com.android.systemui.dreams.complication;

import static com.android.systemui.flags.Flags.DREAM_MEDIA_TAP_TO_OPEN;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.PendingIntent;
import android.content.Intent;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.View;

import androidx.test.filters.SmallTest;

import com.android.systemui.ActivityIntentHelper;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.media.MediaCarouselController;
import com.android.systemui.media.dream.MediaDreamComplication;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.policy.KeyguardStateController;

import org.junit.Before;
import org.junit.Test;
@@ -48,21 +59,52 @@ public class DreamMediaEntryComplicationTest extends SysuiTestCase {
    @Mock
    private MediaDreamComplication mMediaComplication;

    @Mock
    private MediaCarouselController mMediaCarouselController;

    @Mock
    private ActivityStarter mActivityStarter;

    @Mock
    private ActivityIntentHelper mActivityIntentHelper;

    @Mock
    private KeyguardStateController mKeyguardStateController;

    @Mock
    private NotificationLockscreenUserManager mLockscreenUserManager;

    @Mock
    private FeatureFlags mFeatureFlags;

    @Mock
    private PendingIntent mPendingIntent;

    private final Intent mIntent = new Intent("android.test.TEST_ACTION");
    private final Integer mCurrentUserId = 99;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        when(mFeatureFlags.isEnabled(DREAM_MEDIA_TAP_TO_OPEN)).thenReturn(false);
    }

    /**
     * Ensures clicking media entry chip adds/removes media complication.
     */
    @Test
    public void testClick() {
    public void testClickToOpenUMO() {
        final DreamMediaEntryComplication.DreamMediaEntryViewController viewController =
                new DreamMediaEntryComplication.DreamMediaEntryViewController(
                        mView,
                        mDreamOverlayStateController,
                        mMediaComplication);
                        mMediaComplication,
                        mMediaCarouselController,
                        mActivityStarter,
                        mActivityIntentHelper,
                        mKeyguardStateController,
                        mLockscreenUserManager,
                        mFeatureFlags);

        final ArgumentCaptor<View.OnClickListener> clickListenerCaptor =
                ArgumentCaptor.forClass(View.OnClickListener.class);
@@ -85,10 +127,90 @@ public class DreamMediaEntryComplicationTest extends SysuiTestCase {
                new DreamMediaEntryComplication.DreamMediaEntryViewController(
                        mView,
                        mDreamOverlayStateController,
                        mMediaComplication);
                        mMediaComplication,
                        mMediaCarouselController,
                        mActivityStarter,
                        mActivityIntentHelper,
                        mKeyguardStateController,
                        mLockscreenUserManager,
                        mFeatureFlags);

        viewController.onViewDetached();
        verify(mView).setSelected(false);
        verify(mDreamOverlayStateController).removeComplication(mMediaComplication);
    }

    /**
     * Ensures clicking media entry chip opens media when flag is set.
     */
    @Test
    public void testClickToOpenMediaOverLockscreen() {
        when(mFeatureFlags.isEnabled(DREAM_MEDIA_TAP_TO_OPEN)).thenReturn(true);

        when(mMediaCarouselController.getCurrentVisibleMediaContentIntent()).thenReturn(
                mPendingIntent);
        when(mKeyguardStateController.isShowing()).thenReturn(true);
        when(mPendingIntent.getIntent()).thenReturn(mIntent);
        when(mLockscreenUserManager.getCurrentUserId()).thenReturn(mCurrentUserId);

        final DreamMediaEntryComplication.DreamMediaEntryViewController viewController =
                new DreamMediaEntryComplication.DreamMediaEntryViewController(
                        mView,
                        mDreamOverlayStateController,
                        mMediaComplication,
                        mMediaCarouselController,
                        mActivityStarter,
                        mActivityIntentHelper,
                        mKeyguardStateController,
                        mLockscreenUserManager,
                        mFeatureFlags);
        viewController.onViewAttached();

        final ArgumentCaptor<View.OnClickListener> clickListenerCaptor =
                ArgumentCaptor.forClass(View.OnClickListener.class);
        verify(mView).setOnClickListener(clickListenerCaptor.capture());

        when(mActivityIntentHelper.wouldShowOverLockscreen(mIntent, mCurrentUserId)).thenReturn(
                true);

        clickListenerCaptor.getValue().onClick(mView);
        verify(mActivityStarter).startActivity(mIntent, true, null, true);
    }

    /**
     * Ensures clicking media entry chip opens media when flag is set.
     */
    @Test
    public void testClickToOpenMediaDismissingLockscreen() {
        when(mFeatureFlags.isEnabled(DREAM_MEDIA_TAP_TO_OPEN)).thenReturn(true);

        when(mMediaCarouselController.getCurrentVisibleMediaContentIntent()).thenReturn(
                mPendingIntent);
        when(mKeyguardStateController.isShowing()).thenReturn(true);
        when(mPendingIntent.getIntent()).thenReturn(mIntent);
        when(mLockscreenUserManager.getCurrentUserId()).thenReturn(mCurrentUserId);

        final DreamMediaEntryComplication.DreamMediaEntryViewController viewController =
                new DreamMediaEntryComplication.DreamMediaEntryViewController(
                        mView,
                        mDreamOverlayStateController,
                        mMediaComplication,
                        mMediaCarouselController,
                        mActivityStarter,
                        mActivityIntentHelper,
                        mKeyguardStateController,
                        mLockscreenUserManager,
                        mFeatureFlags);
        viewController.onViewAttached();

        final ArgumentCaptor<View.OnClickListener> clickListenerCaptor =
                ArgumentCaptor.forClass(View.OnClickListener.class);
        verify(mView).setOnClickListener(clickListenerCaptor.capture());

        when(mActivityIntentHelper.wouldShowOverLockscreen(mIntent, mCurrentUserId)).thenReturn(
                false);

        clickListenerCaptor.getValue().onClick(mView);
        verify(mActivityStarter).postStartActivityDismissingKeyguard(mPendingIntent, null);
    }
}
Loading