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

import android.view.View;
import com.iab.omid.library.bytedance2.internal.e;
import com.iab.omid.library.bytedance2.utils.h;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
public class a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final HashMap<View, String> f24520a = new HashMap<>();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final HashMap<View, C0120a> f24521b = new HashMap<>();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final HashMap<String, View> f24522c = new HashMap<>();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final HashSet<View> f24523d = new HashSet<>();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final HashSet<String> f24524e = new HashSet<>();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final HashSet<String> f24525f = new HashSet<>();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final HashMap<String, String> f24526g = new HashMap<>();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final Map<View, Boolean> f24527h = new WeakHashMap();

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private boolean f24528i;

    /* JADX INFO: renamed from: com.iab.omid.library.bytedance2.walking.a$a, reason: collision with other inner class name */
    public static class C0120a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final e f24529a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final ArrayList<String> f24530b = new ArrayList<>();

        public C0120a(e eVar, String str) {
            this.f24529a = eVar;
            a(str);
        }

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

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

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

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

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

    public C0120a c(View view) {
        C0120a c0120a = this.f24521b.get(view);
        if (c0120a != null) {
            this.f24521b.remove(view);
        }
        return c0120a;
    }

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

    public c e(View view) {
        return this.f24523d.contains(view) ? c.PARENT_VIEW : this.f24528i ? c.OBSTRUCTION_VIEW : c.UNDERLYING_VIEW;
    }

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

    private String a(View view) {
        if (!view.isAttachedToWindow()) {
            return "notAttached";
        }
        if (b(view).booleanValue()) {
            return "noWindowFocus";
        }
        HashSet hashSet = new HashSet();
        while (view != null) {
            String strA = h.a(view);
            if (strA != null) {
                return strA;
            }
            hashSet.add(view);
            Object parent = view.getParent();
            view = parent instanceof View ? (View) parent : null;
        }
        this.f24523d.addAll(hashSet);
        return null;
    }

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

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

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

    public void e() {
        com.iab.omid.library.bytedance2.internal.c cVarC = com.iab.omid.library.bytedance2.internal.c.c();
        if (cVarC != null) {
            for (com.iab.omid.library.bytedance2.adsession.a aVar : cVarC.a()) {
                View viewC = aVar.c();
                if (aVar.f()) {
                    String adSessionId = aVar.getAdSessionId();
                    if (viewC != null) {
                        String strA = a(viewC);
                        if (strA == null) {
                            this.f24524e.add(adSessionId);
                            this.f24520a.put(viewC, adSessionId);
                            a(aVar);
                        } else if (strA != "noWindowFocus") {
                            this.f24525f.add(adSessionId);
                            this.f24522c.put(adSessionId, viewC);
                            this.f24526g.put(adSessionId, strA);
                        }
                    } else {
                        this.f24525f.add(adSessionId);
                        this.f24526g.put(adSessionId, "noAdView");
                    }
                }
            }
        }
    }

    public void a() {
        this.f24520a.clear();
        this.f24521b.clear();
        this.f24522c.clear();
        this.f24523d.clear();
        this.f24524e.clear();
        this.f24525f.clear();
        this.f24526g.clear();
        this.f24528i = false;
    }

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

    private void a(com.iab.omid.library.bytedance2.adsession.a aVar) {
        Iterator<e> it = aVar.d().iterator();
        while (it.hasNext()) {
            a(it.next(), aVar);
        }
    }

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