package o;

import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.firebase.messaging.FirebaseMessaging;
import ir.devixor.app.service.ForegroundService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final /* synthetic */ class G1 implements InterfaceC2677v1, InterfaceC0320Mj, InterfaceC0250Jq, InterfaceC0246Jm, InterfaceC2439sb0, ST, InterfaceC0823bc0, HT, Gb0 {
    public final /* synthetic */ int l;
    public final /* synthetic */ Object m;

    public /* synthetic */ G1(int i, Object obj) {
        this.l = i;
        this.m = obj;
    }

    @Override // o.InterfaceC0250Jq
    public void a(DZ dz) {
        C0506Tn c0506Tn = (C0506Tn) this.m;
        c0506Tn.getClass();
        Log.isLoggable("FirebaseCrashlytics", 3);
        c0506Tn.b.set((C0506Tn) dz.get());
    }

    @Override // o.Gb0
    public Hb0 b(Fb0 fb0) {
        Context context = (Context) this.m;
        String str = fb0.b;
        C0692a8 c0692a8 = fb0.c;
        if (str == null || str.length() == 0) {
            throw new IllegalArgumentException("Must set a non-null database name to a configuration that uses the no backup directory.");
        }
        return new JC(context, str, c0692a8, true, true);
    }

    @Override // o.InterfaceC2677v1
    public void c(Object obj) {
        ((OC) ((InterfaceC1191fR) this.m).getValue()).g(obj);
    }

    @Override // o.InterfaceC0823bc0
    public Object d() {
        SQLiteDatabase sQLiteDatabaseB;
        int i = this.l;
        Object obj = this.m;
        switch (i) {
            case 14:
                L30 l30 = (L30) ((InterfaceC1025di) obj);
                l30.getClass();
                int i2 = C1312gi.e;
                S60 s60 = new S60(2);
                s60.n = null;
                s60.f325o = new ArrayList();
                s60.p = null;
                s60.m = "";
                HashMap map = new HashMap();
                sQLiteDatabaseB = l30.b();
                sQLiteDatabaseB.beginTransaction();
                try {
                    C1312gi c1312gi = (C1312gi) L30.m(sQLiteDatabaseB.rawQuery("SELECT log_source, reason, events_dropped_count FROM log_event_dropped", new String[0]), new C3034yo(l30, map, s60, 5));
                    sQLiteDatabaseB.setTransactionSuccessful();
                    return c1312gi;
                } finally {
                }
            case 15:
                L30 l302 = (L30) ((InterfaceC0463Rw) obj);
                long jU = l302.m.u() - l302.f204o.d;
                sQLiteDatabaseB = l302.b();
                sQLiteDatabaseB.beginTransaction();
                try {
                    String[] strArr = {String.valueOf(jU)};
                    Cursor cursorRawQuery = sQLiteDatabaseB.rawQuery("SELECT COUNT(*), transport_name FROM events WHERE timestamp_ms < ? GROUP BY transport_name", strArr);
                    while (cursorRawQuery.moveToNext()) {
                        try {
                            l302.g(cursorRawQuery.getInt(0), GM.n, cursorRawQuery.getString(1));
                        } catch (Throwable th) {
                            cursorRawQuery.close();
                            throw th;
                        }
                    }
                    cursorRawQuery.close();
                    int iDelete = sQLiteDatabaseB.delete("events", "timestamp_ms < ?", strArr);
                    sQLiteDatabaseB.setTransactionSuccessful();
                    sQLiteDatabaseB.endTransaction();
                    return Integer.valueOf(iDelete);
                } finally {
                }
            case 16:
                L30 l303 = (L30) ((InterfaceC1025di) ((C0598Xb) obj).i);
                sQLiteDatabaseB = l303.b();
                sQLiteDatabaseB.beginTransaction();
                try {
                    sQLiteDatabaseB.compileStatement("DELETE FROM log_event_dropped").execute();
                    sQLiteDatabaseB.compileStatement("UPDATE global_log_event_state SET last_metrics_upload_ms=" + l303.m.u()).execute();
                    sQLiteDatabaseB.setTransactionSuccessful();
                    return null;
                } finally {
                }
            default:
                C2062oc0 c2062oc0 = (C2062oc0) obj;
                Iterator it = ((Iterable) ((L30) ((InterfaceC0463Rw) c2062oc0.b)).d(new C0387Oy(11))).iterator();
                while (it.hasNext()) {
                    ((C3126zm0) c2062oc0.c).O((C2156pc) it.next(), 1, false);
                }
                return null;
        }
    }

    @Override // o.ST
    public void e(Object obj) {
        C1072e7 c1072e7 = (C1072e7) this.m;
        boolean z = ForegroundService.w;
        c1072e7.g(obj);
    }

    public C0343Ng f(C3126zm0 c3126zm0) throws IOException {
        C0369Og c0369Og = (C0369Og) this.m;
        URL url = (URL) c3126zm0.m;
        if (Log.isLoggable(IJ.u("CctTransportBackend"), 4)) {
            String.format("Making request to: %s", url);
        }
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        httpURLConnection.setConnectTimeout(30000);
        httpURLConnection.setReadTimeout(c0369Og.g);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setInstanceFollowRedirects(false);
        httpURLConnection.setRequestMethod("POST");
        httpURLConnection.setRequestProperty("User-Agent", "datatransport/3.3.0 android/");
        httpURLConnection.setRequestProperty("Content-Encoding", "gzip");
        httpURLConnection.setRequestProperty("Content-Type", "application/json");
        httpURLConnection.setRequestProperty("Accept-Encoding", "gzip");
        String str = (String) c3126zm0.f831o;
        if (str != null) {
            httpURLConnection.setRequestProperty("X-Goog-Api-Key", str);
        }
        try {
            OutputStream outputStream = httpURLConnection.getOutputStream();
            try {
                GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(outputStream);
                try {
                    C0247Jn c0247Jn = c0369Og.a;
                    C0571Wa c0571Wa = (C0571Wa) c3126zm0.n;
                    BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(gZIPOutputStream));
                    C2040oJ c2040oJ = (C2040oJ) c0247Jn.m;
                    C2514tJ c2514tJ = new C2514tJ(bufferedWriter, c2040oJ.a, c2040oJ.b, c2040oJ.c, c2040oJ.d);
                    c2514tJ.h(c0571Wa);
                    c2514tJ.j();
                    c2514tJ.b.flush();
                    gZIPOutputStream.close();
                    if (outputStream != null) {
                        outputStream.close();
                    }
                    int responseCode = httpURLConnection.getResponseCode();
                    Integer numValueOf = Integer.valueOf(responseCode);
                    if (Log.isLoggable(IJ.u("CctTransportBackend"), 4)) {
                        String.format("Status Code: %d", numValueOf);
                    }
                    IJ.j("CctTransportBackend", "Content-Type: %s", httpURLConnection.getHeaderField("Content-Type"));
                    IJ.j("CctTransportBackend", "Content-Encoding: %s", httpURLConnection.getHeaderField("Content-Encoding"));
                    if (responseCode == 302 || responseCode == 301 || responseCode == 307) {
                        return new C0343Ng(responseCode, new URL(httpURLConnection.getHeaderField("Location")), 0L);
                    }
                    if (responseCode != 200) {
                        return new C0343Ng(responseCode, null, 0L);
                    }
                    InputStream inputStream = httpURLConnection.getInputStream();
                    try {
                        InputStream gZIPInputStream = "gzip".equals(httpURLConnection.getHeaderField("Content-Encoding")) ? new GZIPInputStream(inputStream) : inputStream;
                        try {
                            C0343Ng c0343Ng = new C0343Ng(responseCode, null, C0726ac.a(new BufferedReader(new InputStreamReader(gZIPInputStream))).a);
                            if (gZIPInputStream != null) {
                                gZIPInputStream.close();
                            }
                            if (inputStream != null) {
                                inputStream.close();
                            }
                            return c0343Ng;
                        } finally {
                        }
                    } finally {
                    }
                } finally {
                }
            } finally {
            }
        } catch (ConnectException | UnknownHostException unused) {
            Log.isLoggable(IJ.u("CctTransportBackend"), 6);
            return new C0343Ng(500, null, 0L);
        } catch (IOException | C0644Yv unused2) {
            Log.isLoggable(IJ.u("CctTransportBackend"), 6);
            return new C0343Ng(400, null, 0L);
        }
    }

    /* JADX WARN: Type inference failed for: r2v0, types: [java.lang.Iterable, java.lang.Object] */
    public void g() {
        SC sc = (SC) this.m;
        synchronized (AbstractC2884x90.c) {
            ?? r2 = AbstractC2884x90.h;
            ArrayList arrayList = new ArrayList(AbstractC0034Bi.W(r2, 10));
            boolean z = false;
            for (Object obj : r2) {
                boolean z2 = true;
                if (!z && F3.c(obj, sc)) {
                    z = true;
                    z2 = false;
                }
                if (z2) {
                    arrayList.add(obj);
                }
            }
            AbstractC2884x90.h = arrayList;
        }
    }

    public boolean h(C0247Jn c0247Jn, int i, Bundle bundle) {
        InterfaceC1986nm od;
        X7 x7 = (X7) this.m;
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 25 && (i & 1) != 0) {
            try {
                ((AH) c0247Jn.m).d();
                Parcelable parcelable = (Parcelable) ((AH) c0247Jn.m).b();
                bundle = bundle == null ? new Bundle() : new Bundle(bundle);
                bundle.putParcelable("androidx.core.view.extra.INPUT_CONTENT_INFO", parcelable);
            } catch (Exception unused) {
                return false;
            }
        }
        AH ah = (AH) c0247Jn.m;
        ClipData clipData = new ClipData(ah.a(), new ClipData.Item(ah.c()));
        if (i2 >= 31) {
            od = new OD(clipData, 2);
        } else {
            C2081om c2081om = new C2081om();
            c2081om.m = clipData;
            c2081om.n = 2;
            od = c2081om;
        }
        od.o(ah.e());
        od.setExtras(bundle);
        return Oj0.i(x7, od.build()) == null;
    }

    /* JADX WARN: Removed duplicated region for block: B:113:0x0505  */
    /* JADX WARN: Removed duplicated region for block: B:93:0x03ca  */
    /* JADX WARN: Removed duplicated region for block: B:96:0x03d0  */
    /* JADX WARN: Removed duplicated region for block: B:97:0x03d7  */
    @Override // o.InterfaceC0320Mj
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public java.lang.Object i(o.U7 r54) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, android.content.res.Resources.NotFoundException, android.content.pm.PackageManager.NameNotFoundException, java.util.concurrent.TimeoutException {
        /*
            Method dump skipped, instructions count: 1392
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.G1.i(o.U7):java.lang.Object");
    }

    @Override // o.HT
    public void onComplete(Pc0 pc0) {
        switch (this.l) {
            case ConnectionResult.SERVICE_UPDATING /* 18 */:
                Lk0.b((Intent) this.m);
                break;
            case 19:
                ((C1417hm0) this.m).b.d(null);
                break;
            default:
                ((ScheduledFuture) this.m).cancel(false);
                break;
        }
    }

    @Override // o.InterfaceC0246Jm
    public Object then(Pc0 pc0) {
        boolean z;
        switch (this.l) {
            case 5:
                return (Pc0) ((CallableC0273Kn) this.m).call();
            case 6:
                ((Runnable) this.m).run();
                return AbstractC0752ap.K(null);
            case 12:
                ((U7) this.m).getClass();
                if (pc0.h()) {
                    C0820bb c0820bb = (C0820bb) pc0.f();
                    String str = c0820bb.b;
                    Log.isLoggable("FirebaseCrashlytics", 3);
                    File file = c0820bb.c;
                    z = true;
                    if (file.delete()) {
                        file.getPath();
                        Log.isLoggable("FirebaseCrashlytics", 3);
                    } else {
                        file.getPath();
                    }
                } else {
                    pc0.e();
                    z = false;
                }
                return Boolean.valueOf(z);
            default:
                ((CountDownLatch) this.m).countDown();
                return null;
        }
    }

    @Override // o.InterfaceC2439sb0
    public Pc0 then(Object obj) {
        ArrayDeque arrayDeque;
        boolean z;
        String str = (String) this.m;
        C1022dg0 c1022dg0 = (C1022dg0) obj;
        WT wt = FirebaseMessaging.l;
        c1022dg0.getClass();
        C0735ag0 c0735ag0 = new C0735ag0("S", str);
        C0831bg0 c0831bg0 = c1022dg0.h;
        synchronized (c0831bg0) {
            Q1 q1 = c0831bg0.a;
            String str2 = c0735ag0.c;
            q1.getClass();
            if (!TextUtils.isEmpty(str2) && !str2.contains((String) q1.n)) {
                synchronized (((ArrayDeque) q1.p)) {
                    if (((ArrayDeque) q1.p).add(str2)) {
                        ((ScheduledThreadPoolExecutor) q1.q).execute(new RunnableC2108p1(19, q1));
                    }
                }
            }
        }
        Qc0 qc0 = new Qc0();
        synchronized (c1022dg0.e) {
            try {
                String str3 = c0735ag0.c;
                if (c1022dg0.e.containsKey(str3)) {
                    arrayDeque = (ArrayDeque) c1022dg0.e.get(str3);
                } else {
                    ArrayDeque arrayDeque2 = new ArrayDeque();
                    c1022dg0.e.put(str3, arrayDeque2);
                    arrayDeque = arrayDeque2;
                }
                arrayDeque.add(qc0);
            } catch (Throwable th) {
                throw th;
            }
        }
        Hw0 hw0 = qc0.a;
        if (c1022dg0.h.a() != null) {
            synchronized (c1022dg0) {
                z = c1022dg0.g;
            }
            if (!z) {
                c1022dg0.f(0L);
                return hw0;
            }
        }
        return hw0;
    }
}
