Merge "Fix BTHS is still in pairing list after BTHS is connected"

This commit is contained in:
TreeHugger Robot
2019-10-29 08:39:49 +00:00
committed by Android (Google) Code Review
3 changed files with 99 additions and 12 deletions

View File

@@ -29,9 +29,9 @@ import android.widget.Toast;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settingslib.search.Indexable;
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.search.Indexable;
import com.android.settingslib.widget.FooterPreference;
/**
@@ -191,12 +191,19 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
}
@Override
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
if (mSelectedDevice != null) {
BluetoothDevice device = cachedDevice.getDevice();
if (device != null && mSelectedDevice.equals(device)
&& state == BluetoothAdapter.STATE_CONNECTED) {
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
int bluetoothProfile) {
// This callback is used to handle the case that bonded device is connected in pairing list.
// 1. If user selected multiple bonded devices in pairing list, after connected
// finish this page.
// 2. If the bonded devices auto connected in paring list, after connected it will be
// removed from paring list.
if (cachedDevice != null && cachedDevice.isConnected()) {
final BluetoothDevice device = cachedDevice.getDevice();
if (device != null && mSelectedList.contains(device)) {
finish();
} else if (mDevicePreferenceMap.containsKey(cachedDevice)) {
onDeviceDeleted(cachedDevice);
}
}
}

View File

@@ -35,9 +35,10 @@ import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.WeakHashMap;
import java.util.List;
/**
* Parent class for settings fragments that contain a list of Bluetooth
@@ -72,6 +73,7 @@ public abstract class DeviceListPreferenceFragment extends
final HashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap =
new HashMap<>();
final List<BluetoothDevice> mSelectedList = new ArrayList<>();
boolean mShowDevicesWithoutNames;
@@ -154,6 +156,7 @@ public abstract class DeviceListPreferenceFragment extends
BluetoothDevicePreference btPreference = (BluetoothDevicePreference) preference;
CachedBluetoothDevice device = btPreference.getCachedDevice();
mSelectedDevice = device.getDevice();
mSelectedList.add(mSelectedDevice);
onDevicePreferenceClick(btPreference);
return true;
}