Use another callback to notify the updater that UI should be updated

Replace onConnectionStateChanged callback
with onProfileConnectionStateChanged. While
updater is notified, isFilterMatched(cachedDevice)
will decide whether to add/remove from UI based
on audio profiles and audio mode.

Bug: 76447449
Test: make RunSettingsRoboTests -j28
Change-Id: Icfba1ce2297e4638679158f9f99bae276940d885
This commit is contained in:
ryanywlin
2018-05-03 13:40:52 +08:00
committed by Ryan Lin
parent b87eb6aa06
commit 5365eaa6db
8 changed files with 78 additions and 61 deletions

View File

@@ -16,11 +16,11 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.media.AudioManager;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -57,18 +57,20 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
}
@Override
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
int bluetoothProfile) {
if (DBG) {
Log.d(TAG,"onConnectionStateChanged() device : " +
cachedDevice.getName() + ", state : " + state);
Log.d(TAG, "onProfileConnectionStateChanged() device: " +
cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: "
+ bluetoothProfile);
}
if (state == BluetoothAdapter.STATE_CONNECTED) {
if (state == BluetoothProfile.STATE_CONNECTED) {
if (isFilterMatched(cachedDevice)) {
addPreference(cachedDevice);
} else {
removePreference(cachedDevice);
}
} else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
} else if (state == BluetoothProfile.STATE_DISCONNECTED) {
removePreference(cachedDevice);
}
}