package o;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import com.google.android.gms.common.internal.Preconditions;
import java.util.ArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Or0 implements Runnable {
    public final /* synthetic */ int l;
    public final /* synthetic */ C1531iw0 m;
    public final /* synthetic */ BinderC1237fs0 n;

    public /* synthetic */ Or0(BinderC1237fs0 binderC1237fs0, C1531iw0 c1531iw0, int i) {
        this.l = i;
        this.m = c1531iw0;
        this.n = binderC1237fs0;
    }

    @Override // java.lang.Runnable
    public final void run() throws Throwable {
        switch (this.l) {
            case 0:
                BinderC1237fs0 binderC1237fs0 = this.n;
                binderC1237fs0.d.B();
                binderC1237fs0.d.X(this.m);
                break;
            case 1:
                BinderC1237fs0 binderC1237fs02 = this.n;
                binderC1237fs02.d.B();
                C1051dv0 c1051dv0 = binderC1237fs02.d;
                c1051dv0.c().r();
                c1051dv0.k0();
                C1531iw0 c1531iw0 = this.m;
                Preconditions.checkNotNull(c1531iw0);
                String str = c1531iw0.l;
                Preconditions.checkNotEmpty(str);
                int i = 0;
                if (c1051dv0.d0().C(null, AbstractC1900mq0.z0)) {
                    long jCurrentTimeMillis = c1051dv0.e().currentTimeMillis();
                    int iA = c1051dv0.d0().A(null, AbstractC1900mq0.i0);
                    c1051dv0.d0();
                    long jLongValue = jCurrentTimeMillis - ((Long) AbstractC1900mq0.e.a(null)).longValue();
                    while (i < iA && c1051dv0.I(null, jLongValue)) {
                        i++;
                    }
                } else {
                    c1051dv0.d0();
                    long jIntValue = ((Integer) AbstractC1900mq0.l.a(null)).intValue();
                    while (i < jIntValue && c1051dv0.I(str, 0L)) {
                        i++;
                    }
                }
                if (c1051dv0.d0().C(null, AbstractC1900mq0.A0)) {
                    c1051dv0.c().r();
                    c1051dv0.H();
                }
                Mu0 mu0 = c1051dv0.j;
                Wr0 wr0A = Wr0.a(c1531iw0.P);
                mu0.r();
                if (wr0A == Wr0.n && !Mu0.v(str)) {
                    C2851wr0 c2851wr0 = mu0.b.a;
                    C1051dv0.T(c2851wr0);
                    Dq0 dq0E = c2851wr0.E(str);
                    if (dq0E != null && dq0E.D() && !dq0E.E().q().isEmpty()) {
                        c1051dv0.b().n.c(str, "[sgtm] Going background, trigger client side upload. appId");
                        c1051dv0.r(str, c1051dv0.e().currentTimeMillis());
                        break;
                    }
                }
                break;
            case 2:
                BinderC1237fs0 binderC1237fs03 = this.n;
                binderC1237fs03.d.B();
                C1051dv0 c1051dv02 = binderC1237fs03.d;
                c1051dv02.c().r();
                c1051dv02.k0();
                C1531iw0 c1531iw02 = this.m;
                Preconditions.checkNotEmpty(c1531iw02.l);
                c1051dv02.b0(c1531iw02);
                break;
            case 3:
                BinderC1237fs0 binderC1237fs04 = this.n;
                binderC1237fs04.d.B();
                C1051dv0 c1051dv03 = binderC1237fs04.d;
                if (c1051dv03.y != null) {
                    ArrayList arrayList = new ArrayList();
                    c1051dv03.z = arrayList;
                    arrayList.addAll(c1051dv03.y);
                }
                C2940xo0 c2940xo0 = c1051dv03.c;
                C1051dv0.T(c2940xo0);
                Kr0 kr0 = (Kr0) c2940xo0.a;
                C1531iw0 c1531iw03 = this.m;
                String str2 = (String) Preconditions.checkNotNull(c1531iw03.l);
                Preconditions.checkNotEmpty(str2);
                c2940xo0.r();
                c2940xo0.t();
                try {
                    SQLiteDatabase sQLiteDatabaseH0 = c2940xo0.h0();
                    String[] strArr = {str2};
                    int iDelete = sQLiteDatabaseH0.delete("apps", "app_id=?", strArr) + sQLiteDatabaseH0.delete("events", "app_id=?", strArr) + sQLiteDatabaseH0.delete("events_snapshot", "app_id=?", strArr) + sQLiteDatabaseH0.delete("user_attributes", "app_id=?", strArr) + sQLiteDatabaseH0.delete("conditional_properties", "app_id=?", strArr) + sQLiteDatabaseH0.delete("raw_events", "app_id=?", strArr) + sQLiteDatabaseH0.delete("raw_events_metadata", "app_id=?", strArr) + sQLiteDatabaseH0.delete("queue", "app_id=?", strArr) + sQLiteDatabaseH0.delete("audience_filter_values", "app_id=?", strArr) + sQLiteDatabaseH0.delete("main_event_params", "app_id=?", strArr) + sQLiteDatabaseH0.delete("default_event_params", "app_id=?", strArr) + sQLiteDatabaseH0.delete("trigger_uris", "app_id=?", strArr) + sQLiteDatabaseH0.delete("upload_queue", "app_id=?", strArr);
                    if (kr0.d.C(null, AbstractC1900mq0.h1)) {
                        iDelete += sQLiteDatabaseH0.delete("no_data_mode_events", "app_id=?", strArr);
                    }
                    if (iDelete > 0) {
                        Nq0 nq0 = kr0.f;
                        Kr0.l(nq0);
                        nq0.n.d("Reset analytics data. app, records", str2, Integer.valueOf(iDelete));
                    }
                } catch (SQLiteException e) {
                    Nq0 nq02 = kr0.f;
                    Kr0.l(nq02);
                    nq02.f.d("Error resetting analytics data. appId, error", Nq0.A(str2), e);
                }
                if (c1531iw03.s) {
                    c1051dv03.X(c1531iw03);
                    break;
                }
                break;
            case 4:
                BinderC1237fs0 binderC1237fs05 = this.n;
                binderC1237fs05.d.B();
                C1051dv0 c1051dv04 = binderC1237fs05.d;
                c1051dv04.c().r();
                c1051dv04.k0();
                C1531iw0 c1531iw04 = this.m;
                Preconditions.checkNotEmpty(c1531iw04.l);
                c1051dv04.l0(c1531iw04);
                c1051dv04.m0(c1531iw04);
                break;
            case 5:
                C1051dv0 c1051dv05 = this.n.d;
                c1051dv05.B();
                c1051dv05.m0(this.m);
                break;
            default:
                C1051dv0 c1051dv06 = this.n.d;
                c1051dv06.B();
                c1051dv06.l0(this.m);
                break;
        }
    }
}
