正在查看: xDrip+ v04633772025.07.16 应用的 DoNothingService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 DoNothingService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.services;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import com.eveningoutpost.dexdrip.GcmActivity;
import com.eveningoutpost.dexdrip.GcmListenerSvc;
import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.cloud.jamcm.Pusher;
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.CollectionServiceStarter;
import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter;
import com.eveningoutpost.dexdrip.utilitymodels.InstalledApps;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.StatusItem;
import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline;
import com.eveningoutpost.dexdrip.xdrip;
import java.util.ArrayList;
import java.util.List;
public class DoNothingService extends Service {
private static final String TAG = "DoNothingService";
private static String lastState = "Not running";
private static BgReading last_bg = null;
private static long max_wake_time_difference = 0;
private static long nextWakeUpTime = -1;
private static int wakeUpErrors;
private static long wake_time_difference;
private DoNothingService dexCollectionService;
private ForegroundServiceStarter foregroundServiceStarter;
public SharedPreferences.OnSharedPreferenceChangeListener prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
if (str.compareTo("run_service_in_foreground") == 0) {
UserError.Log.d("FOREGROUND", "run_service_in_foreground changed!");
if (!sharedPreferences.getBoolean("run_service_in_foreground", false)) {
DoNothingService.this.dexCollectionService.stopForeground(true);
UserError.Log.d(DoNothingService.TAG, "Removing from foreground");
} else {
DoNothingService doNothingService = DoNothingService.this;
doNothingService.foregroundServiceStarter = new ForegroundServiceStarter(doNothingService.getApplicationContext(), DoNothingService.this.dexCollectionService);
DoNothingService.this.foregroundServiceStarter.start();
UserError.Log.d(DoNothingService.TAG, "Moving to foreground");
}
}
}
};
private SharedPreferences prefs;
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
ForegroundServiceStarter foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this);
this.foregroundServiceStarter = foregroundServiceStarter;
foregroundServiceStarter.start();
this.dexCollectionService = this;
this.prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
listenForChangeInSettings();
UserError.Log.i(TAG, "onCreate: STARTING SERVICE");
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
final PowerManager.WakeLock wakeLock = JoH.getWakeLock("donothing-follower", UsbId.SILABS_CP2102);
lastState = "Trying to start " + JoH.hourMinuteString();
if (nextWakeUpTime > 0) {
long tsl = JoH.tsl() - nextWakeUpTime;
wake_time_difference = tsl;
if (tsl > 300000) {
UserError.Log.e(TAG, "Slow Wake up! time difference in ms: " + wake_time_difference);
wakeUpErrors = wakeUpErrors + 3;
max_wake_time_difference = Math.max(max_wake_time_difference, wake_time_difference);
} else {
int i3 = wakeUpErrors;
if (i3 > 0) {
wakeUpErrors = i3 - 1;
}
}
}
if (CollectionServiceStarter.isFollower(getApplicationContext()) || CollectionServiceStarter.isLibre2App(getApplicationContext())) {
new Thread(new Runnable() {
@Override
public final void run() {
DoNothingService.this.lambda$onStartCommand$0(wakeLock);
}
}).start();
if (Pusher.enabled()) {
Pusher.immortality();
}
lastState = "Started " + JoH.hourMinuteString();
return 1;
}
stopSelf();
JoH.releaseWakeLock(wakeLock);
return 2;
}
public void lambda$onStartCommand$0(PowerManager.WakeLock wakeLock) {
int lastMessageMinutesAgo = GcmListenerSvc.lastMessageMinutesAgo();
if (lastMessageMinutesAgo > 60 && lastMessageMinutesAgo < 80 && JoH.ratelimit("slow-service-restart", 60)) {
UserError.Log.e(TAG, "Restarting collection service + full wakeup due to minsago: " + lastMessageMinutesAgo + " !!!");
Home.startHomeWithExtra(getApplicationContext(), "HOME_FULL_WAKEUP", "1");
CollectionServiceStarter.restartCollectionService(getApplicationContext());
}
int i = 1000;
if (lastMessageMinutesAgo > 6) {
if (Home.get_follower()) {
GcmActivity.requestPing();
}
if (lastMessageMinutesAgo < 60) {
i = (lastMessageMinutesAgo / 6) * 1000;
}
}
try {
Thread.sleep(i);
} catch (InterruptedException unused) {
}
setFailOverTimer();
JoH.releaseWakeLock(wakeLock);
}
@Override
public void onDestroy() {
super.onDestroy();
String str = TAG;
UserError.Log.d(str, "onDestroy entered");
this.foregroundServiceStarter.stop();
UserError.Log.i(str, "SERVICE STOPPED");
lastState = "Stopped " + JoH.hourMinuteString();
}
private void setFailOverTimer() {
if (Home.get_follower()) {
UserError.Log.d(TAG, "setFailoverTimer: Restarting in: 10 minutes");
nextWakeUpTime = JoH.tsl() + 600000;
JoH.wakeUpIntent(this, 600000L, WakeLockTrampoline.getPendingIntent(getClass()));
return;
}
stopSelf();
}
public void listenForChangeInSettings() {
this.prefs.registerOnSharedPreferenceChangeListener(this.prefListener);
}
public static List<StatusItem> megaStatus() {
String str;
String str2;
ArrayList arrayList = new ArrayList();
if (GcmActivity.cease_all_activity) {
arrayList.add(new StatusItem("SYNC DISABLED", Pref.getBooleanDefaultFalse("disable_all_sync") ? "By preference option" : InstalledApps.isGooglePlayInstalled(xdrip.getAppContext()) ? "Not by preference option" : "By missing Google Play services", StatusItem.Highlight.CRITICAL));
}
if (Home.get_master()) {
arrayList.add(new StatusItem("Service State", "We are the Master"));
} else {
arrayList.add(new StatusItem("Service State", lastState));
updateLastBg();
if (last_bg != null) {
arrayList.add(new StatusItem("Glucose Data", JoH.niceTimeSince(last_bg.timestamp) + " ago"));
}
if (wakeUpErrors > 0) {
arrayList.add(new StatusItem("Slow Wake up", JoH.niceTimeScalar(wake_time_difference)));
arrayList.add(new StatusItem("Wake Up Errors", Integer.valueOf(wakeUpErrors)));
}
long j = max_wake_time_difference;
if (j > 0) {
arrayList.add(new StatusItem("Slowest Wake up", JoH.niceTimeScalar(j)));
}
if (JoH.buggy_samsung) {
arrayList.add(new StatusItem("Buggy handset", "Using workaround", max_wake_time_difference < 300000 ? StatusItem.Highlight.GOOD : StatusItem.Highlight.BAD));
}
long j2 = nextWakeUpTime;
if (j2 != -1) {
arrayList.add(new StatusItem("Next Wake up", JoH.niceTimeTill(j2)));
}
}
if (Pusher.enabled()) {
try {
boolean connected = Pusher.connected();
long connectedTime = Pusher.connectedTime();
if (Home.get_engineering_mode()) {
str = " (" + JoH.niceTimeScalar(connectedTime) + ")";
} else {
str = "";
}
if (connected) {
str2 = "Connected" + str;
} else {
str2 = "Not connected";
}
arrayList.add(new StatusItem("xDrip Cloud", str2, connected ? StatusItem.Highlight.GOOD : StatusItem.Highlight.NOTICE));
arrayList.add(new StatusItem("Status", Pusher.getInstance().getStatusString()));
if (!connected) {
long nextReconnectionDue = Pusher.getInstance().getNextReconnectionDue();
arrayList.add(new StatusItem("Next reconnection", nextReconnectionDue != -1 ? JoH.niceTimeScalar(Math.max(JoH.msTill(nextReconnectionDue), 0L)) : "Unknown"));
}
if (Home.get_engineering_mode()) {
arrayList.add(new StatusItem("Sent hour / total", Pusher.sentLastHour() + " (" + Pusher.sentTotal() + ")"));
arrayList.add(new StatusItem("Recv hour / total", Pusher.receivedLastHour() + " (" + Pusher.receivedTotal() + ")"));
}
} catch (Exception e) {
arrayList.add(new StatusItem("Error", e.toString(), StatusItem.Highlight.CRITICAL));
}
}
return arrayList;
}
private static void updateLastBg() {
if (last_bg == null || JoH.ratelimit("follower-bg-status", 5)) {
last_bg = BgReading.last();
}
}
public static android.text.SpannableString nanoStatus() {
throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.services.DoNothingService.nanoStatus():android.text.SpannableString");
}
}