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

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

Merge changes from topic "ashabalin-has-group-playback" into main

* changes:
  Consolidate group playback checks with `hasGroupPlayback` method.
  Don't add input devices to the list of selected devices.
parents ecd85b10 befbec58
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -410,6 +410,7 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
                List.of(mMediaDevice1, mMediaDevice2));
                List.of(mMediaDevice1, mMediaDevice2));
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(
                List.of(mMediaDevice1, mMediaDevice2));
                List.of(mMediaDevice1, mMediaDevice2));
        when(mMediaSwitchingController.hasGroupPlayback()).thenReturn(true);


        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
        // Expand the group control.
        // Expand the group control.
@@ -1031,7 +1032,10 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
        when(mMediaSwitchingController.getSelectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getSelectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getSelectedMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getSelectedMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.hasGroupPlayback()).thenReturn(true);


        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mMediaOutputAdapter.updateItems();
    }
    }
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -332,6 +332,7 @@ class MediaOutputAdapterTest : SysuiTestCase() {
        mMediaSwitchingController.stub {
        mMediaSwitchingController.stub {
            on { isGroupListCollapsed } doReturn false
            on { isGroupListCollapsed } doReturn false
            on { isVolumeControlEnabledForSession } doReturn true
            on { isVolumeControlEnabledForSession } doReturn true
            on { hasGroupPlayback() } doReturn true
        }
        }
        mMediaSwitchingController.stub {
        mMediaSwitchingController.stub {
            on { selectedMediaDevice } doReturn listOf(mMediaDevice1, mMediaDevice2)
            on { selectedMediaDevice } doReturn listOf(mMediaDevice1, mMediaDevice2)
@@ -790,6 +791,7 @@ class MediaOutputAdapterTest : SysuiTestCase() {
            on { selectableMediaDevice } doReturn selectedDevices
            on { selectableMediaDevice } doReturn selectedDevices
            on { selectedMediaDevice } doReturn selectedDevices
            on { selectedMediaDevice } doReturn selectedDevices
            on { deselectableMediaDevice } doReturn selectedDevices
            on { deselectableMediaDevice } doReturn selectedDevices
            on { hasGroupPlayback() } doReturn true
        }
        }
        mMediaOutputAdapter = MediaOutputAdapter(mMediaSwitchingController)
        mMediaOutputAdapter = MediaOutputAdapter(mMediaSwitchingController)
        updateAdapterWithDevices(listOf(mMediaDevice1, mMediaDevice2))
        updateAdapterWithDevices(listOf(mMediaDevice1, mMediaDevice2))
+1 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :
            // Avoid grouping broadcast devices because grouped volume control is not available for
            // Avoid grouping broadcast devices because grouped volume control is not available for
            // broadcast session.
            // broadcast session.
            mGroupSelectedItems =
            mGroupSelectedItems =
                mController.selectedMediaDevice.size > 1 &&
                mController.hasGroupPlayback() &&
                    (!Flags.enableOutputSwitcherPersonalAudioSharing() ||
                    (!Flags.enableOutputSwitcherPersonalAudioSharing() ||
                        mController.isVolumeControlEnabledForSession)
                        mController.isVolumeControlEnabledForSession)
        }
        }
+4 −8
Original line number Original line Diff line number Diff line
@@ -75,7 +75,7 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
    boolean isCurrentlyConnected(MediaDevice device) {
    boolean isCurrentlyConnected(MediaDevice device) {
        return TextUtils.equals(device.getId(),
        return TextUtils.equals(device.getId(),
                mController.getCurrentConnectedMediaDevice().getId())
                mController.getCurrentConnectedMediaDevice().getId())
                || (mController.getSelectedMediaDevice().size() == 1
                || (!mController.hasGroupPlayback()
                && isDeviceIncluded(mController.getSelectedMediaDevice(), device));
                && isDeviceIncluded(mController.getSelectedMediaDevice(), device));
    }
    }


