package L1;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.SystemClock;
import com.google.android.gms.internal.measurement.P3;
import java.util.Objects;
import w1.C1091a;

/* JADX INFO: renamed from: L1.m, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0116m extends SQLiteOpenHelper {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ int f1903k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final /* synthetic */ A2.e f1904l;

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public C0116m(C0119n c0119n, Context context) {
        this(context, "google_app_measurement.db");
        this.f1903k = 0;
        Objects.requireNonNull(c0119n);
        this.f1904l = c0119n;
    }

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final SQLiteDatabase getWritableDatabase() {
        switch (this.f1903k) {
            case 0:
                C0119n c0119n = (C0119n) this.f1904l;
                ((C0146w0) c0119n.f29k).getClass();
                T t4 = c0119n.f1918o;
                if (t4.f1557l != 0) {
                    ((C1091a) t4.f1558m).getClass();
                    if (SystemClock.elapsedRealtime() - t4.f1557l < 3600000) {
                        throw new SQLiteException("Database open failed");
                    }
                }
                try {
                    return super.getWritableDatabase();
                } catch (SQLiteException unused) {
                    ((C1091a) t4.f1558m).getClass();
                    t4.f1557l = SystemClock.elapsedRealtime();
                    C0146w0 c0146w0 = (C0146w0) c0119n.f29k;
                    X x5 = c0146w0.p;
                    C0146w0.l(x5);
                    x5.p.b("Opening the database failed, dropping and recreating it");
                    if (!c0146w0.f2032k.getDatabasePath("google_app_measurement.db").delete()) {
                        X x6 = c0146w0.p;
                        C0146w0.l(x6);
                        x6.p.c("Failed to delete corrupted db file", "google_app_measurement.db");
                    }
                    try {
                        SQLiteDatabase writableDatabase = super.getWritableDatabase();
                        t4.f1557l = 0L;
                        return writableDatabase;
                    } catch (SQLiteException e2) {
                        X x7 = c0146w0.p;
                        C0146w0.l(x7);
                        x7.p.c("Failed to open freshly created database", e2);
                        throw e2;
                    }
                }
            default:
                try {
                    return super.getWritableDatabase();
                } catch (SQLiteDatabaseLockedException e6) {
                    throw e6;
                } catch (SQLiteException unused2) {
                    P p = (P) this.f1904l;
                    C0146w0 c0146w02 = (C0146w0) p.f29k;
                    X x8 = c0146w02.p;
                    C0146w0.l(x8);
                    x8.p.b("Opening the local database failed, dropping and recreating it");
                    if (!c0146w02.f2032k.getDatabasePath("google_app_measurement_local.db").delete()) {
                        X x9 = c0146w02.p;
                        C0146w0.l(x9);
                        x9.p.c("Failed to delete corrupted local db file", "google_app_measurement_local.db");
                    }
                    try {
                        return super.getWritableDatabase();
                    } catch (SQLiteException e7) {
                        X x10 = ((C0146w0) p.f29k).p;
                        C0146w0.l(x10);
                        x10.p.c("Failed to open local database. Events will bypass local storage", e7);
                        return null;
                    }
                }
        }
    }

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final void onCreate(SQLiteDatabase sQLiteDatabase) {
        switch (this.f1903k) {
            case 0:
                X x5 = ((C0146w0) ((C0119n) this.f1904l).f29k).p;
                C0146w0.l(x5);
                M0.f(x5, sQLiteDatabase);
                break;
            default:
                X x6 = ((C0146w0) ((P) this.f1904l).f29k).p;
                C0146w0.l(x6);
                M0.f(x6, sQLiteDatabase);
                break;
        }
    }

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final void onDowngrade(SQLiteDatabase sQLiteDatabase, int i, int i5) {
        int i6 = this.f1903k;
    }

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final void onOpen(SQLiteDatabase sQLiteDatabase) throws Throwable {
        switch (this.f1903k) {
            case 0:
                String[] strArr = C0119n.p;
                C0146w0 c0146w0 = (C0146w0) ((C0119n) this.f1904l).f29k;
                X x5 = c0146w0.p;
                C0146w0.l(x5);
                M0.c(x5, sQLiteDatabase, "events", "CREATE TABLE IF NOT EXISTS events ( app_id TEXT NOT NULL, name TEXT NOT NULL, lifetime_count INTEGER NOT NULL, current_bundle_count INTEGER NOT NULL, last_fire_timestamp INTEGER NOT NULL, PRIMARY KEY (app_id, name)) ;", "app_id,name,lifetime_count,current_bundle_count,last_fire_timestamp", strArr);
                X x6 = c0146w0.p;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "events_snapshot", "CREATE TABLE IF NOT EXISTS events_snapshot ( app_id TEXT NOT NULL, name TEXT NOT NULL, lifetime_count INTEGER NOT NULL, current_bundle_count INTEGER NOT NULL, last_fire_timestamp INTEGER NOT NULL, last_bundled_timestamp INTEGER, last_bundled_day INTEGER, last_sampled_complex_event_id INTEGER, last_sampling_rate INTEGER, last_exempt_from_sampling INTEGER, current_session_count INTEGER, PRIMARY KEY (app_id, name)) ;", "app_id,name,lifetime_count,current_bundle_count,last_fire_timestamp,last_bundled_timestamp,last_bundled_day,last_sampled_complex_event_id,last_sampling_rate,last_exempt_from_sampling,current_session_count", null);
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "conditional_properties", "CREATE TABLE IF NOT EXISTS conditional_properties ( app_id TEXT NOT NULL, origin TEXT NOT NULL, name TEXT NOT NULL, value BLOB NOT NULL, creation_timestamp INTEGER NOT NULL, active INTEGER NOT NULL, trigger_event_name TEXT, trigger_timeout INTEGER NOT NULL, timed_out_event BLOB,triggered_event BLOB, triggered_timestamp INTEGER NOT NULL, time_to_live INTEGER NOT NULL, expired_event BLOB, PRIMARY KEY (app_id, name)) ;", "app_id,origin,name,value,active,trigger_event_name,trigger_timeout,creation_timestamp,timed_out_event,triggered_event,triggered_timestamp,time_to_live,expired_event", null);
                String[] strArr2 = C0119n.f1908r;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "user_attributes", "CREATE TABLE IF NOT EXISTS user_attributes ( app_id TEXT NOT NULL, name TEXT NOT NULL, set_timestamp INTEGER NOT NULL, value BLOB NOT NULL, PRIMARY KEY (app_id, name)) ;", "app_id,name,set_timestamp,value", strArr2);
                String[] strArr3 = C0119n.f1909s;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "apps", "CREATE TABLE IF NOT EXISTS apps ( app_id TEXT NOT NULL, app_instance_id TEXT, gmp_app_id TEXT, resettable_device_id_hash TEXT, last_bundle_index INTEGER NOT NULL, last_bundle_end_timestamp INTEGER NOT NULL, PRIMARY KEY (app_id)) ;", "app_id,app_instance_id,gmp_app_id,resettable_device_id_hash,last_bundle_index,last_bundle_end_timestamp", strArr3);
                String[] strArr4 = C0119n.f1911u;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "queue", "CREATE TABLE IF NOT EXISTS queue ( app_id TEXT NOT NULL, bundle_end_timestamp INTEGER NOT NULL, data BLOB NOT NULL);", "app_id,bundle_end_timestamp,data", strArr4);
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "raw_events_metadata", "CREATE TABLE IF NOT EXISTS raw_events_metadata ( app_id TEXT NOT NULL, metadata_fingerprint INTEGER NOT NULL, metadata BLOB NOT NULL, PRIMARY KEY (app_id, metadata_fingerprint));", "app_id,metadata_fingerprint,metadata", null);
                String[] strArr5 = C0119n.f1910t;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "raw_events", "CREATE TABLE IF NOT EXISTS raw_events ( app_id TEXT NOT NULL, name TEXT NOT NULL, timestamp INTEGER NOT NULL, metadata_fingerprint INTEGER NOT NULL, data BLOB NOT NULL);", "app_id,name,timestamp,metadata_fingerprint,data", strArr5);
                String[] strArr6 = C0119n.f1912v;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "event_filters", "CREATE TABLE IF NOT EXISTS event_filters ( app_id TEXT NOT NULL, audience_id INTEGER NOT NULL, filter_id INTEGER NOT NULL, event_name TEXT NOT NULL, data BLOB NOT NULL, PRIMARY KEY (app_id, event_name, audience_id, filter_id));", "app_id,audience_id,filter_id,event_name,data", strArr6);
                String[] strArr7 = C0119n.f1913w;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "property_filters", "CREATE TABLE IF NOT EXISTS property_filters ( app_id TEXT NOT NULL, audience_id INTEGER NOT NULL, filter_id INTEGER NOT NULL, property_name TEXT NOT NULL, data BLOB NOT NULL, PRIMARY KEY (app_id, property_name, audience_id, filter_id));", "app_id,audience_id,filter_id,property_name,data", strArr7);
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "audience_filter_values", "CREATE TABLE IF NOT EXISTS audience_filter_values ( app_id TEXT NOT NULL, audience_id INTEGER NOT NULL, current_results BLOB, PRIMARY KEY (app_id, audience_id));", "app_id,audience_id,current_results", null);
                String[] strArr8 = C0119n.f1914x;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "app2", "CREATE TABLE IF NOT EXISTS app2 ( app_id TEXT NOT NULL, first_open_count INTEGER NOT NULL, PRIMARY KEY (app_id));", "app_id,first_open_count", strArr8);
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "main_event_params", "CREATE TABLE IF NOT EXISTS main_event_params ( app_id TEXT NOT NULL, event_id TEXT NOT NULL, children_to_process INTEGER NOT NULL, main_event BLOB NOT NULL, PRIMARY KEY (app_id));", "app_id,event_id,children_to_process,main_event", null);
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "default_event_params", "CREATE TABLE IF NOT EXISTS default_event_params ( app_id TEXT NOT NULL, parameters BLOB NOT NULL, PRIMARY KEY (app_id));", "app_id,parameters", null);
                String[] strArr9 = C0119n.f1915y;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "consent_settings", "CREATE TABLE IF NOT EXISTS consent_settings ( app_id TEXT NOT NULL, consent_state TEXT NOT NULL, PRIMARY KEY (app_id));", "app_id,consent_state", strArr9);
                P3.a();
                String[] strArr10 = C0119n.f1916z;
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "trigger_uris", "CREATE TABLE IF NOT EXISTS trigger_uris ( app_id TEXT NOT NULL, trigger_uri TEXT NOT NULL, timestamp_millis INTEGER NOT NULL, source INTEGER NOT NULL);", "app_id,trigger_uri,source,timestamp_millis", strArr10);
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "upload_queue", "CREATE TABLE IF NOT EXISTS upload_queue ( app_id TEXT NOT NULL, upload_uri TEXT NOT NULL, upload_headers TEXT NOT NULL, upload_type INTEGER NOT NULL, measurement_batch BLOB NOT NULL, retry_count INTEGER NOT NULL, creation_timestamp INTEGER NOT NULL );", "app_id,upload_uri,upload_headers,upload_type,measurement_batch,retry_count,creation_timestamp", C0119n.q);
                C0146w0.l(x6);
                M0.c(x6, sQLiteDatabase, "no_data_mode_events", "CREATE TABLE IF NOT EXISTS no_data_mode_events ( app_id TEXT NOT NULL, name TEXT NOT NULL, data BLOB NOT NULL, timestamp_millis INTEGER NOT NULL);", "app_id,name,data,timestamp_millis", null);
                break;
            default:
                String[] strArr11 = P.f1532o;
                X x7 = ((C0146w0) ((P) this.f1904l).f29k).p;
                C0146w0.l(x7);
                M0.c(x7, sQLiteDatabase, "messages", "create table if not exists messages ( type INTEGER NOT NULL, entry BLOB NOT NULL)", "type,entry", strArr11);
                break;
        }
    }

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i5) {
        int i6 = this.f1903k;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public C0116m(P p, Context context) {
        this(context, "google_app_measurement_local.db");
        this.f1903k = 1;
        Objects.requireNonNull(p);
        this.f1904l = p;
    }

    public C0116m(Context context, String str) {
        super(context, true == str.equals("") ? null : str, (SQLiteDatabase.CursorFactory) null, 1);
    }

    private final void a(SQLiteDatabase sQLiteDatabase, int i, int i5) {
    }

    private final void e(SQLiteDatabase sQLiteDatabase, int i, int i5) {
    }

    private final void f(SQLiteDatabase sQLiteDatabase, int i, int i5) {
    }

    private final void h(SQLiteDatabase sQLiteDatabase, int i, int i5) {
    }
}
