From 4120d686b8a656db3211ab3f10e04a49f7792873 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Wed, 15 Jun 2016 22:15:21 +0200 Subject: [PATCH 1/4] Some key events were not working with the default audio player. Reported in #322 --- .../service/receivers/GBMusicControlReceiver.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java index 459d3c15..eaaa046c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/receivers/GBMusicControlReceiver.java @@ -69,7 +69,9 @@ public class GBMusicControlReceiver extends BroadcastReceiver { Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, keyCode, 0); upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent); - upIntent.setPackage(audioPlayer); + if (!"default".equals(audioPlayer)) { + upIntent.setPackage(audioPlayer); + } context.sendOrderedBroadcast(upIntent, null); } } From d225743d642e5da27ec59c67bee98a04a4015428 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 15 Jun 2016 22:53:05 +0200 Subject: [PATCH 2/4] Pebble: some preparations for Pebble 2 --- .../gadgetbridge/devices/pebble/PBWReader.java | 2 +- .../service/devices/pebble/PebbleProtocol.java | 12 ++++++++---- .../gadgetbridge/util/PebbleUtils.java | 4 ++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java index 42f05b74..8248d257 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java @@ -103,7 +103,7 @@ public class PBWReader { * we still prefer the subfolders if present. * chalk needs to be its subfolder */ - if (platform.equals("aplite") || platform.equals("basalt")) { + if (platform.equals("aplite") || platform.equals("basalt") || platform.equals("diorite")) { boolean hasPlatformDir = false; InputStream afin = new BufferedInputStream(cr.openInputStream(uri)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index c350bd76..95ff6628 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -245,15 +245,19 @@ public class PebbleProtocol extends GBDeviceProtocol { static final long GB_UUID_MASK = 0x4767744272646700L; - // base is -5 + // base is -8 private static final String[] hwRevisions = { // Emulator - "spalding_bb2", "snowy_bb2", "snowy_bb", "bb2", "bb", + "silk_bb2", "unknown", "silk_bb", + "spalding_bb2", "snowy_bb2", "snowy_bb", + "bb2", "bb", "unknown", // Pebble "ev1", "ev2", "ev2_3", "ev2_4", "v1_5", "v2_0", // Pebble Time - "snowy_evt2", "snowy_dvt", "spalding_dvt", "snowy_s3", "spalding" + "snowy_evt2", "snowy_dvt", "spalding_dvt", "snowy_s3", "spalding", + // Pebble 2 + "silk_evt", "unknown", "silk" }; private static final Random mRandom = new Random(); @@ -2041,7 +2045,7 @@ public class PebbleProtocol extends GBDeviceProtocol { } buf.get(tmp, 0, 9); - int hwRev = buf.get() + 5; + int hwRev = buf.get() + 8; if (hwRev >= 0 && hwRev < hwRevisions.length) { versionCmd.hwVersion = hwRevisions[hwRev]; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java index 11ec9678..848235e6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java @@ -7,6 +7,8 @@ public class PebbleUtils { platformName = "basalt"; } else if (hwRev.startsWith("spalding")) { platformName = "chalk"; + } else if (hwRev.startsWith("silk")) { + platformName = "diorite"; } else { platformName = "aplite"; } @@ -20,6 +22,8 @@ public class PebbleUtils { model = "pebble_time_black"; } else if (hwRev.startsWith("spalding")) { model = "pebble_time_round_black_20mm"; + } else if (hwRev.startsWith("silk")) { + model = "pebble2_black"; } else { model = "pebble_black"; } From b79b94809af07d6910f423424032433eb373d2e2 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 16 Jun 2016 00:24:27 +0200 Subject: [PATCH 3/4] initial support for FW 4.0-dp1 --- .../pebble/AppMessageHandlerMisfit.java | 2 +- .../devices/pebble/PebbleIoThread.java | 4 +-- .../devices/pebble/PebbleProtocol.java | 29 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java index 1a7e4b97..adc42650 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java @@ -69,7 +69,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler { break; } - if (!mPebbleProtocol.isFw3x) { + if (mPebbleProtocol.mFwMajor < 3) { timestamp -= SimpleTimeZone.getDefault().getOffset(timestamp * 1000L) / 1000; } Date startDate = new Date((long) timestamp * 1000L); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index fcc19641..e7fd0d7e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -296,7 +296,7 @@ public class PebbleIoThread extends GBDeviceIoThread { if (mPBWReader.isFirmware()) { writeInstallApp(mPebbleProtocol.encodeInstallFirmwareComplete()); finishInstall(false); - } else if (mPBWReader.isLanguage() || mPebbleProtocol.isFw3x) { + } else if (mPBWReader.isLanguage() || mPebbleProtocol.mFwMajor >= 3) { finishInstall(false); // FIXME: dont know yet how to detect success } else { writeInstallApp(mPebbleProtocol.encodeAppRefresh(mInstallSlot)); @@ -614,7 +614,7 @@ public class PebbleIoThread extends GBDeviceIoThread { writeInstallApp(mPebbleProtocol.encodeGetTime()); } else { GBDeviceApp app = mPBWReader.getGBDeviceApp(); - if (mPebbleProtocol.isFw3x && !mPBWReader.isLanguage()) { + if (mPebbleProtocol.mFwMajor >= 3 && !mPBWReader.isLanguage()) { if (appId == 0) { // only install metadata - not the binaries write(mPebbleProtocol.encodeInstallMetadata(app.getUUID(), app.getName(), mPBWReader.getAppVersion(), mPBWReader.getSdkVersion(), mPBWReader.getFlags(), mPBWReader.getIconId())); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index 95ff6628..1a882db1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -262,7 +262,7 @@ public class PebbleProtocol extends GBDeviceProtocol { private static final Random mRandom = new Random(); - boolean isFw3x = false; + int mFwMajor = 3; boolean mForceProtocol = false; GBDeviceEventScreenshot mDevEventScreenshot = null; int mScreenshotRemaining = -1; @@ -453,12 +453,12 @@ public class PebbleProtocol extends GBDeviceProtocol { } Long ts = System.currentTimeMillis(); - if (!isFw3x) { + if (mFwMajor < 3) { ts += (SimpleTimeZone.getDefault().getOffset(ts)); } ts /= 1000; - if (isFw3x) { + if (mFwMajor >= 3) { // 3.x notification return encodeBlobdbNotification(id, (int) (ts & 0xffffffffL), title, subtitle, notificationSpec.body, notificationSpec.sourceName, hasHandle, notificationSpec.type, notificationSpec.cannedReplies); } else if (mForceProtocol || notificationSpec.type != NotificationType.EMAIL) { @@ -500,7 +500,7 @@ public class PebbleProtocol extends GBDeviceProtocol { long ts = System.currentTimeMillis(); long ts_offset = (SimpleTimeZone.getDefault().getOffset(ts)); ByteBuffer buf; - if (isFw3x) { + if (mFwMajor >= 3) { String timezone = SimpleTimeZone.getDefault().getID(); short length = (short) (LENGTH_SETTIME + timezone.getBytes().length + 3); buf = ByteBuffer.allocate(LENGTH_PREFIX + length); @@ -1194,7 +1194,7 @@ public class PebbleProtocol extends GBDeviceProtocol { @Override public byte[] encodeAppInfoReq() { - if (isFw3x) { + if (mFwMajor >= 3) { return null; // can't do this on 3.x :( } return encodeSimpleMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETUUIDS); @@ -1202,7 +1202,7 @@ public class PebbleProtocol extends GBDeviceProtocol { @Override public byte[] encodeAppStart(UUID uuid, boolean start) { - if (isFw3x) { + if (mFwMajor >= 3) { ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPRUNSTATE); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_APPRUNSTATE); @@ -1221,7 +1221,7 @@ public class PebbleProtocol extends GBDeviceProtocol { @Override public byte[] encodeAppDelete(UUID uuid) { - if (isFw3x) { + if (mFwMajor >= 3) { if (UUID_PEBBLE_HEALTH.equals(uuid)) { return encodeActivateHealth(false); } @@ -1317,7 +1317,7 @@ public class PebbleProtocol extends GBDeviceProtocol { /* pebble specific install methods */ public byte[] encodeUploadStart(byte type, int app_id, int size, String filename) { short length; - if (isFw3x && (type != PUTBYTES_TYPE_FILE)) { + if (mFwMajor >= 3 && (type != PUTBYTES_TYPE_FILE)) { length = LENGTH_UPLOADSTART_3X; type |= 0b10000000; } else { @@ -1336,7 +1336,7 @@ public class PebbleProtocol extends GBDeviceProtocol { buf.putInt(size); buf.put(type); - if (isFw3x && (type != PUTBYTES_TYPE_FILE)) { + if (mFwMajor >= 3 && (type != PUTBYTES_TYPE_FILE)) { buf.putInt(app_id); } else { // slot @@ -1724,7 +1724,7 @@ public class PebbleProtocol extends GBDeviceProtocol { int id; long uuid_high = 0; long uuid_low = 0; - if (isFw3x) { + if (mFwMajor >= 3) { buf.order(ByteOrder.BIG_ENDIAN); uuid_high = buf.getLong(); uuid_low = buf.getLong(); @@ -1792,9 +1792,9 @@ public class PebbleProtocol extends GBDeviceProtocol { break; } GBDeviceEventSendBytes sendBytesAck = null; - if (isFw3x || needsAck2x) { + if (mFwMajor >= 3 || needsAck2x) { sendBytesAck = new GBDeviceEventSendBytes(); - if (isFw3x) { + if (mFwMajor >= 3) { sendBytesAck.encodedBytes = encodeActionResponse(new UUID(uuid_high, uuid_low), icon_id, caption); } else { sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, caption); @@ -2040,9 +2040,8 @@ public class PebbleProtocol extends GBDeviceProtocol { buf.get(tmp, 0, 32); versionCmd.fwVersion = new String(tmp).trim(); - if (versionCmd.fwVersion.startsWith("v3")) { - isFw3x = true; - } + + mFwMajor = versionCmd.fwVersion.charAt(1); buf.get(tmp, 0, 9); int hwRev = buf.get() + 8; From 9f61458790d1f1ab7fe496ac7f5dd114f34e3355 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 16 Jun 2016 00:59:15 +0200 Subject: [PATCH 4/4] Pebble: Allow installation of aplite apps on diorite --- .../devices/pebble/PBWReader.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java index 8248d257..9e613a23 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java @@ -96,23 +96,35 @@ public class PBWReader { String platformDir = ""; if (!uri.toString().endsWith(".pbz")) { - platformDir = platform + "/"; - /* * for aplite and basalt it is possible to install 2.x apps which have no subfolder * we still prefer the subfolders if present. * chalk needs to be its subfolder */ - if (platform.equals("aplite") || platform.equals("basalt") || platform.equals("diorite")) { - boolean hasPlatformDir = false; + String[] platformDirs; + switch (platform) { + case "basalt": + platformDirs = new String[]{"basalt/"}; + break; + case "chalk": + platformDirs = new String[]{"chalk/"}; + break; + case "diorite": + platformDirs = new String[]{"diorite/", "aplite/"}; + break; + default: + platformDirs = new String[]{"aplite/"}; + } + + for (String dir : platformDirs) { InputStream afin = new BufferedInputStream(cr.openInputStream(uri)); ZipInputStream zis = new ZipInputStream(afin); ZipEntry ze; try { while ((ze = zis.getNextEntry()) != null) { - if (ze.getName().startsWith(platformDir)) { - hasPlatformDir = true; + if (ze.getName().startsWith(dir)) { + platformDir = dir; break; } } @@ -120,13 +132,13 @@ public class PBWReader { } catch (IOException e) { e.printStackTrace(); } + } - if (!hasPlatformDir) { - platformDir = ""; - } + if (platform.equals("chalk") && platformDir.equals("")) { + return; } } - + LOG.info("using platformdir: '" + platformDir + "'"); String appName = null; String appCreator = null; String appVersion = null;