正在查看: xDrip+ v04633772025.07.16 应用的 NightscoutFollowService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 NightscoutFollowService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.cgm.nsfollow;
import android.content.Intent;
import android.os.IBinder;
import android.os.PowerManager;
import android.text.SpannableString;
import com.eveningoutpost.dexdrip.cgm.nsfollow.utils.Anticipate;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbId;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.Treatments;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.Inevitable;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.StatusItem;
import com.eveningoutpost.dexdrip.utils.DexCollectionType;
import com.eveningoutpost.dexdrip.utils.framework.BuggySamsung;
import com.eveningoutpost.dexdrip.utils.framework.ForegroundService;
import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline;
import com.eveningoutpost.dexdrip.xdrip;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
public class NightscoutFollowService extends ForegroundService {
private static volatile long bgReceiveDelay = 0;
private static BuggySamsung buggySamsung = null;
private static volatile BgReading lastBg = null;
private static volatile long lastBgTime = 0;
private static volatile long lastPoll = 0;
protected static volatile String lastState = "";
private static volatile Treatments lastTreatment;
private static volatile long lastTreatmentTime;
private static volatile long treatmentReceivedDelay;
private static volatile long wakeup_time;
@Override
public IBinder onBind(Intent intent) {
return null;
}
private void buggySamsungCheck() {
if (buggySamsung == null) {
buggySamsung = new BuggySamsung("NightscoutFollow");
}
buggySamsung.evaluate(wakeup_time);
wakeup_time = 0L;
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
PowerManager.WakeLock wakeLock = JoH.getWakeLock("NSFollow-osc", UsbId.SILABS_CP2102);
try {
UserError.Log.d("NightscoutFollow", "WAKE UP WAKE UP WAKE UP");
if (!shouldServiceRun()) {
UserError.Log.d("NightscoutFollow", "Stopping service due to shouldServiceRun() result");
stopSelf();
JoH.releaseWakeLock(wakeLock);
return 2;
}
buggySamsungCheck();
lastBg = BgReading.lastNoSenssor();
if (lastBg != null) {
lastBgTime = lastBg.timestamp;
}
if (lastBg != null && JoH.msSince(lastBg.timestamp) <= 300000) {
UserError.Log.d("NightscoutFollow", "Already have recent reading: " + JoH.msSince(lastBg.timestamp));
scheduleWakeUp();
JoH.releaseWakeLock(wakeLock);
return 1;
}
if (JoH.ratelimit("last-ns-follow-poll", 5)) {
Inevitable.task("NS-Follow-Work", 200L, new Runnable() {
@Override
public final void run() {
NightscoutFollowService.lambda$onStartCommand$0();
}
});
}
scheduleWakeUp();
JoH.releaseWakeLock(wakeLock);
return 1;
} catch (Throwable th) {
JoH.releaseWakeLock(wakeLock);
throw th;
}
}
public static void lambda$onStartCommand$0() {
NightscoutFollow.work(true);
lastPoll = JoH.tsl();
}
static void updateBgReceiveDelay() {
lastBg = BgReading.lastNoSenssor();
if (lastBg == null || lastBgTime == lastBg.timestamp) {
return;
}
bgReceiveDelay = JoH.msSince(lastBg.timestamp);
lastBgTime = lastBg.timestamp;
}
static void updateTreatmentDownloaded() {
lastTreatment = Treatments.lastNotFromXdrip();
if (lastTreatment == null || lastTreatmentTime == lastTreatment.timestamp) {
return;
}
treatmentReceivedDelay = JoH.msSince(lastTreatment.timestamp);
lastTreatmentTime = lastTreatment.timestamp;
}
static void scheduleWakeUp() {
BgReading lastNoSenssor = BgReading.lastNoSenssor();
long j = lastNoSenssor != null ? lastNoSenssor.timestamp : 0L;
long next = Anticipate.next(JoH.tsl(), j, 300000L, 10000L) + 10000;
wakeup_time = next;
UserError.Log.d("NightscoutFollow", "Anticipate next: " + JoH.dateTimeText(next) + " last: " + JoH.dateTimeText(j));
JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(next), WakeLockTrampoline.getPendingIntent(NightscoutFollowService.class, 1020));
}
private static boolean shouldServiceRun() {
return DexCollectionType.getDexCollectionType() == DexCollectionType.NSFollow;
}
public static List<StatusItem> megaStatus() {
String str;
StatusItem.Highlight highlight;
String str2;
String str3;
BgReading lastNoSenssor = BgReading.lastNoSenssor();
long stringToInt = Pref.getStringToInt("nsfollow_lag", 0) * 1000;
String str4 = "n/a";
String niceTimeScalar = lastPoll > 0 ? JoH.niceTimeScalar(JoH.msSince(lastPoll)) : "n/a";
StatusItem.Highlight highlight2 = StatusItem.Highlight.NORMAL;
if (bgReceiveDelay > 0) {
str = JoH.niceTimeScalar(bgReceiveDelay);
highlight = bgReceiveDelay - stringToInt > 150000 ? StatusItem.Highlight.BAD : highlight2;
if (bgReceiveDelay - stringToInt > 600000) {
highlight = StatusItem.Highlight.CRITICAL;
}
} else {
str = "n/a";
highlight = highlight2;
}
if (lastNoSenssor != null) {
long msSince = JoH.msSince(lastNoSenssor.timestamp);
str2 = JoH.niceTimeScalar(msSince);
if (msSince > 330000 + stringToInt) {
highlight2 = StatusItem.Highlight.BAD;
}
} else {
str2 = "n/a";
}
if (lastTreatment != null) {
str4 = JoH.niceTimeScalar(JoH.msSince(lastTreatment.timestamp));
str3 = JoH.niceTimeScalar(treatmentReceivedDelay);
} else {
str3 = "n/a";
}
ArrayList arrayList = new ArrayList();
StringBuilder sb = new StringBuilder();
sb.append(str2);
sb.append(lastNoSenssor != null ? " ago" : "");
arrayList.add(new StatusItem("Latest BG", sb.toString(), highlight2));
arrayList.add(new StatusItem("BG receive delay", str, highlight));
if (NightscoutFollow.treatmentDownloadEnabled()) {
arrayList.add(new StatusItem());
StringBuilder sb2 = new StringBuilder();
sb2.append(str4);
sb2.append(lastTreatment != null ? " ago" : "");
arrayList.add(new StatusItem("Latest Treatment", sb2.toString()));
arrayList.add(new StatusItem("Treatment receive delay", str3));
}
arrayList.add(new StatusItem());
StringBuilder sb3 = new StringBuilder();
sb3.append(niceTimeScalar);
sb3.append(lastPoll <= 0 ? "" : " ago");
arrayList.add(new StatusItem("Last poll", sb3.toString()));
arrayList.add(new StatusItem("Next poll in", JoH.niceTimeScalar(wakeup_time - JoH.tsl())));
if (lastNoSenssor != null) {
arrayList.add(new StatusItem("Last BG time", JoH.dateTimeText(lastNoSenssor.timestamp)));
}
arrayList.add(new StatusItem("Next poll time", JoH.dateTimeText(wakeup_time)));
arrayList.add(new StatusItem());
arrayList.add(new StatusItem("Buggy handset", JoH.buggy_samsung ? xdrip.gs(2131757071) : xdrip.gs(2131755900)));
arrayList.add(new StatusItem("Download treatments", NightscoutFollow.treatmentDownloadEnabled() ? xdrip.gs(2131757071) : xdrip.gs(2131755900)));
if (StringUtils.isNotBlank(lastState)) {
arrayList.add(new StatusItem());
arrayList.add(new StatusItem("Last state", lastState));
}
return arrayList;
}
static void msg(String str) {
lastState = str;
}
public static SpannableString nanoStatus() {
if (JoH.emptyString(lastState)) {
return null;
}
return new SpannableString(lastState);
}
}