正在查看: xDrip+ v04633772025.07.16 应用的 AidexReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 AidexReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.receivers.aidex;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;
import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbId;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.BloodTest;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.Sensor;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utils.DexCollectionType;
import com.eveningoutpost.dexdrip.xdrip;
public class AidexReceiver extends BroadcastReceiver {
private static final Object lock = new Object();
private static SharedPreferences prefs;
@Override
public void onReceive(final Context context, final Intent intent) {
if (DexCollectionType.getDexCollectionType() != DexCollectionType.AidexReceiver) {
UserError.Log.w("AidexReceiver", "Received Aidex Broadcast, but AidexReceiver is not selected as collector.");
} else {
new Thread() {
@Override
public void run() {
char c;
PowerManager.WakeLock wakeLock = JoH.getWakeLock("aidex-receiver", UsbId.SILABS_CP2102);
synchronized (AidexReceiver.lock) {
try {
UserError.Log.d("AidexReceiver", "Aidex onReceiver: " + intent.getAction());
JoH.benchmark(null);
if (AidexReceiver.prefs == null) {
SharedPreferences unused = AidexReceiver.prefs = PreferenceManager.getDefaultSharedPreferences(context);
}
Bundle extras = intent.getExtras();
String action = intent.getAction();
if (extras != null && action != null) {
UserError.Log.d("AidexReceiver", "Action: " + action);
JoH.dumpBundle(extras, "AidexReceiver");
switch (action.hashCode()) {
case -1647543956:
if (action.equals("com.microtechmd.cgms.aidex.action.BgEstimate")) {
c = 0;
break;
}
c = 65535;
break;
case -1350842870:
if (action.equals("com.microtechmd.cgms.aidex.action.Notification")) {
c = 5;
break;
}
c = 65535;
break;
case -719667989:
if (action.equals("com.microtechmd.cgms.aidex.action.Calibration")) {
c = 1;
break;
}
c = 65535;
break;
case 166757302:
if (action.equals("com.microtechmd.cgms.aidex.action.SensorRestart")) {
c = 3;
break;
}
c = 65535;
break;
case 1226791867:
if (action.equals("com.microtechmd.cgms.aidex.action.SensorStop")) {
c = 4;
break;
}
c = 65535;
break;
case 1563589319:
if (action.equals("com.microtechmd.cgms.aidex.action.SensorNew")) {
c = 2;
break;
}
c = 65535;
break;
default:
c = 65535;
break;
}
if (c == 0) {
AidexReceiver.this.processNewBGEstimate(extras);
} else if (c == 1) {
AidexReceiver.this.processCalibration(extras);
} else if (c == 2) {
AidexReceiver.this.processSensorStart(extras);
} else if (c == 3) {
AidexReceiver.this.processSensorRestart(extras);
} else if (c == 4) {
AidexReceiver.this.processSensorStop(extras);
} else if (c == 5) {
AidexReceiver.this.processNotification(extras);
} else {
UserError.Log.e("AidexReceiver", "Unknown action! " + action);
}
return;
}
UserError.Log.d("AidexReceiver", "Either bundle or action is null.");
} finally {
JoH.benchmark("Aidex process");
JoH.releaseWakeLock(wakeLock);
}
}
}
}.start();
}
}
public void processNewBGEstimate(Bundle bundle) {
int doubleValue;
if (!bundle.containsKey("com.microtechmd.cgms.aidex.Time") || !bundle.containsKey("com.microtechmd.cgms.aidex.SensorId") || !bundle.containsKey("com.microtechmd.cgms.aidex.BgType") || !bundle.containsKey("com.microtechmd.cgms.aidex.BgValue")) {
UserError.Log.e("AidexReceiver", "Aidex Broadcast for NewBGEstimate invalid, missing one of required parameters: SendorId, Timestamp, BgType or BgValue! Ignoring broadcast.");
return;
}
String string = bundle.getString("com.microtechmd.cgms.aidex.SensorId");
long j = bundle.getLong("com.microtechmd.cgms.aidex.Time");
String string2 = bundle.getString("com.microtechmd.cgms.aidex.BgType");
Double valueOf = Double.valueOf(bundle.getDouble("com.microtechmd.cgms.aidex.BgValue"));
if ("mg/dl".equalsIgnoreCase(string2)) {
doubleValue = valueOf.intValue();
} else if ("mmol/l".equalsIgnoreCase(string2)) {
doubleValue = (int) (valueOf.doubleValue() * 18.0182d);
} else {
UserError.Log.e("AidexReceiver", "Aidex Broadcast BgType invalid. BgType needs to be either: mg/dl or mmol/l.");
return;
}
int i = doubleValue;
if (i <= 0) {
UserError.Log.w("AidexReceiver", "Aidex Broadcast received BG=0, ignoring it.");
return;
}
checkIfCorrectSensorIsRunning(string, j);
UserError.Log.i("AidexReceiver", "Aidex Broadcast NewBGEstimate received: bg=" + i + ", time=" + JoH.dateTimeText(j));
BgReading.bgReadingInsertFromInt(i, j, 270000L, true);
}
private void checkIfCorrectSensorIsRunning(String str, long j) {
Sensor currentSensor = Sensor.currentSensor();
if (currentSensor != null) {
if (currentSensor.uuid.equals(str) || !JoH.pratelimit("aidex-sensor-restart", 1200)) {
return;
}
Sensor.stopSensor();
Sensor.create(j - 10000, str);
return;
}
Sensor.create(j - 10000, str);
}
public void processCalibration(Bundle bundle) {
if (Pref.getBooleanDefaultFalse("accept_broadcast_calibrations")) {
long j = bundle.getLong("com.microtechmd.cgms.aidex.Time", -1L);
double d = bundle.getDouble("com.microtechmd.cgms.aidex.BgValue", -1.0d);
String string = bundle.getString("com.microtechmd.cgms.aidex.BgType", "mg/dl");
long tsl = JoH.tsl() - j;
if (d <= BgReading.BESTOFFSET) {
Log.e("AidexReceiver", "Received broadcast calibration without glucose number");
return;
}
if (tsl < 0) {
Home.toaststaticnext(xdrip.gs(2131755638));
return;
}
double d2 = "mmol/l".equals(string) ? 18.0182d * d : d;
UserError.Log.ueh("AidexReceiver", "Adding blood test calibration: " + JoH.qs(d, 2) + " offset ms: " + JoH.qs(tsl, 0));
BloodTest.create(j, d2, "Aidex", null);
return;
}
Log.w("AidexReceiver", "Received broadcast calibration from Aidex, but we don't accept calibrations (check settings)");
}
public void processSensorStart(Bundle bundle) {
if (bundle == null || !bundle.containsKey("com.microtechmd.cgms.aidex.Time")) {
return;
}
long j = bundle.getLong("com.microtechmd.cgms.aidex.Time");
if (stopCurrentSensor(bundle.getString("com.microtechmd.cgms.aidex.SensorId"))) {
Sensor.create(j, bundle.getString("com.microtechmd.cgms.aidex.SensorId"));
}
}
private boolean stopCurrentSensor(String str) {
Sensor currentSensor = Sensor.currentSensor();
if (currentSensor == null) {
return true;
}
if (currentSensor.uuid.equals(str)) {
return false;
}
Sensor.stopSensor();
return true;
}
public void processSensorRestart(Bundle bundle) {
Log.w("AidexReceiver", "Received broadcast Sensor Restart from Aidex, but we don't process it.");
if (JoH.pratelimit("aidex-sensor-restart", 1200)) {
String string = bundle.getString("com.microtechmd.cgms.aidex.SensorId");
Sensor byUuid = Sensor.getByUuid(string);
long j = bundle.getLong("com.microtechmd.cgms.aidex.Time");
if (byUuid != null) {
Sensor currentSensor = Sensor.currentSensor();
if (currentSensor == null) {
if (byUuid.stopped_at != 0) {
Sensor.restartSensor(string);
return;
}
return;
} else {
if (byUuid.equals(currentSensor)) {
return;
}
stopCurrentSensor("x");
if (byUuid.stopped_at != 0) {
Sensor.restartSensor(string);
return;
}
return;
}
}
if (stopCurrentSensor(string)) {
Sensor.create(j, string);
return;
}
return;
}
UserError.Log.wtf("AidexReceiver", "Exceeded rate limit for sensor restart in processSensorRestart()");
}
public void processSensorStop(Bundle bundle) {
String string = bundle.getString("com.microtechmd.cgms.aidex.SensorId");
Sensor currentSensor = Sensor.currentSensor();
if (currentSensor == null || currentSensor.uuid.equals(string)) {
return;
}
Sensor.stopSensor();
}
public void processNotification(Bundle bundle) {
UserError.Log.i("AidexReceiver", "Received Aidex Notification");
String string = bundle.getString("com.microtechmd.cgms.aidex.MessageType");
String string2 = bundle.getString("com.microtechmd.cgms.aidex.MessageValue");
if (string2 != null && string2.length() > 0) {
UserError.Log.i("AidexReceiver", " Notification type=" + string + " with value=" + string2);
return;
}
UserError.Log.i("AidexReceiver", " Notification type=" + string);
}
}