package defpackage;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.TreeMap;

/* JADX INFO: renamed from: ᵭʢˏ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4115 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public boolean f15747;

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

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public boolean f15749;

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

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final /* synthetic */ int f15751;

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

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

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

    public C4115(C1452 c1452, AbstractC2717 abstractC2717) {
        int i;
        Object c3614;
        this.f15751 = 1;
        int i2 = c1452.f5911;
        String str = c1452.f5898;
        InterfaceC4674 interfaceC4674 = c1452.f5902;
        this.f15753 = c1452;
        this.f15750 = abstractC2717;
        Object obj = c1452.f5905;
        this.f15754 = obj == null ? C2808.f10794 : obj;
        InterfaceC1153 interfaceC1153 = c1452.f5908;
        if (interfaceC1153 != null) {
            if (interfaceC1153 instanceof C2518) {
                c3614 = new C4634(new ˊˊᵞᵽ(this, 9, interfaceC1153), str == null ? ":memory:" : str);
            } else if (str == null) {
                c3614 = new C3614(new ˊˊᵞᵽ(this, 9, interfaceC1153));
            } else {
                ˊˊᵞᵽ r10 = new ˊˊᵞᵽ(this, 9, interfaceC1153);
                int iM8218 = AbstractC3653.m8218(i2);
                if (iM8218 == 1) {
                    i = 1;
                } else {
                    if (iM8218 != 2) {
                        throw new IllegalStateException(("Can't get max number of reader for journal mode '" + AbstractC2704.m6514(i2) + '\'').toString());
                    }
                    i = 4;
                }
                int iM82182 = AbstractC3653.m8218(i2);
                if (iM82182 != 1 && iM82182 != 2) {
                    throw new IllegalStateException(("Can't get max number of writers for journal mode '" + AbstractC2704.m6514(i2) + '\'').toString());
                }
                c3614 = new C3614(r10, str, i);
            }
            this.f15752 = c3614;
        } else {
            if (interfaceC4674 == null) {
                ᵕᵩʽᵲ.ᵮᵣᵗˈ("SQLiteManager was constructed with both null driver and open helper factory!");
                throw null;
            }
            this.f15752 = new C3345(new ᵢʒʡᵟ(28, interfaceC4674.mo8266(new C3609(c1452.f5910, str, new C1785(this, abstractC2717.f10430), false, false))));
        }
        boolean z = i2 == 3;
        InterfaceC5441 interfaceC5441M8980 = m8980();
        if (interfaceC5441M8980 != null) {
            interfaceC5441M8980.setWriteAheadLoggingEnabled(z);
        }
    }

    public C4115(C1452 c1452, ᵦʞˀ r5) {
        this.f15751 = 1;
        this.f15753 = c1452;
        this.f15750 = new C1405(-1, "", "");
        List list = c1452.f5905;
        C2808 c2808 = C2808.f10794;
        this.f15754 = list == null ? c2808 : list;
        AbstractC4126.m8997(list == null ? c2808 : list, new C1156(1, new ᵨˈʼﹶ(29, this)));
        throw new C2637();
    }

    public C4115(boolean z, boolean z2, Long l, Long l2, Long l3, Long l4) {
        this.f15751 = 0;
        this.f15747 = z;
        this.f15749 = z2;
        this.f15753 = l;
        this.f15750 = l2;
        this.f15754 = l3;
        this.f15752 = l4;
        this.f15748 = AbstractC2206.m5796(C2561.f9904);
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static void m8978(InterfaceC2047 interfaceC2047) {
        InterfaceC4296 interfaceC4296Mo5461 = interfaceC2047.mo5461("PRAGMA busy_timeout");
        try {
            interfaceC4296Mo5461.mo3331();
            long j = interfaceC4296Mo5461.getLong(0);
            ᵣˉ.ᵮᵣᵗˈ(interfaceC4296Mo5461, (Throwable) null);
            if (j < 3000) {
                ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "PRAGMA busy_timeout = 3000");
            }
        } catch (Throwable th) {
            try {
                throw th;
            } catch (Throwable th2) {
                ᵣˉ.ᵮᵣᵗˈ(interfaceC4296Mo5461, th);
                throw th2;
            }
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static final void m8979(C4115 c4115, InterfaceC2047 interfaceC2047) throws Throwable {
        Object c2586;
        AbstractC2717 abstractC2717 = (AbstractC2717) c4115.f15750;
        C1452 c1452 = (C1452) c4115.f15753;
        if (c1452.f5911 == 3) {
            ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "PRAGMA journal_mode = WAL");
        } else {
            ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "PRAGMA journal_mode = TRUNCATE");
        }
        if (c1452.f5911 == 3) {
            ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "PRAGMA synchronous = NORMAL");
        } else {
            ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "PRAGMA synchronous = FULL");
        }
        m8978(interfaceC2047);
        InterfaceC4296 interfaceC4296Mo5461 = interfaceC2047.mo5461("PRAGMA user_version");
        try {
            interfaceC4296Mo5461.mo3331();
            int i = (int) interfaceC4296Mo5461.getLong(0);
            ᵣˉ.ᵮᵣᵗˈ(interfaceC4296Mo5461, (Throwable) null);
            int i2 = abstractC2717.f10430;
            if (i != i2) {
                ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "BEGIN EXCLUSIVE TRANSACTION");
                try {
                    if (i == 0) {
                        c4115.m8983(interfaceC2047);
                    } else {
                        c4115.m8981(interfaceC2047, i, i2);
                    }
                    ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "PRAGMA user_version = " + i2);
                    c2586 = C5063.f19112;
                } catch (Throwable th) {
                    c2586 = new C2586(th);
                }
                if (!(c2586 instanceof C2586)) {
                    ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "END TRANSACTION");
                }
                Throwable thM5818 = AbstractC2231.m5818(c2586);
                if (thM5818 != null) {
                    ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "ROLLBACK TRANSACTION");
                    throw thM5818;
                }
            }
            c4115.m8984(interfaceC2047);
        } finally {
        }
    }

    public String toString() {
        switch (this.f15751) {
            case 0:
                Map map = (Map) this.f15748;
                Long l = (Long) this.f15752;
                Long l2 = (Long) this.f15754;
                Long l3 = (Long) this.f15750;
                Long l4 = (Long) this.f15753;
                ArrayList arrayList = new ArrayList();
                if (this.f15747) {
                    arrayList.add("isRegularFile");
                }
                if (this.f15749) {
                    arrayList.add("isDirectory");
                }
                if (l4 != null) {
                    arrayList.add("byteCount=" + l4.longValue());
                }
                if (l3 != null) {
                    arrayList.add("createdAt=" + l3.longValue());
                }
                if (l2 != null) {
                    arrayList.add("lastModifiedAt=" + l2.longValue());
                }
                if (l != null) {
                    arrayList.add("lastAccessedAt=" + l.longValue());
                }
                if (!map.isEmpty()) {
                    arrayList.add("extras=" + map);
                }
                return AbstractC4126.m8996(arrayList, ", ", "FileMetadata(", ")", null, 56);
            default:
                return super.toString();
        }
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public InterfaceC5441 m8980() {
        InterfaceC2794 interfaceC2794 = (InterfaceC2794) this.f15752;
        C3345 c3345 = interfaceC2794 instanceof C3345 ? (C3345) interfaceC2794 : null;
        if (c3345 != null) {
            return (InterfaceC5441) c3345.f12817.ᵜᵪʾ;
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:111:0x009b A[EDGE_INSN: B:111:0x009b->B:39:0x009b BREAK  A[LOOP:4: B:9:0x0025->B:115:?], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:15:0x0030  */
    /* JADX WARN: Removed duplicated region for block: B:17:0x003c  */
    /* JADX WARN: Removed duplicated region for block: B:19:0x0048  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x0061  */
    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void m8981(InterfaceC2047 interfaceC2047, int i, int i2) {
        Iterable iterable;
        C1081 c1081;
        boolean z;
        AbstractC2717 abstractC2717 = (AbstractC2717) this.f15750;
        C1452 c1452 = (C1452) this.f15753;
        C1141 c1141 = c1452.f5913;
        if (i == i2) {
            iterable = C2808.f10794;
        } else {
            boolean z2 = i2 > i;
            ArrayList arrayList = new ArrayList();
            int i3 = i;
            do {
                if (z2) {
                    if (i3 >= i2) {
                        iterable = arrayList;
                        break;
                    }
                    LinkedHashMap linkedHashMap = c1141.f4907;
                    if (z2) {
                        TreeMap treeMap = (TreeMap) linkedHashMap.get(Integer.valueOf(i3));
                        if (treeMap != null) {
                            c1081 = new C1081(treeMap, treeMap.keySet());
                        }
                        if (c1081 != null) {
                        }
                    } else {
                        TreeMap treeMap2 = (TreeMap) linkedHashMap.get(Integer.valueOf(i3));
                        c1081 = treeMap2 == null ? null : new C1081(treeMap2, treeMap2.descendingKeySet());
                        if (c1081 != null) {
                            break;
                        }
                        Map map = (Map) c1081.f4615;
                        Iterator it = ((Iterable) c1081.f4616).iterator();
                        while (it.hasNext()) {
                            int iIntValue = ((Number) it.next()).intValue();
                            if (!z2) {
                                if (i2 <= iIntValue && iIntValue < i3) {
                                    arrayList.add(map.get(Integer.valueOf(iIntValue)));
                                    z = true;
                                    i3 = iIntValue;
                                    break;
                                    break;
                                }
                            } else if (i3 + 1 <= iIntValue && iIntValue <= i2) {
                                arrayList.add(map.get(Integer.valueOf(iIntValue)));
                                z = true;
                                i3 = iIntValue;
                                break;
                            }
                        }
                        z = false;
                    }
                } else {
                    if (i3 <= i2) {
                        iterable = arrayList;
                        break;
                    }
                    LinkedHashMap linkedHashMap2 = c1141.f4907;
                    if (z2) {
                    }
                }
            } while (z);
            iterable = null;
        }
        if (iterable != null) {
            abstractC2717.mo4058(interfaceC2047);
            Iterator it2 = iterable.iterator();
            while (it2.hasNext()) {
                ((AbstractC2726) it2.next()).mo1842(interfaceC2047);
            }
            C3789 c3789Mo4056 = abstractC2717.mo4056(interfaceC2047);
            if (!c3789Mo4056.f14391) {
                ᵷᵝˎ.ˊᵨᵧ(c3789Mo4056.f14392, "Migration didn't properly handle: ");
                return;
            } else {
                abstractC2717.mo4059();
                m8982(interfaceC2047);
                return;
            }
        }
        if (ᵘᵞʿⁱ.ᵯᵷʽ(c1452, i, i2)) {
            throw new IllegalStateException(("A migration from " + i + " to " + i2 + " was required but not found. Please provide the necessary Migration path via RoomDatabase.Builder.addMigration(...) or allow for destructive migrations via one of the RoomDatabase.Builder.fallbackToDestructiveMigration* functions.").toString());
        }
        if (c1452.f5904) {
            InterfaceC4296 interfaceC4296Mo5461 = interfaceC2047.mo5461("SELECT name, type FROM sqlite_master WHERE type = 'table' OR type = 'view'");
            try {
                C0970 c0970 = ᵽˊᵘᵬ.ᵷᵺʾᵖ();
                while (interfaceC4296Mo5461.mo3331()) {
                    String strMo3327 = interfaceC4296Mo5461.mo3327(0);
                    if (!AbstractC5498.m11136(strMo3327, "sqlite_", false) && !strMo3327.equals("android_metadata")) {
                        c0970.add(new C1081(strMo3327, Boolean.valueOf(ᵥˈᵛ.ˊᵫᵗ(interfaceC4296Mo5461.mo3327(1), "view"))));
                    }
                }
                C0970 c09702 = ᵽˊᵘᵬ.ᵲᵶᵳˈ(c0970);
                ᵣˉ.ᵮᵣᵗˈ(interfaceC4296Mo5461, (Throwable) null);
                ListIterator listIterator = c09702.listIterator(0);
                while (true) {
                    C4848 c4848 = (C4848) listIterator;
                    if (!c4848.hasNext()) {
                        break;
                    }
                    C1081 c10812 = (C1081) c4848.next();
                    String str = (String) c10812.f4615;
                    if (((Boolean) c10812.f4616).booleanValue()) {
                        ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "DROP VIEW IF EXISTS " + str);
                    } else {
                        ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "DROP TABLE IF EXISTS " + str);
                    }
                }
            } finally {
            }
        } else {
            abstractC2717.mo4053(interfaceC2047);
        }
        Iterator it3 = ((List) this.f15754).iterator();
        while (it3.hasNext()) {
            ((C1156) it3.next()).getClass();
        }
        abstractC2717.mo4057(interfaceC2047);
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public void m8982(InterfaceC2047 interfaceC2047) {
        ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)");
        ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '" + ((AbstractC2717) this.f15750).f10428 + "')");
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public void m8983(InterfaceC2047 interfaceC2047) {
        AbstractC2717 abstractC2717 = (AbstractC2717) this.f15750;
        InterfaceC4296 interfaceC4296Mo5461 = interfaceC2047.mo5461("SELECT count(*) FROM sqlite_master WHERE name != 'android_metadata'");
        try {
            boolean z = false;
            if (interfaceC4296Mo5461.mo3331()) {
                if (interfaceC4296Mo5461.getLong(0) == 0) {
                    z = true;
                }
            }
            ᵣˉ.ᵮᵣᵗˈ(interfaceC4296Mo5461, (Throwable) null);
            abstractC2717.mo4057(interfaceC2047);
            if (!z) {
                C3789 c3789Mo4056 = abstractC2717.mo4056(interfaceC2047);
                if (!c3789Mo4056.f14391) {
                    ᵷᵝˎ.ˊᵨᵧ(c3789Mo4056.f14392, "Pre-packaged database has an invalid schema: ");
                    return;
                }
            }
            m8982(interfaceC2047);
            abstractC2717.mo4054();
            Iterator it = ((List) this.f15754).iterator();
            while (it.hasNext()) {
                ((C1156) it.next()).getClass();
            }
        } finally {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0023  */
    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void m8984(InterfaceC2047 interfaceC2047) throws Throwable {
        boolean z;
        Object c2586;
        C3789 c3789Mo4056;
        AbstractC2717 abstractC2717 = (AbstractC2717) this.f15750;
        InterfaceC4296 interfaceC4296Mo5461 = interfaceC2047.mo5461("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'room_master_table'");
        try {
            if (interfaceC4296Mo5461.mo3331()) {
                z = interfaceC4296Mo5461.getLong(0) != 0;
            }
            ᵣˉ.ᵮᵣᵗˈ(interfaceC4296Mo5461, (Throwable) null);
            if (z) {
                interfaceC4296Mo5461 = interfaceC2047.mo5461("SELECT identity_hash FROM room_master_table WHERE id = 42 LIMIT 1");
                try {
                    String strMo3327 = interfaceC4296Mo5461.mo3331() ? interfaceC4296Mo5461.mo3327(0) : null;
                    ᵣˉ.ᵮᵣᵗˈ(interfaceC4296Mo5461, (Throwable) null);
                    if (!abstractC2717.f10428.equals(strMo3327) && !abstractC2717.f10429.equals(strMo3327)) {
                        throw new IllegalStateException(("Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number. Expected identity hash: " + abstractC2717.f10428 + ", found: " + strMo3327).toString());
                    }
                } finally {
                }
            } else {
                ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "BEGIN EXCLUSIVE TRANSACTION");
                try {
                    c3789Mo4056 = abstractC2717.mo4056(interfaceC2047);
                } catch (Throwable th) {
                    c2586 = new C2586(th);
                }
                if (!c3789Mo4056.f14391) {
                    throw new IllegalStateException(("Pre-packaged database has an invalid schema: " + c3789Mo4056.f14392).toString());
                }
                abstractC2717.mo4059();
                m8982(interfaceC2047);
                c2586 = C5063.f19112;
                if (!(c2586 instanceof C2586)) {
                    ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "END TRANSACTION");
                }
                Throwable thM5818 = AbstractC2231.m5818(c2586);
                if (thM5818 != null) {
                    ˋˀᵧ.ᵪᵹᵥᵻ(interfaceC2047, "ROLLBACK TRANSACTION");
                    throw thM5818;
                }
            }
            abstractC2717.mo4055(interfaceC2047);
            for (C1156 c1156 : (List) this.f15754) {
                c1156.getClass();
                if (interfaceC2047 instanceof C3562) {
                    C5178 c5178 = ((C3562) interfaceC2047).f13646;
                    switch (c1156.f4939) {
                        case 0:
                            c5178.m10716();
                            try {
                                StringBuilder sb = new StringBuilder("DELETE FROM workspec WHERE state IN (2, 3, 5) AND (last_enqueue_time + minimum_retention_duration) < ");
                                ((ᵤᵮᵨ) c1156.f4938).getClass();
                                sb.append(System.currentTimeMillis() - 86400000);
                                sb.append(" AND (SELECT COUNT(*)=0 FROM dependency WHERE     prerequisite_id=id AND     work_spec_id NOT IN         (SELECT id FROM workspec WHERE state IN (2, 3, 5)))");
                                c5178.m10712(sb.toString());
                                c5178.m10711();
                            } finally {
                                c5178.m10709();
                            }
                            break;
                        default:
                            ((ᵨˈʼﹶ) c1156.f4938).ʽˈˋ(c5178);
                            break;
                    }
                }
            }
            this.f15747 = true;
        } finally {
            try {
                throw th;
            } finally {
            }
        }
    }
}
