WatchUpdaterService: process requests in a separate thread.
Previously, requests were executed on the main thread (base class is Service, not IntentService), which prompted Android to kill AAPS multiple times a day due to timeouts (of currently unknown origins). (cherry picked from commit 5ae45d5)
This commit is contained in:
parent
75a6366115
commit
8f813d52fa
1 changed files with 31 additions and 24 deletions
|
@ -6,6 +6,8 @@ import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -82,6 +84,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(WatchUpdaterService.class);
|
private static Logger log = LoggerFactory.getLogger(WatchUpdaterService.class);
|
||||||
|
|
||||||
|
private Handler handler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
@ -91,6 +94,11 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
if (wear_integration) {
|
if (wear_integration) {
|
||||||
googleApiConnect();
|
googleApiConnect();
|
||||||
}
|
}
|
||||||
|
if (handler == null) {
|
||||||
|
HandlerThread handlerThread = new HandlerThread(this.getClass().getSimpleName() + "Handler");
|
||||||
|
handlerThread.start();
|
||||||
|
handler = new Handler(handlerThread.getLooper());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void listenForChangeInSettings() {
|
public void listenForChangeInSettings() {
|
||||||
|
@ -123,34 +131,33 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
String action = null;
|
String action = intent != null ? intent.getAction() : null;
|
||||||
if (intent != null) {
|
|
||||||
action = intent.getAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wear_integration) {
|
if (wear_integration) {
|
||||||
if (googleApiClient.isConnected()) {
|
handler.post(() -> {
|
||||||
if (ACTION_RESEND.equals(action)) {
|
if (googleApiClient.isConnected()) {
|
||||||
resendData();
|
if (ACTION_RESEND.equals(action)) {
|
||||||
} else if (ACTION_OPEN_SETTINGS.equals(action)) {
|
resendData();
|
||||||
sendNotification();
|
} else if (ACTION_OPEN_SETTINGS.equals(action)) {
|
||||||
} else if (ACTION_SEND_STATUS.equals(action)) {
|
sendNotification();
|
||||||
sendStatus();
|
} else if (ACTION_SEND_STATUS.equals(action)) {
|
||||||
} else if (ACTION_SEND_BASALS.equals(action)) {
|
sendStatus();
|
||||||
sendBasals();
|
} else if (ACTION_SEND_BASALS.equals(action)) {
|
||||||
} else if (ACTION_SEND_BOLUSPROGRESS.equals(action)) {
|
sendBasals();
|
||||||
sendBolusProgress(intent.getIntExtra("progresspercent", 0), intent.hasExtra("progressstatus") ? intent.getStringExtra("progressstatus") : "");
|
} else if (ACTION_SEND_BOLUSPROGRESS.equals(action)) {
|
||||||
} else if (ACTION_SEND_ACTIONCONFIRMATIONREQUEST.equals(action)) {
|
sendBolusProgress(intent.getIntExtra("progresspercent", 0), intent.hasExtra("progressstatus") ? intent.getStringExtra("progressstatus") : "");
|
||||||
String title = intent.getStringExtra("title");
|
} else if (ACTION_SEND_ACTIONCONFIRMATIONREQUEST.equals(action)) {
|
||||||
String message = intent.getStringExtra("message");
|
String title = intent.getStringExtra("title");
|
||||||
String actionstring = intent.getStringExtra("actionstring");
|
String message = intent.getStringExtra("message");
|
||||||
sendActionConfirmationRequest(title, message, actionstring);
|
String actionstring = intent.getStringExtra("actionstring");
|
||||||
|
sendActionConfirmationRequest(title, message, actionstring);
|
||||||
|
} else {
|
||||||
|
sendData();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sendData();
|
googleApiClient.connect();
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
googleApiClient.connect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
|
|
Loading…
Reference in a new issue