mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Xiaomi: remove battery-related request timer on disconnect
This commit is contained in:
parent
cb44982edb
commit
ebf0dbc2d0
@ -223,6 +223,12 @@ public class XiaomiBleSupport extends XiaomiConnectionSupport {
|
|||||||
if (characteristicActivityData != null)
|
if (characteristicActivityData != null)
|
||||||
characteristicActivityData.setMtu(mtu);
|
characteristicActivityData.setMtu(mtu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect() {
|
||||||
|
mXiaomiSupport.onDisconnect();
|
||||||
|
super.disconnect();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public XiaomiBleSupport(final XiaomiSupport xiaomiSupport) {
|
public XiaomiBleSupport(final XiaomiSupport xiaomiSupport) {
|
||||||
|
@ -94,6 +94,18 @@ public class XiaomiSppSupport extends XiaomiConnectionSupport {
|
|||||||
protected UUID getSupportedService() {
|
protected UUID getSupportedService() {
|
||||||
return XiaomiUuids.UUID_SERVICE_SERIAL_PORT_PROFILE;
|
return XiaomiUuids.UUID_SERVICE_SERIAL_PORT_PROFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect() {
|
||||||
|
mXiaomiSupport.onDisconnect();
|
||||||
|
super.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
mXiaomiSupport.onDisconnect();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
@ -203,6 +203,13 @@ public class XiaomiSupport extends AbstractDeviceSupport {
|
|||||||
this.cachedFirmwareVersion = version;
|
this.cachedFirmwareVersion = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onDisconnect() {
|
||||||
|
// propagate disconnection to services
|
||||||
|
for (AbstractXiaomiService service : mServiceMap.values()) {
|
||||||
|
service.onDisconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void handleCommandBytes(final byte[] plainValue) {
|
public void handleCommandBytes(final byte[] plainValue) {
|
||||||
LOG.debug("Got command: {}", GB.hexdump(plainValue));
|
LOG.debug("Got command: {}", GB.hexdump(plainValue));
|
||||||
|
|
||||||
|
@ -62,4 +62,6 @@ public abstract class AbstractXiaomiService {
|
|||||||
protected Prefs getDevicePrefs() {
|
protected Prefs getDevicePrefs() {
|
||||||
return new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getSupport().getDevice().getAddress()));
|
return new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getSupport().getDevice().getAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onDisconnect() {}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.services;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.services;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
@ -102,14 +103,10 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
|
|
||||||
// Not null if we're installing a firmware
|
// Not null if we're installing a firmware
|
||||||
private XiaomiFWHelper fwHelper = null;
|
private XiaomiFWHelper fwHelper = null;
|
||||||
private Handler handler = new Handler();
|
private Handler handler = new Handler(Looper.getMainLooper());
|
||||||
private final Runnable batteryStateRequestRunnable = new Runnable() {
|
private final Runnable batteryStateRequestRunnable = () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
getSupport().sendCommand("get device status", COMMAND_TYPE, CMD_DEVICE_STATE_GET);
|
getSupport().sendCommand("get device status", COMMAND_TYPE, CMD_DEVICE_STATE_GET);
|
||||||
getSupport().sendCommand("get battery state", COMMAND_TYPE, CMD_BATTERY);
|
getSupport().sendCommand("get battery state", COMMAND_TYPE, CMD_BATTERY);
|
||||||
handler.postDelayed(this, BATTERY_STATE_REQUEST_INTERVAL);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private WearingState currentWearingState = WearingState.UNKNOWN;
|
private WearingState currentWearingState = WearingState.UNKNOWN;
|
||||||
@ -135,7 +132,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
getSupport().sendCommand("get widget parts", COMMAND_TYPE, CMD_WIDGET_PARTS_GET);
|
getSupport().sendCommand("get widget parts", COMMAND_TYPE, CMD_WIDGET_PARTS_GET);
|
||||||
getSupport().sendCommand("get workout types", COMMAND_TYPE, CMD_WORKOUT_TYPES_GET);
|
getSupport().sendCommand("get workout types", COMMAND_TYPE, CMD_WORKOUT_TYPES_GET);
|
||||||
|
|
||||||
handler.postDelayed(batteryStateRequestRunnable, BATTERY_STATE_REQUEST_INTERVAL);
|
rearmBatteryStateRequestTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -368,8 +365,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
getSupport().evaluateGBDeviceEvent(batteryInfo);
|
getSupport().evaluateGBDeviceEvent(batteryInfo);
|
||||||
|
|
||||||
// reset battery level request timer
|
// reset battery level request timer
|
||||||
handler.removeCallbacks(batteryStateRequestRunnable);
|
rearmBatteryStateRequestTimer();
|
||||||
handler.postDelayed(batteryStateRequestRunnable, BATTERY_STATE_REQUEST_INTERVAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPassword() {
|
private void setPassword() {
|
||||||
@ -800,8 +796,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
// TODO: handle activity state
|
// TODO: handle activity state
|
||||||
|
|
||||||
// reset battery level refresh timer
|
// reset battery level refresh timer
|
||||||
handler.removeCallbacks(batteryStateRequestRunnable);
|
rearmBatteryStateRequestTimer();
|
||||||
handler.postDelayed(batteryStateRequestRunnable, BATTERY_STATE_REQUEST_INTERVAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleDeviceState(XiaomiProto.DeviceState deviceState) {
|
public void handleDeviceState(XiaomiProto.DeviceState deviceState) {
|
||||||
@ -983,4 +978,14 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
public void onUploadProgress(final int stringResource, final int progressPercent, final boolean ongoing) {
|
public void onUploadProgress(final int stringResource, final int progressPercent, final boolean ongoing) {
|
||||||
getSupport().getConnectionSpecificSupport().onUploadProgress(stringResource, progressPercent, ongoing);
|
getSupport().getConnectionSpecificSupport().onUploadProgress(stringResource, progressPercent, ongoing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rearmBatteryStateRequestTimer() {
|
||||||
|
this.handler.removeCallbacks(this.batteryStateRequestRunnable);
|
||||||
|
this.handler.postDelayed(this.batteryStateRequestRunnable, BATTERY_STATE_REQUEST_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnect() {
|
||||||
|
this.handler.removeCallbacks(this.batteryStateRequestRunnable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user