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

Commit 5f8775a5 authored by Alexandr Shabalin's avatar Alexandr Shabalin Committed by Android (Google) Code Review
Browse files

Merge changes from topic "ashabalin-fix-flag-related-tests" into main

* changes:
  Fix the UI for the `UserManager.DISALLOW_ADJUST_VOLUME` option.
  Consolidate the status icon and subtitle rendering.
  Fix unit tests for `enable_output_switcher_session_grouping`.
parents 6ba4ce77 d38b82c1
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -618,6 +618,7 @@ public abstract class InfoMediaManager {
        return getActiveRoutingSession().getVolume();
        return getActiveRoutingSession().getVolume();
    }
    }


    @Nullable
    CharSequence getSessionName() {
    CharSequence getSessionName() {
        return getActiveRoutingSession().getName();
        return getActiveRoutingSession().getName();
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -444,6 +444,7 @@ public class LocalMediaManager implements BluetoothCallback {
     *
     *
     * @return current name of the session, and return {@code null} if not found.
     * @return current name of the session, and return {@code null} if not found.
     */
     */
    @Nullable
    public CharSequence getSessionName() {
    public CharSequence getSessionName() {
        return mInfoMediaManager.getSessionName();
        return mInfoMediaManager.getSessionName();
    }
    }
+18 −20
Original line number Original line Diff line number Diff line
@@ -107,6 +107,9 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
        when(mMediaSwitchingController.getDeviceIconCompat(mMediaDevice2)).thenReturn(mIconCompat);
        when(mMediaSwitchingController.getDeviceIconCompat(mMediaDevice2)).thenReturn(mIconCompat);
        when(mMediaSwitchingController.getCurrentConnectedMediaDevice()).thenReturn(mMediaDevice1);
        when(mMediaSwitchingController.getCurrentConnectedMediaDevice()).thenReturn(mMediaDevice1);
        when(mMediaSwitchingController.isActiveRemoteDevice(mMediaDevice1)).thenReturn(true);
        when(mMediaSwitchingController.isActiveRemoteDevice(mMediaDevice1)).thenReturn(true);
        when(mMediaSwitchingController.getSessionVolumeMax()).thenReturn(TEST_MAX_VOLUME);
        when(mMediaSwitchingController.getSessionVolume()).thenReturn(TEST_CURRENT_VOLUME);
        when(mMediaSwitchingController.getSessionName()).thenReturn(TEST_SESSION_NAME);
        when(mIconCompat.toIcon(mContext)).thenReturn(mIcon);
        when(mIconCompat.toIcon(mContext)).thenReturn(mIcon);
        when(mMediaDevice1.getName()).thenReturn(TEST_DEVICE_NAME_1);
        when(mMediaDevice1.getName()).thenReturn(TEST_DEVICE_NAME_1);
        when(mMediaDevice1.getId()).thenReturn(TEST_DEVICE_ID_1);
        when(mMediaDevice1.getId()).thenReturn(TEST_DEVICE_ID_1);
@@ -163,6 +166,7 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
                mContext.getText(R.string.media_output_dialog_pairing_new).toString());
                mContext.getText(R.string.media_output_dialog_pairing_new).toString());
    }
    }


    @DisableFlags(Flags.FLAG_ENABLE_OUTPUT_SWITCHER_SESSION_GROUPING)
    @Test
    @Test
    public void onBindViewHolder_bindGroup_withSessionName_verifyView() {
    public void onBindViewHolder_bindGroup_withSessionName_verifyView() {
        when(mMediaSwitchingController.getSelectedMediaDevice())
        when(mMediaSwitchingController.getSelectedMediaDevice())
@@ -184,6 +188,7 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.VISIBLE);
    }
    }


    @DisableFlags(Flags.FLAG_ENABLE_OUTPUT_SWITCHER_SESSION_GROUPING)
    @Test
    @Test
    public void onBindViewHolder_bindGroup_noSessionName_verifyView() {
    public void onBindViewHolder_bindGroup_noSessionName_verifyView() {
        when(mMediaSwitchingController.getSelectedMediaDevice())
        when(mMediaSwitchingController.getSelectedMediaDevice())
@@ -232,6 +237,7 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE);
    }
    }


    @DisableFlags(Flags.FLAG_ENABLE_OUTPUT_SWITCHER_SESSION_GROUPING)
    @Test
    @Test
    public void onBindViewHolder_bindConnectedRemoteDevice_verifyView() {
    public void onBindViewHolder_bindConnectedRemoteDevice_verifyView() {
        when(mMediaSwitchingController.getSelectableMediaDevice())
        when(mMediaSwitchingController.getSelectableMediaDevice())
@@ -812,26 +818,22 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
        verify(mMediaSwitchingController).removeDeviceFromPlayMedia(mMediaDevice1);
        verify(mMediaSwitchingController).removeDeviceFromPlayMedia(mMediaDevice1);
    }
    }


    @DisableFlags(Flags.FLAG_ENABLE_OUTPUT_SWITCHER_SESSION_GROUPING)
    @Test
    @Test
    public void onItemClick_onGroupActionTriggered_verifySeekbarDisabled() {
    public void onBindViewHolder_hasVolumeAdjustmentRestriction_verifySeekbarDisabled() {
        when(mMediaSwitchingController.getSelectedMediaDevice())
        when(mMediaSwitchingController.getSelectedMediaDevice()).thenReturn(
                .thenReturn(
                List.of(mMediaDevice1, mMediaDevice2));
                        mMediaItems.stream()
        when(mMediaSwitchingController.isCurrentConnectedDeviceRemote()).thenReturn(true);
                                .map((item) -> item.getMediaDevice().get())
                                .collect(Collectors.toList()));
        mMediaOutputAdapter = new MediaOutputAdapter(mMediaSwitchingController);
        mMediaOutputAdapter.updateItems();
        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
        List<MediaDevice> selectableDevices = new ArrayList<>();
        selectableDevices.add(mMediaDevice1);
        when(mMediaSwitchingController.getSelectableMediaDevice()).thenReturn(selectableDevices);
        when(mMediaSwitchingController.hasAdjustVolumeUserRestriction()).thenReturn(true);
        when(mMediaSwitchingController.hasAdjustVolumeUserRestriction()).thenReturn(true);
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
        mMediaOutputAdapter.updateItems();


        mViewHolder.mContainerLayout.performClick();
        // Connected and selected device
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.GONE);


        assertThat(mViewHolder.mSeekBar.isEnabled()).isFalse();
        // Selected device
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1);
        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.GONE);
    }
    }


    @Test
    @Test
