package d3;

import android.os.Bundle;
import android.os.SystemClock;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/* JADX INFO: renamed from: d3.j1, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0795j1 extends F {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public boolean f12018A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final Object f12019B;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public volatile C0786g1 f12020s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public volatile C0786g1 f12021t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public C0786g1 f12022u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final ConcurrentHashMap f12023v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public com.google.android.gms.internal.measurement.W f12024w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public volatile boolean f12025x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public volatile C0786g1 f12026y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public C0786g1 f12027z;

    public C0795j1(C0817r0 c0817r0) {
        super(c0817r0);
        this.f12019B = new Object();
        this.f12023v = new ConcurrentHashMap();
    }

    @Override // d3.F
    public final boolean H() {
        return false;
    }

    public final void I(String str, C0786g1 c0786g1, boolean z8) {
        C0786g1 c0786g12;
        C0786g1 c0786g13 = this.f12020s == null ? this.f12021t : this.f12020s;
        if (c0786g1.f11980b == null) {
            c0786g12 = new C0786g1(c0786g1.f11979a, str != null ? M(str) : null, c0786g1.f11981c, c0786g1.f11983e, c0786g1.f11984f);
        } else {
            c0786g12 = c0786g1;
        }
        this.f12021t = this.f12020s;
        this.f12020s = c0786g12;
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        c0817r0.D.getClass();
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        C0815q0 c0815q0 = c0817r0.f12151z;
        C0817r0.k(c0815q0);
        c0815q0.O(new RunnableC0789h1(this, c0786g12, c0786g13, jElapsedRealtime, z8));
    }

    /* JADX WARN: Removed duplicated region for block: B:10:0x002d  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00b8  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void J(C0786g1 c0786g1, C0786g1 c0786g12, long j8, boolean z8, Bundle bundle) {
        boolean z9;
        long j9;
        E();
        boolean z10 = false;
        if (c0786g12 != null) {
            z9 = (c0786g12.f11981c == c0786g1.f11981c && Objects.equals(c0786g12.f11980b, c0786g1.f11980b) && Objects.equals(c0786g12.f11979a, c0786g1.f11979a)) ? false : true;
        }
        if (z8 && this.f12022u != null) {
            z10 = true;
        }
        boolean z11 = c0786g1.f11983e;
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (z9) {
            Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
            W1.U(c0786g1, bundle2, true);
            if (c0786g12 != null) {
                String str = c0786g12.f11979a;
                if (str != null) {
                    bundle2.putString("_pn", str);
                }
                String str2 = c0786g12.f11980b;
                if (str2 != null) {
                    bundle2.putString("_pc", str2);
                }
                bundle2.putLong("_pi", c0786g12.f11981c);
            }
            if (z10) {
                A1 a1 = c0817r0.f12121A;
                C0817r0.j(a1);
                L0.X x8 = a1.f11427v;
                j9 = 0;
                long j10 = j8 - x8.f3744r;
                x8.f3744r = j8;
                if (j10 > 0) {
                    W1 w12 = c0817r0.f12122B;
                    C0817r0.i(w12);
                    w12.S(bundle2, j10);
                }
            } else {
                j9 = 0;
            }
            if (!c0817r0.f12148w.S()) {
                bundle2.putLong("_mst", 1L);
            }
            String str3 = true != z11 ? "auto" : "app";
            c0817r0.D.getClass();
            long jCurrentTimeMillis = System.currentTimeMillis();
            if (z11) {
                long j11 = c0786g1.f11984f;
                long j12 = j11 == j9 ? jCurrentTimeMillis : j11;
                Y0 y02 = c0817r0.f12125F;
                C0817r0.j(y02);
                y02.Q(j12, bundle2, str3, "_vs");
            }
        }
        if (z10) {
            K(this.f12022u, true, j8);
        }
        this.f12022u = c0786g1;
        if (z11) {
            this.f12027z = c0786g1;
        }
        C0824t1 c0824t1R = c0817r0.r();
        c0824t1R.E();
        c0824t1R.F();
        c0824t1R.V(new G3.b(c0824t1R, c0786g1, 17, false));
    }

    public final void K(C0786g1 c0786g1, boolean z8, long j8) {
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        C0764A c0764a = c0817r0.f12126G;
        C0817r0.h(c0764a);
        c0817r0.D.getClass();
        c0764a.H(SystemClock.elapsedRealtime());
        boolean z9 = c0786g1 != null && c0786g1.f11982d;
        A1 a1 = c0817r0.f12121A;
        C0817r0.j(a1);
        if (!a1.f11427v.a(z9, z8, j8) || c0786g1 == null) {
            return;
        }
        c0786g1.f11982d = false;
    }

    public final C0786g1 L(boolean z8) {
        F();
        E();
        if (!z8) {
            return this.f12022u;
        }
        C0786g1 c0786g1 = this.f12022u;
        return c0786g1 != null ? c0786g1 : this.f12027z;
    }

    public final String M(String str) {
        if (str == null) {
            return "Activity";
        }
        String[] strArrSplit = str.split("\\.");
        int length = strArrSplit.length;
        String str2 = length > 0 ? strArrSplit[length - 1] : "";
        int length2 = str2.length();
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        c0817r0.f12148w.getClass();
        if (length2 <= 500) {
            return str2;
        }
        c0817r0.f12148w.getClass();
        return str2.substring(0, 500);
    }

    public final void N(com.google.android.gms.internal.measurement.W w4, Bundle bundle) {
        Bundle bundle2;
        if (!((C0817r0) this.f5146q).f12148w.S() || bundle == null || (bundle2 = bundle.getBundle("com.google.app_measurement.screen_service")) == null) {
            return;
        }
        this.f12023v.put(Integer.valueOf(w4.f9767q), new C0786g1(bundle2.getLong("id"), bundle2.getString("name"), bundle2.getString("referrer_name")));
    }

    public final C0786g1 O(com.google.android.gms.internal.measurement.W w4) {
        P2.w.f(w4);
        Integer numValueOf = Integer.valueOf(w4.f9767q);
        ConcurrentHashMap concurrentHashMap = this.f12023v;
        C0786g1 c0786g1 = (C0786g1) concurrentHashMap.get(numValueOf);
        if (c0786g1 == null) {
            String strM = M(w4.f9768r);
            W1 w12 = ((C0817r0) this.f5146q).f12122B;
            C0817r0.i(w12);
            C0786g1 c0786g12 = new C0786g1(w12.P0(), null, strM);
            concurrentHashMap.put(numValueOf, c0786g12);
            c0786g1 = c0786g12;
        }
        return this.f12026y != null ? this.f12026y : c0786g1;
    }
}
