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

Commit 1b7fe82e authored by Iván Budnik's avatar Iván Budnik
Browse files

Inline MediaDeviceUtils methods

This is a non-functional simplification.

This change removes unnecessary delegation.

Test: Presubmit.
Bug: 205124386
Change-Id: Ia6b2fb2a46e53e3459012138809b451073a81ba5
parent 211c51c5
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.settingslib.media.MediaDevice.SelectionBehavior.SELECT

import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHearingAid;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
@@ -100,7 +101,12 @@ public class BluetoothMediaDevice extends MediaDevice {

    @Override
    public String getId() {
        return MediaDeviceUtils.getId(mCachedDevice);
        if (mCachedDevice.isHearingAidDevice()) {
            if (mCachedDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
                return Long.toString(mCachedDevice.getHiSyncId());
            }
        }
        return mCachedDevice.getAddress();
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public class ComplexMediaDevice extends MediaDevice {

    @Override
    public String getId() {
        return MediaDeviceUtils.getId(mRouteInfo);
        return mRouteInfo.getId();
    }

    public boolean isConnected() {
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public class InfoMediaDevice extends MediaDevice {

    @Override
    public String getId() {
        return MediaDeviceUtils.getId(mRouteInfo);
        return mRouteInfo.getId();
    }

    public boolean isConnected() {
+0 −27
Original line number Diff line number Diff line
@@ -16,29 +16,11 @@
package com.android.settingslib.media;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHearingAid;
import android.media.MediaRoute2Info;

import com.android.settingslib.bluetooth.CachedBluetoothDevice;

/**
 * MediaDeviceUtils provides utility function for MediaDevice
 */
public class MediaDeviceUtils {
    /**
     * Use CachedBluetoothDevice address to represent unique id
     *
     * @param cachedDevice the CachedBluetoothDevice
     * @return CachedBluetoothDevice address
     */
    public static String getId(CachedBluetoothDevice cachedDevice) {
        if (cachedDevice.isHearingAidDevice()) {
            if (cachedDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
                return Long.toString(cachedDevice.getHiSyncId());
            }
        }
        return cachedDevice.getAddress();
    }

    /**
     * Use BluetoothDevice address to represent unique id
@@ -50,13 +32,4 @@ public class MediaDeviceUtils {
        return bluetoothDevice.getAddress();
    }

    /**
     * Use MediaRoute2Info id to represent unique id
     *
     * @param route the MediaRoute2Info
     * @return MediaRoute2Info id
     */
    public static String getId(MediaRoute2Info route) {
        return route.getId();
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class BluetoothMediaDeviceTest {

    private static final String TEST_ADDRESS = "11:22:33:44:55:66";

    @Mock
    private CachedBluetoothDevice mDevice;

@@ -111,4 +113,10 @@ public class BluetoothMediaDeviceTest {

        assertThat(mBluetoothMediaDevice.getIcon() instanceof BitmapDrawable).isFalse();
    }

    @Test
    public void getId_returnsCachedBluetoothDeviceAddress() {
        when(mDevice.getAddress()).thenReturn(TEST_ADDRESS);
        assertThat(mBluetoothMediaDevice.getId()).isEqualTo(TEST_ADDRESS);
    }
}
Loading