Warkop v5.73.0版本的 MD5 值为:a4330ec2d6f5e146f59fc7622f3cdb45

以下内容为反编译后的 m.java 源代码,内容仅作参考


package com.zendrive.sdk.utilities;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.util.Base64;
import androidx.annotation.NonNull;
import com.google.android.gms.wallet.WalletConstants;
import com.zendrive.sdk.PhonePosition;
import com.zendrive.sdk.ZendriveDriveType;
import com.zendrive.sdk.ZendriveEventSeverity;
import com.zendrive.sdk.ZendriveEventType;
import com.zendrive.sdk.ZendriveRegion;
import com.zendrive.sdk.ZendriveTurnDirection;
import com.zendrive.sdk.ZendriveUserMode;
import com.zendrive.sdk.ZendriveVehicleType;
import com.zendrive.sdk.c;
import com.zendrive.sdk.cdetectorlib.CEventData;
import com.zendrive.sdk.cdetectorlib.CEventDataList;
import com.zendrive.sdk.cdetectorlib.CEventList;
import com.zendrive.sdk.cdetectorlib.CLoggerConfig;
import com.zendrive.sdk.cdetectorlib.CStringList;
import com.zendrive.sdk.cdetectorlib.CTripFeatures;
import com.zendrive.sdk.cdetectorlib.CTripInfo;
import com.zendrive.sdk.cdetectorlib.CTripScore;
import com.zendrive.sdk.cdetectorlib.CTripScorer;
import com.zendrive.sdk.cdetectorlib.cdetectorlibJNI;
import com.zendrive.sdk.cdetectorlib.h;
import com.zendrive.sdk.data.DetectorInfo;
import com.zendrive.sdk.data.Event;
import com.zendrive.sdk.data.GPS;
import com.zendrive.sdk.data.HighFreqGps;
import com.zendrive.sdk.data.SpeedLimitDataPoint;
import com.zendrive.sdk.data.Trip;
import com.zendrive.sdk.data.TripInsight;
import com.zendrive.sdk.data.TripSummary;
import com.zendrive.sdk.data.TripTimestampPoint;
import com.zendrive.sdk.data.TripTrail;
import com.zendrive.sdk.data.Vehicle;
import com.zendrive.sdk.data.ZendriveBluetoothDevice;
import com.zendrive.sdk.i.a7;
import com.zendrive.sdk.i.e6;
import com.zendrive.sdk.i.j8;
import com.zendrive.sdk.i.k;
import com.zendrive.sdk.i.k6;
import com.zendrive.sdk.i.l6;
import com.zendrive.sdk.i.n6;
import com.zendrive.sdk.i.q6;
import com.zendrive.sdk.i.s1;
import com.zendrive.sdk.i.t6;
import com.zendrive.sdk.i.u1;
import com.zendrive.sdk.i.w5;
import com.zendrive.sdk.i.x5;
import com.zendrive.sdk.i.y4;
import com.zendrive.sdk.i.y6;
import com.zendrive.sdk.m;
import com.zendrive.sdk.o;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.crypto.Cipher;
import javax.net.ssl.HttpsURLConnection;
import ns.b0;
import org.cryptonode.jncryptor.CryptorException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import sinet.startup.inDriver.core.data.data.NotificationData;
import sinet.startup.inDriver.data.OrdersData;

public class m {

    @SuppressLint({"StaticFieldLeak"})
    private static Context f42918a;

    public static void A(Context context, String str, byte[] bArr) {
        File f05 = f0(context);
        if (!f05.exists()) {
            f05.mkdirs();
        }
        L(new File(f05, str), bArr, false);
    }

    public static void B(Context context, HttpsURLConnection httpsURLConnection, String str, ns.u uVar) {
        String j05;
        if (uVar != null && uVar.b("X-User-Id") != null) {
            j05 = null;
        } else {
            j05 = j0(context);
        }
        HashMap<String, String> s15 = s(context, str, j05);
        for (String str2 : s15.keySet()) {
            httpsURLConnection.setRequestProperty(str2, s15.get(str2));
        }
        if (uVar != null) {
            for (int i15 = 0; i15 < uVar.size(); i15++) {
                httpsURLConnection.setRequestProperty(uVar.g(i15), uVar.u(i15));
            }
        }
    }

    public static void C(Context context, b0.a aVar, String str) {
        b0(context, aVar, str, j0(context));
    }

    public static void E(Looper looper) {
        Looper myLooper;
        String name;
        if (Thread.currentThread() != null && (myLooper = Looper.myLooper()) != looper) {
            Object[] objArr = new Object[2];
            String str = "null";
            if (myLooper == null) {
                name = "null";
            } else {
                name = myLooper.getThread().getName();
            }
            objArr[0] = name;
            if (looper != null) {
                str = looper.getThread().getName();
            }
            objArr[1] = str;
            new AssertionError(String.format("Running on unexpected looper thread: %s when expecting %s", objArr));
        }
    }

    public static void F(com.zendrive.sdk.x xVar) {
        if (!xVar.e()) {
            b1.g("PublicAPIUtility", "maybeLogResultForUser", xVar.d(), new Object[0]);
        }
    }

    public static void G(CTripFeatures cTripFeatures, com.zendrive.sdk.i.w wVar, Trip trip, Context context) {
        CStringList a15 = cTripFeatures.a();
        for (int i15 = 0; i15 < a15.size(); i15++) {
            H(wVar, trip.timestamp, trip.timestampEnd, "TripFeatures", a15.a(i15), cTripFeatures.c(a15.a(i15)), context);
        }
    }

    private static void H(com.zendrive.sdk.i.w wVar, long j15, long j16, String str, String str2, String str3, Context context) {
        try {
            JSONObject a15 = com.zendrive.sdk.manager.k.a(wVar, j15, j16);
            a15.put("tripTimestamp", j15);
            a15.put("tripTimestampEnd", j16);
            a15.put("subType", str2);
            u1.d(context).f().f(str, a15, new JSONObject(str3));
        } catch (JSONException e15) {
            b1.d("TripUtil", "saveToDebugData", "JsonException in " + str + " debug data: " + e15.getMessage(), new Object[0]);
        }
    }

