package androidx.room; import android.database.Cursor; import java.util.Iterator; import java.util.List; import p0.c; /* loaded from: classes.dex */ public class i extends c.a { /* renamed from: b, reason: collision with root package name */ private androidx.room.a f2636b; /* renamed from: c, reason: collision with root package name */ private final a f2637c; /* renamed from: d, reason: collision with root package name */ private final String f2638d; /* renamed from: e, reason: collision with root package name */ private final String f2639e; public static abstract class a { /* renamed from: a, reason: collision with root package name */ public final int f2640a; public a(int i10) { this.f2640a = i10; } protected abstract void a(p0.b bVar); protected abstract void b(p0.b bVar); protected abstract void c(p0.b bVar); protected abstract void d(p0.b bVar); protected abstract void e(p0.b bVar); protected abstract void f(p0.b bVar); protected abstract b g(p0.b bVar); } public static class b { /* renamed from: a, reason: collision with root package name */ public final boolean f2641a; /* renamed from: b, reason: collision with root package name */ public final String f2642b; public b(boolean z10, String str) { this.f2641a = z10; this.f2642b = str; } } public i(androidx.room.a aVar, a aVar2, String str, String str2) { super(aVar2.f2640a); this.f2636b = aVar; this.f2637c = aVar2; this.f2638d = str; this.f2639e = str2; } private void h(p0.b bVar) { if (!k(bVar)) { b g10 = this.f2637c.g(bVar); if (g10.f2641a) { this.f2637c.e(bVar); l(bVar); return; } else { throw new IllegalStateException("Pre-packaged database has an invalid schema: " + g10.f2642b); } } Cursor y02 = bVar.y0(new p0.a("SELECT identity_hash FROM room_master_table WHERE id = 42 LIMIT 1")); try { String string = y02.moveToFirst() ? y02.getString(0) : null; y02.close(); if (!this.f2638d.equals(string) && !this.f2639e.equals(string)) { 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."); } } catch (Throwable th) { y02.close(); throw th; } } private void i(p0.b bVar) { bVar.B("CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)"); } private static boolean j(p0.b bVar) { Cursor c02 = bVar.c0("SELECT count(*) FROM sqlite_master WHERE name != 'android_metadata'"); try { boolean z10 = false; if (c02.moveToFirst()) { if (c02.getInt(0) == 0) { z10 = true; } } return z10; } finally { c02.close(); } } private static boolean k(p0.b bVar) { Cursor c02 = bVar.c0("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name='room_master_table'"); try { boolean z10 = false; if (c02.moveToFirst()) { if (c02.getInt(0) != 0) { z10 = true; } } return z10; } finally { c02.close(); } } private void l(p0.b bVar) { i(bVar); bVar.B(m0.b.a(this.f2638d)); } @Override // p0.c.a public void b(p0.b bVar) { super.b(bVar); } @Override // p0.c.a public void d(p0.b bVar) { boolean j10 = j(bVar); this.f2637c.a(bVar); if (!j10) { b g10 = this.f2637c.g(bVar); if (!g10.f2641a) { throw new IllegalStateException("Pre-packaged database has an invalid schema: " + g10.f2642b); } } l(bVar); this.f2637c.c(bVar); } @Override // p0.c.a public void e(p0.b bVar, int i10, int i11) { g(bVar, i10, i11); } @Override // p0.c.a public void f(p0.b bVar) { super.f(bVar); h(bVar); this.f2637c.d(bVar); this.f2636b = null; } @Override // p0.c.a public void g(p0.b bVar, int i10, int i11) { boolean z10; List c10; androidx.room.a aVar = this.f2636b; if (aVar == null || (c10 = aVar.f2542d.c(i10, i11)) == null) { z10 = false; } else { this.f2637c.f(bVar); Iterator it = c10.iterator(); while (it.hasNext()) { ((n0.a) it.next()).a(bVar); } b g10 = this.f2637c.g(bVar); if (!g10.f2641a) { throw new IllegalStateException("Migration didn't properly handle: " + g10.f2642b); } this.f2637c.e(bVar); l(bVar); z10 = true; } if (z10) { return; } androidx.room.a aVar2 = this.f2636b; if (aVar2 != null && !aVar2.a(i10, i11)) { this.f2637c.b(bVar); this.f2637c.a(bVar); return; } throw new IllegalStateException("A migration from " + i10 + " to " + i11 + " was required but not found. Please provide the necessary Migration path via RoomDatabase.Builder.addMigration(Migration ...) or allow for destructive migrations via one of the RoomDatabase.Builder.fallbackToDestructiveMigration* methods."); } }