package o;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.google.firebase.messaging.EnhancedIntentService;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Nj, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final /* synthetic */ class C0346Nj implements InterfaceC0320Mj, HT, InterfaceC2543tg, InterfaceC0250Jq, InterfaceC0246Jm, J30, InterfaceC0823bc0 {
    public final /* synthetic */ int l;
    public final /* synthetic */ Object m;
    public final /* synthetic */ Object n;

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

    @Override // o.InterfaceC0250Jq
    public void a(DZ dz) {
        InterfaceC0250Jq interfaceC0250Jq = (InterfaceC0250Jq) this.m;
        InterfaceC0250Jq interfaceC0250Jq2 = (InterfaceC0250Jq) this.n;
        interfaceC0250Jq.a(dz);
        interfaceC0250Jq2.a(dz);
    }

    @Override // o.J30
    public Object apply(Object obj) {
        L30 l30 = (L30) this.m;
        C2156pc c2156pc = (C2156pc) this.n;
        SQLiteDatabase sQLiteDatabase = (SQLiteDatabase) obj;
        C0364Ob c0364Ob = l30.f204o;
        ArrayList arrayListF = l30.f(sQLiteDatabase, c2156pc, c0364Ob.b);
        for (HY hy : HY.values()) {
            if (hy != c2156pc.c) {
                int size = c0364Ob.b - arrayListF.size();
                if (size <= 0) {
                    break;
                }
                arrayListF.addAll(l30.f(sQLiteDatabase, c2156pc.b(hy), size));
            }
        }
        HashMap map = new HashMap();
        StringBuilder sb = new StringBuilder("event_id IN (");
        for (int i = 0; i < arrayListF.size(); i++) {
            sb.append(((C0917cc) arrayListF.get(i)).a);
            if (i < arrayListF.size() - 1) {
                sb.append(',');
            }
        }
        sb.append(')');
        Cursor cursorQuery = sQLiteDatabase.query("event_metadata", new String[]{"event_id", "name", "value"}, sb.toString(), null, null, null, null);
        while (cursorQuery.moveToNext()) {
            try {
                long j = cursorQuery.getLong(0);
                Set hashSet = (Set) map.get(Long.valueOf(j));
                if (hashSet == null) {
                    hashSet = new HashSet();
                    map.put(Long.valueOf(j), hashSet);
                }
                hashSet.add(new K30(cursorQuery.getString(1), cursorQuery.getString(2)));
            } catch (Throwable th) {
                cursorQuery.close();
                throw th;
            }
        }
        cursorQuery.close();
        ListIterator listIterator = arrayListF.listIterator();
        while (listIterator.hasNext()) {
            C0917cc c0917cc = (C0917cc) listIterator.next();
            long j2 = c0917cc.a;
            if (map.containsKey(Long.valueOf(j2))) {
                C0312Mb c0312MbC = c0917cc.c.c();
                for (K30 k30 : (Set) map.get(Long.valueOf(j2))) {
                    c0312MbC.b(k30.a, k30.b);
                }
                listIterator.set(new C0917cc(j2, c0917cc.b, c0312MbC.c()));
            }
        }
        return arrayListF;
    }

    @Override // o.InterfaceC0823bc0
    public Object d() {
        switch (this.l) {
            case 7:
                C0598Xb c0598Xb = (C0598Xb) this.m;
                Iterable iterable = (Iterable) this.n;
                L30 l30 = (L30) ((InterfaceC0463Rw) c0598Xb.c);
                l30.getClass();
                if (iterable.iterator().hasNext()) {
                    l30.b().compileStatement("DELETE FROM events WHERE _id in " + L30.l(iterable)).execute();
                    break;
                }
                break;
            default:
                C0598Xb c0598Xb2 = (C0598Xb) this.m;
                for (Map.Entry entry : ((HashMap) this.n).entrySet()) {
                    ((L30) ((InterfaceC1025di) c0598Xb2.i)).g(((Integer) entry.getValue()).intValue(), GM.r, (String) entry.getKey());
                }
                break;
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:9:0x002d  */
    @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 r5) {
        /*
            r4 = this;
            int r0 = r4.l
            switch(r0) {
                case 0: goto L91;
                default: goto L5;
            }
        L5:
            java.lang.Object r0 = r4.m
            java.lang.String r0 = (java.lang.String) r0
            java.lang.Object r1 = r4.n
            o.Pi r1 = (o.C0397Pi) r1
            java.lang.Class<android.content.Context> r2 = android.content.Context.class
            java.lang.Object r5 = r5.a(r2)
            android.content.Context r5 = (android.content.Context) r5
            int r1 = r1.l
            switch(r1) {
                case 24: goto L7f;
                case 25: goto L72;
                case 26: goto L30;
                default: goto L1a;
            }
        L1a:
            android.content.pm.PackageManager r1 = r5.getPackageManager()
            java.lang.String r5 = r5.getPackageName()
            java.lang.String r5 = r1.getInstallerPackageName(r5)
            if (r5 == 0) goto L2d
            java.lang.String r5 = com.google.firebase.FirebaseCommonRegistrar.a(r5)
            goto L8b
        L2d:
            java.lang.String r5 = ""
            goto L8b
        L30:
            int r1 = android.os.Build.VERSION.SDK_INT
            android.content.pm.PackageManager r2 = r5.getPackageManager()
            java.lang.String r3 = "android.hardware.type.television"
            boolean r2 = r2.hasSystemFeature(r3)
            if (r2 == 0) goto L41
            java.lang.String r5 = "tv"
            goto L8b
        L41:
            android.content.pm.PackageManager r2 = r5.getPackageManager()
            java.lang.String r3 = "android.hardware.type.watch"
            boolean r2 = r2.hasSystemFeature(r3)
            if (r2 == 0) goto L50
            java.lang.String r5 = "watch"
            goto L8b
        L50:
            android.content.pm.PackageManager r2 = r5.getPackageManager()
            java.lang.String r3 = "android.hardware.type.automotive"
            boolean r2 = r2.hasSystemFeature(r3)
            if (r2 == 0) goto L5f
            java.lang.String r5 = "auto"
            goto L8b
        L5f:
            r2 = 26
            if (r1 < r2) goto L2d
            android.content.pm.PackageManager r5 = r5.getPackageManager()
            java.lang.String r1 = "android.hardware.type.embedded"
            boolean r5 = r5.hasSystemFeature(r1)
            if (r5 == 0) goto L2d
            java.lang.String r5 = "embedded"
            goto L8b
        L72:
            android.content.pm.ApplicationInfo r5 = r5.getApplicationInfo()
            if (r5 == 0) goto L2d
            int r5 = r5.minSdkVersion
            java.lang.String r5 = java.lang.String.valueOf(r5)
            goto L8b
        L7f:
            android.content.pm.ApplicationInfo r5 = r5.getApplicationInfo()
            if (r5 == 0) goto L2d
            int r5 = r5.targetSdkVersion
            java.lang.String r5 = java.lang.String.valueOf(r5)
        L8b:
            o.Wb r1 = new o.Wb
            r1.<init>(r0, r5)
            return r1
        L91:
            java.lang.Object r0 = r4.m
            java.lang.String r0 = (java.lang.String) r0
            java.lang.Object r1 = r4.n
            o.tj r1 = (o.C2549tj) r1
            android.os.Trace.beginSection(r0)     // Catch: java.lang.Throwable -> La6
            o.Mj r0 = r1.f     // Catch: java.lang.Throwable -> La6
            java.lang.Object r5 = r0.i(r5)     // Catch: java.lang.Throwable -> La6
            android.os.Trace.endSection()
            return r5
        La6:
            r5 = move-exception
            android.os.Trace.endSection()
            throw r5
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C0346Nj.i(o.U7):java.lang.Object");
    }

    @Override // o.InterfaceC2543tg
    public void onCancel() throws IllegalAccessException, Resources.NotFoundException, PackageManager.NameNotFoundException, ClassNotFoundException, IllegalArgumentException, InvocationTargetException {
        AbstractC3019yg0 abstractC3019yg0 = (AbstractC3019yg0) this.m;
        RunnableC0890cD runnableC0890cD = (RunnableC0890cD) this.n;
        abstractC3019yg0.d();
        runnableC0890cD.run();
    }

    @Override // o.HT
    public void onComplete(Pc0 pc0) {
        EnhancedIntentService enhancedIntentService = (EnhancedIntentService) this.m;
        Intent intent = (Intent) this.n;
        int i = EnhancedIntentService.l;
        enhancedIntentService.a(intent);
    }

    @Override // o.InterfaceC0246Jm
    public Object then(Pc0 pc0) {
        C3031ym0 c3031ym0 = (C3031ym0) this.n;
        String str = (String) this.m;
        synchronized (c3031ym0) {
            ((C1839m9) c3031ym0.n).remove(str);
        }
        return pc0;
    }

    public /* synthetic */ C0346Nj(C3031ym0 c3031ym0, String str) {
        this.l = 5;
        this.n = c3031ym0;
        this.m = str;
    }
}
