1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-14 14:09:28 +01:00

Merge branch 'fossil-q-hr' of https://codeberg.org/Freeyourgadget/Gadgetbridge into fossil-q-hr

This commit is contained in:
Daniel Dakhno 2020-01-03 18:04:30 +01:00
commit 822759c238
4 changed files with 37 additions and 12 deletions

View File

@ -31,6 +31,7 @@ import androidx.annotation.NonNull;
import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
@ -170,7 +171,7 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
@Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return null;
return new int[] {R.xml.devicesettings_pairingkey };
}
}

View File

@ -111,6 +111,8 @@ public class QHybridSupport extends QHybridBaseSupport {
public static final String ITEM_TIMEZONE_OFFSET = "STEPTIMEZONE_OFFSET_COUNT";
private static final Logger logger = LoggerFactory.getLogger(QHybridSupport.class);
private final BroadcastReceiver commandReceiver;
private final BroadcastReceiver globalCommandReceiver;
private PackageConfigHelper helper;
@ -139,7 +141,7 @@ public class QHybridSupport extends QHybridBaseSupport {
commandFilter.addAction(QHYBRID_COMMAND_OVERWRITE_BUTTONS);
commandFilter.addAction(QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED);
commandFilter.addAction(QHYBRID_COMMAND_SEND_MENU_ITEMS);
BroadcastReceiver commandReceiver = new BroadcastReceiver() {
commandReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -233,7 +235,7 @@ public class QHybridSupport extends QHybridBaseSupport {
globalFilter.addAction(QHYBRID_ACTION_SET_ACTIVITY_HAND);
globalFilter.addAction(QHYBRID_COMMAND_SET_MENU_MESSAGE);
globalFilter.addAction(QHYBRID_COMMAND_SET_WIDGET_CONTENT);
BroadcastReceiver globalCommandReceiver = new BroadcastReceiver() {
globalCommandReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//noinspection SwitchStatementWithTooFewBranches
@ -276,6 +278,13 @@ public class QHybridSupport extends QHybridBaseSupport {
GBApplication.getContext().registerReceiver(globalCommandReceiver, globalFilter);
}
@Override
public void dispose() {
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(commandReceiver);
GBApplication.getContext().unregisterReceiver(globalCommandReceiver);
super.dispose();
}
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
super.onSetAlarms(alarms);

View File

@ -2,26 +2,23 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fos
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.TimeZone;
import java.util.zip.CRC32;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.Widget;
@ -32,10 +29,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.encoder.RLEEncoder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.RequestMtuRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.SetDeviceStateRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.*;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.TimeConfigItem;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest;
@ -53,8 +49,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidgetElement;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.utils.StringUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.*;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_PHONE_REQUEST;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_WATCH_REQUEST;
public class FossilHRWatchAdapter extends FossilWatchAdapter {
private byte[] secretKey = new byte[]{(byte) 0x60, (byte) 0x26, (byte) 0xB7, (byte) 0xFD, (byte) 0xB2, (byte) 0x6D, (byte) 0x05, (byte) 0x5E, (byte) 0xDA, (byte) 0xF7, (byte) 0x4B, (byte) 0x49, (byte) 0x98, (byte) 0x78, (byte) 0x02, (byte) 0x38};
@ -279,9 +277,26 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
}
public byte[] getSecretKey() {
return secretKey;
byte[] authKeyBytes = new byte[16];
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(getDeviceSupport().getDevice().getAddress());
String authKey = sharedPrefs.getString("authkey", null);
if (authKey != null && !authKey.isEmpty()) {
byte[] srcBytes = authKey.trim().getBytes();
if (authKey.length() == 34 && authKey.startsWith("0x")) {
srcBytes = GB.hexStringToByteArray(authKey.substring(2));
}
System.arraycopy(srcBytes, 0, authKeyBytes, 0, Math.min(srcBytes.length, 16));
}
return authKeyBytes;
}
// public byte[] getSecretKey() {
// return secretKey;
// }
public void setSecretKey(byte[] secretKey) {
this.secretKey = secretKey;
}

View File

@ -59,7 +59,7 @@ public abstract class Request {
public abstract byte[] getStartSequence();
public void handleResponse(BluetoothGattCharacteristic characteristic){};
public void handleResponse(BluetoothGattCharacteristic characteristic) {}
public String getName(){
Class thisClass = getClass();