mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
Revert to previous state if connection fails, this fixes multiple bugs when pebble is reconnecting
This commit is contained in:
parent
bb44cb1e19
commit
40438ebe0e
@ -104,7 +104,7 @@ public class BluetoothCommunicationService extends Service {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
sharedPrefs.edit().putString("last_device_address", btDeviceAddress).commit();
|
||||
|
||||
if (btDeviceAddress != null && !isConnected()) {
|
||||
if (btDeviceAddress != null && !isConnected() && !isConnecting()) {
|
||||
// currently only one thread allowed
|
||||
if (mGBDeviceIoThread != null) {
|
||||
mGBDeviceIoThread.quit();
|
||||
@ -201,6 +201,10 @@ public class BluetoothCommunicationService extends Service {
|
||||
return mGBDevice != null && mGBDevice.getState() == State.CONNECTED;
|
||||
}
|
||||
|
||||
private boolean isConnecting() {
|
||||
return mGBDevice != null && mGBDevice.getState() == State.CONNECTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@ -80,6 +80,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
protected boolean connect(String btDeviceAddress) {
|
||||
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
|
||||
ParcelUuid uuids[] = btDevice.getUuids();
|
||||
GBDevice.State originalState = gbDevice.getState();
|
||||
try {
|
||||
mBtSocket = btDevice.createRfcommSocketToServiceRecord(uuids[0].getUuid());
|
||||
mBtSocket.connect();
|
||||
@ -87,7 +88,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
mmOutStream = mBtSocket.getOutputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
gbDevice.setState(GBDevice.State.NOT_CONNECTED);
|
||||
gbDevice.setState(originalState);
|
||||
mmInStream = null;
|
||||
mmOutStream = null;
|
||||
mBtSocket = null;
|
||||
|
Loading…
Reference in New Issue
Block a user