AndroidAPS/app/src/main/java/info/nightscout/androidaps/MainApp.java

434 lines
19 KiB
Java
Raw Normal View History

2016-06-05 01:40:35 +02:00
package info.nightscout.androidaps;
2020-01-03 14:30:39 +01:00
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
2017-07-24 01:50:27 +02:00
import android.content.IntentFilter;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
2019-07-05 01:22:45 +02:00
2019-12-24 16:07:17 +01:00
import androidx.annotation.ColorRes;
import androidx.annotation.StringRes;
2020-01-03 14:30:39 +01:00
import androidx.core.app.NotificationCompat;
import androidx.core.app.TaskStackBuilder;
2019-12-24 16:07:17 +01:00
import androidx.core.content.ContextCompat;
2019-05-16 13:57:37 +02:00
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
2016-06-05 01:40:35 +02:00
2016-06-24 17:48:11 +02:00
import com.crashlytics.android.Crashlytics;
2019-04-05 00:32:26 +02:00
import com.google.firebase.analytics.FirebaseAnalytics;
2016-06-05 01:40:35 +02:00
import com.j256.ormlite.android.apptools.OpenHelperManager;
2017-12-22 02:55:40 +01:00
import net.danlew.android.joda.JodaTimeAndroid;
2019-12-13 13:12:36 +01:00
import org.json.JSONException;
2016-08-05 23:54:03 +02:00
2019-12-23 13:27:15 +01:00
import javax.inject.Inject;
2019-12-13 02:12:19 +01:00
import dagger.android.AndroidInjector;
2019-12-21 20:17:08 +01:00
import dagger.android.DaggerApplication;
2020-03-10 18:58:27 +01:00
import dagger.android.HasAndroidInjector;
2019-12-13 13:12:36 +01:00
import info.nightscout.androidaps.data.Profile;
2016-08-05 23:54:03 +02:00
import info.nightscout.androidaps.db.DatabaseHelper;
2019-12-13 02:12:19 +01:00
import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent;
2019-12-28 01:52:20 +01:00
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
2019-03-02 14:37:53 +01:00
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
2019-02-28 23:16:50 +01:00
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
2020-03-16 21:40:29 +01:00
import info.nightscout.androidaps.plugins.configBuilder.PluginStore;
2020-03-16 22:49:34 +01:00
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
2019-03-02 15:13:42 +01:00
import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin;
2019-02-28 23:16:50 +01:00
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin;
2019-03-07 10:32:29 +01:00
import info.nightscout.androidaps.plugins.constraints.storage.StorageConstraintPlugin;
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerPlugin;
2020-01-03 16:29:59 +01:00
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils;
2019-09-01 13:43:11 +02:00
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin;
2018-09-18 10:05:19 +02:00
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin;
2019-03-02 14:37:53 +01:00
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
2020-01-28 18:00:46 +01:00
import info.nightscout.androidaps.plugins.general.dataBroadcaster.DataBroadcastPlugin;
2019-02-28 23:16:50 +01:00
import info.nightscout.androidaps.plugins.general.food.FoodPlugin;
import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
2019-03-02 14:37:53 +01:00
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
2019-12-30 00:53:44 +01:00
import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin;
2019-03-02 14:37:53 +01:00
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
2019-12-28 15:00:16 +01:00
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatusLinePlugin;
2019-03-02 14:37:53 +01:00
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefUltraRapidActingPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
2019-02-28 23:16:50 +01:00
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
2019-02-26 20:38:27 +01:00
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin;
import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
2019-02-26 20:38:27 +01:00
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
2019-02-28 23:16:50 +01:00
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
2019-12-30 23:26:48 +01:00
import info.nightscout.androidaps.plugins.source.DexcomPlugin;
import info.nightscout.androidaps.plugins.source.EversensePlugin;
import info.nightscout.androidaps.plugins.source.GlimpPlugin;
import info.nightscout.androidaps.plugins.source.MM640gPlugin;
2020-01-10 23:14:58 +01:00
import info.nightscout.androidaps.plugins.source.NSClientSourcePlugin;
2019-12-30 23:26:48 +01:00
import info.nightscout.androidaps.plugins.source.PoctechPlugin;
2020-01-10 23:14:58 +01:00
import info.nightscout.androidaps.plugins.source.RandomBgPlugin;
2019-12-30 23:26:48 +01:00
import info.nightscout.androidaps.plugins.source.TomatoPlugin;
import info.nightscout.androidaps.plugins.source.XdripPlugin;
2019-02-28 23:16:50 +01:00
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.receivers.ChargingStateReceiver;
2017-07-24 01:50:27 +02:00
import info.nightscout.androidaps.receivers.DataReceiver;
2016-12-16 02:00:53 +01:00
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
import info.nightscout.androidaps.receivers.NetworkChangeReceiver;
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver;
2018-07-29 15:37:28 +02:00
import info.nightscout.androidaps.services.Intents;
2019-12-13 02:12:19 +01:00
import info.nightscout.androidaps.utils.ActivityMonitor;
2019-02-26 20:38:27 +01:00
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.LocaleHelper;
2020-01-03 14:30:39 +01:00
import info.nightscout.androidaps.utils.resources.ResourceHelper;
2020-03-16 22:49:34 +01:00
import info.nightscout.androidaps.utils.sharedPreferences.SP;
2016-06-24 17:48:11 +02:00
import io.fabric.sdk.android.Fabric;
2016-06-05 01:40:35 +02:00
2019-12-21 20:17:08 +01:00
public class MainApp extends DaggerApplication {
2016-06-05 01:40:35 +02:00
2019-12-21 20:17:08 +01:00
static MainApp sInstance;
2020-01-02 23:25:29 +01:00
private static Resources sResources;
2016-06-05 01:40:35 +02:00
2020-01-03 14:30:39 +01:00
static FirebaseAnalytics firebaseAnalytics;
2019-04-05 00:32:26 +02:00
2019-12-21 20:17:08 +01:00
static DatabaseHelper sDatabaseHelper = null;
2016-06-05 01:40:35 +02:00
2020-03-16 22:49:34 +01:00
DataReceiver dataReceiver = new DataReceiver();
TimeDateOrTZChangeReceiver timeDateOrTZChangeReceiver;
2017-07-24 01:50:27 +02:00
2020-01-06 20:34:14 +01:00
private String CHANNEL_ID = "AndroidAPS-Ongoing"; // TODO: move to OngoingNotificationProvider (and dagger)
private int ONGOING_NOTIFICATION_ID = 4711; // TODO: move to OngoingNotificationProvider (and dagger)
private Notification notification; // TODO: move to OngoingNotificationProvider (and dagger)
2020-01-03 14:30:39 +01:00
2020-03-16 21:40:29 +01:00
@Inject PluginStore pluginStore;
2020-03-10 18:58:27 +01:00
@Inject public HasAndroidInjector injector;
2019-12-31 09:41:02 +01:00
@Inject AAPSLogger aapsLogger;
@Inject ActivityMonitor activityMonitor;
2020-01-03 14:30:39 +01:00
@Inject FabricPrivacy fabricPrivacy;
@Inject ResourceHelper resourceHelper;
2020-01-03 16:29:59 +01:00
@Inject VersionCheckerUtils versionCheckersUtils;
2020-03-16 22:49:34 +01:00
@Inject SP sp;
@Inject ProfileFunction profileFunction;
2019-12-30 00:53:44 +01:00
@Inject ActionsPlugin actionsPlugin;
@Inject AutomationPlugin automationPlugin;
2020-01-10 23:14:58 +01:00
@Inject ComboPlugin comboPlugin;
2019-12-30 00:53:44 +01:00
@Inject CareportalPlugin careportalPlugin;
2019-12-28 15:00:16 +01:00
@Inject ConfigBuilderPlugin configBuilderPlugin;
2019-12-30 00:53:44 +01:00
@Inject DanaRPlugin danaRPlugin;
@Inject DanaRSPlugin danaRSPlugin;
@Inject DanaRv2Plugin danaRv2Plugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin;
2020-01-28 18:00:46 +01:00
@Inject DataBroadcastPlugin dataBroadcastPlugin;
2020-01-02 20:48:36 +01:00
@Inject DstHelperPlugin dstHelperPlugin;
2020-01-02 23:58:21 +01:00
@Inject FoodPlugin foodPlugin;
@Inject InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
@Inject InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin;
@Inject InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin;
2019-12-30 13:40:42 +01:00
@Inject IobCobCalculatorPlugin iobCobCalculatorPlugin;
2020-01-10 23:14:58 +01:00
@Inject LocalInsightPlugin localInsightPlugin;
2019-12-30 00:53:44 +01:00
@Inject LocalProfilePlugin localProfilePlugin;
2019-12-30 11:35:49 +01:00
@Inject LoopPlugin loopPlugin;
2020-01-10 23:14:58 +01:00
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject MDIPlugin mdiPlugin;
@Inject NSProfilePlugin nsProfilePlugin;
2019-12-30 00:53:44 +01:00
@Inject ObjectivesPlugin objectivesPlugin;
2019-12-28 01:14:04 +01:00
@Inject SafetyPlugin safetyPlugin;
@Inject SmsCommunicatorPlugin smsCommunicatorPlugin;
2019-12-28 01:14:04 +01:00
@Inject OpenAPSMAPlugin openAPSMAPlugin;
@Inject OpenAPSAMAPlugin openAPSAMAPlugin;
@Inject OpenAPSSMBPlugin openAPSSMBPlugin;
2019-12-30 00:53:44 +01:00
@Inject OverviewPlugin overviewPlugin;
2020-01-02 23:25:29 +01:00
@Inject PersistentNotificationPlugin persistentNotificationPlugin;
2019-12-30 10:02:40 +01:00
@Inject RandomBgPlugin randomBgPlugin;
2020-01-10 23:14:58 +01:00
@Inject SensitivityOref1Plugin sensitivityOref1Plugin;
@Inject SensitivityAAPSPlugin sensitivityAAPSPlugin;
@Inject SensitivityOref0Plugin sensitivityOref0Plugin;
@Inject SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin;
2020-01-03 14:30:39 +01:00
@Inject SignatureVerifierPlugin signatureVerifierPlugin;
2020-01-10 23:14:58 +01:00
@Inject StorageConstraintPlugin storageConstraintPlugin;
2019-12-30 23:26:48 +01:00
@Inject DexcomPlugin dexcomPlugin;
@Inject EversensePlugin eversensePlugin;
@Inject GlimpPlugin glimpPlugin;
2020-01-01 23:23:16 +01:00
@Inject MaintenancePlugin maintenancePlugin;
2019-12-30 23:26:48 +01:00
@Inject MM640gPlugin mM640GPlugin;
2020-01-10 23:14:58 +01:00
@Inject NSClientPlugin nsClientPlugin;
2019-12-30 23:26:48 +01:00
@Inject NSClientSourcePlugin nSClientSourcePlugin;
@Inject PoctechPlugin poctechPlugin;
@Inject TomatoPlugin tomatoPlugin;
@Inject XdripPlugin xdripPlugin;
2019-12-28 15:00:16 +01:00
@Inject StatusLinePlugin statusLinePlugin;
2019-12-30 00:53:44 +01:00
@Inject TidepoolPlugin tidepoolPlugin;
2019-12-28 22:51:04 +01:00
@Inject TreatmentsPlugin treatmentsPlugin;
2019-12-30 00:53:44 +01:00
@Inject VirtualPumpPlugin virtualPumpPlugin;
@Inject VersionCheckerPlugin versionCheckerPlugin;
2019-12-30 19:52:51 +01:00
@Inject WearPlugin wearPlugin;
2020-01-06 15:22:28 +01:00
@Inject KeepAliveReceiver.KeepAliveManager keepAliveManager;
2019-12-23 13:27:15 +01:00
2016-06-05 01:40:35 +02:00
@Override
public void onCreate() {
super.onCreate();
2019-12-13 02:12:19 +01:00
2020-03-16 22:49:34 +01:00
aapsLogger.debug("onCreate");
2018-02-22 13:30:36 +01:00
sInstance = this;
sResources = getResources();
LocaleHelper.INSTANCE.update(this);
2020-01-03 14:30:39 +01:00
generateEmptyNotification();
2018-03-31 00:36:03 +02:00
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
2018-02-22 13:30:36 +01:00
/* TODO: put back
Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> {
if (ex instanceof InternalError) {
// usually the app trying to spawn a thread while being killed
return;
}
log.error("Uncaught exception crashing app", ex);
});
*/
2018-02-22 13:30:36 +01:00
try {
2020-01-03 14:30:39 +01:00
if (fabricPrivacy.fabricEnabled()) {
2018-02-22 13:30:36 +01:00
Fabric.with(this, new Crashlytics());
}
} catch (Exception e) {
2020-03-16 22:49:34 +01:00
aapsLogger.error("Error with Fabric init! " + e);
2018-02-22 13:30:36 +01:00
}
2019-12-31 09:41:02 +01:00
registerActivityLifecycleCallbacks(activityMonitor);
2019-10-15 23:50:09 +02:00
2020-01-03 14:30:39 +01:00
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
firebaseAnalytics.setAnalyticsCollectionEnabled(!Boolean.getBoolean("disableFirebase") && fabricPrivacy.fabricEnabled());
2019-04-05 00:32:26 +02:00
2017-12-22 02:55:40 +01:00
JodaTimeAndroid.init(this);
2018-02-22 13:30:36 +01:00
2020-03-16 22:49:34 +01:00
aapsLogger.debug("Version: " + BuildConfig.VERSION_NAME);
aapsLogger.debug("BuildVersion: " + BuildConfig.BUILDVERSION);
aapsLogger.debug("Remote: " + BuildConfig.REMOTE);
2016-06-05 01:40:35 +02:00
2017-07-24 01:50:27 +02:00
registerLocalBroadcastReceiver();
2019-04-22 14:10:12 +02:00
//trigger here to see the new version on app start after an update
2020-01-03 16:29:59 +01:00
versionCheckersUtils.triggerCheckVersion();
2019-04-22 14:10:12 +02:00
2020-01-10 23:14:58 +01:00
// Register all tabs in app here
2020-03-16 21:40:29 +01:00
pluginStore.add(overviewPlugin);
pluginStore.add(iobCobCalculatorPlugin);
if (!Config.NSCLIENT) pluginStore.add(actionsPlugin);
pluginStore.add(insulinOrefRapidActingPlugin);
pluginStore.add(insulinOrefUltraRapidActingPlugin);
pluginStore.add(insulinOrefFreePeakPlugin);
pluginStore.add(sensitivityOref0Plugin);
pluginStore.add(sensitivityAAPSPlugin);
pluginStore.add(sensitivityWeightedAveragePlugin);
pluginStore.add(sensitivityOref1Plugin);
if (Config.PUMPDRIVERS) pluginStore.add(danaRPlugin);
if (Config.PUMPDRIVERS) pluginStore.add(danaRKoreanPlugin);
if (Config.PUMPDRIVERS) pluginStore.add(danaRv2Plugin);
if (Config.PUMPDRIVERS) pluginStore.add(danaRSPlugin);
if (Config.PUMPDRIVERS) pluginStore.add(localInsightPlugin);
if (Config.PUMPDRIVERS) pluginStore.add(comboPlugin);
if (Config.PUMPDRIVERS) pluginStore.add(medtronicPumpPlugin);
if (!Config.NSCLIENT) pluginStore.add(mdiPlugin);
if (!Config.NSCLIENT) pluginStore.add(virtualPumpPlugin);
if (Config.NSCLIENT) pluginStore.add(careportalPlugin);
if (Config.APS) pluginStore.add(loopPlugin);
if (Config.APS) pluginStore.add(openAPSMAPlugin);
if (Config.APS) pluginStore.add(openAPSAMAPlugin);
if (Config.APS) pluginStore.add(openAPSSMBPlugin);
pluginStore.add(nsProfilePlugin);
if (!Config.NSCLIENT) pluginStore.add(localProfilePlugin);
pluginStore.add(treatmentsPlugin);
if (!Config.NSCLIENT) pluginStore.add(safetyPlugin);
if (!Config.NSCLIENT) pluginStore.add(versionCheckerPlugin);
if (Config.APS) pluginStore.add(storageConstraintPlugin);
if (Config.APS) pluginStore.add(signatureVerifierPlugin);
if (Config.APS) pluginStore.add(objectivesPlugin);
pluginStore.add(xdripPlugin);
pluginStore.add(nSClientSourcePlugin);
pluginStore.add(mM640GPlugin);
pluginStore.add(glimpPlugin);
pluginStore.add(dexcomPlugin);
pluginStore.add(poctechPlugin);
pluginStore.add(tomatoPlugin);
pluginStore.add(eversensePlugin);
pluginStore.add(randomBgPlugin);
if (!Config.NSCLIENT) pluginStore.add(smsCommunicatorPlugin);
pluginStore.add(foodPlugin);
pluginStore.add(wearPlugin);
pluginStore.add(statusLinePlugin);
pluginStore.add(persistentNotificationPlugin);
pluginStore.add(nsClientPlugin);
2019-12-30 00:53:44 +01:00
// if (engineeringMode) pluginsList.add(tidepoolPlugin);
2020-03-16 21:40:29 +01:00
pluginStore.add(maintenancePlugin);
pluginStore.add(automationPlugin);
pluginStore.add(dstHelperPlugin);
pluginStore.add(dataBroadcastPlugin);
2020-03-16 21:40:29 +01:00
pluginStore.add(configBuilderPlugin);
2020-01-10 23:14:58 +01:00
configBuilderPlugin.initialize();
NSUpload.uploadAppStart();
2017-08-23 13:28:07 +02:00
2020-01-06 15:22:28 +01:00
new Thread(() -> keepAliveManager.setAlarm(this)).start();
2019-12-13 13:12:36 +01:00
doMigrations();
}
2019-12-13 13:12:36 +01:00
private void doMigrations() {
// guarantee that the unreachable threshold is at least 30 and of type String
// Added in 1.57 at 21.01.2018
2020-03-16 22:49:34 +01:00
int unreachable_threshold = sp.getInt(R.string.key_pump_unreachable_threshold, 30);
sp.remove(R.string.key_pump_unreachable_threshold);
2019-12-13 13:12:36 +01:00
if (unreachable_threshold < 30) unreachable_threshold = 30;
2020-03-16 22:49:34 +01:00
sp.putString(R.string.key_pump_unreachable_threshold, Integer.toString(unreachable_threshold));
2019-12-13 13:12:36 +01:00
// 2.5 -> 2.6
2020-03-16 22:49:34 +01:00
if (!sp.contains(R.string.key_units)) {
2019-12-13 13:12:36 +01:00
String newUnits = Constants.MGDL;
2020-03-16 22:49:34 +01:00
Profile p = profileFunction.getProfile();
2019-12-13 13:12:36 +01:00
if (p != null && p.getData() != null && p.getData().has("units")) {
try {
newUnits = p.getData().getString("units");
} catch (JSONException e) {
2020-03-16 22:49:34 +01:00
aapsLogger.error("Unhandled exception", e);
2019-12-13 13:12:36 +01:00
}
}
2020-03-16 22:49:34 +01:00
sp.putString(R.string.key_units, newUnits);
2019-12-13 13:12:36 +01:00
}
2017-07-24 01:50:27 +02:00
}
2019-12-21 20:17:08 +01:00
@Override
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
return DaggerAppComponent
.builder()
.application(this)
.build();
}
2017-07-24 01:50:27 +02:00
private void registerLocalBroadcastReceiver() {
2019-12-24 16:07:17 +01:00
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
2017-07-24 01:50:27 +02:00
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
2017-07-24 01:55:01 +02:00
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
2017-07-24 01:58:23 +02:00
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
2017-07-24 02:02:54 +02:00
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG));
2017-07-24 02:09:26 +02:00
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL));
this.timeDateOrTZChangeReceiver = new TimeDateOrTZChangeReceiver();
this.timeDateOrTZChangeReceiver.registerBroadcasts(this);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
2020-03-16 22:49:34 +01:00
intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
registerReceiver(new NetworkChangeReceiver(), intentFilter);
registerReceiver(new ChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
2016-12-16 02:00:53 +01:00
}
2019-12-30 00:53:44 +01:00
@Deprecated
2019-12-24 16:07:17 +01:00
public static String gs(@StringRes int id) {
2018-01-14 21:42:36 +01:00
return sResources.getString(id);
}
2019-12-30 00:53:44 +01:00
@Deprecated
2019-12-24 16:07:17 +01:00
public static String gs(@StringRes int id, Object... args) {
return sResources.getString(id, args);
}
2019-12-30 00:53:44 +01:00
@Deprecated
2019-12-24 16:07:17 +01:00
public static int gc(@ColorRes int id) {
return ContextCompat.getColor(instance(), id);
2018-03-10 19:22:31 +01:00
}
2020-01-02 23:25:29 +01:00
@Deprecated
public static Resources resources() {
return sResources;
}
2019-12-30 00:53:44 +01:00
@Deprecated
2016-06-05 01:40:35 +02:00
public static MainApp instance() {
return sInstance;
}
public static DatabaseHelper getDbHelper() {
2016-07-07 10:34:20 +02:00
return sDatabaseHelper;
2016-06-05 01:40:35 +02:00
}
2020-01-03 14:30:39 +01:00
public FirebaseAnalytics getFirebaseAnalytics() {
return firebaseAnalytics;
2019-04-05 00:32:26 +02:00
}
2020-01-03 14:30:39 +01:00
// global Notification has been moved to MainApp because PersistentNotificationPlugin is initialized too late
private void generateEmptyNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
builder.setOngoing(true)
.setOnlyAlertOnce(true)
.setCategory(NotificationCompat.CATEGORY_STATUS)
.setSmallIcon(resourceHelper.getNotificationIcon())
.setLargeIcon(resourceHelper.decodeResource(resourceHelper.getIcon()));
builder.setContentTitle(resourceHelper.gs(R.string.loading));
Intent resultIntent = new Intent(this, MainApp.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notification = builder.build();
mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification);
}
public int notificationId() {
return ONGOING_NOTIFICATION_ID;
}
public String channelId() {
return CHANNEL_ID;
}
public void setNotification(Notification notification) {
this.notification = notification;
}
public Notification getNotification() {
2020-01-10 23:14:58 +01:00
return notification;
2020-01-03 14:30:39 +01:00
}
2016-06-05 01:40:35 +02:00
@Override
public void onTerminate() {
2019-12-28 01:52:20 +01:00
aapsLogger.debug(LTag.CORE, "onTerminate");
2019-12-24 16:07:17 +01:00
if (timeDateOrTZChangeReceiver != null)
unregisterReceiver(timeDateOrTZChangeReceiver);
2019-12-31 09:41:02 +01:00
unregisterActivityLifecycleCallbacks(activityMonitor);
2020-01-06 15:22:28 +01:00
keepAliveManager.cancelAlarm(this);
2019-12-24 16:07:17 +01:00
super.onTerminate();
2016-06-05 01:40:35 +02:00
}
2016-12-16 02:00:53 +01:00
}