package com.iab.omid.library.mmadbridge.walking;

import android.view.View;
import android.view.ViewParent;
import com.iab.omid.library.mmadbridge.internal.e;
import com.iab.omid.library.mmadbridge.utils.h;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.WeakHashMap;
/* loaded from: classes5.dex */
public class a {

    /* renamed from: a  reason: collision with root package name */
    private final HashMap<View, String> f2105a = new HashMap<>();
    private final HashMap<View, C0233a> b = new HashMap<>();
    private final HashMap<String, View> c = new HashMap<>();
    private final HashSet<View> d = new HashSet<>();
    private final HashSet<String> e = new HashSet<>();
    private final HashSet<String> f = new HashSet<>();
    private final HashMap<String, String> g = new HashMap<>();
    private final HashSet<String> h = new HashSet<>();
    private final Map<View, Boolean> i = new WeakHashMap();
    private boolean j;

    /* renamed from: com.iab.omid.library.mmadbridge.walking.a$a  reason: collision with other inner class name */
    /* loaded from: classes5.dex */
    public static class C0233a {

        /* renamed from: a  reason: collision with root package name */
        private final e f2106a;
        private final ArrayList<String> b = new ArrayList<>();

        public C0233a(e eVar, String str) {
            this.f2106a = eVar;
            a(str);
        }

        public e a() {
            return this.f2106a;
        }

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

        public ArrayList<String> b() {
            return this.b;
        }
    }

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

    private String a(View view, boolean z) {
        if (view.isAttachedToWindow()) {
            if (!a(view).booleanValue() || z) {
                HashSet hashSet = new HashSet();
                while (view != null) {
                    String a2 = h.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";
    }

    private void a(com.iab.omid.library.mmadbridge.adsession.a aVar) {
        for (e eVar : aVar.d()) {
            a(eVar, aVar);
        }
    }

    private void a(e eVar, com.iab.omid.library.mmadbridge.adsession.a aVar) {
        View view = eVar.c().get();
        if (view == null) {
            return;
        }
        C0233a c0233a = this.b.get(view);
        if (c0233a != null) {
            c0233a.a(aVar.getAdSessionId());
        } else {
            this.b.put(view, new C0233a(eVar, aVar.getAdSessionId()));
        }
    }

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

    public void a() {
        this.f2105a.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 C0233a b(View view) {
        C0233a c0233a = this.b.get(view);
        if (c0233a != null) {
            this.b.remove(view);
        }
        return c0233a;
    }

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

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

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

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

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

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

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

    public void e() {
        com.iab.omid.library.mmadbridge.internal.c c = com.iab.omid.library.mmadbridge.internal.c.c();
        if (c != null) {
            for (com.iab.omid.library.mmadbridge.adsession.a aVar : c.a()) {
                View c2 = aVar.c();
                if (aVar.f()) {
                    String adSessionId = aVar.getAdSessionId();
                    if (c2 != null) {
                        boolean e = h.e(c2);
                        if (e) {
                            this.h.add(adSessionId);
                        }
                        String a2 = a(c2, e);
                        if (a2 == null) {
                            this.e.add(adSessionId);
                            this.f2105a.put(c2, adSessionId);
                            a(aVar);
                        } else if (a2 != "noWindowFocus") {
                            this.f.add(adSessionId);
                            this.c.put(adSessionId, c2);
                            this.g.put(adSessionId, a2);
                        }
                    } else {
                        this.f.add(adSessionId);
                        this.g.put(adSessionId, "noAdView");
                    }
                }
            }
        }
    }

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