1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

[Huawei] Add SendExtendedAccountRequest

This commit is contained in:
Damien 'Psolyca' Gaignon 2024-03-11 23:14:57 +01:00
parent d1eb6ae740
commit d59b7c7bfa
No known key found for this signature in database
GPG Key ID: 9E9404E5D9E11843
5 changed files with 104 additions and 3 deletions

View File

@ -369,7 +369,21 @@ public class HuaweiCoordinator {
} }
public boolean supportsAccount() { public boolean supportsAccount() {
return supportsCommandForService(0x1A, 0x05) || supportsCommandForService(0x1A, 0x06); return supportsCommandForService(0x1A, 0x01);
}
public boolean supportsAccountJudgment() {
return supportsCommandForService(0x1A, 0x05);
}
public boolean supportsAccountSwitch() {
return supportsCommandForService(0x1A, 0x06);
}
public boolean supportsDiffAccountPairingOptimization() {
if (supportsExpandCapability())
return supportsExpandCapability(0xac);
return false;
} }
public boolean supportsMusic() { public boolean supportsMusic() {

View File

@ -520,6 +520,8 @@ public class HuaweiPacket {
switch(this.commandId) { switch(this.commandId) {
case AccountRelated.SendAccountToDevice.id: case AccountRelated.SendAccountToDevice.id:
return new AccountRelated.SendAccountToDevice.Response(paramsProvider).fromPacket(this); return new AccountRelated.SendAccountToDevice.Response(paramsProvider).fromPacket(this);
case AccountRelated.SendExtendedAccountToDevice.id:
return new AccountRelated.SendExtendedAccountToDevice.Response(paramsProvider).fromPacket(this);
default: default:
this.isEncrypted = this.attemptDecrypt(); // Helps with debugging this.isEncrypted = this.attemptDecrypt(); // Helps with debugging
return this; return this;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2024 Damien Gaignon /* Copyright (C) 2024 Damien Gaignon, Vitalii Tomin
This file is part of Gadgetbridge. This file is part of Gadgetbridge.
@ -45,4 +45,30 @@ public class AccountRelated {
} }
} }
} }
public static class SendExtendedAccountToDevice {
public static final byte id = 0x05;
public static class Request extends HuaweiPacket {
public Request (ParamsProvider paramsProvider, boolean accountPairingOptimization) {
super(paramsProvider);
this.serviceId = AccountRelated.id;
this.commandId = id;
this.tlv = new HuaweiTLV()
.put(0x01);
if (accountPairingOptimization) {
this.tlv.put(0x03, (byte)0x01);
}
this.complete = true;
}
}
public static class Response extends HuaweiPacket {
public Response (ParamsProvider paramsProvider) {
super(paramsProvider);
}
}
}
} }

View File

@ -78,6 +78,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetEventAlarmList; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetEventAlarmList;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetNotificationConstraintsRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetNotificationConstraintsRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetSmartAlarmList; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetSmartAlarmList;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendExtendedAccountRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendGpsAndTimeToDeviceRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendGpsAndTimeToDeviceRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendWeatherCurrentRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendWeatherCurrentRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendNotifyHeartRateCapabilityRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendNotifyHeartRateCapabilityRequest;
@ -595,10 +596,14 @@ public class HuaweiSupportProvider {
GetExpandCapabilityRequest expandCapabilityReq = new GetExpandCapabilityRequest(this); GetExpandCapabilityRequest expandCapabilityReq = new GetExpandCapabilityRequest(this);
expandCapabilityReq.doPerform(); expandCapabilityReq.doPerform();
} }
if (getHuaweiCoordinator().supportsAccount()) { // GetAccountJudgment if (getHuaweiCoordinator().supportsAccount()) {
SendAccountRequest sendAccountReq = new SendAccountRequest(this); SendAccountRequest sendAccountReq = new SendAccountRequest(this);
sendAccountReq.doPerform(); sendAccountReq.doPerform();
} }
if (getHuaweiCoordinator().supportsAccountJudgment() && getHuaweiCoordinator().supportsAccountSwitch()) {
SendExtendedAccountRequest sendExtendedAccountRequest = new SendExtendedAccountRequest(this);
sendExtendedAccountRequest.doPerform();
}
if (getHuaweiCoordinator().supportsActivityType()) { if (getHuaweiCoordinator().supportsActivityType()) {
GetActivityTypeRequest activityTypeReq = new GetActivityTypeRequest(this); GetActivityTypeRequest activityTypeReq = new GetActivityTypeRequest(this);
activityTypeReq.doPerform(); activityTypeReq.doPerform();

View File

@ -0,0 +1,54 @@
/* Copyright (C) 2024 Vitalii Tomin
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket.CryptoException;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.AccountRelated;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
public class SendExtendedAccountRequest extends Request {
private static final Logger LOG = LoggerFactory.getLogger(SendExtendedAccountRequest.class);
public SendExtendedAccountRequest(HuaweiSupportProvider support) {
super(support);
this.serviceId = AccountRelated.id;
this.commandId = AccountRelated.SendExtendedAccountToDevice.id;
}
@Override
protected List<byte[]> createRequest() throws Request.RequestCreationException {
try {
return new AccountRelated.SendExtendedAccountToDevice.Request(
paramsProvider,
supportProvider.getHuaweiCoordinator().supportsDiffAccountPairingOptimization())
.serialize();
} catch (CryptoException e) {
throw new Request.RequestCreationException(e);
}
}
@Override
protected void processResponse() throws Request.ResponseParseException {
LOG.debug("handle Send Extended Account to Device");
}
}