mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Zepp OS: Fix support class reuse
This commit is contained in:
+9
-7
@@ -108,8 +108,7 @@ public class Huami2021ChunkedDecoder {
|
|||||||
if (sharedSessionKey == null) {
|
if (sharedSessionKey == null) {
|
||||||
// Should never happen
|
// Should never happen
|
||||||
LOG.warn("Got encrypted message, but there's no shared session key");
|
LOG.warn("Got encrypted message, but there's no shared session key");
|
||||||
currentHandle = null;
|
reset();
|
||||||
currentType = 0;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,9 +120,8 @@ public class Huami2021ChunkedDecoder {
|
|||||||
buf = CryptoUtils.decryptAES(buf, messagekey);
|
buf = CryptoUtils.decryptAES(buf, messagekey);
|
||||||
buf = ArrayUtils.subarray(buf, 0, currentLength);
|
buf = ArrayUtils.subarray(buf, 0, currentLength);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("error decrypting " + e);
|
LOG.warn("error decrypting {}", e.getMessage());
|
||||||
currentHandle = null;
|
reset();
|
||||||
currentType = 0;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,10 +137,14 @@ public class Huami2021ChunkedDecoder {
|
|||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
LOG.error("Failed to handle payload", e);
|
LOG.error("Failed to handle payload", e);
|
||||||
}
|
}
|
||||||
currentHandle = null;
|
reset();
|
||||||
currentType = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return needsAck;
|
return needsAck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
currentHandle = null;
|
||||||
|
currentType = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -154,4 +154,9 @@ public class Huami2021ChunkedEncoder {
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
writeHandle = 0;
|
||||||
|
encryptedSequenceNr = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -45,6 +45,11 @@ public class HuamiFetcher {
|
|||||||
this.mSupport = mSupport;
|
this.mSupport = mSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
fetchOperationQueue.clear();
|
||||||
|
currentOperation = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void onFetchRecordedData(final int dataTypes) {
|
public void onFetchRecordedData(final int dataTypes) {
|
||||||
final GBDevice gbDevice = mSupport.getDevice();
|
final GBDevice gbDevice = mSupport.getDevice();
|
||||||
final DeviceCoordinator coordinator = mSupport.getCoordinator();
|
final DeviceCoordinator coordinator = mSupport.getCoordinator();
|
||||||
|
|||||||
+2
@@ -124,6 +124,8 @@ public class ZeppOsBtbrSupport extends AbstractBTBRDeviceSupport implements Zepp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TransactionBuilder initializeDevice(final TransactionBuilder builder) {
|
protected TransactionBuilder initializeDevice(final TransactionBuilder builder) {
|
||||||
|
packetBuffer.clear();
|
||||||
|
|
||||||
write(builder, CMD_CHANNELS_GET, new byte[]{});
|
write(builder, CMD_CHANNELS_GET, new byte[]{});
|
||||||
scheduleNextPing(25 * 60 * 1000L);
|
scheduleNextPing(25 * 60 * 1000L);
|
||||||
return builder;
|
return builder;
|
||||||
|
|||||||
+4
-4
@@ -257,10 +257,6 @@ public class ZeppOsSupport extends AbstractDeviceSupport
|
|||||||
this.communicator = communicator;
|
this.communicator = communicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeppOsCommunicator getCommunicator() {
|
|
||||||
return communicator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContext(final GBDevice gbDevice, final BluetoothAdapter btAdapter, final Context context) {
|
public void setContext(final GBDevice gbDevice, final BluetoothAdapter btAdapter, final Context context) {
|
||||||
super.setContext(gbDevice, btAdapter, context);
|
super.setContext(gbDevice, btAdapter, context);
|
||||||
@@ -297,6 +293,10 @@ public class ZeppOsSupport extends AbstractDeviceSupport
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void initializeDevice(final ZeppOsTransactionBuilder builder) {
|
protected void initializeDevice(final ZeppOsTransactionBuilder builder) {
|
||||||
|
huami2021ChunkedEncoder.reset();
|
||||||
|
huami2021ChunkedDecoder.reset();
|
||||||
|
fetcher.reset();
|
||||||
|
|
||||||
builder.setDeviceState(getDevice(), GBDevice.State.AUTHENTICATING, getContext());
|
builder.setDeviceState(getDevice(), GBDevice.State.AUTHENTICATING, getContext());
|
||||||
|
|
||||||
authenticationService.startAuthentication(builder);
|
authenticationService.startAuthentication(builder);
|
||||||
|
|||||||
+5
@@ -129,6 +129,11 @@ public class ZeppOsFindDeviceService extends AbstractZeppOsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(final ZeppOsTransactionBuilder builder) {
|
public void initialize(final ZeppOsTransactionBuilder builder) {
|
||||||
|
findWatchHandler.removeCallbacksAndMessages(null);
|
||||||
|
findPhoneHandler.removeCallbacksAndMessages(null);
|
||||||
|
findingWatch = false;
|
||||||
|
findPhoneStarted = false;
|
||||||
|
|
||||||
write(builder, CMD_CAPABILITIES_REQUEST);
|
write(builder, CMD_CAPABILITIES_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
@@ -91,6 +91,11 @@ public class ZeppOsHeartRateService extends AbstractZeppOsService {
|
|||||||
LOG.warn("Unexpected heart rate byte {}", String.format("0x%02x", payload[0]));
|
LOG.warn("Unexpected heart rate byte {}", String.format("0x%02x", payload[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(final ZeppOsTransactionBuilder builder) {
|
||||||
|
realtimeHandler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
realtimeHandler.removeCallbacksAndMessages(null);
|
realtimeHandler.removeCallbacksAndMessages(null);
|
||||||
|
|||||||
+3
@@ -116,6 +116,9 @@ public class ZeppOsMusicService extends AbstractZeppOsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(final ZeppOsTransactionBuilder builder) {
|
public void initialize(final ZeppOsTransactionBuilder builder) {
|
||||||
|
handler.removeCallbacksAndMessages(null);
|
||||||
|
isMusicAppStarted = false;
|
||||||
|
|
||||||
if (mediaManager == null) {
|
if (mediaManager == null) {
|
||||||
mediaManager = new MediaManager(getContext());
|
mediaManager = new MediaManager(getContext());
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -104,6 +104,9 @@ public class ZeppOsNotificationService extends AbstractZeppOsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(final ZeppOsTransactionBuilder builder) {
|
public void initialize(final ZeppOsTransactionBuilder builder) {
|
||||||
|
mNotificationReplyAction.clear();
|
||||||
|
mNotificationPictures.clear();
|
||||||
|
|
||||||
write(builder, NOTIFICATION_CMD_CAPABILITIES_REQUEST);
|
write(builder, NOTIFICATION_CMD_CAPABILITIES_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -172,6 +172,8 @@ public class ZeppOsWatchfaceService extends AbstractZeppOsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(final ZeppOsTransactionBuilder builder) {
|
public void initialize(final ZeppOsTransactionBuilder builder) {
|
||||||
|
watchfaces.clear();
|
||||||
|
|
||||||
requestWatchfaces(builder);
|
requestWatchfaces(builder);
|
||||||
requestCurrentWatchface(builder);
|
requestCurrentWatchface(builder);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -28,6 +28,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsTransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsTransactionBuilder;
|
||||||
|
|||||||
+8
@@ -34,6 +34,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiUtils;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsActivityType;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsActivityType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsTransactionBuilder;
|
||||||
|
|
||||||
public class ZeppOsWorkoutService extends AbstractZeppOsService {
|
public class ZeppOsWorkoutService extends AbstractZeppOsService {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ZeppOsWorkoutService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ZeppOsWorkoutService.class);
|
||||||
@@ -74,6 +75,13 @@ public class ZeppOsWorkoutService extends AbstractZeppOsService {
|
|||||||
return ENDPOINT;
|
return ENDPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(final ZeppOsTransactionBuilder builder) {
|
||||||
|
workoutNeedsGps = false;
|
||||||
|
workoutActivityKind = ActivityKind.UNKNOWN;
|
||||||
|
lastPhoneGpsSent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePayload(final byte[] payload) {
|
public void handlePayload(final byte[] payload) {
|
||||||
switch (payload[0]) {
|
switch (payload[0]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user