package N2;

import L1.RunnableC0090d0;
import P.C0160d;
import P.InterfaceC0159c;
import P.Q;
import a1.C0222i;
import android.content.ClipData;
import android.content.ClipDescription;
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.util.Log;
import android.view.View;
import com.google.android.gms.internal.measurement.A1;
import com.google.android.gms.internal.measurement.AbstractC0366e2;
import com.google.firebase.messaging.G;
import com.google.firebase.messaging.I;
import com.google.firebase.messaging.w;
import d1.C0539a;
import i1.InterfaceC0622b;
import io.flutter.Build;
import io.flutter.embedding.android.AndroidTouchProcessor;
import io.flutter.plugin.editing.FlutterTextUtils;
import io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin;
import io.flutter.plugins.firebase.core.GeneratedAndroidFirebaseCore;
import io.flutter.util.ViewUtils;
import io.sentry.C1;
import io.sentry.EnumC0738m1;
import io.sentry.InterfaceC0771v1;
import io.sentry.L0;
import io.sentry.M0;
import io.sentry.N0;
import io.sentry.O1;
import io.sentry.P;
import io.sentry.Q1;
import io.sentry.S1;
import io.sentry.android.core.O;
import io.sentry.android.core.SentryAndroidOptions;
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.io.RandomAccessFile;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import m.AbstractC0882t;
import r4.AbstractC0983h;
import s1.z;