@@ -1037,10 +1039,6 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
    }
    }


    private void initializeSession() {
    private void initializeSession() {
        when(mMediaSwitchingController.getSessionVolumeMax()).thenReturn(TEST_MAX_VOLUME);
        when(mMediaSwitchingController.getSessionVolume()).thenReturn(TEST_CURRENT_VOLUME);
        when(mMediaSwitchingController.getSessionName()).thenReturn(TEST_SESSION_NAME);

        List<MediaDevice> selectedDevices = new ArrayList<>();
        List<MediaDevice> selectedDevices = new ArrayList<>();
        selectedDevices.add(mMediaDevice1);
        selectedDevices.add(mMediaDevice1);
        selectedDevices.add(mMediaDevice2);
        selectedDevices.add(mMediaDevice2);
+33 −45
Original line number Original line Diff line number Diff line
@@ -188,7 +188,9 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
            GroupStatus groupStatus = null;
            GroupStatus groupStatus = null;
            OngoingSessionStatus ongoingSessionStatus = null;
            OngoingSessionStatus ongoingSessionStatus = null;
            ConnectionState connectionState = ConnectionState.DISCONNECTED;
            ConnectionState connectionState = ConnectionState.DISCONNECTED;
            boolean restrictVolumeAdjustment = false;
            boolean restrictVolumeAdjustment = mController.hasAdjustVolumeUserRestriction();
            String subtitle = null;
            Drawable deviceStatusIcon = null;
            boolean deviceDisabled = false;
            boolean deviceDisabled = false;
            View.OnClickListener clickListener = null;
            View.OnClickListener clickListener = null;


@@ -196,11 +198,9 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                mCurrentActivePosition = -1;
                mCurrentActivePosition = -1;
            }
            }
            mItemLayout.setVisibility(View.VISIBLE);
            mItemLayout.setVisibility(View.VISIBLE);
            mStatusIcon.setVisibility(View.GONE);


            if (mController.isAnyDeviceTransferring()) {
            if (mController.isAnyDeviceTransferring()) {
                if (device.getState() == MediaDeviceState.STATE_CONNECTING
                if (device.getState() == MediaDeviceState.STATE_CONNECTING) {
                        && !mController.hasAdjustVolumeUserRestriction()) {
                    connectionState = ConnectionState.CONNECTING;
                    connectionState = ConnectionState.CONNECTING;
                }
                }
            } else {
            } else {
@@ -221,40 +221,27 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                        isDeviceGroup = true;
                        isDeviceGroup = true;
                    }
                    }
                } else if (device.hasSubtext()) {
                } else if (device.hasSubtext()) {
                    subtitle = device.getSubtextString();
                    boolean isActiveWithOngoingSession =
                    boolean isActiveWithOngoingSession =
                            device.hasOngoingSession() && (currentlyConnected || isSelected);
                            device.hasOngoingSession() && (currentlyConnected || isSelected);
                    if (isActiveWithOngoingSession) {
                    if (isActiveWithOngoingSession) {
                        mCurrentActivePosition = position;
                        mCurrentActivePosition = position;
                        mSubTitleText.setText(device.getSubtextString());
                        ongoingSessionStatus = new OngoingSessionStatus(
                        ongoingSessionStatus = new OngoingSessionStatus(
                                device.isHostForOngoingSession());
                                device.isHostForOngoingSession());
                        setSubtextAndStatus(true /* showSubtitle */, false /* showStatus */);
                        connectionState = ConnectionState.CONNECTED;
                        connectionState = ConnectionState.CONNECTED;
                    } else {
                    } else {
                        if (currentlyConnected) {
                        if (currentlyConnected) {
                            mCurrentActivePosition = position;
                            mCurrentActivePosition = position;
                            connectionState = ConnectionState.CONNECTED;
                            connectionState = ConnectionState.CONNECTED;
                        }
                        }
                        mSubTitleText.setText(device.getSubtextString());
                        Drawable deviceStatusIcon =
                                device.hasOngoingSession() ? mContext.getDrawable(
                                        R.drawable.ic_sound_bars_anim)
                                        : Api34Impl.getDeviceStatusIconBasedOnSelectionBehavior(
                                                device,
                                                mContext);
                        if (deviceStatusIcon != null) {
                            updateDeviceStatusIcon(deviceStatusIcon);
                        }
                        clickListener = getClickListenerBasedOnSelectionBehavior(device);
                        clickListener = getClickListenerBasedOnSelectionBehavior(device);
                        deviceDisabled = clickListener == null;
                        deviceDisabled = clickListener == null;
                        setSubtextAndStatus(true /* showSubtitle */,
                        deviceStatusIcon = getDeviceStatusIcon(device, device.hasOngoingSession());
                                deviceStatusIcon != null /* showStatus */);
                    }
                    }
                } else if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) {
                } else if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) {
                    updateConnectionFailedStatusIcon();
                    deviceStatusIcon = mContext.getDrawable(R.drawable.media_output_status_failed);
                    mSubTitleText.setText(R.string.media_output_dialog_connect_failed);
                    subtitle = mContext.getString(R.string.media_output_dialog_connect_failed);
                    clickListener = v -> onItemClick(v, device);
                    clickListener = v -> onItemClick(v, device);
                    setSubtextAndStatus(true /* showSubtitle */, true /* showStatus */);
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                    connectionState = ConnectionState.CONNECTING;
                    connectionState = ConnectionState.CONNECTING;
                } else if (mController.getSelectedMediaDevice().size() > 1 && isSelected) {
                } else if (mController.getSelectedMediaDevice().size() > 1 && isSelected) {
@@ -263,8 +250,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                            true /* selected */,
                            true /* selected */,
                            isDeselectable /* deselectable */);
                            isDeselectable /* deselectable */);
                    connectionState = ConnectionState.CONNECTED;
                    connectionState = ConnectionState.CONNECTED;
                } else if (!mController.hasAdjustVolumeUserRestriction()
                } else if (currentlyConnected) {
                        && currentlyConnected) {
                    // single selected device
                    // single selected device
                    if (isMutingExpectedDeviceExist
                    if (isMutingExpectedDeviceExist
                            && !mController.isCurrentConnectedDeviceRemote()) {
                            && !mController.isCurrentConnectedDeviceRemote()) {
@@ -297,23 +283,15 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                    }
                    }
                    deviceDisabled = clickListener == null;
                    deviceDisabled = clickListener == null;
                } else {
                } else {
                    Drawable deviceStatusIcon =
                    deviceStatusIcon = getDeviceStatusIcon(device, device.hasOngoingSession());
                            device.hasOngoingSession() ? mContext.getDrawable(
                                    R.drawable.ic_sound_bars_anim)
                                    : Api34Impl.getDeviceStatusIconBasedOnSelectionBehavior(
                                            device,
                                            mContext);
                    if (deviceStatusIcon != null) {
                        updateDeviceStatusIcon(deviceStatusIcon);
                        mStatusIcon.setVisibility(View.VISIBLE);
                    }
                    clickListener = getClickListenerBasedOnSelectionBehavior(device);
                    clickListener = getClickListenerBasedOnSelectionBehavior(device);
                    deviceDisabled = clickListener == null;
                    deviceDisabled = clickListener == null;
                }
                }
            }
            }


            if (isDeviceGroup) {
            if (isDeviceGroup) {
                String sessionName = mController.getSessionName().toString();
                String sessionName = mController.getSessionName() == null ? ""
                        : mController.getSessionName().toString();
                updateTitle(sessionName);
                updateTitle(sessionName);
                updateUnmutedVolumeIcon(null /* device */);
                updateUnmutedVolumeIcon(null /* device */);
                updateGroupSeekBar(getGroupItemContentDescription(sessionName));
                updateGroupSeekBar(getGroupItemContentDescription(sessionName));
@@ -328,6 +306,8 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                updateLoadingIndicator(connectionState);
                updateLoadingIndicator(connectionState);
                updateFullItemClickListener(clickListener);
                updateFullItemClickListener(clickListener);
                updateContentAlpha(deviceDisabled);
                updateContentAlpha(deviceDisabled);
                updateSubtitle(subtitle);
                updateDeviceStatusIcon(deviceStatusIcon);
                updateItemBackground(connectionState);
                updateItemBackground(connectionState);
            }
            }
        }
        }
