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

Commit 4be99386 authored by Alex Shabalin's avatar Alex Shabalin
Browse files

Detach color scheme from MediaSwitchingController.

Additionally, set main and background thread executors as constructor
arguments for MediaOutputAdapterLegacy so that screenshot tests have
control over the asynchronous execution.

This change is needed to:
- Not mock the colors for the UI tests.
- Clearly differentiate colors for the legacy UI from the colors for the
updated UI.

Flag: EXEMPT refactor
Bug: 389978538
Fix: 389978538
Test: atest
SystemUIGoogleScreenshotTests:com.android.systemui.media.dialog,
atest SystemUITests:com.android.systemui.media.dialog

Change-Id: I685384e3a4ce2700228dde13375b9a1995b40b0b
parent d0904b97
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -48,10 +48,12 @@ import androidx.test.filters.SmallTest;
import com.android.media.flags.Flags;
import com.android.settingslib.media.LocalMediaManager;
import com.android.settingslib.media.MediaDevice;
import com.android.settingslib.utils.ThreadUtils;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.res.R;

import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListeningExecutorService;

import org.junit.Before;
import org.junit.Test;
@@ -61,6 +63,7 @@ import org.mockito.Captor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

@SmallTest
@@ -95,6 +98,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
    private List<MediaDevice> mMediaDevices = new ArrayList<>();
    private List<MediaItem> mMediaItems = new ArrayList<>();
    MediaOutputSeekbar mSpyMediaOutputSeekbar;
    Executor mMainExecutor = mContext.getMainExecutor();
    ListeningExecutorService mBackgroundExecutor = ThreadUtils.getBackgroundExecutor();

    @Before
    public void setUp() {
@@ -108,6 +113,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
        when(mMediaSwitchingController.getSessionVolumeMax()).thenReturn(TEST_MAX_VOLUME);
        when(mMediaSwitchingController.getSessionVolume()).thenReturn(TEST_CURRENT_VOLUME);
        when(mMediaSwitchingController.getSessionName()).thenReturn(TEST_SESSION_NAME);
        when(mMediaSwitchingController.getColorSchemeLegacy()).thenReturn(
                mock(MediaOutputColorSchemeLegacy.class));
        when(mIconCompat.toIcon(mContext)).thenReturn(mIcon);
        when(mMediaDevice1.getName()).thenReturn(TEST_DEVICE_NAME_1);
        when(mMediaDevice1.getId()).thenReturn(TEST_DEVICE_ID_1);
@@ -122,7 +129,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
        mMediaItems.add(MediaItem.createDeviceMediaItem(mMediaDevice1, true));
        mMediaItems.add(MediaItem.createDeviceMediaItem(mMediaDevice2, false));

        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
@@ -148,7 +156,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {

    @Test
    public void onBindViewHolder_bindPairNew_verifyView() {
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
@@ -173,7 +182,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
                                .map((item) -> item.getMediaDevice().get())
                                .collect(Collectors.toList()));
        when(mMediaSwitchingController.getSessionName()).thenReturn(TEST_SESSION_NAME);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
@@ -195,7 +205,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
                                .map((item) -> item.getMediaDevice().get())
                                .collect(Collectors.toList()));
        when(mMediaSwitchingController.getSessionName()).thenReturn(null);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
@@ -665,7 +676,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {

    @Test
    public void onItemClick_clickPairNew_verifyLaunchBluetoothPairing() {
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
@@ -683,7 +695,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
        assertThat(mMediaDevice2.getState()).isEqualTo(
                LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED);
        when(mMediaDevice2.getSelectionBehavior()).thenReturn(SELECTION_BEHAVIOR_TRANSFER);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
@@ -701,7 +714,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
        assertThat(mMediaDevice2.getState()).isEqualTo(
                LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED);
        when(mMediaDevice2.getSelectionBehavior()).thenReturn(SELECTION_BEHAVIOR_TRANSFER);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController,
                mContext.getMainExecutor(), ThreadUtils.getBackgroundExecutor());
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
@@ -723,7 +737,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
        when(mMediaDevice2.getState()).thenReturn(
                LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED);
        when(mMediaDevice2.getSelectionBehavior()).thenReturn(SELECTION_BEHAVIOR_GO_TO_APP);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
+3 −2
Original line number Diff line number Diff line
@@ -351,8 +351,9 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
        @VisibleForTesting
        void showCustomEndSessionDialog(MediaDevice device) {
            MediaSessionReleaseDialog mediaSessionReleaseDialog = new MediaSessionReleaseDialog(
                    mContext, () -> transferOutput(device), mController.getColorButtonBackground(),
                    mController.getColorItemContent());
                    mContext, () -> transferOutput(device),
                    mController.getColorSchemeLegacy().getColorButtonBackground(),
                    mController.getColorSchemeLegacy().getColorItemContent());
            mediaSessionReleaseDialog.show();
        }

+44 −31
Original line number Diff line number Diff line
@@ -50,9 +50,11 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.media.flags.Flags;
import com.android.settingslib.media.InputMediaDevice;
import com.android.settingslib.media.MediaDevice;
import com.android.settingslib.utils.ThreadUtils;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.res.R;

import java.util.concurrent.Executor;
/**
 * A RecyclerView adapter for the legacy UI media output dialog device list.
 */
@@ -63,11 +65,19 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
    private static final int UNMUTE_DEFAULT_VOLUME = 2;
    @VisibleForTesting static final float DEVICE_DISABLED_ALPHA = 0.5f;
    @VisibleForTesting static final float DEVICE_ACTIVE_ALPHA = 1f;
    private final Executor mMainExecutor;
    private final Executor mBackgroundExecutor;
    View mHolderView;
    private boolean mIsInitVolumeFirstTime;

    public MediaOutputAdapterLegacy(MediaSwitchingController controller) {
    public MediaOutputAdapterLegacy(
            MediaSwitchingController controller,
            @Main Executor mainExecutor,
            @Background Executor backgroundExecutor
    ) {
        super(controller);
        mMainExecutor = mainExecutor;
        mBackgroundExecutor = backgroundExecutor;
        mIsInitVolumeFirstTime = true;
    }

@@ -181,9 +191,9 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
            mEndTouchArea.setVisibility(View.GONE);
            mEndClickIcon.setVisibility(View.GONE);
            mContainerLayout.setOnClickListener(null);
            mTitleText.setTextColor(mController.getColorItemContent());
            mSubTitleText.setTextColor(mController.getColorItemContent());
            mVolumeValueText.setTextColor(mController.getColorItemContent());
            mTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent());
            mSubTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent());
            mVolumeValueText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent());
            mIconAreaLayout.setBackground(null);
            updateIconAreaClickListener(null);
            updateSeekBarProgressColor();
