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