package com.chartboost.sdk.impl;

import android.view.View;
import android.view.ViewParent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.WeakHashMap;
/* loaded from: classes2.dex */
public class hc {

    /* renamed from: a  reason: collision with root package name */
    public final HashMap f1718a = new HashMap();
    public final HashMap b = new HashMap();
    public final HashMap c = new HashMap();
    public final HashSet d = new HashSet();
    public final HashSet e = new HashSet();
    public final HashSet f = new HashSet();
    public final HashMap g = new HashMap();
    public final HashSet h = new HashSet();
    public final Map i = new WeakHashMap();
    public boolean j;

    /* loaded from: classes2.dex */
    public static class a {

        /* renamed from: a  reason: collision with root package name */
        public final hd f1719a;
        public final ArrayList b = new ArrayList();

        public a(hd hdVar, String str) {
            this.f1719a = hdVar;
            a(str);
        }

        public hd a() {
            return this.f1719a;
        }

        public ArrayList b() {
            return this.b;
        }

        public void a(String str) {
            this.b.add(str);
        }
    }

    public View a(String str) {
        return (View) this.c.get(str);
    }

    public a b(View view) {
        a aVar = (a) this.b.get(view);
        if (aVar != null) {
            this.b.remove(view);
        }
        return aVar;
    }

    public HashSet b() {
        return this.f;
    }

    public String c(View view) {
        if (this.f1718a.size() == 0) {
            return null;
        }
        String str = (String) this.f1718a.get(view);
        if (str != null) {
            this.f1718a.remove(view);
        }
        return str;
    }

    public HashSet c() {
        return this.e;
    }

    public yc d(View view) {
        return this.d.contains(view) ? yc.PARENT_VIEW : this.j ? yc.OBSTRUCTION_VIEW : yc.UNDERLYING_VIEW;
    }

    public void d() {
        this.j = true;
    }

    public void e() {
        vc c = vc.c();
        if (c != null) {
            for (bc bcVar : c.a()) {
                View e = bcVar.e();
                if (bcVar.h()) {
                    String j = bcVar.j();
                    if (e != null) {
                        boolean e2 = qd.e(e);
                        if (e2) {
                            this.h.add(j);
                        }
                        String a2 = a(e, e2);
                        if (a2 == null) {
                            this.e.add(j);
                            this.f1718a.put(e, j);
                            a(bcVar);
                        } else if (a2 != "noWindowFocus") {
                            this.f.add(j);
                            this.c.put(j, e);
                            this.g.put(j, a2);
                        }
                    } else {
                        this.f.add(j);
                        this.g.put(j, "noAdView");
                    }
                }
            }
        }
    }

    public final Boolean a(View view) {
        if (view.hasWindowFocus()) {
            this.i.remove(view);
            return Boolean.FALSE;
        } else if (this.i.containsKey(view)) {
            return (Boolean) this.i.get(view);
        } else {
            Map map = this.i;
            Boolean bool = Boolean.FALSE;
            map.put(view, bool);
            return bool;
        }
    }

    public String b(String str) {
        return (String) this.g.get(str);
    }

    public boolean e(View view) {
        if (this.i.containsKey(view)) {
            this.i.put(view, Boolean.TRUE);
            return false;
        }
        return true;
    }

    public final String a(View view, boolean z) {
        if (view.isAttachedToWindow()) {
            if (!a(view).booleanValue() || z) {
                HashSet hashSet = new HashSet();
                while (view != null) {
                    String a2 = qd.a(view);
                    if (a2 != null) {
                        return a2;
                    }
                    hashSet.add(view);
                    ViewParent parent = view.getParent();
                    view = parent instanceof View ? (View) parent : null;
                }
                this.d.addAll(hashSet);
                return null;
            }
            return "noWindowFocus";
        }
        return "notAttached";
    }

    public boolean c(String str) {
        return this.h.contains(str);
    }

    public void a() {
        this.f1718a.clear();
        this.b.clear();
        this.c.clear();
        this.d.clear();
        this.e.clear();
        this.f.clear();
        this.g.clear();
        this.j = false;
        this.h.clear();
    }

    public final void a(bc bcVar) {
        for (hd hdVar : bcVar.f()) {
            a(hdVar, bcVar);
        }
    }

    public final void a(hd hdVar, bc bcVar) {
        View view = (View) hdVar.c().get();
        if (view == null) {
            return;
        }
        a aVar = (a) this.b.get(view);
        if (aVar != null) {
            aVar.a(bcVar.j());
        } else {
            this.b.put(view, new a(hdVar, bcVar.j()));
        }
    }
}