@@ -193,14 +203,14 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {

        /** Binds a ViewHolder for a "Connect a device" item. */
        void onBindPairNewDevice() {
            mTitleText.setTextColor(mController.getColorItemContent());
            mTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent());
            mCheckBox.setVisibility(View.GONE);
            updateTitle(mContext.getText(R.string.media_output_dialog_pairing_new));
            updateItemBackground(ConnectionState.DISCONNECTED);
            final Drawable addDrawable = mContext.getDrawable(R.drawable.ic_add);
            mTitleIcon.setImageDrawable(addDrawable);
            mTitleIcon.setImageTintList(
                    ColorStateList.valueOf(mController.getColorItemContent()));
            mTitleIcon.setImageTintList(ColorStateList.valueOf(
                    mController.getColorSchemeLegacy().getColorItemContent()));
            mContainerLayout.setOnClickListener(mController::launchBluetoothPairing);
        }

@@ -297,8 +307,8 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
        protected void updateLoadingIndicator(ConnectionState connectionState) {
            if (connectionState == ConnectionState.CONNECTING) {
                mProgressBar.setVisibility(View.VISIBLE);
                mProgressBar.getIndeterminateDrawable().setTintList(
                        ColorStateList.valueOf(mController.getColorItemContent()));
                mProgressBar.getIndeterminateDrawable().setTintList(ColorStateList.valueOf(
                        mController.getColorSchemeLegacy().getColorItemContent()));
            } else {
                mProgressBar.setVisibility(View.GONE);
            }
@@ -318,8 +328,8 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {

            // Connected or connecting state has a darker background.
            int backgroundColor = isConnected || isConnecting
                    ? mController.getColorConnectedItemBackground()
                    : mController.getColorItemBackground();
                    ? mController.getColorSchemeLegacy().getColorConnectedItemBackground()
                    : mController.getColorSchemeLegacy().getColorItemBackground();
            mItemLayout.setBackgroundTintList(ColorStateList.valueOf(backgroundColor));
        }

@@ -332,13 +342,13 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
        }

        private void updateSeekBarProgressColor() {
            mSeekBar.setProgressTintList(
                    ColorStateList.valueOf(mController.getColorSeekbarProgress()));
            mSeekBar.setProgressTintList(ColorStateList.valueOf(
                    mController.getColorSchemeLegacy().getColorSeekbarProgress()));
            final Drawable contrastDotDrawable =
                    ((LayerDrawable) mSeekBar.getProgressDrawable()).findDrawableByLayerId(
                            R.id.contrast_dot);
            contrastDotDrawable.setTintList(
                    ColorStateList.valueOf(mController.getColorItemContent()));
            contrastDotDrawable.setTintList(ColorStateList.valueOf(
                    mController.getColorSchemeLegacy().getColorItemContent()));
        }

        void updateSeekbarProgressBackground() {
@@ -503,9 +513,10 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
            boolean isInputMediaDevice = device instanceof InputMediaDevice;
            int id = getDrawableId(isInputMediaDevice, isMutedVolumeIcon);
            mTitleIcon.setImageDrawable(mContext.getDrawable(id));
            mTitleIcon.setImageTintList(ColorStateList.valueOf(mController.getColorItemContent()));
            mIconAreaLayout.setBackgroundTintList(
                    ColorStateList.valueOf(mController.getColorSeekbarProgress()));
            mTitleIcon.setImageTintList(ColorStateList.valueOf(
                    mController.getColorSchemeLegacy().getColorItemContent()));
            mIconAreaLayout.setBackgroundTintList(ColorStateList.valueOf(
                    mController.getColorSchemeLegacy().getColorSeekbarProgress()));
        }

        @VisibleForTesting
