mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 02:55: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:
parent
13260416f3
commit
e43fed2e7e
@ -5,7 +5,9 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
@ -17,14 +19,18 @@ import android.widget.ListView;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
|
|
||||||
|
|
||||||
public class AppManagerActivity extends Activity {
|
public class AppManagerActivity extends Activity {
|
||||||
@ -49,6 +55,15 @@ public class AppManagerActivity extends Activity {
|
|||||||
|
|
||||||
appList.add(new GBDeviceApp(uuid, appName, appCreator, "", appType));
|
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();
|
mGBDeviceAppAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,6 +72,23 @@ public class AppManagerActivity extends Activity {
|
|||||||
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
||||||
private GBDeviceApp selectedApp = null;
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -38,6 +38,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
static final short ENDPOINT_PHONECONTROL = 33;
|
static final short ENDPOINT_PHONECONTROL = 33;
|
||||||
static final short ENDPOINT_APPLICATIONMESSAGE = 48;
|
static final short ENDPOINT_APPLICATIONMESSAGE = 48;
|
||||||
static final short ENDPOINT_LAUNCHER = 49;
|
static final short ENDPOINT_LAUNCHER = 49;
|
||||||
|
static final short ENDPOINT_APPRUNSTATE = 52;
|
||||||
static final short ENDPOINT_LOGS = 2000;
|
static final short ENDPOINT_LOGS = 2000;
|
||||||
static final short ENDPOINT_PING = 2001;
|
static final short ENDPOINT_PING = 2001;
|
||||||
static final short ENDPOINT_LOGDUMP = 2002;
|
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_BLOBDB = (short) 45531; // 3.x only
|
||||||
static final short ENDPOINT_PUTBYTES = (short) 48879;
|
static final short ENDPOINT_PUTBYTES = (short) 48879;
|
||||||
|
|
||||||
|
static final byte APPRUNSTATE_START = 1;
|
||||||
|
|
||||||
static final byte NOTIFICATION_EMAIL = 0;
|
static final byte NOTIFICATION_EMAIL = 0;
|
||||||
static final byte NOTIFICATION_SMS = 1;
|
static final byte NOTIFICATION_SMS = 1;
|
||||||
static final byte NOTIFICATION_TWITTER = 2;
|
static final byte NOTIFICATION_TWITTER = 2;
|
||||||
@ -161,18 +164,20 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
static final byte TYPE_INT32 = 3;
|
static final byte TYPE_INT32 = 3;
|
||||||
|
|
||||||
static final short LENGTH_PREFIX = 4;
|
static final short LENGTH_PREFIX = 4;
|
||||||
static final short LENGTH_PING = 5;
|
|
||||||
static final short LENGTH_SIMPLEMESSAGE = 1;
|
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_REMOVEAPP = 17;
|
||||||
static final short LENGTH_REFRESHAPP = 5;
|
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_UPLOADSTART = 7;
|
||||||
static final short LENGTH_UPLOADCHUNK = 9;
|
static final short LENGTH_UPLOADCHUNK = 9;
|
||||||
static final short LENGTH_UPLOADCOMMIT = 9;
|
static final short LENGTH_UPLOADCOMMIT = 9;
|
||||||
static final short LENGTH_UPLOADCOMPLETE = 5;
|
static final short LENGTH_UPLOADCOMPLETE = 5;
|
||||||
static final short LENGTH_UPLOADCANCEL = 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 final String[] hwRevisions = {"unknown", "ev1", "ev2", "ev2_3", "ev2_4", "v1_5", "v2_0", "evt2", "dvt"};
|
||||||
private static Random mRandom = new Random();
|
private static Random mRandom = new Random();
|
||||||
@ -509,10 +514,21 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] encodeAppStart(UUID uuid) {
|
public byte[] encodeAppStart(UUID uuid) {
|
||||||
|
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<>();
|
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
|
||||||
pairs.add(new Pair<>(1, (Object) 1)); // launch
|
pairs.add(new Pair<>(1, (Object) 1)); // launch
|
||||||
return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs);
|
return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] encodeAppDelete(UUID uuid) {
|
public byte[] encodeAppDelete(UUID uuid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user