1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Pebble: various preparations for FW 3.x support

- Implement encodeAppStart() for FW 3.x
- List cached PBWs in AppManager (currently only UUID)
This commit is contained in:
Andreas Shimokawa 2015-08-11 13:55:35 +02:00
parent 13260416f3
commit e43fed2e7e
2 changed files with 56 additions and 8 deletions

View File

@ -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<GBDeviceApp> 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<GBDeviceApp> getCachedApps() {
List<GBDeviceApp> 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);

View File

@ -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<Pair<Integer, Object>> 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<Pair<Integer, Object>> pairs = new ArrayList<>();
pairs.add(new Pair<>(1, (Object) 1)); // launch
return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs);
}
}
@Override