public static void handleResyncWearAfterBackfill(final long earliest) { if (earliest_backfill == 0 || earliest < earliest_backfill) earliest_backfill = earliest; if (WatchUpdaterService.isEnabled()) { Inevitable.task("wear-backfill-sync", 10000, () -> { WatchUpdaterService.startServiceAndResendDataIfNeeded(earliest_backfill); earliest_backfill = 0; }); } }
private void sendData() { BgReading bg = BgReading.last(); if (bg != null) { forceGoogleApiConnect(); if (wear_integration) { final int battery = PowerStateReceiver.getBatteryLevel(getApplicationContext()); new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap(bg, mPrefs, new BgGraphBuilder(getApplicationContext()), battery)); } } }
private double inMgdl(double value, SharedPreferences sPrefs) { if (!doMgdl(sPrefs)) { return value * Constants.MMOLL_TO_MGDL; } else { return value; } }
@Override public void onCreate() { mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); wear_integration = mPrefs.getBoolean("wear_sync", false); //is_using_g5 = (getDexCollectionType() == DexCollectionType.DexcomG5); is_using_bt = DexCollectionType.hasBluetooth(); if (wear_integration) { googleApiConnect(); } setSettings(); listenForChangeInSettings(); }
public static void startServiceAndResendDataIfNeeded(final long since) { if (isEnabled()) { if (JoH.ratelimit("wear-resend-data", 60)) { startServiceAndResendData(since); } } }
switch (event.getPath()) { case WEARABLE_RESEND_PATH: resendData(0); break; case WEARABLE_VOICE_PAYLOAD: receivedText(getApplicationContext(), eventData); break; case WEARABLE_APPROVE_TREATMENT: approveTreatment(getApplicationContext(), ""); break; case WEARABLE_CANCEL_TREATMENT: cancelTreatment(getApplicationContext(), ""); break; case WEARABLE_SNOOZE_ALERT: JoH.static_toast_long(getResources().getString(R.string.alert_snoozed_by_watch)); break; case SYNC_BGS_PATH + "_BM"://TEST ignore only for benchmark case SYNC_BGS_PATH + "_BM_DUP_COMPRESS": Log.d(TAG, "onMessageReceived Ignore, just for test!"); decomprBytes = decompressBytes(event.getPath(), event.getData(), true);//bBenchmark dataMap = DataMap.fromByteArray(decomprBytes); if (dataMap != null) { syncTransmitterData(dataMap, true);//bBenchmark=true case SYNC_LOGS_PATH + "_BM_DUP_COMPRESS": Log.d(TAG, "onMessageReceived Ignore, just for test!");
if (googleApiClient.isConnected()) { if (ACTION_RESEND.equals(action)) { resendData(intent.getLongExtra("resend-since", 0)); } else if (ACTION_OPEN_SETTINGS.equals(action)) { Log.d(TAG, "onStartCommand Action=ACTION_OPEN_SETTINGS"); sendNotification(OPEN_SETTINGS, "openSettings"); } else if (ACTION_SEND_TOAST.equals(action)) { Log.d(TAG, "onStartCommand Action=ACTION_SEND_TOAST msg=" + intent.getStringExtra("msg")); sendWearLocalToast(intent.getStringExtra("msg"), Toast.LENGTH_LONG); } else if (ACTION_SEND_STATUS.equals(action)) {//KS added for HAPP sendRequestExtra(NEW_STATUS_PATH, "externalStatusString", intent.getStringExtra("externalStatusString")); } else if (ACTION_SNOOZE_ALERT.equals(action)) { Log.d(TAG, "onStartCommand Action=" + ACTION_SNOOZE_ALERT + " repeatTime=" + intent.getStringExtra("repeatTime")); sendRequestExtra(WEARABLE_SNOOZE_ALERT, "repeatTime", intent.getStringExtra("repeatTime")); } else if (ACTION_SYNC_DB.equals(action)) {//KS Log.d(TAG, "onStartCommand Action=" + ACTION_SYNC_DB + " Path=" + SYNC_DB_PATH); sendNotification(SYNC_DB_PATH, "syncDB"); initWearData(); } else if (ACTION_RESET_DB.equals(action)) {//KS Log.d(TAG, "onStartCommand Action=" + ACTION_RESET_DB + " Path=" + RESET_DB_PATH); sendNotification(RESET_DB_PATH, "resetDB"); initWearData(); } else if (ACTION_DISABLE_FORCE_WEAR.equals(action)) {//KS int bg_wear_missed_minutes = readPrefsInt(mPrefs, "disable_wearG5_on_missedreadings_level", 30); Log.d(TAG, "onStartCommand Action=ACTION_DISABLE_FORCE_WEAR"); Pref.setBoolean("force_wearG5", false); final String msgDisableWear = getResources().getString(R.string.notify_disable_wearG5_on_missedreadings, bg_wear_missed_minutes);
change = true; Log.d(TAG, "syncPrefData disable_wearG5_on_lowbattery=true; switch force_wearG5:" + force_wearG5); String msg = getResources().getString(R.string.notify_when_wear_low_battery); JoH.static_toast_long(msg); sendWearLocalToast(msg, Toast.LENGTH_LONG); prefs.apply(); } else if (!dex_txid.equals(mPrefs.getString("dex_txid", "default"))) { sendPrefSettings(); processConnect();
continue; receivedText(getApplicationContext(), record); PersistentStore.setLong(LAST_RECORD_TIMESTAMP, timestamp); sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "TREATMENTS", -1);
private void sendActiveBtDeviceData() {//KS if (is_using_bt) {//only required for Collector running on watch forceGoogleApiConnect(); ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice != null) { if (wear_integration) { DataMap dataMap = new DataMap(); Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected); dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP dataMap.putString("name", btDevice.name); dataMap.putString("address", btDevice.address); dataMap.putBoolean("connected", btDevice.connected); new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap); } } } else { Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt"); } }
private void sendG5QueueData(String queueData) { if ((wear_integration) && (queueData != null)) { forceGoogleApiConnect(); new SendToDataLayerThread(WEARABLE_G5_QUEUE_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap("queueData", queueData)); } }
@Override public void onPeerDisconnected(com.google.android.gms.wearable.Node peer) {//KS onPeerConnected and onPeerDisconnected deprecated at the same time as BIND_LISTENER super.onPeerDisconnected(peer); String id = peer.getId(); String name = peer.getDisplayName(); Log.d(TAG, "onPeerDisconnected peer name & ID: " + name + "|" + id); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (sharedPrefs.getBoolean("watch_integration", false)) { Log.d(TAG, "onPeerDisconnected watch_integration=true Phone startBtService"); startBtService(); } }
private void stopBtService() { Log.d(TAG, "stopService call stopService"); CollectionServiceStarter.stopBtService(getApplicationContext()); Log.d(TAG, "stopBtService should have called onDestroy"); }
private void startBtService() {//KS Log.d(TAG, "startBtService"); is_using_bt = DexCollectionType.hasBluetooth();//(getDexCollectionType() == DexCollectionType.DexcomG5) if (is_using_bt) { if (!isCollectorRunning()) { CollectionServiceStarter.startBtService(getApplicationContext()); Log.d(TAG, "startBtService startService"); } else { Log.d(TAG, "startBtService collector already running!"); } } else { Log.d(TAG, "Not starting any BT Collector service as it is not our data source"); } }
private void sendPrefSettings() {//KS forceGoogleApiConnect(); DataMap dataMap = new DataMap(); String dexCollector = "None"; dataMap.putString("locale", locale.getLanguage() + (country != null && !country.isEmpty() ? "_" + country : "")); dataMap.putString("build-version-name", getVersionID());
switch (event.getPath()) { case WEARABLE_RESEND_PATH: resendData(0); break; case WEARABLE_VOICE_PAYLOAD: receivedText(getApplicationContext(), eventData); break; case WEARABLE_APPROVE_TREATMENT: approveTreatment(getApplicationContext(), ""); break; case WEARABLE_CANCEL_TREATMENT: cancelTreatment(getApplicationContext(), ""); break; case WEARABLE_SNOOZE_ALERT: JoH.static_toast_long(getResources().getString(R.string.alert_snoozed_by_watch)); break; case SYNC_BGS_PATH + "_BM"://TEST ignore only for benchmark case SYNC_BGS_PATH + "_BM_DUP_COMPRESS": Log.d(TAG, "onMessageReceived Ignore, just for test!"); decomprBytes = decompressBytes(event.getPath(), event.getData(), true);//bBenchmark dataMap = DataMap.fromByteArray(decomprBytes); if (dataMap != null) { syncTransmitterData(dataMap, true);//bBenchmark=true case SYNC_LOGS_PATH + "_BM_DUP_COMPRESS": Log.d(TAG, "onMessageReceived Ignore, just for test!");
if (googleApiClient.isConnected()) { if (ACTION_RESEND.equals(action)) { resendData(intent.getLongExtra("resend-since", 0)); } else if (ACTION_OPEN_SETTINGS.equals(action)) { Log.d(TAG, "onStartCommand Action=ACTION_OPEN_SETTINGS"); sendNotification(OPEN_SETTINGS, "openSettings"); } else if (ACTION_SEND_TOAST.equals(action)) { Log.d(TAG, "onStartCommand Action=ACTION_SEND_TOAST msg=" + intent.getStringExtra("msg")); sendWearLocalToast(intent.getStringExtra("msg"), Toast.LENGTH_LONG); } else if (ACTION_SEND_STATUS.equals(action)) {//KS added for HAPP sendRequestExtra(NEW_STATUS_PATH, "externalStatusString", intent.getStringExtra("externalStatusString")); } else if (ACTION_SNOOZE_ALERT.equals(action)) { Log.d(TAG, "onStartCommand Action=" + ACTION_SNOOZE_ALERT + " repeatTime=" + intent.getStringExtra("repeatTime")); sendRequestExtra(WEARABLE_SNOOZE_ALERT, "repeatTime", intent.getStringExtra("repeatTime")); } else if (ACTION_SYNC_DB.equals(action)) {//KS Log.d(TAG, "onStartCommand Action=" + ACTION_SYNC_DB + " Path=" + SYNC_DB_PATH); sendNotification(SYNC_DB_PATH, "syncDB"); initWearData(); } else if (ACTION_RESET_DB.equals(action)) {//KS Log.d(TAG, "onStartCommand Action=" + ACTION_RESET_DB + " Path=" + RESET_DB_PATH); sendNotification(RESET_DB_PATH, "resetDB"); initWearData(); } else if (ACTION_DISABLE_FORCE_WEAR.equals(action)) {//KS int bg_wear_missed_minutes = readPrefsInt(mPrefs, "disable_wearG5_on_missedreadings_level", 30); Log.d(TAG, "onStartCommand Action=ACTION_DISABLE_FORCE_WEAR"); Pref.setBoolean("force_wearG5", false); final String msgDisableWear = getResources().getString(R.string.notify_disable_wearG5_on_missedreadings, bg_wear_missed_minutes);
@Override public void onCreate() { mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); wear_integration = mPrefs.getBoolean("wear_sync", false); //is_using_g5 = (getDexCollectionType() == DexCollectionType.DexcomG5); is_using_bt = DexCollectionType.hasBluetooth(); if (wear_integration) { googleApiConnect(); } setSettings(); listenForChangeInSettings(); }
change = true; Log.d(TAG, "syncPrefData disable_wearG5_on_lowbattery=true; switch force_wearG5:" + force_wearG5); String msg = getResources().getString(R.string.notify_when_wear_low_battery); JoH.static_toast_long(msg); sendWearLocalToast(msg, Toast.LENGTH_LONG); prefs.apply(); } else if (!dex_txid.equals(mPrefs.getString("dex_txid", "default"))) { sendPrefSettings(); processConnect();