    public static void I(com.zendrive.sdk.i.w wVar, Trip trip, Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("tripEndDecisionTimestamp", trip.tripEndDecisionTimestamp);
            jSONObject.put("tripStartReason", trip.tripStartReason.f42409a);
            H(wVar, trip.timestamp, trip.timestampEnd, "TripFeatures", "AdditionalInfo", jSONObject.toString(), context);
        } catch (JSONException e15) {
            b1.d("TripUtil", "saveAdditionalInfoToDebugData", "JsonException in AdditionalInfo debug data: " + e15.getMessage(), new Object[0]);
        }
    }

    public static void J(com.zendrive.sdk.i.w wVar, com.zendrive.sdk.i.k kVar, Trip trip) {
        Iterator<Event> it = kVar.a(trip.timestamp, trip.timestampEnd, n6.Accident, -1).iterator();
        while (true) {
            if (it.hasNext()) {
                Event next = it.next();
                if (next.prod) {
                    String[] strArr = u0.f42969a;
                    if (!next.eventDetectorId.equals("mock_collision")) {
                        break;
                    }
                }
            } else {
                Iterator<Event> it4 = kVar.a(trip.timestamp, trip.timestampEnd, n6.NearAccident, -1).iterator();
                while (it4.hasNext()) {
                    if (u0.q(it4.next())) {
                    }
                }
            }
        }
        long a15 = q0.a();
        b1.d("TripUtil", "setDebugTimestampOnAccident", "Set debug timestamp on accident : %d", Long.valueOf(a15));
        wVar.a(Long.valueOf(a15));
        kVar.a(trip);
        TripTimestampPoint tripTimestampPoint = new TripTimestampPoint();
        tripTimestampPoint.timestamp = trip.timestamp;
        tripTimestampPoint.timestampEnd = trip.timestampEnd;
        kVar.a(tripTimestampPoint);
    }

    public static final void K(@NotNull File file, String str) {
        File[] listFiles;
        boolean V;
        if (str != null && str.length() != 0 && file.isDirectory() && (listFiles = file.listFiles()) != null) {
            for (File file2 : listFiles) {
                if (file2.isFile()) {
                    V = kotlin.text.v.V(file2.getName(), str, false, 2, null);
                    if (V && !file2.delete()) {
                        b1.d("FileIOUtil", "deleteFileWithPrefix", "Deletion failed for file: " + file2.getName(), new Object[0]);
                    }
                }
            }
        }
    }

    public static final void L(@NotNull File file, @NotNull byte[] bArr, boolean z15) {
        FileOutputStream fileOutputStream = new FileOutputStream(file, z15);
        try {
            fileOutputStream.write(bArr);
            fileOutputStream.flush();
            no.b.a(fileOutputStream, null);
        } finally {
        }
    }

    public static final void M(@NotNull Writer writer, @NotNull s0 s0Var) {
        BufferedWriter bufferedWriter = new BufferedWriter(writer);
        try {
            s0Var.a(bufferedWriter);
            bufferedWriter.flush();
            no.b.a(bufferedWriter, null);
        } finally {
        }
    }

    private static void N(JSONObject jSONObject, String str, long j15, long j16, int i15, int i16) {
        JSONObject jSONObject2;
        if (jSONObject.has(str)) {
            jSONObject2 = jSONObject.getJSONObject(str);
            JSONArray jSONArray = jSONObject2.getJSONArray("connectionTimeline");
            JSONObject jSONObject3 = new JSONObject();
            jSONObject3.put("connectionTimestamp", j15);
            jSONObject3.put("disconnectionTimestamp", j16);
            jSONArray.put(jSONObject3);
            jSONObject2.put("connectionTimeline", jSONArray);
        } else {
            JSONObject jSONObject4 = new JSONObject();
            JSONArray jSONArray2 = new JSONArray();
            JSONObject jSONObject5 = new JSONObject();
            jSONObject5.put("connectionTimestamp", j15);
            jSONObject5.put("disconnectionTimestamp", j16);
            jSONArray2.put(jSONObject5);
            jSONObject4.put("connectionTimeline", jSONArray2);
            jSONObject4.put("minorClass", i16);
            jSONObject4.put("majorClass", i15);
            jSONObject2 = jSONObject4;
        }
        jSONObject.put(str, jSONObject2);
    }

    public static boolean O(com.zendrive.sdk.l lVar, com.zendrive.sdk.l lVar2) {
        if (lVar == null || lVar2 == null || !lVar.f().equals(lVar2.f()) || !lVar.b().equals(lVar2.b()) || !lVar2.a().e().equals(lVar.a().e()) || lVar2.a().f() != lVar.a().f()) {
            return false;
        }
        return true;
    }

    public static boolean P(GPS gps) {
        double d15 = gps.estimatedSpeed;
        if (d15 <= 100.0d) {
            int i15 = com.zendrive.sdk.data.a.f40640c;
            if (d15 >= 2.2351999282836914d) {
                return true;
            }
        }
        return false;
    }

    public static boolean Q(com.zendrive.sdk.i.k kVar, long j15, com.zendrive.sdk.c cVar) {
        ZendriveVehicleType zendriveVehicleType;
        ZendriveUserMode zendriveUserMode;
        PhonePosition phonePosition;
        int i15;
        ZendriveEventType zendriveEventType;
        ZendriveEventType zendriveEventType2;
        com.zendrive.sdk.o oVar;
        ZendriveEventSeverity zendriveEventSeverity;
        String str;
        String str2;
        double d15;
        double d16;
        double d17;
        String str3 = "user_speed_mph";
        String str4 = "max_user_speed_mph";
        if (kVar != null) {
            Trip trip = (Trip) kVar.a(Trip.class, j15);
            if (trip != null) {
                TripSummary g15 = g(trip, kVar);
                Trip trip2 = g15.trip;
                cVar.driveId = Long.valueOf(trip2.timestamp).toString();
                cVar.startTimeMillis = trip2.timestamp;
                cVar.endTimeMillis = trip2.timestampEnd;
                if (trip2.tripEndReason.equals("MaxTripTime")) {
                    cVar.warnings.add(c.a.UnexpectedTripDuration);
                }
                cVar.trackingId = g0(trip2.trackingId);
                cVar.sessionId = g0(trip2.sessionId);
                cVar.driveType = U(trip2);
                a7 a7Var = trip2.tripTypeV2;
                if (U(trip2) != ZendriveDriveType.DRIVE) {
                    zendriveVehicleType = null;
                } else if (a7Var == a7.Motorcycle) {
                    zendriveVehicleType = ZendriveVehicleType.MOTORCYCLE;
                } else {
                    zendriveVehicleType = ZendriveVehicleType.CAR;
                }
                cVar.vehicleType = zendriveVehicleType;
                a7 a7Var2 = trip2.tripTypeV2;
                if (a7Var2 == a7.Driver) {
                    zendriveUserMode = ZendriveUserMode.DRIVER;
                } else if (a7Var2 == a7.Passenger) {
                    zendriveUserMode = ZendriveUserMode.PASSENGER;
                } else {
                    zendriveUserMode = null;
                }
                cVar.userMode = zendriveUserMode;
                t6 t6Var = trip2.phonePosition;
                if (t6Var == t6.Unknown) {
                    phonePosition = PhonePosition.UNKNOWN;
                } else if (t6Var == t6.Mount) {
                    phonePosition = PhonePosition.MOUNT;
                } else {
                    phonePosition = PhonePosition.UNKNOWN;
                }
                cVar.phonePosition = phonePosition;
                cVar.insurancePeriod = d(trip2.insurancePeriod);
                if (cVar.driveType != ZendriveDriveType.INVALID) {
                    cVar.distanceMeters = trip2.distance;
                    cVar.averageSpeed = trip2.averageSpeed;
                    cVar.maxSpeed = trip2.maxSpeed;
                    List<TripTrail> list = g15.tripTrail;
                    List<Event> list2 = g15.events;
                    ArrayList<com.zendrive.sdk.h> arrayList = new ArrayList<>();
                    for (TripTrail tripTrail : list) {
                        arrayList.add(new com.zendrive.sdk.h(new com.zendrive.sdk.g(tripTrail.latitude, tripTrail.longitude), tripTrail.timestamp));
                        str3 = str3;
                        str4 = str4;
                    }
                    String str5 = str3;
                    String str6 = str4;
                    for (Event event : list2) {
                        if (event.prod) {
                            arrayList.add(new com.zendrive.sdk.h(new com.zendrive.sdk.g(event.latitudeStart, event.longitudeStart), event.timestamp));
                            arrayList.add(new com.zendrive.sdk.h(new com.zendrive.sdk.g(event.latitudeEnd, event.longitudeEnd), event.timestampEnd));
                        }
                    }
                    Collections.sort(arrayList, new x());
                    cVar.waypoints = arrayList;
                    for (Event event2 : g15.events) {
                        if (event2.prod && !com.zendrive.sdk.manager.f.j(event2)) {
                            n6 n6Var = event2.eventType;
                            int i16 = i0.f42906c;
                            int ordinal = n6Var.ordinal();
                            if (ordinal != 1) {
                                if (ordinal != 2) {
                                    if (ordinal != 7) {
                                        if (ordinal != 9) {
                                            if (ordinal != 12) {
                                                switch (ordinal) {
                                                    case 17:
                                                        zendriveEventType = ZendriveEventType.PHONE_SCREEN_INTERACTION;
                                                        break;
                                                    case 18:
                                                        zendriveEventType = ZendriveEventType.HARD_TURN;
                                                        break;
                                                    case 19:
                                                        zendriveEventType = ZendriveEventType.STOP_SIGN_VIOLATION;
                                                        break;
                                                    case 20:
                                                        zendriveEventType = ZendriveEventType.HANDS_FREE_PHONE_CALL;
                                                        break;
                                                    case 21:
                                                        zendriveEventType = ZendriveEventType.PASSIVE_DISTRACTION;
                                                        break;
                                                    default:
                                                        zendriveEventType2 = null;
                                                        break;
                                                }
                                            } else {
                                                zendriveEventType = ZendriveEventType.COLLISION;
                                            }
                                        } else {
                                            zendriveEventType = ZendriveEventType.SPEEDING;
                                        }
                                    } else {
                                        zendriveEventType = ZendriveEventType.PHONE_HANDLING;
                                    }
                                } else {
                                    zendriveEventType = ZendriveEventType.HARD_BRAKE;
                                }
                            } else {
                                zendriveEventType = ZendriveEventType.AGGRESSIVE_ACCELERATION;
                            }
                            zendriveEventType2 = zendriveEventType;
                            if (zendriveEventType2 == null) {
                                str = str5;
                                str2 = str6;
                                oVar = null;
                            } else {
                                oVar = new com.zendrive.sdk.o();
                                oVar.f42676c = zendriveEventType2;
                                oVar.f42677d = event2.timestamp;
                                oVar.f42678e = event2.timestampEnd;
                                oVar.f42679f = new com.zendrive.sdk.g(event2.latitudeStart, event2.longitudeStart);
                                oVar.f42680g = new com.zendrive.sdk.g(event2.latitudeEnd, event2.longitudeEnd);
                                int ordinal2 = event2.eventType.ordinal();
                                if (ordinal2 != 1) {
                                    if (ordinal2 != 2) {
                                        zendriveEventSeverity = ZendriveEventSeverity.NOT_AVAILABLE;
                                    } else {
                                        try {
                                            JSONObject jSONObject = new JSONObject(event2.data);
                                            if (jSONObject.has("magnitude_mps2")) {
                                                if (Math.abs(jSONObject.getDouble("magnitude_mps2")) > 4.4d) {
                                                    zendriveEventSeverity = ZendriveEventSeverity.HIGH;
                                                } else {
                                                    zendriveEventSeverity = ZendriveEventSeverity.LOW;
                                                }
                                            } else {
                                                zendriveEventSeverity = ZendriveEventSeverity.NOT_AVAILABLE;
                                            }
                                        } catch (JSONException e15) {
                                            b1.d("PublicAPIUtility", "getSeverity", "Error parsing event.data %s", e15.toString());
                                        }
                                    }
                                } else {
                                    com.zendrive.sdk.cdetectorlib.f b15 = com.zendrive.sdk.cdetectorlib.f.b(event2.severity);
                                    int ordinal3 = b15.ordinal();
                                    if (ordinal3 != 0) {
                                        if (ordinal3 != 1) {
                                            if (ordinal3 != 2) {
                                                new IllegalStateException("Unknown severity: " + b15.name());
                                                zendriveEventSeverity = ZendriveEventSeverity.NOT_AVAILABLE;
                                            } else {
                                                zendriveEventSeverity = ZendriveEventSeverity.HIGH;
                                            }
                                        } else {
                                            zendriveEventSeverity = ZendriveEventSeverity.LOW;
                                        }
                                    } else {
                                        zendriveEventSeverity = ZendriveEventSeverity.NOT_AVAILABLE;
                                    }
                                }
                                oVar.f42681h = zendriveEventSeverity;
                                if (zendriveEventType2 == ZendriveEventType.SPEEDING) {
                                    try {
                                        JSONObject jSONObject2 = new JSONObject(event2.data);
                                        o.a aVar = new o.a();
                                        oVar.f42683j = aVar;
                                        if (jSONObject2.has("speed_limit_mph")) {
                                            d15 = jSONObject2.getDouble("speed_limit_mph") * 0.4469444444444444d;
                                        } else {
                                            d15 = -1.0d;
                                        }
                                        aVar.f42684a = d15;
                                        o.a aVar2 = oVar.f42683j;
                                        str2 = str6;
                                        try {
                                            if (jSONObject2.has(str2)) {
                                                d16 = jSONObject2.getDouble(str2) * 0.4469444444444444d;
                                            } else {
                                                d16 = -1.0d;
                                            }
                                            aVar2.f42685b = d16;
                                            o.a aVar3 = oVar.f42683j;
                                            str = str5;
                                            try {
                                                if (jSONObject2.has(str)) {
                                                    d17 = jSONObject2.getDouble(str) * 0.4469444444444444d;
                                                } else {
                                                    d17 = -1.0d;
                                                }
                                                aVar3.f42686c = d17;
                                            } catch (JSONException e16) {
                                                e = e16;
                                                b1.d("PublicAPIUtility", "getZendriveEvent", "Error parsing speeding event.data %s", e.toString());
                                                if (oVar != null) {
                                                }
                                                str6 = str2;
                                                str5 = str;
                                            }
                                        } catch (JSONException e17) {
                                            e = e17;
                                            str = str5;
                                        }
                                    } catch (JSONException e18) {
                                        e = e18;
                                        str = str5;
                                        str2 = str6;
                                    }
                                } else {
                                    str = str5;
                                    str2 = str6;
                                    if (zendriveEventType2 == ZendriveEventType.HARD_TURN) {
                                        try {
                                            int ordinal4 = h.a.a(cdetectorlibJNI.CHardTurnEvent_turnTypeFromString(new JSONObject(event2.data).get(cdetectorlibJNI.CHardTurnEvent_turnTypeKey()).toString())).ordinal();
                                            if (ordinal4 != 0) {
                                                if (ordinal4 == 1) {
                                                    oVar.f42682i = ZendriveTurnDirection.RIGHT;
                                                }
                                            } else {
                                                oVar.f42682i = ZendriveTurnDirection.LEFT;
                                            }
                                        } catch (JSONException e19) {
                                            b1.d("PublicAPIUtility", "getZendriveEvent", "Error parsing hard turn event.data %s", e19.toString());
                                        }
                                    }
                                }
                            }
                            if (oVar != null) {
                                cVar.events.add(oVar);
                            }
                            str6 = str2;
                            str5 = str;
                        }
                    }
                    TripInsight tripInsight = g15.tripInsight;
                    if (tripInsight != null) {
                        cVar.eventRatings.f42702c = u0.b(tripInsight.rapidAccelerationRating);
                        cVar.eventRatings.f42703d = u0.b(tripInsight.hardBrakeRating);
                        cVar.eventRatings.f42705f = u0.b(tripInsight.hardTurnRating);
                        cVar.eventRatings.f42704e = u0.b(tripInsight.overSpeedingRating);
                        cVar.eventRatings.f42706g = u0.b(tripInsight.phoneUseRating);
                    }
                    com.zendrive.sdk.e eVar = cVar.score;
                    if (tripInsight != null) {
                        double d18 = tripInsight.zendriveScore;
                        if (d18 >= 0.0d) {
                            i15 = (int) Math.round(d18 * 100.0d);
                            eVar.f40718c = i15;
                            if (trip2.extrapolatedDistance != -1.0d) {
                                com.zendrive.sdk.q qVar = new com.zendrive.sdk.q();
                                qVar.f42707c = trip2.extrapolatedDistance;
                                qVar.f42708d = new com.zendrive.sdk.g(trip2.estimatedStartLocationLatitude, trip2.estimatedStartLocationLongitude);
                                cVar.extrapolationDetails = qVar;
                            }
                        }
                    }
                    i15 = -1;
                    eVar.f40718c = i15;
                    if (trip2.extrapolatedDistance != -1.0d) {
                    }
                }
                Vehicle vehicle = g15.vehicle;
                if (vehicle != null) {
                    cVar.vehicleTaggingDetails = new com.zendrive.sdk.n0(vehicle.vehicleId, vehicle.isTaggedByBeacon, vehicle.isTaggedByBluetoothStereo);
                    return true;
                }
                return true;
            }
            b1.d("ZendriveIntent", "populateDriveInfo", "No trip in DB with trip timestamp: %d", Long.valueOf(j15));
        } else {
            b1.d("ZendriveIntent", "populateDriveInfo", "CentralDataStore is null", new Object[0]);
        }
        return false;
    }

    public static boolean R(File file) {
        File[] listFiles = file.listFiles();
        if (listFiles != null) {
            for (File file2 : listFiles) {
                R(file2);
            }
        }
        return file.delete();
    }

    @NotNull
    public static final byte[] S(@NotNull InputStream inputStream) {
        try {
            byte[] c15 = no.a.c(inputStream);
            no.b.a(inputStream, null);
            return c15;
        } catch (Throwable th4) {
            try {
                throw th4;
            } catch (Throwable th5) {
                no.b.a(inputStream, th4);
                throw th5;
            }
        }
    }

    public static final long T(@NotNull File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] listFiles = file.listFiles();
                if (listFiles == null) {
                    return 0L;
                }
                long j15 = 0;
                for (File file2 : listFiles) {
                    j15 += T(file2);
                    if (j15 < 0) {
                        return Long.MAX_VALUE;
                    }
                }
                return j15;
            }
            return file.length();
        }
        throw new IllegalArgumentException(file + " does not exist");
    }

    public static ZendriveDriveType U(Trip trip) {
        if (!trip.isValid) {
            return ZendriveDriveType.INVALID;
        }
        a7 a7Var = trip.tripTypeV2;
        if (a7Var != a7.Bicycle && a7Var != a7.Transit && a7Var != a7.OffRoad && a7Var != a7.Bus && a7Var != a7.HighSpeedVehicle) {
            return ZendriveDriveType.DRIVE;
        }
        return ZendriveDriveType.NON_DRIVING;
    }

    public static a7 V(com.zendrive.sdk.i.k kVar, Trip trip) {
        if (trip.tripTypeV2 == null) {
            trip.tripTypeV2 = a7.Drive;
        }
        boolean z15 = !p(kVar, trip.timestamp).isEmpty();
        a7 a7Var = trip.tripTypeV2;
        a7 a7Var2 = a7.Drive;
        if (a7Var == a7Var2) {
            if (trip.isAutoStart() && !z15 && (trip.averageSpeed >= 42.0d || trip.maxSpeed >= 58.11d)) {
                return a7.HighSpeedVehicle;
            }
            if (trip.isDedicatedVehicleType) {
                e6 e6Var = trip.vehicleType;
                if (e6Var != null && e6Var.ordinal() == 2) {
                    return a7.Motorcycle;
                }
                return a7Var2;
            }
        } else if (a7Var != a7.Motorcycle && z15) {
            return a7Var2;
        }
        return trip.tripTypeV2;
    }

    public static String W(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(OrdersData.SCHEME_PHONE);
        if (telephonyManager == null) {
            return "";
        }
        String networkCountryIso = telephonyManager.getNetworkCountryIso();
        if (networkCountryIso.isEmpty()) {
            networkCountryIso = telephonyManager.getSimCountryIso();
        }
        return networkCountryIso.toLowerCase(Locale.US);
    }

    @NotNull
    public static final String X(@NotNull InputStream inputStream) {
        try {
            String f15 = no.m.f(new InputStreamReader(inputStream, kotlin.text.b.UTF_8));
            no.b.a(inputStream, null);
            return f15;
        } catch (Throwable th4) {
            try {
                throw th4;
            } catch (Throwable th5) {
                no.b.a(inputStream, th4);
                throw th5;
            }
        }
    }

    public static List<TripTrail> Y(com.zendrive.sdk.i.k kVar, long j15, long j16) {
        ArrayList<GPS> a15;
        ArrayList<GPS> a16;
        GPS gps;
        GPS gps2;
        kVar.getClass();
        ArrayList b15 = kVar.b(TripTrail.class, j15, j16, -1);
        if (b15.isEmpty()) {
            a15 = kVar.a(j15, j16, -1, 65);
            a16 = a15;
        } else {
            a15 = kVar.a(j15, ((TripTrail) b15.get(0)).timestamp - 1, -1, 65);
            a16 = kVar.a(((TripTrail) b15.get(b15.size() - 1)).timestamp + 1, j16, -1, 65);
        }
        int i15 = 0;
        while (true) {
            gps = null;
            if (i15 < a15.size()) {
                if (a15.get(i15).horizontalAccuracy <= 30) {
                    gps2 = a15.get(i15);
                    break;
                }
                i15++;
            } else {
                gps2 = null;
                break;
            }
        }
        int size = a16.size() - 1;
        while (true) {
            if (size < 0) {
                break;
            }
            if (a16.get(size).horizontalAccuracy <= 30) {
                gps = a16.get(size);
                break;
            }
            size--;
        }
        if (gps2 != null) {
            b15.add(0, TripTrail.getTripTrailPoint(gps2));
        }
        if (gps != null) {
            b15.add(TripTrail.getTripTrailPoint(gps));
        }
        b15.isEmpty();
        return b15;
    }

    public static JSONObject Z(Context context, String str) {
        try {
            FileInputStream fileInputStream = new FileInputStream(new File(f0(context), str));
            try {
                String X = X(fileInputStream);
                fileInputStream.close();
                try {
                    return new JSONObject(X);
                } catch (JSONException e15) {
                    b1.d("SdkMetricUtil", "readFromFile", "Couldn't create JSON object: " + e15.getMessage(), new Object[0]);
                    return null;
                }
            } catch (Throwable th4) {
                try {
                    throw th4;
                } catch (Throwable th5) {
                    try {
                        fileInputStream.close();
                    } catch (Throwable th6) {
                        th4.addSuppressed(th6);
                    }
                    throw th5;
                }
            }
        } catch (FileNotFoundException unused) {
            return null;
        } catch (IOException e16) {
            b1.d("SdkMetricUtil", "readFromFile", "Exception occurred when reading the file: " + e16.getMessage(), new Object[0]);
            return null;
        }
    }

    public static double a(double d15, double d16, double d17, double d18) {
        double radians = Math.toRadians(d17 - d15) / 2.0d;
        double radians2 = Math.toRadians(d18 - d16) / 2.0d;
        double sin = (Math.sin(radians) * Math.sin(radians)) + (Math.sin(radians2) * Math.sin(radians2) * Math.cos(Math.toRadians(d15)) * Math.cos(Math.toRadians(d17)));
        return 6371000 * Math.atan2(Math.sqrt(sin), Math.sqrt(1.0d - sin)) * 2.0d;
    }

    public static void a0() {
        if (Thread.currentThread() != null) {
            E(x5.a());
        }
    }

    public static double b(com.zendrive.sdk.i.k kVar, Trip trip) {
        List<TripTrail> Y = Y(kVar, trip.timestamp, trip.timestampEnd);
        double d15 = 0.0d;
        int i15 = 1;
        while (true) {
            ArrayList arrayList = (ArrayList) Y;
            if (i15 < arrayList.size()) {
                int i16 = i15 - 1;
                d15 += a(((TripTrail) arrayList.get(i16)).latitude, ((TripTrail) arrayList.get(i16)).longitude, ((TripTrail) arrayList.get(i15)).latitude, ((TripTrail) arrayList.get(i15)).longitude);
                i15++;
            } else {
                return d15;
            }
        }
    }

    public static void b0(Context context, b0.a aVar, String str, String str2) {
        HashMap<String, String> s15 = s(context, str, str2);
        for (String str3 : s15.keySet()) {
            aVar.a(str3, s15.get(str3));
        }
    }

    public static long c(com.zendrive.sdk.i.k kVar, long j15, long j16) {
        Event event;
        Iterator it = kVar.a(Event.class, j15, j16, -1, k.c.DESC).iterator();
        while (true) {
            if (it.hasNext()) {
                event = (Event) it.next();
                if (event.eventType == n6.PhoneTap) {
                    break;
                }
            } else {
                event = null;
                break;
            }
        }
        if (event != null) {
            return event.timestampEnd + 1;
        }
        return j15;
    }

    public static void c0(Looper looper) {
        String name;
        Looper myLooper = Looper.myLooper();
        if (myLooper == looper) {
            Object[] objArr = new Object[2];
            String str = "null";
            if (myLooper == null) {
                name = "null";
            } else {
                name = myLooper.getThread().getName();
            }
            objArr[0] = name;
            if (looper != null) {
                str = looper.getThread().getName();
            }
            objArr[1] = str;
            new AssertionError(String.format("Running on unexpected looper thread: %s when expecting %s", objArr));
        }
    }

    public static com.zendrive.sdk.r d(q6 q6Var) {
        if (q6Var == null) {
            return null;
        }
        int ordinal = q6Var.ordinal();
        if (ordinal != 1) {
            if (ordinal != 2) {
                if (ordinal != 3) {
                    return null;
                }
                return com.zendrive.sdk.r.Period3;
            }
            return com.zendrive.sdk.r.Period2;
        }
        return com.zendrive.sdk.r.Period1;
    }

    public static boolean d0(String str) {
        if (str != null && !"".equals(str) && !str.matches(".*[? \\\\&/;#\n]+.*")) {
            return true;
        }
        return false;
    }

    public static GPS e(Location location) {
        GPS.Builder longitude = new GPS.Builder().setTimestamp(q0.b(location.getElapsedRealtimeNanos() / 1000000)).setAltitude((int) location.getAltitude()).setLatitude(location.getLatitude()).setLongitude(location.getLongitude());
        if (location.hasBearing()) {
            longitude.setCourse((int) location.getBearing());
        }
        if (location.hasAccuracy()) {
            longitude.setHorizontalAccuracy((int) location.getAccuracy());
        }
        if (location.hasSpeed()) {
            longitude.setRawSpeed(location.getSpeed());
        }
        return longitude.build2();
    }

    public static Handler e0(Looper looper) {
        return new d1(looper);
    }

    public static GPS f(n0 n0Var) {
        GPS gps = n0Var.f42927e;
        return new GPS.Builder().setTimestamp(gps.timestamp).setReceivedAtTimestamp(gps.receivedAtTimestamp).setAltitude(gps.altitude).setLatitude(gps.latitude).setLongitude(gps.longitude).setCourse(gps.course).setHorizontalAccuracy(gps.horizontalAccuracy).setRawSpeed(gps.rawSpeed).setEstimatedSpeed(n0Var.f42923a).setSmoothedLatitude(n0Var.f42925c).setSmoothedLongitude(n0Var.f42926d).build2();
    }

    @NotNull
    public static final File f0(@NotNull Context context) {
        return new File(context.getFilesDir(), "com.zendrive.sdk");
    }

    public static TripSummary g(Trip trip, com.zendrive.sdk.i.k kVar) {
        TripInsight tripInsight;
        byte[] bArr;
        int i15;
        int i16;
        int i17;
        int uploadSizeBytes;
        TripSummary tripSummary = new TripSummary();
        tripSummary.timestamp = trip.timestamp;
        tripSummary.trip = trip;
        tripSummary.tripSummaryVersion = trip.version;
        tripSummary.events = kVar.a(trip.timestamp, Math.max(trip.timestampEnd, trip.tripEndDecisionTimestamp), -1, false);
        tripSummary.tripTrail = Y(kVar, trip.timestamp, trip.timestampEnd);
        long j15 = trip.timestamp;
        ArrayList b15 = kVar.b(TripInsight.class, j15, j15, 1);
        if (b15.isEmpty()) {
            tripInsight = null;
        } else {
            tripInsight = (TripInsight) b15.get(0);
        }
        tripSummary.tripInsight = tripInsight;
        long j16 = trip.timestamp;
        ArrayList b16 = kVar.b(SpeedLimitDataPoint.class, j16, j16, 1);
        if (b16.isEmpty()) {
            bArr = null;
        } else {
            bArr = ((SpeedLimitDataPoint) b16.get(0)).speedLimitData;
        }
        tripSummary.speedLimitData = bArr;
        HashSet hashSet = new HashSet(kVar.b(DetectorInfo.class, trip.timestamp, trip.timestampEnd, -1));
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            DetectorInfo detectorInfo = (DetectorInfo) it.next();
            if (detectorInfo.isProd) {
                arrayList.add(detectorInfo);
            } else {
                arrayList2.add(detectorInfo);
            }
        }
        tripSummary.prodDetectors = arrayList;
        tripSummary.nonProdDetectors = arrayList2;
        if (tripSummary.events != null) {
            ArrayList arrayList3 = new ArrayList();
            int i18 = 0;
            i15 = 0;
            while (true) {
                if (i18 >= tripSummary.events.size()) {
                    break;
                }
                Event event = tripSummary.events.get(i18);
                if ((i18 < tripSummary.getMaxNumEventsToUpload() || event.eventType == n6.Accident) && (event.timestamp <= trip.timestampEnd || event.eventType == n6.NearAccident)) {
                    if (event.eventType == n6.Accident) {
                        uploadSizeBytes = event.uploadSizeBytesForAccident();
                    } else {
                        uploadSizeBytes = event.uploadSizeBytes();
                    }
                    int i19 = uploadSizeBytes + i15;
                    if (i19 > 196608) {
                        tripSummary.isTrimmed = true;
                        break;
                    }
                    arrayList3.add(event);
                    i15 = i19;
                }
                i18++;
            }
            tripSummary.events = arrayList3;
        } else {
            i15 = 0;
        }
        List<TripTrail> list = tripSummary.tripTrail;
        if (list != null && !list.isEmpty()) {
            ArrayList arrayList4 = new ArrayList();
            int uploadSizeBytes2 = (196608 - i15) / tripSummary.tripTrail.get(0).uploadSizeBytes();
            if (uploadSizeBytes2 > 0) {
                if (uploadSizeBytes2 >= tripSummary.getMaxNumTripTrailsToUpload()) {
                    uploadSizeBytes2 = tripSummary.getMaxNumTripTrailsToUpload();
                }
                int size = tripSummary.tripTrail.size() - uploadSizeBytes2;
                if (size > 0) {
                    i17 = tripSummary.tripTrail.size() / (size + 1);
                } else {
                    i17 = 0;
                }
                int i25 = 0;
                i16 = 0;
                for (int i26 = 0; i26 < tripSummary.tripTrail.size(); i26++) {
                    TripTrail tripTrail = tripSummary.tripTrail.get(i26);
                    if (i26 != 0 && i26 != tripSummary.tripTrail.size() - 1 && i25 < size && i17 != 0 && (i26 + 1) % i17 == 0) {
                        i25++;
                    } else {
                        i16 += tripTrail.uploadSizeBytes();
                        arrayList4.add(tripTrail);
                    }
                }
                if (i25 > 0) {
                    tripSummary.isTrimmed = true;
                }
            } else {
                i16 = 0;
            }
            tripSummary.tripTrail = arrayList4;
        } else {
            i16 = 0;
        }
        byte[] bArr2 = tripSummary.speedLimitData;
        if (bArr2 != null && bArr2.length >= 196608 - (i15 + i16)) {
            tripSummary.isTrimmed = true;
            tripSummary.speedLimitData = null;
        }
        ArrayList<Vehicle> a15 = kVar.a(trip.timestamp);
        if (!a15.isEmpty()) {
            tripSummary.vehicle = a15.get(0);
        }
        return tripSummary;
    }

    public static String g0(String str) {
        if ("".equals(str)) {
            return null;
        }
        return str;
    }

    public static y4 h(Intent intent) {
        if (!"com.zendrive.sdk.accident".equals(intent.getAction())) {
            return y4.UNKNOWN;
        }
        return y4.b(intent.getIntExtra("accident_callback_key", -1));
    }

    public static void h0() {
        e0[] values = e0.values();
        for (int i15 = 0; i15 < 5; i15++) {
            e0 e0Var = values[i15];
            if (com.zendrive.sdk.cdetectorlib.h.m() && e0Var.r().size() > 0) {
                new x0().e(e0Var);
            }
        }
    }

    @NonNull
    public static t6 i(Trip trip) {
        if (trip.mountFraction >= 0.8d) {
            return t6.Mount;
        }
        return t6.Unknown;
    }

    public static String i0() {
        if (u1.l() == null) {
            return "android-9.0.0";
        }
        return "android-9.0.0-HMS";
    }

    public static j8 j(@NonNull Trip trip, Context context) {
        u1 d15 = u1.d(context);
        if (d15 != null && trip.isAutoStart()) {
            return d15.o().O().f41725b;
        }
        return null;
    }

    private static String j0(Context context) {
        return com.zendrive.sdk.i.w.a(context).j().b();
    }

    public static y6 k(@NonNull String str) {
        str.hashCode();
        char c15 = 65535;
        switch (str.hashCode()) {
            case -1914982106:
                if (str.equals("PartialTrip")) {
                    c15 = 0;
                    break;
                }
                break;
            case -1608353955:
                if (str.equals("EndedOnPause")) {
                    c15 = 1;
                    break;
                }
                break;
            case -1598830044:
                if (str.equals("Teardown")) {
                    c15 = 2;
                    break;
                }
                break;
            case -1387514686:
                if (str.equals("FalseDetection")) {
                    c15 = 3;
                    break;
                }
                break;
            case -1072750741:
                if (str.equals("LowDisplacement")) {
                    c15 = 4;
                    break;
                }
                break;
            case -396660673:
                if (str.equals("WalkingDetector")) {
                    c15 = 5;
                    break;
                }
                break;
            case -210718569:
                if (str.equals("DriveTimeout")) {
                    c15 = 6;
                    break;
                }
                break;
            case 149039143:
                if (str.equals("BusinessHoursPause")) {
                    c15 = 7;
                    break;
                }
                break;
            case 597617928:
                if (str.equals("ManualStop")) {
                    c15 = '\b';
                    break;
                }
                break;
            case 714714780:
                if (str.equals("InvalidTrip")) {
                    c15 = '\t';
                    break;
                }
                break;
            case 916041206:
                if (str.equals("MaxTripTime")) {
                    c15 = '\n';
                    break;
                }
                break;
            case 1018322208:
                if (str.equals("AutoOff")) {
                    c15 = 11;
                    break;
                }
                break;
            case 1194085256:
                if (str.equals("WalkingActivity")) {
                    c15 = '\f';
                    break;
                }
                break;
            case 1346273308:
                if (str.equals("ManualStart")) {
                    c15 = '\r';
                    break;
                }
                break;
        }
        switch (c15) {
            case 0:
                return y6.PartialTrip;
            case 1:
                return y6.EndedOnPause;
            case 2:
                return y6.Teardown;
            case 3:
                return y6.FalseDetection;
            case 4:
                return y6.LowDisplacement;
            case 5:
                return y6.WalkingDetector;
            case 6:
                return y6.DriveTimeout;
            case 7:
                return y6.BusinessHours;
            case '\b':
                return y6.ManualStop;
            case '\t':
                return y6.InvalidTrip;
            case '\n':
                return y6.MaxTripTime;
            case 11:
                return y6.AutoOff;
            case '\f':
                return y6.WalkingActivity;
            case '\r':
                return y6.ManualStart;
            default:
                return null;
        }
    }

    public static String k0() {
        Context context = f42918a;
        if (context != null && com.zendrive.sdk.i.w.a(context).X()) {
            Context context2 = f42918a;
            Object obj = u1.f42007c;
            return com.zendrive.sdk.i.w.a(context2).n();
        }
        return null;
    }

    public static y0 l(Context context, com.zendrive.sdk.l lVar, String str) {
        a0 a0Var;
        byte[] bArr;
        l6 l6Var;
        k6 k6Var;
        a0 a0Var2;
        z0 m15 = m(context, lVar.f(), lVar.b(), str, lVar.a().e(), lVar.e(), true);
        int i15 = m15.f43009a;
        if (i15 == 200) {
            a0Var = a0.OK;
            bArr = m15.f43010b;
        } else {
            if (i15 == 400) {
                byte[] bArr2 = m15.f43011c;
                Charset charset = StandardCharsets.UTF_8;
                b1.d("SDKApiClient", "parseZendriveHttpResponse", "Bad request, error: %s", new String(bArr2, charset));
                try {
                    JSONObject jSONObject = new JSONObject(new String(m15.f43011c, charset)).getJSONObject("error");
                    int i16 = jSONObject.getInt(NotificationData.JSON_TYPE);
                    if (i16 != 0) {
                        if (i16 != 1) {
                            l6Var = null;
                        } else {
                            l6Var = l6.Resolvable;
                        }
                    } else {
                        l6Var = l6.Unresolvable;
                    }
                    int i17 = jSONObject.getInt("code");
                    if (i17 != 100) {
                        if (i17 != 101) {
                            k6Var = null;
                        } else {
                            k6Var = k6.RegionUnsupported;
                        }
                    } else {
                        k6Var = k6.UserDeprovisioned;
                    }
                    b1.d("SDKApiClient", "parseErrorBytes", jSONObject.getString("message"), new Object[0]);
                    if (l6Var == l6.Unresolvable) {
                        if (k6Var == k6.RegionUnsupported) {
                            a0Var2 = a0.REGION_UNSUPPORTED;
                        } else if (k6Var == k6.UserDeprovisioned) {
                            a0Var2 = a0.USER_DEPROVISIONED;
                        }
                        a0Var = a0Var2;
                    }
                } catch (JSONException e15) {
                    b1.d("SDKApiClient", "parseErrorBytes", "Unable to create json with error bytes: %s: " + e15.getMessage(), new Object[0]);
                }
                a0Var = a0.NETWORK_NOT_AVAILABLE;
            } else if (i15 != 401 && i15 != 403) {
                a0Var = a0.NETWORK_NOT_AVAILABLE;
            } else {
                a0Var = a0.INVALID_SDK_KEY;
            }
            bArr = null;
        }
        if (bArr == null) {
            if (a0.REGION_UNSUPPORTED == a0Var) {
                b1.g("PublicAPIUtility", "getAuthenticateSDKResponse", "Region is not supported for this account.", new Object[0]);
            }
            if (a0.INVALID_SDK_KEY == a0Var) {
                b1.g("PublicAPIUtility", "getAuthenticateSDKResponse", "Failed to verify zendrive api key.", new Object[0]);
            }
        }
        y0 y0Var = new y0(bArr, a0Var);
        y0Var.f43006c = true;
        return y0Var;
    }

    public static boolean l0(Context context) {
        return Boolean.TRUE.equals(u1.d(context).o().O().f41728e.f41593h);
    }

    private static z0 m(Context context, String str, String str2, String str3, m.a aVar, ZendriveRegion zendriveRegion, boolean z15) {
        int i15;
        String str4;
        String str5;
        String str6;
        int i16;
        String str7;
        Object[] objArr;
        Charset charset;
        String b15 = k.b(context);
        String str8 = "";
        if (b15 == null) {
            try {
                objArr = new Object[3];
                charset = StandardCharsets.UTF_8;
            } catch (UnsupportedEncodingException e15) {
                e = e15;
            }
            try {
                objArr[0] = URLEncoder.encode(str2, charset.name());
                objArr[1] = URLEncoder.encode(str3, charset.name());
                objArr[2] = aVar.toString();
                str8 = String.format("/v6/authenticate_sdk?user_id=%s&installation_id=%s&service_level=%s", objArr);
            } catch (UnsupportedEncodingException e16) {
                e = e16;
                b1.e("SDKApiClient", "getHttpResponse", e, "Error encoding sdk auth url params", new Object[0]);
                String str9 = str8;
                b1.d("SDKApiClient", "getHttpResponse", "Network call to url %s with region %s", str9, zendriveRegion);
                return y.c("auth", context, str9, str, str2, zendriveRegion);
            }
            String str92 = str8;
            b1.d("SDKApiClient", "getHttpResponse", "Network call to url %s with region %s", str92, zendriveRegion);
            return y.c("auth", context, str92, str, str2, zendriveRegion);
        }
        if (b15.isEmpty()) {
            b1.d("SDKApiClient", "getHttpResponse", "SdkAuth proxy url is empty in AndroidManifest - HTTP_NOT_FOUND", new Object[0]);
            return new z0(WalletConstants.ERROR_CODE_INVALID_PARAMETERS, null, null);
        }
        StringBuilder sb5 = new StringBuilder();
        int i17 = 12;
        while (true) {
            int i18 = i17 - 1;
            if (i17 == 0) {
                break;
            }
            sb5.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt((int) (Math.random() * 62)));
            i17 = i18;
        }
        sb5.append(String.valueOf(q0.a()));
        String sb6 = sb5.toString();
        com.zendrive.sdk.i.w a15 = com.zendrive.sdk.i.w.a(context);
        String N = a15.N();
        if (N == null) {
            i15 = 200;
            str4 = sb6;
            z0 c15 = y.c("auth", context, b15 + "/v6/key_management/public_key", str, str2, zendriveRegion);
            if (c15.f43009a == 200 && c15.f43010b != null) {
                try {
                    str5 = new JSONObject(new String(c15.f43010b, StandardCharsets.UTF_8)).getString("public_key");
                    try {
                        a15.f(str5);
                    } catch (JSONException unused) {
                        N = str5;
                        b1.d("SDKApiClient", "getPublicKey", "Error parsing publicKey response", new Object[0]);
                        str5 = N;
                        str6 = str4;
                        if (str6 != null) {
                        }
                        i16 = 0;
                        str7 = null;
                        if (str7 != null) {
                        }
                    }
                } catch (JSONException unused2) {
                }
                str6 = str4;
                if (str6 != null || str5 == null) {
                    i16 = 0;
                } else {
                    try {
                        byte[] bytes = str6.getBytes(StandardCharsets.UTF_8);
                        PublicKey generatePublic = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str5, 0)));
                        Cipher cipher = Cipher.getInstance("RSA");
                        cipher.init(1, generatePublic);
                        str7 = Base64.encodeToString(cipher.doFinal(bytes), 10);
                        i16 = 0;
                    } catch (Exception e17) {
                        i16 = 0;
                        b1.d("SDKApiClient", "getToken", "Exception in generation sdk_auth token: " + e17.getMessage(), new Object[0]);
                    }
                    if (str7 != null) {
                        b1.d("SDKApiClient", "getHttpResponse", "Token for SdkAuth is null - HTTP_NOT_FOUND", new Object[i16]);
                        return new z0(WalletConstants.ERROR_CODE_INVALID_PARAMETERS, null, null);
                    }
                    try {
                        str8 = String.format(b15 + "/v6/authenticate_sdk?token=%s", URLEncoder.encode(str7, StandardCharsets.UTF_8.name()));
                    } catch (UnsupportedEncodingException e18) {
                        b1.e("SDKApiClient", "getHttpResponse", e18, "Error encoding proxy sdk auth url params", new Object[0]);
                    }
                    String str10 = str8;
                    b1.d("SDKApiClient", "getHttpResponse", "Network call to url %s", str10);
                    z0 c16 = y.c("auth", context, str10, str, str2, zendriveRegion);
                    int i19 = c16.f43009a;
                    if (i19 == i15 && c16.f43010b != null) {
                        try {
                            c16.f43010b = new qt.b(1000).b(c16.f43010b, str6.toCharArray());
                            return c16;
                        } catch (CryptorException e19) {
                            b1.d("SDKApiClient", "getHttpResponse", "Exception decrypting sdk auth response: " + e19.getMessage(), new Object[0]);
                            if (z15) {
                                b1.d("SDKApiClient", "getHttpResponse", "Retrying sdk authentication", new Object[0]);
                                com.zendrive.sdk.i.w.a(context).f((String) null);
                                return m(context, str, str2, str3, aVar, zendriveRegion, false);
                            }
                            b1.d("SDKApiClient", "getHttpResponse", "Decryption failed - HTTP_NOT_FOUND", new Object[0]);
                            return new z0(WalletConstants.ERROR_CODE_INVALID_PARAMETERS, null, null);
                        }
                    }
                    if (i19 == 401 && z15) {
                        b1.d("SDKApiClient", "getHttpResponse", "SdkConfig auth unauthorized. Retrying", new Object[0]);
                        com.zendrive.sdk.i.w.a(context).f((String) null);
                        return m(context, str, str2, str3, aVar, zendriveRegion, false);
                    }
                    return c16;
                }
                str7 = null;
                if (str7 != null) {
                }
            }
        } else {
            i15 = 200;
            str4 = sb6;
        }
        str5 = N;
        str6 = str4;
        if (str6 != null) {
        }
        i16 = 0;
        str7 = null;
        if (str7 != null) {
        }
    }

    public static Handler m0() {
        Looper mainLooper;
        if (Looper.myLooper() != null) {
            mainLooper = Looper.myLooper();
        } else {
            mainLooper = Looper.getMainLooper();
        }
        return new Handler(mainLooper);
    }

    public static String o(ZendriveRegion zendriveRegion) {
        int ordinal = zendriveRegion.ordinal();
        if (ordinal != 0) {
            if (ordinal == 1) {
                return "https://sdk-api.eu.zendrive.com";
            }
            throw new IllegalStateException("Unexpected value: " + zendriveRegion);
        }
        return "https://sdk-api.zendrive.com";
    }

    public static String p(com.zendrive.sdk.i.k kVar, long j15) {
        ArrayList<Vehicle> a15 = kVar.a(j15);
        if (!a15.isEmpty()) {
            return a15.get(0).vehicleId;
        }
        return "";
    }

    public static String q(String str, String str2, String str3, String str4, ZendriveRegion zendriveRegion) {
        String str5;
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
            Charset charset = StandardCharsets.UTF_8;
            messageDigest.update(str2.getBytes(charset));
            messageDigest.update(str3.getBytes(charset));
            messageDigest.update(str4.getBytes(charset));
            messageDigest.update(str.getBytes(charset));
            int ordinal = zendriveRegion.ordinal();
            if (ordinal != 0) {
                if (ordinal == 1) {
                    str5 = "eu";
                } else {
                    throw new IllegalStateException("Unexpected value: " + zendriveRegion);
                }
            } else {
                str5 = "";
            }
            messageDigest.update(str5.getBytes(charset));
            return Base64.encodeToString(messageDigest.digest(), 0, 9, 10).replaceAll("=", "-");
        } catch (NoSuchAlgorithmException e15) {
            b1.d("PublicAPIUtility", "computeDriverId", com.zendrive.sdk.i.class.getName() + ":Invalid algorithm for computing digest", e15);
            return null;
        }
    }

    public static HashMap r(Context context) {
        return s(context, com.zendrive.sdk.i.w.a(context).j().f(), j0(context));
    }

    private static HashMap<String, String> s(Context context, String str, String str2) {
        String str3;
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("Authorization", "SDKKEY " + str);
        hashMap.put("X-Build-Number", i0());
        hashMap.put("X-Device-Type", Build.MANUFACTURER + "-" + Build.MODEL);
        hashMap.put("X-Device-Os-Version", Integer.toString(Build.VERSION.SDK_INT));
        hashMap.put("X-Country-Code", W(context));
        hashMap.put("X-App-Bundle-Id", context.getPackageName());
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            String str4 = i.f42903a;
            str3 = packageInfo.versionName + "_" + androidx.core.content.pm.a.a(packageInfo);
        } catch (PackageManager.NameNotFoundException unused) {
            str3 = "";
        }
        hashMap.put("X-App-Version", str3);
        if (str2 != null) {
            hashMap.put("X-User-Id", str2);
        }
        return hashMap;
    }

    public static List<com.zendrive.sdk.data.m> t(com.zendrive.sdk.i.k kVar, long j15, long j16, List<TripTrail> list) {
        ?? arrayList;
        ArrayList arrayList2 = new ArrayList();
        for (TripTrail tripTrail : list) {
            if (tripTrail.isSpeedLimitPoint) {
                arrayList2.add(tripTrail);
            }
        }
        ArrayList<HighFreqGps> b15 = kVar.b(j15, j16, -1, 65);
        if (b15.isEmpty()) {
            b1.d("GPSUtility", "getHighFreqGPSWithEstimatedSpeed", "No GPS points for estimated speed calculation", new Object[0]);
            arrayList = Collections.emptyList();
        } else {
            ArrayList arrayList3 = new ArrayList();
            r0 r0Var = new r0(new v(arrayList3));
            HighFreqGps highFreqGps = b15.get(b15.size() - 1);
            Iterator<HighFreqGps> it = b15.iterator();
            while (it.hasNext()) {
                r0Var.g(it.next());
            }
            r0Var.d(highFreqGps);
            arrayList = new ArrayList();
            for (int i15 = 0; i15 < arrayList3.size(); i15++) {
                n0 n0Var = (n0) arrayList3.get(i15);
                HighFreqGps build2 = new HighFreqGps.Builder(new GPS.Builder(n0Var.f42927e).setEstimatedSpeed(n0Var.f42923a).setSmoothedLatitude(n0Var.f42925c).setSmoothedLongitude(n0Var.f42926d).build2()).build2();
                if (highFreqGps.timestamp != build2.timestamp || !arrayList.contains(build2)) {
                    arrayList.add(build2);
                }
            }
        }
        ArrayList arrayList4 = new ArrayList();
        for (int i16 = 0; i16 < arrayList.size(); i16++) {
            arrayList4.add(Long.valueOf(((HighFreqGps) arrayList.get(i16)).timestamp));
        }
        ArrayList arrayList5 = new ArrayList();
        ArrayList arrayList6 = new ArrayList();
        for (int i17 = 0; i17 < arrayList2.size(); i17++) {
            TripTrail tripTrail2 = (TripTrail) arrayList2.get(i17);
            int binarySearch = Collections.binarySearch(arrayList4, Long.valueOf(tripTrail2.timestamp));
            if (binarySearch <= -1) {
                arrayList6.add(tripTrail2);
            } else {
                HighFreqGps highFreqGps2 = (HighFreqGps) arrayList.get(binarySearch);
                com.zendrive.sdk.data.m mVar = new com.zendrive.sdk.data.m();
                mVar.f40710d = tripTrail2.timestamp;
                mVar.f40711e = highFreqGps2.rawSpeed;
                mVar.f40707a = tripTrail2.latitude;
                mVar.f40708b = tripTrail2.longitude;
                mVar.f40709c = tripTrail2.course;
                arrayList5.add(mVar);
            }
        }
        if (!arrayList6.isEmpty()) {
            StringBuilder sb5 = new StringBuilder(Long.toString(((TripTrail) arrayList6.get(0)).timestamp));
            for (int i18 = 1; i18 < arrayList6.size(); i18++) {
                sb5.append(", ");
                sb5.append(((TripTrail) arrayList6.get(i18)).timestamp);
            }
            String str = "Speed limit marked pts in Trip Trail don't match GPS timestamp: " + ((Object) sb5);
            b1.d("SpeedLimitQueryPointGenerator", "computeSpeedLimitQueryPoints", str, new Object[0]);
            new RuntimeException(str);
        }
        return arrayList5;
    }

    public static JSONObject u(Context context, com.zendrive.sdk.i.w wVar, com.zendrive.sdk.i.k kVar, Trip trip) {
        int i15;
        int i16;
        BluetoothDevice a15;
        long j15 = trip.timestamp;
        long j16 = trip.timestampEnd;
        kVar.getClass();
        ArrayList b15 = kVar.b(ZendriveBluetoothDevice.class, j15, j16, -1);
        JSONObject jSONObject = new JSONObject();
        try {
            Iterator it = b15.iterator();
            while (it.hasNext()) {
                ZendriveBluetoothDevice zendriveBluetoothDevice = (ZendriveBluetoothDevice) it.next();
                N(jSONObject, zendriveBluetoothDevice.deviceId, zendriveBluetoothDevice.connectionTimestamp, zendriveBluetoothDevice.disconnectionTimestamp, zendriveBluetoothDevice.majorClass, zendriveBluetoothDevice.minorClass);
            }
            JSONObject d15 = wVar.d();
            Iterator<String> keys = d15.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                long j17 = d15.getLong(next);
                if (i.f(context) && (a15 = com.zendrive.sdk.i.i.a(context, wVar, next)) != null && a15.getBluetoothClass() != null) {
                    i15 = a15.getBluetoothClass().getDeviceClass();
                    i16 = a15.getBluetoothClass().getMajorDeviceClass();
                } else {
                    i15 = -1;
                    i16 = -1;
                }
                N(jSONObject, next, j17, -1L, i15, i16);
            }
        } catch (JSONException e15) {
            b1.e("TripUtil", "populateBluetoothActiveDurationsInfo", e15, "JsonException in BluetoothDeviceInfo debug data", new Object[0]);
        }
        return jSONObject;
    }

    public static void v(Context context, Trip trip, com.zendrive.sdk.i.k kVar) {
        boolean booleanValue;
        long j15 = trip.timestamp;
        kVar.getClass();
        if (!kVar.b(TripInsight.class, j15, j15, 1).isEmpty()) {
            return;
        }
        ArrayList<Event> a15 = kVar.a(trip.timestamp, trip.timestampEnd, -1, true);
        List<s1> a16 = w5.a(context, com.zendrive.sdk.i.w.a(context.getApplicationContext()).O());
        ArrayList arrayList = new ArrayList();
        for (s1 s1Var : a16) {
            int ordinal = s1Var.f41866b.ordinal();
            if (ordinal != 1) {
                if (ordinal != 2) {
                    if (ordinal != 7) {
                        if (ordinal != 9) {
                            if (ordinal != 12) {
                                switch (ordinal) {
                                    case 17:
                                        if (s1Var.f41865a.equals("sdk_phone_tap_v2")) {
                                            booleanValue = com.zendrive.sdk.i.v0.a(context);
                                            break;
                                        } else {
                                            booleanValue = u0.m(n6.PhoneTap, com.zendrive.sdk.data.g.a(context), context);
                                            break;
                                        }
                                    case 18:
                                        if (((Boolean) ((HashMap) com.zendrive.sdk.i.s0.a(context)).get(ZendriveEventType.HARD_TURN)).booleanValue() && trip.numLeftTurns >= 0 && trip.numRightTurns >= 0) {
                                            if (Boolean.TRUE.equals(s1Var.f41867c)) {
                                                break;
                                            } else {
                                                arrayList.add(s1Var.f41865a);
                                                break;
                                            }
                                        }
                                        break;
                                    case 19:
                                        booleanValue = ((Boolean) ((HashMap) com.zendrive.sdk.i.s0.a(context)).get(ZendriveEventType.STOP_SIGN_VIOLATION)).booleanValue();
                                        break;
                                }
                            } else {
                                booleanValue = ((Boolean) ((HashMap) com.zendrive.sdk.i.s0.a(context)).get(ZendriveEventType.COLLISION)).booleanValue();
                            }
                        } else {
                            booleanValue = ((Boolean) ((HashMap) com.zendrive.sdk.i.s0.a(context)).get(ZendriveEventType.SPEEDING)).booleanValue();
                        }
                    } else {
                        booleanValue = ((Boolean) ((HashMap) com.zendrive.sdk.i.s0.a(context)).get(ZendriveEventType.PHONE_HANDLING)).booleanValue();
                    }
                } else {
                    booleanValue = ((Boolean) ((HashMap) com.zendrive.sdk.i.s0.a(context)).get(ZendriveEventType.HARD_BRAKE)).booleanValue();
                }
            } else {
                booleanValue = ((Boolean) ((HashMap) com.zendrive.sdk.i.s0.a(context)).get(ZendriveEventType.AGGRESSIVE_ACCELERATION)).booleanValue();
            }
            if (booleanValue) {
                if (Boolean.TRUE.equals(s1Var.f41867c)) {
                }
            }
        }
        CEventDataList cEventDataList = new CEventDataList();
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            String str = (String) it.next();
            CEventData cEventData = new CEventData();
            cEventData.d(str);
            CEventList cEventList = new CEventList();
            Iterator<Event> it4 = a15.iterator();
            while (it4.hasNext()) {
                Event next = it4.next();
                if (str.equals(next.eventDetectorId) && !com.zendrive.sdk.manager.f.j(next)) {
                    cEventList.b(new com.zendrive.sdk.cpp.a(next));
                }
            }
            cEventData.c(cEventList);
            cEventDataList.b(cEventData);
            b1.d("ZendriveScorer", "calculateTripScore", "Added " + cEventData.e().size() + " events for detector_id: " + cEventData.b() + " to eventDataList.", new Object[0]);
        }
        CTripInfo cTripInfo = new CTripInfo();
        cTripInfo.e(trip.countryCode);
        cTripInfo.b(trip.distance);
        cTripInfo.c(trip.nonIdleTimeMillis);
        cTripInfo.f((short) trip.numLeftTurns);
        cTripInfo.g((short) trip.numRightTurns);
        cTripInfo.d(u0.e(trip.vehicleType));
        CTripScorer.Config config = new CTripScorer.Config();
        config.b(new CLoggerConfig(com.zendrive.sdk.cdetectorlib.i.LOGLEVEL_INFO, JLoggerSink.instance));
        CTripScore a17 = new CTripScorer(config).a(cTripInfo, cEventDataList);
        TripInsight tripInsight = new TripInsight(a17.j(), u0.h(a17.i()), a17.b(), u0.h(a17.a()), a17.d(), u0.h(a17.c()), a17.h(), u0.h(a17.g()), a17.f(), u0.h(a17.e()), a17.k(), trip.timestamp);
        b1.d("ZendriveScorer", "calculateTripScore", "Created %s", tripInsight.toString());
        kVar.a(tripInsight);
        kVar.a(true);
    }

    public static void w(Context context, com.zendrive.sdk.i.w wVar, Trip trip, com.zendrive.sdk.i.k kVar) {
        Vehicle vehicle;
        ArrayList<Vehicle> a15 = kVar.a(trip.timestamp);
        String str = null;
        if (!a15.isEmpty()) {
            vehicle = a15.get(0);
        } else {
            vehicle = null;
        }
        JSONArray b15 = p0.b(trip, kVar);
        if (vehicle != null) {
            str = vehicle.vehicleId;
        }
        JSONObject jSONObject = new JSONObject();
        if (str != null) {
            try {
                if (str.length() > 0) {
                    jSONObject.put("com.zendrive.sdk.vehicleId", str);
                    String str2 = vehicle.connectedBluetoothStereoVehicleId;
                    String str3 = vehicle.connectedBeaconVehicleId;
                    boolean z15 = vehicle.isTaggedByBluetoothStereo;
                    boolean z16 = vehicle.isTaggedByBeacon;
                    if (str2 != null) {
                        jSONObject.put("bluetoothStereoVehicleId", str2);
                    }
                    if (str3 != null) {
                        jSONObject.put("beaconVehicleId", str3);
                    }
                    jSONObject.put("com.zendrive.sdk.isTaggedByBluetoothStereo", z15);
                    jSONObject.put("com.zendrive.sdk.isTaggedByBeacon", z16);
                }
            } catch (JSONException e15) {
                b1.e("VehicleTaggingUtil", "generateDebugDataValueJsonForVehicleTagging", e15, "JsonException while creating vehicle tagging debug data", new Object[0]);
            }
        }
        if (b15.length() > 0) {
            jSONObject.put("scannedBeaconsList", b15);
        }
        if (jSONObject.length() > 0) {
            H(wVar, trip.timestamp, trip.timestampEnd, "VehicleTaggingData", "VehicleTagInfo", jSONObject.toString(), context);
        }
    }

    public static void x(Context context, com.zendrive.sdk.i.w wVar, Trip trip, JSONObject jSONObject) {
        if (jSONObject.length() != 0) {
            H(wVar, trip.timestamp, trip.timestampEnd, "BluetoothData", "BluetoothActiveDurationsInfo", jSONObject.toString(), context);
        }
    }

    public static void y(Context context, Runnable runnable, long j15, Handler handler) {
        int hashCode;
        if (f42918a == null) {
            f42918a = context.getApplicationContext();
        }
        String k05 = k0();
        Message obtain = Message.obtain(handler, runnable);
        if (k05 == null) {
            hashCode = 0;
        } else {
            hashCode = k05.hashCode();
        }
        obtain.arg1 = hashCode;
        handler.sendMessageDelayed(obtain, j15);
    }

    public static void z(Context context, String str) {
        File fileStreamPath = context.getFileStreamPath(str);
        if (fileStreamPath != null && fileStreamPath.exists()) {
            File file = new File(f0(context), str);
            try {
                FileInputStream fileInputStream = new FileInputStream(fileStreamPath);
                try {
                    L(file, X(fileInputStream).getBytes(StandardCharsets.UTF_8), false);
                    if (!fileStreamPath.delete()) {
                        new RuntimeException("Unable to delete current file");
                    }
                    fileInputStream.close();
                } catch (Throwable th4) {
                    try {
                        throw th4;
                    } finally {
                    }
                }
            } catch (IOException unused) {
                new RuntimeException("Cannot read current file");
            }
        }
    }
}