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

@@ -28,17 +28,15 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.widget.GearPreference;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* Update the bluetooth devices. It gets bluetooth event from {@link LocalBluetoothManager} using
@@ -48,7 +46,8 @@ import java.util.Objects;
* In {@link BluetoothDeviceUpdater}, it uses {@link BluetoothDeviceFilter.Filter} to detect
* whether the {@link CachedBluetoothDevice} is relevant.
*/
public abstract class BluetoothDeviceUpdater implements BluetoothCallback {
public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
LocalBluetoothProfileManager.ServiceListener {
private static final String TAG = "BluetoothDeviceUpdater";
private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY =
"persist.bluetooth.showdeviceswithoutnames";
@@ -116,6 +115,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback {
public void registerCallback() {
mLocalManager.setForegroundActivity(mFragment.getContext());
mLocalManager.getEventManager().registerCallback(this);
mLocalManager.getProfileManager().addServiceListener(this);
forceUpdate();
}
@@ -125,6 +125,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback {
public void unregisterCallback() {
mLocalManager.setForegroundActivity(null);
mLocalManager.getEventManager().unregisterCallback(this);
mLocalManager.getProfileManager().removeServiceListener(this);
}
/**
@@ -170,6 +171,17 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback {
public void onAudioModeChanged() {
}
@Override
public void onServiceConnected() {
// When bluetooth service connected update the UI
forceUpdate();
}
@Override
public void onServiceDisconnected() {
}
/**
* Set the context to generate the {@link Preference}, so it could get the correct theme.
*/
@@ -221,4 +233,16 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback {
mPreferenceMap.remove(device);
}
}
/**
* @return {@code true} if {@code cachedBluetoothDevice} is connected
* and the bond state is bonded.
*/
public boolean isDeviceConnected(CachedBluetoothDevice cachedDevice) {
if (cachedDevice == null) {
return false;
}
final BluetoothDevice device = cachedDevice.getDevice();
return device.getBondState() == BluetoothDevice.BOND_BONDED && device.isConnected();
}
}