1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-09 22:57:54 +02:00

More fixes : acquiring the wakelock BEFORE scheduling the Timer

This commit is contained in:
Mikael Vallerie 2019-03-14 15:25:51 +01:00
parent c794201fc1
commit 4a00f4c068

View File

@ -1321,13 +1321,13 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.info("Activating timer"); LOG.info("Activating timer");
final Timer buttonActionTimer = new Timer("Mi Band Button Action Timer"); final Timer buttonActionTimer = new Timer("Mi Band Button Action Timer");
buttonActionTimer.schedule(new TimerTask() { buttonActionTimer.scheduleAtFixedRate(new TimerTask() {
@Override @Override
public void run() { public void run() {
runButtonAction(); runButtonAction();
buttonActionTimer.cancel(); buttonActionTimer.cancel();
} }
}, buttonActionDelay); }, buttonActionDelay, buttonActionDelay);
} }
else { else {
LOG.info("Activating button action"); LOG.info("Activating button action");
@ -1335,18 +1335,17 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
} }
if (isCustomMenuEnabled) { if (isCustomMenuEnabled) {
if(isWakelockEnabled) {
LOG.info("Acquiring wakelock");
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
deviceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport:wakelock");
deviceWakeLock.acquire();
}
final Timer customMenuTimer = new Timer("Mi Band Button Action Custom Menu"); final Timer customMenuTimer = new Timer("Mi Band Button Action Custom Menu");
customMenuTimer.schedule(new TimerTask() { customMenuTimer.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
LOG.info("Activating custom menu"); LOG.info("Activating custom menu");
if(isWakelockEnabled) {
LOG.info("Acquiring wakelock");
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
deviceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport:wakelock");
deviceWakeLock.acquire();
}
resetCustomMenuTimerTimeout(); resetCustomMenuTimerTimeout();
runCustomMenu(); runCustomMenu();
customMenuTimer.cancel(); customMenuTimer.cancel();