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

Commit 9d3092cb authored by Tim Peng's avatar Tim Peng Committed by tim peng
Browse files

Add zero state in output switcher

-Update visibility of switcher preference in SoundSetting
-Update visibility of indicator slice in Volume Panel
-Add test case

Bug: 152357002
Test: make -j50 RunSettingsRoboTests
Change-Id: I8aa4e960b72f2c3c26ced78153c4ff620a123f40
parent df8b9acc
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -129,9 +129,9 @@ public class MediaOutputIndicatorSlice implements CustomSliceable {
        // Return true if
        // 1. AudioMode is not in on-going call
        // 2. worker is not null
        // 3. Available devices are more than 1
        // 3. Available devices are more than 0
        return getWorker() != null
                && !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
                && getWorker().getMediaDevices().size() > 1;
                && getWorker().getMediaDevices().size() > 0;
    }
}
+46 −13
Original line number Diff line number Diff line
@@ -22,8 +22,11 @@ import static android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;

import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.SpannableString;
@@ -39,6 +42,8 @@ import androidx.slice.builders.SliceAction;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.bluetooth.BluetoothPairingDetail;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.slices.SliceBroadcastReceiver;
@@ -81,7 +86,6 @@ public class MediaOutputSlice implements CustomSliceable {

        final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
                .setAccentColor(COLOR_NOT_TINTED);

        if (!isVisible()) {
            Log.d(TAG, "getSlice() is not visible");
            return listBuilder.build();
@@ -99,6 +103,11 @@ public class MediaOutputSlice implements CustomSliceable {
            }
        } else {
            final MediaDevice connectedDevice = worker.getCurrentConnectedMediaDevice();
            if (devices.size() == 1) {
                // Zero state
                addRow(connectedDevice, connectedDevice, listBuilder);
                listBuilder.addRow(getPairNewRow());
            } else {
                final boolean isTouched = worker.getIsTouched();
                // Fix the last top device when user press device to transfer.
                final MediaDevice topDevice = isTouched ? worker.getTopDevice() : connectedDevice;
@@ -114,9 +123,33 @@ public class MediaOutputSlice implements CustomSliceable {
                    }
                }
            }
        }
        return listBuilder.build();
    }

    private ListBuilder.RowBuilder getPairNewRow() {
        final Drawable d = mContext.getDrawable(R.drawable.ic_add_24dp);
        d.setColorFilter(new PorterDuffColorFilter(Utils.getColorAccentDefaultColor(mContext),
                PorterDuff.Mode.SRC_IN));
        final IconCompat icon = Utils.createIconWithDrawable(d);
        final String title = mContext.getString(R.string.bluetooth_pairing_pref_title);
        final Intent intent = new SubSettingLauncher(mContext)
                .setDestination(BluetoothPairingDetail.class.getName())
                .setTitleRes(R.string.bluetooth_pairing_page_title)
                .setSourceMetricsCategory(SettingsEnums.PANEL_MEDIA_OUTPUT)
                .toIntent();
        final SliceAction primarySliceAction = SliceAction.createDeeplink(
                PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */),
                IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp/*ic_add_blue_24dp*/),
                ListBuilder.ICON_IMAGE,
                mContext.getText(R.string.bluetooth_pairing_pref_title));
        final ListBuilder.RowBuilder builder = new ListBuilder.RowBuilder()
                .setTitleItem(icon, ListBuilder.ICON_IMAGE)
                .setTitle(title)
                .setPrimaryAction(primarySliceAction);
        return builder;
    }

    private ListBuilder.InputRangeBuilder getGroupRow() {
        final IconCompat icon = IconCompat.createWithResource(mContext,
                R.drawable.ic_speaker_group_black_24dp);
@@ -321,10 +354,10 @@ public class MediaOutputSlice implements CustomSliceable {
        // Return true if
        // 1. AudioMode is not in on-going call
        // 2. worker is not null
        // 3. Available devices are more than 1
        // 3. Available devices are more than 0
        return getWorker() != null
                && !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
                && getWorker().getMediaDevices().size() > 1;
                && getWorker().getMediaDevices().size() > 0;

    }
}
+10 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.media.AudioManager;
import android.text.TextUtils;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settingslib.Utils;
@@ -46,6 +47,15 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
        super(context, key);
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);

        if (!Utils.isAudioModeOngoingCall(mContext)) {
            mPreference.setVisible(true);
        }
    }

    @Override
    public void updateState(Preference preference) {
        if (preference == null) {
@@ -61,7 +71,6 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
            return;
        }

        boolean deviceConnected = false;
        BluetoothDevice activeDevice = null;
        // Show preference if there is connected or previously connected device
        // Find active device and set its name as the preference's summary
@@ -70,10 +79,8 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
        if (mAudioManager.getMode() == AudioManager.MODE_NORMAL
                && ((connectedA2dpDevices != null && !connectedA2dpDevices.isEmpty())
                || (connectedHADevices != null && !connectedHADevices.isEmpty()))) {
            deviceConnected = true;
            activeDevice = findActiveDevice();
        }
        mPreference.setVisible(deviceConnected);
        mPreference.setSummary((activeDevice == null) ?
                mContext.getText(R.string.media_output_default_summary) :
                activeDevice.getAlias());
+0 −1
Original line number Diff line number Diff line
@@ -123,7 +123,6 @@ public class MediaOutputIndicatorSliceTest {
    @Test
    public void getSlice_withConnectedDevice_verifyMetadata() {
        mDevices.add(mDevice1);
        mDevices.add(mDevice2);
        when(sMediaOutputIndicatorWorker.getMediaDevices()).thenReturn(mDevices);
        doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
        mAudioManager.setMode(AudioManager.MODE_NORMAL);
+63 −0
Original line number Diff line number Diff line
@@ -410,6 +410,69 @@ public class MediaOutputSliceTest {
                R.string.media_output_switch_error_text))).isNotEqualTo(-1);
    }

    @Test
    public void getSlice_zeroState_containPairingText() {
        final List<MediaDevice> mSelectedDevices = new ArrayList<>();
        final List<MediaDevice> mSelectableDevices = new ArrayList<>();
        mDevices.clear();
        final MediaDevice device = mock(MediaDevice.class);
        when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
        when(device.getIcon()).thenReturn(mTestDrawable);
        when(device.getMaxVolume()).thenReturn(100);
        when(device.isConnected()).thenReturn(true);
        when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE);
        when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
        mSelectedDevices.add(device);
        when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
        mDevices.add(device);
        when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
        when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
        mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);

        final Slice mediaSlice = mMediaOutputSlice.getSlice();
        String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
                null).toString();

        assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(
                R.string.bluetooth_pairing_pref_title))).isNotEqualTo(-1);
    }

    @Test
    public void getSlice_twoConnectedDevices_notContainPairingText() {
        final List<MediaDevice> mSelectedDevices = new ArrayList<>();
        final List<MediaDevice> mSelectableDevices = new ArrayList<>();
        mDevices.clear();
        final MediaDevice device = mock(MediaDevice.class);
        when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
        when(device.getIcon()).thenReturn(mTestDrawable);
        when(device.getMaxVolume()).thenReturn(100);
        when(device.isConnected()).thenReturn(true);
        when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
        when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
        final MediaDevice device2 = mock(MediaDevice.class);
        when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
        when(device2.getIcon()).thenReturn(mTestDrawable);
        when(device2.getMaxVolume()).thenReturn(100);
        when(device2.isConnected()).thenReturn(true);
        when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
        when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
        mSelectedDevices.add(device);
        mSelectableDevices.add(device2);
        when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
        mDevices.add(device);
        mDevices.add(device2);
        when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
        when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
        mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);

        final Slice mediaSlice = mMediaOutputSlice.getSlice();
        String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
                null).toString();

        assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(
                R.string.bluetooth_pairing_pref_title))).isEqualTo(-1);
    }

    @Test
    public void onNotifyChange_foundMediaDevice_connect() {
        mDevices.clear();
Loading