1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-09-01 03:55:47 +02:00

huawei: Handle some watchface install errors

* handle too many watchface installed
* handle insufficient space
* sort related code while at it
This commit is contained in:
Vitaliy Tomin 2024-08-15 12:36:44 +08:00 committed by José Rebelo
parent cea51e6ef8
commit 1940db7204
5 changed files with 37 additions and 7 deletions

View File

@ -578,12 +578,14 @@ public class HuaweiPacket {
}
case FileUpload.id:
switch(this.commandId) {
case FileUpload.FileNextChunkParams.id:
return new FileUpload.FileNextChunkParams(paramsProvider).fromPacket(this);
case FileUpload.FileUploadConsultAck.id:
return new FileUpload.FileUploadConsultAck.Response(paramsProvider).fromPacket(this);
case FileUpload.FileInfoSend.id:
return new FileUpload.FileInfoSend.Response(paramsProvider).fromPacket(this);
case FileUpload.FileHashSend.id:
return new FileUpload.FileHashSend.Response(paramsProvider).fromPacket(this);
case FileUpload.FileUploadConsultAck.id:
return new FileUpload.FileUploadConsultAck.Response(paramsProvider).fromPacket(this);
case FileUpload.FileNextChunkParams.id:
return new FileUpload.FileNextChunkParams(paramsProvider).fromPacket(this);
default:
this.isEncrypted = this.attemptDecrypt(); // Helps with debugging
return this;
@ -594,10 +596,10 @@ public class HuaweiPacket {
return new Watchface.WatchfaceParams.Response(paramsProvider).fromPacket(this);
case Watchface.DeviceWatchInfo.id:
return new Watchface.DeviceWatchInfo.Response(paramsProvider).fromPacket(this);
case Watchface.WatchfaceNameInfo.id:
return new Watchface.WatchfaceNameInfo.Response(paramsProvider).fromPacket(this);
case Watchface.WatchfaceConfirm.id:
return new Watchface.WatchfaceConfirm.Response(paramsProvider).fromPacket(this);
case Watchface.WatchfaceNameInfo.id:
return new Watchface.WatchfaceNameInfo.Response(paramsProvider).fromPacket(this);
default:
this.isEncrypted = this.attemptDecrypt(); // Helps with debugging
return this;

View File

@ -72,9 +72,14 @@ public class FileUpload {
}
public static class Response extends HuaweiPacket {
public int result = 0;
public Response (ParamsProvider paramsProvider) {
super(paramsProvider);
}
@Override
public void parseTlv() throws HuaweiPacket.ParseException {
this.result = this.tlv.getInteger(0x7f);
}
}
}

View File

@ -42,6 +42,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.CameraActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCameraRemote;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDisplayMessage;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
@ -415,7 +416,18 @@ public class AsynchronousResponse {
private void handleFileUpload(HuaweiPacket response) throws Request.ResponseParseException {
if (response.serviceId == FileUpload.id) {
if (response.commandId == FileUpload.FileHashSend.id) {
if (response.commandId == FileUpload.FileInfoSend.id) {
if (!(response instanceof FileUpload.FileInfoSend.Response))
throw new Request.ResponseTypeMismatchException(response, FileUpload.FileInfoSend.Response.class);
FileUpload.FileInfoSend.Response resp = (FileUpload.FileInfoSend.Response) response;
if (resp.result == 140004) {
LOG.error("Too many watchfaces installed");
support.handleGBDeviceEvent(new GBDeviceEventDisplayMessage(support.getContext().getString(R.string.cannot_upload_watchface_too_many_watchfaces_installed), Toast.LENGTH_LONG, GB.ERROR));
} else if (resp.result == 140009) {
LOG.error("Insufficient space for upload");
support.handleGBDeviceEvent(new GBDeviceEventDisplayMessage(support.getContext().getString(R.string.insufficient_space_for_upload), Toast.LENGTH_LONG, GB.ERROR));
}
} else if (response.commandId == FileUpload.FileHashSend.id) {
if (!(response instanceof FileUpload.FileHashSend.Response))
throw new Request.ResponseTypeMismatchException(response, FileUpload.FileHashSend.Response.class);
FileUpload.FileHashSend.Response resp = (FileUpload.FileHashSend.Response) response;

View File

@ -47,6 +47,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCameraRemote;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDisplayMessage;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiCoordinator;
@ -258,6 +259,14 @@ public class HuaweiSupportProvider {
}
}
public void handleGBDeviceEvent(GBDeviceEventDisplayMessage message) {
if (isBLE()) {
leSupport.handleGBDeviceEvent(message);
} else {
brSupport.handleGBDeviceEvent(message);
}
}
public void setGps(boolean start) {
if (start) {
if (!GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_WORKOUT_SEND_GPS_TO_BAND, false))

View File

@ -3147,4 +3147,6 @@
<string name="battery_percentage_str">%1$s%%</string>
<string name="pref_fetch_unknown_files_title">Fetch unknown files</string>
<string name="pref_fetch_unknown_files_summary">Fetch unknown activity files from the watch. They will not be processed, but will be saved in the phone.</string>
<string name="cannot_upload_watchface_too_many_watchfaces_installed">"Cannot upload watchface, too many watchfaces installed"</string>
<string name="insufficient_space_for_upload">"Insufficient space for upload"</string>
</resources>