2016-06-05 01:40:35 +02:00
|
|
|
package info.nightscout.androidaps;
|
|
|
|
|
|
|
|
import android.app.Application;
|
2017-07-24 01:50:27 +02:00
|
|
|
import android.content.IntentFilter;
|
2016-06-24 17:16:17 +02:00
|
|
|
import android.content.res.Resources;
|
2017-09-06 20:00:36 +02:00
|
|
|
import android.os.SystemClock;
|
2016-07-18 20:19:55 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2018-06-09 22:07:41 +02:00
|
|
|
import android.support.annotation.PluralsRes;
|
2017-07-24 01:50:27 +02:00
|
|
|
import android.support.v4.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;
|
|
|
|
import com.squareup.otto.Bus;
|
2017-10-14 17:24:01 +02:00
|
|
|
import com.squareup.otto.LoggingBus;
|
2016-06-05 01:40:35 +02:00
|
|
|
import com.squareup.otto.ThreadEnforcer;
|
|
|
|
|
2017-12-22 02:55:40 +01:00
|
|
|
import net.danlew.android.joda.JodaTimeAndroid;
|
|
|
|
|
2016-08-05 23:54:03 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-03-05 22:30:48 +01:00
|
|
|
import java.io.File;
|
2016-08-05 23:54:03 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2018-03-19 18:21:02 +01:00
|
|
|
import info.nightscout.androidaps.data.ConstraintChecker;
|
2016-08-05 23:54:03 +02:00
|
|
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
2016-07-18 20:19:55 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
2018-03-31 00:36:03 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginType;
|
|
|
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
2018-07-29 15:37:28 +02:00
|
|
|
import info.nightscout.androidaps.logging.L;
|
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;
|
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;
|
2019-03-07 10:32:29 +01:00
|
|
|
import info.nightscout.androidaps.plugins.constraints.storage.StorageConstraintPlugin;
|
2019-03-02 14:37:53 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.actions.ActionsFragment;
|
|
|
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
|
2019-02-28 23:16:50 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.food.FoodPlugin;
|
2019-03-02 14:37:53 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.maintenance.LoggerUtils;
|
2019-02-28 23:16:50 +01:00
|
|
|
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.nsclient.receivers.AckAlarmReceiver;
|
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.receivers.DBAccessReceiver;
|
|
|
|
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;
|
|
|
|
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
|
|
|
|
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;
|
|
|
|
import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin;
|
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.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;
|
|
|
|
import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin;
|
|
|
|
import info.nightscout.androidaps.plugins.source.SourceDexcomG6Plugin;
|
|
|
|
import info.nightscout.androidaps.plugins.source.SourceEversensePlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.source.SourceGlimpPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.source.SourceMM640gPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.source.SourceNSClientPlugin;
|
|
|
|
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.plugins.treatments.TreatmentsPlugin;
|
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;
|
2017-07-24 02:27:16 +02:00
|
|
|
import info.nightscout.androidaps.receivers.NSAlarmReceiver;
|
2018-07-29 15:37:28 +02:00
|
|
|
import info.nightscout.androidaps.services.Intents;
|
2019-02-26 20:38:27 +01:00
|
|
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
2016-06-24 17:48:11 +02:00
|
|
|
import io.fabric.sdk.android.Fabric;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
|
|
|
|
2016-08-05 23:54:03 +02:00
|
|
|
public class MainApp extends Application {
|
2018-07-29 15:37:28 +02:00
|
|
|
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
2016-12-16 02:00:53 +01:00
|
|
|
private static KeepAliveReceiver keepAliveReceiver;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
|
|
|
private static Bus sBus;
|
|
|
|
private static MainApp sInstance;
|
2016-07-07 10:34:20 +02:00
|
|
|
public static Resources sResources;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
2019-04-05 00:32:26 +02:00
|
|
|
private static FirebaseAnalytics mFirebaseAnalytics;
|
|
|
|
|
2016-07-07 10:34:20 +02:00
|
|
|
private static DatabaseHelper sDatabaseHelper = null;
|
2018-03-19 18:21:02 +01:00
|
|
|
private static ConstraintChecker sConstraintsChecker = null;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
2016-07-18 20:19:55 +02:00
|
|
|
private static ArrayList<PluginBase> pluginsList = null;
|
|
|
|
|
2017-07-24 01:50:27 +02:00
|
|
|
private static DataReceiver dataReceiver = new DataReceiver();
|
2017-07-24 02:27:16 +02:00
|
|
|
private static NSAlarmReceiver alarmReciever = new NSAlarmReceiver();
|
2017-07-24 02:33:29 +02:00
|
|
|
private static AckAlarmReceiver ackAlarmReciever = new AckAlarmReceiver();
|
2018-08-15 22:09:13 +02:00
|
|
|
private static DBAccessReceiver dbAccessReciever = new DBAccessReceiver();
|
2017-07-24 01:50:27 +02:00
|
|
|
private LocalBroadcastManager lbm;
|
|
|
|
|
2018-03-05 22:30:48 +01:00
|
|
|
public static boolean devBranch;
|
|
|
|
public static boolean engineeringMode;
|
|
|
|
|
2016-06-05 01:40:35 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2018-08-07 21:45:35 +02:00
|
|
|
log.debug("onCreate");
|
2018-02-22 13:30:36 +01:00
|
|
|
sInstance = this;
|
|
|
|
sResources = getResources();
|
2018-03-19 18:21:02 +01:00
|
|
|
sConstraintsChecker = new ConstraintChecker(this);
|
2018-03-31 00:36:03 +02:00
|
|
|
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
|
2018-02-22 13:30:36 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (FabricPrivacy.fabricEnabled()) {
|
|
|
|
Fabric.with(this, new Crashlytics());
|
|
|
|
Crashlytics.setString("BUILDVERSION", BuildConfig.BUILDVERSION);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2018-07-29 15:37:28 +02:00
|
|
|
log.error("Error with Fabric init! " + e);
|
2018-02-22 13:30:36 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 00:32:26 +02:00
|
|
|
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
|
|
|
|
2017-12-22 02:55:40 +01:00
|
|
|
JodaTimeAndroid.init(this);
|
2018-02-22 13:30:36 +01:00
|
|
|
|
2016-11-08 19:10:25 +01:00
|
|
|
log.info("Version: " + BuildConfig.VERSION_NAME);
|
|
|
|
log.info("BuildVersion: " + BuildConfig.BUILDVERSION);
|
2016-06-05 01:40:35 +02:00
|
|
|
|
2018-07-23 20:58:20 +02:00
|
|
|
String extFilesDir = LoggerUtils.getLogDirectory();
|
2018-03-31 00:36:03 +02:00
|
|
|
File engineeringModeSemaphore = new File(extFilesDir, "engineering_mode");
|
2018-03-18 19:48:41 +01:00
|
|
|
|
|
|
|
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile();
|
|
|
|
devBranch = BuildConfig.VERSION.contains("dev");
|
|
|
|
|
2018-08-29 08:10:06 +02:00
|
|
|
sBus = L.isEnabled(L.EVENTS) && devBranch ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY);
|
2017-10-14 15:24:41 +02:00
|
|
|
|
2017-07-24 01:50:27 +02:00
|
|
|
registerLocalBroadcastReceiver();
|
|
|
|
|
2016-07-18 20:19:55 +02:00
|
|
|
if (pluginsList == null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
pluginsList = new ArrayList<>();
|
2016-07-18 20:19:55 +02:00
|
|
|
// Register all tabs in app here
|
2017-10-06 16:39:59 +02:00
|
|
|
pluginsList.add(OverviewPlugin.getPlugin());
|
2017-06-24 13:22:50 +02:00
|
|
|
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
|
2017-02-23 20:00:33 +01:00
|
|
|
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
2017-08-31 22:00:45 +02:00
|
|
|
pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin());
|
|
|
|
pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin());
|
|
|
|
pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin());
|
2017-06-24 11:04:09 +02:00
|
|
|
pluginsList.add(SensitivityOref0Plugin.getPlugin());
|
2017-06-30 11:56:36 +02:00
|
|
|
pluginsList.add(SensitivityAAPSPlugin.getPlugin());
|
2017-07-07 15:08:21 +02:00
|
|
|
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
2018-06-19 20:41:40 +02:00
|
|
|
pluginsList.add(SensitivityOref1Plugin.getPlugin());
|
2018-08-07 21:07:43 +02:00
|
|
|
if (Config.PUMPDRIVERS) pluginsList.add(DanaRPlugin.getPlugin());
|
|
|
|
if (Config.PUMPDRIVERS) pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
|
|
|
if (Config.PUMPDRIVERS) pluginsList.add(DanaRv2Plugin.getPlugin());
|
|
|
|
if (Config.PUMPDRIVERS) pluginsList.add(DanaRSPlugin.getPlugin());
|
2019-03-02 12:18:06 +01:00
|
|
|
if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin());
|
2017-11-01 20:43:59 +01:00
|
|
|
pluginsList.add(CareportalPlugin.getPlugin());
|
2018-08-07 21:07:43 +02:00
|
|
|
if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin());
|
2017-06-24 13:22:50 +02:00
|
|
|
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
|
2018-03-31 21:41:14 +02:00
|
|
|
pluginsList.add(VirtualPumpPlugin.getPlugin());
|
2017-11-01 20:43:59 +01:00
|
|
|
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
|
|
|
|
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
|
|
|
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
2017-11-01 20:50:14 +01:00
|
|
|
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
2017-10-07 17:48:03 +02:00
|
|
|
pluginsList.add(NSProfilePlugin.getPlugin());
|
|
|
|
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
|
2018-01-21 13:37:38 +01:00
|
|
|
if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin());
|
2017-10-07 17:48:03 +02:00
|
|
|
pluginsList.add(TreatmentsPlugin.getPlugin());
|
2017-06-24 13:22:50 +02:00
|
|
|
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
2019-03-07 10:32:29 +01:00
|
|
|
if (Config.SAFETY) pluginsList.add(StorageConstraintPlugin.getPlugin());
|
2017-10-06 16:39:59 +02:00
|
|
|
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
2018-08-14 16:06:02 +02:00
|
|
|
pluginsList.add(SourceXdripPlugin.getPlugin());
|
2018-08-07 21:45:35 +02:00
|
|
|
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
2018-08-14 16:06:02 +02:00
|
|
|
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
|
|
|
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
|
|
|
pluginsList.add(SourceDexcomG5Plugin.getPlugin());
|
2018-12-01 10:51:53 +01:00
|
|
|
pluginsList.add(SourceDexcomG6Plugin.getPlugin());
|
2018-08-14 16:06:02 +02:00
|
|
|
pluginsList.add(SourcePoctechPlugin.getPlugin());
|
2019-02-19 16:26:16 +01:00
|
|
|
pluginsList.add(SourceTomatoPlugin.getPlugin());
|
2018-12-11 21:56:57 +01:00
|
|
|
pluginsList.add(SourceEversensePlugin.getPlugin());
|
2017-10-07 17:48:03 +02:00
|
|
|
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
2017-10-17 20:55:23 +02:00
|
|
|
pluginsList.add(FoodPlugin.getPlugin());
|
2016-11-17 16:38:58 +01:00
|
|
|
|
2017-11-01 20:43:59 +01:00
|
|
|
pluginsList.add(WearPlugin.initPlugin(this));
|
|
|
|
pluginsList.add(StatuslinePlugin.initPlugin(this));
|
2018-06-17 23:33:32 +02:00
|
|
|
pluginsList.add(PersistentNotificationPlugin.getPlugin());
|
2018-03-23 22:44:37 +01:00
|
|
|
pluginsList.add(NSClientPlugin.getPlugin());
|
2018-07-28 22:45:40 +02:00
|
|
|
pluginsList.add(MaintenancePlugin.initPlugin(this));
|
2016-11-17 16:38:58 +01:00
|
|
|
|
2018-09-17 19:56:56 +02:00
|
|
|
pluginsList.add(ConfigBuilderPlugin.getPlugin());
|
2016-07-18 20:19:55 +02:00
|
|
|
|
2018-11-06 10:25:39 +01:00
|
|
|
pluginsList.add(DstHelperPlugin.getPlugin());
|
|
|
|
|
2019-03-07 10:32:29 +01:00
|
|
|
|
2018-09-17 19:56:56 +02:00
|
|
|
ConfigBuilderPlugin.getPlugin().initialize();
|
2016-07-18 20:19:55 +02:00
|
|
|
}
|
2018-03-19 17:06:22 +01:00
|
|
|
|
2018-07-10 17:55:50 +02:00
|
|
|
NSUpload.uploadAppStart();
|
2017-08-23 13:28:07 +02:00
|
|
|
|
2018-09-17 17:43:42 +02:00
|
|
|
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
2018-03-31 00:36:03 +02:00
|
|
|
if (pump != null) {
|
|
|
|
new Thread(() -> {
|
2017-09-06 20:00:36 +02:00
|
|
|
SystemClock.sleep(5000);
|
2018-09-17 19:29:01 +02:00
|
|
|
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Initialization", null);
|
2017-10-25 17:49:23 +02:00
|
|
|
startKeepAliveService();
|
2018-03-31 00:36:03 +02:00
|
|
|
}).start();
|
|
|
|
}
|
2017-07-24 01:50:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void registerLocalBroadcastReceiver() {
|
|
|
|
lbm = LocalBroadcastManager.getInstance(this);
|
|
|
|
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-10-17 20:55:23 +02:00
|
|
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_FOOD));
|
|
|
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_FOOD));
|
|
|
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_FOOD));
|
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:00:46 +02:00
|
|
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS));
|
2017-07-24 02:02:54 +02:00
|
|
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG));
|
2017-07-24 02:06:05 +02:00
|
|
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_DEVICESTATUS));
|
2017-07-24 02:09:26 +02:00
|
|
|
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL));
|
|
|
|
|
2017-07-24 02:27:16 +02:00
|
|
|
//register alarms
|
|
|
|
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ALARM));
|
|
|
|
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ANNOUNCEMENT));
|
|
|
|
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_CLEAR_ALARM));
|
|
|
|
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_URGENT_ALARM));
|
|
|
|
|
|
|
|
//register ack alarm
|
2017-07-24 02:33:29 +02:00
|
|
|
lbm.registerReceiver(ackAlarmReciever, new IntentFilter(Intents.ACTION_ACK_ALARM));
|
2018-08-15 22:09:13 +02:00
|
|
|
|
|
|
|
//register dbaccess
|
|
|
|
lbm.registerReceiver(dbAccessReciever, new IntentFilter(Intents.ACTION_DATABASE));
|
2016-12-16 02:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void startKeepAliveService() {
|
|
|
|
if (keepAliveReceiver == null) {
|
|
|
|
keepAliveReceiver = new KeepAliveReceiver();
|
|
|
|
keepAliveReceiver.setAlarm(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 16:37:27 +02:00
|
|
|
public void stopKeepAliveService() {
|
|
|
|
if (keepAliveReceiver != null)
|
2017-12-17 01:40:27 +01:00
|
|
|
KeepAliveReceiver.cancelAlarm(this);
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 22:36:52 +02:00
|
|
|
public static void subscribe(Object subscriber) {
|
|
|
|
try {
|
|
|
|
bus().register(subscriber);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// already registered
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unsubscribe(Object subscriber) {
|
|
|
|
try {
|
|
|
|
bus().unregister(subscriber);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// already unregistered
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 01:40:35 +02:00
|
|
|
public static Bus bus() {
|
|
|
|
return sBus;
|
|
|
|
}
|
2016-08-05 23:54:03 +02:00
|
|
|
|
2018-01-14 21:42:36 +01:00
|
|
|
public static String gs(int id) {
|
|
|
|
return sResources.getString(id);
|
|
|
|
}
|
|
|
|
|
2018-01-25 20:26:07 +01:00
|
|
|
public static String gs(int id, Object... args) {
|
|
|
|
return sResources.getString(id, args);
|
|
|
|
}
|
|
|
|
|
2018-06-09 22:07:41 +02:00
|
|
|
public static String gq(@PluralsRes int id, int quantity, Object... args) {
|
|
|
|
return sResources.getQuantityString(id, quantity, args);
|
|
|
|
}
|
|
|
|
|
2018-03-10 19:22:31 +01:00
|
|
|
public static int gc(int id) {
|
|
|
|
return sResources.getColor(id);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public static void closeDbHelper() {
|
2016-07-07 10:34:20 +02:00
|
|
|
if (sDatabaseHelper != null) {
|
|
|
|
sDatabaseHelper.close();
|
|
|
|
sDatabaseHelper = null;
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 00:32:26 +02:00
|
|
|
public static FirebaseAnalytics getFirebaseAnalytics() {
|
|
|
|
return mFirebaseAnalytics;
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:21:02 +01:00
|
|
|
public static ConstraintChecker getConstraintChecker() {
|
|
|
|
return sConstraintsChecker;
|
|
|
|
}
|
|
|
|
|
2016-07-18 20:19:55 +02:00
|
|
|
public static ArrayList<PluginBase> getPluginsList() {
|
|
|
|
return pluginsList;
|
|
|
|
}
|
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
public static ArrayList<PluginBase> getSpecificPluginsList(PluginType type) {
|
2016-08-05 23:54:03 +02:00
|
|
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
2016-07-18 20:19:55 +02:00
|
|
|
|
|
|
|
if (pluginsList != null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
for (PluginBase p : pluginsList) {
|
2016-07-18 20:19:55 +02:00
|
|
|
if (p.getType() == type)
|
|
|
|
newList.add(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(PluginType type) {
|
2017-04-29 16:59:44 +02:00
|
|
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
|
|
|
|
|
|
|
if (pluginsList != null) {
|
|
|
|
for (PluginBase p : pluginsList) {
|
|
|
|
if (p.getType() == type)
|
|
|
|
if (p.showInList(type))
|
|
|
|
newList.add(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
2016-07-18 20:19:55 +02:00
|
|
|
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
|
2016-08-05 23:54:03 +02:00
|
|
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
2016-07-18 20:19:55 +02:00
|
|
|
|
|
|
|
if (pluginsList != null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
for (PluginBase p : pluginsList) {
|
|
|
|
if (p.getClass() != ConfigBuilderPlugin.class && interfaceClass.isAssignableFrom(p.getClass()))
|
2016-07-18 20:19:55 +02:00
|
|
|
newList.add(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
public static ArrayList<PluginBase> getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type) {
|
2017-04-29 16:59:44 +02:00
|
|
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
|
|
|
|
|
|
|
if (pluginsList != null) {
|
|
|
|
for (PluginBase p : pluginsList) {
|
|
|
|
if (p.getClass() != ConfigBuilderPlugin.class && interfaceClass.isAssignableFrom(p.getClass()))
|
|
|
|
if (p.showInList(type))
|
|
|
|
newList.add(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
2016-07-18 20:19:55 +02:00
|
|
|
@Nullable
|
2017-08-19 03:22:43 +02:00
|
|
|
public static <T extends PluginBase> T getSpecificPlugin(Class<T> pluginClass) {
|
2016-07-18 20:19:55 +02:00
|
|
|
if (pluginsList != null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
for (PluginBase p : pluginsList) {
|
2017-08-19 03:22:43 +02:00
|
|
|
if (pluginClass.isAssignableFrom(p.getClass()))
|
|
|
|
return (T) p;
|
2016-07-18 20:19:55 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-03-18 17:38:05 +01:00
|
|
|
public static boolean isEngineeringModeOrRelease() {
|
2018-08-07 21:07:43 +02:00
|
|
|
if (!Config.APS)
|
2018-03-24 17:09:56 +01:00
|
|
|
return true;
|
2018-03-17 21:23:45 +01:00
|
|
|
return engineeringMode || !devBranch;
|
|
|
|
}
|
|
|
|
|
2018-05-02 18:39:37 +02:00
|
|
|
public static boolean isDev() {
|
|
|
|
return devBranch;
|
|
|
|
}
|
|
|
|
|
2019-03-02 14:37:53 +01:00
|
|
|
public static int getIcon() {
|
|
|
|
if (Config.NSCLIENT)
|
|
|
|
return R.mipmap.ic_yellowowl;
|
|
|
|
else if (Config.PUMPCONTROL)
|
|
|
|
return R.mipmap.ic_pumpcontrol;
|
|
|
|
else
|
|
|
|
return R.mipmap.ic_launcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getNotificationIcon() {
|
|
|
|
if (Config.NSCLIENT)
|
|
|
|
return R.drawable.ic_notif_nsclient;
|
|
|
|
else if (Config.PUMPCONTROL)
|
|
|
|
return R.drawable.ic_notif_pumpcontrol;
|
|
|
|
else
|
|
|
|
return R.drawable.ic_notif_aaps;
|
|
|
|
}
|
|
|
|
|
2016-06-05 01:40:35 +02:00
|
|
|
@Override
|
|
|
|
public void onTerminate() {
|
2018-07-29 15:37:28 +02:00
|
|
|
if (L.isEnabled(L.CORE))
|
|
|
|
log.debug("onTerminate");
|
2016-06-05 01:40:35 +02:00
|
|
|
super.onTerminate();
|
2018-03-31 15:00:32 +02:00
|
|
|
if (sDatabaseHelper != null) {
|
|
|
|
sDatabaseHelper.close();
|
|
|
|
sDatabaseHelper = null;
|
|
|
|
}
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
2016-12-16 02:00:53 +01:00
|
|
|
}
|