still don't know what is goind on with uploading files...

This commit is contained in:
dakhnod 2019-11-04 02:47:38 +01:00
parent 1318b58ad2
commit 016ae8be13
12 changed files with 196 additions and 53 deletions

View File

@ -40,6 +40,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCallback;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter;
@ -73,6 +74,7 @@ public class QHybridSupport extends QHybridBaseSupport {
public static final String ITEM_EXTENDED_VIBRATION_SUPPORT = "EXTENDED_VIBRATION";
public static final String ITEM_HAS_ACTIVITY_HAND = "HAS_ACTIVITY_HAND";
public static final String ITEM_USE_ACTIVITY_HAND = "USE_ACTIVITY_HAND";
public static final String ITEM_LAST_HEARTBEAT = "LAST_HEARTBEAT";
private static final Logger logger = LoggerFactory.getLogger(QHybridSupport.class);
@ -354,9 +356,8 @@ public class QHybridSupport extends QHybridBaseSupport {
@Override
public void onFindDevice(boolean start) {
try {
if (start && !watchAdapter.supportsExtendedVibration()) {
if (watchAdapter.supportsExtendedVibration()) {
GB.toast("Device does not support brr brr", Toast.LENGTH_SHORT, GB.INFO);
return;
}
} catch (UnsupportedOperationException e) {
notifiyException(e);

View File

@ -40,6 +40,7 @@ public abstract class WatchAdapter {
public abstract void syncNotificationSettings();
public abstract void onTestNewFunction();
public abstract boolean supportsFindDevice();
public abstract boolean supportsExtendedVibration();
public abstract boolean supportsActivityHand();
public abstract String getModelName();

View File

@ -5,17 +5,18 @@ import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import android.widget.Toast;
import java.util.ArrayDeque;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Queue;
import java.util.TimeZone;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilter;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter;
@ -23,9 +24,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Req
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationGetRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePrepareRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileCloseRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.NotificationFilterPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest;
@ -47,10 +47,13 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void initialize() {
playPairingAnimation();
queueWrite(new ConfigurationGetRequest(this));
syncNotificationSettings();
// playPairingAnimation();
// queueWrite(new FileDeleteRequest((short) 0x0200));
// queueWrite(new ConfigurationGetRequest(this));
//
// syncNotificationSettings();
getDeviceSupport().getDevice().setState(GBDevice.State.INITIALIZED);
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
}
@Override
@ -153,10 +156,6 @@ public class FossilWatchAdapter extends WatchAdapter {
PackageConfigHelper helper = new PackageConfigHelper(getContext());
final ArrayList<NotificationConfiguration> configurations = helper.getNotificationConfigurations();
if (configurations.size() == 1) configurations.add(configurations.get(0));
queueWrite(new FilePrepareRequest((short) 0x0C00) {
@Override
public void onPrepare() {
super.onPrepare();
queueWrite(new NotificationFilterPutRequest(configurations, FossilWatchAdapter.this) {
@Override
public void onFilePut(boolean success) {
@ -173,8 +172,6 @@ public class FossilWatchAdapter extends WatchAdapter {
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
}
});
}
});
} catch (GBException e) {
e.printStackTrace();
}
@ -182,25 +179,23 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void onTestNewFunction() {
try {
queueWrite(new NotificationFilterPutRequest(new PackageConfigHelper(getContext()).getNotificationConfigurations(), this));
} catch (GBException e) {
e.printStackTrace();
}
@Override
public boolean supportsFindDevice() {
return false;
}
@Override
public boolean supportsExtendedVibration() {
/*String modelNumber = getDeviceSupport().getDevice().getModel();
String modelNumber = getDeviceSupport().getDevice().getModel();
switch (modelNumber) {
case "HW.0.0":
return true;
case "HL.0.0":
return false;
}
throw new UnsupportedOperationException("model " + modelNumber + " not supported");*/
return false;
throw new UnsupportedOperationException("model " + modelNumber + " not supported");
}
@Override
@ -229,15 +224,19 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void onFetchActivityData() {
NotificationConfiguration config = new NotificationConfiguration((short) 0, (short) 0, (short) 0, null);
config.setPackageName("org.telegram.messenger");
playNotification(config);
// queueWrite(new ConfigurationPutRequest(new ConfigurationPutRequest.ConfigItem[0], this));
queueWrite(new ConfigurationPutRequest(new ConfigurationPutRequest.VibrationStrengthConfigItem((byte) 100), this));
// queueWrite(new ConfigurationGetRequest(this));
}
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
switch (characteristic.getUuid().toString()) {
case "3dda0006-957f-7d4a-34a6-74696673696d": {
handleBackgroundCharacteristic(characteristic);
break;
}
case "3dda0002-957f-7d4a-34a6-74696673696d": {
break;
}
@ -251,6 +250,7 @@ public class FossilWatchAdapter extends WatchAdapter {
} catch (RuntimeException e) {
e.printStackTrace();
getDeviceSupport().notifiyException(e);
GB.toast(fossilRequest.getName() + " failed", Toast.LENGTH_SHORT, GB.ERROR);
requestFinished = true;
}
@ -271,6 +271,21 @@ public class FossilWatchAdapter extends WatchAdapter {
return true;
}
private void handleBackgroundCharacteristic(BluetoothGattCharacteristic characteristic){
byte[] value = characteristic.getValue();
switch (value[1]){
case 2: {
byte syncId = value[2];
getDeviceSupport().getDevice().addDeviceInfo(new GenericItem(QHybridSupport.ITEM_LAST_HEARTBEAT, DateFormat.getTimeInstance().format(new Date())));
break;
}
case 8: {
break;
}
}
}
private void log(String message) {
Log.d("FossilWatchAdapter", message);
}

View File

@ -397,6 +397,11 @@ public class MisfitWatchAdapter extends WatchAdapter {
}
@Override
public boolean supportsFindDevice() {
return supportsExtendedVibration();
}
@Override
public boolean supportsExtendedVibration() {
String modelNumber = getDeviceSupport().getDevice().getModel();

View File

@ -1,7 +1,15 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
public abstract class FossilRequest extends Request {
public abstract boolean isFinished();
@Override
public UUID getRequestUUID() {
return UUID.fromString("3dda0003-957f-7d4a-34a6-74696673696d");
}
}

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileCloseAndPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
public class ConfigurationPutRequest extends FilePutRequest {
@ -57,15 +58,25 @@ public class ConfigurationPutRequest extends FilePutRequest {
}
public ConfigurationPutRequest(ConfigItem item, FossilWatchAdapter adapter) {
super((short) 0x0800, createFileContent(item), adapter);
super((short) 0x0800, createFileContent(new ConfigItem[]{item}), adapter);
}
public static byte[] createFileContent(ConfigItem item) {
ByteBuffer buffer = ByteBuffer.allocate(item.getItemSize() + 3);
public ConfigurationPutRequest(ConfigItem[] items, FossilWatchAdapter adapter) {
super((short) 0x0800, createFileContent(items), adapter);
}
private static byte[] createFileContent(ConfigItem[] items) {
int overallSize = 0;
for(ConfigItem item : items){
overallSize += item.getItemSize() + 3;
}
ByteBuffer buffer = ByteBuffer.allocate(overallSize);
buffer.order(ByteOrder.LITTLE_ENDIAN);
for(ConfigItem item : items){
buffer.putShort(item.getId());
buffer.put((byte) item.getItemSize());
buffer.put(item.getContent());
}
return buffer.array();
}

View File

@ -0,0 +1,37 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
import android.widget.Toast;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.NotificationFilterPutRequest;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class FileCloseAndPutRequest extends FileCloseRequest {
FossilWatchAdapter adapter;
byte[] data;
public FileCloseAndPutRequest(short fileHandle, byte[] data, FossilWatchAdapter adapter) {
super(fileHandle);
this.adapter = adapter;
this.data = data;
}
@Override
public void onPrepare() {
super.onPrepare();
adapter.queueWrite(new FilePutRequest(getHandle(), this.data, adapter) {
@Override
public void onFilePut(boolean success) {
super.onFilePut(success);
FileCloseAndPutRequest.this.onFilePut(success);
}
});
}
public void onFilePut(boolean success){
}
}

View File

@ -9,11 +9,11 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
public class FilePrepareRequest extends FossilRequest {
public class FileCloseRequest extends FossilRequest {
private boolean isFinished = false;
private short handle;
public FilePrepareRequest(short fileHandle) {
public FileCloseRequest(short fileHandle) {
this.handle = fileHandle;
ByteBuffer buffer = this.createBuffer();
buffer.putShort(fileHandle);
@ -21,6 +21,10 @@ public class FilePrepareRequest extends FossilRequest {
this.data = buffer.array();
}
public short getHandle() {
return handle;
}
@Override
public void handleResponse(BluetoothGattCharacteristic characteristic) {
super.handleResponse(characteristic);

View File

@ -0,0 +1,59 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
import android.bluetooth.BluetoothGattCharacteristic;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
public class FileDeleteRequest extends FossilRequest {
private boolean finished = false;
private short handle;
public FileDeleteRequest(short handle) {
this.handle = handle;
ByteBuffer buffer = createBuffer();
buffer.putShort(handle);
this.data = buffer.array();
}
@Override
public void handleResponse(BluetoothGattCharacteristic characteristic) {
super.handleResponse(characteristic);
if(!characteristic.getUuid().toString().equals("3dda0003-957f-7d4a-34a6-74696673696d"))
throw new RuntimeException("wrong response UUID");
byte[] value = characteristic.getValue();
if(value.length != 4) throw new RuntimeException("wrong response length");
if(value[0] != (byte) 0x8B) throw new RuntimeException("wrong response start");
ByteBuffer buffer = ByteBuffer.wrap(value);
buffer.order(ByteOrder.LITTLE_ENDIAN);
if(buffer.getShort(1) != this.handle) throw new RuntimeException("wrong response handle");
if(buffer.get(3) != 0) throw new RuntimeException("wrong response status: " + buffer.get(3));
this.finished = true;
}
@Override
public boolean isFinished() {
return finished;
}
@Override
public byte[] getStartSequence() {
return new byte[]{(byte) 0x0B};
}
@Override
public int getPayloadLength() {
return 3;
}
}

View File

@ -14,7 +14,7 @@ public abstract class FileLookupAndGetRequest extends FileLookupRequest {
public void handleFileData(byte[] fileData) {
FileLookupAndGetRequest.this.handleFileData(fileData);
}
});
}, true);
}
abstract public void handleFileData(byte[] fileData);

View File

@ -161,6 +161,7 @@ public class FilePutRequest extends FossilRequest {
break;
}
case 9: {
this.onFilePut(false);
throw new RuntimeException("file put timeout");
/*timeout = true;
ByteBuffer buffer2 = ByteBuffer.allocate(3);

View File

@ -7,6 +7,7 @@ import java.util.zip.CRC32;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileCloseAndPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
public class NotificationFilterPutRequest extends FilePutRequest {