com.eveningoutpost.dexdrip.UtilityModels.Intents Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.Intents. 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: Home.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void staticRefreshBGCharts(boolean override) {
    reset_viewport = true;
    if (activityVisible || override) {
        Intent updateIntent = new Intent(Intents.ACTION_NEW_BG_ESTIMATE_NO_DATA);
        mActivity.sendBroadcast(updateIntent);
    }
}
 
Example #2
Source File: NSClientReceiver.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void testCalibration() {
    Bundle bundle = new Bundle();
    bundle.putDouble("glucose_number", 5.5d+ (JoH.ts() % 100)/100d); // format is local format, in this example 5.5 mmol/l or specify the units as shown below
    bundle.putString("units", "mmol"); // mgdl or mmol
    bundle.putLong("timestamp", JoH.tsl()-10000);
    Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION);
    intent.putExtras(bundle);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    xdrip.getAppContext().sendBroadcast(intent);
}
 
Example #3
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume()
{
    super.onResume();
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(ActivityRecognizedService.prefListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && DexCollectionType.hasBluetooth() && !WholeHouse.isRpi()) {
        LocationHelper.requestLocationForBluetooth(this); // double check!
    }
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(LeFunEntry.prefListener);
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(MiBandEntry.prefListener);
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(BlueJayEntry.prefListener);
    LocalBroadcastManager.getInstance(this).registerReceiver(mibandStatusReceiver,
            new IntentFilter(Intents.PREFERENCE_INTENT));
}
 
Example #4
Source File: MiBandEntry.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void sendPrefIntent(MiBandService.MIBAND_INTEND_STATES state, Integer progress, String descrText) {
    final Intent progressIntent = new Intent(Intents.PREFERENCE_INTENT);
    progressIntent.putExtra("state", state.name());
    progressIntent.putExtra("progress", progress);
    if (!descrText.isEmpty())
        progressIntent.putExtra("descr_text", descrText);
    LocalBroadcastManager.getInstance(xdrip.getAppContext()).sendBroadcast(progressIntent);
}
 
Example #5
Source File: MiBandEntry.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void sendPrefIntent(MiBandService.MIBAND_INTEND_STATES state, Integer progress, String descrText) {
    final Intent progressIntent = new Intent(Intents.PREFERENCE_INTENT);
    progressIntent.putExtra("state", state.name());
    progressIntent.putExtra("progress", progress);
    if (!descrText.isEmpty())
        progressIntent.putExtra("descr_text", descrText);
    LocalBroadcastManager.getInstance(xdrip.getAppContext()).sendBroadcast(progressIntent);
}
 
Example #6
Source File: Preferences.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume()
{
    super.onResume();
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(ActivityRecognizedService.prefListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && DexCollectionType.hasBluetooth() && !WholeHouse.isRpi()) {
        LocationHelper.requestLocationForBluetooth(this); // double check!
    }
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(LeFunEntry.prefListener);
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(MiBandEntry.prefListener);
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(BlueJayEntry.prefListener);
    LocalBroadcastManager.getInstance(this).registerReceiver(mibandStatusReceiver,
            new IntentFilter(Intents.PREFERENCE_INTENT));
}
 
Example #7
Source File: Home.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void staticRefreshBGCharts(boolean override) {
    reset_viewport = true;
    if (activityVisible || override) {
        Intent updateIntent = new Intent(Intents.ACTION_NEW_BG_ESTIMATE_NO_DATA);
        mActivity.sendBroadcast(updateIntent);
    }
}
 
Example #8
Source File: NSClientReceiver.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void testCalibration() {
    Bundle bundle = new Bundle();
    bundle.putDouble("glucose_number", 5.5d+ (JoH.ts() % 100)/100d); // format is local format, in this example 5.5 mmol/l or specify the units as shown below
    bundle.putString("units", "mmol"); // mgdl or mmol
    bundle.putLong("timestamp", JoH.tsl()-10000);
    Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION);
    intent.putExtras(bundle);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    xdrip.getAppContext().sendBroadcast(intent);
}
 
