Implement audio switch UI

* Implement available media devices group
* Add AvailableMediaDeviceGroupController to realize UI, the user can see the all device that can be activated in this group.
* ConnectedDeviceGroupController change to show the device that cannot be activated but is connected.
* Refactoring the below class, implement the controller in connected_devices.xml.
  ConnectedDeviceGroupController.java
  SavedDeviceGroupController.java
  ConnectedDeviceDashboardFragment.java
  connected_devices.xml
* Add AvailableMediaBluetoothDeviceUpdaterTest to verify the add/remove preference behavior when connectedStateChanged or profileAudioStateChanged
* Add test that used to verify device is connected or not in BluetoothDeviceUpdaterTest.
* Add test that used to verify the add/remove preference behavior when connectedStateChanged or profileAudioStateChanged in ConnectedBluetoothDeviceUpdaterTest.
* Add AvailableMediaDeviceGroupControllerTest to verify bluetooth feature is supported or not and test register callback.
* Add test that used to verify bluetooth feature is supported or not and test register callback in ConnectedDeviceGroupControllerTest.
* Add test that used to verify bluetooth feature is supported or not and test register callback in SavedDeviceGroupControllerTest

Bug: 74134939
Test: make -j40 RunSettingsRoboTests
Change-Id: I54d03c2ddadc6a4be7519dd74cdbcb5055d44083
This commit is contained in:
hughchen
2018-03-23 16:14:13 +08:00
committed by Hugh Chen
parent 28041fb8cd
commit bd3e5de207
18 changed files with 949 additions and 85 deletions

View File

@@ -23,6 +23,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.support.v7.preference.Preference;
@@ -32,7 +33,11 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +59,14 @@ public class BluetoothDeviceUpdaterTest {
private BluetoothDevice mBluetoothDevice;
@Mock
private SettingsActivity mSettingsActivity;
@Mock
private LocalBluetoothManager mLocalManager;
@Mock
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
@Mock
private HeadsetProfile mHeadsetProfile;
@Mock
private A2dpProfile mA2dpProfile;
private Context mContext;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -66,10 +79,14 @@ public class BluetoothDeviceUpdaterTest {
mContext = RuntimeEnvironment.application;
doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
mBluetoothDeviceUpdater =
new BluetoothDeviceUpdater(mDashboardFragment, mDevicePreferenceCallback, null) {
new BluetoothDeviceUpdater(mDashboardFragment, mDevicePreferenceCallback,
mLocalManager) {
@Override
public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
return true;
@@ -124,4 +141,20 @@ public class BluetoothDeviceUpdaterTest {
assertThat(intentCaptor.getValue().getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
.isEqualTo(BluetoothDeviceDetailsFragment.class.getName());
}
@Test
public void isDeviceConnected_deviceConnected() {
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
doReturn(true).when(mBluetoothDevice).isConnected();
assertThat(mBluetoothDeviceUpdater.isDeviceConnected(mCachedBluetoothDevice)).isTrue();
}
@Test
public void isDeviceConnected_deviceNotConnected() {
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
doReturn(false).when(mBluetoothDevice).isConnected();
assertThat(mBluetoothDeviceUpdater.isDeviceConnected(mCachedBluetoothDevice)).isFalse();
}
}