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.notification.NotificationFilterPutRequest;
|
||||
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.MoveHandsRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest;
|
||||
@ -459,6 +460,11 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
fossilRequest.handleResponse(characteristic);
|
||||
requestFinished = fossilRequest.isFinished();
|
||||
} catch (RuntimeException e) {
|
||||
if(fossilRequest instanceof VerifyPrivateKeyRequest){
|
||||
getDeviceSupport().getDevice().setState(GBDevice.State.AUTHENTICATION_REQUIRED);
|
||||
requestQueue.clear();
|
||||
}
|
||||
|
||||
GB.log("error", GB.ERROR, e);
|
||||
getDeviceSupport().notifiyException(fossilRequest.getName(), e);
|
||||
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 SetDeviceStateRequest(GBDevice.State.AUTHENTICATING));
|
||||
|
||||
negotiateSymmetricKey();
|
||||
|
||||
queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZING));
|
||||
|
||||
// icons
|
||||
|
||||
// queueWrite(new NotificationFilterPutHRRequest(new NotificationHRConfiguration[]{
|
||||
@ -94,10 +98,8 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
|
||||
overwriteButtons(null);
|
||||
|
||||
queueWrite(new FileDeleteRequest((short) 0x0700));
|
||||
|
||||
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
|
||||
|
||||
queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZED));
|
||||
@ -164,6 +166,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
}
|
||||
|
||||
|
||||
// queueWrite(new FileDeleteRequest((short) 0x0700));
|
||||
queueWrite(new AssetFilePutRequest(
|
||||
new AssetFile[]{widgetImages[0]},
|
||||
this
|
||||
@ -175,6 +178,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
|
||||
// widgetImages[1].setFileName(widgetImages[0].getFileName());
|
||||
|
||||
queueWrite(new FileDeleteRequest((short) 0x0503));
|
||||
queueWrite(new ImagesSetRequest(
|
||||
widgetImages,
|
||||
this
|
||||
|
@ -65,7 +65,8 @@ public class FileCloseRequest extends FossilRequest {
|
||||
|
||||
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;
|
||||
|
||||
|
@ -55,7 +55,8 @@ public class FileDeleteRequest extends FossilRequest {
|
||||
if(buffer.getShort(1) != this.handle) throw new RuntimeException("wrong response handle");
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -75,8 +75,9 @@ public abstract class FileGetRequest extends FossilRequest {
|
||||
|
||||
byte status = buffer.get(3);
|
||||
|
||||
if(status != 0){
|
||||
throw new RuntimeException("FileGet error: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
throw new RuntimeException("FileGet error: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
if(this.handle != handle){
|
||||
|
@ -82,8 +82,9 @@ public class FileLookupRequest extends FossilRequest {
|
||||
|
||||
byte status = buffer.get(3);
|
||||
|
||||
if(status != 0){
|
||||
throw new RuntimeException("file lookup error: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
throw new RuntimeException("file lookup error: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
if(this.handle != handle){
|
||||
|
@ -100,8 +100,9 @@ public class FilePutRequest extends FossilRequest {
|
||||
int crc = buffer.getInt(8);
|
||||
byte status = value[3];
|
||||
|
||||
if (status != 0) {
|
||||
throw new RuntimeException("upload status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
throw new RuntimeException("upload status: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
if (handle != this.handle) {
|
||||
@ -145,9 +146,10 @@ public class FilePutRequest extends FossilRequest {
|
||||
|
||||
byte status = buffer.get(3);
|
||||
|
||||
if (status != 0) {
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
onFilePut(false);
|
||||
throw new RuntimeException("wrong closing status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
throw new RuntimeException("wrong closing status: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
this.state = UploadState.UPLOADED;
|
||||
|
@ -65,7 +65,8 @@ public class FileVerifyRequest extends FossilRequest {
|
||||
|
||||
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;
|
||||
|
||||
|
@ -82,7 +82,9 @@ public class VerifyPrivateKeyRequest extends FossilRequest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} 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;
|
||||
|
@ -85,8 +85,9 @@ public abstract class FileEncryptedGetRequest extends FossilRequest {
|
||||
|
||||
byte status = buffer.get(3);
|
||||
|
||||
if(status != 0){
|
||||
throw new RuntimeException("FileGet error: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
throw new RuntimeException("FileGet error: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
if(this.handle != handle){
|
||||
|
@ -127,8 +127,9 @@ public class FileEncryptedPutRequest extends FossilRequest {
|
||||
int crc = buffer.getInt(8);
|
||||
byte status = value[3];
|
||||
|
||||
if (status != 0) {
|
||||
throw new RuntimeException("upload status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
throw new RuntimeException("upload status: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
if (handle != this.handle) {
|
||||
@ -172,9 +173,10 @@ public class FileEncryptedPutRequest extends FossilRequest {
|
||||
|
||||
byte status = buffer.get(3);
|
||||
|
||||
if (status != 0) {
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
onFilePut(false);
|
||||
throw new RuntimeException("wrong closing status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
throw new RuntimeException("wrong closing status: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
this.state = UploadState.UPLOADED;
|
||||
|
@ -86,8 +86,9 @@ public class FilePutRawRequest extends FossilRequest {
|
||||
int crc = buffer.getInt(8);
|
||||
byte status = value[3];
|
||||
|
||||
if (status != 0) {
|
||||
throw new RuntimeException("upload status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
throw new RuntimeException("upload status: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
if (handle != this.handle) {
|
||||
@ -131,9 +132,10 @@ public class FilePutRawRequest extends FossilRequest {
|
||||
|
||||
byte status = buffer.get(3);
|
||||
|
||||
if (status != 0) {
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
onFilePut(false);
|
||||
throw new RuntimeException("wrong closing status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
throw new RuntimeException("wrong closing status: " + code + " (" + status + ")");
|
||||
}
|
||||
|
||||
this.state = UploadState.UPLOADED;
|
||||
|
@ -1,38 +1,55 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public enum ResultCode {
|
||||
SUCCESS(0),
|
||||
INVALID_OPERATION_DATA(1),
|
||||
OPERATION_IN_PROGRESS(2),
|
||||
MISS_PACKET(3),
|
||||
SOCKET_BUSY(4),
|
||||
VERIFICATION_FAIL(5),
|
||||
OVERFLOW(6),
|
||||
SIZE_OVER_LIMIT(7),
|
||||
FIRMWARE_INTERNAL_ERROR(128),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_OPEN(129),
|
||||
FIRMWARE_INTERNAL_ERROR_ACCESS_ERROR(130),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_FOUND(131),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_VALID(132),
|
||||
FIRMWARE_INTERNAL_ERROR_ALREADY_CREATE(133),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_ENOUGH_MEMORY(134),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_IMPLEMENTED(135),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_SUPPORT(136),
|
||||
FIRMWARE_INTERNAL_ERROR_SOCKET_BUSY(137),
|
||||
FIRMWARE_INTERNAL_ERROR_SOCKET_ALREADY_OPEN(138),
|
||||
FIRMWARE_INTERNAL_ERROR_INPUT_DATA_INVALID(139),
|
||||
FIRMWARE_INTERNAL_NOT_AUTHENTICATE(140),
|
||||
FIRMWARE_INTERNAL_SIZE_OVER_LIMIT(141),
|
||||
UNKNOWN(-1);
|
||||
SUCCESS(0, true),
|
||||
INVALID_OPERATION_DATA(1, false),
|
||||
OPERATION_IN_PROGRESS(2, false),
|
||||
MISS_PACKET(3, false),
|
||||
SOCKET_BUSY(4, false),
|
||||
VERIFICATION_FAIL(5, false),
|
||||
OVERFLOW(6, false),
|
||||
SIZE_OVER_LIMIT(7, false),
|
||||
FIRMWARE_INTERNAL_ERROR(128, false),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_OPEN(129, false),
|
||||
FIRMWARE_INTERNAL_ERROR_ACCESS_ERROR(130, false),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_FOUND(131, false),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_VALID(132, false),
|
||||
FIRMWARE_INTERNAL_ERROR_ALREADY_CREATE(133, false),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_ENOUGH_MEMORY(134, false),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_IMPLEMENTED(135, false),
|
||||
FIRMWARE_INTERNAL_ERROR_NOT_SUPPORT(136, false),
|
||||
FIRMWARE_INTERNAL_ERROR_SOCKET_BUSY(137, false),
|
||||
FIRMWARE_INTERNAL_ERROR_SOCKET_ALREADY_OPEN(138, false),
|
||||
FIRMWARE_INTERNAL_ERROR_INPUT_DATA_INVALID(139, false),
|
||||
FIRMWARE_INTERNAL_NOT_AUTHENTICATE(140, false),
|
||||
FIRMWARE_INTERNAL_SIZE_OVER_LIMIT(141, false),
|
||||
UNKNOWN(-1, false),
|
||||
|
||||
// no clue what there one mean
|
||||
UNKNOWN_1(-125, true);
|
||||
|
||||
boolean success;
|
||||
int code;
|
||||
|
||||
ResultCode(int code) {
|
||||
private ResultCode(int code, boolean success){
|
||||
this.code = code;
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public boolean inidicatesSuccess(){
|
||||
return this.success;
|
||||
}
|
||||
|
||||
public static ResultCode fromCode(int code){
|
||||
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;
|
||||
}
|
||||
|
@ -70,8 +70,9 @@ public class DownloadFileRequest extends FileRequest {
|
||||
buffer1.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.status = buffer1.get(3);
|
||||
short realHandle = buffer1.getShort(1);
|
||||
if(status != 0){
|
||||
log("wrong status: " + ResultCode.fromCode(status) + " (" + status + ")");
|
||||
ResultCode code = ResultCode.fromCode(status);
|
||||
if(!code.inidicatesSuccess()){
|
||||
log("wrong status: " + code + " (" + status + ")");
|
||||
}else if(realHandle != fileHandle){
|
||||
log("wrong handle: " + realHandle);
|
||||
completed = true;
|
||||
|
Loading…
Reference in New Issue
Block a user