diff options
6 files changed, 17 insertions, 144 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java index 33550d57223e..cdb87404b016 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java @@ -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; @@ -98,7 +99,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(); } /** diff --git a/packages/SettingsLib/src/com/android/settingslib/media/ComplexMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/ComplexMediaDevice.java index 7a5477b5aef4..338fb872650c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/ComplexMediaDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/ComplexMediaDevice.java @@ -62,7 +62,7 @@ public class ComplexMediaDevice extends MediaDevice { @Override public String getId() { - return MediaDeviceUtils.getId(mRouteInfo); + return mRouteInfo.getId(); } public boolean isConnected() { diff --git a/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaDevice.java index 0a26bf21c6d0..1347dd131f69 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaDevice.java @@ -117,7 +117,7 @@ public class InfoMediaDevice extends MediaDevice { @Override public String getId() { - return MediaDeviceUtils.getId(mRouteInfo); + return mRouteInfo.getId(); } public boolean isConnected() { diff --git a/packages/SettingsLib/src/com/android/settingslib/media/MediaDeviceUtils.java b/packages/SettingsLib/src/com/android/settingslib/media/MediaDeviceUtils.java deleted file mode 100644 index b3a52b9ec788..000000000000 --- a/packages/SettingsLib/src/com/android/settingslib/media/MediaDeviceUtils.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 - * - * @param bluetoothDevice the BluetoothDevice - * @return BluetoothDevice address - */ - public static String getId(BluetoothDevice bluetoothDevice) { - 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(); - } -} diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java index 0d299b57f80a..7061742a56d2 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java @@ -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); + } } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/MediaDeviceUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/MediaDeviceUtilsTest.java deleted file mode 100644 index 30a6ad2576db..000000000000 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/MediaDeviceUtilsTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settingslib.media; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.when; - -import android.bluetooth.BluetoothDevice; -import android.media.MediaRoute2Info; - -import com.android.settingslib.bluetooth.CachedBluetoothDevice; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class MediaDeviceUtilsTest { - - private static final String TEST_ADDRESS = "11:22:33:44:55:66"; - private static final String TEST_ROUTE_ID = "test_route_id"; - - @Mock - private CachedBluetoothDevice mCachedDevice; - @Mock - private BluetoothDevice mBluetoothDevice; - @Mock - private MediaRoute2Info mRouteInfo; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void getId_returnCachedBluetoothDeviceAddress() { - when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS); - - final String id = MediaDeviceUtils.getId(mCachedDevice); - - assertThat(id).isEqualTo(TEST_ADDRESS); - } - - @Test - public void getId_returnBluetoothDeviceAddress() { - when(mBluetoothDevice.getAddress()).thenReturn(TEST_ADDRESS); - - final String id = MediaDeviceUtils.getId(mBluetoothDevice); - - assertThat(id).isEqualTo(TEST_ADDRESS); - } - - @Test - public void getId_returnRouteInfoId() { - when(mRouteInfo.getId()).thenReturn(TEST_ROUTE_ID); - - final String id = MediaDeviceUtils.getId(mRouteInfo); - - assertThat(id).isEqualTo(TEST_ROUTE_ID); - } -} |