正在查看: xDrip+ v04633772025.07.16 应用的 SyncingService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 SyncingService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.importedlibraries.dexcom;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import androidx.health.platform.client.error.ErrorCode;
import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalRecord;
import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.CdcAcmSerialDriver;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.ProbeTable;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbSerialDriver;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbSerialProber;
import com.eveningoutpost.dexdrip.models.Calibration;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import java.io.IOException;
import java.util.HashMap;
import org.json.JSONArray;
public class SyncingService extends IntentService {
private final String TAG;
private final int TIME_SYNC_OFFSET;
private UsbDevice dexcom;
private UsbDeviceConnection mConnection;
private Context mContext;
private UsbSerialDriver mSerialDevice;
private UsbManager mUsbManager;
public static void startActionCalibrationCheckin(Context context) {
Intent intent = new Intent(context, (Class<?>) SyncingService.class);
intent.setAction("com.eveningoutpost.dexdrip.CalibrationCheckInActivity");
context.startService(intent);
}
public SyncingService() {
super("SyncingService");
this.TAG = SyncingService.class.getSimpleName();
this.TIME_SYNC_OFFSET = ErrorCode.INVALID_OWNERSHIP;
}
@Override
protected void onHandleIntent(Intent intent) {
this.mContext = getApplicationContext();
if (intent != null) {
String action = intent.getAction();
if ("com.eveningoutpost.dexdrip.importedlibraries.dexcom.action.SYNC".equals(action)) {
handleActionSync(intent.getIntExtra("com.eveningoutpost.dexdrip.importedlibraries.dexcom.extra.SYNC_PERIOD", 1));
} else if ("com.eveningoutpost.dexdrip.CalibrationCheckInActivity".equals(action)) {
UserError.Log.i("CALIBRATION-CHECK-IN: ", "Beginning check in process");
performCalibrationCheckin();
}
}
}
private void performCalibrationCheckin() {
String str;
PowerManager.WakeLock newWakeLock = ((PowerManager) getApplicationContext().getSystemService("power")).newWakeLock(1, "NSDownload");
newWakeLock.acquire();
try {
UserError.Log.i("CALIBRATION-CHECK-IN: ", "Wake Lock Acquired");
if (acquireSerialDevice()) {
try {
try {
CalRecord[] recentCalRecords = new ReadData(this.mSerialDevice, this.mConnection, this.dexcom).getRecentCalRecords();
UserError.Log.i("CALIBRATION-CHECK-IN: ", "Found " + recentCalRecords.length + " Records!");
save_most_recent_cal_record(recentCalRecords);
} catch (Exception e) {
UserError.Log.wtf("Unhandled exception caught", e);
try {
this.mSerialDevice.getPorts().get(0).close();
} catch (IOException e2) {
e = e2;
str = this.TAG;
UserError.Log.e(str, "Unable to close", e);
}
}
try {
this.mSerialDevice.getPorts().get(0).close();
} catch (IOException e3) {
e = e3;
str = this.TAG;
UserError.Log.e(str, "Unable to close", e);
}
} finally {
}
} else {
UserError.Log.w("CALIBRATION-CHECK-IN: ", "Failed to acquire serial device");
}
} finally {
JoH.releaseWakeLock(newWakeLock);
}
}
private void handleActionSync(int i) {
PowerManager.WakeLock newWakeLock = ((PowerManager) getApplicationContext().getSystemService("power")).newWakeLock(1, "NSDownload");
newWakeLock.acquire();
try {
sync(i);
} finally {
newWakeLock.release();
}
}
private void sync(int i) {
if (acquireSerialDevice()) {
try {
try {
try {
try {
try {
ReadData readData = new ReadData(this.mSerialDevice);
EGVRecord[] recentEGVsPages = readData.getRecentEGVsPages(i);
readData.getRecentMeterRecords();
Utils.mergeGlucoseDataRecords(recentEGVsPages, readData.getRecentSensorRecords(i));
if (PreferenceManager.getDefaultSharedPreferences(this.mContext).getBoolean("cloud_cal_data", false)) {
readData.getRecentCalRecords();
}
readData.getTimeSinceEGVRecord(recentEGVsPages[recentEGVsPages.length - 1]);
readData.readDisplayTime().getTime();
JSONArray jSONArray = new JSONArray();
for (EGVRecord eGVRecord : recentEGVsPages) {
jSONArray.put(eGVRecord.toJSON());
}
EGVRecord eGVRecord2 = recentEGVsPages[recentEGVsPages.length - 1];
this.mSerialDevice.getPorts().get(0).close();
} catch (NegativeArraySizeException e) {
UserError.Log.wtf("Negative array exception from receiver", e);
this.mSerialDevice.getPorts().get(0).close();
}
} catch (ArrayIndexOutOfBoundsException e2) {
UserError.Log.wtf("Unable to read from the dexcom, maybe it will work next time", e2);
this.mSerialDevice.getPorts().get(0).close();
} catch (IndexOutOfBoundsException e3) {
UserError.Log.wtf("IndexOutOfBounds exception from receiver", e3);
this.mSerialDevice.getPorts().get(0).close();
}
} catch (CRCFailRuntimeException e4) {
UserError.Log.wtf("CRC failed", e4);
this.mSerialDevice.getPorts().get(0).close();
} catch (Exception e5) {
UserError.Log.wtf("Unhandled exception caught", e5);
this.mSerialDevice.getPorts().get(0).close();
}
} catch (Throwable th) {
try {
this.mSerialDevice.getPorts().get(0).close();
} catch (IOException e6) {
UserError.Log.e(this.TAG, "Unable to close", e6);
}
throw th;
}
} catch (IOException e7) {
UserError.Log.e(this.TAG, "Unable to close", e7);
}
}
}
private void save_most_recent_cal_record(CalRecord[] calRecordArr) {
int length = calRecordArr.length;
Calibration.create(calRecordArr, getApplicationContext(), false, 0L);
}
private boolean acquireSerialDevice() {
findDexcom();
UsbManager usbManager = this.mUsbManager;
if (usbManager == null) {
UserError.Log.w("CALIBRATION-CHECK-IN: ", "USB manager is null");
return false;
}
UsbDevice usbDevice = this.dexcom;
if (usbDevice == null) {
UserError.Log.e(this.TAG, "dex device == null");
return false;
}
if (usbManager.hasPermission(usbDevice)) {
ProbeTable probeTable = new ProbeTable();
probeTable.addProduct(8867, 71, CdcAcmSerialDriver.class);
for (UsbSerialDriver usbSerialDriver : new UsbSerialProber(probeTable).findAllDrivers(this.mUsbManager)) {
if (usbSerialDriver != null) {
UsbDeviceConnection openDevice = this.mUsbManager.openDevice(usbSerialDriver.getDevice());
if (openDevice != null) {
this.mSerialDevice = usbSerialDriver;
this.mConnection = openDevice;
UserError.Log.i("CALIBRATION-CHECK-IN: ", "CONNECTEDDDD!!");
return true;
}
} else {
UserError.Log.w("CALIBRATION-CHECK-IN: ", "Driver was no good");
}
}
UserError.Log.w("CALIBRATION-CHECK-IN: ", "No usable drivers found");
} else {
UserError.Log.w("CALIBRATION-CHECK-IN: ", "You dont have permissions for that dexcom!!");
}
return false;
}
public static boolean isG4Connected(Context context) {
HashMap<String, UsbDevice> deviceList = ((UsbManager) context.getSystemService("usb")).getDeviceList();
UserError.Log.i("USB DEVICES = ", deviceList.toString());
UserError.Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));
for (UsbDevice usbDevice : deviceList.values()) {
if (usbDevice.getVendorId() == 8867 && usbDevice.getProductId() == 71 && usbDevice.getDeviceClass() == 2 && usbDevice.getDeviceSubclass() == 0 && usbDevice.getDeviceProtocol() == 0) {
UserError.Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
return true;
}
}
return false;
}
public UsbDevice findDexcom() {
UserError.Log.i("CALIBRATION-CHECK-IN: ", "Searching for dexcom");
UsbManager usbManager = (UsbManager) getApplicationContext().getSystemService("usb");
this.mUsbManager = usbManager;
UserError.Log.i("USB MANAGER = ", usbManager.toString());
HashMap<String, UsbDevice> deviceList = this.mUsbManager.getDeviceList();
UserError.Log.i("USB DEVICES = ", deviceList.toString());
UserError.Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));
for (UsbDevice usbDevice : deviceList.values()) {
if (usbDevice.getVendorId() == 8867 && usbDevice.getProductId() == 71 && usbDevice.getDeviceClass() == 2 && usbDevice.getDeviceSubclass() == 0 && usbDevice.getDeviceProtocol() == 0) {
this.dexcom = usbDevice;
UserError.Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
return usbDevice;
}
UserError.Log.w("CALIBRATION-CHECK-IN: ", "that was not a dexcom (I dont think)");
}
return null;
}
}