package com.google.android.gms.measurement.internal;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteFullException;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable;
import com.google.android.gms.common.internal.safeparcel.SafeParcelReader;
import com.google.android.gms.common.util.Clock;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes3.dex */
public final class zzgf extends zzh {
    private final zzgi zza;
    private boolean zzb;

    /* JADX INFO: Access modifiers changed from: package-private */
    public zzgf(zzhy zzhyVar) {
        super(zzhyVar);
        this.zza = new zzgi(this, zza(), "google_app_measurement_local.db");
    }

    private static long zza(SQLiteDatabase sQLiteDatabase) {
        Cursor cursor = null;
        try {
            cursor = sQLiteDatabase.query("messages", new String[]{"rowid"}, "type=?", new String[]{"3"}, null, null, "rowid desc", "1");
            if (cursor.moveToFirst()) {
                long j10 = cursor.getLong(0);
                cursor.close();
                return j10;
            }
            cursor.close();
            return -1L;
        } catch (Throwable th2) {
            if (cursor != null) {
                cursor.close();
            }
            throw th2;
        }
    }

    private final SQLiteDatabase zzad() throws SQLiteException {
        if (this.zzb) {
            return null;
        }
        SQLiteDatabase writableDatabase = this.zza.getWritableDatabase();
        if (writableDatabase != null) {
            return writableDatabase;
        }
        this.zzb = true;
        return null;
    }

    private final boolean zzae() {
        return zza().getDatabasePath("google_app_measurement_local.db").exists();
    }

    public final void zzaa() {
        int delete;
        zzt();
        try {
            SQLiteDatabase zzad = zzad();
            if (zzad == null || (delete = zzad.delete("messages", null, null) + 0) <= 0) {
                return;
            }
            zzj().zzp().zza("Reset local analytics data. records", Integer.valueOf(delete));
        } catch (SQLiteException e10) {
            zzj().zzg().zza("Error resetting local analytics data. error", e10);
        }
    }

    public final boolean zzab() {
        return zza(3, new byte[0]);
    }

    public final boolean zzac() {
        zzt();
        if (this.zzb || !zzae()) {
            return false;
        }
        int i10 = 5;
        for (int i11 = 0; i11 < 5; i11++) {
            SQLiteDatabase sQLiteDatabase = null;
            try {
                try {
                    SQLiteDatabase zzad = zzad();
                    if (zzad == null) {
                        this.zzb = true;
                        if (zzad != null) {
                            zzad.close();
                        }
                        return false;
                    }
                    zzad.beginTransaction();
                    zzad.delete("messages", "type == ?", new String[]{Integer.toString(3)});
                    zzad.setTransactionSuccessful();
                    zzad.endTransaction();
                    zzad.close();
                    return true;
                } catch (SQLiteDatabaseLockedException unused) {
                    SystemClock.sleep(i10);
                    i10 += 20;
                    if (0 != 0) {
                        sQLiteDatabase.close();
                    }
                }
            } catch (SQLiteFullException e10) {
                zzj().zzg().zza("Error deleting app launch break from local database", e10);
                this.zzb = true;
                if (0 != 0) {
                    sQLiteDatabase.close();
                }
            } catch (SQLiteException e11) {
                if (0 != 0) {
                    try {
                        if (sQLiteDatabase.inTransaction()) {
                            sQLiteDatabase.endTransaction();
                        }
                    } catch (Throwable th2) {
                        if (0 != 0) {
                            sQLiteDatabase.close();
                        }
                        throw th2;
                    }
                }
                zzj().zzg().zza("Error deleting app launch break from local database", e11);
                this.zzb = true;
                if (0 != 0) {
                    sQLiteDatabase.close();
                }
            }
        }
        zzj().zzu().zza("Error deleting app launch break from local database in reasonable time");
        return false;
    }

    @Override // com.google.android.gms.measurement.internal.zzja, com.google.android.gms.measurement.internal.zzjc
    public final /* bridge */ /* synthetic */ Clock zzb() {
        return super.zzb();
    }

    @Override // com.google.android.gms.measurement.internal.zze
    public final /* bridge */ /* synthetic */ zzb zzc() {
        return super.zzc();
    }

