Eros: do don't run Handler on UI thread

This commit is contained in:
Milos Kozak 2021-10-20 00:09:02 +02:00
parent 29da63d264
commit 523eabd29f

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.SystemClock; import android.os.SystemClock;
@ -159,7 +160,8 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
private int timeChangeRetries; private int timeChangeRetries;
private long nextPodWarningCheck; private long nextPodWarningCheck;
private long lastConnectionTimeMillis; private long lastConnectionTimeMillis;
private final Handler loopHandler = new Handler(Looper.getMainLooper()); private HandlerThread handlerThread;
private Handler loopHandler;
private final Runnable statusChecker; private final Runnable statusChecker;
@ -279,6 +281,12 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
if (handlerThread == null) {
handlerThread = new HandlerThread(OmnipodErosPumpPlugin.class.getSimpleName());
handlerThread.start();
loopHandler = new Handler(handlerThread.getLooper());
}
loopHandler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MILLIS); loopHandler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MILLIS);
// We can't do this in PodStateManager itself, because JodaTimeAndroid.init() hasn't been called yet // We can't do this in PodStateManager itself, because JodaTimeAndroid.init() hasn't been called yet