1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-19 21:31:14 +02:00

Handled the potential case of the same scan finishing twice and canceling a running scan being displayed

This commit is contained in:
TaaviE 2020-08-02 23:43:00 +03:00
parent 83f3b8565e
commit 749cf91f63

View File

@ -132,15 +132,17 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
switch (Objects.requireNonNull(intent.getAction())) { switch (Objects.requireNonNull(intent.getAction())) {
case BluetoothAdapter.ACTION_DISCOVERY_STARTED: case BluetoothAdapter.ACTION_DISCOVERY_STARTED: {
LOG.debug("ACTION_DISCOVERY_STARTED");
if (isScanning != Scanning.SCANNING_BLE) { if (isScanning != Scanning.SCANNING_BLE) {
if (isScanning != Scanning.SCANNING_BT_NEXT_BLE) { if (isScanning != Scanning.SCANNING_BT_NEXT_BLE) {
setIsScanning(Scanning.SCANNING_BT); setIsScanning(Scanning.SCANNING_BT);
} }
startButton.setText(getString(R.string.discovery_stop_scanning));
} }
break; break;
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED: }
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED: {
LOG.debug("ACTION_DISCOVERY_FINISHED");
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -149,23 +151,26 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
checkAndRequestLocationPermission(); checkAndRequestLocationPermission();
stopDiscovery(); stopDiscovery();
startDiscovery(Scanning.SCANNING_BLE); startDiscovery(Scanning.SCANNING_BLE);
} else {
discoveryFinished();
} }
} }
}); });
break; break;
case BluetoothAdapter.ACTION_STATE_CHANGED: }
case BluetoothAdapter.ACTION_STATE_CHANGED: {
LOG.debug("ACTION_STATE_CHANGED ");
int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF); int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
bluetoothStateChanged(newState); bluetoothStateChanged(newState);
break; break;
}
case BluetoothDevice.ACTION_FOUND: { case BluetoothDevice.ACTION_FOUND: {
LOG.debug("ACTION_FOUND");
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, GBDevice.RSSI_UNKNOWN); short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, GBDevice.RSSI_UNKNOWN);
handleDeviceFound(device, rssi); handleDeviceFound(device, rssi);
break; break;
} }
case BluetoothDevice.ACTION_UUID: { case BluetoothDevice.ACTION_UUID: {
LOG.debug("ACTION_UUID");
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, GBDevice.RSSI_UNKNOWN); short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, GBDevice.RSSI_UNKNOWN);
Parcelable[] uuids = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID); Parcelable[] uuids = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
@ -174,6 +179,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
break; break;
} }
case BluetoothDevice.ACTION_BOND_STATE_CHANGED: { case BluetoothDevice.ACTION_BOND_STATE_CHANGED: {
LOG.debug("ACTION_BOND_STATE_CHANGED");
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device != null && bondingDevice != null && device.getAddress().equals(bondingDevice.getMacAddress())) { if (device != null && bondingDevice != null && device.getAddress().equals(bondingDevice.getMacAddress())) {
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE);