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

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import xyz.stream.download.config.InnerConstant;

/* JADX INFO: loaded from: classes2.dex */
public final class w2 extends x0 {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public volatile x2 f21959c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public volatile x2 f21960d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public x2 f21961e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public Activity f21963g;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public volatile x2 f21965i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public x2 f21966j;

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

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

    public w2(m1 m1Var) {
        super(m1Var);
        this.f21968l = new Object();
        this.f21962f = new ConcurrentHashMap();
    }

    @Override // com.google.android.gms.measurement.internal.x0
    public final boolean F() {
        return false;
    }

    public final x2 G(boolean z10) {
        D();
        w();
        if (!z10) {
            return this.f21961e;
        }
        x2 x2Var = this.f21961e;
        return x2Var != null ? x2Var : this.f21966j;
    }

    public final String H(Class cls) {
        String canonicalName = cls.getCanonicalName();
        if (canonicalName == null) {
            return "Activity";
        }
        String[] strArrSplit = canonicalName.split("\\.");
        String str = strArrSplit.length > 0 ? strArrSplit[strArrSplit.length - 1] : "";
        return str.length() > s().y(null, false) ? str.substring(0, s().y(null, false)) : str;
    }

    public final void I(Activity activity, Bundle bundle) {
        Bundle bundle2;
        if (!s().L() || bundle == null || (bundle2 = bundle.getBundle("com.google.app_measurement.screen_service")) == null) {
            return;
        }
        this.f21962f.put(Integer.valueOf(activity.hashCode()), new x2(bundle2.getString("name"), bundle2.getString("referrer_name"), bundle2.getLong(InnerConstant.Db.f36069id)));
    }

    public final void J(Activity activity, x2 x2Var, boolean z10) {
        x2 x2Var2;
        x2 x2Var3 = this.f21959c == null ? this.f21960d : this.f21959c;
        if (x2Var.zzb == null) {
            x2Var2 = new x2(x2Var.zza, activity != null ? H(activity.getClass()) : null, x2Var.f21977a, x2Var.f21979c, x2Var.f21980d);
        } else {
            x2Var2 = x2Var;
        }
        this.f21960d = this.f21959c;
        this.f21959c = x2Var2;
        ((i8.d) zzb()).getClass();
        zzl().I(new r2(this, x2Var2, x2Var3, SystemClock.elapsedRealtime(), z10));
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x002f  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00b5  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void K(x2 x2Var, x2 x2Var2, long j10, boolean z10, Bundle bundle) {
        boolean z11;
        w();
        boolean z12 = false;
        if (x2Var2 != null) {
            z11 = (x2Var2.f21977a == x2Var.f21977a && Objects.equals(x2Var2.zzb, x2Var.zzb) && Objects.equals(x2Var2.zza, x2Var.zza)) ? false : true;
        }
        if (z10 && this.f21961e != null) {
            z12 = true;
        }
        if (z11) {
            Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
            n4.X(x2Var, bundle2, true);
            if (x2Var2 != null) {
                String str = x2Var2.zza;
                if (str != null) {
                    bundle2.putString("_pn", str);
                }
                String str2 = x2Var2.zzb;
                if (str2 != null) {
                    bundle2.putString("_pc", str2);
                }
                bundle2.putLong("_pi", x2Var2.f21977a);
            }
            if (z12) {
                xyz.stream.utils.k0 k0Var = C().f21780f;
                long j11 = j10 - k0Var.f36159c;
                k0Var.f36159c = j10;
                if (j11 > 0) {
                    v().N(bundle2, j11);
                }
            }
            if (!s().L()) {
                bundle2.putLong("_mst", 1L);
            }
            String str3 = x2Var.f21979c ? "app" : "auto";
            ((i8.d) zzb()).getClass();
            long jCurrentTimeMillis = System.currentTimeMillis();
            if (x2Var.f21979c) {
                long j12 = x2Var.f21980d;
                if (j12 == 0) {
                    j12 = jCurrentTimeMillis;
                }
                z().Q(str3, "_vs", bundle2, j12);
            }
        }
        if (z12) {
            L(this.f21961e, true, j10);
        }
        this.f21961e = x2Var;
        if (x2Var.f21979c) {
            this.f21966j = x2Var;
        }
        a3 a3VarB = B();
        a3VarB.w();
        a3VarB.D();
        a3VarB.I(new s1(a3VarB, x2Var, 9));
    }

    public final void L(x2 x2Var, boolean z10, long j10) {
        s sVarH = ((m1) this.f31277a).h();
        ((i8.d) zzb()).getClass();
        sVarH.D(SystemClock.elapsedRealtime());
        if (!C().f21780f.d(j10, x2Var != null && x2Var.f21978b, z10) || x2Var == null) {
            return;
        }
        x2Var.f21978b = false;
    }

    public final x2 M(Activity activity) {
        com.google.android.gms.common.internal.w.checkNotNull(activity);
        x2 x2Var = (x2) this.f21962f.get(Integer.valueOf(activity.hashCode()));
        if (x2Var == null) {
            x2 x2Var2 = new x2(null, H(activity.getClass()), v().F0());
            this.f21962f.put(Integer.valueOf(activity.hashCode()), x2Var2);
            x2Var = x2Var2;
        }
        return this.f21965i != null ? this.f21965i : x2Var;
    }
}