@@ -428,19 +408,26 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                    device, mController, v -> onItemClick(v, device));
                    device, mController, v -> onItemClick(v, device));
        }
        }


        private void updateConnectionFailedStatusIcon() {
        @Nullable
            mStatusIcon.setImageDrawable(
        private Drawable getDeviceStatusIcon(MediaDevice device, boolean hasOngoingSession) {
                    mContext.getDrawable(R.drawable.media_output_status_failed));
            if (hasOngoingSession) {
            mStatusIcon.setImageTintList(
                return mContext.getDrawable(R.drawable.ic_sound_bars_anim);
                    ColorStateList.valueOf(mController.getColorItemContent()));
            } else {
                return Api34Impl.getDeviceStatusIconBasedOnSelectionBehavior(device, mContext);
            }
        }
        }


        private void updateDeviceStatusIcon(Drawable drawable) {
        void updateDeviceStatusIcon(@Nullable Drawable deviceStatusIcon) {
            mStatusIcon.setImageDrawable(drawable);
            if (deviceStatusIcon == null) {
                mStatusIcon.setVisibility(View.GONE);
            } else {
                mStatusIcon.setImageDrawable(deviceStatusIcon);
                mStatusIcon.setImageTintList(
                mStatusIcon.setImageTintList(
                        ColorStateList.valueOf(mController.getColorItemContent()));
                        ColorStateList.valueOf(mController.getColorItemContent()));
            if (drawable instanceof AnimatedVectorDrawable) {
                if (deviceStatusIcon instanceof AnimatedVectorDrawable) {
                ((AnimatedVectorDrawable) drawable).start();
                    ((AnimatedVectorDrawable) deviceStatusIcon).start();
                }
                mStatusIcon.setVisibility(View.VISIBLE);
            }
            }
        }
        }


