正在查看: xDrip+ v04633772025.07.16 应用的 NSClientReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 NSClientReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import com.eveningoutpost.dexdrip.insulin.aaps.AAPSStatusHandler;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import java.util.HashMap;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class NSClientReceiver extends BroadcastReceiver {
private static SharedPreferences prefs;
@Override
public void onReceive(Context context, Intent intent) {
int i;
Log.d("jamorham nsreceiver", "NSRECEIVER onReceiver: " + intent.getAction());
if (prefs == null) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
}
Bundle extras = intent.getExtras();
String action = intent.getAction();
if (action == null) {
}
i = 0;
switch (action) {
case "info.nightscout.client.NEW_FOOD":
case "info.nightscout.client.NEW_TREATMENT":
if (extras != null) {
if (prefs.getBoolean("accept_nsclient_treatments", true)) {
String string = extras.getString("treatment", "");
if (string.length() > 0) {
process_TREATMENT_json(string);
}
String string2 = extras.getString("treatments", "");
if (string2.length() > 0) {
try {
JSONArray jSONArray = new JSONArray(string2);
while (i < jSONArray.length()) {
process_TREATMENT_json(jSONArray.getString(i));
i++;
}
break;
} catch (JSONException e) {
Log.e("jamorham nsreceiver", "Json exception with treatments: " + e.toString());
return;
}
}
} else {
Log.d("jamorham nsreceiver", "Ignoring nsclient treatment data due to preference");
break;
}
}
break;
case "info.nightscout.client.NS_BRIDGE":
case "info.nightscout.client.NEW_DEVICESTATUS":
if (extras != null) {
if (prefs.getBoolean("accept_nsclient_treatments", true)) {
String string3 = extras.getString("devicestatus", "");
if (!JoH.emptyString(string3)) {
try {
AAPSStatusHandler.processDeviceStatus(string3);
break;
} catch (Exception e2) {
Log.e("jamorham nsreceiver", "Exception processing device status in NS_BRIDGE action: " + e2);
return;
}
} else {
Log.e("jamorham nsreceiver", "Empty device status received via NS_BRIDGE action");
break;
}
} else {
Log.e("jamorham nsreceiver", "Cannot accept device status as preference setting prevents it");
break;
}
}
break;
case "info.nightscout.client.NEW_SGV":
if (!Home.get_follower() || !prefs.getBoolean("accept_nsclient_sgv", true)) {
Log.d("jamorham nsreceiver", "Ignoring SGV data as we are not a follower");
break;
} else if (extras != null) {
String string4 = extras.getString("sgvs", "");
if (string4.length() > 0) {
try {
JSONArray jSONArray2 = new JSONArray(string4);
while (i < jSONArray2.length()) {
process_SGV_json(jSONArray2.getString(i));
i++;
}
} catch (JSONException e3) {
Log.e("jamorham nsreceiver", "Json exception with sgvs: " + e3.toString());
}
}
String string5 = extras.getString("sgv", "");
if (string5.length() > 0) {
process_SGV_json(string5);
break;
}
}
break;
case "com.eveningoutpost.dexdrip.NewCalibration":
if (extras != null) {
if (Pref.getBooleanDefaultFalse("accept_broadcast_calibrations")) {
long j = extras.getLong("timestamp", -1L);
double d = extras.getDouble("glucose_number", -1.0d);
String string6 = extras.getString("units", "");
long tsl = JoH.tsl() - j;
if (d <= BgReading.BESTOFFSET) {
Log.e("jamorham nsreceiver", "Received broadcast calibration without glucose number");
break;
} else if (tsl < 0) {
Home.toaststaticnext(xdrip.gs(2131755638));
break;
} else {
String string7 = Pref.getString("units", "mgdl");
if (string6.equals("mgdl") && !string7.equals("mgdl")) {
d *= 0.0554994394556615d;
Log.d("jamorham nsreceiver", "Converting from mgdl to mmol: " + JoH.qs(d, 2));
} else if (string6.equals("mmol") && !string7.equals("mmol")) {
d *= 18.0182d;
Log.d("jamorham nsreceiver", "Converting from mmol to mgdl: " + JoH.qs(d, 2));
}
UserError.Log.ueh("jamorham nsreceiver", "Processing broadcasted calibration: " + JoH.qs(d, 2) + " offset ms: " + JoH.qs(tsl, 0));
Intent intent2 = new Intent(xdrip.getAppContext(), (Class<?>) AddCalibration.class);
intent2.setFlags(268435456);
intent2.putExtra("timestamp", JoH.tsl());
intent2.putExtra("bg_string", JoH.qs(d));
intent2.putExtra("bg_age", Long.toString(tsl / 1000));
intent2.putExtra("allow_undo", "true");
intent2.putExtra("note_only", "false");
intent2.putExtra("cal_source", "NSClientReceiver");
Home.startIntentThreadWithDelayedRefresh(intent2);
break;
}
} else {
Log.e("jamorham nsreceiver", "Received broadcast calibration, but inter-app preference is set to ignore");
break;
}
}
break;
default:
Log.e("jamorham nsreceiver", "Unknown action! " + action);
break;
}
}
private void process_TREATMENT_json(java.lang.String r6) {
throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.NSClientReceiver.process_TREATMENT_json(java.lang.String):void");
}
private void process_SGV_json(String str) {
if (str == null) {
Log.e("jamorham nsreceiver", "SGV json is null!");
return;
}
HashMap<String, Object> JsonStringtoMap = JoH.JsonStringtoMap(str);
if (JsonStringtoMap == null) {
Log.e("jamorham nsreceiver", "SGV map results in null!");
} else {
BgReading.bgReadingInsertFromJson(toBgReadingJSON(JsonStringtoMap));
}
}
private String toBgReadingJSON(HashMap<String, Object> hashMap) {
JSONObject jSONObject = new JSONObject();
try {
try {
jSONObject.put("uuid", UUID.randomUUID().toString());
jSONObject.put("source_info", "NSClient Follow");
jSONObject.put("timestamp", hashMap.get("mills"));
jSONObject.put("calculated_value", hashMap.get("mgdl"));
try {
jSONObject.put("filtered_calculated_value", ((Double) hashMap.get("filtered")).doubleValue() / (((Double) hashMap.get("unfiltered")).doubleValue() / ((Double) hashMap.get("mgdl")).doubleValue()));
} catch (NullPointerException unused) {
Log.i("jamorham nsreceiver", "Cannot calculate raw slope due to null pointer on unfiltered?");
jSONObject.put("filtered_calculated_value", hashMap.get("mgdl"));
}
jSONObject.put("filtered_data", hashMap.get("filtered") != null ? ((Double) hashMap.get("filtered")).doubleValue() / 1000.0d : 1.0d);
jSONObject.put("raw_data", hashMap.get("unfiltered") != null ? ((Double) hashMap.get("unfiltered")).doubleValue() / 1000.0d : 1.0d);
jSONObject.put("calculated_value_slope", Double.valueOf(BgReading.slopefromName(hashMap.get("direction").toString())));
if (BgReading.isSlopeNameInvalid(hashMap.get("direction").toString())) {
jSONObject.put("hide_slope", true);
}
jSONObject.put("noise", hashMap.get("noise"));
return jSONObject.toString();
} catch (JSONException e) {
e = e;
Log.e("jamorham nsreceiver", "JSON or Null Exception in toBgReadingJSON: " + e);
return "";
}
} catch (NullPointerException e2) {
e = e2;
Log.e("jamorham nsreceiver", "JSON or Null Exception in toBgReadingJSON: " + e);
return "";
}
}
private String toTreatmentJSON(HashMap<String, Object> hashMap) {
JSONObject jSONObject = new JSONObject();
try {
Object obj = hashMap.get("mills");
if (obj == null) {
obj = hashMap.get("date");
}
jSONObject.put("timestamp", obj);
jSONObject.put("eventType", hashMap.get("eventType"));
jSONObject.put("enteredBy", hashMap.get("enteredBy"));
if (hashMap.containsKey("carbs")) {
jSONObject.put("carbs", hashMap.get("carbs"));
}
if (hashMap.containsKey("insulin")) {
jSONObject.put("insulin", hashMap.get("insulin"));
}
if (hashMap.containsKey("insulinJSON")) {
jSONObject.put("insulinInjections", hashMap.get("insulinJSON"));
}
if (hashMap.containsKey("notes")) {
jSONObject.put("notes", hashMap.get("notes"));
}
jSONObject.put("created_at", hashMap.get("created_at"));
return jSONObject.toString();
} catch (JSONException e) {
e.printStackTrace();
return "";
}
}
}