Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter#restartCollectionServiceBackground()
The following examples show how to use
com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter#restartCollectionServiceBackground() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StopSensor.java From xDrip with GNU General Public License v3.0 | 6 votes |
public synchronized static void stop() { Sensor.stopSensor(); Inevitable.task("stop-sensor",1000, Sensor::stopSensor); AlertPlayer.getPlayer().stopAlert(xdrip.getAppContext(), true, false); JoH.static_toast_long(gs(R.string.sensor_stopped)); JoH.clearCache(); LibreAlarmReceiver.clearSensorStats(); PluggableCalibration.invalidateAllCaches(); Ob1G5StateMachine.stopSensor(); CollectionServiceStarter.restartCollectionServiceBackground(); Home.staticRefreshBGCharts(); NanoStatus.keepFollowerUpdated(false); }
Example 2
Source File: StopSensor.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public synchronized static void stop() { Sensor.stopSensor(); Inevitable.task("stop-sensor",1000, Sensor::stopSensor); AlertPlayer.getPlayer().stopAlert(xdrip.getAppContext(), true, false); JoH.static_toast_long(gs(R.string.sensor_stopped)); JoH.clearCache(); LibreAlarmReceiver.clearSensorStats(); PluggableCalibration.invalidateAllCaches(); Ob1G5StateMachine.stopSensor(); CollectionServiceStarter.restartCollectionServiceBackground(); Home.staticRefreshBGCharts(); NanoStatus.keepFollowerUpdated(false); }
Example 3
Source File: BlueJayEntry.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { for (val hunt : HUNT_PREFERENCES) if (key.startsWith(hunt)) { android.util.Log.d("BlueJayPref", "Hit on Preference key: " + key); if (key.equals(PREF_PHONE_COLLECTOR_ENABLED)) { CollectionServiceStarter.restartCollectionServiceBackground(); } startWithRefresh(); break; } }
Example 4
Source File: BlueJayEntry.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { for (val hunt : HUNT_PREFERENCES) if (key.startsWith(hunt)) { android.util.Log.d("BlueJayPref", "Hit on Preference key: " + key); if (key.equals(PREF_PHONE_COLLECTOR_ENABLED)) { CollectionServiceStarter.restartCollectionServiceBackground(); } startWithRefresh(); break; } }
Example 5
Source File: Ob1G5CollectionService.java From xDrip with GNU General Public License v3.0 | 4 votes |
private synchronized void automata() { if ((last_automata_state != state) || state == INIT || (JoH.ratelimit("jam-g5-dupe-auto", 2))) { last_automata_state = state; final PowerManager.WakeLock wl = JoH.getWakeLock("jam-g5-automata", 60000); try { switch (state) { case INIT: initialize(); break; case SCAN: // no connection? lets try a restart if (JoH.msSince(static_last_connected) > 30 * 60 * 1000) { if (JoH.pratelimit("ob1-collector-restart", 1200)) { CollectionServiceStarter.restartCollectionServiceBackground(); break; } } // TODO check if we know mac!!! Sync as part of wear sync?? - TODO preload transmitter mac?? if (useMinimizeScanningStrategy()) { UserError.Log.d(TAG, "Skipping Scanning! : Changing state due to minimize_scanning flags"); changeState(CONNECT_NOW); } else { scan_for_device(); } break; case CONNECT_NOW: connect_to_device(false); break; case CONNECT: connect_to_device(true); break; case DISCOVER: if (wear_broadcast && usingAlt()) { msg("Pausing"); UserError.Log.d(TAG, "Pausing for alt: "); JoH.threadSleep(1000); } if (do_discovery) { discover_services(); } else { UserError.Log.d(TAG, "Skipping discovery"); changeState(STATE.CHECK_AUTH); } break; case CHECK_AUTH: if (do_auth) { final PowerManager.WakeLock linger_wl_connect = JoH.getWakeLock("jam-g5-check-linger", 6000); if (!Ob1G5StateMachine.doCheckAuth(this, connection)) resetState(); } else { UserError.Log.d(TAG, "Skipping authentication"); changeState(GET_DATA); } break; case PREBOND: if (!getInitiateBondingFlag()) { final PowerManager.WakeLock linger_wl_prebond = JoH.getWakeLock("jam-g5-prebond-linger", 16000); if (!Ob1G5StateMachine.doKeepAliveAndBondRequest(this, connection)) resetState(); } else { UserError.Log.d(TAG, "Going directly to initiate bond"); changeState(BOND); } break; case BOND: if (getInitiateBondingFlag()) { UserError.Log.d(TAG, "State bond attempting to create bond"); } else { UserError.Log.d(TAG, "State bond currently does nothing as setting disabled"); } create_bond(); break; case RESET: UserError.Log.d(TAG, "Entering hard reset state"); Ob1G5StateMachine.doReset(this, connection); break; case GET_DATA: if (hardResetTransmitterNow) { send_reset_command(); } else { final PowerManager.WakeLock linger_wl_get_data = JoH.getWakeLock("jam-g5-get-linger", 6000); if (!Ob1G5StateMachine.doGetData(this, connection)) resetState(); } break; case CLOSE: prepareToWakeup(); break; case CLOSED: handleWakeup(); break; } } finally { JoH.releaseWakeLock(wl); } } else { UserError.Log.d(TAG, "Ignoring duplicate automata state within 2 seconds: " + state); } }
Example 6
Source File: StartNewSensor.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static void startSensorForTime(long startTime) { Sensor.create(startTime); UserError.Log.ueh("NEW SENSOR", "Sensor started at " + JoH.dateTimeText(startTime)); JoH.static_toast_long(gs(R.string.new_sensor_started)); startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_SYNC_SENSOR, TAG); LibreAlarmReceiver.clearSensorStats(); // TODO this is just a timer and could be confusing - consider removing this notification // JoH.scheduleNotification(xdrip.getAppContext(), "Sensor should be ready", xdrip.getAppContext().getString(R.string.please_enter_two_calibrations_to_get_started), 60 * 130, Home.SENSOR_READY_ID); // reverse libre hacky workaround Treatments.SensorStart((DexCollectionType.hasLibre() ? startTime + (3600000) : startTime)); CollectionServiceStarter.restartCollectionServiceBackground(); Ob1G5StateMachine.startSensor(startTime); JoH.clearCache(); Home.staticRefreshBGCharts(); }
Example 7
Source File: MissedReadingService.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { final boolean bg_missed_alerts; final PowerManager.WakeLock wl = JoH.getWakeLock("missed-reading-service", 60000); try { final boolean sensorActive = Sensor.isActive(); Log.d(TAG, "MissedReadingService onHandleIntent"); // test debug log final long stale_millis = Home.stale_data_millis(); // send to pebble if (Pref.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType() != 1) && !BgReading.last_within_millis(stale_millis)) { if (JoH.ratelimit("peb-miss", 120)) { // TODO replace ratelimit with Inevitable.task? JoH.startService(PebbleWatchSync.class); } // update pebble even when we don't have data to ensure missed readings show } if (LeFunEntry.isEnabled() && (!BgReading.last_within_millis(stale_millis))) { LeFun.showLatestBG(); } if ((Pref.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() && if (!BgReading.last_within_millis(stale_millis) && sensorActive && (!getLocalServiceCollectingState())) { if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) { Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: " + aggressive_backoff_timer); if (aggressive_backoff_timer < 1200) aggressive_backoff_timer += 60; CollectionServiceStarter.restartCollectionServiceBackground(); } else { aggressive_backoff_timer = 120; // reset } } } Reminder.processAnyDueReminders(); BluetoothGlucoseMeter.immortality(); XdripWebService.immortality(); // InPenEntry.immortality(); DesertSync.pullAsEnabled(); NanoStatus.keepFollowerUpdated(); LockScreenWallPaper.timerPoll(); // TODO functionalize the actual checking bg_missed_alerts = Pref.getBoolean("bg_missed_alerts", false); if (!bg_missed_alerts) { // we should not do anything in this case. if the ui, changes will be called again return; } if (!sensorActive) { // sensor not running we should return return; } if (!JoH.upForAtLeastMins(15)) { Log.d(TAG, "Uptime less than 15 minutes so not processing for missed reading"); return; } if ((Home.get_forced_wear()) && Pref.getBoolean("disable_wearG5_on_missedreadings", false)) { int bg_wear_missed_minutes = Pref.getStringToInt("disable_wearG5_on_missedreadings_level", 30); if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) { Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected"); startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG); } } final int bg_missed_minutes = Pref.getStringToInt("bg_missed_minutes", 30); final long now = JoH.tsl(); // check if readings have been missed if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) && Pref.getLong("alerts_disabled_until", 0) <= now && (BgReading.getTimeSinceLastReading() < (Constants.HOUR_IN_MS * 6)) && inTimeFrame()) { Notifications.bgMissedAlert(xdrip.getAppContext()); checkBackAfterSnoozeTime(xdrip.getAppContext(), now); } else { long disabletime = Pref.getLong("alerts_disabled_until", 0) - now; long missedTime = bg_missed_minutes * 1000 * 60 - BgReading.getTimeSinceLastReading(); long alarmIn = Math.max(disabletime, missedTime); checkBackAfterMissedTime(alarmIn); } } finally { JoH.releaseWakeLock(wl); } }
Example 8
Source File: NightscoutFollow.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static void resetInstance() { retrofit = null; service = null; UserError.Log.d(TAG, "Instance reset"); CollectionServiceStarter.restartCollectionServiceBackground(); }
Example 9
Source File: xdrip.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate() { xdrip.context = getApplicationContext(); super.onCreate(); try { if (PreferenceManager.getDefaultSharedPreferences(xdrip.context).getBoolean("enable_crashlytics", true)) { initCrashlytics(this); initBF(); } } catch (Exception e) { Log.e(TAG, e.toString()); } executor = new PlusAsyncExecutor(); PreferenceManager.setDefaultValues(this, R.xml.pref_general, true); PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, true); PreferenceManager.setDefaultValues(this, R.xml.pref_advanced_settings, true); PreferenceManager.setDefaultValues(this, R.xml.pref_notifications, true); PreferenceManager.setDefaultValues(this, R.xml.pref_data_source, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_defaults, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_prefs, true); checkForcedEnglish(xdrip.context); JoH.ratelimit("policy-never", 3600); // don't on first load new IdempotentMigrations(getApplicationContext()).performAll(); JobManager.create(this).addJobCreator(new XDripJobCreator()); DailyJob.schedule(); //SyncService.startSyncServiceSoon(); if (!isRunningTest()) { MissedReadingService.delayedLaunch(); NFCReaderX.handleHomeScreenScanPreference(getApplicationContext()); AlertType.fromSettings(getApplicationContext()); //new CollectionServiceStarter(getApplicationContext()).start(getApplicationContext()); CollectionServiceStarter.restartCollectionServiceBackground(); PlusSyncService.startSyncService(context, "xdrip.java"); if (Pref.getBoolean("motion_tracking_enabled", false)) { ActivityRecognizedService.startActivityRecogniser(getApplicationContext()); } BluetoothGlucoseMeter.startIfEnabled(); LeFunEntry.initialStartIfEnabled(); MiBandEntry.initialStartIfEnabled(); BlueJayEntry.initialStartIfEnabled(); XdripWebService.immortality(); VersionTracker.updateDevice(); } else { Log.d(TAG, "Detected running test mode, holding back on background processes"); } Reminder.firstInit(xdrip.getAppContext()); PluggableCalibration.invalidateCache(); }
Example 10
Source File: Ob1G5CollectionService.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
private synchronized void automata() { if ((last_automata_state != state) || state == INIT || (JoH.ratelimit("jam-g5-dupe-auto", 2))) { last_automata_state = state; final PowerManager.WakeLock wl = JoH.getWakeLock("jam-g5-automata", 60000); try { switch (state) { case INIT: initialize(); break; case SCAN: // no connection? lets try a restart if (JoH.msSince(static_last_connected) > 30 * 60 * 1000) { if (JoH.pratelimit("ob1-collector-restart", 1200)) { CollectionServiceStarter.restartCollectionServiceBackground(); break; } } // TODO check if we know mac!!! Sync as part of wear sync?? - TODO preload transmitter mac?? if (useMinimizeScanningStrategy()) { UserError.Log.d(TAG, "Skipping Scanning! : Changing state due to minimize_scanning flags"); changeState(CONNECT_NOW); } else { scan_for_device(); } break; case CONNECT_NOW: connect_to_device(false); break; case CONNECT: connect_to_device(true); break; case DISCOVER: if (wear_broadcast && usingAlt()) { msg("Pausing"); UserError.Log.d(TAG, "Pausing for alt: "); JoH.threadSleep(1000); } if (do_discovery) { discover_services(); } else { UserError.Log.d(TAG, "Skipping discovery"); changeState(STATE.CHECK_AUTH); } break; case CHECK_AUTH: if (do_auth) { final PowerManager.WakeLock linger_wl_connect = JoH.getWakeLock("jam-g5-check-linger", 6000); if (!Ob1G5StateMachine.doCheckAuth(this, connection)) resetState(); } else { UserError.Log.d(TAG, "Skipping authentication"); changeState(GET_DATA); } break; case PREBOND: if (!getInitiateBondingFlag()) { final PowerManager.WakeLock linger_wl_prebond = JoH.getWakeLock("jam-g5-prebond-linger", 16000); if (!Ob1G5StateMachine.doKeepAliveAndBondRequest(this, connection)) resetState(); } else { UserError.Log.d(TAG, "Going directly to initiate bond"); changeState(BOND); } break; case BOND: if (getInitiateBondingFlag()) { UserError.Log.d(TAG, "State bond attempting to create bond"); } else { UserError.Log.d(TAG, "State bond currently does nothing as setting disabled"); } create_bond(); break; case RESET: UserError.Log.d(TAG, "Entering hard reset state"); Ob1G5StateMachine.doReset(this, connection); break; case GET_DATA: if (hardResetTransmitterNow) { send_reset_command(); } else { final PowerManager.WakeLock linger_wl_get_data = JoH.getWakeLock("jam-g5-get-linger", 6000); if (!Ob1G5StateMachine.doGetData(this, connection)) resetState(); } break; case CLOSE: prepareToWakeup(); break; case CLOSED: handleWakeup(); break; } } finally { JoH.releaseWakeLock(wl); } } else { UserError.Log.d(TAG, "Ignoring duplicate automata state within 2 seconds: " + state); } }
Example 11
Source File: StartNewSensor.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public static void startSensorForTime(long startTime) { Sensor.create(startTime); UserError.Log.ueh("NEW SENSOR", "Sensor started at " + JoH.dateTimeText(startTime)); JoH.static_toast_long(gs(R.string.new_sensor_started)); startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_SYNC_SENSOR, TAG); LibreAlarmReceiver.clearSensorStats(); // TODO this is just a timer and could be confusing - consider removing this notification // JoH.scheduleNotification(xdrip.getAppContext(), "Sensor should be ready", xdrip.getAppContext().getString(R.string.please_enter_two_calibrations_to_get_started), 60 * 130, Home.SENSOR_READY_ID); // reverse libre hacky workaround Treatments.SensorStart((DexCollectionType.hasLibre() ? startTime + (3600000) : startTime)); CollectionServiceStarter.restartCollectionServiceBackground(); Ob1G5StateMachine.startSensor(startTime); JoH.clearCache(); Home.staticRefreshBGCharts(); }
Example 12
Source File: MissedReadingService.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { final boolean bg_missed_alerts; final PowerManager.WakeLock wl = JoH.getWakeLock("missed-reading-service", 60000); try { final boolean sensorActive = Sensor.isActive(); Log.d(TAG, "MissedReadingService onHandleIntent"); // test debug log final long stale_millis = Home.stale_data_millis(); // send to pebble if (Pref.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType() != 1) && !BgReading.last_within_millis(stale_millis)) { if (JoH.ratelimit("peb-miss", 120)) { // TODO replace ratelimit with Inevitable.task? JoH.startService(PebbleWatchSync.class); } // update pebble even when we don't have data to ensure missed readings show } if (LeFunEntry.isEnabled() && (!BgReading.last_within_millis(stale_millis))) { LeFun.showLatestBG(); } if ((Pref.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() && if (!BgReading.last_within_millis(stale_millis) && sensorActive && (!getLocalServiceCollectingState())) { if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) { Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: " + aggressive_backoff_timer); if (aggressive_backoff_timer < 1200) aggressive_backoff_timer += 60; CollectionServiceStarter.restartCollectionServiceBackground(); } else { aggressive_backoff_timer = 120; // reset } } } Reminder.processAnyDueReminders(); BluetoothGlucoseMeter.immortality(); XdripWebService.immortality(); // InPenEntry.immortality(); DesertSync.pullAsEnabled(); NanoStatus.keepFollowerUpdated(); LockScreenWallPaper.timerPoll(); // TODO functionalize the actual checking bg_missed_alerts = Pref.getBoolean("bg_missed_alerts", false); if (!bg_missed_alerts) { // we should not do anything in this case. if the ui, changes will be called again return; } if (!sensorActive) { // sensor not running we should return return; } if (!JoH.upForAtLeastMins(15)) { Log.d(TAG, "Uptime less than 15 minutes so not processing for missed reading"); return; } if ((Home.get_forced_wear()) && Pref.getBoolean("disable_wearG5_on_missedreadings", false)) { int bg_wear_missed_minutes = Pref.getStringToInt("disable_wearG5_on_missedreadings_level", 30); if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) { Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected"); startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG); } } final int bg_missed_minutes = Pref.getStringToInt("bg_missed_minutes", 30); final long now = JoH.tsl(); // check if readings have been missed if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) && Pref.getLong("alerts_disabled_until", 0) <= now && (BgReading.getTimeSinceLastReading() < (Constants.HOUR_IN_MS * 6)) && inTimeFrame()) { Notifications.bgMissedAlert(xdrip.getAppContext()); checkBackAfterSnoozeTime(xdrip.getAppContext(), now); } else { long disabletime = Pref.getLong("alerts_disabled_until", 0) - now; long missedTime = bg_missed_minutes * 1000 * 60 - BgReading.getTimeSinceLastReading(); long alarmIn = Math.max(disabletime, missedTime); checkBackAfterMissedTime(alarmIn); } } finally { JoH.releaseWakeLock(wl); } }
Example 13
Source File: NightscoutFollow.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public static void resetInstance() { retrofit = null; service = null; UserError.Log.d(TAG, "Instance reset"); CollectionServiceStarter.restartCollectionServiceBackground(); }
Example 14
Source File: xdrip.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate() { xdrip.context = getApplicationContext(); super.onCreate(); try { if (PreferenceManager.getDefaultSharedPreferences(xdrip.context).getBoolean("enable_crashlytics", true)) { initCrashlytics(this); initBF(); } } catch (Exception e) { Log.e(TAG, e.toString()); } executor = new PlusAsyncExecutor(); PreferenceManager.setDefaultValues(this, R.xml.pref_general, true); PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, true); PreferenceManager.setDefaultValues(this, R.xml.pref_advanced_settings, true); PreferenceManager.setDefaultValues(this, R.xml.pref_notifications, true); PreferenceManager.setDefaultValues(this, R.xml.pref_data_source, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_defaults, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_prefs, true); checkForcedEnglish(xdrip.context); JoH.ratelimit("policy-never", 3600); // don't on first load new IdempotentMigrations(getApplicationContext()).performAll(); JobManager.create(this).addJobCreator(new XDripJobCreator()); DailyJob.schedule(); //SyncService.startSyncServiceSoon(); if (!isRunningTest()) { MissedReadingService.delayedLaunch(); NFCReaderX.handleHomeScreenScanPreference(getApplicationContext()); AlertType.fromSettings(getApplicationContext()); //new CollectionServiceStarter(getApplicationContext()).start(getApplicationContext()); CollectionServiceStarter.restartCollectionServiceBackground(); PlusSyncService.startSyncService(context, "xdrip.java"); if (Pref.getBoolean("motion_tracking_enabled", false)) { ActivityRecognizedService.startActivityRecogniser(getApplicationContext()); } BluetoothGlucoseMeter.startIfEnabled(); LeFunEntry.initialStartIfEnabled(); MiBandEntry.initialStartIfEnabled(); BlueJayEntry.initialStartIfEnabled(); XdripWebService.immortality(); VersionTracker.updateDevice(); } else { Log.d(TAG, "Detected running test mode, holding back on background processes"); } Reminder.firstInit(xdrip.getAppContext()); PluggableCalibration.invalidateCache(); }