lowest priority for background calculations

This commit is contained in:
Milos Kozak 2017-12-04 19:57:09 +01:00
parent 23e37a8be7
commit 620c56e4cb

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.IobCobCalculator;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.Process;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.util.LongSparseArray; import android.support.v4.util.LongSparseArray;
@ -134,7 +135,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
IobCobCalculatorPlugin() { IobCobCalculatorPlugin() {
MainApp.bus().register(this); MainApp.bus().register(this);
if (sHandlerThread == null) { if (sHandlerThread == null) {
sHandlerThread = new HandlerThread(IobCobCalculatorPlugin.class.getSimpleName()); sHandlerThread = new HandlerThread(IobCobCalculatorPlugin.class.getSimpleName(), Process.THREAD_PRIORITY_LOWEST);
sHandlerThread.start(); sHandlerThread.start();
sHandler = new Handler(sHandlerThread.getLooper()); sHandler = new Handler(sHandlerThread.getLooper());
} }
@ -232,7 +233,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
private BgReading findOlder(long time) { private BgReading findOlder(long time) {
BgReading lastFound = bgReadings.get(bgReadings.size() - 1); BgReading lastFound = bgReadings.get(bgReadings.size() - 1);
if (lastFound.date > time) return null; if (lastFound.date > time) return null;
for (int i = bgReadings.size() - 2; i >=0 ; --i) { for (int i = bgReadings.size() - 2; i >= 0; --i) {
if (bgReadings.get(i).date < time) continue; if (bgReadings.get(i).date < time) continue;
lastFound = bgReadings.get(i); lastFound = bgReadings.get(i);
if (bgReadings.get(i).date > time) break; if (bgReadings.get(i).date > time) break;
@ -251,7 +252,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
long currentTime = bgReadings.get(0).date + 5 * 60 * 1000 - bgReadings.get(0).date % (5 * 60 * 1000) - 5 * 60 * 1000L; long currentTime = bgReadings.get(0).date + 5 * 60 * 1000 - bgReadings.get(0).date % (5 * 60 * 1000) - 5 * 60 * 1000L;
//log.debug("First reading: " + new Date(currentTime).toLocaleString()); //log.debug("First reading: " + new Date(currentTime).toLocaleString());
while (true) { while (true) {
// test if current value is older than current time // test if current value is older than current time
BgReading newer = findNewer(currentTime); BgReading newer = findNewer(currentTime);
BgReading older = findOlder(currentTime); BgReading older = findOlder(currentTime);
@ -677,8 +678,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
for (int index = iobTable.size() - 1; index >= 0; index--) { for (int index = iobTable.size() - 1; index >= 0; index--) {
if (iobTable.keyAt(index) > time) { if (iobTable.keyAt(index) > time) {
if (Config.logAutosensData) if (Config.logAutosensData)
if (Config.logAutosensData) if (Config.logAutosensData)
log.debug("Removing from iobTable: " + new Date(iobTable.keyAt(index)).toLocaleString()); log.debug("Removing from iobTable: " + new Date(iobTable.keyAt(index)).toLocaleString());
iobTable.removeAt(index); iobTable.removeAt(index);
} else { } else {
break; break;