package d3;

import N1.C0207h;
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.J3;

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

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final /* synthetic */ O3.e f12048r;

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public C0802m(C0805n c0805n, Context context) {
        this(context, "google_app_measurement.db");
        this.f12047q = 0;
        this.f12048r = c0805n;
    }

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final SQLiteDatabase getWritableDatabase() {
        switch (this.f12047q) {
            case n4.u0.f15495q /* 0 */:
                C0805n c0805n = (C0805n) this.f12048r;
                C0207h c0207h = c0805n.f12071u;
                C0817r0 c0817r0 = (C0817r0) c0805n.f5146q;
                c0817r0.getClass();
                if (c0207h.f4547r != 0) {
                    ((T2.a) c0207h.f4548s).getClass();
                    if (SystemClock.elapsedRealtime() - c0207h.f4547r < 3600000) {
                        throw new SQLiteException("Database open failed");
                    }
                }
                try {
                    return super.getWritableDatabase();
                } catch (SQLiteException unused) {
                    C0207h c0207h2 = c0805n.f12071u;
                    ((T2.a) c0207h2.f4548s).getClass();
                    c0207h2.f4547r = SystemClock.elapsedRealtime();
                    Z z8 = c0817r0.f12150y;
                    C0817r0.k(z8);
                    z8.f11875v.b("Opening the database failed, dropping and recreating it");
                    if (!c0817r0.f12142q.getDatabasePath("google_app_measurement.db").delete()) {
                        Z z9 = c0817r0.f12150y;
                        C0817r0.k(z9);
                        z9.f11875v.c("google_app_measurement.db", "Failed to delete corrupted db file");
                    }
                    try {
                        SQLiteDatabase writableDatabase = super.getWritableDatabase();
                        c0207h2.f4547r = 0L;
                        return writableDatabase;
                    } catch (SQLiteException e8) {
                        Z z10 = c0817r0.f12150y;
                        C0817r0.k(z10);
                        z10.f11875v.c(e8, "Failed to open freshly created database");
                        throw e8;
                    }
                }
            default:
                try {
                    return super.getWritableDatabase();
                } catch (SQLiteDatabaseLockedException e9) {
                    throw e9;
                } catch (SQLiteException unused2) {
                    S s8 = (S) this.f12048r;
                    C0817r0 c0817r02 = (C0817r0) s8.f5146q;
                    Z z11 = c0817r02.f12150y;
                    C0817r0.k(z11);
                    z11.f11875v.b("Opening the local database failed, dropping and recreating it");
                    if (!c0817r02.f12142q.getDatabasePath("google_app_measurement_local.db").delete()) {
                        Z z12 = c0817r02.f12150y;
                        C0817r0.k(z12);
                        z12.f11875v.c("google_app_measurement_local.db", "Failed to delete corrupted local db file");
                    }
                    try {
                        return super.getWritableDatabase();
                    } catch (SQLiteException e10) {
                        Z z13 = ((C0817r0) s8.f5146q).f12150y;
                        C0817r0.k(z13);
                        z13.f11875v.c(e10, "Failed to open local database. Events will bypass local storage");
                        return null;
                    }
                }
        }
    }

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final void onCreate(SQLiteDatabase sQLiteDatabase) {
        switch (this.f12047q) {
            case n4.u0.f15495q /* 0 */:
                Z z8 = ((C0817r0) ((C0805n) this.f12048r).f5146q).f12150y;
                C0817r0.k(z8);
                G0.f(z8, sQLiteDatabase);
                break;
            default:
                Z z9 = ((C0817r0) ((S) this.f12048r).f5146q).f12150y;
                C0817r0.k(z9);
                G0.f(z9, sQLiteDatabase);
                break;
        }
    }

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

    @Override // android.database.sqlite.SQLiteOpenHelper
    public final void onOpen(SQLiteDatabase sQLiteDatabase) throws Throwable {
        switch (this.f12047q) {
            case n4.u0.f15495q /* 0 */:
                C0817r0 c0817r0 = (C0817r0) ((C0805n) this.f12048r).f5146q;
                Z z8 = c0817r0.f12150y;
                C0817r0.k(z8);
                G0.c(z8, 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", C0805n.f12065v);
                Z z9 = c0817r0.f12150y;
                C0817r0.k(z9);
                G0.c(z9, 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);
                C0817r0.k(z9);
                G0.c(z9, 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);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12067x);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12068y);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12060A);
                C0817r0.k(z9);
                G0.c(z9, 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);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12069z);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12061B);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12062C);
                C0817r0.k(z9);
                G0.c(z9, 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);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.D);
                C0817r0.k(z9);
                G0.c(z9, 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);
                C0817r0.k(z9);
                G0.c(z9, 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);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12063E);
                J3.b();
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12064F);
                C0817r0.k(z9);
                G0.c(z9, 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", C0805n.f12066w);
                break;
            default:
                Z z10 = ((C0817r0) ((S) this.f12048r).f5146q).f12150y;
                C0817r0.k(z10);
                G0.c(z10, sQLiteDatabase, "messages", "create table if not exists messages ( type INTEGER NOT NULL, entry BLOB NOT NULL)", "type,entry", S.f11702u);
                break;
        }
    }

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

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public C0802m(S s8, Context context) {
        this(context, "google_app_measurement_local.db");
        this.f12047q = 1;
        this.f12048r = s8;
    }

    public C0802m(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 b(SQLiteDatabase sQLiteDatabase, int i, int i5) {
    }

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

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