huawei: Add watchface uploading progress

This commit is contained in:
Vitaliy Tomin 2024-04-06 00:48:58 +08:00
parent c1f286e823
commit ad4e373131
3 changed files with 49 additions and 0 deletions

View File

@ -411,6 +411,7 @@ public class AsynchronousResponse {
support.huaweiUploadManager.setFileUploadParams(resp.fileUploadParams);
try {
support.huaweiUploadManager.setDeviceBusy();
SendFileUploadAck sendFileUploadAck = new SendFileUploadAck(this.support, resp.fileUploadParams.no_encrypt);
sendFileUploadAck.doPerform();
} catch (IOException e) {
@ -422,6 +423,8 @@ public class AsynchronousResponse {
FileUpload.FileNextChunkParams resp = (FileUpload.FileNextChunkParams) response;
support.huaweiUploadManager.setUploadChunkSize(resp.nextchunkSize);
support.huaweiUploadManager.setCurrentUploadPosition(resp.bytesUploaded);
int progress = Math.round(((float)resp.bytesUploaded / (float)support.huaweiUploadManager.getFileSize())* 100);
support.onUploadProgress(R.string.updatefirmwareoperation_update_in_progress, progress, true);
try {
SendFileUploadChunk sendFileUploadChunk = new SendFileUploadChunk(this.support, this.support.huaweiUploadManager);
@ -431,6 +434,8 @@ public class AsynchronousResponse {
}
} else if (response.commandId == FileUpload.FileUploadResult.id) {
try {
support.huaweiUploadManager.unsetDeviceBusy();
support.onUploadProgress(R.string.updatefirmwareoperation_update_complete, 100, false);
SendFileUploadComplete sendFileUploadComplete = new SendFileUploadComplete(this.support);
SendWatchfaceOperation sendWatchfaceOperation = new SendWatchfaceOperation(this.support, this.support.huaweiUploadManager.getFileName());
sendFileUploadComplete.doPerform();

View File

@ -1847,8 +1847,33 @@ public class HuaweiSupportProvider {
GB.toast(context, "Failed to send watchface info", Toast.LENGTH_SHORT, GB.ERROR, e);
LOG.error("Failed to send watchface info", e);
}
}
public void onUploadProgress(int textRsrc, int progressPercent, boolean ongoing) {
try {
if (isBLE()) {
nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder leBuilder = createLeTransactionBuilder("FetchRecordedData");
leBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction(
context.getString(textRsrc),
ongoing,
progressPercent,
context
));
leBuilder.queue(leSupport.getQueue());
} else {
nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder brBuilder = createBrTransactionBuilder("FetchRecordedData");
brBuilder.add(new nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetProgressAction(
context.getString(textRsrc),
ongoing,
progressPercent,
context));
brBuilder.queue(brSupport.getQueue());
}
} catch (final Exception e) {
LOG.error("Failed to update progress notification", e);
}
}

View File

@ -10,7 +10,9 @@ import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.FileUpload.FileUploadParams;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBZipFile;
import nodomain.freeyourgadget.gadgetbridge.util.UriHelper;
@ -127,5 +129,22 @@ public class HuaweiUploadManager {
return fileUploadParams.unit_size;
}
public void setDeviceBusy() {
final GBDevice device = support.getDevice();
device.setBusyTask(support.getContext().getString(R.string.uploading_watchface));
device.sendDeviceUpdateIntent(support.getContext());
}
public void unsetDeviceBusy() {
final GBDevice device = support.getDevice();
if (device != null && device.isConnected()) {
if (device.isBusy()) {
device.unsetBusyTask();
device.sendDeviceUpdateIntent(support.getContext());
}
device.sendDeviceUpdateIntent(support.getContext());
}
}
}