mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-27 09:41:16 +02:00
Pebble: add experimental reconnect support for standby-mode on firmware 3.x
- You should also set reconnect attempts to 0 in preferences when using this. - It also works when you set flight mode on the pebble, then wait for about 5 minutes and turn BT back on - Pebble FW 2.x support ist completely untested.
This commit is contained in:
parent
9f60bf3561
commit
11e02fbf5f
@ -194,6 +194,8 @@ public class GBDevice implements Parcelable {
|
|||||||
switch (mState) {
|
switch (mState) {
|
||||||
case NOT_CONNECTED:
|
case NOT_CONNECTED:
|
||||||
return GBApplication.getContext().getString(R.string.not_connected);
|
return GBApplication.getContext().getString(R.string.not_connected);
|
||||||
|
case WAITING_FOR_RECONNECT:
|
||||||
|
return GBApplication.getContext().getString(R.string.waiting_for_reconnect);
|
||||||
case CONNECTING:
|
case CONNECTING:
|
||||||
return GBApplication.getContext().getString(R.string.connecting);
|
return GBApplication.getContext().getString(R.string.connecting);
|
||||||
case CONNECTED:
|
case CONNECTED:
|
||||||
@ -310,6 +312,7 @@ public class GBDevice implements Parcelable {
|
|||||||
public enum State {
|
public enum State {
|
||||||
// Note: the order is important!
|
// Note: the order is important!
|
||||||
NOT_CONNECTED,
|
NOT_CONNECTED,
|
||||||
|
WAITING_FOR_RECONNECT,
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
CONNECTED,
|
CONNECTED,
|
||||||
INITIALIZING,
|
INITIALIZING,
|
||||||
@ -319,6 +322,6 @@ public class GBDevice implements Parcelable {
|
|||||||
* device name, firmware version, hardware revision (as applicable) is available
|
* device name, firmware version, hardware revision (as applicable) is available
|
||||||
* in the GBDevice.
|
* in the GBDevice.
|
||||||
*/
|
*/
|
||||||
INITIALIZED
|
INITIALIZED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
|
|||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothServerSocket;
|
||||||
import android.bluetooth.BluetoothSocket;
|
import android.bluetooth.BluetoothSocket;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -46,6 +47,9 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
|||||||
public class PebbleIoThread extends GBDeviceIoThread {
|
public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(PebbleIoThread.class);
|
private static final Logger LOG = LoggerFactory.getLogger(PebbleIoThread.class);
|
||||||
|
|
||||||
|
private static final UUID PEBBLE_UUID_RECONNECT = UUID.fromString("00000000-deca-fade-deca-deafdecacafe");
|
||||||
|
private static final UUID PEBBLE_UUID_RECONNECT3X = UUID.fromString("a924496e-cc7c-4dff-8a9f-9a76cc2e9d50");
|
||||||
|
|
||||||
public static final String PEBBLEKIT_ACTION_PEBBLE_CONNECTED = "com.getpebble.action.PEBBLE_CONNECTED";
|
public static final String PEBBLEKIT_ACTION_PEBBLE_CONNECTED = "com.getpebble.action.PEBBLE_CONNECTED";
|
||||||
public static final String PEBBLEKIT_ACTION_PEBBLE_DISCONNECTED = "com.getpebble.action.PEBBLE_DISCONNECTED";
|
public static final String PEBBLEKIT_ACTION_PEBBLE_DISCONNECTED = "com.getpebble.action.PEBBLE_DISCONNECTED";
|
||||||
public static final String PEBBLEKIT_ACTION_APP_ACK = "com.getpebble.action.app.ACK";
|
public static final String PEBBLEKIT_ACTION_APP_ACK = "com.getpebble.action.app.ACK";
|
||||||
@ -66,6 +70,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
private boolean mIsTCP = false;
|
private boolean mIsTCP = false;
|
||||||
private BluetoothAdapter mBtAdapter = null;
|
private BluetoothAdapter mBtAdapter = null;
|
||||||
private BluetoothSocket mBtSocket = null;
|
private BluetoothSocket mBtSocket = null;
|
||||||
|
private BluetoothServerSocket mBtServerSocket = null;
|
||||||
private Socket mTCPSocket = null; // for emulator
|
private Socket mTCPSocket = null; // for emulator
|
||||||
private InputStream mInStream = null;
|
private InputStream mInStream = null;
|
||||||
private OutputStream mOutStream = null;
|
private OutputStream mOutStream = null;
|
||||||
@ -157,7 +162,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
mEnablePebblekit = sharedPrefs.getBoolean("pebble_enable_pebblekit", false);
|
mEnablePebblekit = sharedPrefs.getBoolean("pebble_enable_pebblekit", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean connect(String btDeviceAddress) {
|
protected boolean connect(String btDeviceAddress) {
|
||||||
GBDevice.State originalState = gbDevice.getState();
|
GBDevice.State originalState = gbDevice.getState();
|
||||||
@ -174,6 +178,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
mIsTCP = false;
|
mIsTCP = false;
|
||||||
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
|
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
|
||||||
ParcelUuid uuids[] = btDevice.getUuids();
|
ParcelUuid uuids[] = btDevice.getUuids();
|
||||||
|
for (ParcelUuid uuid : uuids) {
|
||||||
|
LOG.info("found service UUID " + uuid);
|
||||||
|
}
|
||||||
mBtSocket = btDevice.createRfcommSocketToServiceRecord(uuids[0].getUuid());
|
mBtSocket = btDevice.createRfcommSocketToServiceRecord(uuids[0].getUuid());
|
||||||
mBtSocket.connect();
|
mBtSocket.connect();
|
||||||
mInStream = mBtSocket.getInputStream();
|
mInStream = mBtSocket.getInputStream();
|
||||||
@ -347,15 +354,30 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
||||||
LOG.info(e.getMessage());
|
LOG.info(e.getMessage());
|
||||||
gbDevice.setState(GBDevice.State.CONNECTING);
|
|
||||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
|
||||||
mIsConnected = false;
|
mIsConnected = false;
|
||||||
int reconnectAttempts = Integer.valueOf(sharedPrefs.getString("pebble_reconnect_attempts", "10"));
|
int reconnectAttempts = Integer.valueOf(sharedPrefs.getString("pebble_reconnect_attempts", "10"));
|
||||||
while (reconnectAttempts-- > 0 && !mQuit) {
|
if (reconnectAttempts > 0) {
|
||||||
LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")");
|
gbDevice.setState(GBDevice.State.CONNECTED);
|
||||||
mIsConnected = connect(gbDevice.getAddress());
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
if (mIsConnected)
|
while (reconnectAttempts-- > 0 && !mQuit) {
|
||||||
break;
|
LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")");
|
||||||
|
mIsConnected = connect(gbDevice.getAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!mIsConnected) {
|
||||||
|
try {
|
||||||
|
gbDevice.setState(GBDevice.State.WAITING_FOR_RECONNECT);
|
||||||
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
|
UUID reconnectUUID = mPebbleProtocol.isFw3x ? PEBBLE_UUID_RECONNECT3X : PEBBLE_UUID_RECONNECT;
|
||||||
|
mBtServerSocket = mBtAdapter.listenUsingRfcommWithServiceRecord("PebbleReconnectListener", reconnectUUID);
|
||||||
|
mBtSocket = mBtServerSocket.accept();
|
||||||
|
LOG.info("incoming connection on reconnect uuid (" + reconnectUUID + "), will connect actively");
|
||||||
|
mBtSocket.close();
|
||||||
|
mIsConnected = connect(gbDevice.getAddress());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
LOG.info("error while reconnecting");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!mIsConnected) {
|
if (!mIsConnected) {
|
||||||
mBtSocket = null;
|
mBtSocket = null;
|
||||||
@ -652,6 +674,13 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mBtServerSocket != null) {
|
||||||
|
try {
|
||||||
|
mBtServerSocket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (mTCPSocket != null) {
|
if (mTCPSocket != null) {
|
||||||
try {
|
try {
|
||||||
mTCPSocket.close();
|
mTCPSocket.close();
|
||||||
|
@ -1110,7 +1110,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
buf.put((byte) 8); // minor
|
buf.put((byte) 8); // minor
|
||||||
buf.put((byte) 1); // patch
|
buf.put((byte) 1); // patch
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
buf.putLong(0x0000000000000003); //flags
|
buf.putLong(0x00000000000000af); //flags
|
||||||
|
|
||||||
return buf.array();
|
return buf.array();
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
<string name="when_screen_off">cuando la pantalla está apagada</string>
|
<string name="when_screen_off">cuando la pantalla está apagada</string>
|
||||||
<string name="never">nunca</string>
|
<string name="never">nunca</string>
|
||||||
<string name="pref_blacklist">Excluir aplicaciones</string>
|
<string name="pref_blacklist">Excluir aplicaciones</string>
|
||||||
<string name="pref_title_canned_replies">Respuestas rápidas</string>
|
<string name="pref_title_canned_replies">Respuestas enlatadas</string>
|
||||||
<string name="pref_header_development">Opciones de desarrollador</string>
|
<string name="pref_header_development">Opciones de desarrollador</string>
|
||||||
<string name="pref_title_development_miaddr">Dirección de MiBand</string>
|
<string name="pref_title_development_miaddr">Dirección de MiBand</string>
|
||||||
<string name="pref_title_pebble_settings">Ajustes de Pebble</string>
|
<string name="pref_title_pebble_settings">Ajustes de Pebble</string>
|
||||||
@ -198,4 +198,5 @@
|
|||||||
<string name="pref_title_keep_data_on_device">Mantener los datos de actividad en el dispositivo</string>
|
<string name="pref_title_keep_data_on_device">Mantener los datos de actividad en el dispositivo</string>
|
||||||
<string name="miband_fwinstaller_incompatible_version">Firmware incompatible</string>
|
<string name="miband_fwinstaller_incompatible_version">Firmware incompatible</string>
|
||||||
<string name="fwinstaller_firmware_not_compatible_to_device">Este firmware no es compatible con tu dispositivo</string>
|
<string name="fwinstaller_firmware_not_compatible_to_device">Este firmware no es compatible con tu dispositivo</string>
|
||||||
|
<string name="miband_prefs_reserve_alarm_calendar">Reserva de alarmas para próximos eventos</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -215,4 +215,5 @@
|
|||||||
<string name="miband_fwinstaller_incompatible_version">Incompatible firmware</string>
|
<string name="miband_fwinstaller_incompatible_version">Incompatible firmware</string>
|
||||||
<string name="fwinstaller_firmware_not_compatible_to_device">This firmware is not compatible with the device</string>
|
<string name="fwinstaller_firmware_not_compatible_to_device">This firmware is not compatible with the device</string>
|
||||||
<string name="miband_prefs_reserve_alarm_calendar">Alarms to reserve for upcoming events</string>
|
<string name="miband_prefs_reserve_alarm_calendar">Alarms to reserve for upcoming events</string>
|
||||||
|
<string name="waiting_for_reconnect">waiting for reconnect</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user