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

Commit 5b3b93fc authored by Chelsea Hao's avatar Chelsea Hao Committed by Android (Google) Code Review
Browse files

Merge "Read metadata field `DEVICE_TYPE_UNTETHERED_HEADSET` when retrieving...

Merge "Read metadata field `DEVICE_TYPE_UNTETHERED_HEADSET` when retrieving icon for a CachedBluetoothDevice." into main
parents ce6e3b50 5403dcbc
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -101,6 +101,22 @@ public class BluetoothUtils {
        void onShowError(Context context, String name, int messageResId);
    }

    /**
     * @param context to access resources from
     * @param cachedDevice to get class from
     * @return pair containing the drawable and the description of the type of the device. The type
     *     could either derived from metadata or CoD.
     */
    public static Pair<Drawable, String> getDerivedBtClassDrawableWithDescription(
            Context context, CachedBluetoothDevice cachedDevice) {
        return BluetoothUtils.isAdvancedUntetheredDevice(cachedDevice.getDevice())
                ? new Pair<>(
                        getBluetoothDrawable(
                                context, com.android.internal.R.drawable.ic_bt_headphones_a2dp),
                        context.getString(R.string.bluetooth_talkback_headphone))
                : BluetoothUtils.getBtClassDrawableWithDescription(context, cachedDevice);
    }

    /**
     * @param context to access resources from
     * @param cachedDevice to get class from
@@ -731,9 +747,7 @@ public class BluetoothUtils {
        int broadcastId = broadcast.getLatestBroadcastId();
        return !sourceList.isEmpty()
                && broadcastId != UNKNOWN_VALUE_PLACEHOLDER
                && sourceList.stream()
                        .anyMatch(
                                source -> isSourceMatched(source, broadcastId));
                && sourceList.stream().anyMatch(source -> isSourceMatched(source, broadcastId));
    }

    /** Checks the connectivity status based on the provided broadcast receive state. */
@@ -1030,8 +1044,7 @@ public class BluetoothUtils {
                                        cachedDevice.getAddress());
                        break;
                    case BluetoothProfile.LE_AUDIO:
                        if (audioDeviceCategory
                                == AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER) {
                        if (audioDeviceCategory == AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER) {
                            saDevice =
                                    new AudioDeviceAttributes(
                                            AudioDeviceAttributes.ROLE_OUTPUT,
+33 −5
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.util.Pair;

import com.android.internal.R;
import com.android.settingslib.widget.AdaptiveIcon;

import com.google.common.collect.ImmutableList;
@@ -117,6 +118,34 @@ public class BluetoothUtilsTest {
        when(mHearingAid.getProfileId()).thenReturn(BluetoothProfile.HEARING_AID);
    }

    @Test
    public void
            getDerivedBtClassDrawableWithDescription_isAdvancedUntetheredDevice_returnHeadset() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
                .thenReturn(BOOL_METADATA.getBytes());
        when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
        Pair<Drawable, String> pair =
                BluetoothUtils.getDerivedBtClassDrawableWithDescription(
                        mContext, mCachedBluetoothDevice);

        verify(mContext).getDrawable(R.drawable.ic_bt_headphones_a2dp);
    }

    @Test
    public void
            getDerivedBtClassDrawableWithDescription_notAdvancedUntetheredDevice_returnPhone() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
                .thenReturn("false".getBytes());
        when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
        when(mCachedBluetoothDevice.getBtClass().getMajorDeviceClass())
                .thenReturn(BluetoothClass.Device.Major.PHONE);
        Pair<Drawable, String> pair =
                BluetoothUtils.getDerivedBtClassDrawableWithDescription(
                        mContext, mCachedBluetoothDevice);

        verify(mContext).getDrawable(R.drawable.ic_phone);
    }

    @Test
    public void getBtClassDrawableWithDescription_typePhone_returnPhoneDrawable() {
        when(mCachedBluetoothDevice.getBtClass().getMajorDeviceClass())
@@ -699,7 +728,6 @@ public class BluetoothUtilsTest {
                .isFalse();
    }


    @Test
    public void isAvailableHearingDevice_isConnectedHearingAid_returnTure() {
        when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);