From e43fed2e7ef4bd2b85e9288cbe2c20f90ff7bc77 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 11 Aug 2015 13:55:35 +0200 Subject: [PATCH] Pebble: various preparations for FW 3.x support - Implement encodeAppStart() for FW 3.x - List cached PBWs in AppManager (currently only UUID) --- .../activities/AppManagerActivity.java | 34 ++++++++++++++++++- .../devices/pebble/PebbleProtocol.java | 30 ++++++++++++---- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java index c2a813d67..db93a0efe 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java @@ -5,7 +5,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v4.app.NavUtils; import android.support.v4.content.LocalBroadcastManager; import android.view.ContextMenu; @@ -17,14 +19,18 @@ import android.widget.ListView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService; +import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; public class AppManagerActivity extends Activity { @@ -49,6 +55,15 @@ public class AppManagerActivity extends Activity { appList.add(new GBDeviceApp(uuid, appName, appCreator, "", appType)); } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext()); + + if (sharedPrefs.getBoolean("pebble_force_untested", false)) { + List cachedApps = getCachedApps(); + for (GBDeviceApp app : cachedApps) { + appList.add(app); + } + } mGBDeviceAppAdapter.notifyDataSetChanged(); } } @@ -57,6 +72,23 @@ public class AppManagerActivity extends Activity { private GBDeviceAppAdapter mGBDeviceAppAdapter; private GBDeviceApp selectedApp = null; + private List getCachedApps() { + List cachedAppList = new ArrayList<>(); + try { + File cachePath = new File(FileUtils.getExternalFilesDir().getPath() + "/pbw-cache"); + File files[] = cachePath.listFiles(); + for (File file : files) { + if (file.getName().endsWith(".pbw")) { + UUID uuid = UUID.fromString(file.getName().substring(0, file.getName().length() - 4)); + cachedAppList.add(new GBDeviceApp(uuid, uuid.toString(), "N/A", "", GBDeviceApp.Type.UNKNOWN)); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return cachedAppList; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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 1702b95f5..15cda706b 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 @@ -38,6 +38,7 @@ public class PebbleProtocol extends GBDeviceProtocol { static final short ENDPOINT_PHONECONTROL = 33; static final short ENDPOINT_APPLICATIONMESSAGE = 48; static final short ENDPOINT_LAUNCHER = 49; + static final short ENDPOINT_APPRUNSTATE = 52; static final short ENDPOINT_LOGS = 2000; static final short ENDPOINT_PING = 2001; static final short ENDPOINT_LOGDUMP = 2002; @@ -58,6 +59,8 @@ public class PebbleProtocol extends GBDeviceProtocol { static final short ENDPOINT_BLOBDB = (short) 45531; // 3.x only static final short ENDPOINT_PUTBYTES = (short) 48879; + static final byte APPRUNSTATE_START = 1; + static final byte NOTIFICATION_EMAIL = 0; static final byte NOTIFICATION_SMS = 1; static final byte NOTIFICATION_TWITTER = 2; @@ -161,18 +164,20 @@ public class PebbleProtocol extends GBDeviceProtocol { static final byte TYPE_INT32 = 3; static final short LENGTH_PREFIX = 4; - static final short LENGTH_PING = 5; static final short LENGTH_SIMPLEMESSAGE = 1; - static final short LENGTH_SETTIME = 5; + + static final short LENGTH_APPRUNSTATE = 17; + static final short LENGTH_PING = 5; + static final short LENGTH_PHONEVERSION = 17; static final short LENGTH_REMOVEAPP = 17; static final short LENGTH_REFRESHAPP = 5; - static final short LENGTH_PHONEVERSION = 17; + static final short LENGTH_SETTIME = 5; + static final short LENGTH_SYSTEMMESSAGE = 2; static final short LENGTH_UPLOADSTART = 7; static final short LENGTH_UPLOADCHUNK = 9; static final short LENGTH_UPLOADCOMMIT = 9; static final short LENGTH_UPLOADCOMPLETE = 5; 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", "evt2", "dvt"}; private static Random mRandom = new Random(); @@ -509,9 +514,20 @@ public class PebbleProtocol extends GBDeviceProtocol { @Override public byte[] encodeAppStart(UUID uuid) { - ArrayList> pairs = new ArrayList<>(); - pairs.add(new Pair<>(1, (Object) 1)); // launch - return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs); + if (isFw3x) { + ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPRUNSTATE); + buf.order(ByteOrder.BIG_ENDIAN); + buf.putShort(LENGTH_APPRUNSTATE); + buf.putShort(ENDPOINT_APPRUNSTATE); + buf.put(APPRUNSTATE_START); + buf.putLong(uuid.getMostSignificantBits()); + buf.putLong(uuid.getLeastSignificantBits()); + return buf.array(); + } else { + ArrayList> pairs = new ArrayList<>(); + pairs.add(new Pair<>(1, (Object) 1)); // launch + return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs); + } } @Override