Example #9
Source File: LibreOOPAlgorithm.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
static public void SendData(byte[] fullData, long timestamp, byte []patchUid,  byte []patchInfo) {
    if(fullData == null) {
        Log.e(TAG, "SendData called with null data");
        return;
    }
    
    if(fullData.length < 344) {
        Log.e(TAG, "SendData called with data size too small. " + fullData.length);
        return;
    }
    Log.i(TAG, "Sending full data to OOP Algorithm data-len = " + fullData.length);
    
    fullData = java.util.Arrays.copyOfRange(fullData, 0, 0x158);
    Log.i(TAG, "Data that will be sent is " + HexDump.dumpHexString(fullData));
    
    Intent intent = new Intent(Intents.XDRIP_PLUS_LIBRE_DATA);
    Bundle bundle = new Bundle();
    bundle.putByteArray(Intents.LIBRE_DATA_BUFFER, fullData);
    bundle.putLong(Intents.LIBRE_DATA_TIMESTAMP, timestamp);
    bundle.putString(Intents.LIBRE_SN, PersistentStore.getString("LibreSN"));
    if(patchUid != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_UID_BUFFER, patchUid);
    }
    if(patchInfo != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_INFO_BUFFER, patchInfo);
    }
    
    intent.putExtras(bundle);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

    final String packages = PersistentStore.getString(CompatibleApps.EXTERNAL_ALG_PACKAGES);
    if (packages.length() > 0) {
        final String[] packagesE = packages.split(",");
        for (final String destination : packagesE) {
            if (destination.length() > 3) {
                intent.setPackage(destination);
                Log.d(TAG, "Sending to package: " + destination);
                xdrip.getAppContext().sendBroadcast(intent);
            }
        }
    } else {
        Log.d(TAG, "Sending to generic package");
        xdrip.getAppContext().sendBroadcast(intent);
    }
}
 
Example #10
Source File: Home.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static void updateStatusLine(String key, String value) {
    final Intent homeStatus = new Intent(Intents.HOME_STATUS_ACTION);
    homeStatus.putExtra(key, value);
    LocalBroadcastManager.getInstance(xdrip.getAppContext()).sendBroadcast(homeStatus);
    Log.d(TAG, "Home Status update: " + key + " / " + value);
}
 
Example #11
Source File: BlueJayRemote.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static Intent getAPIintent() {
    return new Intent(Intents.BLUEJAY_THINJAM_API);
}
 
Example #12
Source File: BlueJayEmit.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static Intent getAPIintent() {
    return new Intent(Intents.BLUEJAY_THINJAM_EMIT);
}
 
