Revert "Revert "Pass in active device to all BluetoothA2dp APIs ..."

Revert submission 10303287-revert-10253996-bt-a2dp-no-null-FQRXACWPIA

Reason for revert: Fixing breakage
Reverted Changes:
I4d9f2f819:Revert "Make sure calls to BluetoothA2dp APIs pass...
I771ca0d57:Revert "Need to now pass in active device instead ...
I76529c7a1:Revert "Pass in active device to all BluetoothA2dp...
I297bda68d:Revert "Require user pass in a non-null BluetoothD...
I525327959:Revert "Pass in active device to all BluetoothA2dp...
I1d8660b11:Revert "Pass in active device to all BluetoothA2dp...

Bug: 147287141
Test: robotests
Merged-In: I5aecfa4b5a8e371b914573ddd080acb98078bfca
Change-Id: I5aecfa4b5a8e371b914573ddd080acb98078bfca
This commit is contained in:
Rahul Sabnis
2020-02-25 22:28:00 +00:00
parent f7fe2b0dec
commit 3e0f661f11
11 changed files with 137 additions and 45 deletions

View File

@@ -83,7 +83,11 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
synchronized (mBluetoothA2dpConfigStore) { synchronized (mBluetoothA2dpConfigStore) {
if (mBluetoothA2dp != null) { if (mBluetoothA2dp != null) {
setCodecConfigPreference(null, codecConfig); // Use current active device BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
return false;
}
setCodecConfigPreference(activeDevice, codecConfig);
} }
} }
// Because the setting is not persisted into permanent storage, we cannot call update state // Because the setting is not persisted into permanent storage, we cannot call update state
@@ -102,13 +106,14 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
if (getCodecConfig(null) == null || mPreference == null) { // Use current active device BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null || getCodecConfig(activeDevice) == null || mPreference == null) {
return; return;
} }
BluetoothCodecConfig codecConfig; BluetoothCodecConfig codecConfig;
synchronized (mBluetoothA2dpConfigStore) { synchronized (mBluetoothA2dpConfigStore) {
codecConfig = getCodecConfig(null); // Use current active device codecConfig = getCodecConfig(activeDevice);
} }
final int index = getCurrentA2dpSettingIndex(codecConfig); final int index = getCurrentA2dpSettingIndex(codecConfig);
@@ -178,13 +183,23 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
@VisibleForTesting @VisibleForTesting
void setCodecConfigPreference(BluetoothDevice device, void setCodecConfigPreference(BluetoothDevice device,
BluetoothCodecConfig config) { BluetoothCodecConfig config) {
mBluetoothA2dp.setCodecConfigPreference(device, config); BluetoothDevice bluetoothDevice =
(device != null) ? device : mBluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return;
}
mBluetoothA2dp.setCodecConfigPreference(bluetoothDevice, config);
} }
@VisibleForTesting @VisibleForTesting
BluetoothCodecConfig getCodecConfig(BluetoothDevice device) { BluetoothCodecConfig getCodecConfig(BluetoothDevice device) {
if (mBluetoothA2dp != null) { if (mBluetoothA2dp != null) {
BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(device); BluetoothDevice bluetoothDevice =
(device != null) ? device : mBluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return null;
}
BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(bluetoothDevice);
if (codecStatus != null) { if (codecStatus != null) {
return codecStatus.getCodecConfig(); return codecStatus.getCodecConfig();
} }

View File

@@ -80,7 +80,10 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
} }
writeConfigurationValues(index); writeConfigurationValues(index);
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
bluetoothA2dp.setCodecConfigPreference(null, codecConfig); BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice != null) {
bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig);
}
mPreference.setSummary(((BaseBluetoothDialogPreference) mPreference).generateSummary( mPreference.setSummary(((BaseBluetoothDialogPreference) mPreference).generateSummary(
index)); index));
} }
@@ -146,7 +149,13 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
if (bluetoothA2dp == null) { if (bluetoothA2dp == null) {
return null; return null;
} }
final BluetoothCodecStatus codecStatus = bluetoothA2dp.getCodecStatus(null); BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
Log.d(TAG, "Unable to get current codec config. No active device.");
return null;
}
final BluetoothCodecStatus codecStatus =
bluetoothA2dp.getCodecStatus(activeDevice);
if (codecStatus == null) { if (codecStatus == null) {
Log.d(TAG, "Unable to get current codec config. Codec status is null"); Log.d(TAG, "Unable to get current codec config. Codec status is null");
return null; return null;
@@ -164,7 +173,12 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
if (bluetoothA2dp == null) { if (bluetoothA2dp == null) {
return null; return null;
} }
final BluetoothCodecStatus codecStatus = bluetoothA2dp.getCodecStatus(device); BluetoothDevice bluetoothDevice =
(device != null) ? device : bluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return null;
}
final BluetoothCodecStatus codecStatus = bluetoothA2dp.getCodecStatus(bluetoothDevice);
if (codecStatus != null) { if (codecStatus != null) {
return codecStatus.getCodecsSelectableCapabilities(); return codecStatus.getCodecsSelectableCapabilities();
} }
@@ -177,7 +191,12 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
* @return {@link BluetoothCodecConfig}. * @return {@link BluetoothCodecConfig}.
*/ */
protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) { protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) {
final BluetoothCodecConfig[] configs = getSelectableConfigs(null); BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
Log.d(TAG, "Unable to get selectable config. No active device.");
return null;
}
final BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice);
if (configs == null) { if (configs == null) {
Log.d(TAG, "Unable to get selectable config. Selectable configs is empty."); Log.d(TAG, "Unable to get selectable config. Selectable configs is empty.");
return null; return null;

View File

@@ -83,9 +83,9 @@ public class BluetoothCodecDialogPreferenceController extends
return index; return index;
} }
// Check HD audio is enabled, display the available list. // Check HD audio is enabled, display the available list.
if (bluetoothA2dp.getOptionalCodecsEnabled(activeDevice) if (bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) { == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
BluetoothCodecConfig[] configs = getSelectableConfigs(null); BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice);
if (configs != null) { if (configs != null) {
return getIndexFromConfig(configs); return getIndexFromConfig(configs);
} }
@@ -101,7 +101,8 @@ public class BluetoothCodecDialogPreferenceController extends
int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
switch (index) { switch (index) {
case 0: case 0:
codecTypeValue = getHighestCodec(getSelectableConfigs(null)); codecTypeValue = getHighestCodec(getSelectableConfigs(
mBluetoothA2dp.getActiveDevice()));
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
break; break;
case 1: case 1:

View File

@@ -58,11 +58,11 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe
mPreference.setEnabled(false); mPreference.setEnabled(false);
return; return;
} }
final boolean supported = (bluetoothA2dp.supportsOptionalCodecs(activeDevice) final boolean supported = (bluetoothA2dp.isOptionalCodecsSupported(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
mPreference.setEnabled(supported); mPreference.setEnabled(supported);
if (supported) { if (supported) {
final boolean isEnabled = bluetoothA2dp.getOptionalCodecsEnabled(activeDevice) final boolean isEnabled = bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED; == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED;
((SwitchPreference) mPreference).setChecked(isEnabled); ((SwitchPreference) mPreference).setChecked(isEnabled);
} }
@@ -84,11 +84,16 @@ public class BluetoothHDAudioPreferenceController extends AbstractBluetoothPrefe
final int prefValue = enabled final int prefValue = enabled
? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED
: BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
bluetoothA2dp.setOptionalCodecsEnabled(bluetoothA2dp.getActiveDevice(), prefValue); BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
mPreference.setEnabled(false);
return true;
}
bluetoothA2dp.setOptionalCodecsEnabled(activeDevice, prefValue);
if (enabled) { if (enabled) {
bluetoothA2dp.enableOptionalCodecs(null); // Use current active device bluetoothA2dp.enableOptionalCodecs(activeDevice);
} else { } else {
bluetoothA2dp.disableOptionalCodecs(null); // Use current active device bluetoothA2dp.disableOptionalCodecs(activeDevice);
} }
mCallback.onBluetoothHDAudioEnabled(enabled); mCallback.onBluetoothHDAudioEnabled(enabled);
return true; return true;

View File

@@ -24,8 +24,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -49,6 +51,7 @@ import java.util.List;
public class AbstractBluetoothDialogPreferenceControllerTest { public class AbstractBluetoothDialogPreferenceControllerTest {
private static final String SUMMARY = "Test summary"; private static final String SUMMARY = "Test summary";
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
@Mock @Mock
private BluetoothA2dp mBluetoothA2dp; private BluetoothA2dp mBluetoothA2dp;
@@ -62,6 +65,7 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
private BluetoothCodecConfig mCodecConfigAAC; private BluetoothCodecConfig mCodecConfigAAC;
private BluetoothCodecConfig mCodecConfigSBC; private BluetoothCodecConfig mCodecConfigSBC;
private BluetoothCodecConfig[] mCodecConfigs = new BluetoothCodecConfig[2]; private BluetoothCodecConfig[] mCodecConfigs = new BluetoothCodecConfig[2];
private BluetoothDevice mActiveDevice;
private Context mContext; private Context mContext;
private int mCurrentConfig; private int mCurrentConfig;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
@@ -74,6 +78,7 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
mLifecycleOwner = () -> mLifecycle; mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore()); mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = spy(new AbstractBluetoothDialogPreferenceControllerImpl(mContext, mLifecycle, mController = spy(new AbstractBluetoothDialogPreferenceControllerImpl(mContext, mLifecycle,
mBluetoothA2dpConfigStore)); mBluetoothA2dpConfigStore));
mPreference = spy(new BaseBluetoothDialogPreferenceImpl(mContext)); mPreference = spy(new BaseBluetoothDialogPreferenceImpl(mContext));
@@ -87,6 +92,7 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mCurrentConfig = mController.getCurrentConfigIndex(); mCurrentConfig = mController.getCurrentConfigIndex();
when(mPreference.generateSummary(mCurrentConfig)).thenReturn(SUMMARY); when(mPreference.generateSummary(mCurrentConfig)).thenReturn(SUMMARY);
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
} }
@Test @Test
@@ -103,13 +109,15 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
@Test @Test
public void onIndexUpdated_checkFlow() { public void onIndexUpdated_checkFlow() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mCodecConfigAAC); when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mCodecConfigAAC);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.onIndexUpdated(mCurrentConfig); mController.onIndexUpdated(mCurrentConfig);
verify(mController).writeConfigurationValues(mCurrentConfig); verify(mController).writeConfigurationValues(mCurrentConfig);
verify(mBluetoothA2dp).setCodecConfigPreference(null, mCodecConfigAAC); verify(mBluetoothA2dp).setCodecConfigPreference(
mActiveDevice, mCodecConfigAAC);
assertThat(mPreference.getSummary()).isEqualTo(SUMMARY); assertThat(mPreference.getSummary()).isEqualTo(SUMMARY);
} }
@@ -134,14 +142,15 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
assertThat(mController.getCurrentCodecConfig()).isNull(); assertThat(mController.getCurrentCodecConfig()).isNull();
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(null); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(null);
assertThat(mController.getCurrentCodecConfig()).isNull(); assertThat(mController.getCurrentCodecConfig()).isNull();
} }
@Test @Test
public void getCurrentCodecConfig_verifyConfig() { public void getCurrentCodecConfig_verifyConfig() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getCurrentCodecConfig()).isEqualTo(mCodecConfigAAC); assertThat(mController.getCurrentCodecConfig()).isEqualTo(mCodecConfigAAC);
@@ -150,7 +159,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
@Test @Test
public void getSelectableConfigs_verifyConfig() { public void getSelectableConfigs_verifyConfig() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs); assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs);
@@ -159,7 +169,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
@Test @Test
public void getSelectableByCodecType_verifyConfig() { public void getSelectableByCodecType_verifyConfig() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getSelectableByCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)) assertThat(mController.getSelectableByCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC))
@@ -169,7 +180,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
@Test @Test
public void getSelectableByCodecType_unavailable() { public void getSelectableByCodecType_unavailable() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getSelectableByCodecType( assertThat(mController.getSelectableByCodecType(
@@ -179,7 +191,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
@Test @Test
public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() { public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecConfigAAC.getCodecType()); verify(mBluetoothA2dpConfigStore).setCodecType(mCodecConfigAAC.getCodecType());

View File

@@ -23,8 +23,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -47,6 +49,8 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class BluetoothBitPerSampleDialogPreferenceControllerTest { public class BluetoothBitPerSampleDialogPreferenceControllerTest {
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
@Mock @Mock
private BluetoothA2dp mBluetoothA2dp; private BluetoothA2dp mBluetoothA2dp;
@Mock @Mock
@@ -58,6 +62,7 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest {
private BluetoothCodecStatus mCodecStatus; private BluetoothCodecStatus mCodecStatus;
private BluetoothCodecConfig mCodecConfigAAC; private BluetoothCodecConfig mCodecConfigAAC;
private BluetoothCodecConfig mCodecConfigSBC; private BluetoothCodecConfig mCodecConfigSBC;
private BluetoothDevice mActiveDevice;
private Context mContext; private Context mContext;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
@@ -69,6 +74,7 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest {
mLifecycleOwner = () -> mLifecycle; mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore()); mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = spy(new BluetoothBitPerSampleDialogPreferenceController(mContext, mLifecycle, mController = spy(new BluetoothBitPerSampleDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore)); mBluetoothA2dpConfigStore));
mPreference = new BluetoothBitPerSampleDialogPreference(mContext); mPreference = new BluetoothBitPerSampleDialogPreference(mContext);
@@ -86,13 +92,14 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest {
BluetoothCodecConfig.BITS_PER_SAMPLE_24, BluetoothCodecConfig.BITS_PER_SAMPLE_24,
BluetoothCodecConfig.CHANNEL_MODE_NONE, BluetoothCodecConfig.CHANNEL_MODE_NONE,
0, 0, 0, 0); 0, 0, 0, 0);
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
} }
@Test @Test
public void writeConfigurationValues_selectDefault_setHighest() { public void writeConfigurationValues_selectDefault_setHighest() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0); mController.writeConfigurationValues(0);
@@ -121,7 +128,7 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest {
public void getSelectableIndex_verifyList() { public void getSelectableIndex_verifyList() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
List<Integer> indexList = new ArrayList<>(); List<Integer> indexList = new ArrayList<>();
indexList.add(mPreference.getDefaultIndex()); indexList.add(mPreference.getDefaultIndex());

View File

@@ -23,8 +23,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -47,6 +49,8 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class BluetoothChannelModeDialogPreferenceControllerTest { public class BluetoothChannelModeDialogPreferenceControllerTest {
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
@Mock @Mock
private BluetoothA2dp mBluetoothA2dp; private BluetoothA2dp mBluetoothA2dp;
@Mock @Mock
@@ -58,6 +62,7 @@ public class BluetoothChannelModeDialogPreferenceControllerTest {
private BluetoothCodecStatus mCodecStatus; private BluetoothCodecStatus mCodecStatus;
private BluetoothCodecConfig mCodecConfigAAC; private BluetoothCodecConfig mCodecConfigAAC;
private BluetoothCodecConfig mCodecConfigSBC; private BluetoothCodecConfig mCodecConfigSBC;
private BluetoothDevice mActiveDevice;
private Context mContext; private Context mContext;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
@@ -69,6 +74,7 @@ public class BluetoothChannelModeDialogPreferenceControllerTest {
mLifecycleOwner = () -> mLifecycle; mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore()); mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = new BluetoothChannelModeDialogPreferenceController(mContext, mLifecycle, mController = new BluetoothChannelModeDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore); mBluetoothA2dpConfigStore);
mPreference = new BluetoothChannelModeDialogPreference(mContext); mPreference = new BluetoothChannelModeDialogPreference(mContext);
@@ -86,13 +92,14 @@ public class BluetoothChannelModeDialogPreferenceControllerTest {
BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
BluetoothCodecConfig.CHANNEL_MODE_MONO | BluetoothCodecConfig.CHANNEL_MODE_STEREO, BluetoothCodecConfig.CHANNEL_MODE_MONO | BluetoothCodecConfig.CHANNEL_MODE_STEREO,
0, 0, 0, 0); 0, 0, 0, 0);
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
} }
@Test @Test
public void writeConfigurationValues_selectDefault_setHighest() { public void writeConfigurationValues_selectDefault_setHighest() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0); mController.writeConfigurationValues(0);
@@ -118,7 +125,7 @@ public class BluetoothChannelModeDialogPreferenceControllerTest {
public void getSelectableIndex_verifyList() { public void getSelectableIndex_verifyList() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
List<Integer> indexList = new ArrayList<>(); List<Integer> indexList = new ArrayList<>();
indexList.add(mPreference.getDefaultIndex()); indexList.add(mPreference.getDefaultIndex());

View File

@@ -24,8 +24,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -45,6 +47,8 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class BluetoothCodecDialogPreferenceControllerTest { public class BluetoothCodecDialogPreferenceControllerTest {
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
@Mock @Mock
private BluetoothA2dp mBluetoothA2dp; private BluetoothA2dp mBluetoothA2dp;
@Mock @Mock
@@ -61,10 +65,12 @@ public class BluetoothCodecDialogPreferenceControllerTest {
private BluetoothCodecConfig mCodecConfigAPTX; private BluetoothCodecConfig mCodecConfigAPTX;
private BluetoothCodecConfig mCodecConfigAPTXHD; private BluetoothCodecConfig mCodecConfigAPTXHD;
private BluetoothCodecConfig mCodecConfigLDAC; private BluetoothCodecConfig mCodecConfigLDAC;
private BluetoothDevice mActiveDevice;
private Context mContext; private Context mContext;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
@Before @Before
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
@@ -72,6 +78,7 @@ public class BluetoothCodecDialogPreferenceControllerTest {
mLifecycleOwner = () -> mLifecycle; mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore()); mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = new BluetoothCodecDialogPreferenceController(mContext, mLifecycle, mController = new BluetoothCodecDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore, mCallback); mBluetoothA2dpConfigStore, mCallback);
mPreference = new BluetoothCodecDialogPreference(mContext); mPreference = new BluetoothCodecDialogPreference(mContext);
@@ -93,13 +100,14 @@ public class BluetoothCodecDialogPreferenceControllerTest {
mCodecConfigAPTXHD = new BluetoothCodecConfig( mCodecConfigAPTXHD = new BluetoothCodecConfig(
BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD); BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD);
mCodecConfigLDAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC); mCodecConfigLDAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC);
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
} }
@Test @Test
public void writeConfigurationValues_selectDefault_setHighest() { public void writeConfigurationValues_selectDefault_setHighest() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0); mController.writeConfigurationValues(0);
@@ -111,7 +119,7 @@ public class BluetoothCodecDialogPreferenceControllerTest {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX, BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC}; mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(1); mController.writeConfigurationValues(1);
@@ -138,7 +146,7 @@ public class BluetoothCodecDialogPreferenceControllerTest {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX, BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC}; mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(2); mController.writeConfigurationValues(2);

View File

@@ -59,10 +59,10 @@ public class BluetoothHDAudioPreferenceControllerTest {
private BluetoothHDAudioPreferenceController mController; private BluetoothHDAudioPreferenceController mController;
private SwitchPreference mPreference; private SwitchPreference mPreference;
private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore; private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
private BluetoothDevice mActiveDevice;
private Context mContext; private Context mContext;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private BluetoothDevice mActiveDevice;
@Before @Before
public void setup() { public void setup() {
@@ -91,7 +91,7 @@ public class BluetoothHDAudioPreferenceControllerTest {
@Test @Test
public void updateState_codecSupported_setEnable() { public void updateState_codecSupported_setEnable() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn( when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -102,7 +102,7 @@ public class BluetoothHDAudioPreferenceControllerTest {
@Test @Test
public void updateState_codecNotSupported_setDisable() { public void updateState_codecNotSupported_setDisable() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn( when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED); mBluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -113,9 +113,9 @@ public class BluetoothHDAudioPreferenceControllerTest {
@Test @Test
public void updateState_codecSupportedAndEnabled_checked() { public void updateState_codecSupportedAndEnabled_checked() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn( when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
when(mBluetoothA2dp.getOptionalCodecsEnabled(mActiveDevice)).thenReturn( when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); mBluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -126,9 +126,9 @@ public class BluetoothHDAudioPreferenceControllerTest {
@Test @Test
public void updateState_codecSupportedAndDisabled_notChecked() { public void updateState_codecSupportedAndDisabled_notChecked() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn( when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED); mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
when(mBluetoothA2dp.getOptionalCodecsEnabled(mActiveDevice)).thenReturn( when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED); mBluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -143,7 +143,7 @@ public class BluetoothHDAudioPreferenceControllerTest {
final boolean enabled = false; final boolean enabled = false;
mController.onPreferenceChange(mPreference, enabled); mController.onPreferenceChange(mPreference, enabled);
verify(mBluetoothA2dp).disableOptionalCodecs(null); verify(mBluetoothA2dp).disableOptionalCodecs(mActiveDevice);
verify(mBluetoothA2dp).setOptionalCodecsEnabled(mActiveDevice, verify(mBluetoothA2dp).setOptionalCodecsEnabled(mActiveDevice,
BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED); BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED);
verify(mCallback).onBluetoothHDAudioEnabled(enabled); verify(mCallback).onBluetoothHDAudioEnabled(enabled);
@@ -156,7 +156,7 @@ public class BluetoothHDAudioPreferenceControllerTest {
final boolean enabled = true; final boolean enabled = true;
mController.onPreferenceChange(mPreference, enabled); mController.onPreferenceChange(mPreference, enabled);
verify(mBluetoothA2dp).enableOptionalCodecs(null); verify(mBluetoothA2dp).enableOptionalCodecs(mActiveDevice);
verify(mBluetoothA2dp).setOptionalCodecsEnabled(mActiveDevice, verify(mBluetoothA2dp).setOptionalCodecsEnabled(mActiveDevice,
BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
verify(mCallback).onBluetoothHDAudioEnabled(enabled); verify(mCallback).onBluetoothHDAudioEnabled(enabled);

View File

@@ -23,8 +23,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -44,6 +46,8 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class BluetoothQualityDialogPreferenceControllerTest { public class BluetoothQualityDialogPreferenceControllerTest {
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
@Mock @Mock
private BluetoothA2dp mBluetoothA2dp; private BluetoothA2dp mBluetoothA2dp;
@Mock @Mock
@@ -55,6 +59,7 @@ public class BluetoothQualityDialogPreferenceControllerTest {
private BluetoothCodecStatus mCodecStatus; private BluetoothCodecStatus mCodecStatus;
private BluetoothCodecConfig mCodecConfigAAC; private BluetoothCodecConfig mCodecConfigAAC;
private BluetoothCodecConfig mCodecConfigLDAC; private BluetoothCodecConfig mCodecConfigLDAC;
private BluetoothDevice mActiveDevice;
private Context mContext; private Context mContext;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
@@ -66,6 +71,7 @@ public class BluetoothQualityDialogPreferenceControllerTest {
mLifecycleOwner = () -> mLifecycle; mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore()); mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = new BluetoothQualityDialogPreferenceController(mContext, mLifecycle, mController = new BluetoothQualityDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore); mBluetoothA2dpConfigStore);
mPreference = new BluetoothQualityDialogPreference(mContext); mPreference = new BluetoothQualityDialogPreference(mContext);
@@ -83,6 +89,7 @@ public class BluetoothQualityDialogPreferenceControllerTest {
BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
BluetoothCodecConfig.CHANNEL_MODE_NONE, BluetoothCodecConfig.CHANNEL_MODE_NONE,
1001, 0, 0, 0); 1001, 0, 0, 0);
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
} }
@Test @Test
@@ -110,7 +117,7 @@ public class BluetoothQualityDialogPreferenceControllerTest {
public void updateState_codeTypeIsLDAC_enablePreference() { public void updateState_codeTypeIsLDAC_enablePreference() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -121,7 +128,7 @@ public class BluetoothQualityDialogPreferenceControllerTest {
public void updateState_codeTypeAAC_disablePreference() { public void updateState_codeTypeAAC_disablePreference() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference); mController.updateState(mPreference);

View File

@@ -23,8 +23,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -47,6 +49,8 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class BluetoothSampleRateDialogPreferenceControllerTest { public class BluetoothSampleRateDialogPreferenceControllerTest {
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
@Mock @Mock
private BluetoothA2dp mBluetoothA2dp; private BluetoothA2dp mBluetoothA2dp;
@Mock @Mock
@@ -58,10 +62,12 @@ public class BluetoothSampleRateDialogPreferenceControllerTest {
private BluetoothCodecStatus mCodecStatus; private BluetoothCodecStatus mCodecStatus;
private BluetoothCodecConfig mCodecConfigAAC; private BluetoothCodecConfig mCodecConfigAAC;
private BluetoothCodecConfig mCodecConfigSBC; private BluetoothCodecConfig mCodecConfigSBC;
private BluetoothDevice mActiveDevice;
private Context mContext; private Context mContext;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
@Before @Before
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
@@ -69,6 +75,7 @@ public class BluetoothSampleRateDialogPreferenceControllerTest {
mLifecycleOwner = () -> mLifecycle; mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore()); mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = spy(new BluetoothSampleRateDialogPreferenceController(mContext, mLifecycle, mController = spy(new BluetoothSampleRateDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore)); mBluetoothA2dpConfigStore));
mPreference = new BluetoothSampleRateDialogPreference(mContext); mPreference = new BluetoothSampleRateDialogPreference(mContext);
@@ -86,6 +93,7 @@ public class BluetoothSampleRateDialogPreferenceControllerTest {
BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
BluetoothCodecConfig.CHANNEL_MODE_NONE, BluetoothCodecConfig.CHANNEL_MODE_NONE,
0, 0, 0, 0); 0, 0, 0, 0);
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
} }
@Test @Test
@@ -93,7 +101,8 @@ public class BluetoothSampleRateDialogPreferenceControllerTest {
mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC); mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC);
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0); mController.writeConfigurationValues(0);
@@ -125,7 +134,8 @@ public class BluetoothSampleRateDialogPreferenceControllerTest {
public void getSelectableIndex_verifyList() { public void getSelectableIndex_verifyList() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus); when(mBluetoothA2dp.getCodecStatus(
mActiveDevice)).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.onBluetoothServiceConnected(mBluetoothA2dp);
List<Integer> indexList = new ArrayList<>(); List<Integer> indexList = new ArrayList<>();
indexList.add(mController.getDefaultIndex()); indexList.add(mController.getDefaultIndex());