Pebble: make sure that "waiting for reconnect" state is set when initial connect fails
This commit is contained in:
parent
4533c80c95
commit
33da6c2925
|
@ -161,6 +161,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
@Override
|
@Override
|
||||||
protected boolean connect(String btDeviceAddress) {
|
protected boolean connect(String btDeviceAddress) {
|
||||||
GBDevice.State originalState = gbDevice.getState();
|
GBDevice.State originalState = gbDevice.getState();
|
||||||
|
gbDevice.setState(GBDevice.State.CONNECTING);
|
||||||
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
try {
|
try {
|
||||||
// contains only one ":"? then it is addr:port
|
// contains only one ":"? then it is addr:port
|
||||||
int firstColon = btDeviceAddress.indexOf(":");
|
int firstColon = btDeviceAddress.indexOf(":");
|
||||||
|
@ -188,6 +190,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
gbDevice.setState(originalState);
|
gbDevice.setState(originalState);
|
||||||
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
|
|
||||||
mInStream = null;
|
mInStream = null;
|
||||||
mOutStream = null;
|
mOutStream = null;
|
||||||
mBtSocket = null;
|
mBtSocket = null;
|
||||||
|
@ -197,12 +201,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
mPebbleProtocol.setForceProtocol(prefs.getBoolean("pebble_force_protocol", false));
|
mPebbleProtocol.setForceProtocol(prefs.getBoolean("pebble_force_protocol", false));
|
||||||
|
|
||||||
mIsConnected = true;
|
mIsConnected = true;
|
||||||
if (originalState == GBDevice.State.WAITING_FOR_RECONNECT) {
|
write(mPebbleProtocol.encodeFirmwareVersionReq());
|
||||||
gbDevice.setState(GBDevice.State.INITIALIZED);
|
gbDevice.setState(GBDevice.State.CONNECTED);
|
||||||
} else {
|
|
||||||
gbDevice.setState(GBDevice.State.CONNECTED);
|
|
||||||
write(mPebbleProtocol.encodeFirmwareVersionReq());
|
|
||||||
}
|
|
||||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -210,15 +210,18 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
gbDevice.setState(GBDevice.State.CONNECTING);
|
|
||||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
|
||||||
|
|
||||||
mIsConnected = connect(gbDevice.getAddress());
|
mIsConnected = connect(gbDevice.getAddress());
|
||||||
enablePebbleKitReceiver(mIsConnected);
|
if (!mIsConnected) {
|
||||||
mQuit = !mIsConnected; // quit if not connected
|
if (GBApplication.getGBPrefs().getAutoReconnect()) {
|
||||||
|
gbDevice.setState(GBDevice.State.WAITING_FOR_RECONNECT);
|
||||||
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
|
enablePebbleKitReceiver(true);
|
||||||
|
mQuit = false;
|
||||||
while (!mQuit) {
|
while (!mQuit) {
|
||||||
try {
|
try {
|
||||||
if (mIsInstalling) {
|
if (mIsInstalling) {
|
||||||
|
@ -361,8 +364,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
mIsConnected = false;
|
mIsConnected = false;
|
||||||
int reconnectAttempts = prefs.getInt("pebble_reconnect_attempts", 10);
|
int reconnectAttempts = prefs.getInt("pebble_reconnect_attempts", 10);
|
||||||
if (!mQuit && GBApplication.getGBPrefs().getAutoReconnect() && reconnectAttempts > 0) {
|
if (!mQuit && GBApplication.getGBPrefs().getAutoReconnect() && reconnectAttempts > 0) {
|
||||||
gbDevice.setState(GBDevice.State.CONNECTING);
|
|
||||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
|
||||||
int delaySeconds = 1;
|
int delaySeconds = 1;
|
||||||
while (reconnectAttempts-- > 0 && !mQuit && !mIsConnected) {
|
while (reconnectAttempts-- > 0 && !mQuit && !mIsConnected) {
|
||||||
LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")");
|
LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")");
|
||||||
|
|
Loading…
Reference in New Issue