119 lines
4.7 KiB
Java
119 lines
4.7 KiB
Java
package com.google.android.gms.measurement.internal;
|
|
|
|
import android.database.Cursor;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.database.sqlite.SQLiteException;
|
|
import android.text.TextUtils;
|
|
import com.unity3d.ads.metadata.MediationMetaData;
|
|
import java.io.File;
|
|
import java.util.Collections;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class zzx {
|
|
private static Set<String> a(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 {
|
|
Collections.addAll(hashSet, rawQuery.getColumnNames());
|
|
return hashSet;
|
|
} finally {
|
|
rawQuery.close();
|
|
}
|
|
}
|
|
|
|
static void a(zzas zzasVar, SQLiteDatabase sQLiteDatabase, String str, String str2, String str3, String[] strArr) throws SQLiteException {
|
|
if (zzasVar != null) {
|
|
if (!a(zzasVar, sQLiteDatabase, str)) {
|
|
sQLiteDatabase.execSQL(str2);
|
|
}
|
|
try {
|
|
if (zzasVar != null) {
|
|
Set<String> a = a(sQLiteDatabase, str);
|
|
for (String str4 : str3.split(",")) {
|
|
if (!a.remove(str4)) {
|
|
StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 35 + String.valueOf(str4).length());
|
|
sb.append("Table ");
|
|
sb.append(str);
|
|
sb.append(" is missing required column: ");
|
|
sb.append(str4);
|
|
throw new SQLiteException(sb.toString());
|
|
}
|
|
}
|
|
if (strArr != null) {
|
|
for (int i = 0; i < strArr.length; i += 2) {
|
|
if (!a.remove(strArr[i])) {
|
|
sQLiteDatabase.execSQL(strArr[i + 1]);
|
|
}
|
|
}
|
|
}
|
|
if (a.isEmpty()) {
|
|
return;
|
|
}
|
|
zzasVar.w().a("Table has extra columns. table, columns", str, TextUtils.join(", ", a));
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Monitor must not be null");
|
|
} catch (SQLiteException e) {
|
|
zzasVar.t().a("Failed to verify columns on table that was just created", str);
|
|
throw e;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException("Monitor must not be null");
|
|
}
|
|
|
|
private static boolean a(zzas zzasVar, SQLiteDatabase sQLiteDatabase, String str) {
|
|
if (zzasVar != null) {
|
|
Cursor cursor = null;
|
|
try {
|
|
try {
|
|
cursor = sQLiteDatabase.query("SQLITE_MASTER", new String[]{MediationMetaData.KEY_NAME}, "name=?", new String[]{str}, null, null, null);
|
|
boolean moveToFirst = cursor.moveToFirst();
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
return moveToFirst;
|
|
} catch (SQLiteException e) {
|
|
zzasVar.w().a("Error querying for table", str, e);
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
return false;
|
|
}
|
|
} catch (Throwable th) {
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
throw th;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException("Monitor must not be null");
|
|
}
|
|
|
|
static void a(zzas zzasVar, SQLiteDatabase sQLiteDatabase) {
|
|
if (zzasVar != null) {
|
|
File file = new File(sQLiteDatabase.getPath());
|
|
if (!file.setReadable(false, false)) {
|
|
zzasVar.w().a("Failed to turn off database read permission");
|
|
}
|
|
if (!file.setWritable(false, false)) {
|
|
zzasVar.w().a("Failed to turn off database write permission");
|
|
}
|
|
if (!file.setReadable(true, true)) {
|
|
zzasVar.w().a("Failed to turn on database read permission for owner");
|
|
}
|
|
if (file.setWritable(true, true)) {
|
|
return;
|
|
}
|
|
zzasVar.w().a("Failed to turn on database write permission for owner");
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Monitor must not be null");
|
|
}
|
|
}
|