Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java +7 −17 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.BluetoothUuid; Loading @@ -28,9 +27,7 @@ import android.content.Context; import android.os.ParcelUuid; import android.os.ParcelUuid; import android.util.Log; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.settingslib.R; import com.android.settingslib.R; import com.android.settingslib.wrapper.BluetoothA2dpWrapper; import java.util.ArrayList; import java.util.ArrayList; import java.util.Arrays; import java.util.Arrays; Loading @@ -43,7 +40,6 @@ public class A2dpProfile implements LocalBluetoothProfile { private Context mContext; private Context mContext; private BluetoothA2dp mService; private BluetoothA2dp mService; private BluetoothA2dpWrapper mServiceWrapper; private boolean mIsProfileReady; private boolean mIsProfileReady; private final LocalBluetoothAdapter mLocalAdapter; private final LocalBluetoothAdapter mLocalAdapter; Loading @@ -67,7 +63,6 @@ public class A2dpProfile implements LocalBluetoothProfile { public void onServiceConnected(int profile, BluetoothProfile proxy) { public void onServiceConnected(int profile, BluetoothProfile proxy) { if (V) Log.d(TAG,"Bluetooth service connected"); if (V) Log.d(TAG,"Bluetooth service connected"); mService = (BluetoothA2dp) proxy; mService = (BluetoothA2dp) proxy; mServiceWrapper = new BluetoothA2dpWrapper(mService); // We just bound to the service, so refresh the UI for any connected A2DP devices. // We just bound to the service, so refresh the UI for any connected A2DP devices. List<BluetoothDevice> deviceList = mService.getConnectedDevices(); List<BluetoothDevice> deviceList = mService.getConnectedDevices(); while (!deviceList.isEmpty()) { while (!deviceList.isEmpty()) { Loading Loading @@ -105,11 +100,6 @@ public class A2dpProfile implements LocalBluetoothProfile { BluetoothProfile.A2DP); BluetoothProfile.A2DP); } } @VisibleForTesting void setBluetoothA2dpWrapper(BluetoothA2dpWrapper wrapper) { mServiceWrapper = wrapper; } public boolean isConnectable() { public boolean isConnectable() { return true; return true; } } Loading Loading @@ -203,12 +193,12 @@ public class A2dpProfile implements LocalBluetoothProfile { } } public boolean supportsHighQualityAudio(BluetoothDevice device) { public boolean supportsHighQualityAudio(BluetoothDevice device) { int support = mServiceWrapper.supportsOptionalCodecs(device); int support = mService.supportsOptionalCodecs(device); return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED; return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED; } } public boolean isHighQualityAudioEnabled(BluetoothDevice device) { public boolean isHighQualityAudioEnabled(BluetoothDevice device) { int enabled = mServiceWrapper.getOptionalCodecsEnabled(device); int enabled = mService.getOptionalCodecsEnabled(device); if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) { if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) { return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED; return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED; } else if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED && } else if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED && Loading @@ -219,8 +209,8 @@ public class A2dpProfile implements LocalBluetoothProfile { return true; return true; } } BluetoothCodecConfig codecConfig = null; BluetoothCodecConfig codecConfig = null; if (mServiceWrapper.getCodecStatus(device) != null) { if (mService.getCodecStatus(device) != null) { codecConfig = mServiceWrapper.getCodecStatus(device).getCodecConfig(); codecConfig = mService.getCodecStatus(device).getCodecConfig(); } } if (codecConfig != null) { if (codecConfig != null) { return !codecConfig.isMandatoryCodec(); return !codecConfig.isMandatoryCodec(); Loading @@ -233,7 +223,7 @@ public class A2dpProfile implements LocalBluetoothProfile { int prefValue = enabled int prefValue = enabled ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; mServiceWrapper.setOptionalCodecsEnabled(device, prefValue); mService.setOptionalCodecsEnabled(device, prefValue); if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED) { if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED) { return; return; } } Loading @@ -253,8 +243,8 @@ public class A2dpProfile implements LocalBluetoothProfile { // We want to get the highest priority codec, since that's the one that will be used with // We want to get the highest priority codec, since that's the one that will be used with // this device, and see if it is high-quality (ie non-mandatory). // this device, and see if it is high-quality (ie non-mandatory). BluetoothCodecConfig[] selectable = null; BluetoothCodecConfig[] selectable = null; if (mServiceWrapper.getCodecStatus(device) != null) { if (mService.getCodecStatus(device) != null) { selectable = mServiceWrapper.getCodecStatus(device).getCodecsSelectableCapabilities(); selectable = mService.getCodecStatus(device).getCodecsSelectableCapabilities(); // To get the highest priority, we sort in reverse. // To get the highest priority, we sort in reverse. Arrays.sort(selectable, Arrays.sort(selectable, (a, b) -> { (a, b) -> { Loading packages/SettingsLib/src/com/android/settingslib/wrapper/BluetoothA2dpWrapper.javadeleted 100644 → 0 +0 −70 Original line number Original line Diff line number Diff line /* * Copyright (C) 2017 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.wrapper; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothDevice; /** * This class replicates some methods of android.bluetooth.BluetoothA2dp that are new and not * yet available in our current version of Robolectric. It provides a thin wrapper to call the real * methods in production and a mock in tests. */ public class BluetoothA2dpWrapper { private BluetoothA2dp mService; public BluetoothA2dpWrapper(BluetoothA2dp service) { mService = service; } /** * @return the real {@code BluetoothA2dp} object */ public BluetoothA2dp getService() { return mService; } /** * Wraps {@code BluetoothA2dp.getCodecStatus} */ public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) { return mService.getCodecStatus(device); } /** * Wraps {@code BluetoothA2dp.supportsOptionalCodecs} */ public int supportsOptionalCodecs(BluetoothDevice device) { return mService.supportsOptionalCodecs(device); } /** * Wraps {@code BluetoothA2dp.getOptionalCodecsEnabled} */ public int getOptionalCodecsEnabled(BluetoothDevice device) { return mService.getOptionalCodecsEnabled(device); } /** * Wraps {@code BluetoothA2dp.setOptionalCodecsEnabled} */ public void setOptionalCodecsEnabled(BluetoothDevice device, int value) { mService.setOptionalCodecsEnabled(device, value); } } packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java +13 −16 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.content.Context; import android.content.res.Resources; import android.content.res.Resources; import com.android.settingslib.R; import com.android.settingslib.R; import com.android.settingslib.wrapper.BluetoothA2dpWrapper; import org.junit.Before; import org.junit.Before; import org.junit.Test; import org.junit.Test; Loading @@ -49,7 +48,6 @@ public class A2dpProfileTest { @Mock LocalBluetoothProfileManager mProfileManager; @Mock LocalBluetoothProfileManager mProfileManager; @Mock BluetoothDevice mDevice; @Mock BluetoothDevice mDevice; @Mock BluetoothA2dp mBluetoothA2dp; @Mock BluetoothA2dp mBluetoothA2dp; @Mock BluetoothA2dpWrapper mBluetoothA2dpWrapper; BluetoothProfile.ServiceListener mServiceListener; BluetoothProfile.ServiceListener mServiceListener; A2dpProfile mProfile; A2dpProfile mProfile; Loading @@ -68,31 +66,30 @@ public class A2dpProfileTest { mProfile = new A2dpProfile(mContext, mAdapter, mDeviceManager, mProfileManager); mProfile = new A2dpProfile(mContext, mAdapter, mDeviceManager, mProfileManager); mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp); mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp); mProfile.setBluetoothA2dpWrapper(mBluetoothA2dpWrapper); } } @Test @Test public void supportsHighQualityAudio() { public void supportsHighQualityAudio() { when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isTrue(); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isTrue(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN); BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); } } @Test @Test public void isHighQualityAudioEnabled() { public void isHighQualityAudioEnabled() { when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn( when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn( when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED); BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); Loading @@ -100,23 +97,23 @@ public class A2dpProfileTest { // then isHighQualityAudioEnabled() should return true or false based on whether optional // then isHighQualityAudioEnabled() should return true or false based on whether optional // codecs are supported. If the device is connected then we should ask it directly, but if // codecs are supported. If the device is connected then we should ask it directly, but if // the device isn't connected then rely on the stored pref about such support. // the device isn't connected then rely on the stored pref about such support. when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn( when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN); BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN); when(mBluetoothA2dp.getConnectionState(any())).thenReturn( when(mBluetoothA2dp.getConnectionState(any())).thenReturn( BluetoothProfile.STATE_DISCONNECTED); BluetoothProfile.STATE_DISCONNECTED); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); when(mBluetoothA2dp.getConnectionState(any())).thenReturn( when(mBluetoothA2dp.getConnectionState(any())).thenReturn( BluetoothProfile.STATE_CONNECTED); BluetoothProfile.STATE_CONNECTED); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status); when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); when(status.getCodecConfig()).thenReturn(config); when(status.getCodecConfig()).thenReturn(config); when(config.isMandatoryCodec()).thenReturn(false); when(config.isMandatoryCodec()).thenReturn(false); Loading Loading @@ -151,14 +148,14 @@ public class A2dpProfileTest { // Most tests want to simulate optional codecs being supported by the device, so do that // Most tests want to simulate optional codecs being supported by the device, so do that // by default here. // by default here. when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); } } @Test @Test public void getLableCodecsNotSupported() { public void getLableCodecsNotSupported() { setupLabelTest(); setupLabelTest(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); assertThat(mProfile.getHighQualityAudioOptionLabel(mDevice)).isEqualTo(UNKNOWN_CODEC_LABEL); assertThat(mProfile.getHighQualityAudioOptionLabel(mDevice)).isEqualTo(UNKNOWN_CODEC_LABEL); } } Loading @@ -179,7 +176,7 @@ public class A2dpProfileTest { BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig[] configs = {config}; BluetoothCodecConfig[] configs = {config}; when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status); when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(config.isMandatoryCodec()).thenReturn(true); when(config.isMandatoryCodec()).thenReturn(true); Loading @@ -194,7 +191,7 @@ public class A2dpProfileTest { BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig[] configs = {config}; BluetoothCodecConfig[] configs = {config}; when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status); when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(config.isMandatoryCodec()).thenReturn(false); when(config.isMandatoryCodec()).thenReturn(false); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java +7 −17 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.BluetoothUuid; Loading @@ -28,9 +27,7 @@ import android.content.Context; import android.os.ParcelUuid; import android.os.ParcelUuid; import android.util.Log; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.settingslib.R; import com.android.settingslib.R; import com.android.settingslib.wrapper.BluetoothA2dpWrapper; import java.util.ArrayList; import java.util.ArrayList; import java.util.Arrays; import java.util.Arrays; Loading @@ -43,7 +40,6 @@ public class A2dpProfile implements LocalBluetoothProfile { private Context mContext; private Context mContext; private BluetoothA2dp mService; private BluetoothA2dp mService; private BluetoothA2dpWrapper mServiceWrapper; private boolean mIsProfileReady; private boolean mIsProfileReady; private final LocalBluetoothAdapter mLocalAdapter; private final LocalBluetoothAdapter mLocalAdapter; Loading @@ -67,7 +63,6 @@ public class A2dpProfile implements LocalBluetoothProfile { public void onServiceConnected(int profile, BluetoothProfile proxy) { public void onServiceConnected(int profile, BluetoothProfile proxy) { if (V) Log.d(TAG,"Bluetooth service connected"); if (V) Log.d(TAG,"Bluetooth service connected"); mService = (BluetoothA2dp) proxy; mService = (BluetoothA2dp) proxy; mServiceWrapper = new BluetoothA2dpWrapper(mService); // We just bound to the service, so refresh the UI for any connected A2DP devices. // We just bound to the service, so refresh the UI for any connected A2DP devices. List<BluetoothDevice> deviceList = mService.getConnectedDevices(); List<BluetoothDevice> deviceList = mService.getConnectedDevices(); while (!deviceList.isEmpty()) { while (!deviceList.isEmpty()) { Loading Loading @@ -105,11 +100,6 @@ public class A2dpProfile implements LocalBluetoothProfile { BluetoothProfile.A2DP); BluetoothProfile.A2DP); } } @VisibleForTesting void setBluetoothA2dpWrapper(BluetoothA2dpWrapper wrapper) { mServiceWrapper = wrapper; } public boolean isConnectable() { public boolean isConnectable() { return true; return true; } } Loading Loading @@ -203,12 +193,12 @@ public class A2dpProfile implements LocalBluetoothProfile { } } public boolean supportsHighQualityAudio(BluetoothDevice device) { public boolean supportsHighQualityAudio(BluetoothDevice device) { int support = mServiceWrapper.supportsOptionalCodecs(device); int support = mService.supportsOptionalCodecs(device); return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED; return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED; } } public boolean isHighQualityAudioEnabled(BluetoothDevice device) { public boolean isHighQualityAudioEnabled(BluetoothDevice device) { int enabled = mServiceWrapper.getOptionalCodecsEnabled(device); int enabled = mService.getOptionalCodecsEnabled(device); if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) { if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) { return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED; return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED; } else if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED && } else if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED && Loading @@ -219,8 +209,8 @@ public class A2dpProfile implements LocalBluetoothProfile { return true; return true; } } BluetoothCodecConfig codecConfig = null; BluetoothCodecConfig codecConfig = null; if (mServiceWrapper.getCodecStatus(device) != null) { if (mService.getCodecStatus(device) != null) { codecConfig = mServiceWrapper.getCodecStatus(device).getCodecConfig(); codecConfig = mService.getCodecStatus(device).getCodecConfig(); } } if (codecConfig != null) { if (codecConfig != null) { return !codecConfig.isMandatoryCodec(); return !codecConfig.isMandatoryCodec(); Loading @@ -233,7 +223,7 @@ public class A2dpProfile implements LocalBluetoothProfile { int prefValue = enabled int prefValue = enabled ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; mServiceWrapper.setOptionalCodecsEnabled(device, prefValue); mService.setOptionalCodecsEnabled(device, prefValue); if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED) { if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED) { return; return; } } Loading @@ -253,8 +243,8 @@ public class A2dpProfile implements LocalBluetoothProfile { // We want to get the highest priority codec, since that's the one that will be used with // We want to get the highest priority codec, since that's the one that will be used with // this device, and see if it is high-quality (ie non-mandatory). // this device, and see if it is high-quality (ie non-mandatory). BluetoothCodecConfig[] selectable = null; BluetoothCodecConfig[] selectable = null; if (mServiceWrapper.getCodecStatus(device) != null) { if (mService.getCodecStatus(device) != null) { selectable = mServiceWrapper.getCodecStatus(device).getCodecsSelectableCapabilities(); selectable = mService.getCodecStatus(device).getCodecsSelectableCapabilities(); // To get the highest priority, we sort in reverse. // To get the highest priority, we sort in reverse. Arrays.sort(selectable, Arrays.sort(selectable, (a, b) -> { (a, b) -> { Loading
packages/SettingsLib/src/com/android/settingslib/wrapper/BluetoothA2dpWrapper.javadeleted 100644 → 0 +0 −70 Original line number Original line Diff line number Diff line /* * Copyright (C) 2017 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.wrapper; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothDevice; /** * This class replicates some methods of android.bluetooth.BluetoothA2dp that are new and not * yet available in our current version of Robolectric. It provides a thin wrapper to call the real * methods in production and a mock in tests. */ public class BluetoothA2dpWrapper { private BluetoothA2dp mService; public BluetoothA2dpWrapper(BluetoothA2dp service) { mService = service; } /** * @return the real {@code BluetoothA2dp} object */ public BluetoothA2dp getService() { return mService; } /** * Wraps {@code BluetoothA2dp.getCodecStatus} */ public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) { return mService.getCodecStatus(device); } /** * Wraps {@code BluetoothA2dp.supportsOptionalCodecs} */ public int supportsOptionalCodecs(BluetoothDevice device) { return mService.supportsOptionalCodecs(device); } /** * Wraps {@code BluetoothA2dp.getOptionalCodecsEnabled} */ public int getOptionalCodecsEnabled(BluetoothDevice device) { return mService.getOptionalCodecsEnabled(device); } /** * Wraps {@code BluetoothA2dp.setOptionalCodecsEnabled} */ public void setOptionalCodecsEnabled(BluetoothDevice device, int value) { mService.setOptionalCodecsEnabled(device, value); } }
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java +13 −16 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.content.Context; import android.content.res.Resources; import android.content.res.Resources; import com.android.settingslib.R; import com.android.settingslib.R; import com.android.settingslib.wrapper.BluetoothA2dpWrapper; import org.junit.Before; import org.junit.Before; import org.junit.Test; import org.junit.Test; Loading @@ -49,7 +48,6 @@ public class A2dpProfileTest { @Mock LocalBluetoothProfileManager mProfileManager; @Mock LocalBluetoothProfileManager mProfileManager; @Mock BluetoothDevice mDevice; @Mock BluetoothDevice mDevice; @Mock BluetoothA2dp mBluetoothA2dp; @Mock BluetoothA2dp mBluetoothA2dp; @Mock BluetoothA2dpWrapper mBluetoothA2dpWrapper; BluetoothProfile.ServiceListener mServiceListener; BluetoothProfile.ServiceListener mServiceListener; A2dpProfile mProfile; A2dpProfile mProfile; Loading @@ -68,31 +66,30 @@ public class A2dpProfileTest { mProfile = new A2dpProfile(mContext, mAdapter, mDeviceManager, mProfileManager); mProfile = new A2dpProfile(mContext, mAdapter, mDeviceManager, mProfileManager); mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp); mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp); mProfile.setBluetoothA2dpWrapper(mBluetoothA2dpWrapper); } } @Test @Test public void supportsHighQualityAudio() { public void supportsHighQualityAudio() { when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isTrue(); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isTrue(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN); BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse(); } } @Test @Test public void isHighQualityAudioEnabled() { public void isHighQualityAudioEnabled() { when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn( when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn( when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED); BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); Loading @@ -100,23 +97,23 @@ public class A2dpProfileTest { // then isHighQualityAudioEnabled() should return true or false based on whether optional // then isHighQualityAudioEnabled() should return true or false based on whether optional // codecs are supported. If the device is connected then we should ask it directly, but if // codecs are supported. If the device is connected then we should ask it directly, but if // the device isn't connected then rely on the stored pref about such support. // the device isn't connected then rely on the stored pref about such support. when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn( when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN); BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN); when(mBluetoothA2dp.getConnectionState(any())).thenReturn( when(mBluetoothA2dp.getConnectionState(any())).thenReturn( BluetoothProfile.STATE_DISCONNECTED); BluetoothProfile.STATE_DISCONNECTED); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue(); when(mBluetoothA2dp.getConnectionState(any())).thenReturn( when(mBluetoothA2dp.getConnectionState(any())).thenReturn( BluetoothProfile.STATE_CONNECTED); BluetoothProfile.STATE_CONNECTED); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status); when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); when(status.getCodecConfig()).thenReturn(config); when(status.getCodecConfig()).thenReturn(config); when(config.isMandatoryCodec()).thenReturn(false); when(config.isMandatoryCodec()).thenReturn(false); Loading Loading @@ -151,14 +148,14 @@ public class A2dpProfileTest { // Most tests want to simulate optional codecs being supported by the device, so do that // Most tests want to simulate optional codecs being supported by the device, so do that // by default here. // by default here. when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); } } @Test @Test public void getLableCodecsNotSupported() { public void getLableCodecsNotSupported() { setupLabelTest(); setupLabelTest(); when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn( when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); assertThat(mProfile.getHighQualityAudioOptionLabel(mDevice)).isEqualTo(UNKNOWN_CODEC_LABEL); assertThat(mProfile.getHighQualityAudioOptionLabel(mDevice)).isEqualTo(UNKNOWN_CODEC_LABEL); } } Loading @@ -179,7 +176,7 @@ public class A2dpProfileTest { BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig[] configs = {config}; BluetoothCodecConfig[] configs = {config}; when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status); when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(config.isMandatoryCodec()).thenReturn(true); when(config.isMandatoryCodec()).thenReturn(true); Loading @@ -194,7 +191,7 @@ public class A2dpProfileTest { BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecStatus status = mock(BluetoothCodecStatus.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig config = mock(BluetoothCodecConfig.class); BluetoothCodecConfig[] configs = {config}; BluetoothCodecConfig[] configs = {config}; when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status); when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(status.getCodecsSelectableCapabilities()).thenReturn(configs); when(config.isMandatoryCodec()).thenReturn(false); when(config.isMandatoryCodec()).thenReturn(false); Loading