导航菜单

页面标题

页面副标题

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

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

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


package com.eveningoutpost.dexdrip.cgm.carelinkfollow.client;

import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthType;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthentication;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkCredentialStore;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.EditableCookieJar;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ActiveNotification;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Alarm;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ClearedNotification;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.CountrySettings;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.DataUpload;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.DisplayMessage;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.M2MEnabled;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Marker;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.MonitorData;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.NotificationHistory;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Patient;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Profile;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentData;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentUploads;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.SensorGlucose;
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.User;
import com.eveningoutpost.dexdrip.models.JoH;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import okhttp3.ConnectionPool;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class CareLinkClient {
    protected static final SimpleDateFormat[] ZONED_DATE_FORMATS = {new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX")};
    protected String carelinkCountry;
    protected String carelinkPassword;
    protected String carelinkUsername;
    protected CareLinkCredentialStore credentialStore;
    private boolean lastDataSuccess;
    private String lastErrorMessage;
    private boolean lastLoginSuccess;
    protected int lastResponseCode;
    protected CountrySettings sessionCountrySettings;
    protected Boolean sessionDeviceIsBle;
    protected Boolean sessionM2MEnabled;
    protected MonitorData sessionMonitorData;
    protected Patient[] sessionPatients;
    protected Profile sessionProfile;
    protected RecentUploads sessionRecentUploads;
    protected User sessionUser;
    protected OkHttpClient httpClient = null;
    protected boolean loginInProcess = false;
    protected boolean collectingSessionInfos = false;
    protected boolean sessionInfosLoaded = false;

    protected enum RequestType {
        HtmlGet,
        HtmlPost,
        Json
    }

    public int getLastResponseCode() {
        return this.lastResponseCode;
    }

    public String getLastErrorMessage() {
        return this.lastErrorMessage;
    }

    public CareLinkClient(CareLinkCredentialStore careLinkCredentialStore) {
        this.carelinkCountry = careLinkCredentialStore.getCredential().country;
        this.credentialStore = careLinkCredentialStore;
        createHttpClient();
    }

    private void createHttpClient() {
        EditableCookieJar editableCookieJar = new EditableCookieJar();
        if (this.credentialStore.getCredential().cookies != null && this.credentialStore.getCredential().cookies.length > 0) {
            editableCookieJar.AddCookies(this.credentialStore.getCredential().cookies);
        }
        this.httpClient = new OkHttpClient.Builder().cookieJar(editableCookieJar).connectionPool(new ConnectionPool(5, 10L, TimeUnit.MINUTES)).build();
    }

    protected String careLinkServer() {
        return this.carelinkCountry.equals("us") ? "carelink.minimed.com" : "carelink.minimed.eu";
    }

    protected String cloudServer() {
        return this.carelinkCountry.equals("us") ? "clcloud.minimed.com" : "clcloud.minimed.eu";
    }

    public RecentData getRecentData() {
        return getRecentData(getDefaultPatientUsername());
    }

    public RecentData getRecentData(String str) {
        if (getAuthentication() == null) {
            return null;
        }
        if (isBleDevice(str)) {
            return getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(), str, this.sessionCountrySettings.blePereodicDataEndpoint);
        }
        if (this.sessionM2MEnabled.booleanValue()) {
            return getM2MPatientData(str);
        }
        return getLast24Hours();
    }

    public String getDefaultPatientUsername() {
        if (getAuthentication() == null) {
            return null;
        }
        if (this.sessionUser.isCarePartner() && this.sessionM2MEnabled.booleanValue()) {
            Patient[] patientArr = this.sessionPatients;
            if (patientArr == null || patientArr.length <= 0) {
                return null;
            }
            return patientArr[0].username;
        }
        String str = this.sessionProfile.username;
        if (str != null) {
            return str;
        }
        return null;
    }

    public boolean isBleDevice(String str) {
        Boolean isRecentUploadBle;
        Boolean bool = this.sessionDeviceIsBle;
        if (bool != null) {
            return bool.booleanValue();
        }
        if (getAuthentication() == null) {
            return false;
        }
        if (!this.sessionUser.isCarePartner() && (isRecentUploadBle = isRecentUploadBle()) != null) {
            this.sessionDeviceIsBle = isRecentUploadBle;
            return isRecentUploadBle.booleanValue();
        }
        if (this.sessionM2MEnabled.booleanValue() && this.sessionUser.isCarePartner()) {
            if (str != null && this.sessionPatients != null) {
                int i = 0;
                while (true) {
                    Patient[] patientArr = this.sessionPatients;
                    if (i >= patientArr.length) {
                        break;
                    }
                    if (patientArr[i].username.equals(str)) {
                        return this.sessionPatients[i].isBle();
                    }
                    i++;
                }
            }
            return false;
        }
        return this.sessionMonitorData.isBle();
    }

    public Boolean isRecentUploadBle() {
        RecentUploads recentUploads = this.sessionRecentUploads;
        if (recentUploads == null) {
            return null;
        }
        for (DataUpload dataUpload : recentUploads.recentUploads) {
            if (dataUpload.device.toUpperCase().contains("MINIMED")) {
                return Boolean.TRUE;
            }
            if (dataUpload.device.toUpperCase().contains(RecentData.DEVICE_FAMILY_GUARDIAN)) {
                return Boolean.FALSE;
            }
        }
        return null;
    }

    protected boolean executeLoginProcedure() {
        this.lastLoginSuccess = false;
        this.loginInProcess = true;
        this.lastErrorMessage = "";
        try {
            try {
                clearSessionInfos();
                Response loginSession = getLoginSession();
                this.lastResponseCode = loginSession.code();
                Response doLogin = doLogin(loginSession);
                this.lastResponseCode = doLogin.code();
                loginSession.close();
                Response doConsent = doConsent(doLogin);
                doLogin.close();
                this.lastResponseCode = doConsent.code();
                doConsent.close();
                if (getSessionInfos()) {
                    this.lastLoginSuccess = true;
                }
            } catch (Exception e) {
                this.lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage();
            }
            this.loginInProcess = false;
            return this.lastLoginSuccess;
        } catch (Throwable th) {
            this.loginInProcess = false;
            throw th;
        }
    }

    protected boolean getSessionInfos() {
        Boolean bool;
        this.collectingSessionInfos = true;
        try {
            clearSessionInfos();
            this.sessionUser = getMyUser();
            this.sessionProfile = getMyProfile();
            this.sessionCountrySettings = getMyCountrySettings();
            if (!this.sessionUser.isCarePartner()) {
                this.sessionRecentUploads = getRecentUploads(30);
            }
            Boolean valueOf = Boolean.valueOf(getM2MEnabled().value);
            this.sessionM2MEnabled = valueOf;
            if (valueOf.booleanValue() && this.sessionUser.isCarePartner()) {
                this.sessionPatients = getM2MPatients();
            } else {
                this.sessionMonitorData = getMonitorData();
            }
            if (this.sessionUser != null && this.sessionProfile != null && this.sessionCountrySettings != null && (bool = this.sessionM2MEnabled) != null && (((!bool.booleanValue() || !this.sessionUser.isCarePartner()) && this.sessionMonitorData != null) || (this.sessionM2MEnabled.booleanValue() && this.sessionUser.isCarePartner() && this.sessionPatients != null))) {
                this.sessionInfosLoaded = true;
            } else {
                clearSessionInfos();
            }
        } catch (Exception unused) {
        } catch (Throwable th) {
            this.collectingSessionInfos = false;
            throw th;
        }
        this.collectingSessionInfos = false;
        return this.sessionInfosLoaded;
    }

    protected void clearSessionInfos() {
        this.sessionUser = null;
        this.sessionProfile = null;
        this.sessionCountrySettings = null;
        this.sessionMonitorData = null;
        this.sessionPatients = null;
        this.sessionInfosLoaded = false;
    }

    protected Response getLoginSession() throws IOException {
        Request.Builder url = new Request.Builder().url(new HttpUrl.Builder().scheme("https").host(careLinkServer()).addPathSegments("patient/sso/login").addQueryParameter("country", this.carelinkCountry).addQueryParameter("lang", "en").build());
        addHttpHeaders(url, RequestType.HtmlGet, true);
        return this.httpClient.newCall(url.build()).execute();
    }

    protected Response doLogin(Response response) throws IOException {
        Request.Builder post = new Request.Builder().url(new HttpUrl.Builder().scheme(response.request().url().scheme()).host(response.request().url().host()).addPathSegments(response.request().url().encodedPath().substring(1)).addQueryParameter("locale", response.request().url().queryParameter("locale")).addQueryParameter("country", response.request().url().queryParameter("countrycode")).build()).post(new FormBody.Builder().add("sessionID", response.request().url().queryParameter("sessionID")).add("sessionData", response.request().url().queryParameter("sessionData")).add("locale", response.request().url().queryParameter("locale")).add("action", "login").add("username", this.carelinkUsername).add("password", this.carelinkPassword).add("actionButton", "Log in").build());
        addHttpHeaders(post, RequestType.HtmlGet, true);
        return this.httpClient.newCall(post.build()).execute();
    }

    protected Response doConsent(Response response) throws IOException {
        String string = response.body().string();
        String extractResponseData = extractResponseData(string, "(form action=\")(.*)(\" method=\"POST\")", 2);
        Request.Builder post = new Request.Builder().url(extractResponseData).post(new FormBody.Builder().add("action", "consent").add("sessionID", extractResponseData(string, "(<input type=\"hidden\" name=\"sessionID\" value=\")(.*)(\">)", 2)).add("sessionData", extractResponseData(string, "(<input type=\"hidden\" name=\"sessionData\" value=\")(.*)(\">)", 2)).add("response_type", "code").add("response_mode", "query").build());
        addHttpHeaders(post, RequestType.HtmlPost, true);
        return this.httpClient.newCall(post.build()).execute();
    }

    protected String extractResponseData(String str, String str2, int i) {
        Matcher matcher = Pattern.compile(str2).matcher(str);
        if (matcher.find()) {
            return matcher.group(i);
        }
        return null;
    }

    protected CareLinkAuthentication getAuthentication() {
        CareLinkCredentialStore careLinkCredentialStore = this.credentialStore;
        if (careLinkCredentialStore != null) {
            if (!this.sessionInfosLoaded && careLinkCredentialStore.getAuthStatus() == 2 && !this.collectingSessionInfos) {
                getSessionInfos();
            }
            if (this.collectingSessionInfos || this.sessionInfosLoaded) {
                return this.credentialStore.getCredential().getAuthentication();
            }
            return null;
        }
        if (!(((SimpleOkHttpCookieJar) this.httpClient.cookieJar()).contains("auth_tmp_token") && ((SimpleOkHttpCookieJar) this.httpClient.cookieJar()).contains("c_token_valid_to") && new Date(Date.parse(((SimpleOkHttpCookieJar) this.httpClient.cookieJar()).getCookies("c_token_valid_to").get(0).value())).after(new Date(new Date(System.currentTimeMillis()).getTime() + 60000)) && this.lastResponseCode != 401 && (this.loginInProcess || this.lastLoginSuccess)) && (this.loginInProcess || !executeLoginProcedure())) {
            return null;
        }
        return new CareLinkAuthentication(new Headers.Builder().add("Authorization", "Bearer " + ((SimpleOkHttpCookieJar) this.httpClient.cookieJar()).getCookies("auth_tmp_token").get(0).value()).build(), CareLinkAuthType.Browser);
    }

    public User getMyUser() {
        return (User) getData(careLinkServer(), "patient/users/me", null, null, User.class);
    }

    public Profile getMyProfile() {
        return (Profile) getData(careLinkServer(), "patient/users/me/profile", null, null, Profile.class);
    }

    public RecentUploads getRecentUploads(int i) {
        HashMap hashMap = new HashMap();
        hashMap.put("numUploads", String.valueOf(i));
        return (RecentUploads) getData(careLinkServer(), "patient/dataUpload/recentUploads", hashMap, null, RecentUploads.class);
    }

    public MonitorData getMonitorData() {
        return (MonitorData) getData(careLinkServer(), "patient/monitor/data", null, null, MonitorData.class);
    }

    public CountrySettings getMyCountrySettings() {
        HashMap hashMap = new HashMap();
        hashMap.put("countryCode", this.carelinkCountry);
        hashMap.put("language", "en");
        return (CountrySettings) getData(careLinkServer(), "patient/countries/settings", hashMap, null, CountrySettings.class);
    }

    public M2MEnabled getM2MEnabled() {
        return (M2MEnabled) getData(careLinkServer(), "patient/configuration/system/personal.cp.m2m.enabled", null, null, M2MEnabled.class);
    }

    public Patient[] getM2MPatients() {
        return (Patient[]) getData(careLinkServer(), "patient/m2m/links/patients", null, null, Patient[].class);
    }

    public RecentData getLast24Hours() {
        RecentData recentData;
        Exception e;
        HashMap hashMap = new HashMap();
        hashMap.put("cpSerialNumber", "NONE");
        hashMap.put("msgType", "last24hours");
        hashMap.put("requestTime", String.valueOf(System.currentTimeMillis()));
        try {
            recentData = (RecentData) getData(cloudServer(), "patient/connect/data", null, null, RecentData.class);
            if (recentData != null) {
                try {
                    correctTimeInRecentData(recentData);
                } catch (Exception e2) {
                    e = e2;
                    this.lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage();
                    return recentData;
                }
            }
        } catch (Exception e3) {
            recentData = null;
            e = e3;
        }
        return recentData;
    }

    public RecentData getConnectDisplayMessage(String str, String str2, String str3, String str4) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("username", str);
        jsonObject.addProperty("role", str2);
        if (!JoH.emptyString(str3)) {
            jsonObject.addProperty("patientId", str3);
        }
        try {
            DisplayMessage displayMessage = (DisplayMessage) getData(new HttpUrl.Builder().scheme("https").host(cloudServer()).addPathSegments("connect/carepartner/v11/display/message").build(), RequestBody.create(MediaType.get("application/json; charset=utf-8"), new GsonBuilder().create().toJson((JsonElement) jsonObject)), DisplayMessage.class);
            if (displayMessage == null || displayMessage.patientData == null) {
                return null;
            }
            correctTimeInDisplayMessage(displayMessage);
            return displayMessage.patientData;
        } catch (Exception e) {
            this.lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage();
            return null;
        }
    }

    public RecentData getM2MPatientData(String str) {
        if (str == null || str.isEmpty()) {
            return null;
        }
        HashMap hashMap = new HashMap();
        hashMap.put("cpSerialNumber", "NONE");
        hashMap.put("msgType", "last24hours");
        hashMap.put("requestTime", String.valueOf(System.currentTimeMillis()));
        RecentData recentData = (RecentData) getData(cloudServer(), "patient/m2m/connect/data/gc/patients/" + str, null, null, RecentData.class);
        if (recentData != null) {
            correctTimeInRecentData(recentData);
        }
        return recentData;
    }

    protected <T> T getData(okhttp3.HttpUrl r7, okhttp3.RequestBody r8, java.lang.Class<T> r9) {
        throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.cgm.carelinkfollow.client.CareLinkClient.getData(okhttp3.HttpUrl, okhttp3.RequestBody, java.lang.Class):java.lang.Object");
    }

    protected <T> T getData(String str, String str2, Map<String, String> map, RequestBody requestBody, Class<T> cls) {
        HttpUrl.Builder addPathSegments = new HttpUrl.Builder().scheme("https").host(str).addPathSegments(str2);
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                addPathSegments.addQueryParameter(entry.getKey(), entry.getValue());
            }
        }
        return (T) getData(addPathSegments.build(), requestBody, cls);
    }

    protected void addHttpHeaders(Request.Builder builder, RequestType requestType, boolean z) {
        if (z) {
            builder.addHeader("Accept-Language", "en;q=0.9, *;q=0.8").addHeader("Connection", "keep-alive").addHeader("Sec-Ch-Ua", "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"").addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36");
        }
        int i = AnonymousClass1.$SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$client$CareLinkClient$RequestType[requestType.ordinal()];
        if (i == 1) {
            builder.addHeader("Accept", "application/json, text/plain, */*");
            builder.addHeader("Content-Type", "application/json; charset=utf-8");
            return;
        }
        if (i == 2) {
            builder.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        } else if (i != 3) {
            return;
        }
        builder.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        builder.addHeader("Content-Type", "application/x-www-form-urlencoded");
    }

    static class AnonymousClass1 {
        static final int[] $SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$client$CareLinkClient$RequestType;

        static {
            int[] iArr = new int[RequestType.values().length];
            $SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$client$CareLinkClient$RequestType = iArr;
            try {
                iArr[RequestType.Json.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$client$CareLinkClient$RequestType[RequestType.HtmlGet.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$com$eveningoutpost$dexdrip$cgm$carelinkfollow$client$CareLinkClient$RequestType[RequestType.HtmlPost.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    protected void correctTimeInDisplayMessage(DisplayMessage displayMessage) {
        int round;
        RecentData recentData = displayMessage.patientData;
        Date date = recentData.lastConduitDateTime;
        if (date != null && date.getTime() > 1 && recentData.lastConduitUpdateServerDateTime.longValue() > 1 && (round = (int) Math.round((recentData.lastConduitUpdateServerDateTime.longValue() - recentData.lastConduitDateTime.getTime()) / 3600000.0d)) != 0 && round < 26) {
            recentData.lastConduitDateTime = shiftDateByHours(recentData.lastConduitDateTime, round);
            List<SensorGlucose> list = recentData.sgs;
            if (list != null) {
                for (SensorGlucose sensorGlucose : list) {
                    Date date2 = sensorGlucose.timestamp;
                    if (date2 != null) {
                        sensorGlucose.timestamp = shiftDateByHours(date2, round);
                    }
                }
            }
            List<Marker> list2 = recentData.markers;
            if (list2 != null) {
                for (Marker marker : list2) {
                    Date date3 = marker.timestamp;
                    if (date3 != null) {
                        marker.timestamp = shiftDateByHours(date3, round);
                    }
                }
            }
            NotificationHistory notificationHistory = recentData.notificationHistory;
            if (notificationHistory != null) {
                List<ClearedNotification> list3 = notificationHistory.clearedNotifications;
                if (list3 != null) {
                    for (ClearedNotification clearedNotification : list3) {
                        Date date4 = clearedNotification.dateTime;
                        if (date4 != null) {
                            clearedNotification.dateTime = shiftDateByHours(date4, round);
                            clearedNotification.triggeredDateTime = shiftDateByHours(clearedNotification.triggeredDateTime, round);
                        }
                    }
                }
                List<ActiveNotification> list4 = recentData.notificationHistory.activeNotifications;
                if (list4 != null) {
                    for (ActiveNotification activeNotification : list4) {
                        Date date5 = activeNotification.dateTime;
                        if (date5 != null) {
                            activeNotification.dateTime = shiftDateByHours(date5, round);
                        }
                    }
                }
            }
        }
        displayMessage.patientData = recentData;
    }

    protected void correctTimeInRecentData(RecentData recentData) {
        List<Marker> list;
        boolean z;
        int round;
        String zoneOffset;
        String str;
        String str2;
        String str3 = recentData.sMedicalDeviceTime;
        if (str3 != null && !str3.isEmpty() && recentData.lastMedicalDeviceDataUpdateServerTime > 1) {
            if (parseDateString(recentData.sMedicalDeviceTime) == null) {
                SensorGlucose sensorGlucose = recentData.lastSG;
                if (sensorGlucose != null && (str2 = sensorGlucose.datetime) != null) {
                    zoneOffset = getZoneOffset(str2);
                } else {
                    zoneOffset = getZoneOffset(recentData.lastAlarm.datetime);
                }
                Alarm alarm = recentData.lastAlarm;
                if (alarm != null && (str = alarm.datetime) != null) {
                    alarm.datetimeAsDate = parseDateString(str);
                }
                recentData.sMedicalDeviceTime += zoneOffset;
                recentData.medicalDeviceTimeAsString += zoneOffset;
                recentData.sLastSensorTime += zoneOffset;
                recentData.lastSensorTSAsString += zoneOffset;
                z = true;
            } else {
                z = false;
            }
            recentData.dMedicalDeviceTime = parseDateString(recentData.sMedicalDeviceTime);
            recentData.medicalDeviceTimeAsDate = parseDateString(recentData.medicalDeviceTimeAsString);
            recentData.dLastSensorTime = parseDateString(recentData.sLastSensorTime);
            recentData.lastSensorTSAsDate = parseDateString(recentData.lastSensorTSAsString);
            List<SensorGlucose> list2 = recentData.sgs;
            if (list2 != null) {
                for (SensorGlucose sensorGlucose2 : list2) {
                    sensorGlucose2.datetimeAsDate = parseDateString(sensorGlucose2.datetime);
                }
            }
            if (!z && (round = (int) Math.round((recentData.lastMedicalDeviceDataUpdateServerTime - recentData.dMedicalDeviceTime.getTime()) / 3600000.0d)) != 0 && round < 26) {
                recentData.medicalDeviceTimeAsDate = shiftDateByHours(recentData.medicalDeviceTimeAsDate, round);
                recentData.dMedicalDeviceTime = shiftDateByHours(recentData.dMedicalDeviceTime, round);
                recentData.lastConduitDateTime = shiftDateByHours(recentData.lastConduitDateTime, round);
                recentData.lastSensorTSAsDate = shiftDateByHours(recentData.lastSensorTSAsDate, round);
                recentData.dLastSensorTime = shiftDateByHours(recentData.dLastSensorTime, round);
                List<SensorGlucose> list3 = recentData.sgs;
                if (list3 != null) {
                    for (SensorGlucose sensorGlucose3 : list3) {
                        sensorGlucose3.datetimeAsDate = shiftDateByHours(sensorGlucose3.datetimeAsDate, round);
                    }
                }
                List<Marker> list4 = recentData.markers;
                if (list4 != null) {
                    for (Marker marker : list4) {
                        marker.dateTime = shiftDateByHours(marker.dateTime, round);
                    }
                }
                NotificationHistory notificationHistory = recentData.notificationHistory;
                if (notificationHistory != null) {
                    List<ClearedNotification> list5 = notificationHistory.clearedNotifications;
                    if (list5 != null) {
                        for (ClearedNotification clearedNotification : list5) {
                            clearedNotification.dateTime = shiftDateByHours(clearedNotification.dateTime, round);
                            clearedNotification.triggeredDateTime = shiftDateByHours(clearedNotification.triggeredDateTime, round);
                        }
                    }
                    List<ActiveNotification> list6 = recentData.notificationHistory.activeNotifications;
                    if (list6 != null) {
                        for (ActiveNotification activeNotification : list6) {
                            activeNotification.dateTime = shiftDateByHours(activeNotification.dateTime, round);
                        }
                    }
                }
            }
        }
        if (recentData.dLastSensorTime == null || (list = recentData.markers) == null) {
            return;
        }
        for (Marker marker2 : list) {
            if (marker2 != null && marker2.dateTime == null) {
                try {
                    marker2.dateTime = calcTimeByIndex(recentData.dLastSensorTime, marker2.index, true);
                } catch (Exception unused) {
                }
            }
        }
    }

    protected String getZoneOffset(String str) {
        Matcher matcher = Pattern.compile("(.*)([\\+|-].*)").matcher(str);
        if (matcher.find()) {
            return matcher.group(2);
        }
        return null;
    }

    protected Date parseDateString(String str) {
        for (SimpleDateFormat simpleDateFormat : ZONED_DATE_FORMATS) {
            try {
                return simpleDateFormat.parse(str);
            } catch (Exception unused) {
            }
        }
        return null;
    }

    protected Date shiftDateByHours(Date date, int i) {
        if (date == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(11, i);
        return calendar.getTime();
    }

    protected static Date calcTimeByIndex(Date date, int i, boolean z) {
        if (date == null) {
            return null;
        }
        if (z) {
            return new Date(Math.round(calcTimeByIndex(date, i, false).getTime() / 600000.0d) * 600000);
        }
        return new Date(date.getTime() - ((287 - i) * 300000));
    }
}