@@ -534,8 +545,8 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
                mStatusIcon.setVisibility(View.GONE);
            } else {
                mStatusIcon.setImageDrawable(deviceStatusIcon);
                mStatusIcon.setImageTintList(
                        ColorStateList.valueOf(mController.getColorItemContent()));
                mStatusIcon.setImageTintList(ColorStateList.valueOf(
                        mController.getColorSchemeLegacy().getColorItemContent()));
                if (deviceStatusIcon instanceof AnimatedVectorDrawable) {
                    ((AnimatedVectorDrawable) deviceStatusIcon).start();
                }
@@ -585,9 +596,10 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
        private void updateEndAreaWithIcon(View.OnClickListener clickListener,
                @DrawableRes int iconDrawableId,
                @StringRes int accessibilityStringId) {
            updateEndAreaColor(mController.getColorSeekbarProgress());
            updateEndAreaColor(mController.getColorSchemeLegacy().getColorSeekbarProgress());
            mEndClickIcon.setImageTintList(
                    ColorStateList.valueOf(mController.getColorItemContent()));
                    ColorStateList.valueOf(
                            mController.getColorSchemeLegacy().getColorItemContent()));
            mEndClickIcon.setOnClickListener(clickListener);
            Drawable drawable = mContext.getDrawable(iconDrawableId);
            mEndClickIcon.setImageDrawable(drawable);
@@ -600,8 +612,9 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
        private void updateEndAreaForGroupCheckBox(@NonNull MediaDevice device,
                @NonNull GroupStatus groupStatus) {
            boolean isEnabled = isGroupCheckboxEnabled(groupStatus);
            updateEndAreaColor(groupStatus.selected() ? mController.getColorSeekbarProgress()
                    : mController.getColorItemBackground());
            updateEndAreaColor(groupStatus.selected()
                    ? mController.getColorSchemeLegacy().getColorSeekbarProgress()
                    : mController.getColorSchemeLegacy().getColorItemBackground());
            mCheckBox.setContentDescription(mContext.getString(
                    groupStatus.selected() ? R.string.accessibility_remove_device_from_group
                            : R.string.accessibility_add_device_to_group));
@@ -611,7 +624,7 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
                    isEnabled ? (buttonView, isChecked) -> onGroupActionTriggered(
                            !groupStatus.selected(), device) : null);
            mCheckBox.setEnabled(isEnabled);
            setCheckBoxColor(mCheckBox, mController.getColorItemContent());
            setCheckBoxColor(mCheckBox, mController.getColorSchemeLegacy().getColorItemContent());
        }

        private void setCheckBoxColor(CheckBox checkBox, int color) {
@@ -714,15 +727,15 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
        }

        protected void setUpDeviceIcon(@NonNull MediaDevice device) {
            ThreadUtils.postOnBackgroundThread(() -> {
            mBackgroundExecutor.execute(() -> {
                Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext);
                ThreadUtils.postOnMainThread(() -> {
                mMainExecutor.execute(() -> {
                    if (!TextUtils.equals(mDeviceId, device.getId())) {
                        return;
                    }
                    mTitleIcon.setImageIcon(icon);
                    mTitleIcon.setImageTintList(
                            ColorStateList.valueOf(mController.getColorItemContent()));
                    mTitleIcon.setImageTintList(ColorStateList.valueOf(
                            mController.getColorSchemeLegacy().getColorItemContent()));
                });
            });
        }
@@ -807,7 +820,7 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase {
        }

        void onBind(String groupDividerTitle) {
            mTitleText.setTextColor(mController.getColorItemContent());
            mTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent());
            mTitleText.setText(groupDividerTitle);
        }
    }
+11 −8
Original line number Diff line number Diff line
@@ -342,7 +342,8 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog
                WallpaperColors wallpaperColors = WallpaperColors.fromBitmap(icon.getBitmap());
                colorSetUpdated = !wallpaperColors.equals(mWallpaperColors);
                if (colorSetUpdated) {
                    mMediaSwitchingController.setCurrentColorScheme(wallpaperColors, isDarkThemeOn);
                    mMediaSwitchingController.updateCurrentColorScheme(wallpaperColors,
                            isDarkThemeOn);
                    updateButtonBackgroundColorFilter();
                    updateDialogBackgroundColor();
                }
@@ -359,7 +360,8 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog
            mAppResourceIcon.setVisibility(View.GONE);
        } else if (appSourceIcon != null) {
            Icon appIcon = appSourceIcon.toIcon(mContext);
            mAppResourceIcon.setColorFilter(mMediaSwitchingController.getColorItemContent());
            mAppResourceIcon.setColorFilter(
                    mMediaSwitchingController.getColorSchemeLegacy().getColorItemContent());
            mAppResourceIcon.setImageIcon(appIcon);
        } else {
            Drawable appIconDrawable = mMediaSwitchingController.getAppSourceIconFromPackage();
@@ -419,18 +421,19 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog
    private void updateButtonBackgroundColorFilter() {
        ColorFilter buttonColorFilter =
                new PorterDuffColorFilter(
                        mMediaSwitchingController.getColorButtonBackground(),
                        mMediaSwitchingController.getColorSchemeLegacy().getColorButtonBackground(),
                        PorterDuff.Mode.SRC_IN);
        mDoneButton.getBackground().setColorFilter(buttonColorFilter);
        mStopButton.getBackground().setColorFilter(buttonColorFilter);
        mDoneButton.setTextColor(mMediaSwitchingController.getColorPositiveButtonText());
        mDoneButton.setTextColor(
                mMediaSwitchingController.getColorSchemeLegacy().getColorPositiveButtonText());
    }

    private void updateDialogBackgroundColor() {
        getDialogView()
                .getBackground()
                .setTint(mMediaSwitchingController.getColorDialogBackground());
        mDeviceListLayout.setBackgroundColor(mMediaSwitchingController.getColorDialogBackground());
        getDialogView().getBackground().setTint(
                mMediaSwitchingController.getColorSchemeLegacy().getColorDialogBackground());
        mDeviceListLayout.setBackgroundColor(
                mMediaSwitchingController.getColorSchemeLegacy().getColorDialogBackground());
    }

    public void handleLeBroadcastStarted() {
+7 −2
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ import com.android.systemui.statusbar.phone.SystemUIDialog;

import com.google.zxing.WriterException;

import java.util.concurrent.Executor;

/**
 * Dialog for media output broadcast.
 */
@@ -239,13 +241,16 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
            Context context,
            boolean aboveStatusbar,
            BroadcastSender broadcastSender,
            MediaSwitchingController mediaSwitchingController) {
            MediaSwitchingController mediaSwitchingController,
            Executor mainExecutor,
            Executor backgroundExecutor) {
        super(
                context,
                broadcastSender,
                mediaSwitchingController, /* includePlaybackAndAppMetadata */
                true);
        mAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController);
        mAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mainExecutor,
                backgroundExecutor);
        // TODO(b/226710953): Move the part to MediaOutputBaseDialog for every class
        //  that extends MediaOutputBaseDialog
        if (!aboveStatusbar) {
Loading