what-the-bank/sources/com/google/android/gms/internal/gtm/zzaz.java

145 lines
5.7 KiB
Java

package com.google.android.gms.internal.gtm;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class zzaz extends SQLiteOpenHelper {
private final zzay zzxo;
@Override // android.database.sqlite.SQLiteOpenHelper
public final void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public zzaz(zzay zzayVar, Context context, String str) {
super(context, str, (SQLiteDatabase.CursorFactory) null, 1);
this.zzxo = zzayVar;
}
@Override // android.database.sqlite.SQLiteOpenHelper
public final SQLiteDatabase getWritableDatabase() {
if (!zzay.zza(this.zzxo).zzj(3600000L)) {
throw new SQLiteException("Database open failed");
}
try {
return super.getWritableDatabase();
} catch (SQLiteException unused) {
zzay.zza(this.zzxo).start();
this.zzxo.zzu("Opening the database failed, dropping the table and recreating it");
this.zzxo.getContext().getDatabasePath(zzay.zzb(this.zzxo)).delete();
try {
SQLiteDatabase writableDatabase = super.getWritableDatabase();
zzay.zza(this.zzxo).clear();
return writableDatabase;
} catch (SQLiteException e) {
this.zzxo.zze("Failed to open freshly created database", e);
throw e;
}
}
}
private final boolean zza(SQLiteDatabase sQLiteDatabase, String str) {
Cursor cursor = null;
try {
try {
cursor = sQLiteDatabase.query("SQLITE_MASTER", new String[]{"name"}, "name=?", new String[]{str}, null, null, null);
boolean moveToFirst = cursor.moveToFirst();
if (cursor != null) {
cursor.close();
}
return moveToFirst;
} catch (SQLiteException e) {
this.zzxo.zzc("Error querying for table", str, e);
if (cursor != null) {
cursor.close();
}
return false;
}
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
private static Set<String> zzb(SQLiteDatabase sQLiteDatabase, String str) {
HashSet hashSet = new HashSet();
StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 22);
sb.append("SELECT * FROM ");
sb.append(str);
sb.append(" LIMIT 0");
Cursor rawQuery = sQLiteDatabase.rawQuery(sb.toString(), null);
try {
for (String str2 : rawQuery.getColumnNames()) {
hashSet.add(str2);
}
return hashSet;
} finally {
rawQuery.close();
}
}
@Override // android.database.sqlite.SQLiteOpenHelper
public final void onOpen(SQLiteDatabase sQLiteDatabase) {
if (!zza(sQLiteDatabase, "hits2")) {
sQLiteDatabase.execSQL(zzay.zzdu());
} else {
Set<String> zzb = zzb(sQLiteDatabase, "hits2");
String[] strArr = {"hit_id", "hit_string", "hit_time", "hit_url"};
for (int i = 0; i < 4; i++) {
String str = strArr[i];
if (!zzb.remove(str)) {
String valueOf = String.valueOf(str);
throw new SQLiteException(valueOf.length() != 0 ? "Database hits2 is missing required column: ".concat(valueOf) : new String("Database hits2 is missing required column: "));
}
}
boolean remove = zzb.remove("hit_app_id");
if (!zzb.isEmpty()) {
throw new SQLiteException("Database hits2 has extra columns");
}
if (!remove) {
sQLiteDatabase.execSQL("ALTER TABLE hits2 ADD COLUMN hit_app_id INTEGER");
}
}
if (!zza(sQLiteDatabase, "properties")) {
sQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS properties ( app_uid INTEGER NOT NULL, cid TEXT NOT NULL, tid TEXT NOT NULL, params TEXT NOT NULL, adid INTEGER NOT NULL, hits_count INTEGER NOT NULL, PRIMARY KEY (app_uid, cid, tid)) ;");
return;
}
Set<String> zzb2 = zzb(sQLiteDatabase, "properties");
String[] strArr2 = {"app_uid", "cid", "tid", "params", "adid", "hits_count"};
for (int i2 = 0; i2 < 6; i2++) {
String str2 = strArr2[i2];
if (!zzb2.remove(str2)) {
String valueOf2 = String.valueOf(str2);
throw new SQLiteException(valueOf2.length() != 0 ? "Database properties is missing required column: ".concat(valueOf2) : new String("Database properties is missing required column: "));
}
}
if (!zzb2.isEmpty()) {
throw new SQLiteException("Database properties table has extra columns");
}
}
@Override // android.database.sqlite.SQLiteOpenHelper
public final void onCreate(SQLiteDatabase sQLiteDatabase) {
String path = sQLiteDatabase.getPath();
if (zzbx.version() < 9) {
return;
}
File file = new File(path);
file.setReadable(false, false);
file.setWritable(false, false);
file.setReadable(true, true);
file.setWritable(true, true);
}
}