diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java index 5be17a635..355a6923a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java @@ -358,6 +358,7 @@ public class QHybridSupport extends QHybridBaseSupport { return; } } catch (UnsupportedOperationException e) { + notifiyException(e); GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO); } @@ -478,6 +479,7 @@ public class QHybridSupport extends QHybridBaseSupport { gbDevice.addDeviceInfo(new GenericItem(ITEM_EXTENDED_VIBRATION_SUPPORT, String.valueOf(watchAdapter.supportsExtendedVibration()))); gbDevice.addDeviceInfo(new GenericItem(ITEM_HAS_ACTIVITY_HAND, String.valueOf(watchAdapter.supportsActivityHand()))); } catch (UnsupportedOperationException e) { + notifiyException(e); GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO); gbDevice.addDeviceInfo(new GenericItem(ITEM_EXTENDED_VIBRATION_SUPPORT, "false")); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java index 7dd61de55..beaf4d23b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java @@ -9,7 +9,6 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; -import java.util.NoSuchElementException; import java.util.Queue; import java.util.TimeZone; @@ -21,14 +20,15 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.ConfigurationGetRequest; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.ConfigurationPutRequest; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FileGetRequest; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FileLookupRequest; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FilePrepareRequest; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FilePutRequest; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.NotificationFilterPutRequest; -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.PlayNotificationRequest; +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.FilePutRequest; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.NotificationFilterPutRequest; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.AnimationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.MoveHandsRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest; @@ -36,12 +36,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.mis import nodomain.freeyourgadget.gadgetbridge.util.GB; public class FossilWatchAdapter extends WatchAdapter { - private Queue requestQueue = new ArrayDeque<>(); + private ArrayList requestQueue = new ArrayList<>(); - FilePutRequest filePutRequest; - FileGetRequest fileGetRequest; - FileLookupRequest fileLookupRequest; - FilePrepareRequest filePrepareRequest; + FossilRequest fossilRequest; public FossilWatchAdapter(QHybridSupport deviceSupport) { super(deviceSupport); @@ -51,14 +48,9 @@ public class FossilWatchAdapter extends WatchAdapter { @Override public void initialize() { playPairingAnimation(); - queueWrite(new ConfigurationGetRequest(this) { - @Override - public void handleConfigurationLoaded() { - super.handleConfigurationLoaded(); + queueWrite(new ConfigurationGetRequest(this)); - syncNotificationSettings(); - } - }); + syncNotificationSettings(); } @Override @@ -200,14 +192,16 @@ public class FossilWatchAdapter extends WatchAdapter { @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"); + throw new UnsupportedOperationException("model " + modelNumber + " not supported");*/ + + return false; } @Override @@ -246,94 +240,33 @@ public class FossilWatchAdapter extends WatchAdapter { public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { switch (characteristic.getUuid().toString()) { case "3dda0002-957f-7d4a-34a6-74696673696d": { - if (fileGetRequest == null && fileLookupRequest == null && filePutRequest == null && filePrepareRequest == null) { - try { - queueWrite(requestQueue.remove()); - } catch (NoSuchElementException e) { - log("requestsQueue empty"); - } - } break; } case "3dda0004-957f-7d4a-34a6-74696673696d": case "3dda0003-957f-7d4a-34a6-74696673696d": { - if (filePutRequest != null) { - - filePutRequest.handleResponse(characteristic); - - if (filePutRequest.isFinished()) { - log("filePutRequets finished"); - filePutRequest = null; - try { - queueWrite(requestQueue.remove()); - } catch (NoSuchElementException e) { - log("requestsQueue empty"); - } - } - } else if (fileGetRequest != null) { + if (fossilRequest != null) { boolean requestFinished; try { - fileGetRequest.handleResponse(characteristic); - requestFinished = fileGetRequest.isFinished(); + fossilRequest.handleResponse(characteristic); + requestFinished = fossilRequest.isFinished(); } catch (RuntimeException e) { e.printStackTrace(); + getDeviceSupport().notifiyException(e); requestFinished = true; } if (requestFinished) { - log("fileGetRequest finished"); - fileGetRequest = null; - try { - queueWrite(requestQueue.remove()); - } catch (NoSuchElementException e) { - log("requestsQueue empty"); - } - } - } else if (fileLookupRequest != null) { - boolean requestFinished; - try { - fileLookupRequest.handleResponse(characteristic); - requestFinished = fileLookupRequest.isFinished(); - } catch (RuntimeException e) { - e.printStackTrace(); - requestFinished = true; - } - - if (requestFinished) { - log("fileLookupRequest finished"); - fileLookupRequest = null; - try { - queueWrite(requestQueue.remove()); - } catch (NoSuchElementException e) { - log("requestsQueue empty"); - } - } - } else if (filePrepareRequest != null) { - boolean requestFinished; - try { - filePrepareRequest.handleResponse(characteristic); - requestFinished = filePrepareRequest.isFinished(); - } catch (RuntimeException e) { - e.printStackTrace(); - requestFinished = true; - } - - if (requestFinished) { - log("filePrepareRequest finished"); - filePrepareRequest = null; - try { - queueWrite(requestQueue.remove()); - } catch (NoSuchElementException e) { - log("requestsQueue empty"); - } - } - } else { - try { - queueWrite(requestQueue.remove()); - } catch (NoSuchElementException e) { - log("requestsQueue empty"); + log(fossilRequest.getName() + " finished"); + fossilRequest = null; + }else{ + return true; } } + try { + queueWrite(requestQueue.remove(requestQueue.size() - 1)); + } catch (ArrayIndexOutOfBoundsException e) { + log("requestsQueue empty"); + } } } return true; @@ -343,26 +276,29 @@ public class FossilWatchAdapter extends WatchAdapter { Log.d("FossilWatchAdapter", message); } - public void queueWrite(Request request) { + public void queueWrite(Request request){ + this.queueWrite(request, false); + } + + public void queueWrite(Request request, boolean priorise) { if (request.isBasicRequest()) { try { - queueWrite(requestQueue.remove()); - } catch (NoSuchElementException e) { + queueWrite(requestQueue.remove(requestQueue.size() - 1)); + } catch (ArrayIndexOutOfBoundsException e) { } } else { - if (filePutRequest != null || fileGetRequest != null || fileLookupRequest != null) { - Log.d("FossilWatchAdapter", "queing request: " + request.getName()); - requestQueue.add(request); + if (fossilRequest != null) { + Log.d("requestQueue", "queing request: " + request.getName()); + if(priorise){ + requestQueue.add(0, request); + }else { + requestQueue.add(request); + } return; } - log("executing request directly: " + request.getName()); + Log.d("requestQueue", "executing request: " + request.getName()); - if (request instanceof FilePutRequest) filePutRequest = (FilePutRequest) request; - else if (request instanceof FileGetRequest) fileGetRequest = (FileGetRequest) request; - else if (request instanceof FileLookupRequest) - fileLookupRequest = (FileLookupRequest) request; - else if (request instanceof FilePrepareRequest) - filePrepareRequest = (FilePrepareRequest) request; + if (request instanceof FossilRequest) this.fossilRequest = (FossilRequest) request; } new TransactionBuilder(request.getClass().getSimpleName()).write(getDeviceSupport().getCharacteristic(request.getRequestUUID()), request.getRequestData()).queue(getDeviceSupport().getQueue()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java index ccfb49fb1..c320352fd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java @@ -42,7 +42,9 @@ public abstract class Request { public void handleResponse(BluetoothGattCharacteristic characteristic){}; public String getName(){ - return this.getClass().getSimpleName(); + Class thisClass = getClass(); + while(thisClass.isAnonymousClass()) thisClass = thisClass.getSuperclass(); + return thisClass.getSimpleName(); } protected void log(String message){ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FossilRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FossilRequest.java new file mode 100644 index 000000000..a9a3d1cab --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FossilRequest.java @@ -0,0 +1,7 @@ +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; + +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request; + +public abstract class FossilRequest extends Request { + public abstract boolean isFinished(); +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/PrepareFilesRequestOrWhatever.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/PrepareFilesRequestOrWhatever.java deleted file mode 100644 index 48968cdba..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/PrepareFilesRequestOrWhatever.java +++ /dev/null @@ -1,24 +0,0 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; - -import android.bluetooth.BluetoothGattCharacteristic; - -import java.util.UUID; - -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request; - -public class PrepareFilesRequestOrWhatever extends Request { - @Override - public byte[] getStartSequence() { - return new byte[]{(byte) 0x09, (byte) 0xFF, (byte) 0xFF}; - } - - @Override - public void handleResponse(BluetoothGattCharacteristic characteristic) { - super.handleResponse(characteristic); - } - - @Override - public UUID getRequestUUID() { - return UUID.fromString("3dda0003-957f-7d4a-34a6-74696673696d"); - } -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/SendNotificationFilterRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/SendNotificationFilterRequest.java deleted file mode 100644 index 023cb84f1..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/SendNotificationFilterRequest.java +++ /dev/null @@ -1,67 +0,0 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; - -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; - -public class SendNotificationFilterRequest extends FilePutRequest { - public SendNotificationFilterRequest(FossilWatchAdapter adapter) { - super((short) 0x0C00, createFile(), adapter); - } - - private static byte[] createFile() { - return null; - /*ByteArrayOutputStream var3 = new ByteArrayOutputStream(); - byte var1 = NotificationEntryId.APP_BUNDLE_CRC32.getId$blesdk_productionRelease(); - byte[] var4 = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt((int)this.appBundleCrc).array(); - gwb.k(var4, "ByteBuffer.allocate(4)\n … .array()"); - var3.write(this.c(var1, var4)); - var3.write(this.c(NotificationEntryId.GROUP_ID.getId$blesdk_productionRelease(), new byte[]{this.groupId})); - boolean var2; - if (((CharSequence)this.sender).length() > 0) { - var2 = true; - } else { - var2 = false; - } - - if (var2) { - var1 = NotificationEntryId.SENDER_NAME.getId$blesdk_productionRelease(); - String var7 = bcf.da(this.sender); - Charset var5 = bdq.bqp.Qs(); - if (var7 == null) { - throw new TypeCastException("null cannot be cast to non-null type java.lang.String"); - } - - var4 = var7.getBytes(var5); - gwb.k(var4, "(this as java.lang.String).getBytes(charset)"); - var3.write(this.c(var1, var4)); - } - - if (this.priority != (short)-1) { - var3.write(this.c(NotificationEntryId.PRIORITY.getId$blesdk_productionRelease(), new byte[]{(byte)this.priority})); - } - - NotificationHandMovingConfig var8 = this.handMovingConfig; - if (var8 != null) { - var3.write(this.c(NotificationEntryId.HAND_MOVING.getId$blesdk_productionRelease(), var8.getData$blesdk_productionRelease())); - } - - NotificationVibePattern var9 = this.vibePattern; - if (var9 != null) { - var3.write(this.c(NotificationEntryId.VIBE.getId$blesdk_productionRelease(), new byte[]{var9.getId$blesdk_productionRelease()})); - } - - NotificationIconConfig var10 = this.iconConfig; - if (var10 != null) { - var3.write(this.c(NotificationEntryId.ICON_IMAGE.getId$blesdk_productionRelease(), var10.getNotificationFilterIconConfigData$blesdk_productionRelease())); - } - - byte[] var6 = var3.toByteArray(); - var6 = ByteBuffer.allocate(var6.length + 2).order(ByteOrder.LITTLE_ENDIAN).putShort((short)var6.length).put(var6).array(); - gwb.k(var6, "ByteBuffer\n …\n .array()"); - return var6;*/ - } -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/ConfigurationGetRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationGetRequest.java similarity index 91% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/ConfigurationGetRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationGetRequest.java index 89699773e..cd9382d8c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/ConfigurationGetRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationGetRequest.java @@ -1,9 +1,10 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; 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.requests.fossil.file.FileLookupAndGetRequest; public class ConfigurationGetRequest extends FileLookupAndGetRequest { public ConfigurationGetRequest(FossilWatchAdapter adapter) { @@ -11,7 +12,7 @@ public class ConfigurationGetRequest extends FileLookupAndGetRequest { } @Override - void handleFileData(byte[] fileData) { + public void handleFileData(byte[] fileData) { byte[] data = new byte[fileData.length - 12 - 4]; System.arraycopy(fileData, 12, data, 0, data.length); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/ConfigurationPutRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationPutRequest.java similarity index 98% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/ConfigurationPutRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationPutRequest.java index 131f0db1a..65b57aacd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/ConfigurationPutRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationPutRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration; import android.graphics.Bitmap; @@ -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.FilePutRequest; public class ConfigurationPutRequest extends FilePutRequest { private static HashMap> itemsById = new HashMap<>(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileGetRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileGetRequest.java similarity index 93% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileGetRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileGetRequest.java index 7de86cba8..89f9fed98 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileGetRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileGetRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file; import android.bluetooth.BluetoothGattCharacteristic; @@ -11,8 +11,9 @@ import java.util.zip.CRC32; 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.requests.Request; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest; -public abstract class FileGetRequest extends Request { +public abstract class FileGetRequest extends FossilRequest { private short handle; private FossilWatchAdapter adapter; @@ -38,6 +39,7 @@ public abstract class FileGetRequest extends Request { return adapter; } + @Override public boolean isFinished(){ return finished; } @@ -110,5 +112,5 @@ public abstract class FileGetRequest extends Request { return 11; } - abstract void handleFileData(byte[] fileData); + abstract public void handleFileData(byte[] fileData); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileLookupAndGetRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileLookupAndGetRequest.java similarity index 81% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileLookupAndGetRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileLookupAndGetRequest.java index 9b9d9e04e..a2121eaae 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileLookupAndGetRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileLookupAndGetRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; @@ -11,11 +11,11 @@ public abstract class FileLookupAndGetRequest extends FileLookupRequest { public void handleFileLookup(short fileHandle){ getAdapter().queueWrite(new FileGetRequest(getHandle(), getAdapter()) { @Override - void handleFileData(byte[] fileData) { + public void handleFileData(byte[] fileData) { FileLookupAndGetRequest.this.handleFileData(fileData); } }); } - abstract void handleFileData(byte[] fileData); + abstract public void handleFileData(byte[] fileData); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileLookupRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileLookupRequest.java similarity index 94% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileLookupRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileLookupRequest.java index 87aff56e0..3790084a7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FileLookupRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FileLookupRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file; import android.bluetooth.BluetoothGattCharacteristic; @@ -11,8 +11,9 @@ import java.util.zip.CRC32; 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.requests.Request; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest; -public class FileLookupRequest extends Request { +public class FileLookupRequest extends FossilRequest { private short handle = -1; private byte fileType; @@ -45,6 +46,7 @@ public class FileLookupRequest extends Request { return handle; } + @Override public boolean isFinished(){ return finished; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FilePrepareRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FilePrepareRequest.java similarity index 90% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FilePrepareRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FilePrepareRequest.java index ab25e0cee..ab0899e5c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FilePrepareRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FilePrepareRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file; import android.bluetooth.BluetoothGattCharacteristic; @@ -7,8 +7,9 @@ import java.nio.ByteOrder; 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 Request { +public class FilePrepareRequest extends FossilRequest { private boolean isFinished = false; private short handle; @@ -62,6 +63,7 @@ public class FilePrepareRequest extends Request { return 3; } + @Override public boolean isFinished(){ return this.isFinished; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FilePutRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FilePutRequest.java similarity index 86% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FilePutRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FilePutRequest.java index 044cde3b7..0f98fcb04 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/FilePutRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/file/FilePutRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file; import android.bluetooth.BluetoothGattCharacteristic; import android.widget.Toast; @@ -13,10 +13,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.CRC32C; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest; import nodomain.freeyourgadget.gadgetbridge.util.GB; -public class FilePutRequest extends Request { - public enum UploadState{INITIALIZED, UPLOADING, CLOSING, UPLOADED, ERROR} +public class FilePutRequest extends FossilRequest { + public enum UploadState{INITIALIZED, UPLOADING, CLOSING, UPLOADED} public UploadState state; @@ -59,9 +60,7 @@ public class FilePutRequest extends Request { switch (responseType) { case 3: { if (value.length != 5 || (value[0] & 0x0F) != 3) { - this.state = UploadState.ERROR; - log("wrong answer header"); - break; + throw new RuntimeException("wrong answer header"); } state = UploadState.UPLOADING; byte[] initialPacket = packets.get(0); @@ -84,15 +83,11 @@ public class FilePutRequest extends Request { byte status = value[3]; if (status != 0) { - this.state = UploadState.ERROR; - log("file error: " + status); - break; + throw new RuntimeException("upload status: " + status); } if (handle != this.handle) { - this.state = UploadState.ERROR; - log("wrong file handle"); - break; + throw new RuntimeException("wrong response handle"); } CRC32C realCrc = new CRC32C(); @@ -100,8 +95,8 @@ public class FilePutRequest extends Request { realCrc.update(data, 1, data.length - 1); if (crc != (int) realCrc.getValue()) { - this.state = UploadState.ERROR; - log("wrong crc"); + // this.state = UploadState.ERROR; + // log("wrong crc"); // TODO CRC // break; } @@ -138,9 +133,7 @@ public class FilePutRequest extends Request { case 4: { if (value.length == 9) return; if (value.length != 4 || (value[0] & 0x0F) != 4) { - this.state = UploadState.ERROR; - log("wrong closing header"); - break; + throw new RuntimeException("wrong file closing header"); } ByteBuffer buffer = ByteBuffer.wrap(value); buffer.order(ByteOrder.LITTLE_ENDIAN); @@ -148,21 +141,15 @@ public class FilePutRequest extends Request { short handle = buffer.getShort(1); if (handle != this.handle) { - this.state = UploadState.ERROR; - log("wrong file handle"); - onFilePut(false); - break; + throw new RuntimeException("wrong file closing handle"); } byte status = buffer.get(3); if (status != 0) { - this.state = UploadState.ERROR; - log("wrong closing handle"); - onFilePut(false); - break; + throw new RuntimeException("wrong closing status: " + status); } this.state = UploadState.UPLOADED; @@ -193,8 +180,9 @@ public class FilePutRequest extends Request { } } + @Override public boolean isFinished(){ - return this.state == UploadState.UPLOADED || this.state == UploadState.ERROR; + return this.state == UploadState.UPLOADED; } private void prepareFilePackets(byte[] file) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/NotificationFilterGetRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/NotificationFilterGetRequest.java similarity index 83% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/NotificationFilterGetRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/NotificationFilterGetRequest.java index c59e58b7c..0c9fb1405 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/NotificationFilterGetRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/NotificationFilterGetRequest.java @@ -1,12 +1,11 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; - -import android.util.Log; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification; import java.nio.ByteBuffer; import java.nio.ByteOrder; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.CRC32C; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest; public class NotificationFilterGetRequest extends FileGetRequest { public NotificationFilterGetRequest(FossilWatchAdapter adapter) { @@ -14,7 +13,7 @@ public class NotificationFilterGetRequest extends FileGetRequest { } @Override - void handleFileData(byte[] fileData) { + public void handleFileData(byte[] fileData) { log("handleFileData"); ByteBuffer buffer = ByteBuffer.wrap(fileData); buffer.order(ByteOrder.LITTLE_ENDIAN); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/NotificationFilterPutRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/NotificationFilterPutRequest.java similarity index 96% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/NotificationFilterPutRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/NotificationFilterPutRequest.java index 9de777d7f..25bf3fbbe 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/NotificationFilterPutRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/NotificationFilterPutRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -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.FilePutRequest; public class NotificationFilterPutRequest extends FilePutRequest { public NotificationFilterPutRequest(NotificationConfiguration[] configs, FossilWatchAdapter adapter) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/PlayNotificationRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayNotificationRequest.java similarity index 97% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/PlayNotificationRequest.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayNotificationRequest.java index 91d7c53d8..5dcacb333 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/PlayNotificationRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayNotificationRequest.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -6,6 +6,7 @@ import java.nio.charset.Charset; import java.util.zip.CRC32; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest; public class PlayNotificationRequest extends FilePutRequest {