mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
Xiaomi: run data upload service finalization on respective queue
This commit is contained in:
parent
d217a0b15f
commit
53a7cc5b30
@ -36,6 +36,7 @@ import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.PlainAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
@ -241,12 +242,12 @@ public class XiaomiBleSupport extends XiaomiConnectionSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUploadProgress(int textRsrc, int progressPercent) {
|
public void onUploadProgress(int textRsrc, int progressPercent, boolean ongoing) {
|
||||||
try {
|
try {
|
||||||
final TransactionBuilder builder = commsSupport.createTransactionBuilder("send data upload progress");
|
final TransactionBuilder builder = commsSupport.createTransactionBuilder("send data upload progress");
|
||||||
builder.add(new SetProgressAction(
|
builder.add(new SetProgressAction(
|
||||||
commsSupport.getContext().getString(textRsrc),
|
commsSupport.getContext().getString(textRsrc),
|
||||||
true,
|
ongoing,
|
||||||
progressPercent,
|
progressPercent,
|
||||||
commsSupport.getContext()
|
commsSupport.getContext()
|
||||||
));
|
));
|
||||||
@ -261,6 +262,19 @@ public class XiaomiBleSupport extends XiaomiConnectionSupport {
|
|||||||
return commsSupport.connect();
|
return commsSupport.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runOnQueue(String taskName, Runnable runnable) {
|
||||||
|
final TransactionBuilder b = commsSupport.createTransactionBuilder("run task " + taskName + " on queue");
|
||||||
|
b.add(new PlainAction() {
|
||||||
|
@Override
|
||||||
|
public boolean run(BluetoothGatt gatt) {
|
||||||
|
runnable.run();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
b.queue(commsSupport.getQueue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
commsSupport.dispose();
|
commsSupport.dispose();
|
||||||
|
@ -27,7 +27,8 @@ import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
|||||||
public abstract class XiaomiConnectionSupport {
|
public abstract class XiaomiConnectionSupport {
|
||||||
public abstract boolean connect();
|
public abstract boolean connect();
|
||||||
public abstract void onAuthSuccess();
|
public abstract void onAuthSuccess();
|
||||||
public abstract void onUploadProgress(int textRsrc, int progressPercent);
|
public abstract void onUploadProgress(int textRsrc, int progressPercent, boolean ongoing);
|
||||||
|
public abstract void runOnQueue(String taskName, Runnable run);
|
||||||
public abstract void dispose();
|
public abstract void dispose();
|
||||||
public abstract void setContext(final GBDevice device, final BluetoothAdapter adapter, final Context context);
|
public abstract void setContext(final GBDevice device, final BluetoothAdapter adapter, final Context context);
|
||||||
public abstract void disconnect();
|
public abstract void disconnect();
|
||||||
|
@ -45,6 +45,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btbr.AbstractBTBRDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.btbr.AbstractBTBRDeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.PlainAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetDeviceStateAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetDeviceStateAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetProgressAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetProgressAction;
|
||||||
|
|
||||||
@ -110,12 +111,12 @@ public class XiaomiSppSupport extends XiaomiConnectionSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUploadProgress(final int textRsrc, final int progressPercent) {
|
public void onUploadProgress(final int textRsrc, final int progressPercent, final boolean ongoing) {
|
||||||
try {
|
try {
|
||||||
final TransactionBuilder builder = commsSupport.createTransactionBuilder("send data upload progress");
|
final TransactionBuilder builder = commsSupport.createTransactionBuilder("send data upload progress");
|
||||||
builder.add(new SetProgressAction(
|
builder.add(new SetProgressAction(
|
||||||
commsSupport.getContext().getString(textRsrc),
|
commsSupport.getContext().getString(textRsrc),
|
||||||
true,
|
ongoing,
|
||||||
progressPercent,
|
progressPercent,
|
||||||
commsSupport.getContext()
|
commsSupport.getContext()
|
||||||
));
|
));
|
||||||
@ -125,6 +126,24 @@ public class XiaomiSppSupport extends XiaomiConnectionSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runOnQueue(String taskName, Runnable runnable) {
|
||||||
|
if (commsSupport == null) {
|
||||||
|
LOG.error("commsSupport is null, unable to queue task");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TransactionBuilder b = commsSupport.createTransactionBuilder("run task " + taskName + " on queue");
|
||||||
|
b.add(new PlainAction() {
|
||||||
|
@Override
|
||||||
|
public boolean run(BluetoothSocket socket) {
|
||||||
|
runnable.run();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
b.queue(commsSupport.getQueue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContext(GBDevice device, BluetoothAdapter adapter, Context context) {
|
public void setContext(GBDevice device, BluetoothAdapter adapter, Context context) {
|
||||||
this.commsSupport.setContext(device, adapter, context);
|
this.commsSupport.setContext(device, adapter, context);
|
||||||
|
@ -168,15 +168,6 @@ public class XiaomiSupport extends AbstractDeviceSupport {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUploadProgress(int textRsrc, int progressPercent) {
|
|
||||||
if (getConnectionSpecificSupport() == null) {
|
|
||||||
LOG.error("onUploadProgress called but connection specific unavailable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
getConnectionSpecificSupport().onUploadProgress(textRsrc, progressPercent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (getConnectionSpecificSupport() != null) {
|
if (getConnectionSpecificSupport() != null) {
|
||||||
|
@ -545,8 +545,10 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
|
|||||||
@Override
|
@Override
|
||||||
public void onUploadFinish(final boolean success) {
|
public void onUploadFinish(final boolean success) {
|
||||||
LOG.debug("Notification icon upload finished: {}", success);
|
LOG.debug("Notification icon upload finished: {}", success);
|
||||||
|
getSupport().getConnectionSpecificSupport().runOnQueue(
|
||||||
getSupport().getDataUploadService().setCallback(null);
|
"notification icon upload finish",
|
||||||
|
() -> getSupport().getDataUploadService().setCallback(null)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -959,21 +959,28 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
public void onUploadFinish(final boolean success) {
|
public void onUploadFinish(final boolean success) {
|
||||||
LOG.debug("Firmware upload finished: {}", success);
|
LOG.debug("Firmware upload finished: {}", success);
|
||||||
|
|
||||||
getSupport().getDataUploadService().setCallback(null);
|
if (getSupport().getConnectionSpecificSupport() != null) {
|
||||||
|
getSupport().getConnectionSpecificSupport().runOnQueue("firmware upload finish", () -> {
|
||||||
|
getSupport().getDataUploadService().setCallback(null);
|
||||||
|
|
||||||
final String notificationMessage = success ?
|
final int notificationMessage = success ?
|
||||||
getSupport().getContext().getString(R.string.updatefirmwareoperation_update_complete) :
|
R.string.updatefirmwareoperation_update_complete :
|
||||||
getSupport().getContext().getString(R.string.updatefirmwareoperation_write_failed);
|
R.string.updatefirmwareoperation_write_failed;
|
||||||
|
|
||||||
GB.updateInstallNotification(notificationMessage, false, 100, getSupport().getContext());
|
onUploadProgress(notificationMessage, 100, false);
|
||||||
|
unsetDeviceBusy();
|
||||||
|
|
||||||
unsetDeviceBusy();
|
fwHelper = null;
|
||||||
|
});
|
||||||
fwHelper = null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUploadProgress(final int progressPercent) {
|
public void onUploadProgress(final int progressPercent) {
|
||||||
getSupport().onUploadProgress(R.string.updatefirmwareoperation_update_in_progress, progressPercent);
|
onUploadProgress(R.string.updatefirmwareoperation_update_in_progress, progressPercent, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onUploadProgress(final int stringResource, final int progressPercent, final boolean ongoing) {
|
||||||
|
getSupport().getConnectionSpecificSupport().onUploadProgress(stringResource, progressPercent, ongoing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,29 +228,36 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService implements Xia
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUploadFinish(final boolean success) {
|
public void onUploadFinish(final boolean success) {
|
||||||
LOG.debug("Watchface upload finished: {}", success);
|
final int notificationMessage = success ?
|
||||||
|
R.string.uploadwatchfaceoperation_complete :
|
||||||
|
R.string.uploadwatchfaceoperation_failed;
|
||||||
|
|
||||||
getSupport().getDataUploadService().setCallback(null);
|
onUploadProgress(notificationMessage, 100, false);
|
||||||
|
|
||||||
final String notificationMessage = success ?
|
if (getSupport().getConnectionSpecificSupport() != null) {
|
||||||
getSupport().getContext().getString(R.string.uploadwatchfaceoperation_complete) :
|
getSupport().getConnectionSpecificSupport().runOnQueue("watchface upload finish", () -> {
|
||||||
getSupport().getContext().getString(R.string.uploadwatchfaceoperation_failed);
|
LOG.debug("Watchface upload finished: {}", success);
|
||||||
|
getSupport().getDataUploadService().setCallback(null);
|
||||||
|
unsetDeviceBusy();
|
||||||
|
|
||||||
GB.updateInstallNotification(notificationMessage, false, 100, getSupport().getContext());
|
if (success) {
|
||||||
|
setWatchface(fwHelper.getId());
|
||||||
|
requestWatchfaceList();
|
||||||
|
}
|
||||||
|
|
||||||
unsetDeviceBusy();
|
fwHelper = null;
|
||||||
|
});
|
||||||
if (success) {
|
|
||||||
setWatchface(fwHelper.getId());
|
|
||||||
requestWatchfaceList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fwHelper = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUploadProgress(final int progressPercent) {
|
public void onUploadProgress(final int progressPercent) {
|
||||||
getSupport().onUploadProgress(R.string.uploadwatchfaceoperation_in_progress, progressPercent);
|
onUploadProgress(R.string.uploadwatchfaceoperation_in_progress, progressPercent, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onUploadProgress(final int stringResource, final int progressPercent, final boolean ongoing) {
|
||||||
|
if (getSupport().getConnectionSpecificSupport() != null)
|
||||||
|
getSupport().getConnectionSpecificSupport().onUploadProgress(stringResource, progressPercent, ongoing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDeviceBusy() {
|
private void setDeviceBusy() {
|
||||||
|
Loading…
Reference in New Issue
Block a user