package d3;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class X0 implements Application.ActivityLifecycleCallbacks {

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

    public X0(Y0 y02) {
        this.f11809q = y02;
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0047 A[Catch: all -> 0x0026, RuntimeException -> 0x0029, TryCatch #1 {RuntimeException -> 0x0029, blocks: (B:3:0x0007, B:5:0x0017, B:7:0x001d, B:22:0x0047, B:25:0x004e, B:27:0x0061, B:29:0x0069, B:35:0x0079, B:40:0x0086, B:15:0x002c, B:17:0x0033, B:19:0x003f), top: B:49:0x0007, outer: #0 }] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0076  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x0081  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x0084  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void a(com.google.android.gms.internal.measurement.W w4, Bundle bundle) {
        Intent intent;
        Uri uri;
        C0817r0 c0817r0 = (C0817r0) this.f11809q.f5146q;
        try {
            try {
                Z z8 = c0817r0.f12150y;
                C0817r0.k(z8);
                z8.D.b("onActivityCreated");
                intent = w4.f9769s;
            } catch (RuntimeException e8) {
                Z z9 = c0817r0.f12150y;
                C0817r0.k(z9);
                z9.f11875v.c(e8, "Throwable caught in onActivityCreated");
            }
            if (intent != null) {
                Uri data = intent.getData();
                if (data != null) {
                    if (!data.isHierarchical()) {
                    }
                    uri = data;
                    if (uri != null && uri.isHierarchical()) {
                        C0817r0.i(c0817r0.f12122B);
                        String stringExtra = intent.getStringExtra("android.intent.extra.REFERRER_NAME");
                        String str = (!"android-app://com.google.android.googlequicksearchbox/https/www.google.com".equals(stringExtra) || "https://www.google.com".equals(stringExtra) || "android-app://com.google.appcrawler".equals(stringExtra)) ? "gs" : "auto";
                        String queryParameter = uri.getQueryParameter("referrer");
                        boolean z10 = bundle != null;
                        C0815q0 c0815q0 = c0817r0.f12151z;
                        C0817r0.k(c0815q0);
                        c0815q0.O(new U0(this, z10, uri, str, queryParameter));
                        C0795j1 c0795j1 = c0817r0.f12124E;
                        C0817r0.j(c0795j1);
                        c0795j1.N(w4, bundle);
                        return;
                    }
                }
                Bundle extras = intent.getExtras();
                if (extras != null) {
                    String string = extras.getString("com.android.vending.referral_url");
                    if (!TextUtils.isEmpty(string)) {
                        data = Uri.parse(string);
                        uri = data;
                        if (uri != null) {
                            C0817r0.i(c0817r0.f12122B);
                            String stringExtra2 = intent.getStringExtra("android.intent.extra.REFERRER_NAME");
                            if ("android-app://com.google.android.googlequicksearchbox/https/www.google.com".equals(stringExtra2)) {
                                String str2 = (!"android-app://com.google.android.googlequicksearchbox/https/www.google.com".equals(stringExtra2) || "https://www.google.com".equals(stringExtra2) || "android-app://com.google.appcrawler".equals(stringExtra2)) ? "gs" : "auto";
                                String queryParameter2 = uri.getQueryParameter("referrer");
                                boolean z102 = bundle != null;
                                C0815q0 c0815q02 = c0817r0.f12151z;
                                C0817r0.k(c0815q02);
                                c0815q02.O(new U0(this, z102, uri, str2, queryParameter2));
                            }
                            C0795j1 c0795j12 = c0817r0.f12124E;
                            C0817r0.j(c0795j12);
                            c0795j12.N(w4, bundle);
                            return;
                        }
                    }
                }
                uri = null;
                if (uri != null) {
                }
            }
        } finally {
            C0795j1 c0795j13 = c0817r0.f12124E;
            C0817r0.j(c0795j13);
            c0795j13.N(w4, bundle);
        }
    }

    public final void b(com.google.android.gms.internal.measurement.W w4) {
        C0795j1 c0795j1 = ((C0817r0) this.f11809q.f5146q).f12124E;
        C0817r0.j(c0795j1);
        synchronized (c0795j1.f12019B) {
            try {
                if (Objects.equals(c0795j1.f12024w, w4)) {
                    c0795j1.f12024w = null;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        if (((C0817r0) c0795j1.f5146q).f12148w.S()) {
            c0795j1.f12023v.remove(Integer.valueOf(w4.f9767q));
        }
    }

    public final void c(com.google.android.gms.internal.measurement.W w4) {
        C0817r0 c0817r0 = (C0817r0) this.f11809q.f5146q;
        C0795j1 c0795j1 = c0817r0.f12124E;
        C0817r0.j(c0795j1);
        synchronized (c0795j1.f12019B) {
            c0795j1.f12018A = false;
            c0795j1.f12025x = true;
        }
        C0817r0 c0817r02 = (C0817r0) c0795j1.f5146q;
        c0817r02.D.getClass();
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        if (c0817r02.f12148w.S()) {
            C0786g1 c0786g1O = c0795j1.O(w4);
            c0795j1.f12021t = c0795j1.f12020s;
            c0795j1.f12020s = null;
            C0815q0 c0815q0 = c0817r02.f12151z;
            C0817r0.k(c0815q0);
            c0815q0.O(new M0(c0795j1, c0786g1O, jElapsedRealtime));
        } else {
            c0795j1.f12020s = null;
            C0815q0 c0815q02 = c0817r02.f12151z;
            C0817r0.k(c0815q02);
            c0815q02.O(new RunnableC0834x(c0795j1, jElapsedRealtime, 1));
        }
        A1 a1 = c0817r0.f12121A;
        C0817r0.j(a1);
        C0817r0 c0817r03 = (C0817r0) a1.f5146q;
        c0817r03.D.getClass();
        long jElapsedRealtime2 = SystemClock.elapsedRealtime();
        C0815q0 c0815q03 = c0817r03.f12151z;
        C0817r0.k(c0815q03);
        c0815q03.O(new RunnableC0836x1(a1, jElapsedRealtime2, 1));
    }

    public final void d(com.google.android.gms.internal.measurement.W w4) {
        C0817r0 c0817r0 = (C0817r0) this.f11809q.f5146q;
        A1 a1 = c0817r0.f12121A;
        C0817r0.j(a1);
        C0817r0 c0817r02 = (C0817r0) a1.f5146q;
        c0817r02.D.getClass();
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        C0815q0 c0815q0 = c0817r02.f12151z;
        C0817r0.k(c0815q0);
        c0815q0.O(new RunnableC0836x1(a1, jElapsedRealtime, 0));
        C0795j1 c0795j1 = c0817r0.f12124E;
        C0817r0.j(c0795j1);
        Object obj = c0795j1.f12019B;
        synchronized (obj) {
            c0795j1.f12018A = true;
            if (!Objects.equals(w4, c0795j1.f12024w)) {
                synchronized (obj) {
                    c0795j1.f12024w = w4;
                    c0795j1.f12025x = false;
                    C0817r0 c0817r03 = (C0817r0) c0795j1.f5146q;
                    if (c0817r03.f12148w.S()) {
                        c0795j1.f12026y = null;
                        C0815q0 c0815q02 = c0817r03.f12151z;
                        C0817r0.k(c0815q02);
                        c0815q02.O(new RunnableC0792i1(c0795j1, 1));
                    }
                }
            }
        }
        C0817r0 c0817r04 = (C0817r0) c0795j1.f5146q;
        if (!c0817r04.f12148w.S()) {
            c0795j1.f12020s = c0795j1.f12026y;
            C0815q0 c0815q03 = c0817r04.f12151z;
            C0817r0.k(c0815q03);
            c0815q03.O(new RunnableC0792i1(c0795j1, 0));
            return;
        }
        c0795j1.I(w4.f9768r, c0795j1.O(w4), false);
        C0764A c0764a = ((C0817r0) c0795j1.f5146q).f12126G;
        C0817r0.h(c0764a);
        C0817r0 c0817r05 = (C0817r0) c0764a.f5146q;
        c0817r05.D.getClass();
        long jElapsedRealtime2 = SystemClock.elapsedRealtime();
        C0815q0 c0815q04 = c0817r05.f12151z;
        C0817r0.k(c0815q04);
        c0815q04.O(new RunnableC0834x(c0764a, jElapsedRealtime2, 0));
    }

    public final void e(com.google.android.gms.internal.measurement.W w4, Bundle bundle) {
        C0786g1 c0786g1;
        C0795j1 c0795j1 = ((C0817r0) this.f11809q.f5146q).f12124E;
        C0817r0.j(c0795j1);
        if (!((C0817r0) c0795j1.f5146q).f12148w.S() || bundle == null || (c0786g1 = (C0786g1) c0795j1.f12023v.get(Integer.valueOf(w4.f9767q))) == null) {
            return;
        }
        Bundle bundle2 = new Bundle();
        bundle2.putLong("id", c0786g1.f11981c);
        bundle2.putString("name", c0786g1.f11979a);
        bundle2.putString("referrer_name", c0786g1.f11980b);
        bundle.putBundle("com.google.app_measurement.screen_service", bundle2);
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityCreated(Activity activity, Bundle bundle) {
        a(com.google.android.gms.internal.measurement.W.a(activity), bundle);
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityDestroyed(Activity activity) {
        b(com.google.android.gms.internal.measurement.W.a(activity));
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityPaused(Activity activity) {
        c(com.google.android.gms.internal.measurement.W.a(activity));
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityResumed(Activity activity) {
        d(com.google.android.gms.internal.measurement.W.a(activity));
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
        e(com.google.android.gms.internal.measurement.W.a(activity), bundle);
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityStarted(Activity activity) {
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityStopped(Activity activity) {
    }
}
