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

import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import androidx.annotation.Nullable;
import java.util.Collections;

/* JADX INFO: loaded from: classes2.dex */
public final class yo0 extends zi implements ViewTreeObserver.OnGlobalLayoutListener, ViewTreeObserver.OnScrollChangedListener, gq, hu {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public n7.p2 f18914b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public lm0 f18915c;

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

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

    @Override // com.google.android.gms.internal.ads.zi
    public final boolean Q2(int i10, Parcel parcel, Parcel parcel2) {
        if (i10 == 3) {
            n7.p2 p2VarZzb = zzb();
            parcel2.writeNoException();
            aj.d(parcel2, p2VarZzb);
            return true;
        }
        ju iuVar = null;
        if (i10 == 4) {
            com.google.android.gms.common.internal.w.d("#008 Must be called on the main UI thread.");
            S2();
            lm0 lm0Var = this.f18915c;
            if (lm0Var != null) {
                lm0Var.o();
            }
            this.f18915c = null;
            this.f18913a = null;
            this.f18914b = null;
            this.f18916d = true;
            parcel2.writeNoException();
            return true;
        }
        if (i10 == 5) {
            k8.a aVarM = k8.b.M(parcel.readStrongBinder());
            IBinder strongBinder = parcel.readStrongBinder();
            if (strongBinder != null) {
                IInterface iInterfaceQueryLocalInterface = strongBinder.queryLocalInterface("com.google.android.gms.ads.internal.instream.client.IInstreamAdCallback");
                iuVar = iInterfaceQueryLocalInterface instanceof ju ? (ju) iInterfaceQueryLocalInterface : new iu(strongBinder, "com.google.android.gms.ads.internal.instream.client.IInstreamAdCallback", 0);
            }
            aj.e(parcel);
            R2(aVarM, iuVar);
            parcel2.writeNoException();
            return true;
        }
        if (i10 != 6) {
            if (i10 != 7) {
                return false;
            }
            pq pqVarZzf = zzf();
            parcel2.writeNoException();
            aj.d(parcel2, pqVarZzf);
            return true;
        }
        k8.a aVarM2 = k8.b.M(parcel.readStrongBinder());
        aj.e(parcel);
        com.google.android.gms.common.internal.w.d("#008 Must be called on the main UI thread.");
        R2(aVarM2, new xo0("com.google.android.gms.ads.internal.instream.client.IInstreamAdCallback"));
        parcel2.writeNoException();
        return true;
    }

    public final void R2(k8.a aVar, ju juVar) {
        com.google.android.gms.common.internal.w.d("#008 Must be called on the main UI thread.");
        if (this.f18916d) {
            q7.j.b("Instream ad can not be shown after destroy().");
            try {
                juVar.e(2);
                return;
            } catch (RemoteException e10) {
                q7.j.zzl("#007 Could not call remote method.", e10);
                return;
            }
        }
        View view = this.f18913a;
        if (view == null || this.f18914b == null) {
            q7.j.b("Instream internal error: ".concat(view == null ? "can not get video view." : "can not get video controller."));
            try {
                juVar.e(0);
                return;
            } catch (RemoteException e11) {
                q7.j.zzl("#007 Could not call remote method.", e11);
                return;
            }
        }
        if (this.f18917e) {
            q7.j.b("Instream ad should not be used again.");
            try {
                juVar.e(1);
                return;
            } catch (RemoteException e12) {
                q7.j.zzl("#007 Could not call remote method.", e12);
                return;
            }
        }
        this.f18917e = true;
        S2();
        ((ViewGroup) k8.b.O(aVar)).addView(this.f18913a, new ViewGroup.LayoutParams(-1, -1));
        g30 g30Var = m7.n.C.B;
        l30 l30Var = new l30(this.f18913a, this);
        ViewTreeObserver viewTreeObserverZze = l30Var.zze();
        if (viewTreeObserverZze != null) {
            l30Var.a(viewTreeObserverZze);
        }
        m30 m30Var = new m30(this.f18913a, this);
        ViewTreeObserver viewTreeObserverZze2 = m30Var.zze();
        if (viewTreeObserverZze2 != null) {
            m30Var.a(viewTreeObserverZze2);
        }
        T2();
        try {
            juVar.zze();
        } catch (RemoteException e13) {
            q7.j.zzl("#007 Could not call remote method.", e13);
        }
    }

    public final void S2() {
        View view = this.f18913a;
        if (view == null) {
            return;
        }
        ViewParent parent = view.getParent();
        if (parent instanceof ViewGroup) {
            ((ViewGroup) parent).removeView(this.f18913a);
        }
    }

    public final void T2() {
        View view;
        lm0 lm0Var = this.f18915c;
        if (lm0Var == null || (view = this.f18913a) == null) {
            return;
        }
        lm0Var.t(view, Collections.emptyMap(), Collections.emptyMap(), lm0.d(this.f18913a));
    }

    @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
    public final void onGlobalLayout() {
        T2();
    }

    @Override // android.view.ViewTreeObserver.OnScrollChangedListener
    public final void onScrollChanged() {
        T2();
    }

    @Override // com.google.android.gms.internal.ads.hu
    @Nullable
    public final n7.p2 zzb() throws RemoteException {
        com.google.android.gms.common.internal.w.d("#008 Must be called on the main UI thread.");
        if (!this.f18916d) {
            return this.f18914b;
        }
        q7.j.b("getVideoController: Instream ad should not be used after destroyed");
        return null;
    }

    @Override // com.google.android.gms.internal.ads.hu
    @Nullable
    public final pq zzf() {
        nm0 nm0Var;
        com.google.android.gms.common.internal.w.d("#008 Must be called on the main UI thread.");
        if (this.f18916d) {
            q7.j.b("getVideoController: Instream ad should not be used after destroyed");
            return null;
        }
        lm0 lm0Var = this.f18915c;
        if (lm0Var == null || (nm0Var = lm0Var.D) == null) {
            return null;
        }
        return nm0Var.zza();
    }
}
