导航菜单

页面标题

页面副标题

xDrip+ v04633772025.07.16 - ExternalStatusService.java 源代码

正在查看: xDrip+ v04633772025.07.16 应用的 ExternalStatusService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.eveningoutpost.dexdrip.wearintegration;

import android.app.IntentService;
import android.content.Intent;
import androidx.legacy.content.WakefulBroadcastReceiver;
import com.eveningoutpost.dexdrip.NewDataObserver;
import com.eveningoutpost.dexdrip.models.APStatus;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExternalStatusService extends IntentService {
    private static final String TAG = "ExternalStatusService";

    public ExternalStatusService() {
        super(TAG);
        setIntentRedelivery(true);
    }

    private static boolean isCurrent(long j) {
        return JoH.msSince(j) < 18000000;
    }

    private static boolean isCurrent() {
        return isCurrent(getLastStatusLineTime());
    }

    public static String getLastStatusLine() {
        return isCurrent() ? PersistentStore.getString("external-status-store") : "";
    }

    public static long getLastStatusLineTime() {
        return PersistentStore.getLong("external-status-store-time");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if (intent == null) {
            return;
        }
        try {
            String action = intent.getAction();
            if (action == null) {
                return;
            }
            if ("com.eveningoutpost.dexdrip.ExternalStatusline".equals(action)) {
                update(JoH.tsl(), intent.getStringExtra("com.eveningoutpost.dexdrip.Extras.Statusline"), true);
            }
        } finally {
            WakefulBroadcastReceiver.completeWakefulIntent(intent);
        }
    }

    public static void update(long j, String str, boolean z) {
        if (str != null) {
            if (str.length() > 70) {
                str = str.substring(0, 70);
            }
            if (isCurrent(j)) {
                PersistentStore.setString("external-status-store", str);
                PersistentStore.setLong("external-status-store-time", j);
            }
            if (str.length() > 0) {
                Double absoluteBRDouble = getAbsoluteBRDouble();
                if (absoluteBRDouble != null) {
                    APStatus.createEfficientRecord(j, absoluteBRDouble.doubleValue());
                } else {
                    Integer tBRInt = getTBRInt();
                    if (tBRInt != null) {
                        APStatus.createEfficientRecord(j, tBRInt.intValue());
                    } else {
                        UserError.Log.wtf(TAG, "Could not parse TBR from: " + str);
                    }
                }
            }
            NewDataObserver.newExternalStatus(z);
        }
    }

    public static String getTBR(String str) {
        if (JoH.emptyString(str)) {
            return "";
        }
        Matcher matcher = Pattern.compile(".*([^0-9]|^)([0-9]+%)", 32).matcher(str);
        return matcher.find() ? matcher.group(matcher.groupCount()) : "100%";
    }

    public static String getAbsoluteBR(String str) {
        if (JoH.emptyString(str)) {
            return "";
        }
        Matcher matcher = Pattern.compile(".*(^|[^0-9.,])([0-9.,]+U/h)", 32).matcher(str);
        if (matcher.find()) {
            return matcher.group(matcher.groupCount());
        }
        return null;
    }

    public static String getTBR() {
        return getTBR(getLastStatusLine());
    }

    public static String getAbsoluteBR() {
        return getAbsoluteBR(getLastStatusLine());
    }

    public static Integer getTBRInt() {
        try {
            return Integer.valueOf(Integer.parseInt(getTBR().replace("%", "")));
        } catch (NumberFormatException unused) {
            return null;
        }
    }

    public static Double getAbsoluteBRDouble() {
        try {
            return Double.valueOf(JoH.tolerantParseDouble(getAbsoluteBR().replace("U/h", "")));
        } catch (NullPointerException | NumberFormatException unused) {
            return null;
        }
    }
}