huawei: Implement watchface managing 27 05

This commit is contained in:
Vitaliy Tomin 2024-04-04 21:47:46 +08:00
parent f027d95a33
commit 44a3f2a456
3 changed files with 74 additions and 0 deletions

View File

@ -70,4 +70,32 @@ public class Watchface {
}
public static class WatchfaceConfirm {
public static final byte id = 0x05;
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(0x7f, 0x000186A0);
this.commandId = id;
}
}
public static class Response extends HuaweiPacket {
public Response (ParamsProvider paramsProvider) {
super(paramsProvider);
}
}
}
}

View File

@ -49,6 +49,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.GpsAndTime;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Menstrual;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.MusicControl;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.FileUpload;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Watchface;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Weather;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.Request;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetPhoneInfoRequest;
@ -57,6 +58,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.Send
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendFileUploadAck;
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.SendWeatherDeviceRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SetMusicStatusRequest;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -106,6 +108,7 @@ public class AsynchronousResponse {
handleWeatherCheck(response);
handleGpsRequest(response);
handleFileUpload(response);
handleWatchface(response);
} catch (Request.ResponseParseException e) {
LOG.error("Response parse exception", e);
}
@ -436,6 +439,20 @@ public class AsynchronousResponse {
}
}
private void handleWatchface(HuaweiPacket response) throws Request.ResponseParseException {
if (response.serviceId == Watchface.id) {
if (response.commandId == Watchface.WatchfaceConfirm.id) {
try {
SendWatchfaceConfirm sendWatchfaceConfirm = new SendWatchfaceConfirm(this.support, support.huaweiUploadManager.getFileName());
sendWatchfaceConfirm.doPerform();
} catch (IOException e) {
LOG.error("Could not send watchface confirm request", e);
}
}
}
}
private void handleWeatherCheck(HuaweiPacket response) {
if (response.serviceId == Weather.id && response.commandId == 0x04) {
// Send back ok

View File

@ -0,0 +1,29 @@
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 SendWatchfaceConfirm extends Request {
private String fileName;
public SendWatchfaceConfirm(HuaweiSupportProvider support, String filename) {
super(support);
this.serviceId = Watchface.id;
this.commandId = Watchface.WatchfaceConfirm.id;
this.fileName = filename;
}
@Override
protected List<byte[]> createRequest() throws RequestCreationException {
try {
return new Watchface.WatchfaceConfirm.Request(this.paramsProvider, this.fileName ).serialize();
} catch (HuaweiPacket.CryptoException e) {
throw new RequestCreationException(e);
}
}
}