mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Huawei: Chain initialize dynamic services requests
Also includes a bit of cleanup. Thanks to José Rebelo for cleaning my code.
This commit is contained in:
parent
098ab77cc6
commit
1315931ff8
@ -285,6 +285,7 @@ public class HuaweiCoordinator {
|
|||||||
public boolean supportsDoNotDisturb() {
|
public boolean supportsDoNotDisturb() {
|
||||||
return supportsCommandForService(0x01, 0x0a);
|
return supportsCommandForService(0x01, 0x0a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsDoNotDisturb(GBDevice gbDevice) {
|
public boolean supportsDoNotDisturb(GBDevice gbDevice) {
|
||||||
return supportsDoNotDisturb() || getForceOption(gbDevice, PREF_FORCE_DND_SUPPORT);
|
return supportsDoNotDisturb() || getForceOption(gbDevice, PREF_FORCE_DND_SUPPORT);
|
||||||
}
|
}
|
||||||
@ -296,6 +297,7 @@ public class HuaweiCoordinator {
|
|||||||
public boolean supportsWearLocation() {
|
public boolean supportsWearLocation() {
|
||||||
return supportsCommandForService(0x01, 0x1a);
|
return supportsCommandForService(0x01, 0x1a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsWearLocation(GBDevice gbDevice) {
|
public boolean supportsWearLocation(GBDevice gbDevice) {
|
||||||
return supportsWearLocation() || getForceOption(gbDevice, PREF_FORCE_ENABLE_WEAR_LOCATION);
|
return supportsWearLocation() || getForceOption(gbDevice, PREF_FORCE_ENABLE_WEAR_LOCATION);
|
||||||
}
|
}
|
||||||
|
@ -178,6 +178,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
|||||||
public class HuaweiSupportProvider {
|
public class HuaweiSupportProvider {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(HuaweiSupportProvider.class);
|
private static final Logger LOG = LoggerFactory.getLogger(HuaweiSupportProvider.class);
|
||||||
|
|
||||||
|
private final int initTimeout = 1000;
|
||||||
|
|
||||||
private HuaweiBRSupport brSupport;
|
private HuaweiBRSupport brSupport;
|
||||||
private HuaweiLESupport leSupport;
|
private HuaweiLESupport leSupport;
|
||||||
|
|
||||||
@ -546,26 +548,18 @@ public class HuaweiSupportProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void initializeDeviceConfigure() {
|
protected void initializeDeviceConfigure() {
|
||||||
nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder leBuilder = null;
|
|
||||||
nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder brBuilder = null;
|
|
||||||
if (isBLE()) {
|
if (isBLE()) {
|
||||||
leBuilder = createLeTransactionBuilder("Initializing");
|
nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder leBuilder = createLeTransactionBuilder("Initializing");
|
||||||
leBuilder.setCallback(leSupport);
|
leBuilder.setCallback(leSupport);
|
||||||
if (!GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean("force_new_protocol", false))
|
if (!GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean("force_new_protocol", false))
|
||||||
leBuilder.notify(leSupport.getCharacteristic(HuaweiConstants.UUID_CHARACTERISTIC_HUAWEI_READ), true);
|
leBuilder.notify(leSupport.getCharacteristic(HuaweiConstants.UUID_CHARACTERISTIC_HUAWEI_READ), true);
|
||||||
leBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction(gbDevice, GBDevice.State.INITIALIZING, context));
|
leBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction(gbDevice, GBDevice.State.INITIALIZING, context));
|
||||||
} else {
|
} else {
|
||||||
brBuilder = createBrTransactionBuilder("Initializing");
|
nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder brBuilder = createBrTransactionBuilder("Initializing");
|
||||||
brBuilder.setCallback(brSupport);
|
brBuilder.setCallback(brSupport);
|
||||||
brBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetDeviceStateAction(gbDevice, GBDevice.State.INITIALIZING, context));
|
brBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetDeviceStateAction(gbDevice, GBDevice.State.INITIALIZING, context));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
GetProductInformationRequest productInformationReq = new GetProductInformationRequest(this);
|
|
||||||
Request setTimeReq = setTime();
|
|
||||||
GetSupportedServicesRequest supportedServicesReq = new GetSupportedServicesRequest(this);
|
|
||||||
productInformationReq.nextRequest(setTimeReq);
|
|
||||||
setTimeReq.nextRequest(supportedServicesReq);
|
|
||||||
productInformationReq.doPerform();
|
|
||||||
if (firstConnection) {
|
if (firstConnection) {
|
||||||
// Workaround to enable PREF_HUAWEI_ROTATE_WRIST_TO_SWITCH_INFO preference
|
// Workaround to enable PREF_HUAWEI_ROTATE_WRIST_TO_SWITCH_INFO preference
|
||||||
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceMac);
|
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceMac);
|
||||||
@ -573,17 +567,33 @@ public class HuaweiSupportProvider {
|
|||||||
editor.putString(DeviceSettingsPreferenceConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, "p_on");
|
editor.putString(DeviceSettingsPreferenceConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, "p_on");
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
getBatteryLevel();
|
|
||||||
sendUserInfo();
|
stopBatteryRunnerDelayed();
|
||||||
if (isBLE()) {
|
GetBatteryLevelRequest batteryLevelReq = new GetBatteryLevelRequest(this);
|
||||||
assert leBuilder != null;
|
batteryLevelReq.setFinalizeReq(new RequestCallback() {
|
||||||
leBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction(gbDevice, GBDevice.State.INITIALIZED, context));
|
@Override
|
||||||
leSupport.performConnected(leBuilder.getTransaction());
|
public void timeout(Request request) {
|
||||||
} else {
|
request.handleNext();
|
||||||
assert brBuilder != null;
|
// Start the battery runner again so it keeps running even if the timeout is hit
|
||||||
brBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetDeviceStateAction(gbDevice, GBDevice.State.INITIALIZED, context));
|
startBatteryRunnerDelayed();
|
||||||
brSupport.performConnected(brBuilder.getTransaction());
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<Request> initRequestQueue = new ArrayList<>();
|
||||||
|
initRequestQueue.add(new GetProductInformationRequest(this));
|
||||||
|
initRequestQueue.add(new SetTimeRequest(this, true));
|
||||||
|
initRequestQueue.add(batteryLevelReq);
|
||||||
|
initRequestQueue.add(new SendFitnessUserInfoRequest(this));
|
||||||
|
initRequestQueue.add(new GetSupportedServicesRequest(this)); // MUST BE LAST - it indirectly kicks off initializeDynamicServices
|
||||||
|
|
||||||
|
// Queue all the requests
|
||||||
|
for (int i = 1; i < initRequestQueue.size(); i++) {
|
||||||
|
initRequestQueue.get(i - 1).setupTimeoutUntilNext(initTimeout);
|
||||||
|
initRequestQueue.get(i - 1).nextRequest(initRequestQueue.get(i));
|
||||||
|
}
|
||||||
|
initRequestQueue.get(initRequestQueue.size() - 1).setupTimeoutUntilNext(initTimeout);
|
||||||
|
|
||||||
|
initRequestQueue.get(0).doPerform();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: Use translatable string
|
// TODO: Use translatable string
|
||||||
GB.toast(context, "Final initialization of Huawei device failed", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast(context, "Final initialization of Huawei device failed", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
@ -694,178 +704,70 @@ public class HuaweiSupportProvider {
|
|||||||
* To be called after the commandsPerService is filled in the coordinator
|
* To be called after the commandsPerService is filled in the coordinator
|
||||||
*/
|
*/
|
||||||
public void initializeDynamicServices() {
|
public void initializeDynamicServices() {
|
||||||
|
try {
|
||||||
|
// All of the below check that they are supported and otherwise they skip themselves
|
||||||
|
final List<Request> initRequestQueue = new ArrayList<>();
|
||||||
|
initRequestQueue.add(new GetExpandCapabilityRequest(this));
|
||||||
|
initRequestQueue.add(new SendExtendedAccountRequest(this));
|
||||||
|
initRequestQueue.add(new GetSettingRelatedRequest(this));
|
||||||
|
initRequestQueue.add(new AcceptAgreementsRequest(this));
|
||||||
|
initRequestQueue.add(new GetActivityTypeRequest(this));
|
||||||
|
initRequestQueue.add(new GetConnectStatusRequest(this));
|
||||||
|
initRequestQueue.add(new GetDndLiftWristTypeRequest(this));
|
||||||
|
initRequestQueue.add(new SendDndDeleteRequest(this));
|
||||||
|
initRequestQueue.add(new SendDndAddRequest(this));
|
||||||
|
initRequestQueue.add(new SendSetUpDeviceStatusRequest(this));
|
||||||
|
initRequestQueue.add(new GetWearStatusRequest(this));
|
||||||
|
initRequestQueue.add(new SendMenstrualCapabilityRequest(this));
|
||||||
|
initRequestQueue.add(new SendNotifyHeartRateCapabilityRequest(this));
|
||||||
|
initRequestQueue.add(new SendNotifyRestHeartRateCapabilityRequest(this));
|
||||||
|
initRequestQueue.add(new SetMediumToStrengthThresholdRequest(this));
|
||||||
|
initRequestQueue.add(new SendFitnessGoalRequest(this));
|
||||||
|
initRequestQueue.add(new GetNotificationCapabilitiesRequest(this));
|
||||||
|
initRequestQueue.add(new GetNotificationConstraintsRequest(this));
|
||||||
|
initRequestQueue.add(new GetWatchfaceParams(this));
|
||||||
|
initRequestQueue.add(new SendCameraRemoteSetupEvent(this, CameraRemote.CameraRemoteSetup.Request.Event.ENABLE_CAMERA));
|
||||||
|
initRequestQueue.add(new GetAppInfoParams(this));
|
||||||
|
initRequestQueue.add(new SetActivateOnLiftRequest(this));
|
||||||
|
initRequestQueue.add(new SetWearLocationRequest(this));
|
||||||
|
initRequestQueue.add(new SetNavigateOnRotateRequest(this));
|
||||||
|
initRequestQueue.add(new SetNotificationRequest(this));
|
||||||
|
initRequestQueue.add(new SetWearMessagePushRequest(this));
|
||||||
|
initRequestQueue.add(new SetTimeZoneIdRequest(this));
|
||||||
|
initRequestQueue.add(new SetLanguageSettingRequest(this));
|
||||||
|
initRequestQueue.add(new SetDateFormatRequest(this));
|
||||||
|
initRequestQueue.add(new SetActivityReminderRequest(this));
|
||||||
|
initRequestQueue.add(new SetTruSleepRequest(this));
|
||||||
|
initRequestQueue.add(new GetContactsCount(this));
|
||||||
|
initRequestQueue.add(new GetEventAlarmList(this));
|
||||||
|
initRequestQueue.add(new GetSmartAlarmList(this));
|
||||||
|
|
||||||
// Setup the alarms
|
// Setup the alarms if necessary
|
||||||
if (!getHuaweiCoordinator().supportsChangingAlarm()) {
|
if (!getHuaweiCoordinator().supportsChangingAlarm() && firstConnection)
|
||||||
if (firstConnection) {
|
|
||||||
// TODO: not really sure if this is necessary, but it probably won't do any harm
|
|
||||||
initializeAlarms();
|
initializeAlarms();
|
||||||
}
|
|
||||||
} else {
|
// Queue all the requests
|
||||||
getAlarms();
|
for (int i = 1; i < initRequestQueue.size(); i++) {
|
||||||
}
|
initRequestQueue.get(i - 1).setupTimeoutUntilNext(initTimeout);
|
||||||
try {
|
initRequestQueue.get(i - 1).nextRequest(initRequestQueue.get(i));
|
||||||
if (getHuaweiCoordinator().supportsExpandCapability()) {
|
|
||||||
GetExpandCapabilityRequest expandCapabilityReq = new GetExpandCapabilityRequest(this);
|
|
||||||
expandCapabilityReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsAccountJudgment() && getHuaweiCoordinator().supportsAccountSwitch()) {
|
|
||||||
SendExtendedAccountRequest sendExtendedAccountRequest = new SendExtendedAccountRequest(this);
|
|
||||||
sendExtendedAccountRequest.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsSettingRelated()) { // GetSettingRelated
|
|
||||||
GetSettingRelatedRequest getSettingRelatedReq = new GetSettingRelatedRequest(this);
|
|
||||||
getSettingRelatedReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsAcceptAgreement()) {
|
|
||||||
AcceptAgreementsRequest acceptAgreementsRequest = new AcceptAgreementsRequest(this);
|
|
||||||
acceptAgreementsRequest.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsActivityType()) {
|
|
||||||
GetActivityTypeRequest activityTypeReq = new GetActivityTypeRequest(this);
|
|
||||||
activityTypeReq.doPerform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getHuaweiCoordinator().supportsConnectStatus()) {
|
initRequestQueue.get(initRequestQueue.size() - 1).setupTimeoutUntilNext(initTimeout);
|
||||||
GetConnectStatusRequest getConnectStatusReq = new GetConnectStatusRequest(this);
|
initRequestQueue.get(initRequestQueue.size() - 1).setFinalizeReq(new RequestCallback() {
|
||||||
getConnectStatusReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsActivateOnLift()) {
|
|
||||||
setActivateOnLift();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsWearLocation(getDevice())) {
|
|
||||||
setWearLocation();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsRotateToCycleInfo()) {
|
|
||||||
setNavigateOnRotate();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsQueryDndLiftWristDisturbType()) {
|
|
||||||
GetDndLiftWristTypeRequest getDndLiftWristTypeReq = new GetDndLiftWristTypeRequest(this);
|
|
||||||
getDndLiftWristTypeReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsDoNotDisturb(gbDevice)) {
|
|
||||||
SendDndDeleteRequest sendDndDeleteReq = new SendDndDeleteRequest(this);
|
|
||||||
SendDndAddRequest sendDndAddReq = new SendDndAddRequest(this);
|
|
||||||
sendDndDeleteReq.nextRequest(sendDndAddReq);
|
|
||||||
sendDndDeleteReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsNotification()) { // 0x02 - 0x04
|
|
||||||
setNotificationStatus();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsDoNotDisturb(gbDevice) && getHuaweiCoordinator().supportsWearMessagePush()) {
|
|
||||||
setDndNotWear();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsTimeAndZoneId()) {
|
|
||||||
setTimeZoneId();
|
|
||||||
}
|
|
||||||
// Nothing usefull yet with this requests
|
|
||||||
if (getHuaweiCoordinator().supportsMultiDevice()) {
|
|
||||||
SendSetUpDeviceStatusRequest sendSetUpDeviceStatusReq = new SendSetUpDeviceStatusRequest(this);
|
|
||||||
sendSetUpDeviceStatusReq.doPerform();
|
|
||||||
GetWearStatusRequest getWearStatusReq = new GetWearStatusRequest(this);
|
|
||||||
getWearStatusReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsMenstrual()) {
|
|
||||||
SendMenstrualCapabilityRequest sendMenstrualCapabilityReq = new SendMenstrualCapabilityRequest(this);
|
|
||||||
sendMenstrualCapabilityReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsLanguageSetting()) { // 0x0c - 0x01
|
|
||||||
setLanguageSetting();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsWorkoutsTrustHeartRate()) {
|
|
||||||
SendNotifyHeartRateCapabilityRequest sendNotifyHeartRateCapabilityReq = new SendNotifyHeartRateCapabilityRequest(this);
|
|
||||||
sendNotifyHeartRateCapabilityReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsFitnessRestHeartRate()) {
|
|
||||||
SendNotifyRestHeartRateCapabilityRequest sendNotifyRestHeartRateCapabilityReq = new SendNotifyRestHeartRateCapabilityRequest(this);
|
|
||||||
sendNotifyRestHeartRateCapabilityReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsFitnessThresholdValue()) {
|
|
||||||
SetMediumToStrengthThresholdRequest setMediumToStrengthThresholdReq = new SetMediumToStrengthThresholdRequest(this);
|
|
||||||
setMediumToStrengthThresholdReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsDateFormat()) { //0x01 - 0x04
|
|
||||||
setDateFormat();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsMotionGoal()) {
|
|
||||||
SendFitnessGoalRequest sendFitnessGoalReq = new SendFitnessGoalRequest(this);
|
|
||||||
sendFitnessGoalReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsActivityReminder()) {
|
|
||||||
setActivityReminder();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getHuaweiCoordinator().supportsTruSleep()) {
|
|
||||||
setTrusleep();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsPromptPushMessage() && getProtocolVersion() == 2) {
|
|
||||||
GetNotificationCapabilitiesRequest getNotificationCapabilitiesReq = new GetNotificationCapabilitiesRequest(this);
|
|
||||||
getNotificationCapabilitiesReq.doPerform();
|
|
||||||
}
|
|
||||||
if (getHuaweiCoordinator().supportsNotificationAlert() && getProtocolVersion() == 2) {
|
|
||||||
GetNotificationConstraintsRequest getNotificationConstraintsReq = new GetNotificationConstraintsRequest(this);
|
|
||||||
getNotificationConstraintsReq.doPerform();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getHuaweiCoordinator().supportsCameraRemote() && GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_CAMERA_REMOTE, false)) {
|
|
||||||
SendCameraRemoteSetupEvent sendCameraRemoteSetupEvent = new SendCameraRemoteSetupEvent(this, CameraRemote.CameraRemoteSetup.Request.Event.ENABLE_CAMERA);
|
|
||||||
sendCameraRemoteSetupEvent.doPerform();
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Limit number of simultaneous commands
|
|
||||||
// Huawei watch, for example the Watch GT4 has limited buffer for incoming commands.
|
|
||||||
// So sending a lot of command broke connection or cause that watch does not answer to requests.
|
|
||||||
// To avoid this issue I perform some commands in the chain, but we should limit number of simultaneous commands
|
|
||||||
|
|
||||||
RequestCallback contactsCallback = new RequestCallback() {
|
|
||||||
@Override
|
@Override
|
||||||
public void call() {
|
public void call() {
|
||||||
if (getHuaweiCoordinator().supportsContacts()) {
|
gbDevice.setState(GBDevice.State.INITIALIZED);
|
||||||
GetContactsCount getContactsCount = new GetContactsCount(HuaweiSupportProvider.this);
|
gbDevice.sendDeviceUpdateIntent(getContext(), GBDevice.DeviceUpdateSubject.DEVICE_STATE);
|
||||||
try {
|
}
|
||||||
getContactsCount.doPerform();
|
});
|
||||||
|
|
||||||
|
initRequestQueue.get(0).doPerform();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Error perform contacts count request", e);
|
// TODO: Translatable string
|
||||||
|
GB.toast("Initialize dynamic services of Huawei device failed", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
|
LOG.error("Initializing dynamic services failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
RequestCallback appsCallback= new RequestCallback() {
|
|
||||||
@Override
|
|
||||||
public void call() {
|
|
||||||
if (getHuaweiCoordinator().supportsAppParams()) {
|
|
||||||
GetAppInfoParams getAppInfoParams = new GetAppInfoParams(HuaweiSupportProvider.this);
|
|
||||||
getAppInfoParams.setFinalizeReq(contactsCallback);
|
|
||||||
try {
|
|
||||||
getAppInfoParams.doPerform();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.error("Error perform app info request", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contactsCallback.call();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (getHuaweiCoordinator().supportsWatchfaceParams()) {
|
|
||||||
GetWatchfaceParams getWatchfaceParams = new GetWatchfaceParams(this);
|
|
||||||
getWatchfaceParams.setFinalizeReq(appsCallback);
|
|
||||||
getWatchfaceParams.doPerform();
|
|
||||||
} else {
|
|
||||||
appsCallback.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
GB.toast(getContext(), "Initialize dynamic services of Huawei device failed", Toast.LENGTH_SHORT, GB.ERROR,
|
|
||||||
e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Properly update the device card
|
|
||||||
gbDevice.sendDeviceUpdateIntent(GBApplication.getContext());
|
|
||||||
GB.signalActivityDataFinish(getDevice());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProtocolVersion(byte protocolVersion) {
|
public void setProtocolVersion(byte protocolVersion) {
|
||||||
this.protocolVersion = protocolVersion;
|
this.protocolVersion = protocolVersion;
|
||||||
@ -917,7 +819,6 @@ public class HuaweiSupportProvider {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
GetEventAlarmList getEventAlarmList = new GetEventAlarmList(this);
|
GetEventAlarmList getEventAlarmList = new GetEventAlarmList(this);
|
||||||
responseManager.addHandler(getEventAlarmList);
|
|
||||||
getEventAlarmList.setFinalizeReq(new RequestCallback() {
|
getEventAlarmList.setFinalizeReq(new RequestCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void call() {
|
public void call() {
|
||||||
@ -925,7 +826,6 @@ public class HuaweiSupportProvider {
|
|||||||
return; // Don't get smart alarms when not supported
|
return; // Don't get smart alarms when not supported
|
||||||
|
|
||||||
GetSmartAlarmList getSmartAlarmList = new GetSmartAlarmList(HuaweiSupportProvider.this);
|
GetSmartAlarmList getSmartAlarmList = new GetSmartAlarmList(HuaweiSupportProvider.this);
|
||||||
responseManager.addHandler(getSmartAlarmList);
|
|
||||||
try {
|
try {
|
||||||
getSmartAlarmList.doPerform();
|
getSmartAlarmList.doPerform();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -1401,7 +1301,7 @@ public class HuaweiSupportProvider {
|
|||||||
|
|
||||||
public void onSetTime() {
|
public void onSetTime() {
|
||||||
try {
|
try {
|
||||||
setTime().doPerform();
|
new SetTimeRequest(this, true).doPerform();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: Use translatable string
|
// TODO: Use translatable string
|
||||||
GB.toast(context, "Failed to configure time", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast(context, "Failed to configure time", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
@ -1409,21 +1309,6 @@ public class HuaweiSupportProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Request setTime() {
|
|
||||||
SetTimeRequest setTimeReq = new SetTimeRequest(this, true);
|
|
||||||
return setTimeReq;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeZoneId() {
|
|
||||||
try {
|
|
||||||
SetTimeZoneIdRequest setTimeZoneIdReq = new SetTimeZoneIdRequest(this);
|
|
||||||
setTimeZoneIdReq.doPerform();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO: Use translatable string
|
|
||||||
GB.toast(context, "Failed to configure time and zoneId", Toast.LENGTH_SHORT, GB.ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSetAlarms(ArrayList<? extends nodomain.freeyourgadget.gadgetbridge.model.Alarm> alarms) {
|
public void onSetAlarms(ArrayList<? extends nodomain.freeyourgadget.gadgetbridge.model.Alarm> alarms) {
|
||||||
boolean smartAlarmEnabled = getHuaweiCoordinator().supportsSmartAlarm(getDevice());
|
boolean smartAlarmEnabled = getHuaweiCoordinator().supportsSmartAlarm(getDevice());
|
||||||
|
|
||||||
@ -1727,7 +1612,6 @@ public class HuaweiSupportProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setActivateOnLift() {
|
public void setActivateOnLift() {
|
||||||
try {
|
try {
|
||||||
SetActivateOnLiftRequest setActivateOnLiftReq = new SetActivateOnLiftRequest(this);
|
SetActivateOnLiftRequest setActivateOnLiftReq = new SetActivateOnLiftRequest(this);
|
||||||
|
@ -16,25 +16,18 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
||||||
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig.AcceptAgreement;
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Alarms.SmartAlarmRequest;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Alarms;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
||||||
|
|
||||||
public class AcceptAgreementsRequest extends Request {
|
public class AcceptAgreementsRequest extends Request {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AcceptAgreementsRequest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AcceptAgreementsRequest.class);
|
||||||
|
|
||||||
|
|
||||||
public AcceptAgreementsRequest(HuaweiSupportProvider support) {
|
public AcceptAgreementsRequest(HuaweiSupportProvider support) {
|
||||||
super(support);
|
super(support);
|
||||||
|
|
||||||
@ -42,6 +35,12 @@ public class AcceptAgreementsRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.AcceptAgreement.id;
|
this.commandId = DeviceConfig.AcceptAgreement.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsAcceptAgreement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
return new DeviceConfig.AcceptAgreement.Request(paramsProvider).serialize();
|
return new DeviceConfig.AcceptAgreement.Request(paramsProvider).serialize();
|
||||||
|
@ -27,7 +27,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
||||||
@ -41,6 +40,11 @@ public class GetActivityTypeRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.ActivityType.id;
|
this.commandId = DeviceConfig.ActivityType.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsActivityType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
DeviceConfig.ActivityType.Request activityRequest = new DeviceConfig.ActivityType.Request(paramsProvider);
|
DeviceConfig.ActivityType.Request activityRequest = new DeviceConfig.ActivityType.Request(paramsProvider);
|
||||||
|
@ -15,6 +15,11 @@ public class GetAppInfoParams extends Request{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsAppParams();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket.CryptoException;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket.CryptoException;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
||||||
@ -35,6 +34,11 @@ public class GetConnectStatusRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.ConnectStatusRequest.id;
|
this.commandId = DeviceConfig.ConnectStatusRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsConnectStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -18,6 +18,11 @@ public class GetContactsCount extends Request {
|
|||||||
this.commandId = Contacts.ContactsCount.id;
|
this.commandId = Contacts.ContactsCount.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsContacts();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -38,6 +38,11 @@ public class GetDndLiftWristTypeRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.DndLiftWristType.id;
|
this.commandId = DeviceConfig.DndLiftWristType.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsQueryDndLiftWristDisturbType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -33,6 +33,11 @@ public class GetEventAlarmList extends Request {
|
|||||||
this.commandId = Alarms.EventAlarmsList.id;
|
this.commandId = Alarms.EventAlarmsList.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsChangingAlarm();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -40,6 +40,11 @@ public class GetExpandCapabilityRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.ExpandCapability.id;
|
this.commandId = DeviceConfig.ExpandCapability.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsExpandCapability();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
DeviceConfig.ExpandCapability.Request expandRequest = new DeviceConfig.ExpandCapability.Request(paramsProvider);
|
DeviceConfig.ExpandCapability.Request expandRequest = new DeviceConfig.ExpandCapability.Request(paramsProvider);
|
||||||
|
@ -35,6 +35,11 @@ public class GetNotificationCapabilitiesRequest extends Request {
|
|||||||
this.commandId = NotificationCapabilities.id;
|
this.commandId = NotificationCapabilities.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsPromptPushMessage() && supportProvider.getProtocolVersion() == 2;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -35,6 +35,11 @@ public class GetNotificationConstraintsRequest extends Request {
|
|||||||
this.commandId = NotificationConstraints.id;
|
this.commandId = NotificationConstraints.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsNotificationAlert() && supportProvider.getProtocolVersion() == 2;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket.CryptoException;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket.CryptoException;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.DeviceConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
||||||
@ -35,6 +34,11 @@ public class GetSettingRelatedRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.SettingRelated.id;
|
this.commandId = DeviceConfig.SettingRelated.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsSettingRelated();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -16,10 +16,6 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
||||||
@ -28,7 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.entities.Alarm;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
||||||
|
|
||||||
public class GetSmartAlarmList extends Request {
|
public class GetSmartAlarmList extends Request {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GetSmartAlarmList.class);
|
|
||||||
|
|
||||||
public GetSmartAlarmList(HuaweiSupportProvider support) {
|
public GetSmartAlarmList(HuaweiSupportProvider support) {
|
||||||
super(support);
|
super(support);
|
||||||
@ -37,6 +32,12 @@ public class GetSmartAlarmList extends Request {
|
|||||||
this.commandId = Alarms.SmartAlarmList.id;
|
this.commandId = Alarms.SmartAlarmList.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsChangingAlarm() &&
|
||||||
|
supportProvider.getHuaweiCoordinator().supportsSmartAlarm(supportProvider.getDevice());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
|
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
||||||
@ -28,8 +25,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupport
|
|||||||
|
|
||||||
public class GetWatchfaceParams extends Request{
|
public class GetWatchfaceParams extends Request{
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GetWatchfaceParams.class);
|
|
||||||
|
|
||||||
public GetWatchfaceParams(HuaweiSupportProvider support) {
|
public GetWatchfaceParams(HuaweiSupportProvider support) {
|
||||||
super(support);
|
super(support);
|
||||||
this.serviceId = Watchface.id;
|
this.serviceId = Watchface.id;
|
||||||
@ -37,6 +32,11 @@ public class GetWatchfaceParams extends Request{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsWatchfaceParams();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -35,6 +35,11 @@ public class GetWearStatusRequest extends Request {
|
|||||||
this.commandId = WearStatus.id;
|
this.commandId = WearStatus.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsMultiDevice();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -18,6 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
|||||||
|
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -109,6 +111,10 @@ public class Request {
|
|||||||
protected HuaweiCrypto huaweiCrypto = null;
|
protected HuaweiCrypto huaweiCrypto = null;
|
||||||
protected boolean addToResponse = true;
|
protected boolean addToResponse = true;
|
||||||
|
|
||||||
|
private final Handler handler;
|
||||||
|
private final Runnable timeoutRunner;
|
||||||
|
private Integer timeout = null;
|
||||||
|
|
||||||
public static class RequestCallback {
|
public static class RequestCallback {
|
||||||
protected HuaweiSupportProvider support = null;
|
protected HuaweiSupportProvider support = null;
|
||||||
public RequestCallback() {}
|
public RequestCallback() {}
|
||||||
@ -122,6 +128,9 @@ public class Request {
|
|||||||
public void handleException(ResponseParseException e) {
|
public void handleException(ResponseParseException e) {
|
||||||
LOG.error("Callback request exception", e);
|
LOG.error("Callback request exception", e);
|
||||||
}
|
}
|
||||||
|
public void timeout(Request request) {
|
||||||
|
request.handleNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request(HuaweiSupportProvider supportProvider, nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder builder) {
|
public Request(HuaweiSupportProvider supportProvider, nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder builder) {
|
||||||
@ -131,6 +140,15 @@ public class Request {
|
|||||||
this.builderBr = builder;
|
this.builderBr = builder;
|
||||||
|
|
||||||
this.isSelfQueue = true;
|
this.isSelfQueue = true;
|
||||||
|
|
||||||
|
this.handler = new Handler(Looper.getMainLooper());
|
||||||
|
this.timeoutRunner = () -> {
|
||||||
|
LOG.debug("Timeout on Service {} command {}", this.serviceId, this.commandId);
|
||||||
|
if (finalizeReq != null)
|
||||||
|
finalizeReq.timeout(this);
|
||||||
|
else
|
||||||
|
this.handleNext();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request(HuaweiSupportProvider supportProvider, nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder builder) {
|
public Request(HuaweiSupportProvider supportProvider, nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder builder) {
|
||||||
@ -140,6 +158,15 @@ public class Request {
|
|||||||
this.builderLe = builder;
|
this.builderLe = builder;
|
||||||
|
|
||||||
this.isSelfQueue = true;
|
this.isSelfQueue = true;
|
||||||
|
|
||||||
|
this.handler = new Handler(Looper.getMainLooper());
|
||||||
|
this.timeoutRunner = () -> {
|
||||||
|
LOG.debug("Timeout on Service {} command {}", this.serviceId, this.commandId);
|
||||||
|
if (finalizeReq != null)
|
||||||
|
finalizeReq.timeout(this);
|
||||||
|
else
|
||||||
|
this.handleNext();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request(HuaweiSupportProvider supportProvider) {
|
public Request(HuaweiSupportProvider supportProvider) {
|
||||||
@ -152,9 +179,27 @@ public class Request {
|
|||||||
this.builderLe = supportProvider.createLeTransactionBuilder(getName());
|
this.builderLe = supportProvider.createLeTransactionBuilder(getName());
|
||||||
|
|
||||||
this.isSelfQueue = true;
|
this.isSelfQueue = true;
|
||||||
|
|
||||||
|
this.handler = new Handler(Looper.getMainLooper());
|
||||||
|
this.timeoutRunner = () -> {
|
||||||
|
LOG.debug("Timeout on Service {} command {}", this.serviceId, this.commandId);
|
||||||
|
if (finalizeReq != null)
|
||||||
|
finalizeReq.timeout(this);
|
||||||
|
else
|
||||||
|
this.handleNext();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPerform() throws IOException {
|
public void doPerform() throws IOException {
|
||||||
|
if (!requestSupported()) {
|
||||||
|
this.handleNext();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.addToResponse) {
|
if (this.addToResponse) {
|
||||||
supportProvider.addInProgressRequest(this);
|
supportProvider.addInProgressRequest(this);
|
||||||
}
|
}
|
||||||
@ -191,6 +236,9 @@ public class Request {
|
|||||||
protected void processResponse() throws ResponseParseException {}
|
protected void processResponse() throws ResponseParseException {}
|
||||||
|
|
||||||
public void handleResponse() {
|
public void handleResponse() {
|
||||||
|
// Stop timeout timer
|
||||||
|
this.handler.removeCallbacks(this.timeoutRunner);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.receivedPacket.parseTlv();
|
this.receivedPacket.parseTlv();
|
||||||
} catch (HuaweiPacket.ParseException e) {
|
} catch (HuaweiPacket.ParseException e) {
|
||||||
@ -206,6 +254,10 @@ public class Request {
|
|||||||
finalizeReq.handleException(e);
|
finalizeReq.handleException(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
handleNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleNext() {
|
||||||
if (nextRequest != null && !stopChain) {
|
if (nextRequest != null && !stopChain) {
|
||||||
try {
|
try {
|
||||||
nextRequest.doPerform();
|
nextRequest.doPerform();
|
||||||
@ -299,6 +351,10 @@ public class Request {
|
|||||||
private void performConnected() throws IOException {
|
private void performConnected() throws IOException {
|
||||||
LOG.debug("Perform connected");
|
LOG.debug("Perform connected");
|
||||||
|
|
||||||
|
// Start the timeout timer
|
||||||
|
if (this.timeout != null)
|
||||||
|
handler.postDelayed(this.timeoutRunner, this.timeout);
|
||||||
|
|
||||||
if (!this.supportProvider.isBLE()) {
|
if (!this.supportProvider.isBLE()) {
|
||||||
nodomain.freeyourgadget.gadgetbridge.service.btbr.Transaction transaction = this.builderBr.getTransaction();
|
nodomain.freeyourgadget.gadgetbridge.service.btbr.Transaction transaction = this.builderBr.getTransaction();
|
||||||
this.supportProvider.performConnected(transaction);
|
this.supportProvider.performConnected(transaction);
|
||||||
@ -311,4 +367,16 @@ public class Request {
|
|||||||
public boolean autoRemoveFromResponseHandler() {
|
public boolean autoRemoveFromResponseHandler() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setupTimeoutUntilNext(int timeout) {
|
||||||
|
this.timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
// Stop timeout timer
|
||||||
|
this.handler.removeCallbacks(this.timeoutRunner);
|
||||||
|
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.CameraRemote;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.CameraRemote;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
|
||||||
@ -33,6 +35,11 @@ public class SendCameraRemoteSetupEvent extends Request {
|
|||||||
this.event = event;
|
this.event = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsCameraRemote() && GBApplication.getDeviceSpecificSharedPrefs(supportProvider.getDevice().getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_CAMERA_REMOTE, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -41,6 +41,11 @@ public class SendDndAddRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.DndAddRequest.id;
|
this.commandId = DeviceConfig.DndAddRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsDoNotDisturb(supportProvider.getDevice());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(supportProvider.getDeviceMac());
|
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(supportProvider.getDeviceMac());
|
||||||
|
@ -34,6 +34,11 @@ public class SendDndDeleteRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.DndDeleteRequest.id;
|
this.commandId = DeviceConfig.DndDeleteRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsDoNotDisturb(supportProvider.getDevice());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -37,6 +37,11 @@ public class SendExtendedAccountRequest extends Request {
|
|||||||
this.commandId = AccountRelated.SendExtendedAccountToDevice.id;
|
this.commandId = AccountRelated.SendExtendedAccountToDevice.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsAccountJudgment() && supportProvider.getHuaweiCoordinator().supportsAccountSwitch();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws Request.RequestCreationException {
|
protected List<byte[]> createRequest() throws Request.RequestCreationException {
|
||||||
String account = GBApplication
|
String account = GBApplication
|
||||||
|
@ -37,6 +37,11 @@ public class SendFitnessGoalRequest extends Request {
|
|||||||
this.commandId = MotionGoal.id;
|
this.commandId = MotionGoal.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsMotionGoal();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -35,6 +35,11 @@ public class SendMenstrualCapabilityRequest extends Request {
|
|||||||
this.commandId = CapabilityRequest.id;
|
this.commandId = CapabilityRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsMenstrual();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -35,6 +35,11 @@ public class SendNotifyHeartRateCapabilityRequest extends Request {
|
|||||||
this.commandId = NotifyHeartRate.id;
|
this.commandId = NotifyHeartRate.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsWorkoutsTrustHeartRate();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -35,6 +35,11 @@ public class SendNotifyRestHeartRateCapabilityRequest extends Request {
|
|||||||
this.commandId = NotifyRestHeartRate.id;
|
this.commandId = NotifyRestHeartRate.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsFitnessRestHeartRate();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -35,6 +35,11 @@ public class SendSetUpDeviceStatusRequest extends Request {
|
|||||||
this.commandId = SetUpDeviceStatusRequest.id;
|
this.commandId = SetUpDeviceStatusRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsMultiDevice();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
int relationShip = 1; // Hardcoded value for now - 1 = mainDevice
|
int relationShip = 1; // Hardcoded value for now - 1 = mainDevice
|
||||||
|
@ -36,6 +36,11 @@ public class SetActivateOnLiftRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.ActivateOnLiftRequest.id;
|
this.commandId = DeviceConfig.ActivateOnLiftRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsActivateOnLift();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
boolean activate = GBApplication
|
boolean activate = GBApplication
|
||||||
|
@ -40,6 +40,11 @@ public class SetActivityReminderRequest extends Request {
|
|||||||
this.commandId = FitnessData.ActivityReminder.id;
|
this.commandId = FitnessData.ActivityReminder.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsActivityReminder();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(supportProvider.getDeviceMac());
|
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(supportProvider.getDeviceMac());
|
||||||
|
@ -37,6 +37,11 @@ public class SetDateFormatRequest extends Request {
|
|||||||
this.commandId = DateFormat.id;
|
this.commandId = DateFormat.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsDateFormat();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
int time = DeviceConfig.Time.hours12;
|
int time = DeviceConfig.Time.hours12;
|
||||||
|
@ -41,6 +41,11 @@ public class SetLanguageSettingRequest extends Request {
|
|||||||
this.commandId = SetLanguageSetting.id;
|
this.commandId = SetLanguageSetting.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsLanguageSetting();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
String localeString = GBApplication
|
String localeString = GBApplication
|
||||||
|
@ -35,6 +35,11 @@ public class SetMediumToStrengthThresholdRequest extends Request {
|
|||||||
this.commandId = MediumToStrengthThreshold.id;
|
this.commandId = MediumToStrengthThreshold.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsFitnessThresholdValue();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -36,6 +36,11 @@ public class SetNavigateOnRotateRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.NavigateOnRotateRequest.id;
|
this.commandId = DeviceConfig.NavigateOnRotateRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsRotateToCycleInfo();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
boolean navigate = GBApplication
|
boolean navigate = GBApplication
|
||||||
|
@ -36,6 +36,11 @@ public class SetNotificationRequest extends Request {
|
|||||||
this.commandId = Notifications.NotificationStateRequest.id;
|
this.commandId = Notifications.NotificationStateRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsNotification();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
boolean status = GBApplication
|
boolean status = GBApplication
|
||||||
|
@ -34,6 +34,11 @@ public class SetTimeZoneIdRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.TimeZoneIdRequest.id;
|
this.commandId = DeviceConfig.TimeZoneIdRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsTimeAndZoneId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
try {
|
try {
|
||||||
|
@ -36,6 +36,11 @@ public class SetTruSleepRequest extends Request {
|
|||||||
this.commandId = FitnessData.TruSleep.id;
|
this.commandId = FitnessData.TruSleep.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsTruSleep();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
boolean truSleepSwitch = GBApplication
|
boolean truSleepSwitch = GBApplication
|
||||||
|
@ -36,6 +36,11 @@ public class SetWearLocationRequest extends Request {
|
|||||||
this.commandId = DeviceConfig.WearLocationRequest.id;
|
this.commandId = DeviceConfig.WearLocationRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsWearLocation(supportProvider.getDevice());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
String locationString = GBApplication
|
String locationString = GBApplication
|
||||||
|
@ -36,6 +36,11 @@ public class SetWearMessagePushRequest extends Request {
|
|||||||
this.commandId = Notifications.WearMessagePushRequest.id;
|
this.commandId = Notifications.WearMessagePushRequest.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requestSupported() {
|
||||||
|
return supportProvider.getHuaweiCoordinator().supportsDoNotDisturb(supportProvider.getDevice()) && supportProvider.getHuaweiCoordinator().supportsWearMessagePush();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<byte[]> createRequest() throws RequestCreationException {
|
protected List<byte[]> createRequest() throws RequestCreationException {
|
||||||
boolean status = GBApplication
|
boolean status = GBApplication
|
||||||
|
Loading…
Reference in New Issue
Block a user