Example #13
Source File: LibreAlarmReceiver.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    new Thread() {
        @Override
        public void run() {
            final PowerManager.WakeLock wl = JoH.getWakeLock("librealarm-receiver", 60000);
            synchronized (lock) {
                try {

                    Log.d(TAG, "LibreReceiver onReceiver: " + intent.getAction());
                    JoH.benchmark(null);
                    // check source
                    if (prefs == null)
                        prefs = PreferenceManager.getDefaultSharedPreferences(context);

                    final Bundle bundle = intent.getExtras();
                    //  BundleScrubber.scrub(bundle);
                    final String action = intent.getAction();


                    if ((bundle != null) && (debug)) {
                        for (String key : bundle.keySet()) {
                            Object value = bundle.get(key);
                            if (value != null) {
                                Log.d(TAG, String.format("%s %s (%s)", key,
                                        value.toString(), value.getClass().getName()));
                            }
                        }
                    }

                    switch (action) {
                        case Intents.LIBRE_ALARM_TO_XDRIP_PLUS:

                            // If we are not currently in a mode supporting libre then switch
                            if (!DexCollectionType.hasLibre()) {
                                DexCollectionType.setDexCollectionType(DexCollectionType.LibreAlarm);
                            }

                            if (bundle == null) break;

                            Log.d(TAG, "Receiving LIBRE_ALARM broadcast");

                            oldest_cmp = oldest;
                            newest_cmp = newest;
                            Log.d(TAG, "At Start: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));

                            final String data = bundle.getString("data");
                            final int bridge_battery = bundle.getInt("bridge_battery");
                            if (bridge_battery > 0) {
                                Pref.setInt("bridge_battery", bridge_battery);
                                CheckBridgeBattery.checkBridgeBattery();
                            }
                            try {
                                final ReadingData.TransferObject object =
                                        new Gson().fromJson(data, ReadingData.TransferObject.class);
                                object.data.CalculateSmothedData();
                                processReadingDataTransferObject(object, JoH.tsl(), "LibreAlarm", false, null, null);
                                Log.d(TAG, "At End: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));
                            } catch (Exception e) {
                                Log.wtf(TAG, "Could not process data structure from LibreAlarm: " + e.toString());
                                JoH.static_toast_long(gs(R.string.librealarm_data_format_appears_incompatible_protocol_changed_or_no_data));
                            }
                            break;

                        default:
                            Log.e(TAG, "Unknown action! " + action);
                            break;
                    }
                } finally {
                    JoH.benchmark("LibreReceiver process");
                    JoH.releaseWakeLock(wl);
                }
            } // lock
        }
    }.start();
}
 
Example #14
Source File: LibreOOPAlgorithm.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
static public void SendData(byte[] fullData, long timestamp, byte []patchUid,  byte []patchInfo) {
    if(fullData == null) {
        Log.e(TAG, "SendData called with null data");
        return;
    }
    
    if(fullData.length < 344) {
        Log.e(TAG, "SendData called with data size too small. " + fullData.length);
        return;
    }
    Log.i(TAG, "Sending full data to OOP Algorithm data-len = " + fullData.length);
    
    fullData = java.util.Arrays.copyOfRange(fullData, 0, 0x158);
    Log.i(TAG, "Data that will be sent is " + HexDump.dumpHexString(fullData));
    
    Intent intent = new Intent(Intents.XDRIP_PLUS_LIBRE_DATA);
    Bundle bundle = new Bundle();
    bundle.putByteArray(Intents.LIBRE_DATA_BUFFER, fullData);
    bundle.putLong(Intents.LIBRE_DATA_TIMESTAMP, timestamp);
    bundle.putString(Intents.LIBRE_SN, PersistentStore.getString("LibreSN"));
    bundle.putInt(Intents.LIBRE_RAW_ID, android.os.Process.myPid());
    
    if(patchUid != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_UID_BUFFER, patchUid);
    }
    if(patchInfo != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_INFO_BUFFER, patchInfo);
    }
    
    intent.putExtras(bundle);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

    final String packages = PersistentStore.getString(CompatibleApps.EXTERNAL_ALG_PACKAGES);
    if (packages.length() > 0) {
        final String[] packagesE = packages.split(",");
        for (final String destination : packagesE) {
            if (destination.length() > 3) {
                intent.setPackage(destination);
                Log.d(TAG, "Sending to package: " + destination);
                xdrip.getAppContext().sendBroadcast(intent);
            }
        }
    } else {
        Log.d(TAG, "Sending to generic package");
        xdrip.getAppContext().sendBroadcast(intent);
    }
}
 
