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

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicBoolean;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Application f15750a;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public long f15758i;

    @Nullable
    private Activity zza;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f15751b = new Object();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final AtomicBoolean f15752c = new AtomicBoolean(true);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f15753d = false;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ArrayList f15754e = new ArrayList();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ArrayList f15755f = new ArrayList();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f15757h = false;

    public final void a(Activity activity) {
        synchronized (this.f15751b) {
            try {
                if (!activity.getClass().getName().startsWith("com.google.android.gms.ads")) {
                    this.zza = activity;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityCreated(Activity activity, Bundle bundle) {
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityDestroyed(Activity activity) {
        synchronized (this.f15751b) {
            try {
                Activity activity2 = this.zza;
                if (activity2 == null) {
                    return;
                }
                if (activity2.equals(activity)) {
                    this.zza = null;
                }
                Iterator it = this.f15755f.iterator();
                while (it.hasNext()) {
                    try {
                        ((hq0) it.next()).d();
                    } catch (Exception e10) {
                        m7.n.C.f30469h.d("AppActivityTracker.ActivityListener.onActivityDestroyed", e10);
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityPaused(Activity activity) {
        a(activity);
        synchronized (this.f15751b) {
            Iterator it = this.f15755f.iterator();
            while (it.hasNext()) {
                try {
                    ((hq0) it.next()).c();
                } catch (Exception e10) {
                    m7.n.C.f30469h.d("AppActivityTracker.ActivityListener.onActivityPaused", e10);
                }
            }
        }
        this.f15753d = true;
        mv1 mv1Var = this.f15756g;
        if (mv1Var != null) {
            p7.r0.f31763l.removeCallbacks(mv1Var);
        }
        p7.m0 m0Var = p7.r0.f31763l;
        mv1 mv1Var2 = new mv1(this);
        this.f15756g = mv1Var2;
        m0Var.postDelayed(mv1Var2, this.f15758i);
    }

    @Override // android.app.Application.ActivityLifecycleCallbacks
    public final void onActivityResumed(Activity activity) {
        a(activity);
        this.f15753d = false;
        boolean z10 = !this.f15752c.getAndSet(true);
        mv1 mv1Var = this.f15756g;
        if (mv1Var != null) {
            p7.r0.f31763l.removeCallbacks(mv1Var);
        }
        synchronized (this.f15751b) {
            Iterator it = this.f15755f.iterator();
            while (it.hasNext()) {
                try {
                    ((hq0) it.next()).b();
                } catch (Exception e10) {
                    m7.n.C.f30469h.d("AppActivityTracker.ActivityListener.onActivityResumed", e10);
                }
            }
            if (z10) {
                Iterator it2 = this.f15754e.iterator();
                while (it2.hasNext()) {
                    try {
                        ((rj) it2.next()).G(true);
                    } catch (Exception unused) {
                    }
                }
            } else {
                q7.j.a("App is still foreground.");
            }
        }
    }

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

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

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

    @Nullable
    public final Activity zzd() {
        return this.zza;
    }

    @Nullable
    public final Context zze() {
        return this.f15750a;
    }
}