    @Override // com.google.android.gms.measurement.internal.zzja, com.google.android.gms.measurement.internal.zzjc
    public final /* bridge */ /* synthetic */ zzab zzd() {
        return super.zzd();
    }

    @Override // com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ zzag zze() {
        return super.zze();
    }

    @Override // com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ zzaz zzf() {
        return super.zzf();
    }

    @Override // com.google.android.gms.measurement.internal.zze
    public final /* bridge */ /* synthetic */ zzgg zzg() {
        return super.zzg();
    }

    @Override // com.google.android.gms.measurement.internal.zze
    public final /* bridge */ /* synthetic */ zzgf zzh() {
        return super.zzh();
    }

    @Override // com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ zzgh zzi() {
        return super.zzi();
    }

    @Override // com.google.android.gms.measurement.internal.zzja, com.google.android.gms.measurement.internal.zzjc
    public final /* bridge */ /* synthetic */ zzgo zzj() {
        return super.zzj();
    }

    @Override // com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ zzha zzk() {
        return super.zzk();
    }

    @Override // com.google.android.gms.measurement.internal.zzja, com.google.android.gms.measurement.internal.zzjc
    public final /* bridge */ /* synthetic */ zzhv zzl() {
        return super.zzl();
    }

    @Override // com.google.android.gms.measurement.internal.zze
    public final /* bridge */ /* synthetic */ zzjq zzm() {
        return super.zzm();
    }

    @Override // com.google.android.gms.measurement.internal.zze
    public final /* bridge */ /* synthetic */ zzlj zzn() {
        return super.zzn();
    }

    @Override // com.google.android.gms.measurement.internal.zze
    public final /* bridge */ /* synthetic */ zzls zzo() {
        return super.zzo();
    }

    @Override // com.google.android.gms.measurement.internal.zze
    public final /* bridge */ /* synthetic */ zznb zzp() {
        return super.zzp();
    }

    @Override // com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ zzos zzq() {
        return super.zzq();
    }

    @Override // com.google.android.gms.measurement.internal.zze, com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ void zzr() {
        super.zzr();
    }

    @Override // com.google.android.gms.measurement.internal.zze, com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ void zzs() {
        super.zzs();
    }

    @Override // com.google.android.gms.measurement.internal.zze, com.google.android.gms.measurement.internal.zzja
    public final /* bridge */ /* synthetic */ void zzt() {
        super.zzt();
    }

    @Override // com.google.android.gms.measurement.internal.zzh
    protected final boolean zzz() {
        return false;
    }

    @Override // com.google.android.gms.measurement.internal.zzja, com.google.android.gms.measurement.internal.zzjc
    public final /* bridge */ /* synthetic */ Context zza() {
        return super.zza();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:143:0x01e0  */
    /* JADX WARN: Removed duplicated region for block: B:145:0x01e5  */
    /* JADX WARN: Removed duplicated region for block: B:147:0x0203 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:21:0x01fb  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0200  */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0203 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:32:0x01cd  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x01d2  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0203 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:37:0x01b5 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:45:0x020d  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0212  */
    /* JADX WARN: Type inference failed for: r3v0 */
    /* JADX WARN: Type inference failed for: r3v1, types: [java.util.List<com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable>] */
    /* JADX WARN: Type inference failed for: r3v16 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r3v3, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r3v4 */
    /* JADX WARN: Type inference failed for: r3v8 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final List<AbstractSafeParcelable> zza(int i10) {
        SQLiteDatabase sQLiteDatabase;
        Cursor cursor;
        SQLiteDatabase sQLiteDatabase2;
        SQLiteDatabase sQLiteDatabase3;
        long j10;
        String str;
        String[] strArr;
        Parcel obtain;
        zzon zzonVar;
        zzae zzaeVar;
        zzt();
        ?? r32 = 0;
        if (this.zzb) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        if (!zzae()) {
            return arrayList;
        }
        int i11 = 5;
        int i12 = 0;
        for (int i13 = 5; i12 < i13; i13 = 5) {
            try {
                sQLiteDatabase = zzad();
                try {
                    if (sQLiteDatabase == null) {
                        this.zzb = true;
                        if (sQLiteDatabase != null) {
                            sQLiteDatabase.close();
                        }
                        return r32;
                    }
                    try {
                        sQLiteDatabase.beginTransaction();
                        long zza = zza(sQLiteDatabase);
                        j10 = -1;
                        if (zza != -1) {
                            try {
                                str = "rowid<?";
                                strArr = new String[]{String.valueOf(zza)};
                            } catch (SQLiteFullException e10) {
                                e = e10;
                                cursor = r32;
                                zzj().zzg().zza("Error reading entries from local database", e);
                                this.zzb = true;
                                if (cursor != null) {
                                    cursor.close();
                                }
                                if (sQLiteDatabase != null) {
                                    sQLiteDatabase.close();
                                }
                                i12++;
                                r32 = 0;
                            } catch (SQLiteException e11) {
                                e = e11;
                                cursor = r32;
                                if (sQLiteDatabase != null) {
                                    try {
                                        if (sQLiteDatabase.inTransaction()) {
                                            sQLiteDatabase.endTransaction();
                                        }
                                    } catch (Throwable th2) {
                                        th = th2;
                                        r32 = cursor;
                                        if (r32 != 0) {
                                            r32.close();
                                        }
                                        if (sQLiteDatabase != null) {
                                            sQLiteDatabase.close();
                                        }
                                        throw th;
                                    }
                                }
                                zzj().zzg().zza("Error reading entries from local database", e);
                                this.zzb = true;
                                if (cursor != null) {
                                    cursor.close();
                                }
                                if (sQLiteDatabase != null) {
                                    sQLiteDatabase.close();
                                }
                                i12++;
                                r32 = 0;
                            } catch (Throwable th3) {
                                th = th3;
                                if (r32 != 0) {
                                }
                                if (sQLiteDatabase != null) {
                                }
                                throw th;
                            }
                        } else {
                            str = r32;
                            strArr = str;
                        }
                        sQLiteDatabase3 = sQLiteDatabase;
                    } catch (SQLiteFullException e12) {
                        e = e12;
                    } catch (SQLiteException e13) {
                        e = e13;
                    } catch (Throwable th4) {
                        th = th4;
                    }
                    try {
                        cursor = sQLiteDatabase.query("messages", new String[]{"rowid", "type", "entry"}, str, strArr, null, null, "rowid asc", Integer.toString(100));
                        while (cursor.moveToNext()) {
                            try {
                                j10 = cursor.getLong(0);
                                int i14 = cursor.getInt(1);
                                byte[] blob = cursor.getBlob(2);
                                if (i14 == 0) {
                                    obtain = Parcel.obtain();
                                    try {
                                        try {
                                            obtain.unmarshall(blob, 0, blob.length);
                                            obtain.setDataPosition(0);
                                            zzbf createFromParcel = zzbf.CREATOR.createFromParcel(obtain);
                                            if (createFromParcel != null) {
                                                arrayList.add(createFromParcel);
                                            }
                                        } finally {
                                        }
                                    } catch (SafeParcelReader.ParseException unused) {
                                        zzj().zzg().zza("Failed to load event from local database");
                                        obtain.recycle();
                                    }
                                } else if (i14 == 1) {
                                    obtain = Parcel.obtain();
                                    try {
                                        try {
                                            obtain.unmarshall(blob, 0, blob.length);
                                            obtain.setDataPosition(0);
                                            zzonVar = zzon.CREATOR.createFromParcel(obtain);
                                        } finally {
                                        }
                                    } catch (SafeParcelReader.ParseException unused2) {
                                        zzj().zzg().zza("Failed to load user property from local database");
                                        obtain.recycle();
                                        zzonVar = null;
                                    }
                                    if (zzonVar != null) {
                                        arrayList.add(zzonVar);
                                    }
                                } else if (i14 == 2) {
                                    obtain = Parcel.obtain();
                                    try {
                                        try {
                                            obtain.unmarshall(blob, 0, blob.length);
                                            obtain.setDataPosition(0);
                                            zzaeVar = zzae.CREATOR.createFromParcel(obtain);
                                        } catch (SafeParcelReader.ParseException unused3) {
                                            zzj().zzg().zza("Failed to load conditional user property from local database");
                                            obtain.recycle();
                                            zzaeVar = null;
                                        }
                                        if (zzaeVar != null) {
                                            arrayList.add(zzaeVar);
                                        }
                                    } finally {
                                    }
                                } else if (i14 == 3) {
                                    zzj().zzu().zza("Skipping app launch break");
                                } else {
                                    zzj().zzg().zza("Unknown record type in local database");
                                }
                            } catch (SQLiteDatabaseLockedException unused4) {
                                sQLiteDatabase2 = sQLiteDatabase3;
                                SystemClock.sleep(i11);
                                i11 += 20;
                                if (cursor != null) {
                                    cursor.close();
                                }
                                if (sQLiteDatabase2 == null) {
                                    sQLiteDatabase2.close();
                                }
                                i12++;
                                r32 = 0;
                            } catch (SQLiteFullException e14) {
                                e = e14;
                                sQLiteDatabase = sQLiteDatabase3;
                                zzj().zzg().zza("Error reading entries from local database", e);
                                this.zzb = true;
                                if (cursor != null) {
                                }
                                if (sQLiteDatabase != null) {
                                }
                                i12++;
                                r32 = 0;
                            } catch (SQLiteException e15) {
                                e = e15;
                                sQLiteDatabase = sQLiteDatabase3;
                                if (sQLiteDatabase != null) {
                                }
                                zzj().zzg().zza("Error reading entries from local database", e);
                                this.zzb = true;
                                if (cursor != null) {
                                }
                                if (sQLiteDatabase != null) {
                                }
                                i12++;
                                r32 = 0;
                            } catch (Throwable th5) {
                                th = th5;
                                sQLiteDatabase = sQLiteDatabase3;
                                r32 = cursor;
                                if (r32 != 0) {
                                }
                                if (sQLiteDatabase != null) {
                                }
                                throw th;
                            }
                        }
                        if (sQLiteDatabase3.delete("messages", "rowid <= ?", new String[]{Long.toString(j10)}) < arrayList.size()) {
                            zzj().zzg().zza("Fewer entries removed from local database than expected");
                        }
                        sQLiteDatabase3.setTransactionSuccessful();
                        sQLiteDatabase3.endTransaction();
                        cursor.close();
                        sQLiteDatabase3.close();
                        return arrayList;
                    } catch (SQLiteDatabaseLockedException unused5) {
                        sQLiteDatabase2 = sQLiteDatabase3;
                        cursor = null;
                        SystemClock.sleep(i11);
                        i11 += 20;
                        if (cursor != null) {
                        }
                        if (sQLiteDatabase2 == null) {
                        }
                        i12++;
                        r32 = 0;
                    } catch (SQLiteFullException e16) {
                        e = e16;
                        sQLiteDatabase = sQLiteDatabase3;
                        cursor = null;
                        zzj().zzg().zza("Error reading entries from local database", e);
                        this.zzb = true;
                        if (cursor != null) {
                        }
                        if (sQLiteDatabase != null) {
                        }
                        i12++;
                        r32 = 0;
                    } catch (SQLiteException e17) {
                        e = e17;
                        sQLiteDatabase = sQLiteDatabase3;
                        cursor = null;
                        if (sQLiteDatabase != null) {
                        }
                        zzj().zzg().zza("Error reading entries from local database", e);
                        this.zzb = true;
                        if (cursor != null) {
                        }
                        if (sQLiteDatabase != null) {
                        }
                        i12++;
                        r32 = 0;
                    } catch (Throwable th6) {
                        th = th6;
                        sQLiteDatabase = sQLiteDatabase3;
                        r32 = 0;
                        if (r32 != 0) {
                        }
                        if (sQLiteDatabase != null) {
                        }
                        throw th;
                    }
                } catch (SQLiteDatabaseLockedException unused6) {
                    sQLiteDatabase3 = sQLiteDatabase;
                }
            } catch (SQLiteDatabaseLockedException unused7) {
                cursor = null;
                sQLiteDatabase2 = null;
            } catch (SQLiteFullException e18) {
                e = e18;
                cursor = null;
                sQLiteDatabase = null;
            } catch (SQLiteException e19) {
                e = e19;
                cursor = null;
                sQLiteDatabase = null;
            } catch (Throwable th7) {
                th = th7;
                r32 = 0;
                sQLiteDatabase = null;
            }
        }
        zzj().zzu().zza("Failed to read events from database in reasonable time");
        return null;
    }

    public final boolean zza(zzae zzaeVar) {
        zzq();
        byte[] zza = zzos.zza((Parcelable) zzaeVar);
        if (zza.length > 131072) {
            zzj().zzn().zza("Conditional user property too long for local database. Sending directly to service");
            return false;
        }
        return zza(2, zza);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:17:0x005f A[Catch: all -> 0x004b, SQLiteException -> 0x004e, SQLiteFullException -> 0x0050, SQLiteDatabaseLockedException -> 0x00b0, TRY_ENTER, TryCatch #7 {SQLiteDatabaseLockedException -> 0x00b0, SQLiteFullException -> 0x0050, SQLiteException -> 0x004e, all -> 0x004b, blocks: (B:74:0x0040, B:76:0x0046, B:17:0x005f, B:19:0x0083, B:20:0x009d), top: B:73:0x0040 }] */
    /* JADX WARN: Removed duplicated region for block: B:45:0x011e  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0123  */
    /* JADX WARN: Removed duplicated region for block: B:70:0x00a8  */
    /* JADX WARN: Type inference failed for: r10v0 */
    /* JADX WARN: Type inference failed for: r10v1 */
    /* JADX WARN: Type inference failed for: r10v2, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r10v4 */
    /* JADX WARN: Type inference failed for: r10v5 */
    /* JADX WARN: Type inference failed for: r10v6, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r10v7 */
    /* JADX WARN: Type inference failed for: r2v0 */
    /* JADX WARN: Type inference failed for: r2v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r2v9 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final boolean zza(int i10, byte[] bArr) {
        SQLiteDatabase sQLiteDatabase;
        ?? r10;
        long j10;
        zzt();
        ?? r22 = 0;
        if (this.zzb) {
            return false;
        }
        ContentValues contentValues = new ContentValues();
        contentValues.put("type", Integer.valueOf(i10));
        contentValues.put("entry", bArr);
        int i11 = 0;
        int i12 = 5;
        for (int i13 = 5; i11 < i13; i13 = 5) {
            Cursor cursor = null;
            r7 = null;
            cursor = null;
            Cursor cursor2 = null;
            cursor = null;
            SQLiteDatabase sQLiteDatabase2 = null;
            try {
                sQLiteDatabase = zzad();
                try {
                    if (sQLiteDatabase == null) {
                        this.zzb = true;
                        if (sQLiteDatabase != null) {
                            sQLiteDatabase.close();
                        }
                        return r22;
                    }
                    sQLiteDatabase.beginTransaction();
                    r10 = sQLiteDatabase.rawQuery("select count(1) from messages", null);
                    if (r10 != 0) {
                        try {
                            if (r10.moveToFirst()) {
                                j10 = r10.getLong(r22);
                                if (j10 >= 100000) {
                                    zzj().zzg().zza("Data loss, local db full");
                                    long j11 = (100000 - j10) + 1;
                                    String[] strArr = new String[1];
                                    strArr[r22] = Long.toString(j11);
                                    long delete = sQLiteDatabase.delete("messages", "rowid in (select rowid from messages order by rowid asc limit ?)", strArr);
                                    if (delete != j11) {
                                        zzj().zzg().zza("Different delete count than expected in local db. expected, received, difference", Long.valueOf(j11), Long.valueOf(delete), Long.valueOf(j11 - delete));
                                    }
                                }
                                sQLiteDatabase.insertOrThrow("messages", null, contentValues);
                                sQLiteDatabase.setTransactionSuccessful();
                                sQLiteDatabase.endTransaction();
                                if (r10 != 0) {
                                    r10.close();
                                }
                                sQLiteDatabase.close();
                                return true;
                            }
                        } catch (SQLiteDatabaseLockedException unused) {
                            cursor2 = r10;
                            SystemClock.sleep(i12);
                            i12 += 20;
                            if (cursor2 != null) {
                                cursor2.close();
                            }
                            if (sQLiteDatabase != null) {
                                sQLiteDatabase.close();
                            }
                            i11++;
                            r22 = 0;
                        } catch (SQLiteFullException e10) {
                            e = e10;
                            cursor = r10;
                            try {
                                zzj().zzg().zza("Error writing entry; local database full", e);
                                this.zzb = true;
                                if (cursor != null) {
                                    cursor.close();
                                }
                                if (sQLiteDatabase != null) {
                                    sQLiteDatabase.close();
                                }
                                i11++;
                                r22 = 0;
                            } catch (Throwable th2) {
                                th = th2;
                                if (cursor != null) {
                                }
                                if (sQLiteDatabase != null) {
                                }
                                throw th;
                            }
                        } catch (SQLiteException e11) {
                            e = e11;
                            sQLiteDatabase2 = sQLiteDatabase;
                            r10 = r10;
                            if (sQLiteDatabase2 != null) {
                                try {
                                    if (sQLiteDatabase2.inTransaction()) {
                                        sQLiteDatabase2.endTransaction();
                                    }
                                } catch (Throwable th3) {
                                    th = th3;
                                    sQLiteDatabase = sQLiteDatabase2;
                                    cursor = r10;
                                    if (cursor != null) {
                                        cursor.close();
                                    }
                                    if (sQLiteDatabase != null) {
                                        sQLiteDatabase.close();
                                    }
                                    throw th;
                                }
                            }
                            zzj().zzg().zza("Error writing entry to local database", e);
                            this.zzb = true;
                            if (r10 != 0) {
                                r10.close();
                            }
                            if (sQLiteDatabase2 != null) {
                                sQLiteDatabase2.close();
                            }
                            i11++;
                            r22 = 0;
                        } catch (Throwable th4) {
                            th = th4;
                            cursor = r10;
                            if (cursor != null) {
                            }
                            if (sQLiteDatabase != null) {
                            }
                            throw th;
                        }
                    }
                    j10 = 0;
                    if (j10 >= 100000) {
                    }
                    sQLiteDatabase.insertOrThrow("messages", null, contentValues);
                    sQLiteDatabase.setTransactionSuccessful();
                    sQLiteDatabase.endTransaction();
                    if (r10 != 0) {
                    }
                    sQLiteDatabase.close();
                    return true;
                } catch (SQLiteDatabaseLockedException unused2) {
                } catch (SQLiteFullException e12) {
                    e = e12;
                } catch (SQLiteException e13) {
                    e = e13;
                    r10 = 0;
                }
            } catch (SQLiteDatabaseLockedException unused3) {
                sQLiteDatabase = null;
            } catch (SQLiteFullException e14) {
                e = e14;
                sQLiteDatabase = null;
            } catch (SQLiteException e15) {
                e = e15;
                r10 = 0;
            } catch (Throwable th5) {
                th = th5;
                sQLiteDatabase = null;
                if (cursor != null) {
                }
                if (sQLiteDatabase != null) {
                }
                throw th;
            }
        }
        zzj().zzp().zza("Failed to write entry to local database");
        return false;
    }

    public final boolean zza(zzbf zzbfVar) {
        Parcel obtain = Parcel.obtain();
        zzbfVar.writeToParcel(obtain, 0);
        byte[] marshall = obtain.marshall();
        obtain.recycle();
        if (marshall.length > 131072) {
            zzj().zzn().zza("Event is too long for local database. Sending event directly to service");
            return false;
        }
        return zza(0, marshall);
    }

    public final boolean zza(zzon zzonVar) {
        Parcel obtain = Parcel.obtain();
        zzonVar.writeToParcel(obtain, 0);
        byte[] marshall = obtain.marshall();
        obtain.recycle();
        if (marshall.length > 131072) {
            zzj().zzn().zza("User property too long for local database. Sending directly to service");
            return false;
        }
        return zza(1, marshall);
    }
}
