package com.google.android.material.shape;

import android.os.Bundle;
import android.os.IBinder;
import android.os.IInterface;
import android.text.Editable;
import android.text.Selection;
import android.text.Spannable;
import android.view.inputmethod.InputConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import kotlin.collections.builders.MapBuilder;
import kotlin.collections.builders.SetBuilder;
import n7.i2;
import xyz.stream.download.config.InnerConstant;

/* JADX INFO: loaded from: classes2.dex */
public class f implements androidx.browser.trusted.g, y0.c, androidx.media3.extractor.k, androidx.datastore.core.c, l3.f, q7.l, db.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final /* synthetic */ f f23066a = new f();

    /* JADX WARN: Code restructure failed: missing block: B:33:0x004b, code lost:
    
        if (java.lang.Character.isHighSurrogate(r5) != false) goto L35;
     */
    /* JADX WARN: Code restructure failed: missing block: B:58:0x0088, code lost:
    
        if (java.lang.Character.isLowSurrogate(r5) != false) goto L60;
     */
    /* JADX WARN: Removed duplicated region for block: B:106:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:48:0x0072 A[EDGE_INSN: B:91:0x0072->B:48:0x0072 BREAK  A[LOOP:2: B:49:0x0074->B:60:0x008b, LOOP_LABEL: LOOP:2: B:49:0x0074->B:60:0x008b], EDGE_INSN: B:94:0x0072->B:48:0x0072 BREAK  A[LOOP:2: B:49:0x0074->B:60:0x008b]] */
    /* JADX WARN: Removed duplicated region for block: B:69:0x00a8 A[ADDED_TO_REGION] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static boolean g(InputConnection inputConnection, Editable editable, int i10, int i11, boolean z10) {
        int iMin;
        Object obj = androidx.emoji2.text.t.f2266k;
        if (editable == null || inputConnection == null || i10 < 0 || i11 < 0) {
            return false;
        }
        int selectionStart = Selection.getSelectionStart(editable);
        int selectionEnd = Selection.getSelectionEnd(editable);
        if (selectionStart == -1 || selectionEnd == -1 || selectionStart != selectionEnd) {
            return false;
        }
        if (z10) {
            int iMax = Math.max(i10, 0);
            int length = editable.length();
            if (selectionStart < 0 || length < selectionStart || iMax < 0) {
                selectionStart = -1;
                int iMax2 = Math.max(i11, 0);
                iMin = editable.length();
                if (selectionEnd < 0 && iMin >= selectionEnd && iMax2 >= 0) {
                    loop2: while (true) {
                        boolean z11 = false;
                        while (true) {
                            if (iMax2 == 0) {
                                iMin = selectionEnd;
                                break loop2;
                            }
                            if (selectionEnd >= iMin) {
                                if (z11) {
                                    break loop2;
                                }
                            } else {
                                char cCharAt = editable.charAt(selectionEnd);
                                if (z11) {
                                    break;
                                }
                                if (!Character.isSurrogate(cCharAt)) {
                                    iMax2--;
                                    selectionEnd++;
                                } else {
                                    if (Character.isLowSurrogate(cCharAt)) {
                                        break loop2;
                                    }
                                    selectionEnd++;
                                    z11 = true;
                                }
                            }
                        }
                        iMax2--;
                        selectionEnd++;
                    }
                    iMin = -1;
                    return selectionStart == -1 ? false : false;
                }
                iMin = -1;
                if (selectionStart == -1 || iMin == -1) {
                }
            } else {
                loop0: while (true) {
                    boolean z12 = false;
                    while (true) {
                        if (iMax == 0) {
                            break loop0;
                        }
                        selectionStart--;
                        if (selectionStart >= 0) {
                            char cCharAt2 = editable.charAt(selectionStart);
                            if (z12) {
                                break;
                            }
                            if (!Character.isSurrogate(cCharAt2)) {
                                iMax--;
                            } else {
                                if (Character.isHighSurrogate(cCharAt2)) {
                                    break loop0;
                                }
                                z12 = true;
                            }
                        } else {
                            if (z12) {
                                break;
                            }
                            selectionStart = 0;
                        }
                    }
                    iMax--;
                }
                selectionStart = -1;
                int iMax22 = Math.max(i11, 0);
                iMin = editable.length();
                if (selectionEnd < 0) {
                    iMin = -1;
                    if (selectionStart == -1) {
                    }
                }
            }
        } else {
            selectionStart = Math.max(selectionStart - i10, 0);
            iMin = Math.min(selectionEnd + i11, editable.length());
        }
        androidx.emoji2.text.e0[] e0VarArr = (androidx.emoji2.text.e0[]) editable.getSpans(selectionStart, iMin, androidx.emoji2.text.e0.class);
        if (e0VarArr == null || e0VarArr.length <= 0) {
            return false;
        }
        for (androidx.emoji2.text.e0 e0Var : e0VarArr) {
            int spanStart = editable.getSpanStart(e0Var);
            int spanEnd = editable.getSpanEnd(e0Var);
            selectionStart = Math.min(spanStart, selectionStart);
            iMin = Math.max(spanEnd, iMin);
        }
        int iMax3 = Math.max(selectionStart, 0);
        int iMin2 = Math.min(iMin, editable.length());
        inputConnection.beginBatchEdit();
        editable.delete(iMax3, iMin2);
        inputConnection.endBatchEdit();
        return true;
    }

    /* JADX WARN: Code restructure failed: missing block: B:67:0x01e0, code lost:
    
        r7.g();
     */
    /* JADX WARN: Code restructure failed: missing block: B:68:0x01e3, code lost:
    
        ua.b.h(r2, null);
        r10 = r7;
     */
    /* JADX WARN: Finally extract failed */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static androidx.room.util.k i(String str, k3.a aVar) throws Exception {
        Map mapV;
        SetBuilder setBuilder;
        nb.g.i(aVar, "connection");
        k3.c cVarJ = aVar.J("PRAGMA table_info(`" + str + "`)");
        try {
            long j10 = 0;
            if (cVarJ.G()) {
                int iA = androidx.room.util.f.a(cVarJ, "name");
                int iA2 = androidx.room.util.f.a(cVarJ, "type");
                int iA3 = androidx.room.util.f.a(cVarJ, "notnull");
                int iA4 = androidx.room.util.f.a(cVarJ, "pk");
                int iA5 = androidx.room.util.f.a(cVarJ, "dflt_value");
                MapBuilder mapBuilder = new MapBuilder();
                while (true) {
                    String strA = cVarJ.A(iA);
                    mapBuilder.put(strA, new androidx.room.util.h((int) cVarJ.getLong(iA4), strA, cVarJ.A(iA2), cVarJ.isNull(iA5) ? null : cVarJ.A(iA5), cVarJ.getLong(iA3) != j10, 2));
                    if (!cVarJ.G()) {
                        break;
                    }
                    j10 = 0;
                }
                mapBuilder.j();
                ua.b.h(cVarJ, null);
                mapV = mapBuilder;
            } else {
                mapV = kotlin.collections.q.V();
                ua.b.h(cVarJ, null);
            }
            cVarJ = aVar.J("PRAGMA foreign_key_list(`" + str + "`)");
            try {
                int iA6 = androidx.room.util.f.a(cVarJ, InnerConstant.Db.f36069id);
                int iA7 = androidx.room.util.f.a(cVarJ, "seq");
                int iA8 = androidx.room.util.f.a(cVarJ, "table");
                int iA9 = androidx.room.util.f.a(cVarJ, "on_delete");
                int iA10 = androidx.room.util.f.a(cVarJ, "on_update");
                List listA = androidx.room.util.g.a(cVarJ);
                cVarJ.reset();
                SetBuilder setBuilder2 = new SetBuilder();
                while (cVarJ.G()) {
                    if (cVarJ.getLong(iA7) == 0) {
                        int i10 = (int) cVarJ.getLong(iA6);
                        ArrayList arrayList = new ArrayList();
                        ArrayList arrayList2 = new ArrayList();
                        int i11 = iA6;
                        ArrayList<androidx.room.util.c> arrayList3 = new ArrayList();
                        for (Object obj : listA) {
                            int i12 = iA7;
                            List list = listA;
                            if (((androidx.room.util.c) obj).f4168a == i10) {
                                arrayList3.add(obj);
                            }
                            iA7 = i12;
                            listA = list;
                        }
                        int i13 = iA7;
                        List list2 = listA;
                        for (androidx.room.util.c cVar : arrayList3) {
                            arrayList.add(cVar.f4170c);
                            arrayList2.add(cVar.f4171d);
                        }
                        setBuilder2.add(new androidx.room.util.i(cVarJ.A(iA8), cVarJ.A(iA9), cVarJ.A(iA10), arrayList, arrayList2));
                        iA6 = i11;
                        iA7 = i13;
                        listA = list2;
                    }
                }
                setBuilder2.g();
                ua.b.h(cVarJ, null);
                cVarJ = aVar.J("PRAGMA index_list(`" + str + "`)");
                try {
                    int iA11 = androidx.room.util.f.a(cVarJ, "name");
                    int iA12 = androidx.room.util.f.a(cVarJ, "origin");
                    int iA13 = androidx.room.util.f.a(cVarJ, "unique");
                    if (iA11 == -1 || iA12 == -1 || iA13 == -1) {
                        ua.b.h(cVarJ, null);
                        setBuilder = null;
                    } else {
                        SetBuilder setBuilder3 = new SetBuilder();
                        while (true) {
                            if (!cVarJ.G()) {
                                break;
                            }
                            if (nb.g.c("c", cVarJ.A(iA12))) {
                                androidx.room.util.j jVarB = androidx.room.util.g.b(aVar, cVarJ.A(iA11), cVarJ.getLong(iA13) == 1);
                                if (jVarB == null) {
                                    ua.b.h(cVarJ, null);
                                    setBuilder = null;
                                    break;
                                }
                                setBuilder3.add(jVarB);
                            }
                        }
                    }
                    return new androidx.room.util.k(str, mapV, setBuilder2, setBuilder);
                } finally {
                }
            } catch (Throwable th) {
                try {
                    throw th;
                } finally {
                }
            }
        } finally {
            try {
                throw th;
            } finally {
            }
        }
    }

    @Override // androidx.media3.extractor.k
    public long a(long j10) {
        return j10;
    }

    @Override // l3.f
    public l3.g b(l3.e eVar) {
        return new m3.e(eVar.f30107a, eVar.f30108b, eVar.f30109c, eVar.f30110d, eVar.f30111e);
    }

    @Override // androidx.browser.trusted.g
    public Bundle c() {
        Bundle bundle = new Bundle();
        bundle.putInt("androidx.browser.trusted.displaymode.KEY_ID", 0);
        return bundle;
    }

    public boolean d() {
        return this instanceof g;
    }

    public void e(float f10, float f11, float f12, e0 e0Var) {
        e0Var.d(f10, 0.0f);
    }

    @Override // q7.l
    public Object f(IBinder iBinder) {
        IBinder iBinder2 = iBinder;
        if (iBinder2 == null) {
            return null;
        }
        IInterface iInterfaceQueryLocalInterface = iBinder2.queryLocalInterface("com.google.android.gms.ads.internal.client.IOutOfContextTesterCreator");
        return iInterfaceQueryLocalInterface instanceof i2 ? (i2) iInterfaceQueryLocalInterface : new i2(iBinder2, "com.google.android.gms.ads.internal.client.IOutOfContextTesterCreator", 0);
    }

    public boolean h(Spannable spannable) {
        return spannable instanceof o0.f;
    }
}
