正在查看: xDrip+ v04633772025.07.16 应用的 ShareFollowService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 ShareFollowService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.cgm.sharefollow;
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.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;
public class ShareFollowService extends ForegroundService {
private static volatile long bgReceiveDelay = 0;
private static BuggySamsung buggySamsung = null;
private static ShareFollowDownload downloader = 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 long last_wakeup;
private static volatile long wakeup_time;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
resetInstance();
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
PowerManager.WakeLock wakeLock = JoH.getWakeLock("SHFollow-osc", UsbId.SILABS_CP2102);
try {
UserError.Log.d("ShareFollow", "WAKE UP WAKE UP WAKE UP");
if (!shouldServiceRun()) {
UserError.Log.d("ShareFollow", "Stopping service due to shouldServiceRun() result");
stopSelf();
JoH.releaseWakeLock(wakeLock);
return 2;
}
buggySamsungCheck();
last_wakeup = JoH.tsl();
lastBg = BgReading.lastNoSenssor();
if (lastBg != null) {
lastBgTime = lastBg.timestamp;
}
if (lastBg != null && JoH.msSince(lastBg.timestamp) <= 300000) {
UserError.Log.d("ShareFollow", "Already have recent reading: " + JoH.msSince(lastBg.timestamp));
scheduleWakeUp();
return 1;
}
if (downloader == null) {
downloader = new ShareFollowDownload(Pref.getBoolean("dex_share_us_acct", true) ? "https://share2.dexcom.com/ShareWebServices/Services/" : "https://shareous1.dexcom.com/ShareWebServices/Services/", Pref.getString("shfollow_user", ""), Pref.getString("shfollow_pass", ""));
}
if (JoH.ratelimit("last-sh-follow-poll", 5)) {
Inevitable.task("SH-Follow-Work", 200L, new Runnable() {
@Override
public final void run() {
ShareFollowService.lambda$onStartCommand$0();
}
});
lastPoll = JoH.tsl();
}
scheduleWakeUp();
return 1;
} finally {
JoH.releaseWakeLock(wakeLock);
}
}
public static void lambda$onStartCommand$0() {
try {
downloader.doEverything(288);
} catch (NullPointerException unused) {
UserError.Log.e("ShareFollow", "Caught concurrency exception when trying to run doeverything");
}
}
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("ShareFollow", "Anticipate next: " + JoH.dateTimeText(next) + " last: " + JoH.dateTimeText(j));
JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(next), WakeLockTrampoline.getPendingIntent(ShareFollowService.class, 1024));
}
private static boolean shouldServiceRun() {
return DexCollectionType.getDexCollectionType() == DexCollectionType.SHFollow;
}
public static boolean isCollecting() {
return JoH.msSince(last_wakeup) < 900000;
}
@Override
public void onDestroy() {
super.onDestroy();
resetInstance();
}
private void buggySamsungCheck() {
if (buggySamsung == null) {
buggySamsung = new BuggySamsung("ShareFollow");
}
buggySamsung.evaluate(wakeup_time);
wakeup_time = 0L;
}
private static String getBestStatusMessage() {
if (JoH.emptyString(lastState)) {
ShareFollowDownload shareFollowDownload = downloader;
if (shareFollowDownload != null) {
return shareFollowDownload.getStatus();
}
return null;
}
return lastState;
}
public static List<StatusItem> megaStatus() {
StatusItem.Highlight highlight;
String str;
String str2;
String str3;
BgReading lastNoSenssor = BgReading.lastNoSenssor();
StatusItem.Highlight highlight2 = StatusItem.Highlight.NORMAL;
String str4 = "n/a";
if (bgReceiveDelay > 0) {
str = JoH.niceTimeScalar(bgReceiveDelay);
highlight = bgReceiveDelay > 150000 ? StatusItem.Highlight.BAD : highlight2;
if (bgReceiveDelay > 600000) {
highlight = StatusItem.Highlight.CRITICAL;
}
} else {
highlight = highlight2;
str = "n/a";
}
if (lastNoSenssor != null) {
long msSince = JoH.msSince(lastNoSenssor.timestamp);
str2 = JoH.niceTimeScalar(msSince);
if (msSince > 330000) {
highlight2 = StatusItem.Highlight.BAD;
}
} else {
str2 = "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 (lastPoll > 0) {
str3 = JoH.niceTimeScalar(JoH.msSince(lastPoll)) + " ago";
} else {
str3 = "n/a";
}
arrayList.add(new StatusItem("Last poll", str3));
if (last_wakeup > 0) {
str4 = JoH.niceTimeScalar(JoH.msSince(last_wakeup)) + " ago";
}
arrayList.add(new StatusItem("Last wakeup", str4));
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("Buggy handset", xdrip.gs(JoH.buggy_samsung ? 2131757071 : 2131755900)));
return arrayList;
}
static void updateBgReceiveDelay() {
lastBg = BgReading.lastNoSenssor();
if (lastBg == null || lastBgTime == lastBg.timestamp) {
return;
}
bgReceiveDelay = JoH.msSince(lastBg.timestamp);
lastBgTime = lastBg.timestamp;
}
public static synchronized void resetInstanceAndInvalidateSession() {
synchronized (ShareFollowService.class) {
try {
ShareFollowDownload shareFollowDownload = downloader;
if (shareFollowDownload != null) {
shareFollowDownload.invalidateSession();
}
} catch (Exception unused) {
}
resetInstance();
}
}
public static void resetInstance() {
downloader = null;
}
public static SpannableString nanoStatus() {
String bestStatusMessage = getBestStatusMessage();
if (JoH.emptyString(bestStatusMessage)) {
return null;
}
return new SpannableString(bestStatusMessage);
}
}