huawei: set watchface as current on upload complete

This commit is contained in:
Vitaliy Tomin 2024-04-05 00:21:13 +08:00
parent 44a3f2a456
commit c1f286e823
3 changed files with 61 additions and 2 deletions

View File

@ -70,6 +70,33 @@ public class Watchface {
}
public static class WatchfaceOperation {
public static final byte id = 0x03;
public static class Request extends HuaweiPacket {
public Request(ParamsProvider paramsProvider,
String fileName) {
super(paramsProvider);
this.serviceId = Watchface.id;
this.tlv = new HuaweiTLV()
.put(0x01, fileName.split("_")[0])
.put(0x02, fileName.split("_")[1])
.put(0x03, (byte) 0x01);
this.commandId = id;
}
}
public static class Response extends HuaweiPacket {
public Response (ParamsProvider paramsProvider) {
super(paramsProvider);
}
}
}
public static class WatchfaceConfirm {
public static final byte id = 0x05;
@ -94,7 +121,6 @@ public class Watchface {
}
}
}

View File

@ -59,6 +59,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.Send
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendFileUploadChunk;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendFileUploadHash;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendWatchfaceConfirm;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendWatchfaceOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendWeatherDeviceRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SetMusicStatusRequest;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -431,7 +432,10 @@ public class AsynchronousResponse {
} else if (response.commandId == FileUpload.FileUploadResult.id) {
try {
SendFileUploadComplete sendFileUploadComplete = new SendFileUploadComplete(this.support);
SendWatchfaceOperation sendWatchfaceOperation = new SendWatchfaceOperation(this.support, this.support.huaweiUploadManager.getFileName());
sendFileUploadComplete.doPerform();
sendWatchfaceOperation.doPerform();
} catch (IOException e) {
LOG.error("Could not send fileupload result request", e);
}
@ -443,8 +447,10 @@ public class AsynchronousResponse {
if (response.serviceId == Watchface.id) {
if (response.commandId == Watchface.WatchfaceConfirm.id) {
try {
SendWatchfaceConfirm sendWatchfaceConfirm = new SendWatchfaceConfirm(this.support, support.huaweiUploadManager.getFileName());
SendWatchfaceConfirm sendWatchfaceConfirm = new SendWatchfaceConfirm(this.support, this.support.huaweiUploadManager.getFileName());
sendWatchfaceConfirm.doPerform();
} catch (IOException e) {
LOG.error("Could not send watchface confirm request", e);
}

View File

@ -0,0 +1,27 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Watchface;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
public class SendWatchfaceOperation extends Request {
private String fileName;
public SendWatchfaceOperation(HuaweiSupportProvider support, String filename) {
super(support);
this.serviceId = Watchface.id;
this.commandId = Watchface.WatchfaceOperation.id;
this.fileName = filename;
}
@Override
protected List<byte[]> createRequest() throws RequestCreationException {
try {
return new Watchface.WatchfaceOperation.Request(this.paramsProvider, this.fileName ).serialize();
} catch (HuaweiPacket.CryptoException e) {
throw new RequestCreationException(e);
}
}
}