@@ -570,6 +557,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
        }
        }


        @DoNotInline
        @DoNotInline
        @Nullable
        static Drawable getDeviceStatusIconBasedOnSelectionBehavior(MediaDevice device,
        static Drawable getDeviceStatusIconBasedOnSelectionBehavior(MediaDevice device,
                Context context) {
                Context context) {
            switch (device.getSelectionBehavior()) {
            switch (device.getSelectionBehavior()) {
+7 −3
Original line number Original line Diff line number Diff line
@@ -241,9 +241,13 @@ public abstract class MediaOutputBaseAdapter extends
            view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
            view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
        }
        }


        void setSubtextAndStatus(boolean showSubtitle, boolean showStatus) {
        void updateSubtitle(@Nullable String subtitle) {
            mStatusIcon.setVisibility(showStatus ? View.VISIBLE : View.GONE);
            if (subtitle == null) {
            mSubTitleText.setVisibility(showSubtitle ? View.VISIBLE : View.GONE);
                mSubTitleText.setVisibility(View.GONE);
            } else {
                mSubTitleText.setText(subtitle);
                mSubTitleText.setVisibility(View.VISIBLE);
            }
        }
        }


        protected void updateLoadingIndicator(ConnectionState connectionState) {
        protected void updateLoadingIndicator(ConnectionState connectionState) {
Loading