Example #15
Source File: LibreReceiver.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    if(DexCollectionType.getDexCollectionType() != DexCollectionType.LibreReceiver)
        return;
    new Thread() {
        @Override
        public void run() {
            PowerManager.WakeLock wl = JoH.getWakeLock("libre-receiver", 60000);
            synchronized (lock) {
                try {

                    Log.d(TAG, "libre onReceiver: " + intent.getAction());
                    JoH.benchmark(null);
                    // check source
                    if (prefs == null)
                        prefs = PreferenceManager.getDefaultSharedPreferences(context);

                    final Bundle bundle = intent.getExtras();
                    //  BundleScrubber.scrub(bundle);
                    final String action = intent.getAction();



                    if (action == null) return;

                    switch (action) {
                        case Intents.LIBRE2_ACTIVATION:
                            Log.v(TAG, "Receiving LibreData activation");
                            try {
                                saveSensorStartTime(intent.getBundleExtra("sensor"), intent.getBundleExtra("bleManager").getString("sensorSerial"));
                            } catch (NullPointerException e) {
                                Log.e(TAG, "Null pointer in LIBRE2_ACTIVATION: " + e);
                            }
                            break;

                        case Intents.LIBRE2_BG:
                            Libre2RawValue currentRawValue = processIntent(intent);
                            if (currentRawValue == null) return;
                            Log.v(TAG,"got bg reading: from sensor:"+currentRawValue.serial+" rawValue:"+currentRawValue.glucose+" at:"+currentRawValue.timestamp);
                            // period of 4.5 minutes to collect 5 readings
                            if(!BgReading.last_within_millis(45 * 6 * 1000 )) {
                                List<Libre2RawValue> smoothingValues = Libre2RawValue.last20Minutes();
                                smoothingValues.add(currentRawValue);
                                processValues(currentRawValue, smoothingValues, context);
                            }
                            currentRawValue.save();

                            break;

                        default:
                            Log.e(TAG, "Unknown action! " + action);
                            break;
                    }
                } finally {
                    JoH.benchmark("NSEmulator process");
                    JoH.releaseWakeLock(wl);
                }
            } // lock
        }
    }.start();
}
 
Example #16
Source File: LibreAlarmReceiver.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    new Thread() {
        @Override
        public void run() {
            final PowerManager.WakeLock wl = JoH.getWakeLock("librealarm-receiver", 60000);
            synchronized (lock) {
                try {

                    Log.d(TAG, "LibreReceiver onReceiver: " + intent.getAction());
                    JoH.benchmark(null);
                    // check source
                    if (prefs == null)
                        prefs = PreferenceManager.getDefaultSharedPreferences(context);

                    final Bundle bundle = intent.getExtras();
                    //  BundleScrubber.scrub(bundle);
                    final String action = intent.getAction();


                    if ((bundle != null) && (debug)) {
                        for (String key : bundle.keySet()) {
                            Object value = bundle.get(key);
                            if (value != null) {
                                Log.d(TAG, String.format("%s %s (%s)", key,
                                        value.toString(), value.getClass().getName()));
                            }
                        }
                    }

                    switch (action) {
                        case Intents.LIBRE_ALARM_TO_XDRIP_PLUS:

                            // If we are not currently in a mode supporting libre then switch
                            if (!DexCollectionType.hasLibre()) {
                                DexCollectionType.setDexCollectionType(DexCollectionType.LibreAlarm);
                            }

                            if (bundle == null) break;

                            Log.d(TAG, "Receiving LIBRE_ALARM broadcast");

                            oldest_cmp = oldest;
                            newest_cmp = newest;
                            Log.d(TAG, "At Start: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));

                            final String data = bundle.getString("data");
                            final int bridge_battery = bundle.getInt("bridge_battery");
                            if (bridge_battery > 0) {
                                Pref.setInt("bridge_battery", bridge_battery);
                                CheckBridgeBattery.checkBridgeBattery();
                            }
                            try {
                                final ReadingData.TransferObject object =
                                        new Gson().fromJson(data, ReadingData.TransferObject.class);
                                object.data.CalculateSmothedData();
                                processReadingDataTransferObject(object, JoH.tsl(), "LibreAlarm", false, null, null);
                                Log.d(TAG, "At End: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));
                            } catch (Exception e) {
                                Log.wtf(TAG, "Could not process data structure from LibreAlarm: " + e.toString());
                                JoH.static_toast_long(gs(R.string.librealarm_data_format_appears_incompatible_protocol_changed_or_no_data));
                            }
                            break;

                        default:
                            Log.e(TAG, "Unknown action! " + action);
                            break;
                    }
                } finally {
                    JoH.benchmark("LibreReceiver process");
                    JoH.releaseWakeLock(wl);
                }
            } // lock
        }
    }.start();
}
 
Example #17
Source File: LibreOOPAlgorithm.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
static public void SendData(byte[] fullData, long timestamp, byte []patchUid,  byte []patchInfo) {
    if(fullData == null) {
        Log.e(TAG, "SendData called with null data");
        return;
    }
    
    if(fullData.length < 344) {
        Log.e(TAG, "SendData called with data size too small. " + fullData.length);
        return;
    }
    Log.i(TAG, "Sending full data to OOP Algorithm data-len = " + fullData.length);
    
    fullData = java.util.Arrays.copyOfRange(fullData, 0, 0x158);
    Log.i(TAG, "Data that will be sent is " + HexDump.dumpHexString(fullData));
    
    Intent intent = new Intent(Intents.XDRIP_PLUS_LIBRE_DATA);
    Bundle bundle = new Bundle();
    bundle.putByteArray(Intents.LIBRE_DATA_BUFFER, fullData);
    bundle.putLong(Intents.LIBRE_DATA_TIMESTAMP, timestamp);
    bundle.putString(Intents.LIBRE_SN, PersistentStore.getString("LibreSN"));
    if(patchUid != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_UID_BUFFER, patchUid);
    }
    if(patchInfo != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_INFO_BUFFER, patchInfo);
    }
    
    intent.putExtras(bundle);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

    final String packages = PersistentStore.getString(CompatibleApps.EXTERNAL_ALG_PACKAGES);
    if (packages.length() > 0) {
        final String[] packagesE = packages.split(",");
        for (final String destination : packagesE) {
            if (destination.length() > 3) {
                intent.setPackage(destination);
                Log.d(TAG, "Sending to package: " + destination);
                xdrip.getAppContext().sendBroadcast(intent);
            }
        }
    } else {
        Log.d(TAG, "Sending to generic package");
        xdrip.getAppContext().sendBroadcast(intent);
    }
}
 
Example #18
Source File: Home.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static void updateStatusLine(String key, String value) {
    final Intent homeStatus = new Intent(Intents.HOME_STATUS_ACTION);
    homeStatus.putExtra(key, value);
    LocalBroadcastManager.getInstance(xdrip.getAppContext()).sendBroadcast(homeStatus);
    Log.d(TAG, "Home Status update: " + key + " / " + value);
}
 
Example #19
Source File: BlueJayRemote.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static Intent getAPIintent() {
    return new Intent(Intents.BLUEJAY_THINJAM_API);
}
 
Example #20
Source File: BlueJayEmit.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static Intent getAPIintent() {
    return new Intent(Intents.BLUEJAY_THINJAM_EMIT);
}
 
Example #21
Source File: LibreAlarmReceiver.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    new Thread() {
        @Override
        public void run() {
            final PowerManager.WakeLock wl = JoH.getWakeLock("librealarm-receiver", 60000);
            synchronized (lock) {
                try {

                    Log.d(TAG, "LibreReceiver onReceiver: " + intent.getAction());
                    JoH.benchmark(null);
                    // check source
                    if (prefs == null)
                        prefs = PreferenceManager.getDefaultSharedPreferences(context);

                    final Bundle bundle = intent.getExtras();
                    //  BundleScrubber.scrub(bundle);
                    final String action = intent.getAction();


                    if ((bundle != null) && (debug)) {
                        for (String key : bundle.keySet()) {
                            Object value = bundle.get(key);
                            if (value != null) {
                                Log.d(TAG, String.format("%s %s (%s)", key,
                                        value.toString(), value.getClass().getName()));
                            }
                        }
                    }

                    switch (action) {
                        case Intents.LIBRE_ALARM_TO_XDRIP_PLUS:

                            // If we are not currently in a mode supporting libre then switch
                            if (!DexCollectionType.hasLibre()) {
                                DexCollectionType.setDexCollectionType(DexCollectionType.LibreAlarm);
                            }

                            if (bundle == null) break;

                            Log.d(TAG, "Receiving LIBRE_ALARM broadcast");

                            oldest_cmp = oldest;
                            newest_cmp = newest;
                            Log.d(TAG, "At Start: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));

                            final String data = bundle.getString("data");
                            final int bridge_battery = bundle.getInt("bridge_battery");
                            if (bridge_battery > 0) {
                                Pref.setInt("bridge_battery", bridge_battery);
                                CheckBridgeBattery.checkBridgeBattery();
                            }
                            try {
                                final ReadingData.TransferObject object =
                                        new Gson().fromJson(data, ReadingData.TransferObject.class);
                                object.data.CalculateSmothedData();
                                processReadingDataTransferObject(object, JoH.tsl(), "LibreAlarm", false, null, null);
                                Log.d(TAG, "At End: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));
                            } catch (Exception e) {
                                Log.wtf(TAG, "Could not process data structure from LibreAlarm: " + e.toString());
                                JoH.static_toast_long(gs(R.string.librealarm_data_format_appears_incompatible_protocol_changed_or_no_data));
                            }
                            break;

                        default:
                            Log.e(TAG, "Unknown action! " + action);
                            break;
                    }
                } finally {
                    JoH.benchmark("LibreReceiver process");
                    JoH.releaseWakeLock(wl);
                }
            } // lock
        }
    }.start();
}
 
Example #22
Source File: LibreOOPAlgorithm.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
static public void SendData(byte[] fullData, long timestamp, byte []patchUid,  byte []patchInfo) {
    if(fullData == null) {
        Log.e(TAG, "SendData called with null data");
        return;
    }
    
    if(fullData.length < 344) {
        Log.e(TAG, "SendData called with data size too small. " + fullData.length);
        return;
    }
    Log.i(TAG, "Sending full data to OOP Algorithm data-len = " + fullData.length);
    
    fullData = java.util.Arrays.copyOfRange(fullData, 0, 0x158);
    Log.i(TAG, "Data that will be sent is " + HexDump.dumpHexString(fullData));
    
    Intent intent = new Intent(Intents.XDRIP_PLUS_LIBRE_DATA);
    Bundle bundle = new Bundle();
    bundle.putByteArray(Intents.LIBRE_DATA_BUFFER, fullData);
    bundle.putLong(Intents.LIBRE_DATA_TIMESTAMP, timestamp);
    bundle.putString(Intents.LIBRE_SN, PersistentStore.getString("LibreSN"));
    bundle.putInt(Intents.LIBRE_RAW_ID, android.os.Process.myPid());
    
    if(patchUid != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_UID_BUFFER, patchUid);
    }
    if(patchInfo != null) {
        bundle.putByteArray(Intents.LIBRE_PATCH_INFO_BUFFER, patchInfo);
    }
    
    intent.putExtras(bundle);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

    final String packages = PersistentStore.getString(CompatibleApps.EXTERNAL_ALG_PACKAGES);
    if (packages.length() > 0) {
        final String[] packagesE = packages.split(",");
        for (final String destination : packagesE) {
            if (destination.length() > 3) {
                intent.setPackage(destination);
                Log.d(TAG, "Sending to package: " + destination);
                xdrip.getAppContext().sendBroadcast(intent);
            }
        }
    } else {
        Log.d(TAG, "Sending to generic package");
        xdrip.getAppContext().sendBroadcast(intent);
    }
}
 
Example #23
Source File: LibreReceiver.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    if(DexCollectionType.getDexCollectionType() != DexCollectionType.LibreReceiver)
        return;
    new Thread() {
        @Override
        public void run() {
            PowerManager.WakeLock wl = JoH.getWakeLock("libre-receiver", 60000);
            synchronized (lock) {
                try {

                    Log.d(TAG, "libre onReceiver: " + intent.getAction());
                    JoH.benchmark(null);
                    // check source
                    if (prefs == null)
                        prefs = PreferenceManager.getDefaultSharedPreferences(context);

                    final Bundle bundle = intent.getExtras();
                    //  BundleScrubber.scrub(bundle);
                    final String action = intent.getAction();



                    if (action == null) return;

                    switch (action) {
                        case Intents.LIBRE2_ACTIVATION:
                            Log.v(TAG, "Receiving LibreData activation");
                            try {
                                saveSensorStartTime(intent.getBundleExtra("sensor"), intent.getBundleExtra("bleManager").getString("sensorSerial"));
                            } catch (NullPointerException e) {
                                Log.e(TAG, "Null pointer in LIBRE2_ACTIVATION: " + e);
                            }
                            break;

                        case Intents.LIBRE2_BG:
                            Libre2RawValue currentRawValue = processIntent(intent);
                            if (currentRawValue == null) return;
                            Log.v(TAG,"got bg reading: from sensor:"+currentRawValue.serial+" rawValue:"+currentRawValue.glucose+" at:"+currentRawValue.timestamp);
                            // period of 4.5 minutes to collect 5 readings
                            if(!BgReading.last_within_millis(45 * 6 * 1000 )) {
                                List<Libre2RawValue> smoothingValues = Libre2RawValue.last20Minutes();
                                smoothingValues.add(currentRawValue);
                                processValues(currentRawValue, smoothingValues, context);
                            }
                            currentRawValue.save();

                            break;

                        default:
                            Log.e(TAG, "Unknown action! " + action);
                            break;
                    }
                } finally {
                    JoH.benchmark("NSEmulator process");
                    JoH.releaseWakeLock(wl);
                }
            } // lock
        }
    }.start();
}
 
Example #24
Source File: LibreAlarmReceiver.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    new Thread() {
        @Override
        public void run() {
            final PowerManager.WakeLock wl = JoH.getWakeLock("librealarm-receiver", 60000);
            synchronized (lock) {
                try {

                    Log.d(TAG, "LibreReceiver onReceiver: " + intent.getAction());
                    JoH.benchmark(null);
                    // check source
                    if (prefs == null)
                        prefs = PreferenceManager.getDefaultSharedPreferences(context);

                    final Bundle bundle = intent.getExtras();
                    //  BundleScrubber.scrub(bundle);
                    final String action = intent.getAction();


                    if ((bundle != null) && (debug)) {
                        for (String key : bundle.keySet()) {
                            Object value = bundle.get(key);
                            if (value != null) {
                                Log.d(TAG, String.format("%s %s (%s)", key,
                                        value.toString(), value.getClass().getName()));
                            }
                        }
                    }

                    switch (action) {
                        case Intents.LIBRE_ALARM_TO_XDRIP_PLUS:

                            // If we are not currently in a mode supporting libre then switch
                            if (!DexCollectionType.hasLibre()) {
                                DexCollectionType.setDexCollectionType(DexCollectionType.LibreAlarm);
                            }

                            if (bundle == null) break;

                            Log.d(TAG, "Receiving LIBRE_ALARM broadcast");

                            oldest_cmp = oldest;
                            newest_cmp = newest;
                            Log.d(TAG, "At Start: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));

                            final String data = bundle.getString("data");
                            final int bridge_battery = bundle.getInt("bridge_battery");
                            if (bridge_battery > 0) {
                                Pref.setInt("bridge_battery", bridge_battery);
                                CheckBridgeBattery.checkBridgeBattery();
                            }
                            try {
                                final ReadingData.TransferObject object =
                                        new Gson().fromJson(data, ReadingData.TransferObject.class);
                                object.data.CalculateSmothedData();
                                processReadingDataTransferObject(object, JoH.tsl(), "LibreAlarm", false, null, null);
                                Log.d(TAG, "At End: Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));
                            } catch (Exception e) {
                                Log.wtf(TAG, "Could not process data structure from LibreAlarm: " + e.toString());
                                JoH.static_toast_long(gs(R.string.librealarm_data_format_appears_incompatible_protocol_changed_or_no_data));
                            }
                            break;

                        default:
                            Log.e(TAG, "Unknown action! " + action);
                            break;
                    }
                } finally {
                    JoH.benchmark("LibreReceiver process");
                    JoH.releaseWakeLock(wl);
                }
            } // lock
        }
    }.start();
}