mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-09 03:37:03 +01:00
Huawei: Correct processing of set time command during the pairing process.
This commit is contained in:
parent
d6d956b748
commit
532c545093
@ -414,6 +414,8 @@ public class HuaweiPacket {
|
||||
return new DeviceConfig.SupportedServices.Response(paramsProvider).fromPacket(this);
|
||||
case DeviceConfig.SupportedCommands.id:
|
||||
return new DeviceConfig.SupportedCommands.Response(paramsProvider).fromPacket(this);
|
||||
case DeviceConfig.TimeRequest.id:
|
||||
return new DeviceConfig.TimeRequest.Response(paramsProvider).fromPacket(this);
|
||||
case DeviceConfig.ProductInfo.id:
|
||||
return new DeviceConfig.ProductInfo.Response(paramsProvider).fromPacket(this);
|
||||
case DeviceConfig.BondParams.id:
|
||||
|
@ -400,6 +400,19 @@ public class DeviceConfig {
|
||||
this(paramsProvider, Calendar.getInstance());
|
||||
}
|
||||
|
||||
public static class Response extends HuaweiPacket {
|
||||
public int deviceTime;
|
||||
|
||||
public Response(ParamsProvider paramsProvider) {
|
||||
super(paramsProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseTlv() throws ParseException {
|
||||
this.deviceTime = this.tlv.getInteger(0x01);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement parsing this request for the log parser support
|
||||
}
|
||||
|
||||
|
@ -550,7 +550,6 @@ public class HuaweiSupportProvider {
|
||||
editor.putString(DeviceSettingsPreferenceConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, "p_on");
|
||||
editor.apply();
|
||||
}
|
||||
onSetTime();
|
||||
getBatteryLevel();
|
||||
sendUserInfo();
|
||||
if (isBLE()) {
|
||||
@ -1363,7 +1362,7 @@ public class HuaweiSupportProvider {
|
||||
}
|
||||
|
||||
private Request setTime() {
|
||||
SetTimeRequest setTimeReq = new SetTimeRequest(this);
|
||||
SetTimeRequest setTimeReq = new SetTimeRequest(this, true);
|
||||
return setTimeReq;
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,13 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupport
|
||||
|
||||
public class SetTimeRequest extends Request {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SetTimeRequest.class);
|
||||
private boolean checkTime;
|
||||
|
||||
public SetTimeRequest(HuaweiSupportProvider support) {
|
||||
public SetTimeRequest(HuaweiSupportProvider support, boolean syncTime) {
|
||||
super(support);
|
||||
this.serviceId = DeviceConfig.id;
|
||||
this.commandId = DeviceConfig.TimeRequest.id;
|
||||
this.checkTime = syncTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,7 +46,19 @@ public class SetTimeRequest extends Request {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processResponse() {
|
||||
protected void processResponse() throws ResponseTypeMismatchException {
|
||||
LOG.debug("handle Set Time");
|
||||
if (!(receivedPacket instanceof DeviceConfig.TimeRequest.Response))
|
||||
throw new ResponseTypeMismatchException(receivedPacket, DeviceConfig.TimeRequest.Response.class);
|
||||
|
||||
int deviceTime = ((DeviceConfig.TimeRequest.Response) receivedPacket).deviceTime;
|
||||
int systemTime = (int) (System.currentTimeMillis() / 1000);
|
||||
int diff = Math.abs(systemTime - deviceTime);
|
||||
LOG.debug("systemTime: {} deviceTime: {} diff: {}",systemTime, deviceTime, diff);
|
||||
if (this.checkTime && diff > 0) {
|
||||
SetTimeRequest setTimeReq = new SetTimeRequest(supportProvider, false);
|
||||
setTimeReq.nextRequest(this.nextRequest);
|
||||
nextRequest(setTimeReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user