正在查看: xDrip+ v04633772025.07.16 应用的 WifiCollectionService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 WifiCollectionService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.services;
import android.annotation.TargetApi;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.IBinder;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.text.SpannableString;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbId;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter;
import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.StatusItem;
import com.eveningoutpost.dexdrip.utils.DexCollectionType;
import com.eveningoutpost.dexdrip.utils.Mdns;
import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline;
import com.eveningoutpost.dexdrip.xdrip;
import java.util.ArrayList;
import java.util.List;
@TargetApi(19)
public class WifiCollectionService extends Service {
private static final String TAG = "WifiCollectionService";
private static String lastState = "Not Running";
private static long max_wakeup_jitter;
private static long requested_wake_time;
public WifiCollectionService 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)) {
WifiCollectionService wifiCollectionService = WifiCollectionService.this;
wifiCollectionService.foregroundServiceStarter = new ForegroundServiceStarter(wifiCollectionService.getApplicationContext(), WifiCollectionService.this.dexCollectionService);
WifiCollectionService.this.foregroundServiceStarter.start();
UserError.Log.d(WifiCollectionService.TAG, "Moving to foreground");
return;
}
WifiCollectionService.this.dexCollectionService.stopForeground(true);
UserError.Log.d(WifiCollectionService.TAG, "Removing from foreground");
}
}
};
private SharedPreferences prefs;
public static SpannableString nanoStatus() {
return null;
}
public static boolean isRunning() {
return (lastState.equals("Not Running") || lastState.startsWith("Stopping", 0)) ? false : true;
}
public static List<StatusItem> megaStatus(Context context) {
ArrayList arrayList = new ArrayList();
arrayList.add(new StatusItem("IP Collector Service", lastState));
arrayList.add(new StatusItem("Next poll", JoH.niceTimeTill(PersistentStore.getLong("WifiCollectionWakeupTime"))));
long j = max_wakeup_jitter;
if (j > 2000) {
arrayList.add(new StatusItem("Wakeup jitter", JoH.niceTimeScalar(j), max_wakeup_jitter > 10000 ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL));
}
if (JoH.buggy_samsung) {
arrayList.add(new StatusItem("Buggy handset", "Using workaround", max_wakeup_jitter < 10000 ? StatusItem.Highlight.GOOD : StatusItem.Highlight.BAD));
}
if (DexCollectionType.hasLibre()) {
arrayList.addAll(LibreWifiReader.megaStatus());
} else {
arrayList.addAll(WixelReader.megaStatus());
}
int i = Pref.getInt("parakeet_battery", 0);
if (i > 0) {
arrayList.add(new StatusItem("Parakeet Battery", i + "%", i < 50 ? i < 40 ? StatusItem.Highlight.BAD : StatusItem.Highlight.NOTICE : StatusItem.Highlight.GOOD));
}
arrayList.addAll(Mdns.megaStatus(context));
return arrayList;
}
@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");
lastState = "Starting up " + JoH.hourMinuteString();
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
PowerManager.WakeLock wakeLock = JoH.getWakeLock("xdrip-wificolsvc-onStart", UsbId.SILABS_CP2102);
if (requested_wake_time > 0) {
JoH.persistentBuggySamsungCheck();
long msSince = JoH.msSince(requested_wake_time);
if (msSince > 2000) {
UserError.Log.d(TAG, "Wake up jitter: " + JoH.niceTimeScalar(msSince));
}
if (msSince > 10000 && !JoH.buggy_samsung && JoH.isSamsung()) {
UserError.Log.wtf(TAG, "Enabled wake workaround due to jitter of: " + JoH.niceTimeScalar(msSince));
JoH.setBuggySamsungEnabled();
max_wakeup_jitter = 0L;
} else {
max_wakeup_jitter = Math.max(max_wakeup_jitter, msSince);
}
}
if (DexCollectionType.hasWifi()) {
runWixelReader();
setFailoverTimer();
lastState = "Started " + JoH.hourMinuteString();
if (!wakeLock.isHeld()) {
return 1;
}
wakeLock.release();
return 1;
}
lastState = "Stopping " + JoH.hourMinuteString();
stopSelf();
if (!wakeLock.isHeld()) {
return 2;
}
wakeLock.release();
return 2;
}
@Override
public void onDestroy() {
super.onDestroy();
String str = TAG;
UserError.Log.d(str, "onDestroy entered");
this.foregroundServiceStarter.stop();
UserError.Log.i(str, "SERVICE STOPPED");
try {
this.prefs.unregisterOnSharedPreferenceChangeListener(this.prefListener);
} catch (Exception unused) {
UserError.Log.e(TAG, "Exception unregistering prefListener");
}
}
public void setFailoverTimer() {
long longValue;
if (DexCollectionType.hasWifi()) {
if (DexCollectionType.hasLibre()) {
longValue = LibreWifiReader.timeForNextRead().longValue();
} else {
longValue = WixelReader.timeForNextRead().longValue();
}
UserError.Log.d(TAG, "setFailoverTimer: Fallover Restarting in: " + (longValue / 60000) + " minutes");
long wakeUpIntent = JoH.wakeUpIntent(this, longValue, WakeLockTrampoline.getPendingIntent(getClass(), 1001));
requested_wake_time = wakeUpIntent;
PersistentStore.setLong("WifiCollectionWakeupTime", wakeUpIntent);
return;
}
stopSelf();
}
public void listenForChangeInSettings() {
this.prefs.registerOnSharedPreferenceChangeListener(this.prefListener);
}
private void runWixelReader() {
AsyncTask wixelReader;
if (DexCollectionType.hasLibre()) {
wixelReader = new LibreWifiReader(getApplicationContext());
} else {
wixelReader = new WixelReader(getApplicationContext());
}
wixelReader.executeOnExecutor(xdrip.executor, new String[0]);
}
}