正在查看: xDrip+ v04633772025.07.16 应用的 CareLinkFollowService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 CareLinkFollowService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.cgm.carelinkfollow;
import android.content.Intent;
import android.os.IBinder;
import android.os.PowerManager;
import android.text.SpannableString;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthType;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkCredentialStore;
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.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;
public class CareLinkFollowService extends ForegroundService {
private static volatile long bgReceiveDelay = 0;
private static BuggySamsung buggySamsung = null;
private static CareLinkFollowDownloader downloader = null;
private static volatile int gracePeriod = 0;
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 int missedPollInterval;
private static volatile int renewBefore;
private static volatile int renewInterval;
private static volatile long wakeup_time;
private static long anticipateNextTokenRefresh(long j, long j2, long j3, long j4) {
long j5 = j2 - j3;
while (j5 <= j) {
j5 += j4;
}
return j5;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
resetInstance();
}
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 (CareLinkFollowService.class) {
try {
CareLinkFollowDownloader careLinkFollowDownloader = downloader;
if (careLinkFollowDownloader != null) {
careLinkFollowDownloader.invalidateSession();
}
} catch (Exception unused) {
}
resetInstance();
}
}
public static void resetInstance() {
downloader = null;
gracePeriod = 0;
missedPollInterval = 0;
renewBefore = 0;
renewInterval = 0;
}
private static boolean shouldServiceRun() {
return DexCollectionType.getDexCollectionType() == DexCollectionType.CLFollow;
}
private static long getGraceMillis() {
return gracePeriod * 1000;
}
private static long getMissedIntervalMillis() {
if (missedPollInterval == 0) {
return 300000L;
}
return missedPollInterval * 60000;
}
private static long getRenewBeforeMillis() {
return renewBefore * 60000;
}
private static long getRenewIntervalMillis() {
return renewInterval * 60000;
}
static void scheduleWakeUp() {
String str;
BgReading lastNoSenssor = BgReading.lastNoSenssor();
long j = lastNoSenssor != null ? lastNoSenssor.timestamp : 0L;
long anticipateNextTokenRefresh = anticipateNextTokenRefresh(JoH.tsl(), CareLinkCredentialStore.getInstance().getAccessExpiresOn(), getRenewBeforeMillis(), getRenewIntervalMillis());
long anticipateNextDataPoll = anticipateNextDataPoll(JoH.tsl(), j, 300000L, getGraceMillis(), getMissedIntervalMillis());
if (anticipateNextTokenRefresh <= anticipateNextDataPoll) {
str = " as access expires: ";
} else {
anticipateNextTokenRefresh = anticipateNextDataPoll;
str = " as last BG timestamp: ";
}
if (JoH.msTill(anticipateNextTokenRefresh) < 20000) {
anticipateNextTokenRefresh = JoH.tsl() + 20000;
}
wakeup_time = anticipateNextTokenRefresh;
UserError.Log.d("CareLinkFollow", "Anticipate next: " + JoH.dateTimeText(anticipateNextTokenRefresh) + str + JoH.dateTimeText(j));
JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(anticipateNextTokenRefresh), WakeLockTrampoline.getPendingIntent(CareLinkFollowService.class, 1030));
}
public static long anticipateNextDataPoll(long j, long j2, long j3, long j4, long j5) {
long j6;
if (j - j2 < j3) {
j6 = j2 + j3;
} else {
j6 = ((j2 - j) % j3) + j;
while (j6 <= j) {
j6 += j5;
}
}
return j6 + j4;
}
private static CareLinkFollowDownloader getDownloader() {
if (downloader == null) {
downloader = new CareLinkFollowDownloader(Pref.getString("clfollow_user", ""), Pref.getString("clfollow_pass", ""), Pref.getString("clfollow_country", "").toLowerCase(), Pref.getString("clfollow_patient", ""));
}
return downloader;
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
PowerManager.WakeLock wakeLock = JoH.getWakeLock("CareLinkFollow-osc", UsbId.SILABS_CP2102);
try {
UserError.Log.d("CareLinkFollow", "WAKE UP WAKE UP WAKE UP");
if (!shouldServiceRun()) {
UserError.Log.d("CareLinkFollow", "Stopping service due to shouldServiceRun() result");
msg("Stopping");
stopSelf();
JoH.releaseWakeLock(wakeLock);
return 2;
}
buggySamsungCheck();
last_wakeup = JoH.tsl();
if (gracePeriod == 0) {
gracePeriod = Pref.getStringToInt("clfollow_grace_period", 30);
}
if (missedPollInterval == 0) {
missedPollInterval = Pref.getStringToInt("clfollow_missed_poll_interval", 5);
}
if (renewBefore == 0) {
renewBefore = 10;
}
if (renewInterval == 0) {
renewInterval = 1;
}
lastBg = BgReading.lastNoSenssor();
if (lastBg != null) {
lastBgTime = lastBg.timestamp;
}
final boolean z = JoH.msTill(CareLinkCredentialStore.getInstance().getAccessExpiresOn()) < getRenewBeforeMillis();
final boolean z2 = lastBg == null || JoH.msSince(lastBg.timestamp) > getGraceMillis() + 300000;
if (!z && !z2) {
UserError.Log.d("CareLinkFollow", "Already have recent reading: " + JoH.msSince(lastBg.timestamp));
scheduleWakeUp();
return 1;
}
if (JoH.ratelimit("last-carelink-follow-poll", 10)) {
Inevitable.task("CareLink-Follow-Work", 200L, new Runnable() {
@Override
public final void run() {
CareLinkFollowService.lambda$onStartCommand$0(z, z2);
}
});
lastPoll = JoH.tsl();
}
scheduleWakeUp();
return 1;
} finally {
JoH.releaseWakeLock(wakeLock);
}
}
public static void lambda$onStartCommand$0(boolean z, boolean z2) {
try {
getDownloader().doEverything(z, z2);
} catch (NullPointerException unused) {
UserError.Log.e("CareLinkFollow", "Caught concurrency exception when trying to run doeverything");
}
}
public static java.util.List<com.eveningoutpost.dexdrip.utilitymodels.StatusItem> megaStatus() {
throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.cgm.carelinkfollow.CareLinkFollowService.megaStatus():java.util.List");
}
static class AnonymousClass1 {
static final int[] $SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$auth$CareLinkAuthType;
static {
int[] iArr = new int[CareLinkAuthType.values().length];
$SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$auth$CareLinkAuthType = iArr;
try {
iArr[CareLinkAuthType.Browser.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$auth$CareLinkAuthType[CareLinkAuthType.MobileApp.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
resetInstance();
}
private void buggySamsungCheck() {
if (buggySamsung == null) {
buggySamsung = new BuggySamsung("CareLinkFollow");
}
buggySamsung.evaluate(wakeup_time);
wakeup_time = 0L;
}
private static void msg(String str) {
lastState = str;
}
private static String getBestStatusMessage() {
if (JoH.emptyString(lastState)) {
CareLinkFollowDownloader careLinkFollowDownloader = downloader;
if (careLinkFollowDownloader != null) {
return careLinkFollowDownloader.getStatus();
}
return null;
}
return lastState;
}
public static SpannableString nanoStatus() {
String bestStatusMessage = getBestStatusMessage();
if (JoH.emptyString(bestStatusMessage)) {
return null;
}
return new SpannableString(bestStatusMessage);
}
}