mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
adjusted response handling
This commit is contained in:
parent
98540fbdb6
commit
9e37f13821
@ -57,6 +57,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
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.NotificationFilterPutRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.AnimationRequest;
|
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.MoveHandsRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest;
|
||||||
@ -459,6 +460,11 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
fossilRequest.handleResponse(characteristic);
|
fossilRequest.handleResponse(characteristic);
|
||||||
requestFinished = fossilRequest.isFinished();
|
requestFinished = fossilRequest.isFinished();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
if(fossilRequest instanceof VerifyPrivateKeyRequest){
|
||||||
|
getDeviceSupport().getDevice().setState(GBDevice.State.AUTHENTICATION_REQUIRED);
|
||||||
|
requestQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
GB.log("error", GB.ERROR, e);
|
GB.log("error", GB.ERROR, e);
|
||||||
getDeviceSupport().notifiyException(fossilRequest.getName(), e);
|
getDeviceSupport().notifiyException(fossilRequest.getName(), e);
|
||||||
GB.toast(fossilRequest.getName() + " failed", Toast.LENGTH_SHORT, GB.ERROR);
|
GB.toast(fossilRequest.getName() + " failed", Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
@ -75,8 +75,12 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
|||||||
queueWrite(new RequestMtuRequest(512));
|
queueWrite(new RequestMtuRequest(512));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queueWrite(new SetDeviceStateRequest(GBDevice.State.AUTHENTICATING));
|
||||||
|
|
||||||
negotiateSymmetricKey();
|
negotiateSymmetricKey();
|
||||||
|
|
||||||
|
queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZING));
|
||||||
|
|
||||||
// icons
|
// icons
|
||||||
|
|
||||||
// queueWrite(new NotificationFilterPutHRRequest(new NotificationHRConfiguration[]{
|
// queueWrite(new NotificationFilterPutHRRequest(new NotificationHRConfiguration[]{
|
||||||
@ -94,10 +98,8 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
|||||||
|
|
||||||
overwriteButtons(null);
|
overwriteButtons(null);
|
||||||
|
|
||||||
queueWrite(new FileDeleteRequest((short) 0x0700));
|
|
||||||
|
|
||||||
loadWidgets();
|
loadWidgets();
|
||||||
renderWidgets();
|
// renderWidgets();
|
||||||
// dunno if there is any point in doing this at start since when no watch is connected the QHybridSupport will not receive any intents anyway
|
// dunno if there is any point in doing this at start since when no watch is connected the QHybridSupport will not receive any intents anyway
|
||||||
|
|
||||||
queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZED));
|
queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZED));
|
||||||
@ -164,6 +166,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// queueWrite(new FileDeleteRequest((short) 0x0700));
|
||||||
queueWrite(new AssetFilePutRequest(
|
queueWrite(new AssetFilePutRequest(
|
||||||
new AssetFile[]{widgetImages[0]},
|
new AssetFile[]{widgetImages[0]},
|
||||||
this
|
this
|
||||||
@ -175,6 +178,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
|||||||
|
|
||||||
// widgetImages[1].setFileName(widgetImages[0].getFileName());
|
// widgetImages[1].setFileName(widgetImages[0].getFileName());
|
||||||
|
|
||||||
|
queueWrite(new FileDeleteRequest((short) 0x0503));
|
||||||
queueWrite(new ImagesSetRequest(
|
queueWrite(new ImagesSetRequest(
|
||||||
widgetImages,
|
widgetImages,
|
||||||
this
|
this
|
||||||
|
@ -65,7 +65,8 @@ public class FileCloseRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if(status != 0) throw new RuntimeException("wrong response status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
|
if(!code.inidicatesSuccess()) throw new RuntimeException("wrong response status: " + code + " (" + status + ")");
|
||||||
|
|
||||||
this.isFinished = true;
|
this.isFinished = true;
|
||||||
|
|
||||||
|
@ -55,7 +55,8 @@ public class FileDeleteRequest extends FossilRequest {
|
|||||||
if(buffer.getShort(1) != this.handle) throw new RuntimeException("wrong response handle");
|
if(buffer.getShort(1) != this.handle) throw new RuntimeException("wrong response handle");
|
||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
if(status != 0) throw new RuntimeException("wrong response status: " + ResultCode.fromCode(status) + "(" + status + ")");
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
|
if(!code.inidicatesSuccess()) throw new RuntimeException("wrong response status: " + code + "(" + status + ")");
|
||||||
|
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,9 @@ public abstract class FileGetRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if(status != 0){
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
throw new RuntimeException("FileGet error: " + ResultCode.fromCode(status) + " (" + status + ")");
|
if(!code.inidicatesSuccess()){
|
||||||
|
throw new RuntimeException("FileGet error: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.handle != handle){
|
if(this.handle != handle){
|
||||||
|
@ -82,8 +82,9 @@ public class FileLookupRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if(status != 0){
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
throw new RuntimeException("file lookup error: " + ResultCode.fromCode(status) + " (" + status + ")");
|
if(!code.inidicatesSuccess()){
|
||||||
|
throw new RuntimeException("file lookup error: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.handle != handle){
|
if(this.handle != handle){
|
||||||
|
@ -100,8 +100,9 @@ public class FilePutRequest extends FossilRequest {
|
|||||||
int crc = buffer.getInt(8);
|
int crc = buffer.getInt(8);
|
||||||
byte status = value[3];
|
byte status = value[3];
|
||||||
|
|
||||||
if (status != 0) {
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
throw new RuntimeException("upload status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
if(!code.inidicatesSuccess()){
|
||||||
|
throw new RuntimeException("upload status: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle != this.handle) {
|
if (handle != this.handle) {
|
||||||
@ -145,9 +146,10 @@ public class FilePutRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if (status != 0) {
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
|
if(!code.inidicatesSuccess()){
|
||||||
onFilePut(false);
|
onFilePut(false);
|
||||||
throw new RuntimeException("wrong closing status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
throw new RuntimeException("wrong closing status: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = UploadState.UPLOADED;
|
this.state = UploadState.UPLOADED;
|
||||||
|
@ -65,7 +65,8 @@ public class FileVerifyRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if(status != 0) throw new RuntimeException("wrong response status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
|
if(!code.inidicatesSuccess()) throw new RuntimeException("wrong response status: " + code + " (" + status + ")");
|
||||||
|
|
||||||
this.isFinished = true;
|
this.isFinished = true;
|
||||||
|
|
||||||
|
@ -82,7 +82,9 @@ public class VerifyPrivateKeyRequest extends FossilRequest {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else if (value[1] == 2) {
|
} else if (value[1] == 2) {
|
||||||
if (value[2] != 0) throw new RuntimeException("Authentication error: " + ResultCode.fromCode(value[2]) + " (" + value[2] + ")");
|
ResultCode code = ResultCode.fromCode(value[2]);
|
||||||
|
|
||||||
|
if (!code.inidicatesSuccess()) throw new RuntimeException("Authentication error: " + code + " (" + value[2] + ")");
|
||||||
|
|
||||||
|
|
||||||
this.isFinished = true;
|
this.isFinished = true;
|
||||||
|
@ -85,8 +85,9 @@ public abstract class FileEncryptedGetRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if(status != 0){
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
throw new RuntimeException("FileGet error: " + ResultCode.fromCode(status) + " (" + status + ")");
|
if(!code.inidicatesSuccess()){
|
||||||
|
throw new RuntimeException("FileGet error: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.handle != handle){
|
if(this.handle != handle){
|
||||||
|
@ -127,8 +127,9 @@ public class FileEncryptedPutRequest extends FossilRequest {
|
|||||||
int crc = buffer.getInt(8);
|
int crc = buffer.getInt(8);
|
||||||
byte status = value[3];
|
byte status = value[3];
|
||||||
|
|
||||||
if (status != 0) {
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
throw new RuntimeException("upload status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
if(!code.inidicatesSuccess()){
|
||||||
|
throw new RuntimeException("upload status: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle != this.handle) {
|
if (handle != this.handle) {
|
||||||
@ -172,9 +173,10 @@ public class FileEncryptedPutRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if (status != 0) {
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
|
if(!code.inidicatesSuccess()){
|
||||||
onFilePut(false);
|
onFilePut(false);
|
||||||
throw new RuntimeException("wrong closing status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
throw new RuntimeException("wrong closing status: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = UploadState.UPLOADED;
|
this.state = UploadState.UPLOADED;
|
||||||
|
@ -86,8 +86,9 @@ public class FilePutRawRequest extends FossilRequest {
|
|||||||
int crc = buffer.getInt(8);
|
int crc = buffer.getInt(8);
|
||||||
byte status = value[3];
|
byte status = value[3];
|
||||||
|
|
||||||
if (status != 0) {
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
throw new RuntimeException("upload status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
if(!code.inidicatesSuccess()){
|
||||||
|
throw new RuntimeException("upload status: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle != this.handle) {
|
if (handle != this.handle) {
|
||||||
@ -131,9 +132,10 @@ public class FilePutRawRequest extends FossilRequest {
|
|||||||
|
|
||||||
byte status = buffer.get(3);
|
byte status = buffer.get(3);
|
||||||
|
|
||||||
if (status != 0) {
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
|
if(!code.inidicatesSuccess()){
|
||||||
onFilePut(false);
|
onFilePut(false);
|
||||||
throw new RuntimeException("wrong closing status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
throw new RuntimeException("wrong closing status: " + code + " (" + status + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = UploadState.UPLOADED;
|
this.state = UploadState.UPLOADED;
|
||||||
|
@ -1,38 +1,55 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
public enum ResultCode {
|
public enum ResultCode {
|
||||||
SUCCESS(0),
|
SUCCESS(0, true),
|
||||||
INVALID_OPERATION_DATA(1),
|
INVALID_OPERATION_DATA(1, false),
|
||||||
OPERATION_IN_PROGRESS(2),
|
OPERATION_IN_PROGRESS(2, false),
|
||||||
MISS_PACKET(3),
|
MISS_PACKET(3, false),
|
||||||
SOCKET_BUSY(4),
|
SOCKET_BUSY(4, false),
|
||||||
VERIFICATION_FAIL(5),
|
VERIFICATION_FAIL(5, false),
|
||||||
OVERFLOW(6),
|
OVERFLOW(6, false),
|
||||||
SIZE_OVER_LIMIT(7),
|
SIZE_OVER_LIMIT(7, false),
|
||||||
FIRMWARE_INTERNAL_ERROR(128),
|
FIRMWARE_INTERNAL_ERROR(128, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_NOT_OPEN(129),
|
FIRMWARE_INTERNAL_ERROR_NOT_OPEN(129, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_ACCESS_ERROR(130),
|
FIRMWARE_INTERNAL_ERROR_ACCESS_ERROR(130, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_NOT_FOUND(131),
|
FIRMWARE_INTERNAL_ERROR_NOT_FOUND(131, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_NOT_VALID(132),
|
FIRMWARE_INTERNAL_ERROR_NOT_VALID(132, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_ALREADY_CREATE(133),
|
FIRMWARE_INTERNAL_ERROR_ALREADY_CREATE(133, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_NOT_ENOUGH_MEMORY(134),
|
FIRMWARE_INTERNAL_ERROR_NOT_ENOUGH_MEMORY(134, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_NOT_IMPLEMENTED(135),
|
FIRMWARE_INTERNAL_ERROR_NOT_IMPLEMENTED(135, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_NOT_SUPPORT(136),
|
FIRMWARE_INTERNAL_ERROR_NOT_SUPPORT(136, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_SOCKET_BUSY(137),
|
FIRMWARE_INTERNAL_ERROR_SOCKET_BUSY(137, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_SOCKET_ALREADY_OPEN(138),
|
FIRMWARE_INTERNAL_ERROR_SOCKET_ALREADY_OPEN(138, false),
|
||||||
FIRMWARE_INTERNAL_ERROR_INPUT_DATA_INVALID(139),
|
FIRMWARE_INTERNAL_ERROR_INPUT_DATA_INVALID(139, false),
|
||||||
FIRMWARE_INTERNAL_NOT_AUTHENTICATE(140),
|
FIRMWARE_INTERNAL_NOT_AUTHENTICATE(140, false),
|
||||||
FIRMWARE_INTERNAL_SIZE_OVER_LIMIT(141),
|
FIRMWARE_INTERNAL_SIZE_OVER_LIMIT(141, false),
|
||||||
UNKNOWN(-1);
|
UNKNOWN(-1, false),
|
||||||
|
|
||||||
|
// no clue what there one mean
|
||||||
|
UNKNOWN_1(-125, true);
|
||||||
|
|
||||||
|
boolean success;
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
ResultCode(int code) {
|
private ResultCode(int code, boolean success){
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inidicatesSuccess(){
|
||||||
|
return this.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResultCode fromCode(int code){
|
public static ResultCode fromCode(int code){
|
||||||
for (ResultCode resultCode : ResultCode.values()){
|
for (ResultCode resultCode : ResultCode.values()){
|
||||||
if(resultCode.code == code) return resultCode;
|
if(resultCode.code == code) {
|
||||||
|
if(resultCode == UNKNOWN_1){
|
||||||
|
GB.log("dunno what code this is: " + code, GB.INFO, null);
|
||||||
|
}
|
||||||
|
return resultCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,9 @@ public class DownloadFileRequest extends FileRequest {
|
|||||||
buffer1.order(ByteOrder.LITTLE_ENDIAN);
|
buffer1.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
this.status = buffer1.get(3);
|
this.status = buffer1.get(3);
|
||||||
short realHandle = buffer1.getShort(1);
|
short realHandle = buffer1.getShort(1);
|
||||||
if(status != 0){
|
ResultCode code = ResultCode.fromCode(status);
|
||||||
log("wrong status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
if(!code.inidicatesSuccess()){
|
||||||
|
log("wrong status: " + code + " (" + status + ")");
|
||||||
}else if(realHandle != fileHandle){
|
}else if(realHandle != fileHandle){
|
||||||
log("wrong handle: " + realHandle);
|
log("wrong handle: " + realHandle);
|
||||||
completed = true;
|
completed = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user