Remove id and index from GBDeviceApp in favor of UUIDs
This commit is contained in:
parent
6fa2017dda
commit
c37cacf43d
|
@ -1,5 +1,7 @@
|
|||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
|
||||
|
||||
public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport {
|
||||
|
@ -106,8 +108,8 @@ public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAppDelete(int id, int index) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeAppDelete(id, index);
|
||||
public void onAppDelete(UUID uuid) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeAppDelete(uuid);
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,13 @@ import android.view.View;
|
|||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
||||
|
||||
|
||||
|
@ -39,11 +41,10 @@ public class AppManagerActivity extends Activity {
|
|||
for (Integer i = 0; i < appCount; i++) {
|
||||
String appName = intent.getStringExtra("app_name" + i.toString());
|
||||
String appCreator = intent.getStringExtra("app_creator" + i.toString());
|
||||
int id = intent.getIntExtra("app_id" + i.toString(), -1);
|
||||
int index = intent.getIntExtra("app_index" + i.toString(), -1);
|
||||
UUID uuid = UUID.fromString(intent.getStringExtra("app_uuid" + i.toString()));
|
||||
GBDeviceApp.Type appType = GBDeviceApp.Type.values()[intent.getIntExtra("app_type" + i.toString(), 0)];
|
||||
|
||||
appList.add(new GBDeviceApp(id, index, appName, appCreator, "", appType));
|
||||
appList.add(new GBDeviceApp(uuid, appName, appCreator, "", appType));
|
||||
}
|
||||
mGBDeviceAppAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
@ -92,8 +93,7 @@ public class AppManagerActivity extends Activity {
|
|||
if (selectedApp != null) {
|
||||
Intent deleteIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||
deleteIntent.setAction(BluetoothCommunicationService.ACTION_DELETEAPP);
|
||||
deleteIntent.putExtra("app_id", selectedApp.getId());
|
||||
deleteIntent.putExtra("app_index", selectedApp.getIndex());
|
||||
deleteIntent.putExtra("app_uuid", selectedApp.getUUID().toString());
|
||||
startService(deleteIntent);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -21,6 +21,8 @@ import android.widget.Toast;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
|
||||
|
@ -226,9 +228,8 @@ public class BluetoothCommunicationService extends Service {
|
|||
mDeviceSupport.onAppInfoReq();
|
||||
break;
|
||||
case ACTION_DELETEAPP:
|
||||
int id = intent.getIntExtra("app_id", -1);
|
||||
int index = intent.getIntExtra("app_index", -1);
|
||||
mDeviceSupport.onAppDelete(id, index);
|
||||
UUID uuid = UUID.fromString(intent.getStringExtra("app_uuid"));
|
||||
mDeviceSupport.onAppDelete(uuid);
|
||||
break;
|
||||
case ACTION_INSTALL_PEBBLEAPP:
|
||||
String uriString = intent.getStringExtra("app_uri");
|
||||
|
|
|
@ -8,7 +8,9 @@ public interface DeviceCoordinator {
|
|||
String EXTRA_DEVICE_MAC_ADDRESS = "nodomain.freeyourgadget.gadgetbridge.discovery.DeviceCandidate.EXTRA_MAC_ADDRESS";
|
||||
|
||||
boolean supports(DeviceCandidate candidate);
|
||||
|
||||
boolean supports(GBDevice device);
|
||||
|
||||
DeviceType getDeviceType();
|
||||
|
||||
Class<? extends Activity> getPairingActivity();
|
||||
|
|
|
@ -28,6 +28,7 @@ public interface DeviceSupport extends EventHandler {
|
|||
BluetoothAdapter getBluetoothAdapter();
|
||||
|
||||
Context getContext();
|
||||
|
||||
boolean useAutoConnect();
|
||||
|
||||
void pair();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface EventHandler {
|
||||
void onSMS(String from, String body);
|
||||
|
||||
|
@ -19,7 +21,7 @@ public interface EventHandler {
|
|||
|
||||
void onAppInfoReq();
|
||||
|
||||
void onAppDelete(int id, int index);
|
||||
void onAppDelete(UUID uuid);
|
||||
|
||||
void onPhoneVersion(byte os);
|
||||
|
||||
|
|
|
@ -3,16 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge;
|
|||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.core.CoreConstants;
|
||||
import ch.qos.logback.core.util.FileUtil;
|
||||
import ch.qos.logback.core.util.StatusPrinter;
|
||||
|
||||
public class GBApplication extends Application {
|
||||
private static GBApplication context;
|
||||
|
|
|
@ -5,11 +5,12 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import com.android.internal.telephony.ITelephony;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.android.internal.telephony.ITelephony;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GBDeviceApp {
|
||||
private final String name;
|
||||
private final String creator;
|
||||
private final String version;
|
||||
private final int id;
|
||||
private final int index;
|
||||
private final UUID uuid;
|
||||
private final Type type;
|
||||
|
||||
public GBDeviceApp(int id, int index, String name, String creator, String version, Type type) {
|
||||
this.id = id;
|
||||
this.index = index;
|
||||
public GBDeviceApp(UUID uuid, String name, String creator, String version, Type type) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.creator = creator;
|
||||
this.version = version;
|
||||
|
@ -29,12 +29,8 @@ public class GBDeviceApp {
|
|||
return version;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
|
|
|
@ -4,14 +4,15 @@ import android.bluetooth.BluetoothGatt;
|
|||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.AbstractDeviceSupport;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public abstract class BtLEAction {
|
|||
/**
|
||||
* Returns true if this actions expects an (async) result which must
|
||||
* be waited for, before continuing with other actions.
|
||||
*
|
||||
* <p/>
|
||||
* This is needed because the current Bluedroid stack can only deal
|
||||
* with one single bluetooth operation at a time.
|
||||
*/
|
||||
|
@ -33,6 +33,7 @@ public abstract class BtLEAction {
|
|||
|
||||
/**
|
||||
* Executes this action, e.g. reads or write a GATT characteristic.
|
||||
*
|
||||
* @param gatt the characteristic to manipulate, or null if none.
|
||||
* @return true if the action was successful, false otherwise
|
||||
*/
|
||||
|
|
|
@ -56,7 +56,7 @@ public interface GattCallback {
|
|||
* @see BluetoothGattCallback#onCharacteristicWrite(BluetoothGatt, BluetoothGattCharacteristic, int)
|
||||
*/
|
||||
void onCharacteristicWrite(BluetoothGatt gatt,
|
||||
BluetoothGattCharacteristic characteristic, int status);
|
||||
BluetoothGattCharacteristic characteristic, int status);
|
||||
|
||||
/**
|
||||
* @param gatt
|
||||
|
@ -64,7 +64,7 @@ public interface GattCallback {
|
|||
* @see BluetoothGattCallback#onCharacteristicChanged(BluetoothGatt, BluetoothGattCharacteristic)
|
||||
*/
|
||||
void onCharacteristicChanged(BluetoothGatt gatt,
|
||||
BluetoothGattCharacteristic characteristic);
|
||||
BluetoothGattCharacteristic characteristic);
|
||||
|
||||
// /**
|
||||
// * @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
|
||||
|
|
|
@ -19,10 +19,11 @@ import android.widget.ListView;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GB;
|
||||
|
@ -203,7 +204,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
|||
if (ensureBluetoothReady()) {
|
||||
if (what == Scanning.SCANNING_BT) {
|
||||
startBTDiscovery();
|
||||
} else if (what == Scanning.SCANNING_BTLE){
|
||||
} else if (what == Scanning.SCANNING_BTLE) {
|
||||
if (GB.supportsBluetoothLE()) {
|
||||
startBTLEDiscovery();
|
||||
} else {
|
||||
|
@ -326,8 +327,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
|||
Intent intent = new Intent(this, pairingActivity);
|
||||
intent.putExtra(DeviceCoordinator.EXTRA_DEVICE_MAC_ADDRESS, deviceCandidate.getMacAddress());
|
||||
startActivity(intent);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
try {
|
||||
BluetoothDevice btDevice = adapter.getRemoteDevice(deviceCandidate.getMacAddress());
|
||||
if (btDevice.createBond()) {
|
||||
|
|
|
@ -7,11 +7,10 @@ import android.content.SharedPreferences;
|
|||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
||||
|
||||
|
|
|
@ -4,10 +4,11 @@ import android.app.Activity;
|
|||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import java.util.Calendar;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
|
@ -50,6 +51,7 @@ public class MiBandCoordinator implements DeviceCoordinator {
|
|||
/**
|
||||
* Returns the configured user info, or, if that is not available or invalid,
|
||||
* a default user info.
|
||||
*
|
||||
* @param miBandAddress
|
||||
*/
|
||||
public static UserInfo getAnyUserInfo(String miBandAddress) {
|
||||
|
@ -63,6 +65,7 @@ public class MiBandCoordinator implements DeviceCoordinator {
|
|||
|
||||
/**
|
||||
* Returns the user info from the user configured data in the preferences.
|
||||
*
|
||||
* @param miBandAddress
|
||||
* @throws IllegalArgumentException when the user info can not be created
|
||||
*/
|
||||
|
|
|
@ -6,9 +6,9 @@ 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.content.LocalBroadcastManager;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
|
@ -8,7 +8,19 @@ import android.support.v4.content.LocalBroadcastManager;
|
|||
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.*;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_GENERIC;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_K9MAIL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_PEBBLEMSG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_SMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_ALIAS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_GENDER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_HEIGHT_CM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_WEIGHT_KG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_YEAR_OF_BIRTH;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.getNotificationPrefKey;
|
||||
|
||||
public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
||||
@Override
|
||||
|
|
|
@ -5,19 +5,37 @@ import android.bluetooth.BluetoothGattCharacteristic;
|
|||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.*;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_ORIGINAL_COLOUR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_PAUSE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.FLASH_COLOUR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.FLASH_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.FLASH_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.FLASH_ORIGINAL_COLOUR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_GENERIC;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_K9MAIL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_SMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.VIBRATION_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.VIBRATION_PAUSE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.getNotificationPrefIntValue;
|
||||
|
||||
public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
|
@ -80,9 +98,9 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||
builder.queue(getQueue());
|
||||
}
|
||||
|
||||
private static final byte[] startVibrate = new byte[]{ 8, 1 };
|
||||
private static final byte[] stopVibrate = new byte[]{ 19 };
|
||||
private static final byte[] reboot = new byte[]{ 12 };
|
||||
private static final byte[] startVibrate = new byte[]{8, 1};
|
||||
private static final byte[] stopVibrate = new byte[]{19};
|
||||
private static final byte[] reboot = new byte[]{12};
|
||||
|
||||
private byte[] getNotification(long vibrateDuration, int vibrateTimes, int flashTimes, int flashColour, int originalColour, long flashDuration) {
|
||||
byte[] vibrate = new byte[]{(byte) 8, (byte) 1};
|
||||
|
@ -304,7 +322,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAppDelete(int id, int index) {
|
||||
public void onAppDelete(UUID uuid) {
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,6 @@ public class UserInfo {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private String ensureTenCharacters(String alias) {
|
||||
char[] result = new char[10];
|
||||
int aliasLen = alias.length();
|
||||
|
|
|
@ -4,6 +4,11 @@ import android.content.ContentResolver;
|
|||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -12,14 +17,10 @@ import java.io.InputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
|
||||
|
||||
public class PBWReader {
|
||||
|
@ -127,9 +128,10 @@ public class PBWReader {
|
|||
String appName = json.getString("shortName");
|
||||
String appCreator = json.getString("companyName");
|
||||
String appVersion = json.getString("versionLabel");
|
||||
UUID uuid = UUID.fromString(json.getString("uuid"));
|
||||
if (appName != null && appCreator != null && appVersion != null) {
|
||||
// FIXME: dont assume WATCHFACE
|
||||
app = new GBDeviceApp(-1, -1, appName, appCreator, appVersion, GBDeviceApp.Type.WATCHFACE);
|
||||
app = new GBDeviceApp(uuid, appName, appCreator, appVersion, GBDeviceApp.Type.WATCHFACE);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -15,13 +15,14 @@ import android.preference.PreferenceManager;
|
|||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
|
||||
|
@ -375,8 +376,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||
for (Integer i = 0; i < appCount; i++) {
|
||||
appInfoIntent.putExtra("app_name" + i.toString(), appInfoCmd.apps[i].getName());
|
||||
appInfoIntent.putExtra("app_creator" + i.toString(), appInfoCmd.apps[i].getCreator());
|
||||
appInfoIntent.putExtra("app_id" + i.toString(), appInfoCmd.apps[i].getId());
|
||||
appInfoIntent.putExtra("app_index" + i.toString(), appInfoCmd.apps[i].getIndex());
|
||||
appInfoIntent.putExtra("app_uuid" + i.toString(), appInfoCmd.apps[i].getUUID().toString());
|
||||
appInfoIntent.putExtra("app_type" + i.toString(), appInfoCmd.apps[i].getType().ordinal());
|
||||
}
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(appInfoIntent);
|
||||
|
|
|
@ -90,6 +90,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
static final byte APPMANAGER_GETAPPBANKSTATUS = 1;
|
||||
static final byte APPMANAGER_REMOVEAPP = 2;
|
||||
static final byte APPMANAGER_REFRESHAPP = 3;
|
||||
static final byte APPMANAGER_GETUUIDS = 5;
|
||||
|
||||
static final int APPMANAGER_RES_SUCCESS = 1;
|
||||
|
||||
|
@ -138,7 +139,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
|
||||
static final byte PHONEVERSION_REMOTE_OS_UNKNOWN = 0;
|
||||
static final byte PHONEVERSION_REMOTE_OS_IOS = 1;
|
||||
public static final byte PHONEVERSION_REMOTE_OS_ANDROID = 2;
|
||||
static final byte PHONEVERSION_REMOTE_OS_ANDROID = 2;
|
||||
static final byte PHONEVERSION_REMOTE_OS_OSX = 3;
|
||||
static final byte PHONEVERSION_REMOTE_OS_LINUX = 4;
|
||||
static final byte PHONEVERSION_REMOTE_OS_WINDOWS = 5;
|
||||
|
@ -147,7 +148,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
static final short LENGTH_PREFIX = 4;
|
||||
static final short LENGTH_SETTIME = 5;
|
||||
static final short LENGTH_GETTIME = 1;
|
||||
static final short LENGTH_REMOVEAPP = 9;
|
||||
static final short LENGTH_REMOVEAPP = 17;
|
||||
static final short LENGTH_REFRESHAPP = 5;
|
||||
static final short LENGTH_PHONEVERSION = 17;
|
||||
static final short LENGTH_UPLOADSTART = 7;
|
||||
|
@ -159,10 +160,15 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
|
||||
private static final String[] hwRevisions = {"unknown", "ev1", "ev2", "ev2_3", "ev2_4", "v1_5", "v2_0"};
|
||||
private static Random mRandom = new Random();
|
||||
static byte last_id = -1;
|
||||
|
||||
|
||||
private byte last_id = -1;
|
||||
private ArrayList<UUID> tmpUUIDS = new ArrayList<>();
|
||||
|
||||
// FIXME: this does not belong here
|
||||
static final UUID WeatherNeatUUID = UUID.fromString("3684003b-a685-45f9-a713-abc6364ba051");
|
||||
|
||||
|
||||
private static byte[] encodeMessage(short endpoint, byte type, int cookie, String[] parts) {
|
||||
// Calculate length first
|
||||
int length = LENGTH_PREFIX + 1;
|
||||
|
@ -377,18 +383,18 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
|
||||
@Override
|
||||
public byte[] encodeAppInfoReq() {
|
||||
return encodeMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETAPPBANKSTATUS, 0, null);
|
||||
return encodeMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETUUIDS, 0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeAppDelete(int id, int index) {
|
||||
public byte[] encodeAppDelete(UUID uuid) {
|
||||
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REMOVEAPP);
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
buf.putShort(LENGTH_REMOVEAPP);
|
||||
buf.putShort(ENDPOINT_APPMANAGER);
|
||||
buf.put(APPMANAGER_REMOVEAPP);
|
||||
buf.putInt(id);
|
||||
buf.putInt(index);
|
||||
buf.putLong(uuid.getMostSignificantBits());
|
||||
buf.putLong(uuid.getLeastSignificantBits());
|
||||
|
||||
return buf.array();
|
||||
}
|
||||
|
@ -682,7 +688,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
appType = GBDeviceApp.Type.APP_GENERIC;
|
||||
}
|
||||
Short appVersion = buf.getShort();
|
||||
appInfoCmd.apps[i] = new GBDeviceApp(id, index, new String(appName).trim(), new String(appCreator).trim(), appVersion.toString(), appType);
|
||||
appInfoCmd.apps[i] = new GBDeviceApp(tmpUUIDS.get(i), new String(appName).trim(), new String(appCreator).trim(), appVersion.toString(), appType);
|
||||
}
|
||||
for (int i = 0; i < slotCount; i++) {
|
||||
if (!slotInUse[i]) {
|
||||
|
@ -693,6 +699,20 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
}
|
||||
cmd = appInfoCmd;
|
||||
break;
|
||||
case APPMANAGER_GETUUIDS:
|
||||
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
|
||||
sendBytes.encodedBytes = encodeMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETAPPBANKSTATUS, 0, null);
|
||||
cmd = sendBytes;
|
||||
tmpUUIDS.clear();
|
||||
slotsUsed = buf.getInt();
|
||||
for (int i = 0; i < slotsUsed; i++) {
|
||||
long uuid_high = buf.getLong();
|
||||
long uuid_low = buf.getLong();
|
||||
UUID uuid = new UUID(uuid_high, uuid_low);
|
||||
LOG.info("found uuid: " + uuid);
|
||||
tmpUUIDS.add(uuid);
|
||||
}
|
||||
break;
|
||||
case APPMANAGER_REMOVEAPP:
|
||||
GBDeviceCommandAppManagementResult deleteRes = new GBDeviceCommandAppManagementResult();
|
||||
deleteRes.type = GBDeviceCommandAppManagementResult.CommandType.DELETE;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package nodomain.freeyourgadget.gadgetbridge.protocol;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
|
||||
|
||||
public abstract class GBDeviceProtocol {
|
||||
|
@ -40,7 +42,7 @@ public abstract class GBDeviceProtocol {
|
|||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeAppDelete(int id, int index) {
|
||||
public byte[] encodeAppDelete(UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -48,7 +50,11 @@ public abstract class GBDeviceProtocol {
|
|||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeReboot() { return null; }
|
||||
public byte[] encodeReboot() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public GBDeviceCommand decodeResponse(byte[] responseData) { return null; }
|
||||
public GBDeviceCommand decodeResponse(byte[] responseData) {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue