正在查看: xDrip+ v04633772025.07.16 应用的 LibreAlarmReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 LibreAlarmReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.Forecast;
import com.eveningoutpost.dexdrip.models.GlucoseData;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.LibreBlock;
import com.eveningoutpost.dexdrip.models.ReadingData;
import com.eveningoutpost.dexdrip.models.SensorSanity;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utils.DexCollectionType;
import com.eveningoutpost.dexdrip.utils.LibreTrendPoint;
import com.eveningoutpost.dexdrip.utils.LibreTrendUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
public class LibreAlarmReceiver extends BroadcastReceiver {
private static final Object lock = new Object();
private static long newest = -1;
private static long newest_cmp = -1;
private static long oldest = -1;
private static long oldest_cmp = -1;
private static SharedPreferences prefs = null;
private static long sensorAge = 0;
private static long timeShiftNearest = -1;
private static double convert_for_dex(int i) {
return i * 117.64705d;
}
public static void clearSensorStats() {
Pref.setInt("nfc_sensor_age", 0);
sensorAge = 0L;
}
private static boolean useGlucoseAsRaw() {
return Pref.getString("calibrate_external_libre_2_algorithm_type", "calibrate_raw").equals("calibrate_glucose");
}
private static void createBGfromGD(GlucoseData glucoseData, boolean z, boolean z2) {
int i;
int i2;
double d = 12.0d;
if (useGlucoseAsRaw()) {
int i3 = glucoseData.glucoseLevel;
if (i3 > 0) {
if (!z || (i2 = glucoseData.glucoseLevelSmoothed) <= 0) {
d = i3 * 1000;
} else {
d = i2 * 1000;
UserError.Log.e("jamorham librereceiver", "Using smoothed value as raw " + d + " instead of " + glucoseData.glucoseLevel);
}
}
} else {
int i4 = glucoseData.glucoseLevelRaw;
if (i4 > 0) {
if (z && (i = glucoseData.glucoseLevelRawSmoothed) > 0) {
d = convert_for_dex(i);
UserError.Log.d("jamorham librereceiver", "Using smoothed value " + d + " instead of " + convert_for_dex(glucoseData.glucoseLevelRaw) + glucoseData);
} else {
d = convert_for_dex(i4);
}
}
}
double d2 = d;
long j = glucoseData.realDate;
if (j > 0) {
long j2 = newest_cmp;
if (j2 != -1) {
long j3 = oldest_cmp;
if (j3 != -1 && j >= j3 && j <= j2) {
UserError.Log.d("jamorham librereceiver", "Already processed from date range: " + JoH.dateTimeText(glucoseData.realDate));
}
}
long j4 = oldest;
if (j < j4 || j4 == -1) {
oldest = j;
}
long j5 = newest;
if (j > j5 || j5 == -1) {
newest = j;
}
if (BgReading.getForPreciseTimestamp(j, DexCollectionType.getCurrentDeduplicationPeriod(), false) == null) {
UserError.Log.d("jamorham librereceiver", "Creating bgreading at: " + JoH.dateTimeText(glucoseData.realDate));
BgReading.create(d2, d2, xdrip.getAppContext(), Long.valueOf(glucoseData.realDate), z2);
} else {
UserError.Log.d("jamorham librereceiver", "Ignoring duplicate timestamp for: " + JoH.dateTimeText(glucoseData.realDate));
}
} else {
UserError.Log.e("jamorham librereceiver", "Fed a zero or negative date");
}
UserError.Log.d("jamorham librereceiver", "Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));
}
@Override
public void onReceive(final Context context, final Intent intent) {
new Thread() {
@Override
public void run() {
throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.LibreAlarmReceiver.AnonymousClass1.run():void");
}
}.start();
}
public static void processReadingDataTransferObject(ReadingData readingData, long j, String str, boolean z, byte[] bArr, byte[] bArr2, boolean z2) {
UserError.Log.d("jamorham librereceiver", "Data that was recieved from librealarm is " + HexDump.dumpHexString(readingData.raw_data));
LibreBlock.createAndSave(str, j, readingData.raw_data, 0, z, bArr, bArr2);
List<LibreTrendPoint> data = LibreTrendUtil.getInstance().getData(JoH.tsl() - 86400000, JoH.tsl(), true);
readingData.ClearErrors(data);
readingData.copyBgVals(data);
boolean booleanDefaultFalse = Pref.getBooleanDefaultFalse("libre_use_smoothed_data");
if (booleanDefaultFalse) {
readingData.calculateSmoothDataImproved(data, z2);
}
if (Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
UserError.Log.wtf("jamorham librereceiver", "Error external_blukon_algorithm should be false here");
}
CalculateFromDataTransferObject(readingData, booleanDefaultFalse, !Pref.getString("calibrate_external_libre_2_algorithm_type", "calibrate_raw").equals("no_calibration"));
}
public static void CalculateFromDataTransferObject(ReadingData readingData, boolean z, boolean z2) {
UserError.Log.i("jamorham librereceiver", "CalculateFromDataTransferObject called");
long currentDeduplicationPeriod = DexCollectionType.getCurrentDeduplicationPeriod();
List<GlucoseData> list = readingData.trend;
if (list != null && list.size() > 0) {
Collections.sort(list);
long j = list.get(list.size() - 1).sensorTime;
long j2 = Pref.getInt("nfc_sensor_age", 0);
sensorAge = j2;
if (j > j2 || SensorSanity.allowTestingWithDeadSensor()) {
sensorAge = j;
Pref.setInt("nfc_sensor_age", (int) j);
Pref.setBoolean("nfc_age_problem", false);
UserError.Log.d("jamorham librereceiver", "Sensor age advanced to: " + j);
} else {
if (j == sensorAge) {
if (BgReading.getTimeSinceLastReading().longValue() > 660000) {
UserError.Log.wtf("jamorham librereceiver", "Sensor age has not advanced: " + sensorAge);
JoH.static_toast_long(xdrip.gs(2131756284));
Pref.setBoolean("nfc_age_problem", true);
return;
}
return;
}
UserError.Log.wtf("jamorham librereceiver", "Sensor age has gone backwards!!! " + sensorAge);
JoH.static_toast_long(xdrip.gs(2131756282));
sensorAge = j;
Pref.setInt("nfc_sensor_age", (int) j);
Pref.setBoolean("nfc_age_problem", true);
}
UserError.Log.d("jamorham librereceiver", "Oldest cmp: " + JoH.dateTimeText(oldest_cmp) + " Newest cmp: " + JoH.dateTimeText(newest_cmp));
if (list.size() > 0) {
getTimeShift(list);
for (GlucoseData glucoseData : list) {
UserError.Log.d("jamorham librereceiver", "DEBUG: sensor time: " + glucoseData.sensorTime);
long j3 = timeShiftNearest;
if (j3 > 0) {
long j4 = glucoseData.realDate;
if (j3 - j4 < currentDeduplicationPeriod && j3 - j4 != 0) {
UserError.Log.d("jamorham librereceiver", "Skipping record due to closeness to the most recent value: " + JoH.dateTimeText(glucoseData.realDate));
}
}
if (z2) {
createBGfromGD(glucoseData, z, false);
} else {
BgReading.bgReadingInsertFromInt(z ? glucoseData.glucoseLevelSmoothed : glucoseData.glucoseLevel, glucoseData.realDate, currentDeduplicationPeriod, true, "Libre2");
}
}
} else {
UserError.Log.e("jamorham librereceiver", "Trend data was empty!");
}
insertFromHistory(readingData.history, z2);
return;
}
UserError.Log.d("jamorham librereceiver", "Trend data is null!");
}
public static void insertFromHistory(List<GlucoseData> list, boolean z) {
long j;
long j2;
long currentDeduplicationPeriod = DexCollectionType.getCurrentDeduplicationPeriod();
if (list != null && list.size() > 1) {
Collections.sort(list);
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
for (GlucoseData glucoseData : list) {
UserError.Log.d("jamorham librereceiver", "history : " + JoH.dateTimeText(glucoseData.realDate) + " " + glucoseData.glucose(false));
arrayList.add(Double.valueOf((double) glucoseData.realDate));
if (z) {
arrayList2.add(Double.valueOf(glucoseData.glucoseLevelRaw));
createBGfromGD(glucoseData, false, true);
} else {
arrayList2.add(Double.valueOf(glucoseData.glucoseLevel));
int i = glucoseData.glucoseLevel;
if (i > 0) {
BgReading.bgReadingInsertFromInt(i, glucoseData.realDate, currentDeduplicationPeriod, false, "Libre2");
}
}
}
long currentSamplePeriod = DexCollectionType.getCurrentSamplePeriod();
SplineInterpolator splineInterpolator = new SplineInterpolator();
if (arrayList.size() >= 3) {
try {
PolynomialSplineFunction interpolate = splineInterpolator.interpolate(Forecast.OLSTrendLine.toPrimitiveFromList(arrayList), Forecast.OLSTrendLine.toPrimitiveFromList(arrayList2));
long j3 = list.get(0).realDate;
long j4 = list.get(list.size() - 1).realDate;
long j5 = j3;
while (j5 <= j4) {
StringBuilder sb = new StringBuilder();
sb.append("Spline: ");
sb.append(JoH.dateTimeText(j5));
sb.append(" value: ");
double d = j5;
long j6 = currentDeduplicationPeriod;
sb.append((int) interpolate.value(d));
UserError.Log.d("jamorham librereceiver", sb.toString());
if (z) {
createBGfromGD(new GlucoseData((int) interpolate.value(d), j5), false, true);
j = j5;
j2 = j4;
} else {
j = j5;
j2 = j4;
BgReading.bgReadingInsertFromInt((int) interpolate.value(d), j5, j6, false, "Libre2");
}
j5 = j + currentSamplePeriod;
currentDeduplicationPeriod = j6;
j4 = j2;
}
return;
} catch (NonMonotonicSequenceException e) {
UserError.Log.e("jamorham librereceiver", "NonMonotonicSequenceException: " + e);
return;
}
}
return;
}
UserError.Log.e("jamorham librereceiver", "no history data");
}
private static long getTimeShift(List<GlucoseData> list) {
Iterator<GlucoseData> it = list.iterator();
long j = -1;
while (it.hasNext()) {
long j2 = it.next().realDate;
if (j2 > j) {
j = j2;
}
}
timeShiftNearest = j;
if (j > 0) {
long msSince = JoH.msSince(j);
if (msSince > 0 && msSince < 300000) {
return msSince;
}
}
return 0L;
}
}