DataService as JobIntentService
This commit is contained in:
parent
9d6654eecf
commit
e0c2e7d579
|
@ -161,7 +161,8 @@
|
|||
<!-- Service processing incomming data -->
|
||||
<service
|
||||
android:name=".services.DataService"
|
||||
android:exported="false" />
|
||||
android:exported="false"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"/>
|
||||
<service
|
||||
android:name=".services.LocationService"
|
||||
android:exported="false" />
|
||||
|
@ -180,7 +181,7 @@
|
|||
<service
|
||||
android:name=".plugins.pump.danaRS.services.DanaRSService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".plugins.general.wear.wearintegration.WatchUpdaterService"
|
||||
android:exported="true">
|
||||
|
@ -247,11 +248,11 @@
|
|||
<service
|
||||
android:name=".plugins.general.nsclient.services.NSClientService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".services.AlarmSoundService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".plugins.general.overview.notifications.DismissNotificationService"
|
||||
android:exported="false" />
|
||||
|
@ -292,7 +293,7 @@
|
|||
<service
|
||||
android:name=".plugins.pump.medtronic.service.RileyLinkMedtronicService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
android:exported="false" />
|
||||
<activity android:name=".plugins.pump.common.dialog.RileyLinkBLEScanActivity">
|
||||
<intent-filter>
|
||||
<action android:name="info.nightscout.androidaps.plugins.PumpCommon.dialog.RileyLinkBLEScanActivity" />
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package info.nightscout.androidaps.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.legacy.content.WakefulBroadcastReceiver;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -10,15 +11,16 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.services.DataService;
|
||||
|
||||
public class DataReceiver extends WakefulBroadcastReceiver {
|
||||
public class DataReceiver extends BroadcastReceiver {
|
||||
private static Logger log = LoggerFactory.getLogger(L.DATASERVICE);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (L.isEnabled(L.DATASERVICE))
|
||||
log.debug("onReceive " + intent);
|
||||
startWakefulService(context, new Intent(context, DataService.class)
|
||||
.setAction(intent.getAction())
|
||||
.putExtras(intent));
|
||||
// Explicitly specify that GcmIntentService will handle the intent.
|
||||
ComponentName comp = new ComponentName(context.getPackageName(),
|
||||
DataService.class.getName());
|
||||
DataService.enqueueWork(context, intent.setComponent(comp));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package info.nightscout.androidaps.services;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Telephony;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.JobIntentService;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -16,15 +19,16 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.events.EventNsFood;
|
||||
import info.nightscout.androidaps.events.EventNsTreatment;
|
||||
import info.nightscout.androidaps.logging.BundleLogger;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin;
|
||||
import info.nightscout.androidaps.plugins.source.SourceEversensePlugin;
|
||||
import info.nightscout.androidaps.plugins.source.SourceGlimpPlugin;
|
||||
|
@ -34,21 +38,30 @@ import info.nightscout.androidaps.plugins.source.SourcePoctechPlugin;
|
|||
import info.nightscout.androidaps.plugins.source.SourceTomatoPlugin;
|
||||
import info.nightscout.androidaps.plugins.source.SourceXdripPlugin;
|
||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||
import info.nightscout.androidaps.logging.BundleLogger;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
|
||||
public class DataService extends IntentService {
|
||||
public class DataService extends JobIntentService {
|
||||
private Logger log = LoggerFactory.getLogger(L.DATASERVICE);
|
||||
|
||||
public DataService() {
|
||||
super("DataService");
|
||||
registerBus();
|
||||
// Service unique ID
|
||||
static final int SERVICE_JOB_ID = 4378;
|
||||
|
||||
// Enqueuing work in to this service.
|
||||
public static void enqueueWork(Context context, Intent work) {
|
||||
enqueueWork(context, DataService.class, SERVICE_JOB_ID, work);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(final Intent intent) {
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (L.isEnabled(L.DATASERVICE))
|
||||
log.debug("All work complete");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleWork(@NonNull Intent intent) {
|
||||
if (L.isEnabled(L.DATASERVICE)) {
|
||||
log.debug("onHandleIntent " + intent);
|
||||
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
|
||||
|
@ -100,7 +113,7 @@ public class DataService extends IntentService {
|
|||
Intents.ACTION_REMOVED_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_NEW_CAL.equals(action) ||
|
||||
Intents.ACTION_NEW_MBG.equals(action))
|
||||
) {
|
||||
) {
|
||||
handleNewDataFromNSClient(intent);
|
||||
} else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) {
|
||||
SmsCommunicatorPlugin.getPlugin().handleNewData(intent);
|
||||
|
@ -108,22 +121,6 @@ public class DataService extends IntentService {
|
|||
|
||||
if (L.isEnabled(L.DATASERVICE))
|
||||
log.debug("onHandleIntent exit " + intent);
|
||||
DataReceiver.completeWakefulIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
private void registerBus() {
|
||||
try {
|
||||
MainApp.bus().unregister(this);
|
||||
} catch (RuntimeException x) {
|
||||
// Ignore
|
||||
}
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
private void handleNewDataFromNSClient(Intent intent) {
|
||||
|
|
Loading…
Reference in a new issue