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

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.zzov;
import com.google.firebase.messaging.Constants;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public final class zzkz implements Application.ActivityLifecycleCallbacks {
    private final /* synthetic */ zzjq zza;

    /* JADX INFO: Access modifiers changed from: package-private */
    public zzkz(zzjq zzjqVar) {
        this.zza = zzjqVar;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: Removed duplicated region for block: B:14:0x00ad A[Catch: RuntimeException -> 0x0198, TRY_ENTER, TryCatch #0 {RuntimeException -> 0x0198, blocks: (B:3:0x000b, B:5:0x0019, B:8:0x002a, B:14:0x00ad, B:16:0x00b9, B:19:0x00ce, B:21:0x00d4, B:24:0x00e1, B:26:0x00e7, B:27:0x00fa, B:29:0x0106, B:33:0x010d, B:37:0x0130, B:38:0x014c, B:40:0x013d, B:41:0x0153, B:43:0x0159, B:45:0x015f, B:47:0x0165, B:49:0x016b, B:51:0x0173, B:55:0x017e, B:57:0x018c, B:59:0x0192, B:62:0x003e, B:65:0x0046, B:67:0x004e, B:69:0x0054, B:71:0x005a, B:73:0x0060, B:75:0x0068, B:77:0x0070, B:79:0x0078, B:81:0x0080, B:82:0x008c, B:84:0x00a4), top: B:2:0x000b }] */
    /* JADX WARN: Removed duplicated region for block: B:31:0x010c A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:33:0x010d A[Catch: RuntimeException -> 0x0198, TRY_LEAVE, TryCatch #0 {RuntimeException -> 0x0198, blocks: (B:3:0x000b, B:5:0x0019, B:8:0x002a, B:14:0x00ad, B:16:0x00b9, B:19:0x00ce, B:21:0x00d4, B:24:0x00e1, B:26:0x00e7, B:27:0x00fa, B:29:0x0106, B:33:0x010d, B:37:0x0130, B:38:0x014c, B:40:0x013d, B:41:0x0153, B:43:0x0159, B:45:0x015f, B:47:0x0165, B:49:0x016b, B:51:0x0173, B:55:0x017e, B:57:0x018c, B:59:0x0192, B:62:0x003e, B:65:0x0046, B:67:0x004e, B:69:0x0054, B:71:0x005a, B:73:0x0060, B:75:0x0068, B:77:0x0070, B:79:0x0078, B:81:0x0080, B:82:0x008c, B:84:0x00a4), top: B:2:0x000b }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static /* synthetic */ void zza(zzkz zzkzVar, boolean z10, Uri uri, String str, String str2) {
        Bundle zza;
        Uri uri2;
        boolean z11;
        zzkzVar.zza.zzt();
        try {
            zzos zzq = zzkzVar.zza.zzq();
            boolean z12 = false;
            boolean z13 = zzov.zza() && zzkzVar.zza.zze().zza(zzbh.zzct);
            if (!TextUtils.isEmpty(str2)) {
                if (str2.contains("gclid") || ((z13 && str2.contains("gbraid")) || str2.contains("utm_campaign") || str2.contains("utm_source") || str2.contains("utm_medium") || str2.contains("utm_id") || str2.contains("dclid") || str2.contains("srsltid") || str2.contains("sfmc_id"))) {
                    zza = zzq.zza(Uri.parse("https://google.com/search?" + str2), z13);
                    if (zza != null) {
                        zza.putString("_cis", "referrer");
                    }
                    if (z10) {
                        zzos zzq2 = zzkzVar.zza.zzq();
                        if (zzov.zza() && zzkzVar.zza.zze().zza(zzbh.zzct)) {
                            uri2 = uri;
                            z11 = true;
                        } else {
                            uri2 = uri;
                            z11 = false;
                        }
                        Bundle zza2 = zzq2.zza(uri2, z11);
                        if (zza2 != null) {
                            zza2.putString("_cis", "intent");
                            if (!zza2.containsKey("gclid") && zza != null && zza.containsKey("gclid")) {
                                zza2.putString("_cer", String.format("gclid=%s", zza.getString("gclid")));
                            }
                            zzkzVar.zza.zzc(str, Constants.ScionAnalytics.EVENT_FIREBASE_CAMPAIGN, zza2);
                            zzkzVar.zza.zza.zza(str, zza2);
                        }
                    }
                    if (TextUtils.isEmpty(str2)) {
                        zzkzVar.zza.zzj().zzc().zza("Activity created with referrer", str2);
                        if (zzkzVar.zza.zze().zza(zzbh.zzbq)) {
                            if (zza != null) {
                                zzkzVar.zza.zzc(str, Constants.ScionAnalytics.EVENT_FIREBASE_CAMPAIGN, zza);
                                zzkzVar.zza.zza.zza(str, zza);
                            } else {
                                zzkzVar.zza.zzj().zzc().zza("Referrer does not contain valid parameters", str2);
                            }
                            zzkzVar.zza.zza("auto", "_ldl", (Object) null, true);
                            return;
                        }
                        if (str2.contains("gclid") && (str2.contains("utm_campaign") || str2.contains("utm_source") || str2.contains("utm_medium") || str2.contains("utm_term") || str2.contains("utm_content"))) {
                            z12 = true;
                        }
                        if (!z12) {
                            zzkzVar.zza.zzj().zzc().zza("Activity created with data 'referrer' without required params");
                            return;
                        } else {
                            if (TextUtils.isEmpty(str2)) {
                                return;
                            }
                            zzkzVar.zza.zza("auto", "_ldl", (Object) str2, true);
                            return;
                        }
                    }
                    return;
                }
                zzq.zzj().zzc().zza("Activity created with data 'referrer' without required params");
            }
            zza = null;
            if (z10) {
            }
            if (TextUtils.isEmpty(str2)) {
            }
        } catch (RuntimeException e10) {
            zzkzVar.zza.zzj().zzg().zza("Throwable caught in handleReferrerForOnActivityCreated", e10);
        }
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityCreated(Activity activity, Bundle bundle) {
        try {
            this.zza.zzj().zzp().zza("onActivityCreated");
            Intent intent = activity.getIntent();
            if (intent == null) {
                return;
            }
            Uri data = intent.getData();
            if (data == null || !data.isHierarchical()) {
                Bundle extras = intent.getExtras();
                if (extras != null) {
                    String string = extras.getString("com.android.vending.referral_url");
                    if (!TextUtils.isEmpty(string)) {
                        data = Uri.parse(string);
                    }
                }
                data = null;
            }
            Uri uri = data;
            if (uri != null && uri.isHierarchical()) {
                this.zza.zzq();
                this.zza.zzl().zzb(new zzlc(this, bundle == null, uri, zzos.zza(intent) ? "gs" : "auto", uri.getQueryParameter("referrer")));
            }
        } catch (RuntimeException e10) {
            this.zza.zzj().zzg().zza("Throwable caught in onActivityCreated", e10);
        } finally {
            this.zza.zzn().zza(activity, bundle);
        }
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityDestroyed(Activity activity) {
        this.zza.zzn().zza(activity);
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityPaused(Activity activity) {
        this.zza.zzn().zzb(activity);
        zznb zzp = this.zza.zzp();
        zzp.zzl().zzb(new zznd(zzp, zzp.zzb().elapsedRealtime()));
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityResumed(Activity activity) {
        zznb zzp = this.zza.zzp();
        zzp.zzl().zzb(new zzne(zzp, zzp.zzb().elapsedRealtime()));
        this.zza.zzn().zzc(activity);
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
        this.zza.zzn().zzb(activity, bundle);
    }

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

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