package defpackage;

import android.content.Context;
import android.media.AudioDeviceInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import androidx.work.impl.WorkDatabase_Impl;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

/* JADX INFO: renamed from: ᵝᵟᴵ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2939 {

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public static final String[] f11316 = {"INSERT", "UPDATE", "DELETE"};

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final Object f11317;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public Object f11318;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final Object f11319;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final Object f11320;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public Object f11321;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public boolean f11322;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final Object f11323;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public Object f11324;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final Object f11325;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public Object f11326;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final Object f11327;

    public C2939(Context context, ᵳᵢᵺ r3, C4683 c4683, AudioDeviceInfo audioDeviceInfo) {
        Context applicationContext = context.getApplicationContext();
        this.f11317 = applicationContext;
        this.f11319 = r3;
        this.f11324 = c4683;
        this.f11321 = audioDeviceInfo;
        String str = AbstractC0956.f4222;
        Looper looperMyLooper = Looper.myLooper();
        Handler handler = new Handler(looperMyLooper == null ? Looper.getMainLooper() : looperMyLooper, null);
        this.f11325 = handler;
        this.f11320 = new C2066(this);
        this.f11327 = new C2911(1, this);
        C2598 c2598 = C5015.f19005;
        String str2 = Build.MANUFACTURER;
        Uri uriFor = (str2.equals("Amazon") || str2.equals("Xiaomi")) ? Settings.Global.getUriFor("external_surround_sound_enabled") : null;
        this.f11323 = uriFor != null ? new C3779(this, handler, applicationContext.getContentResolver(), uriFor) : null;
    }

    public C2939(WorkDatabase_Impl workDatabase_Impl, LinkedHashMap linkedHashMap, LinkedHashMap linkedHashMap2, String[] strArr, boolean z, ˀᵭ r8) {
        this.f11317 = workDatabase_Impl;
        this.f11319 = linkedHashMap;
        this.f11325 = linkedHashMap2;
        this.f11322 = z;
        this.f11327 = r8;
        this.f11321 = new AtomicBoolean(false);
        this.f11324 = new ˑᵸ(17);
        this.f11320 = new LinkedHashMap();
        int length = strArr.length;
        String[] strArr2 = new String[length];
        for (int i = 0; i < length; i++) {
            String str = strArr[i];
            Locale locale = Locale.ROOT;
            String lowerCase = str.toLowerCase(locale);
            ((LinkedHashMap) this.f11320).put(lowerCase, Integer.valueOf(i));
            String str2 = (String) ((LinkedHashMap) this.f11319).get(strArr[i]);
            String lowerCase2 = str2 != null ? str2.toLowerCase(locale) : null;
            if (lowerCase2 != null) {
                lowerCase = lowerCase2;
            }
            strArr2[i] = lowerCase;
        }
        this.f11323 = strArr2;
        for (Map.Entry entry : ((LinkedHashMap) this.f11319).entrySet()) {
            String str3 = (String) entry.getValue();
            Locale locale2 = Locale.ROOT;
            String lowerCase3 = str3.toLowerCase(locale2);
            if (((LinkedHashMap) this.f11320).containsKey(lowerCase3)) {
                String lowerCase4 = ((String) entry.getKey()).toLowerCase(locale2);
                LinkedHashMap linkedHashMap3 = (LinkedHashMap) this.f11320;
                linkedHashMap3.put(lowerCase4, AbstractC2206.m5792(linkedHashMap3, lowerCase3));
            }
        }
        int length2 = ((String[]) this.f11323).length;
        C0764 c0764 = new C0764();
        c0764.f3428 = new ReentrantLock();
        c0764.f3427 = new long[length2];
        c0764.f3429 = new boolean[length2];
        this.f11318 = c0764;
        this.f11326 = new ˈᵷᵵᵞ(((String[]) this.f11323).length);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object m7025(C2939 c2939, AbstractC3500 abstractC3500) throws Throwable {
        C1670 c1670;
        C0767 c0767;
        Object objM667;
        Throwable th;
        C0767 c07672;
        Object value;
        int[] iArr;
        WorkDatabase_Impl workDatabase_Impl = (WorkDatabase_Impl) c2939.f11317;
        if (abstractC3500 instanceof C1670) {
            c1670 = (C1670) abstractC3500;
            int i = c1670.f6606;
            if ((i & Integer.MIN_VALUE) != 0) {
                c1670.f6606 = i - Integer.MIN_VALUE;
            } else {
                c1670 = new C1670(c2939, abstractC3500);
            }
        }
        Object obj = c1670.f6609;
        int i2 = c1670.f6606;
        InterfaceC2643 interfaceC2643 = null;
        int i3 = 1;
        if (i2 == 0) {
            ᵟˌᵫ.ˊˌˊ(obj);
            c0767 = workDatabase_Impl.f969;
            boolean zM2766 = c0767.m2766();
            C2817 c2817 = C2817.f10823;
            if (!zM2766) {
                return c2817;
            }
            try {
                if (!((AtomicBoolean) c2939.f11321).compareAndSet(true, false)) {
                    c0767.m2767();
                    return c2817;
                }
                if (!((Boolean) ((InterfaceC1841) c2939.f11324).mo1021()).booleanValue()) {
                    c0767.m2767();
                    return c2817;
                }
                C4950 c4950 = new C4950(c2939, interfaceC2643, i3);
                c1670.f6607 = c2939;
                c1670.f6608 = c0767;
                c1670.f6606 = 1;
                objM667 = workDatabase_Impl.m667(false, c4950, c1670);
                EnumC0111 enumC0111 = EnumC0111.f1384;
                if (objM667 == enumC0111) {
                    return enumC0111;
                }
            } catch (Throwable th2) {
                C0767 c07673 = c0767;
                th = th2;
                c07672 = c07673;
                c07672.m2767();
                throw th;
            }
        } else {
            if (i2 != 1) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
                return null;
            }
            c07672 = c1670.f6608;
            C2939 c29392 = c1670.f6607;
            try {
                ᵟˌᵫ.ˊˌˊ(obj);
                c0767 = c07672;
                c2939 = c29392;
                objM667 = obj;
            } catch (Throwable th3) {
                th = th3;
                c07672.m2767();
                throw th;
            }
        }
        Set set = (Set) objM667;
        if (!set.isEmpty()) {
            ˈᵷᵵᵞ r1 = (ˈᵷᵵᵞ) c2939.f11326;
            r1.getClass();
            if (!set.isEmpty()) {
                C5346 c5346 = (C5346) r1.ᵜᵪʾ;
                do {
                    value = c5346.getValue();
                    int[] iArr2 = (int[]) value;
                    int length = iArr2.length;
                    iArr = new int[length];
                    for (int i4 = 0; i4 < length; i4++) {
                        iArr[i4] = set.contains(Integer.valueOf(i4)) ? iArr2[i4] + 1 : iArr2[i4];
                    }
                } while (!c5346.m10938(value, iArr));
            }
            ((ˀᵭ) c2939.f11327).ʽˈˋ(set);
        }
        c0767.m2767();
        return set;
    }

    /* JADX WARN: Code restructure failed: missing block: B:17:0x007e, code lost:
    
        if (ᵬʕˎʽ.ᵱᵽʡᵚ(r1, r3, r4) == r8) goto L27;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x00e0, code lost:
    
        if (ᵬʕˎʽ.ᵱᵽʡᵚ(r10, r3, r4) == r8) goto L27;
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x00e2, code lost:
    
        return r8;
     */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00e8  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x001e  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:26:0x00e0 -> B:28:0x00e3). Please report as a decompilation issue!!! */
    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object m7026(C2939 c2939, InterfaceC4862 interfaceC4862, int i, AbstractC3500 abstractC3500) {
        C1647 c1647;
        String[] strArr;
        C2939 c29392;
        int i2;
        InterfaceC5040 interfaceC5040;
        int i3;
        String str;
        C2939 c29393 = c2939;
        InterfaceC5040 interfaceC50402 = interfaceC4862;
        int i4 = i;
        c29393.getClass();
        if (abstractC3500 instanceof C1647) {
            c1647 = (C1647) abstractC3500;
            int i5 = c1647.f6547;
            if ((i5 & Integer.MIN_VALUE) != 0) {
                c1647.f6547 = i5 - Integer.MIN_VALUE;
            } else {
                c1647 = new C1647(c29393, abstractC3500);
            }
        }
        Object obj = c1647.f6545;
        int i6 = c1647.f6547;
        boolean z = true;
        EnumC0111 enumC0111 = EnumC0111.f1384;
        if (i6 == 0) {
            ᵟˌᵫ.ˊˌˊ(obj);
            String str2 = "INSERT OR IGNORE INTO room_table_modification_log VALUES(" + i4 + ", 0)";
            c1647.f6551 = c29393;
            c1647.f6552 = interfaceC50402;
            c1647.f6548 = i4;
            c1647.f6547 = 1;
        } else if (i6 == 1) {
            int i7 = c1647.f6548;
            interfaceC50402 = c1647.f6552;
            C2939 c29394 = c1647.f6551;
            ᵟˌᵫ.ˊˌˊ(obj);
            i4 = i7;
            c29393 = c29394;
        } else {
            if (i6 != 2) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
                return null;
            }
            i2 = c1647.f6549;
            i3 = c1647.f6554;
            i4 = c1647.f6548;
            strArr = c1647.f6546;
            str = c1647.f6553;
            interfaceC5040 = c1647.f6552;
            c29392 = c1647.f6551;
            ᵟˌᵫ.ˊˌˊ(obj);
            boolean z2 = true;
            i3++;
            z = z2;
            if (i3 < i2) {
                return C5063.f19112;
            }
            String str3 = strArr[i3];
            z2 = z;
            StringBuilder sbM8226 = AbstractC3653.m8226("CREATE ", c29392.f11322 ? "TEMP" : "", " TRIGGER IF NOT EXISTS `", "room_table_modification_trigger_" + str + '_' + str3, "` AFTER ");
            AbstractC3589.m8100(sbM8226, str3, " ON `", str, "` BEGIN UPDATE room_table_modification_log SET invalidated = 1 WHERE table_id = ");
            String strM8110 = AbstractC3589.m8110(sbM8226, i4, " AND invalidated = 0; END");
            c1647.f6551 = c29392;
            c1647.f6552 = interfaceC5040;
            c1647.f6553 = str;
            c1647.f6546 = strArr;
            c1647.f6548 = i4;
            c1647.f6554 = i3;
            c1647.f6549 = i2;
            c1647.f6547 = 2;
        }
        String str4 = ((String[]) c29393.f11323)[i4];
        strArr = f11316;
        c29392 = c29393;
        i2 = 3;
        interfaceC5040 = interfaceC50402;
        i3 = 0;
        str = str4;
        if (i3 < i2) {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object m7027(C2939 c2939, InterfaceC5040 interfaceC5040, AbstractC3500 abstractC3500) {
        C1215 c1215;
        if (abstractC3500 instanceof C1215) {
            c1215 = (C1215) abstractC3500;
            int i = c1215.f5144;
            if ((i & Integer.MIN_VALUE) != 0) {
                c1215.f5144 = i - Integer.MIN_VALUE;
            } else {
                c1215 = new C1215(c2939, abstractC3500);
            }
        }
        Object objMo2791 = c1215.f5146;
        int i2 = c1215.f5144;
        EnumC0111 enumC0111 = EnumC0111.f1384;
        if (i2 == 0) {
            ᵟˌᵫ.ˊˌˊ(objMo2791);
            InterfaceC0778 interfaceC0778 = new ᵡˏᵗ(6);
            c1215.f5145 = interfaceC5040;
            c1215.f5144 = 1;
            objMo2791 = interfaceC5040.mo2791("SELECT * FROM room_table_modification_log WHERE invalidated = 1", interfaceC0778, c1215);
            if (objMo2791 != enumC0111) {
            }
            return enumC0111;
        }
        if (i2 != 1) {
            if (i2 != 2) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
                return null;
            }
            Set set = (Set) c1215.f5145;
            ᵟˌᵫ.ˊˌˊ(objMo2791);
            return set;
        }
        interfaceC5040 = (InterfaceC5040) c1215.f5145;
        ᵟˌᵫ.ˊˌˊ(objMo2791);
        Set set2 = (Set) objMo2791;
        if (!set2.isEmpty()) {
            c1215.f5145 = set2;
            c1215.f5144 = 2;
            if (ᵬʕˎʽ.ᵱᵽʡᵚ(interfaceC5040, "UPDATE room_table_modification_log SET invalidated = 0 WHERE invalidated = 1", c1215) == enumC0111) {
                return enumC0111;
            }
        }
        return set2;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x0051  */
    /* JADX WARN: Removed duplicated region for block: B:20:0x0093  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:17:0x008e -> B:19:0x0091). Please report as a decompilation issue!!! */
    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object m7028(C2939 c2939, InterfaceC4862 interfaceC4862, int i, AbstractC3500 abstractC3500) {
        C0641 c0641;
        String str;
        int i2;
        InterfaceC5040 interfaceC5040;
        int i3;
        String[] strArr;
        c2939.getClass();
        if (abstractC3500 instanceof C0641) {
            c0641 = (C0641) abstractC3500;
            int i4 = c0641.f3006;
            if ((i4 & Integer.MIN_VALUE) != 0) {
                c0641.f3006 = i4 - Integer.MIN_VALUE;
            } else {
                c0641 = new C0641(c2939, abstractC3500);
            }
        }
        Object obj = c0641.f3013;
        int i5 = c0641.f3006;
        if (i5 == 0) {
            ᵟˌᵫ.ˊˌˊ(obj);
            str = ((String[]) c2939.f11323)[i];
            i2 = 3;
            interfaceC5040 = interfaceC4862;
            i3 = 0;
            strArr = f11316;
            if (i3 < i2) {
            }
        } else {
            if (i5 != 1) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
                return null;
            }
            i2 = c0641.f3008;
            i3 = c0641.f3007;
            String[] strArr2 = c0641.f3012;
            str = c0641.f3011;
            InterfaceC5040 interfaceC50402 = c0641.f3010;
            ᵟˌᵫ.ˊˌˊ(obj);
            strArr = strArr2;
            interfaceC5040 = interfaceC50402;
            i3++;
            if (i3 < i2) {
                String str2 = "DROP TRIGGER IF EXISTS `" + ("room_table_modification_trigger_" + str + '_' + strArr[i3]) + '`';
                c0641.f3010 = interfaceC5040;
                c0641.f3011 = str;
                c0641.f3012 = strArr;
                c0641.f3007 = i3;
                c0641.f3008 = i2;
                c0641.f3006 = 1;
                Object obj2 = ᵬʕˎʽ.ᵱᵽʡᵚ(interfaceC5040, str2, c0641);
                EnumC0111 enumC0111 = EnumC0111.f1384;
                if (obj2 == enumC0111) {
                    return enumC0111;
                }
                i3++;
                if (i3 < i2) {
                    return C5063.f19112;
                }
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object m7029(AbstractC3500 abstractC3500) throws Throwable {
        C4202 c4202;
        Throwable th;
        C0767 c0767;
        WorkDatabase_Impl workDatabase_Impl = (WorkDatabase_Impl) this.f11317;
        if (abstractC3500 instanceof C4202) {
            c4202 = (C4202) abstractC3500;
            int i = c4202.f16008;
            if ((i & Integer.MIN_VALUE) != 0) {
                c4202.f16008 = i - Integer.MIN_VALUE;
            } else {
                c4202 = new C4202(this, abstractC3500);
            }
        }
        Object obj = c4202.f16010;
        int i2 = c4202.f16008;
        InterfaceC2643 interfaceC2643 = null;
        if (i2 == 0) {
            ᵟˌᵫ.ˊˌˊ(obj);
            C0767 c07672 = workDatabase_Impl.f969;
            if (c07672.m2766()) {
                try {
                    C4950 c4950 = new C4950(this, interfaceC2643, 2);
                    c4202.f16009 = c07672;
                    c4202.f16008 = 1;
                    Object objM667 = workDatabase_Impl.m667(false, c4950, c4202);
                    EnumC0111 enumC0111 = EnumC0111.f1384;
                    if (objM667 == enumC0111) {
                        return enumC0111;
                    }
                    c0767 = c07672;
                    c0767.m2767();
                } catch (Throwable th2) {
                    th = th2;
                    c0767 = c07672;
                    c0767.m2767();
                    throw th;
                }
            }
        } else {
            if (i2 != 1) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
                return null;
            }
            c0767 = c4202.f16009;
            try {
                ᵟˌᵫ.ˊˌˊ(obj);
                c0767.m2767();
            } catch (Throwable th3) {
                th = th3;
                c0767.m2767();
                throw th;
            }
        }
        return C5063.f19112;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public List m7030() {
        C5304 c5304;
        if (Build.VERSION.SDK_INT >= 32 && (c5304 = (C5304) this.f11318) != null) {
            return c5304.m10889();
        }
        C2822 c2822 = AbstractC4509.f17159;
        return C2598.f10048;
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public C1081 m7031(String[] strArr) {
        C5453 c5453 = new C5453();
        for (String str : strArr) {
            Set set = (Set) ((LinkedHashMap) this.f11325).get(str.toLowerCase(Locale.ROOT));
            if (set != null) {
                c5453.addAll(set);
            } else {
                c5453.add(str);
            }
        }
        String[] strArr2 = (String[]) ˌᵨʽʙ.ᵵᵽ(c5453).toArray(new String[0]);
        int length = strArr2.length;
        int[] iArr = new int[length];
        for (int i = 0; i < length; i++) {
            String str2 = strArr2[i];
            Integer num = (Integer) ((LinkedHashMap) this.f11320).get(str2.toLowerCase(Locale.ROOT));
            if (num == null) {
                ᵕᵩʽᵲ.ᵮᵣᵗˈ("There is no table with name ".concat(str2));
                return null;
            }
            iArr[i] = num.intValue();
        }
        return new C1081(strArr2, iArr);
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public void m7032(InterfaceC1841 interfaceC1841, InterfaceC1841 interfaceC18412) {
        if (((AtomicBoolean) this.f11321).compareAndSet(false, true)) {
            interfaceC1841.mo1021();
            C5426 c5426 = ((WorkDatabase_Impl) this.f11317).f968;
            if (c5426 == null) {
                c5426 = null;
            }
            ᵲᵧˇ.ᵱʡˏ(c5426, new C4469(), 0, new ːˑʛ(this, interfaceC18412, (InterfaceC2643) null, 1), 2);
        }
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public void m7033() {
        m7034(C5015.m10345((Context) this.f11317, (C4683) this.f11324, (AudioDeviceInfo) this.f11321, m7030()));
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public void m7034(C5015 c5015) {
        if (!this.f11322 || c5015.equals((C5015) this.f11326)) {
            return;
        }
        this.f11326 = c5015;
        C0453 c0453 = (C0453) ((ᵳᵢᵺ) this.f11319).ᵜᵪʾ;
        c0453.m1888();
        C5015 c50152 = c0453.f2467;
        if (c50152 == null || c5015.equals(c50152)) {
            return;
        }
        c0453.f2467 = c5015;
        C3252 c3252 = c0453.f2476;
        if (c3252 != null) {
            c3252.m7412(-1, new ᵕᵩʽᵲ(4));
        }
    }
}