/* JADX INFO: loaded from: classes.dex */
public final /* synthetic */ class a implements f, P1.e, ViewUtils.ViewVisitor, P1.a, P1.c, InterfaceC0622b, N0, io.sentry.util.b, InterfaceC0771v1, L0 {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ int f2180k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final /* synthetic */ Object f2181l;

    public /* synthetic */ a(int i, Object obj) {
        this.f2180k = i;
        this.f2181l = obj;
    }

    @Override // i1.InterfaceC0622b
    public Object a() {
        SQLiteDatabase sQLiteDatabaseA;
        Object obj = this.f2181l;
        switch (this.f2180k) {
            case 11:
                h1.h hVar = (h1.h) ((h1.c) obj);
                hVar.getClass();
                int i = C0539a.f6031e;
                w wVar = new w();
                wVar.f5944l = null;
                wVar.f5945m = new ArrayList();
                wVar.f5946n = null;
                wVar.f5943k = "";
                HashMap map = new HashMap();
                sQLiteDatabaseA = hVar.a();
                sQLiteDatabaseA.beginTransaction();
                try {
                    C0539a c0539a = (C0539a) h1.h.n(sQLiteDatabaseA.rawQuery("SELECT log_source, reason, events_dropped_count FROM log_event_dropped", new String[0]), new com.google.firebase.messaging.p(hVar, map, wVar, 4));
                    sQLiteDatabaseA.setTransactionSuccessful();
                    return c0539a;
                } finally {
                }
            case 12:
                h1.h hVar2 = (h1.h) ((h1.d) obj);
                long jB = hVar2.f6508l.b() - hVar2.f6510n.f6498d;
                sQLiteDatabaseA = hVar2.a();
                sQLiteDatabaseA.beginTransaction();
                try {
                    String[] strArr = {String.valueOf(jB)};
                    Cursor cursorRawQuery = sQLiteDatabaseA.rawQuery("SELECT COUNT(*), transport_name FROM events WHERE timestamp_ms < ? GROUP BY transport_name", strArr);
                    while (cursorRawQuery.moveToNext()) {
                        try {
                            hVar2.k(cursorRawQuery.getInt(0), d1.c.MESSAGE_TOO_OLD, cursorRawQuery.getString(1));
                        } catch (Throwable th) {
                            cursorRawQuery.close();
                            throw th;
                        }
                    }
                    cursorRawQuery.close();
                    int iDelete = sQLiteDatabaseA.delete("events", "timestamp_ms < ?", strArr);
                    sQLiteDatabaseA.setTransactionSuccessful();
                    sQLiteDatabaseA.endTransaction();
                    return Integer.valueOf(iDelete);
                } finally {
                }
            case FlutterTextUtils.CARRIAGE_RETURN /* 13 */:
                h1.h hVar3 = (h1.h) ((g1.j) obj).i;
                sQLiteDatabaseA = hVar3.a();
                sQLiteDatabaseA.beginTransaction();
                try {
                    sQLiteDatabaseA.compileStatement("DELETE FROM log_event_dropped").execute();
                    sQLiteDatabaseA.compileStatement("UPDATE global_log_event_state SET last_metrics_upload_ms=" + hVar3.f6508l.b()).execute();
                    sQLiteDatabaseA.setTransactionSuccessful();
                    return null;
                } finally {
                }
            default:
                g1.k kVar = (g1.k) obj;
                Iterator it = ((Iterable) ((h1.h) kVar.f6454b).f(new B2.c(27))).iterator();
                while (it.hasNext()) {
                    kVar.f6455c.a((C0222i) it.next(), 1, false);
                }
                return null;
        }
    }

    @Override // io.sentry.L0
    public void b(B2.a aVar) {
        B2.a aVar2 = new B2.a(20);
        M0 m02 = (M0) this.f2181l;
        m02.q = aVar2;
        Q1 q12 = new Q1((io.sentry.protocol.t) aVar2.f135m, (S1) aVar2.f136n, "default", null, null);
        q12.f7014s = "auto";
        Iterator<P> it = m02.f6955j.getScopeObservers().iterator();
        while (it.hasNext()) {
            it.next().l(q12, m02);
        }
    }

    @Override // P1.e
    public void c(Object obj) {
        ((O0.a) this.f2181l).invoke(obj);
    }

    @Override // io.sentry.N0
    public void d(M0 m02) {
        O1 o12;
        switch (this.f2180k) {
            case 17:
                m02.getClass();
                ((AtomicReference) this.f2181l).set(new M0(m02));
                return;
            case 18:
                O o5 = (O) this.f2181l;
                if (o5.f7185k.get() != 0 || (o12 = m02.f6956k) == null) {
                    return;
                }
                Date date = o12.f6977k;
                if ((date == null ? null : (Date) date.clone()) != null) {
                    AtomicLong atomicLong = o5.f7185k;
                    Date date2 = o12.f6977k;
                    atomicLong.set((date2 != null ? (Date) date2.clone() : null).getTime());
                    return;
                }
                return;
            case 19:
                AtomicBoolean atomicBoolean = (AtomicBoolean) this.f2181l;
                O1 o13 = m02.f6956k;
                if (o13 != null) {
                    Date date3 = o13.f6977k;
                    if ((date3 == null ? null : (Date) date3.clone()) != null) {
                        atomicBoolean.set(true);
                        return;
                    }
                    return;
                }
                return;
            case 20:
                io.sentry.android.core.internal.gestures.f fVar = (io.sentry.android.core.internal.gestures.f) this.f2181l;
                fVar.getClass();
                synchronized (m02.f6958m) {
                    if (m02.f6947a == fVar.f7311e) {
                        m02.b();
                    }
                    break;
                }
                return;
            case Build.API_LEVELS.API_21 /* 21 */:
                io.sentry.android.replay.capture.f fVar2 = (io.sentry.android.replay.capture.f) this.f2181l;
                AbstractC0983h.e("this$0", fVar2);
                AbstractC0983h.e("it", m02);
                m02.c(fVar2.i());
                return;
            default:
                io.sentry.android.replay.capture.o oVar = (io.sentry.android.replay.capture.o) this.f2181l;
                AbstractC0983h.e("this$0", oVar);
                AbstractC0983h.e("it", m02);
                m02.c(oVar.i());
                String str = m02.f6949c;
                String strA0 = str != null ? A4.i.a0(str, str) : null;
                y4.d dVar = io.sentry.android.replay.capture.c.q[2];
                io.sentry.android.replay.capture.b bVar = oVar.f7538l;
                bVar.getClass();
                AbstractC0983h.e("property", dVar);
                Object andSet = bVar.f7525b.getAndSet(strA0);
                if (AbstractC0983h.a(andSet, strA0)) {
                    return;
                }
                K4.d dVar2 = new K4.d(andSet, strA0, bVar.f7527d);
                io.sentry.android.replay.capture.c cVar = bVar.f7526c;
                boolean zA = cVar.f7528a.getMainThreadChecker().a();
                C1 c12 = cVar.f7528a;
                if (zA) {
                    AbstractC0366e2.y(io.sentry.android.replay.capture.c.g(cVar), c12, "CaptureStrategy.runInBackground", new RunnableC0090d0(18, dVar2));
                    return;
                }
                try {
                    dVar2.invoke();
                    return;
                } catch (Throwable th) {
                    c12.getLogger().p(EnumC0738m1.ERROR, "Failed to execute task CaptureStrategy.runInBackground", th);
                    return;
                }
        }
    }

    @Override // P1.c
    public void e(P1.h hVar) {
        switch (this.f2180k) {
            case 7:
                G.b((Intent) this.f2181l);
                break;
            case 8:
                ((I) this.f2181l).f5862b.d(null);
                break;
            case AndroidTouchProcessor.PointerChange.PAN_ZOOM_END /* 9 */:
                ((ScheduledFuture) this.f2181l).cancel(false);
                break;
            case 15:
                FlutterFirebaseCorePlugin.lambda$listenToVoidResponse$2((GeneratedAndroidFirebaseCore.VoidResult) this.f2181l, hVar);
                break;
            default:
                FlutterFirebaseCorePlugin.lambda$listenToResponse$1((GeneratedAndroidFirebaseCore.Result) this.f2181l, hVar);
                break;
        }
    }

    @Override // P1.a
    public Object f(P1.h hVar) throws IOException {
        Object obj;
        ((A2.p) this.f2181l).getClass();
        P1.o oVar = (P1.o) hVar;
        synchronized (oVar.f2517a) {
            z.i("Task is not yet complete", oVar.f2519c);
            if (oVar.f2520d) {
                throw new CancellationException("Task is already canceled.");
            }
            if (IOException.class.isInstance(oVar.f2522f)) {
                throw ((Throwable) IOException.class.cast(oVar.f2522f));
            }
            Exception exc = oVar.f2522f;
            if (exc != null) {
                throw new P1.f(exc);
            }
            obj = oVar.f2521e;
        }
        Bundle bundle = (Bundle) obj;
        if (bundle == null) {
            throw new IOException("SERVICE_NOT_AVAILABLE");
        }
        String string = bundle.getString("registration_id");
        if (string != null) {
            return string;
        }
        String string2 = bundle.getString("unregistered");
        if (string2 != null) {
            return string2;
        }
        String string3 = bundle.getString("error");
        if ("RST".equals(string3)) {
            throw new IOException("INSTANCE_ID_RESET");
        }
        if (string3 != null) {
            throw new IOException(string3);
        }
        Log.w("FirebaseMessaging", "Unexpected response: " + bundle, new Throwable());
        throw new IOException("SERVICE_NOT_AVAILABLE");
    }

    @Override // N2.f
    public Object g(A2.p pVar) {
        return this.f2181l;
    }

    @Override // io.sentry.util.b
    public Object h() {
        io.sentry.cache.tape.i iVar;
        int maxBreadcrumbs;
        RandomAccessFile randomAccessFileA;
        switch (this.f2180k) {
            case Build.API_LEVELS.API_23 /* 23 */:
                return ((io.sentry.cache.c) this.f2181l).f7692k.getSerializer();
            default:
                io.sentry.cache.g gVar = (io.sentry.cache.g) this.f2181l;
                SentryAndroidOptions sentryAndroidOptions = gVar.f7702a;
                File fileB = io.sentry.cache.a.b(sentryAndroidOptions, ".scope-cache");
                if (fileB == null) {
                    sentryAndroidOptions.getLogger().j(EnumC0738m1.INFO, "Cache dir is not set, cannot store in scope cache", new Object[0]);
                    return new io.sentry.cache.tape.b();
                }
                File file = new File(fileB, "breadcrumbs.json");
                try {
                    try {
                        maxBreadcrumbs = sentryAndroidOptions.getMaxBreadcrumbs();
                        randomAccessFileA = io.sentry.cache.tape.i.a(file);
                    } catch (IOException e2) {
                        sentryAndroidOptions.getLogger().p(EnumC0738m1.ERROR, "Failed to create breadcrumbs queue", e2);
                        return new io.sentry.cache.tape.b();
                    }
                } catch (IOException unused) {
                    file.delete();
                    try {
                        iVar = new io.sentry.cache.tape.i(file, io.sentry.cache.tape.i.a(file), sentryAndroidOptions.getMaxBreadcrumbs());
                    } catch (Throwable th) {
                        throw th;
                    }
                    break;
                }
                try {
                    iVar = new io.sentry.cache.tape.i(file, randomAccessFileA, maxBreadcrumbs);
                    return new io.sentry.cache.tape.e(iVar, new S.g(gVar));
                } finally {
                    randomAccessFileA.close();
                }
        }
    }

    public Y0.b i(B2.a aVar) throws IOException {
        Y0.c cVar = (Y0.c) this.f2181l;
        String strN = A1.n("CctTransportBackend");
        boolean zIsLoggable = Log.isLoggable(strN, 4);
        URL url = (URL) aVar.f135m;
        if (zIsLoggable) {
            Log.i(strN, String.format("Making request to: %s", url));
        }
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        httpURLConnection.setConnectTimeout(30000);
        httpURLConnection.setReadTimeout(cVar.f3387g);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setInstanceFollowRedirects(false);
        httpURLConnection.setRequestMethod("POST");
        httpURLConnection.setRequestProperty("User-Agent", "datatransport/3.1.9 android/");
        httpURLConnection.setRequestProperty("Content-Encoding", "gzip");
        httpURLConnection.setRequestProperty("Content-Type", "application/json");
        httpURLConnection.setRequestProperty("Accept-Encoding", "gzip");
        String str = (String) aVar.f134l;
        if (str != null) {
            httpURLConnection.setRequestProperty("X-Goog-Api-Key", str);
        }
        try {
            OutputStream outputStream = httpURLConnection.getOutputStream();
            try {
                GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(outputStream);
                try {
                    S.g gVar = cVar.f3381a;
                    Z0.i iVar = (Z0.i) aVar.f136n;
                    BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(gZIPOutputStream));
                    U2.d dVar = (U2.d) gVar.f2797k;
                    U2.e eVar = new U2.e(bufferedWriter, dVar.f2913a, dVar.f2914b, dVar.f2915c, dVar.f2916d);
                    eVar.f(iVar);
                    eVar.h();
                    eVar.f2918b.flush();
                    gZIPOutputStream.close();
                    if (outputStream != null) {
                        outputStream.close();
                    }
                    int responseCode = httpURLConnection.getResponseCode();
                    Integer numValueOf = Integer.valueOf(responseCode);
                    String strN2 = A1.n("CctTransportBackend");
                    if (Log.isLoggable(strN2, 4)) {
                        Log.i(strN2, String.format("Status Code: %d", numValueOf));
                    }
                    A1.e("CctTransportBackend", "Content-Type: %s", httpURLConnection.getHeaderField("Content-Type"));
                    A1.e("CctTransportBackend", "Content-Encoding: %s", httpURLConnection.getHeaderField("Content-Encoding"));
                    if (responseCode == 302 || responseCode == 301 || responseCode == 307) {
                        return new Y0.b(responseCode, new URL(httpURLConnection.getHeaderField("Location")), 0L);
                    }
                    if (responseCode != 200) {
                        return new Y0.b(responseCode, null, 0L);
                    }
                    InputStream inputStream = httpURLConnection.getInputStream();
                    try {
                        InputStream gZIPInputStream = "gzip".equals(httpURLConnection.getHeaderField("Content-Encoding")) ? new GZIPInputStream(inputStream) : inputStream;
                        try {
                            Y0.b bVar = new Y0.b(responseCode, null, Z0.m.a(new BufferedReader(new InputStreamReader(gZIPInputStream))).f3527a);
                            if (gZIPInputStream != null) {
                                gZIPInputStream.close();
                            }
                            if (inputStream != null) {
                                inputStream.close();
                            }
                            return bVar;
                        } finally {
                        }
                    } finally {
                    }
                } finally {
                }
            } finally {
            }
        } catch (S2.b e2) {
            e = e2;
            A1.h("CctTransportBackend", "Couldn't encode request, returning with 400", e);
            return new Y0.b(400, null, 0L);
        } catch (ConnectException e6) {
            e = e6;
            A1.h("CctTransportBackend", "Couldn't open connection, returning with 500", e);
            return new Y0.b(500, null, 0L);
        } catch (UnknownHostException e7) {
            e = e7;
            A1.h("CctTransportBackend", "Couldn't open connection, returning with 500", e);
            return new Y0.b(500, null, 0L);
        } catch (IOException e8) {
            e = e8;
            A1.h("CctTransportBackend", "Couldn't encode request, returning with 400", e);
            return new Y0.b(400, null, 0L);
        }
    }

    public boolean j(g3.c cVar, int i, Bundle bundle) {
        InterfaceC0159c cVar2;
        int i5 = Build.VERSION.SDK_INT;
        if (i5 >= 25 && (i & 1) != 0) {
            try {
                ((R.h) cVar.f6465l).f();
                Parcelable parcelable = (Parcelable) ((R.h) cVar.f6465l).c();
                bundle = bundle == null ? new Bundle() : new Bundle(bundle);
                bundle.putParcelable("androidx.core.view.extra.INPUT_CONTENT_INFO", parcelable);
            } catch (Exception e2) {
                Log.w("InputConnectionCompat", "Can't insert content from IME; requestPermission() failed", e2);
                return false;
            }
        }
        ClipDescription description = ((R.h) cVar.f6465l).getDescription();
        R.h hVar = (R.h) cVar.f6465l;
        ClipData clipData = new ClipData(description, new ClipData.Item(hVar.d()));
        if (i5 >= 31) {
            cVar2 = new g3.c(clipData, 2);
        } else {
            C0160d c0160d = new C0160d();
            c0160d.f2434l = clipData;
            c0160d.f2435m = 2;
            cVar2 = c0160d;
        }
        cVar2.k(hVar.g());
        cVar2.f(bundle);
        return Q.g((AbstractC0882t) this.f2181l, cVar2.d()) == null;
    }

    @Override // io.flutter.util.ViewUtils.ViewVisitor
    public boolean run(View view) {
        return ViewUtils.lambda$hasChildViewOfType$1((Class[]) this.f2181l, view);
    }
}
