Merge "Add Fast Pair saved devices settings preference"
diff --git a/res/layout/add_supervised_user.xml b/res/layout/add_supervised_user.xml
index b95e0f7..33032bd 100644
--- a/res/layout/add_supervised_user.xml
+++ b/res/layout/add_supervised_user.xml
@@ -15,12 +15,18 @@
~ limitations under the License.
-->
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="16dp"
+ android:orientation="vertical">
<Button
android:id="@+id/createSupervisedUser"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@*android:string/supervised_user_creation_label" />
-</FrameLayout>
\ No newline at end of file
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/placeholder_activity" />
+</LinearLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 019a492..a50c51a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -13872,4 +13872,7 @@
<string name="reboot_dialog_reboot_now">Reboot now</string>
<!-- Text on the dialog button to reboot the device later [CHAR LIMIT=50] -->
<string name="reboot_dialog_reboot_later">Reboot later</string>
+
+ <!-- Text to explain an activity is a temporary placeholder [CHAR LIMIT=none] -->
+ <string name="placeholder_activity" translatable="false">*This is a temporary placeholder fallback activity.</string>
</resources>
diff --git a/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java b/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java
index 88dda29..7514577 100644
--- a/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java
+++ b/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java
@@ -17,9 +17,12 @@
package com.android.settings.development;
import android.bluetooth.BluetoothA2dp;
+import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothManager;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.annotation.VisibleForTesting;
@@ -34,6 +37,8 @@
import com.android.settingslib.core.lifecycle.events.OnDestroy;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+import java.util.List;
+
public abstract class AbstractBluetoothA2dpPreferenceController extends
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin, BluetoothServiceConnectionListener, LifecycleObserver,
@@ -48,11 +53,15 @@
private final String[] mListValues;
private final String[] mListSummaries;
+ @VisibleForTesting
+ BluetoothAdapter mBluetoothAdapter;
+
public AbstractBluetoothA2dpPreferenceController(Context context, Lifecycle lifecycle,
BluetoothA2dpConfigStore store) {
super(context);
mBluetoothA2dpConfigStore = store;
+ mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter();
mListValues = getListValues();
mListSummaries = getListSummaries();
@@ -82,13 +91,11 @@
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
synchronized (mBluetoothA2dpConfigStore) {
- if (mBluetoothA2dp != null) {
- BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
- if (activeDevice == null) {
- return false;
- }
- setCodecConfigPreference(activeDevice, codecConfig);
+ BluetoothDevice activeDevice = getA2dpActiveDevice();
+ if (activeDevice == null) {
+ return false;
}
+ setCodecConfigPreference(activeDevice, codecConfig);
}
// Because the setting is not persisted into permanent storage, we cannot call update state
// here to update the preference.
@@ -106,7 +113,7 @@
@Override
public void updateState(Preference preference) {
- BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
+ BluetoothDevice activeDevice = getA2dpActiveDevice();
if (activeDevice == null || getCodecConfig(activeDevice) == null || mPreference == null) {
return;
}
@@ -184,7 +191,7 @@
void setCodecConfigPreference(BluetoothDevice device,
BluetoothCodecConfig config) {
BluetoothDevice bluetoothDevice =
- (device != null) ? device : mBluetoothA2dp.getActiveDevice();
+ (device != null) ? device : getA2dpActiveDevice();
if (bluetoothDevice == null) {
return;
}
@@ -195,7 +202,7 @@
BluetoothCodecConfig getCodecConfig(BluetoothDevice device) {
if (mBluetoothA2dp != null) {
BluetoothDevice bluetoothDevice =
- (device != null) ? device : mBluetoothA2dp.getActiveDevice();
+ (device != null) ? device : getA2dpActiveDevice();
if (bluetoothDevice == null) {
return null;
}
@@ -206,4 +213,13 @@
}
return null;
}
+
+ private BluetoothDevice getA2dpActiveDevice() {
+ if (mBluetoothAdapter == null) {
+ return null;
+ }
+ List<BluetoothDevice> activeDevices =
+ mBluetoothAdapter.getActiveDevices(BluetoothProfile.A2DP);
+ return (activeDevices.size() > 0) ? activeDevices.get(0) : null;
+ }
}
diff --git a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
index 1af6e96..62bcffb 100644
--- a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
@@ -84,7 +84,7 @@
}
writeConfigurationValues(index);
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
- BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
+ BluetoothDevice activeDevice = getA2dpActiveDevice();
if (activeDevice != null) {
bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig);
}
@@ -153,7 +153,7 @@
if (bluetoothA2dp == null) {
return null;
}
- BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
+ BluetoothDevice activeDevice = getA2dpActiveDevice();
if (activeDevice == null) {
Log.d(TAG, "Unable to get current codec config. No active device.");
return null;
@@ -178,7 +178,7 @@
return null;
}
BluetoothDevice bluetoothDevice =
- (device != null) ? device : bluetoothA2dp.getActiveDevice();
+ (device != null) ? device : getA2dpActiveDevice();
if (bluetoothDevice == null) {
return null;
}
@@ -195,7 +195,7 @@
* @return {@link BluetoothCodecConfig}.
*/
protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) {
- BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
+ BluetoothDevice activeDevice = getA2dpActiveDevice();
if (activeDevice == null) {
Log.d(TAG, "Unable to get selectable config. No active device.");
return null;
diff --git a/src/com/android/settings/development/bluetooth/AbstractBluetoothPreferenceController.java b/src/com/android/settings/development/bluetooth/AbstractBluetoothPreferenceController.java
index 6735115..d3fab67 100644
--- a/src/com/android/settings/development/bluetooth/AbstractBluetoothPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/AbstractBluetoothPreferenceController.java
@@ -17,8 +17,14 @@
package com.android.settings.development.bluetooth;
import android.bluetooth.BluetoothA2dp;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothManager;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
+import androidx.annotation.VisibleForTesting;
+
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.development.BluetoothA2dpConfigStore;
import com.android.settings.development.BluetoothServiceConnectionListener;
@@ -27,6 +33,8 @@
import com.android.settingslib.core.lifecycle.events.OnDestroy;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+import java.util.List;
+
/**
* Abstract class for Bluetooth A2DP config controller in developer option.
*/
@@ -36,12 +44,16 @@
protected volatile BluetoothA2dp mBluetoothA2dp;
+ @VisibleForTesting
+ BluetoothAdapter mBluetoothAdapter;
+
public AbstractBluetoothPreferenceController(Context context, Lifecycle lifecycle,
BluetoothA2dpConfigStore store) {
super(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
+ mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter();
}
@Override
@@ -82,4 +94,13 @@
*/
void onBluetoothHDAudioEnabled(boolean enabled);
}
+
+ protected BluetoothDevice getA2dpActiveDevice() {
+ if (mBluetoothAdapter == null) {
+ return null;
+ }
+ List<BluetoothDevice> activeDevices =
+ mBluetoothAdapter.getActiveDevices(BluetoothProfile.A2DP);
+ return (activeDevices.size() > 0) ? activeDevices.get(0) : null;
+ }
}
diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
index 5f916f3..a65a1ba 100644
--- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
@@ -69,7 +69,7 @@
if (bluetoothA2dp == null) {
return index;
}
- final BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
+ final BluetoothDevice activeDevice = getA2dpActiveDevice();
if (activeDevice == null) {
Log.d(TAG, "Unable to get selectable index. No Active Bluetooth device");
return index;
@@ -93,7 +93,7 @@
int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
switch (index) {
case 0:
- final BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
+ final BluetoothDevice activeDevice = getA2dpActiveDevice();
codecTypeValue = getHighestCodec(mBluetoothA2dp, activeDevice,
getSelectableConfigs(activeDevice));
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
diff --git a/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java
index d4ca4e5..8092194 100644
--- a/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java
@@ -52,7 +52,7 @@
mPreference.setEnabled(false);
return;
}
- final BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
+ final BluetoothDevice activeDevice = getA2dpActiveDevice();
if (activeDevice == null) {
Log.e(TAG, "Active device is null. To disable HD audio button");
mPreference.setEnabled(false);
@@ -84,7 +84,7 @@
final int prefValue = enabled
? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED
: BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
- BluetoothDevice activeDevice = bluetoothA2dp.getActiveDevice();
+ BluetoothDevice activeDevice = getA2dpActiveDevice();
if (activeDevice == null) {
mPreference.setEnabled(false);
return true;
diff --git a/src/com/android/settings/users/AddSupervisedUserActivity.java b/src/com/android/settings/users/AddSupervisedUserActivity.java
index f3c5867..8a3221d 100644
--- a/src/com/android/settings/users/AddSupervisedUserActivity.java
+++ b/src/com/android/settings/users/AddSupervisedUserActivity.java
@@ -65,7 +65,9 @@
}
private void createUser() {
- final NewUserRequest request = new NewUserRequest.Builder().build();
+ final NewUserRequest request = new NewUserRequest.Builder()
+ .setName(getString(R.string.user_new_user_name))
+ .build();
final AlertDialog pleaseWaitDialog = new AlertDialog.Builder(this)
.setMessage(getString(R.string.creating_new_user_dialog_message))
diff --git a/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java
index 4276407..783c2ed 100644
--- a/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java
@@ -73,6 +73,7 @@
mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new AbstractBluetoothA2dpPreferenceControllerImpl(mContext, mLifecycle,
mBluetoothA2dpConfigStore));
+ mController.mBluetoothAdapter = null;
doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig(null);
doNothing().when(mController).setCodecConfigPreference(any(), any());
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mBluetoothCodecConfig);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
index c1648bf..d16a507 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
@@ -20,6 +20,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -30,6 +31,7 @@
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
@@ -59,6 +61,8 @@
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
+ private BluetoothAdapter mBluetoothAdapter;
+ @Mock
private PreferenceScreen mScreen;
private AbstractBluetoothDialogPreferenceController mController;
@@ -84,6 +88,7 @@
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = spy(new AbstractBluetoothDialogPreferenceControllerImpl(mContext, mLifecycle,
mBluetoothA2dpConfigStore));
+ mController.mBluetoothAdapter = mBluetoothAdapter;
mPreference = spy(new BaseBluetoothDialogPreferenceImpl(mContext));
mCodecConfigAAC = new BluetoothCodecConfig.Builder()
@@ -99,7 +104,8 @@
mController.displayPreference(mScreen);
mCurrentConfig = mController.getCurrentConfigIndex();
when(mPreference.generateSummary(mCurrentConfig)).thenReturn(SUMMARY);
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
index a042ebe..5a24c8e 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,6 +28,7 @@
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
@@ -55,6 +57,8 @@
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
+ private BluetoothAdapter mBluetoothAdapter;
+ @Mock
private PreferenceScreen mScreen;
private BluetoothBitPerSampleDialogPreferenceController mController;
@@ -81,6 +85,7 @@
mPreference = new BluetoothBitPerSampleDialogPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
+ mController.mBluetoothAdapter = mBluetoothAdapter;
mCodecConfigAAC = new BluetoothCodecConfig.Builder()
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
.setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_16
@@ -90,7 +95,8 @@
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
.setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_24)
.build();
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
index 75d8fc4..3d94e2a 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,6 +28,7 @@
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
@@ -55,6 +57,8 @@
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
+ private BluetoothAdapter mBluetoothAdapter;
+ @Mock
private PreferenceScreen mScreen;
private BluetoothChannelModeDialogPreferenceController mController;
@@ -78,6 +82,7 @@
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = new BluetoothChannelModeDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore);
+ mController.mBluetoothAdapter = mBluetoothAdapter;
mPreference = new BluetoothChannelModeDialogPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
@@ -90,7 +95,8 @@
.setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_MONO
| BluetoothCodecConfig.CHANNEL_MODE_STEREO)
.build();
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
index 3a34aa0..21111cd 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
@@ -29,6 +29,7 @@
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
@@ -56,6 +57,8 @@
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
+ private BluetoothAdapter mBluetoothAdapter;
+ @Mock
private PreferenceScreen mScreen;
@Mock
private AbstractBluetoothPreferenceController.Callback mCallback;
@@ -85,6 +88,7 @@
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = new BluetoothCodecDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore, mCallback);
+ mController.mBluetoothAdapter = mBluetoothAdapter;
mPreference = new BluetoothCodecDialogPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
@@ -115,7 +119,8 @@
mCodecConfigLDAC = new BluetoothCodecConfig.Builder()
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC)
.build();
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java
index 60476de..72ceddf 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java
@@ -18,12 +18,15 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothA2dp;
+import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
@@ -43,6 +46,9 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowBluetoothDevice;
+import java.util.Arrays;
+import java.util.Collections;
+
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothDevice.class})
public class BluetoothHDAudioPreferenceControllerTest {
@@ -52,6 +58,8 @@
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
+ private BluetoothAdapter mBluetoothAdapter;
+ @Mock
private PreferenceScreen mScreen;
@Mock
private AbstractBluetoothPreferenceController.Callback mCallback;
@@ -73,6 +81,7 @@
mBluetoothA2dpConfigStore = spy(new BluetoothA2dpConfigStore());
mController = new BluetoothHDAudioPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore, mCallback);
+ mController.mBluetoothAdapter = mBluetoothAdapter;
mPreference = new SwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
@@ -81,7 +90,8 @@
@Test
public void updateState_noActiveDevice_setDisable() {
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(null);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Collections.emptyList());
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference);
@@ -90,7 +100,8 @@
@Test
public void updateState_codecSupported_setEnable() {
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
@@ -101,7 +112,8 @@
@Test
public void updateState_codecNotSupported_setDisable() {
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
@@ -112,7 +124,8 @@
@Test
public void updateState_codecSupportedAndEnabled_checked() {
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
@@ -125,7 +138,8 @@
@Test
public void updateState_codecSupportedAndDisabled_notChecked() {
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
@@ -138,7 +152,8 @@
@Test
public void onPreferenceChange_disable_verifyFlow() {
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
mController.onBluetoothServiceConnected(mBluetoothA2dp);
final boolean enabled = false;
mController.onPreferenceChange(mPreference, enabled);
@@ -151,7 +166,8 @@
@Test
public void onPreferenceChange_enable_verifyFlow() {
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
mController.onBluetoothServiceConnected(mBluetoothA2dp);
final boolean enabled = true;
mController.onPreferenceChange(mPreference, enabled);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
index e50b716..1bd83f7 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,6 +28,7 @@
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
@@ -53,6 +55,8 @@
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
+ private BluetoothAdapter mBluetoothAdapter;
+ @Mock
private PreferenceScreen mScreen;
private BluetoothQualityDialogPreferenceController mController;
@@ -76,6 +80,7 @@
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = new BluetoothQualityDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore);
+ mController.mBluetoothAdapter = mBluetoothAdapter;
mPreference = new BluetoothQualityDialogPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
@@ -89,7 +94,8 @@
.setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000)
.setCodecSpecific1(1001)
.build();
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
index fca154d..f7d010c 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,6 +28,7 @@
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
@@ -55,6 +57,8 @@
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
+ private BluetoothAdapter mBluetoothAdapter;
+ @Mock
private PreferenceScreen mScreen;
private BluetoothSampleRateDialogPreferenceController mController;
@@ -79,6 +83,7 @@
mActiveDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(DEVICE_ADDRESS);
mController = spy(new BluetoothSampleRateDialogPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore));
+ mController.mBluetoothAdapter = mBluetoothAdapter;
mPreference = new BluetoothSampleRateDialogPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
@@ -91,7 +96,8 @@
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
.setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000)
.build();
- when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
+ when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
+ .thenReturn(Arrays.asList(mActiveDevice));
}
@Test