diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java index aa2932e6b..1854e025b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java @@ -120,12 +120,6 @@ public class PebbleIoThread extends GBDeviceIoThread { mIsConnected = true; - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - if (sharedPrefs.getBoolean("datetime_synconconnect", true)) { - LOG.info("syncing time"); - write(mPebbleProtocol.encodeSetTime(-1)); - } - return true; } @@ -311,6 +305,13 @@ public class PebbleIoThread extends GBDeviceIoThread { Context context = getContext(); switch (deviceCmd.commandClass) { + case VERSION_INFO: + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + if (sharedPrefs.getBoolean("datetime_synconconnect", true)) { + LOG.info("syncing time"); + write(mPebbleProtocol.encodeSetTime(-1)); + } + return false; case APP_MANAGEMENT_RES: GBDeviceCommandAppManagementResult appMgmtRes = (GBDeviceCommandAppManagementResult) deviceCmd; switch (appMgmtRes.type) { @@ -411,6 +412,18 @@ public class PebbleIoThread extends GBDeviceIoThread { if (mPBWReader.isFirmware()) { writeInstallApp(mPebbleProtocol.encodeInstallFirmwareStart()); + + /* + * This is a hack for recovery mode, in which the blocking read has no timeout and the + * firmware installation command does not return any ack. + * In normal mode we would got at least out of the blocking read call after a while. + * + * + * ... we should really not handle installation from thread that does the blocking read + * + */ + writeInstallApp(mPebbleProtocol.encodeGetTime()); + LOG.info("starting firmware installation"); mInstallSlot = 0; mInstallState = PebbleAppInstallState.START_INSTALL; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java index e50823f03..18c7b80c1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java @@ -28,9 +28,6 @@ public class PebbleProtocol extends GBDeviceProtocol { private static final Logger LOG = LoggerFactory.getLogger(PebbleProtocol.class); - // set to false AT YOUR OWN RISK. I ended up in recovery - static private final boolean USE_OLD_NOTIFICATION_PROTOCOL = true; - static final short ENDPOINT_FIRMWARE = 1; static final short ENDPOINT_TIME = 11; static final short ENDPOINT_FIRMWAREVERSION = 16; @@ -164,10 +161,10 @@ public class PebbleProtocol extends GBDeviceProtocol { static final short LENGTH_UPLOADCANCEL = 5; static final short LENGTH_SYSTEMMESSAGE = 2; - private static final String[] hwRevisions = {"unknown", "ev1", "ev2", "ev2_3", "ev2_4", "v1_5", "v2_0"}; + private static final String[] hwRevisions = {"unknown", "ev1", "ev2", "ev2_3", "ev2_4", "v1_5", "v2_0", "evt2", "dvt"}; private static Random mRandom = new Random(); - + boolean isFw3x = true; byte last_id = -1; private ArrayList tmpUUIDS = new ArrayList<>(); @@ -224,7 +221,8 @@ public class PebbleProtocol extends GBDeviceProtocol { ts += (SimpleTimeZone.getDefault().getOffset(ts)); ts /= 1000; - if (USE_OLD_NOTIFICATION_PROTOCOL) { + + if (!isFw3x || true) { // remove || true if necessary on FW 3.x String[] parts = {from, body, ts.toString()}; return encodeMessage(ENDPOINT_NOTIFICATION, NOTIFICATION_SMS, 0, parts); } @@ -682,6 +680,10 @@ public class PebbleProtocol extends GBDeviceProtocol { buf.get(tmp, 0, 32); versionCmd.fwVersion = new String(tmp).trim(); + if (versionCmd.fwVersion.startsWith("3.")) { + isFw3x = true; + } + buf.get(tmp, 0, 9); Byte hwRev = buf.get(); if (hwRev > 0 && hwRev < hwRevisions.length) {