Check connected devices in addition to paired ones when matching
Some bluetooth devices do not require to be paired, so we should also check the list of currently-connected devices when matching. Test: manual Change-Id: I2d87b24982b4ac0d773b40990c739c7bcfe93838
This commit is contained in:
@@ -32,6 +32,7 @@ import android.app.Service;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.bluetooth.le.BluetoothLeScanner;
|
||||
import android.bluetooth.le.ScanCallback;
|
||||
import android.bluetooth.le.ScanFilter;
|
||||
@@ -84,6 +85,7 @@ public class DeviceDiscoveryService extends Service {
|
||||
|
||||
static DeviceDiscoveryService sInstance;
|
||||
|
||||
private BluetoothManager mBluetoothManager;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private WifiManager mWifiManager;
|
||||
@Nullable private BluetoothLeScanner mBLEScanner;
|
||||
@@ -141,7 +143,8 @@ public class DeviceDiscoveryService extends Service {
|
||||
|
||||
if (DEBUG) Log.i(LOG_TAG, "onCreate()");
|
||||
|
||||
mBluetoothAdapter = getSystemService(BluetoothManager.class).getAdapter();
|
||||
mBluetoothManager = getSystemService(BluetoothManager.class);
|
||||
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
||||
mBLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
|
||||
mWifiManager = getSystemService(WifiManager.class);
|
||||
|
||||
@@ -186,6 +189,14 @@ public class DeviceDiscoveryService extends Service {
|
||||
for (BluetoothDevice dev : emptyIfNull(mBluetoothAdapter.getBondedDevices())) {
|
||||
onDeviceFound(DeviceFilterPair.findMatch(dev, mBluetoothFilters));
|
||||
}
|
||||
for (BluetoothDevice dev : emptyIfNull(
|
||||
mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT))) {
|
||||
onDeviceFound(DeviceFilterPair.findMatch(dev, mBluetoothFilters));
|
||||
}
|
||||
for (BluetoothDevice dev : emptyIfNull(
|
||||
mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT_SERVER))) {
|
||||
onDeviceFound(DeviceFilterPair.findMatch(dev, mBluetoothFilters));
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldScan(mBluetoothFilters)) {
|
||||
|
||||
Reference in New Issue
Block a user