package androidx.room; import android.app.ActivityManager; import android.content.Context; import android.database.Cursor; import android.os.CancellationSignal; import android.os.Looper; import android.util.Log; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; import p0.c; /* loaded from: classes.dex */ public abstract class h { /* renamed from: a, reason: collision with root package name */ protected volatile p0.b f2603a; /* renamed from: b, reason: collision with root package name */ private Executor f2604b; /* renamed from: c, reason: collision with root package name */ private Executor f2605c; /* renamed from: d, reason: collision with root package name */ private p0.c f2606d; /* renamed from: f, reason: collision with root package name */ private boolean f2608f; /* renamed from: g, reason: collision with root package name */ boolean f2609g; /* renamed from: h, reason: collision with root package name */ protected List f2610h; /* renamed from: i, reason: collision with root package name */ private final ReentrantReadWriteLock f2611i = new ReentrantReadWriteLock(); /* renamed from: j, reason: collision with root package name */ private final ThreadLocal f2612j = new ThreadLocal(); /* renamed from: k, reason: collision with root package name */ private final Map f2613k = new ConcurrentHashMap(); /* renamed from: e, reason: collision with root package name */ private final e f2607e = e(); public static class a { /* renamed from: a, reason: collision with root package name */ private final Class f2614a; /* renamed from: b, reason: collision with root package name */ private final String f2615b; /* renamed from: c, reason: collision with root package name */ private final Context f2616c; /* renamed from: d, reason: collision with root package name */ private ArrayList f2617d; /* renamed from: e, reason: collision with root package name */ private Executor f2618e; /* renamed from: f, reason: collision with root package name */ private Executor f2619f; /* renamed from: g, reason: collision with root package name */ private c.InterfaceC0208c f2620g; /* renamed from: h, reason: collision with root package name */ private boolean f2621h; /* renamed from: j, reason: collision with root package name */ private boolean f2623j; /* renamed from: l, reason: collision with root package name */ private boolean f2625l; /* renamed from: n, reason: collision with root package name */ private Set f2627n; /* renamed from: o, reason: collision with root package name */ private Set f2628o; /* renamed from: p, reason: collision with root package name */ private String f2629p; /* renamed from: q, reason: collision with root package name */ private File f2630q; /* renamed from: i, reason: collision with root package name */ private c f2622i = c.AUTOMATIC; /* renamed from: k, reason: collision with root package name */ private boolean f2624k = true; /* renamed from: m, reason: collision with root package name */ private final d f2626m = new d(); a(Context context, Class cls, String str) { this.f2616c = context; this.f2614a = cls; this.f2615b = str; } public a a(b bVar) { if (this.f2617d == null) { this.f2617d = new ArrayList(); } this.f2617d.add(bVar); return this; } public a b(n0.a... aVarArr) { if (this.f2628o == null) { this.f2628o = new HashSet(); } for (n0.a aVar : aVarArr) { this.f2628o.add(Integer.valueOf(aVar.f11939a)); this.f2628o.add(Integer.valueOf(aVar.f11940b)); } this.f2626m.b(aVarArr); return this; } public a c() { this.f2621h = true; return this; } public h d() { Executor executor; if (this.f2616c == null) { throw new IllegalArgumentException("Cannot provide null context for the database."); } if (this.f2614a == null) { throw new IllegalArgumentException("Must provide an abstract class that extends RoomDatabase"); } Executor executor2 = this.f2618e; if (executor2 == null && this.f2619f == null) { Executor d10 = j.a.d(); this.f2619f = d10; this.f2618e = d10; } else if (executor2 != null && this.f2619f == null) { this.f2619f = executor2; } else if (executor2 == null && (executor = this.f2619f) != null) { this.f2618e = executor; } Set set = this.f2628o; if (set != null && this.f2627n != null) { for (Integer num : set) { if (this.f2627n.contains(num)) { throw new IllegalArgumentException("Inconsistency detected. A Migration was supplied to addMigration(Migration... migrations) that has a start or end version equal to a start version supplied to fallbackToDestructiveMigrationFrom(int... startVersions). Start version: " + num); } } } if (this.f2620g == null) { this.f2620g = new q0.c(); } String str = this.f2629p; if (str != null || this.f2630q != null) { if (this.f2615b == null) { throw new IllegalArgumentException("Cannot create from asset or file for an in-memory database."); } if (str != null && this.f2630q != null) { throw new IllegalArgumentException("Both createFromAsset() and createFromFile() was called on this Builder but the database can only be created using one of the two configurations."); } this.f2620g = new k(str, this.f2630q, this.f2620g); } Context context = this.f2616c; androidx.room.a aVar = new androidx.room.a(context, this.f2615b, this.f2620g, this.f2626m, this.f2617d, this.f2621h, this.f2622i.b(context), this.f2618e, this.f2619f, this.f2623j, this.f2624k, this.f2625l, this.f2627n, this.f2629p, this.f2630q); h hVar = (h) g.b(this.f2614a, "_Impl"); hVar.l(aVar); return hVar; } public a e() { this.f2624k = false; this.f2625l = true; return this; } public a f(c.InterfaceC0208c interfaceC0208c) { this.f2620g = interfaceC0208c; return this; } public a g(Executor executor) { this.f2618e = executor; return this; } } public static abstract class b { public void a(p0.b bVar) { } public void b(p0.b bVar) { } public void c(p0.b bVar) { } } public enum c { AUTOMATIC, TRUNCATE, WRITE_AHEAD_LOGGING; private static boolean a(ActivityManager activityManager) { return activityManager.isLowRamDevice(); } c b(Context context) { if (this != AUTOMATIC) { return this; } ActivityManager activityManager = (ActivityManager) context.getSystemService("activity"); return (activityManager == null || a(activityManager)) ? TRUNCATE : WRITE_AHEAD_LOGGING; } } public static class d { /* renamed from: a, reason: collision with root package name */ private HashMap f2635a = new HashMap(); private void a(n0.a aVar) { int i10 = aVar.f11939a; int i11 = aVar.f11940b; TreeMap treeMap = (TreeMap) this.f2635a.get(Integer.valueOf(i10)); if (treeMap == null) { treeMap = new TreeMap(); this.f2635a.put(Integer.valueOf(i10), treeMap); } n0.a aVar2 = (n0.a) treeMap.get(Integer.valueOf(i11)); if (aVar2 != null) { Log.w("ROOM", "Overriding migration " + aVar2 + " with " + aVar); } treeMap.put(Integer.valueOf(i11), aVar); } /* JADX WARN: Removed duplicated region for block: B:34:0x0016 A[SYNTHETIC] */ /* JADX WARN: Removed duplicated region for block: B:5:0x0017 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private java.util.List d(java.util.List r7, boolean r8, int r9, int r10) { /* r6 = this; L0: if (r8 == 0) goto L5 if (r9 >= r10) goto L57 goto L7 L5: if (r9 <= r10) goto L57 L7: java.util.HashMap r0 = r6.f2635a java.lang.Integer r1 = java.lang.Integer.valueOf(r9) java.lang.Object r0 = r0.get(r1) java.util.TreeMap r0 = (java.util.TreeMap) r0 r1 = 0 if (r0 != 0) goto L17 return r1 L17: if (r8 == 0) goto L1e java.util.NavigableSet r2 = r0.descendingKeySet() goto L22 L1e: java.util.Set r2 = r0.keySet() L22: java.util.Iterator r2 = r2.iterator() L26: boolean r3 = r2.hasNext() r4 = 0 if (r3 == 0) goto L54 java.lang.Object r3 = r2.next() java.lang.Integer r3 = (java.lang.Integer) r3 int r3 = r3.intValue() r5 = 1 if (r8 == 0) goto L40 if (r3 > r10) goto L45 if (r3 <= r9) goto L45 L3e: r4 = 1 goto L45 L40: if (r3 < r10) goto L45 if (r3 >= r9) goto L45 goto L3e L45: if (r4 == 0) goto L26 java.lang.Integer r9 = java.lang.Integer.valueOf(r3) java.lang.Object r9 = r0.get(r9) r7.add(r9) r9 = r3 r4 = 1 L54: if (r4 != 0) goto L0 return r1 L57: return r7 */ throw new UnsupportedOperationException("Method not decompiled: androidx.room.h.d.d(java.util.List, boolean, int, int):java.util.List"); } public void b(n0.a... aVarArr) { for (n0.a aVar : aVarArr) { a(aVar); } } public List c(int i10, int i11) { if (i10 == i11) { return Collections.emptyList(); } return d(new ArrayList(), i11 > i10, i10, i11); } } private static boolean n() { return Looper.getMainLooper().getThread() == Thread.currentThread(); } public void a() { if (!this.f2608f && n()) { throw new IllegalStateException("Cannot access database on the main thread since it may potentially lock the UI for a long period of time."); } } public void b() { if (!k() && this.f2612j.get() != null) { throw new IllegalStateException("Cannot access database on a different coroutine context inherited from a suspending transaction."); } } public void c() { a(); p0.b b02 = this.f2606d.b0(); this.f2607e.m(b02); b02.v(); } public p0.f d(String str) { a(); b(); return this.f2606d.b0().F(str); } protected abstract e e(); protected abstract p0.c f(androidx.room.a aVar); public void g() { this.f2606d.b0().h0(); if (k()) { return; } this.f2607e.f(); } Lock h() { return this.f2611i.readLock(); } public p0.c i() { return this.f2606d; } public Executor j() { return this.f2604b; } public boolean k() { return this.f2606d.b0().p0(); } public void l(androidx.room.a aVar) { p0.c f10 = f(aVar); this.f2606d = f10; if (f10 instanceof j) { ((j) f10).z(aVar); } boolean z10 = aVar.f2545g == c.WRITE_AHEAD_LOGGING; this.f2606d.setWriteAheadLoggingEnabled(z10); this.f2610h = aVar.f2543e; this.f2604b = aVar.f2546h; this.f2605c = new l(aVar.f2547i); this.f2608f = aVar.f2544f; this.f2609g = z10; if (aVar.f2548j) { this.f2607e.i(aVar.f2540b, aVar.f2541c); } } protected void m(p0.b bVar) { this.f2607e.d(bVar); } public boolean o() { p0.b bVar = this.f2603a; return bVar != null && bVar.isOpen(); } public Cursor p(p0.e eVar) { return q(eVar, null); } public Cursor q(p0.e eVar, CancellationSignal cancellationSignal) { a(); b(); return cancellationSignal != null ? this.f2606d.b0().B0(eVar, cancellationSignal) : this.f2606d.b0().y0(eVar); } public void r() { this.f2606d.b0().U(); } }