@@ -105,7 +105,7 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
        mMediaItemList.clear();
        mMediaItemList.clear();
        mMediaItemList.addAll(mController.getMediaItemList());
        mMediaItemList.addAll(mController.getMediaItemList());
        if (mShouldGroupSelectedMediaItems) {
        if (mShouldGroupSelectedMediaItems) {
            if (mController.getSelectedMediaDevice().size() == 1) {
            if (!mController.hasGroupPlayback()) {
                // Don't group devices if initially there isn't more than one selected.
                // Don't group devices if initially there isn't more than one selected.
                mShouldGroupSelectedMediaItems = false;
                mShouldGroupSelectedMediaItems = false;
            }
            }
@@ -197,7 +197,7 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                    connectionState = ConnectionState.CONNECTING;
                    connectionState = ConnectionState.CONNECTING;
                } else if (!enableOutputSwitcherRedesign() && mShouldGroupSelectedMediaItems
                } else if (!enableOutputSwitcherRedesign() && mShouldGroupSelectedMediaItems
                        && hasMultipleSelectedDevices()
                        && mController.hasGroupPlayback()
                        && isSelected) {
                        && isSelected) {
                    if (mediaItem.isFirstDeviceInGroup()) {
                    if (mediaItem.isFirstDeviceInGroup()) {
                        isDeviceGroup = true;
                        isDeviceGroup = true;
@@ -263,17 +263,13 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
            // A device should either be selectable or, when the device selected, the list should
            // A device should either be selectable or, when the device selected, the list should
            // have other selectable or selected devices.
            // have other selectable or selected devices.
            boolean selectedWithOtherGroupDevices =
            boolean selectedWithOtherGroupDevices =
                    isSelected && (hasMultipleSelectedDevices() || hasSelectableDevices());
                    isSelected && (mController.hasGroupPlayback() || hasSelectableDevices());
            if (isSelectable || selectedWithOtherGroupDevices) {
            if (isSelectable || selectedWithOtherGroupDevices) {
                return new GroupStatus(isSelected, isDeselectable);
                return new GroupStatus(isSelected, isDeselectable);
            }
            }
            return null;
            return null;
        }
        }


        private boolean hasMultipleSelectedDevices() {
            return mController.getSelectedMediaDevice().size() > 1;
        }

        private boolean hasSelectableDevices() {
        private boolean hasSelectableDevices() {
            return !mController.getSelectableMediaDevice().isEmpty();
            return !mController.getSelectableMediaDevice().isEmpty();
        }
        }
+6 −20
Original line number Original line Diff line number Diff line
@@ -647,17 +647,14 @@ public class MediaSwitchingController
                mContext.getString(R.string.media_output_group_title_connected_speakers));
                mContext.getString(R.string.media_output_group_title_connected_speakers));
    }
    }


    @Nullable
    boolean hasGroupPlayback() {
    MediaItem getConnectNewDeviceItem() {
        return getSelectedMediaDevice().size() > 1;
        boolean isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() == 1;
        if (enableInputRouting()) {
            // When input routing is enabled, there are expected to be at least 2 total selected
            // devices: one output device and one input device.
            isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() <= 2;
    }
    }


    @Nullable
    MediaItem getConnectNewDeviceItem() {
        // Attach "Connect a device" item only when current output is not remote and not a group
        // Attach "Connect a device" item only when current output is not remote and not a group
        return (!isCurrentConnectedDeviceRemote() && isSelectedDeviceNotAGroup)
        return (!isCurrentConnectedDeviceRemote() && !hasGroupPlayback())
                ? MediaItem.createPairNewDeviceMediaItem()
                ? MediaItem.createPairNewDeviceMediaItem()
                : null;
                : null;
    }
    }
@@ -779,20 +776,9 @@ public class MediaSwitchingController
    }
    }


    public List<MediaDevice> getSelectedMediaDevice() {
    public List<MediaDevice> getSelectedMediaDevice() {
        if (!enableInputRouting()) {
        return mLocalMediaManager.getSelectedMediaDevice();
        return mLocalMediaManager.getSelectedMediaDevice();
    }
    }


        // Add selected input device if input routing is supported.
        List<MediaDevice> selectedDevices =
                new ArrayList<>(mLocalMediaManager.getSelectedMediaDevice());
        MediaDevice selectedInputDevice = mInputRouteManager.getSelectedInputDevice();
        if (selectedInputDevice != null) {
            selectedDevices.add(selectedInputDevice);
        }
        return selectedDevices;
    }

    List<MediaDevice> getDeselectableMediaDevice() {
    List<MediaDevice> getDeselectableMediaDevice() {
        return mLocalMediaManager.getDeselectableMediaDevice();
        return mLocalMediaManager.getDeselectableMediaDevice();
    }
    }
Loading