package p3;

import I0.C0290e0;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.SparseArray;
import com.google.firebase.encoders.DataEncoder;
import com.google.firebase.encoders.json.JsonDataEncoderBuilder;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.TimeZone;
import m3.AbstractC2478m;
import q3.C2859l;
import q3.I;
import q3.J;
import r3.i;
import s3.InterfaceC2915g;
import u4.c;

/* JADX INFO: loaded from: classes.dex */
public final class b implements InterfaceC2915g {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ConnectivityManager f22975b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Context f22976c;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final c f22978e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final c f22979f;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final DataEncoder f22974a = new JsonDataEncoderBuilder().configureWith(C2859l.f23681a).ignoreNullValues(true).build();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final URL f22977d = b(C2721a.f22968c);

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f22980g = 130000;

    public b(Context context, c cVar, c cVar2) {
        this.f22976c = context;
        this.f22975b = (ConnectivityManager) context.getSystemService("connectivity");
        this.f22978e = cVar2;
        this.f22979f = cVar;
    }

    public static URL b(String str) {
        try {
            return new URL(str);
        } catch (MalformedURLException e6) {
            throw new IllegalArgumentException(A0.a.n("Invalid url: ", str), e6);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:23:0x00af  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x010f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final i a(i iVar) {
        int type;
        int subtype;
        HashMap map;
        NetworkInfo activeNetworkInfo = this.f22975b.getActiveNetworkInfo();
        C0290e0 c0290e0C = iVar.c();
        int i6 = Build.VERSION.SDK_INT;
        HashMap map2 = (HashMap) c0290e0C.f2365g;
        if (map2 == null) {
            throw new IllegalStateException("Property \"autoMetadata\" has not been set");
        }
        map2.put("sdk-version", String.valueOf(i6));
        c0290e0C.b("model", Build.MODEL);
        c0290e0C.b("hardware", Build.HARDWARE);
        c0290e0C.b("device", Build.DEVICE);
        c0290e0C.b("product", Build.PRODUCT);
        c0290e0C.b("os-uild", Build.ID);
        c0290e0C.b("manufacturer", Build.MANUFACTURER);
        c0290e0C.b("fingerprint", Build.FINGERPRINT);
        Calendar.getInstance();
        long offset = TimeZone.getDefault().getOffset(Calendar.getInstance().getTimeInMillis()) / 1000;
        HashMap map3 = (HashMap) c0290e0C.f2365g;
        if (map3 == null) {
            throw new IllegalStateException("Property \"autoMetadata\" has not been set");
        }
        map3.put("tz-offset", String.valueOf(offset));
        int i7 = -1;
        if (activeNetworkInfo == null) {
            SparseArray sparseArray = J.f23629a;
            type = -1;
        } else {
            type = activeNetworkInfo.getType();
        }
        HashMap map4 = (HashMap) c0290e0C.f2365g;
        if (map4 == null) {
            throw new IllegalStateException("Property \"autoMetadata\" has not been set");
        }
        map4.put("net-type", String.valueOf(type));
        if (activeNetworkInfo != null) {
            subtype = activeNetworkInfo.getSubtype();
            if (subtype == -1) {
                SparseArray sparseArray2 = I.f23627a;
                subtype = 100;
            } else if (((I) I.f23627a.get(subtype)) == null) {
            }
            map = (HashMap) c0290e0C.f2365g;
            if (map != null) {
                throw new IllegalStateException("Property \"autoMetadata\" has not been set");
            }
            map.put("mobile-subtype", String.valueOf(subtype));
            c0290e0C.b("country", Locale.getDefault().getCountry());
            c0290e0C.b("locale", Locale.getDefault().getLanguage());
            Context context = this.f22976c;
            String simOperator = ((TelephonyManager) context.getSystemService("phone")).getSimOperator();
            if (simOperator == null) {
                simOperator = "";
            }
            c0290e0C.b("mcc_mnc", simOperator);
            try {
                i7 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
            } catch (PackageManager.NameNotFoundException e6) {
                AbstractC2478m.i(e6, "CctTransportBackend", "Unable to find version code for package");
            }
            c0290e0C.b("application_build", Integer.toString(i7));
            return c0290e0C.c();
        }
        SparseArray sparseArray3 = I.f23627a;
        subtype = 0;
        map = (HashMap) c0290e0C.f2365g;
        if (map != null) {
        }
    }
}
