1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

Huami: Add queued fetch operations

This commit is contained in:
José Rebelo 2023-05-20 23:34:36 +01:00 committed by José Rebelo
parent 23e9a3deb1
commit 3f87bfadd4
3 changed files with 60 additions and 15 deletions

View File

@ -23,6 +23,8 @@ public class RecordedDataTypes {
public static final int TYPE_GPS_TRACKS = 0x00000004; public static final int TYPE_GPS_TRACKS = 0x00000004;
public static final int TYPE_TEMPERATURE = 0x00000008; public static final int TYPE_TEMPERATURE = 0x00000008;
public static final int TYPE_DEBUGLOGS = 0x00000010; public static final int TYPE_DEBUGLOGS = 0x00000010;
public static final int TYPE_SPO2 = 0x00000020;
public static final int TYPE_STRESS = 0x00000040;
public static final int TYPE_ALL = (int)0xffffffff; public static final int TYPE_ALL = (int)0xffffffff;
} }

View File

@ -19,7 +19,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami; package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
import android.app.Notification;
import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context; import android.content.Context;
@ -57,9 +56,11 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.SimpleTimeZone; import java.util.SimpleTimeZone;
import java.util.TimeZone; import java.util.TimeZone;
@ -115,9 +116,12 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.AbstractFetchOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSpo2NormalOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchStressAutoOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchStressManualOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.HuamiFetchDebugLogsOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.HuamiFetchDebugLogsOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.services.ZeppOsCannedMessagesService; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.services.ZeppOsCannedMessagesService;
import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarEvent; import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarEvent;
@ -326,6 +330,8 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
protected Huami2021ChunkedEncoder huami2021ChunkedEncoder; protected Huami2021ChunkedEncoder huami2021ChunkedEncoder;
protected Huami2021ChunkedDecoder huami2021ChunkedDecoder; protected Huami2021ChunkedDecoder huami2021ChunkedDecoder;
private final Queue<AbstractFetchOperation> fetchOperationQueue = new LinkedList<>();
public HuamiSupport() { public HuamiSupport() {
this(LOG); this(LOG);
} }
@ -1645,22 +1651,41 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
public void onFetchRecordedData(int dataTypes) { public void onFetchRecordedData(int dataTypes) {
final HuamiCoordinator coordinator = getCoordinator(); final HuamiCoordinator coordinator = getCoordinator();
if ((dataTypes & RecordedDataTypes.TYPE_ACTIVITY) != 0) {
this.fetchOperationQueue.add(new FetchActivityOperation(this));
}
if ((dataTypes & RecordedDataTypes.TYPE_GPS_TRACKS) != 0 && coordinator.supportsActivityTracks()) {
this.fetchOperationQueue.add(new FetchSportsSummaryOperation(this, 1));
}
if ((dataTypes & RecordedDataTypes.TYPE_DEBUGLOGS) != 0 && coordinator.supportsDebugLogs()) {
this.fetchOperationQueue.add(new HuamiFetchDebugLogsOperation(this));
}
if ((dataTypes & RecordedDataTypes.TYPE_SPO2) != 0 && coordinator.supportsSpo2()) {
this.fetchOperationQueue.add(new FetchSpo2NormalOperation(this));
}
if ((dataTypes & RecordedDataTypes.TYPE_STRESS) != 0 && coordinator.supportsStressMeasurement()) {
this.fetchOperationQueue.add(new FetchStressAutoOperation(this));
this.fetchOperationQueue.add(new FetchStressManualOperation(this));
}
final AbstractFetchOperation nextOperation = this.fetchOperationQueue.poll();
if (nextOperation != null) {
try { try {
// FIXME: currently only one data type supported, these are meant to be flags nextOperation.perform();
if (dataTypes == RecordedDataTypes.TYPE_ACTIVITY) { } catch (final IOException e) {
new FetchActivityOperation(this).perform(); LOG.error("Unable to fetch recorded data", e);
} else if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS && coordinator.supportsActivityTracks()) {
new FetchSportsSummaryOperation(this, 1).perform();
} else if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS && coordinator.supportsDebugLogs()) {
new HuamiFetchDebugLogsOperation(this).perform();
} else {
LOG.warn("fetching multiple data types at once is not supported yet");
} }
} catch (final IOException ex) {
LOG.error("Unable to fetch recorded data types" + dataTypes, ex);
} }
} }
public AbstractFetchOperation getNextFetchOperation() {
return fetchOperationQueue.poll();
}
@Override @Override
public void onEnableRealtimeSteps(boolean enable) { public void onEnableRealtimeSteps(boolean enable) {
try { try {

View File

@ -130,6 +130,24 @@ public abstract class AbstractFetchOperation extends AbstractHuamiOperation {
*/ */
@CallSuper @CallSuper
protected boolean handleActivityFetchFinish(boolean success) { protected boolean handleActivityFetchFinish(boolean success) {
final AbstractFetchOperation nextFetchOperation = getSupport().getNextFetchOperation();
if (nextFetchOperation != null) {
LOG.debug("Performing next operation {}", nextFetchOperation.getName());
try {
nextFetchOperation.perform();
return true;
} catch (final IOException e) {
GB.toast(
getContext(),
"Failed to run next fetch operation",
Toast.LENGTH_SHORT,
GB.ERROR, e
);
return false;
}
}
GB.updateTransferNotification(null, "", false, 100, getContext()); GB.updateTransferNotification(null, "", false, 100, getContext());
operationFinished(); operationFinished();
unsetBusy(); unsetBusy();