Insight async add wake locking
This commit is contained in:
parent
11fcfb88d4
commit
8fa0de19c2
1 changed files with 25 additions and 16 deletions
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpInsight;
|
package info.nightscout.androidaps.plugins.PumpInsight;
|
||||||
|
|
||||||
|
import android.os.PowerManager;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -8,7 +10,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpCallback;
|
import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpCallback;
|
||||||
|
|
||||||
|
import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.getWakeLock;
|
||||||
import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.msSince;
|
import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.msSince;
|
||||||
|
import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.releaseWakeLock;
|
||||||
import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.tsl;
|
import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.tsl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,23 +57,28 @@ public class InsightPumpAsyncAdapter {
|
||||||
|
|
||||||
// blocking call to wait for result callback
|
// blocking call to wait for result callback
|
||||||
Cstatus busyWaitForCommandResult(final UUID uuid, long wait_time) {
|
Cstatus busyWaitForCommandResult(final UUID uuid, long wait_time) {
|
||||||
log("busy wait for command " + uuid);
|
final PowerManager.WakeLock wl = getWakeLock("insight-wait-cmd", 60000);
|
||||||
if (uuid == null) return Cstatus.FAILURE;
|
try {
|
||||||
final long start_time = tsl();
|
log("busy wait for command " + uuid);
|
||||||
Cstatus status = checkCommandResult(uuid);
|
if (uuid == null) return Cstatus.FAILURE;
|
||||||
while ((status == Cstatus.PENDING) && msSince(start_time) < wait_time) {
|
final long start_time = tsl();
|
||||||
//log("command result waiting");
|
Cstatus status = checkCommandResult(uuid);
|
||||||
try {
|
while ((status == Cstatus.PENDING) && msSince(start_time) < wait_time) {
|
||||||
Thread.sleep(200);
|
//log("command result waiting");
|
||||||
} catch (InterruptedException e) {
|
try {
|
||||||
log("Got interrupted exception! " + e);
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log("Got interrupted exception! " + e);
|
||||||
|
}
|
||||||
|
status = checkCommandResult(uuid);
|
||||||
}
|
}
|
||||||
status = checkCommandResult(uuid);
|
if (status == Cstatus.PENDING) {
|
||||||
}
|
return Cstatus.TIMEOUT;
|
||||||
if (status == Cstatus.PENDING) {
|
} else {
|
||||||
return Cstatus.TIMEOUT;
|
return status;
|
||||||
} else {
|
}
|
||||||
return status;
|
} finally {
|
||||||
|
releaseWakeLock(wl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue