Cyber Surfer v5.2.5版本的 MD5 值为:db13c5fce988de393e52d2679f934b22

以下内容为反编译后的 BannerFinder.java 源代码,内容仅作参考


package com.safedk.android.analytics.brandsafety;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.WebView;
import android.widget.TextView;
import com.applovin.communicator.AppLovinCommunicatorMessage;
import com.applovin.mediation.ads.MaxAdView;
import com.safedk.android.SafeDK;
import com.safedk.android.analytics.AppLovinBridge;
import com.safedk.android.analytics.StatsCollector;
import com.safedk.android.analytics.StatsReporter;
import com.safedk.android.analytics.brandsafety.BrandSafetyUtils;
import com.safedk.android.analytics.brandsafety.RedirectDetails;
import com.safedk.android.analytics.brandsafety.creatives.AdNetworkConfiguration;
import com.safedk.android.analytics.brandsafety.creatives.AdNetworkDiscovery;
import com.safedk.android.analytics.brandsafety.creatives.CreativeInfoManager;
import com.safedk.android.analytics.brandsafety.creatives.infos.CreativeInfo;
import com.safedk.android.analytics.events.BrandSafetyEvent;
import com.safedk.android.analytics.reporters.CrashReporter;
import com.safedk.android.internal.SafeDKWebAppInterface;
import com.safedk.android.utils.LinkedHashSetWithItemLimit;
import com.safedk.android.utils.Logger;
import com.safedk.android.utils.PersistentConcurrentHashMap;
import com.safedk.android.utils.SdksMapping;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class BannerFinder extends com.safedk.android.analytics.brandsafety.b {
    protected static final int C = 5;
    protected static final long D = 1000;
    protected static final long E = 500;
    protected static final long H = 10;
    protected final Map<d, e> F;
    protected final Map<String, List<o>> G;
    protected LinkedHashSetWithItemLimit<String> I;
    private static h K = null;
    private static final Map<String, List<WeakReference<MaxAdView>>> L = new HashMap();
    private static final Map<String, BrandSafetyUtils.AdType> M = new HashMap();
    protected static Map<String, RedirectData> J = null;

    public class a implements Runnable {
        e f9193a;
        WeakReference<View> f9194b;
        int c = 0;
        ScheduledFuture<?> d;
        int e;

        public a(e eVar, WeakReference<View> weakReference, int i) {
            this.f9194b = weakReference;
            this.f9193a = eVar;
            this.e = i;
            if (eVar != null) {
                String a2 = BrandSafetyUtils.a(weakReference.get());
                eVar.J = a2;
                l h = eVar.h();
                if (h == null || h.c() == null) {
                    return;
                }
                com.safedk.android.analytics.brandsafety.creatives.e.a(a2, h.c());
                h.c().t("wv=" + a2);
            }
        }

        public synchronized void a(e eVar, View view) {
            if (eVar != null && view != null) {
                try {
                    Logger.d(BannerFinder.this.f9248a, "Taking screenshot, view=" + view);
                    String c = eVar.c();
                    long currentTimeMillis = System.currentTimeMillis();
                    Bitmap a2 = com.safedk.android.analytics.brandsafety.creatives.f.a(view, SafeDK.getInstance().Y());
                    BannerFinder.this.a(eVar, System.currentTimeMillis() - currentTimeMillis, a2);
                    if ((view instanceof ViewGroup) && CreativeInfoManager.a(c, AdNetworkConfiguration.SHOULD_EXTRACT_TEXT_FROM_NATIVE_BANNERS, false)) {
                        BannerFinder.this.a((ViewGroup) view, eVar);
                    }
                    if (a2 != null) {
                        BrandSafetyUtils.a b2 = BrandSafetyUtils.b(c, a2);
                        int a3 = b2.a();
                        if (BrandSafetyUtils.b(c, b2)) {
                            String a4 = BrandSafetyUtils.a(a2);
                            BrandSafetyUtils.ScreenShotOrientation b3 = BrandSafetyUtils.b(a2);
                            l h = eVar.h();
                            String a5 = BrandSafetyUtils.a(a2, BannerFinder.this.c, a4, c, h.f9386a, b3);
                            if (!BannerFinder.this.d(a5, c, a4)) {
                                Logger.d(BannerFinder.this.f9248a, "Taking screenshot - image is not valid : " + a5);
                            }
                            Logger.d(BannerFinder.this.f9248a, "Taking screenshot Screenshot file created, counter = " + this.c + " filename = " + a5 + ", hash = " + a4);
                            long b4 = BrandSafetyUtils.b(a5);
                            Logger.d(BannerFinder.this.f9248a, "Taking screenshot Hash " + a4 + " Stored file size is " + b4 + " bytes, counter is " + this.c + ", uniform pixel count is " + a3 + " (" + ((a3 / 500.0f) * 100.0f) + "%)");
                            int size = BannerFinder.this.y.size();
                            if (BannerFinder.this.e(a4, h.f9386a)) {
                                Logger.d(BannerFinder.this.f9248a, "Not saving file for " + a4 + "_" + h.f9386a);
                                BrandSafetyUtils.c(a5);
                            } else if (size <= SafeDK.getInstance().J()) {
                                if (h.f9387b != null && h.f9387b.f9377a != null && !h.f9387b.f9377a.equals(a4)) {
                                    Logger.d(BannerFinder.this.f9248a, "removing ad file " + h.f9387b.f9378b);
                                    BrandSafetyUtils.c(h.f9387b.f9378b);
                                }
                                h.f9387b = new j(a4, a5, b4, a3, this.c, b3, false);
                                Logger.d(BannerFinder.this.f9248a, "setting data hash = " + a4 + ", file name = " + a5 + ", file size = " + b4 + ", max uniformed pixel count = " + a3 + ", image counter = " + this.c);
                            } else if (BannerFinder.this.d(a4, h.f9386a)) {
                                Logger.d(BannerFinder.this.f9248a, "Image " + a4 + "_" + h.f9386a + " is already scheduled for upload");
                            } else {
                                Logger.d(BannerFinder.this.f9248a, "No open slot for " + a4 + "_" + h.f9386a + "; next hashes to be reported to server are " + BannerFinder.this.y.keySet());
                                BrandSafetyUtils.c(a5);
                            }
                            if (BannerFinder.this.a(a3) && !TextUtils.isEmpty(a4)) {
                                eVar.d(true);
                                eVar.Z = true;
                            }
                        } else {
                            Logger.d(BannerFinder.this.f9248a, "Screenshot is not valid (uniform pixel count too high: " + a3 + ", counter = " + this.c + ", try again...");
                        }
                    }
                } catch (Throwable th) {
                    Logger.e(BannerFinder.this.f9248a, "Error while taking screenshot", th);
                    Logger.printStackTrace();
                    new CrashReporter().caughtException(th);
                }
            }
        }

        @Override
        public void run() {
            this.c++;
            if (this.f9193a == null || !com.safedk.android.utils.l.a((Reference<?>) this.f9193a.ac)) {
                Logger.d(BannerFinder.this.f9248a, "timer task cannot be started: banner activity=" + (!com.safedk.android.utils.l.a((Reference<?>) this.f9193a.ac) ? "" : this.f9193a.ac.get().getClass().getName()) + ", current activity banner=" + this.f9193a);
            } else if (this.c >= this.e || this.f9193a.Z) {
                Logger.d(BannerFinder.this.f9248a, "Going to report banner, eventId=" + this.f9193a.K + ", stopTimerAndReport=" + this.f9193a.Z + ", image counter=" + this.c + ", max attempts=" + this.e + ", isImpressionReported=" + this.f9193a.D);
                if (!this.f9193a.D) {
                    BannerFinder.this.a(this.f9193a, false, "ImpressionHandlerTask");
                }
                this.f9194b.clear();
                this.d.cancel(false);
            } else if (this.f9193a.N) {
                Logger.d(BannerFinder.this.f9248a, "no creative info yet or request no sampling received, current activity banner = " + this.f9193a);
            } else if (BannerFinder.this.a(this.f9193a)) {
                WeakReference<Activity> weakReference = this.f9193a.ac;
                if (com.safedk.android.utils.l.a((Reference<?>) weakReference)) {
                    weakReference.get().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            a.this.a(a.this.f9193a, a.this.f9194b.get());
                        }
                    });
                }
            }
        }
    }

    public class b implements Runnable {
        String f9196a;
        String f9197b;
        String c;
        d d;
        Bundle e;
        int f = 0;
        ScheduledFuture<?> g;

        public b(String str, String str2, String str3, d dVar, Bundle bundle) {
            this.f9196a = str;
            this.f9197b = str2;
            this.c = str3;
            this.d = dVar;
            this.e = bundle;
        }

        @Override
        public void run() {
            boolean z;
            String string = this.e.getString("ad_view");
            e eVar = BannerFinder.this.F.get(this.d);
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            BannerFinder.this.a(this.f9197b, this.c, this.d, string, arrayList, arrayList2);
            if (arrayList.isEmpty() && (eVar == null || eVar.J == null)) {
                Logger.d(BannerFinder.this.f9248a, "web view scanner - failed to find view, scan counter: " + this.f);
                this.f++;
            } else if (!arrayList.isEmpty()) {
                this.f++;
                Logger.d(BannerFinder.this.f9248a, "web view scanner - found view, scan counter: " + this.f);
                WeakReference c = BannerFinder.this.c(arrayList);
                boolean f = BannerFinder.this.f(this.f9196a, this.f9197b);
                if (this.f9197b != null && f && eVar != null) {
                    eVar.a(arrayList2);
                    if (c != null && c.get() != null) {
                        boolean a2 = CreativeInfoManager.a(this.f9197b, AdNetworkConfiguration.DETECT_MULTIPLE_ADS_BY_WEB_VIEW_CHANGE, false);
                        boolean D = eVar.D();
                        Logger.d(BannerFinder.this.f9248a, "web view scanner - should detect multiple ads by web view change ? " + a2 + ", isNativeAd = " + D);
                        String a3 = BrandSafetyUtils.a(c.get());
                        if (!D && a2 && eVar.J != null && !eVar.J.equals(a3)) {
                            z = true;
                            BannerFinder.this.a(eVar, a3);
                            if (!z) {
                                BannerFinder.this.a(arrayList, this.d);
                            }
                            if (this.f9197b == null && f) {
                                if (eVar != null) {
                                    eVar.ab = this.g;
                                    if (c != null && c.get() != null) {
                                        BannerFinder.this.a(eVar, c);
                                        BannerFinder.this.a(this.f9197b, this.c, this.d, c);
                                        if (CreativeInfoManager.a(this.f9197b, AdNetworkConfiguration.SHOULD_EXTRACT_AD_ID_FROM_BANNER_WEB_VIEW, false) && eVar.i() == null) {
                                            Logger.d(BannerFinder.this.f9248a, "web view scanner - keep scanning until we have a match. scan counter: " + this.f + ", activity banner key: " + this.d);
                                        }
                                    }
                                }
                            } else if (this.g != null) {
                                this.g.cancel(false);
                            }
                        }
                    }
                }
                z = false;
                if (!z) {
                }
                if (this.f9197b == null) {
                }
                if (this.g != null) {
                }
            }
            if (this.f < 5 || this.g == null) {
                return;
            }
            Logger.d(BannerFinder.this.f9248a, "web view scanner - failed to find webview, scan counter: " + this.f);
            BannerFinder.this.a(eVar, false, "WebviewScannerTask");
            this.g.cancel(false);
        }
    }

    public BannerFinder(int i) {
        super(BrandSafetyUtils.AdType.BANNER, Arrays.asList(BrandSafetyUtils.n, BrandSafetyUtils.o), "BannerFinder", i);
        this.F = new HashMap();
        this.G = new HashMap();
        this.I = new LinkedHashSetWithItemLimit<>(10L);
        d();
    }

    public BannerFinder(BrandSafetyUtils.AdType adType, List<String> list, String str, int i) {
        super(adType, list, str, i);
        this.F = new HashMap();
        this.G = new HashMap();
        this.I = new LinkedHashSetWithItemLimit<>(10L);
    }

    private Activity a(Bundle bundle) {
        Logger.d(this.f9248a, "getMaxAdViewActivity: started");
        String k = BrandSafetyUtils.k(bundle.getString("ad_view", null));
        Activity foregroundActivity = com.safedk.android.internal.b.getInstance().getForegroundActivity();
        try {
            Iterator<WeakReference<Activity>> it = com.safedk.android.internal.b.getInstance().getAppActivities().iterator();
            while (it.hasNext()) {
                WeakReference<Activity> next = it.next();
                if (next != null && next.get() != null) {
                    Activity activity = next.get();
                    View findViewById = activity.findViewById(16908290);
                    if ((findViewById instanceof ViewGroup) && b(a((ViewGroup) findViewById)).contains(k)) {
                        Logger.d(this.f9248a, "getMaxAdViewActivity: found activity with name " + activity.getClass().getName());
                        return activity;
                    }
                }
            }
        } catch (Exception e) {
            Logger.d(this.f9248a, "getMaxAdViewActivity: exception occurred " + e.getMessage());
        }
        return foregroundActivity;
    }

    public static BrandSafetyUtils.AdType a(WebView webView) {
        boolean z;
        if (webView != null) {
            boolean z2 = false;
            ViewParent viewParent = webView;
            while (true) {
                if (viewParent instanceof View) {
                    View view = (View) viewParent;
                    if (com.safedk.android.internal.b.getInstance().isInterstitialActivity(view.getContext())) {
                        Logger.d("BannerFinder", "extract ad type from web view: " + view + ", INTERSTITIAL activity: " + view.getContext());
                        return BrandSafetyUtils.AdType.INTERSTITIAL;
                    } else if (com.safedk.android.utils.l.a(view.getWidth(), view.getHeight())) {
                        Logger.d("BannerFinder", "extract ad type from web view: " + view + ", BANNER ratio");
                        return BrandSafetyUtils.AdType.BANNER;
                    } else if (com.safedk.android.utils.l.b(view.getWidth(), view.getHeight())) {
                        Logger.d("BannerFinder", "extract ad type from web view: " + view + ", MREC ratio");
                        return BrandSafetyUtils.AdType.MREC;
                    } else if (viewParent instanceof MaxAdView) {
                        BrandSafetyUtils.AdType adType = M.get(BrandSafetyUtils.a(viewParent));
                        if (adType != null) {
                            Logger.d("BannerFinder", "extract ad type from web view: " + view + ", " + adType.name() + " MaxAdView");
                            return adType;
                        }
                        z = true;
                        Logger.d("BannerFinder", "extract ad type from web view: " + viewParent);
                        viewParent = viewParent.getParent();
                        if (viewParent == null) {
                            z2 = z;
                        } else if (!z) {
                            Logger.d("BannerFinder", "extract ad type from web view hierarchy: no MaxAdView, assuming INTERSTITIAL");
                            return BrandSafetyUtils.AdType.INTERSTITIAL;
                        }
                    }
                }
                z = z2;
                Logger.d("BannerFinder", "extract ad type from web view: " + viewParent);
                viewParent = viewParent.getParent();
                if (viewParent == null) {
                }
            }
        }
        Logger.d("BannerFinder", "extract ad type from web view: failed to extract");
        return null;
    }

    private e a(Activity activity, String str, String str2, Bundle bundle) {
        String lowerCase = BrandSafetyUtils.c().name().toLowerCase();
        this.d++;
        Logger.d(this.f9248a, "slot number incremented to " + this.d + ", eventId is " + str2);
        return a(activity, str, this.d, lowerCase, bundle, str2);
    }

    private static BrandSafetyEvent a(e eVar, l lVar, boolean z, boolean z2, long j, String str) {
        return new BrandSafetyEvent(eVar.c(), eVar.q(), str, z2, eVar.d() ? eVar.e() : null, lVar.c(), eVar.a(), eVar.p(), lVar.f9386a != null ? lVar.f9386a : "", eVar.C, z, eVar.r(), lVar.f9387b != null ? lVar.f9387b.f : null, lVar.f9387b != null ? lVar.f9387b.c : 0L, lVar.f9387b != null ? lVar.f9387b.a(com.safedk.android.internal.d.c) : 0.0f, lVar.f9387b != null ? lVar.f9387b.e : 0, eVar.ad, eVar.ae, j, eVar.ah, eVar.ai, eVar.aj, SafeDK.getInstance().e(), eVar.w(), eVar.L, eVar.M, eVar.O, eVar.P, lVar.d, lVar.e, lVar.f, lVar.g);
    }

    private String a(View view, String str) {
        String a2 = BrandSafetyUtils.a((Class) view.getClass());
        return TextUtils.isEmpty(a2) ? TextUtils.isEmpty(str) ? view.getClass().getName() : str : a2;
    }

    private List<WeakReference<View>> a(ViewGroup viewGroup) {
        ArrayList arrayList = new ArrayList();
        a(viewGroup, arrayList);
        return arrayList;
    }

    private void a(ViewGroup viewGroup, String str, d dVar) {
        String a2 = BrandSafetyUtils.a((Class) viewGroup.getClass());
        if (TextUtils.isEmpty(a2) || a2.equals(str) || !a2.equals(com.safedk.android.utils.h.h)) {
            return;
        }
        Logger.d(this.f9248a, "scar-admob ad identified");
        e eVar = this.F.get(dVar);
        if (eVar != null) {
            eVar.aj = true;
        }
    }

    private void a(ViewGroup viewGroup, List<WeakReference<View>> list) {
        if (viewGroup == null) {
            return;
        }
        list.add(new WeakReference<>(viewGroup));
        int i = 0;
        while (true) {
            int i2 = i;
            if (i2 >= viewGroup.getChildCount()) {
                return;
            }
            View childAt = viewGroup.getChildAt(i2);
            list.add(new WeakReference<>(childAt));
            if (childAt instanceof ViewGroup) {
                a((ViewGroup) childAt, list);
            }
            i = i2 + 1;
        }
    }

    public static void a(MaxAdView maxAdView) {
        M.remove(BrandSafetyUtils.a(maxAdView));
        Iterator<String> it = L.keySet().iterator();
        while (it.hasNext() && !a(it.next(), maxAdView)) {
        }
    }

    private void a(d dVar) {
        e eVar = this.F.get(dVar);
        if (eVar != null) {
            eVar.M = true;
        }
    }

    public synchronized void a(e eVar, String str) {
        Logger.d(this.f9248a, "handle web view change - web view change detected from: " + eVar.J + ", to: " + str);
        l h = eVar.h();
        if (h != null && h.c() != null && !h.c().af()) {
            h.c().ag();
            String h2 = h.c().h();
            if (h2 != null) {
                h.c().c(h2 + CreativeInfo.aI);
            }
        }
        eVar.J = str;
        eVar.g().add(new l(UUID.randomUUID().toString()));
        if (eVar.C == null) {
            eVar.C = UUID.randomUUID().toString();
        }
        eVar.Z = false;
    }

    public void a(e eVar, WeakReference<View> weakReference) {
        String a2 = BrandSafetyUtils.a(weakReference.get());
        RedirectData redirectData = J.get(a2);
        Logger.d(this.f9248a, "web view scanner - check for pending redirect: " + redirectData);
        if (redirectData != null) {
            redirectData.a("LateMatchedRedirectWebview=" + a2);
            if (redirectData.k == null) {
                redirectData.k = BrandSafetyUtils.a(this.c);
            }
            if (redirectData.f9243b) {
                eVar.al = true;
            }
            l h = eVar.h();
            if (h != null) {
                h.a(redirectData);
                J.remove(a2);
            }
        }
    }

    public void a(e eVar, boolean z, String str) {
        boolean z2 = !eVar.D;
        Logger.d(this.f9248a, "reporting event , info.isClickReported =" + eVar.E + ", info.isClicked() = " + eVar.d());
        boolean z3 = !eVar.E && eVar.d();
        long j = 0;
        if (eVar.af > 0 && eVar.ag > 0) {
            j = eVar.af - eVar.ag;
        }
        ArrayList arrayList = new ArrayList();
        if (eVar.j().isEmpty()) {
            Logger.d(this.f9248a, "reporting event started, root=" + str + ", isMature=" + z + ", info=" + eVar);
            arrayList.add(a(eVar, eVar.h(), z, eVar.E || z3, j, (String) null));
        } else {
            for (l lVar : eVar.g()) {
                if (lVar.c() != null && lVar.c().T() == null) {
                    Logger.d(this.f9248a, "reporting event - don't report CI as it was matched only by eventId and not by webview resources");
                    lVar.a((CreativeInfo) null);
                }
                String str2 = null;
                if (z && lVar.f9387b != null && lVar.f9387b.f9377a != null) {
                    str2 = lVar.f9387b.f9377a + "_" + lVar.f9386a;
                    Logger.d(this.f9248a, "reporting event - imageFileIsValid filename = " + BrandSafetyUtils.a(eVar.o, lVar.f9387b.f9377a, eVar.c(), lVar.f9386a, lVar.f9387b.f));
                }
                Logger.d(this.f9248a, "reporting event, root=" + str + ", isMature=" + z + ", info=" + eVar + ", uniformity=" + (lVar.f9387b != null ? lVar.f9387b.a(com.safedk.android.internal.d.c) : 0.0f));
                arrayList.add(a(eVar, lVar, z, eVar.E || z3, j, str2));
                if (lVar.c() != null && lVar.f9387b != null) {
                    if (this.y.size() <= SafeDK.getInstance().J()) {
                        Logger.d(this.f9248a, "reporting event waiting to report file " + lVar.f9387b.f9378b);
                        a(eVar, lVar);
                    } else {
                        Logger.d(this.f9248a, "reporting event no open slot for " + this.c + ", " + lVar.f9387b.f9377a + "; next hashes to be reported to server are " + this.y.keySet());
                        BrandSafetyUtils.c(lVar.f9387b.f9378b);
                    }
                }
            }
        }
        if (StatsCollector.c() != null) {
            StatsCollector.c().a(arrayList);
        } else {
            Logger.w(this.f9248a, "reporting event - stats collector instance is null, cannot report brand safety event");
        }
        if (z2) {
            eVar.b(true);
        }
        if (z3) {
            eVar.c(true);
            Logger.w(this.f9248a, "reporting event - setIsClickReported set to true");
        }
    }

    public static void a(String str, MaxAdView maxAdView, BrandSafetyUtils.AdType adType) {
        if (str == null || maxAdView == null) {
            return;
        }
        M.put(BrandSafetyUtils.a(maxAdView), adType);
        List<WeakReference<MaxAdView>> list = L.get(str);
        if (list == null) {
            list = new ArrayList<>();
            L.put(str, list);
            Logger.d("BannerFinder", "add Max ad view: added adUnitId: " + str + " to maxAdViews map");
        } else if (list.get(0).get() == maxAdView) {
            return;
        }
        list.add(0, new WeakReference<>(maxAdView));
        Logger.d("BannerFinder", "add Max ad view: " + maxAdView + ", address: " + BrandSafetyUtils.a(maxAdView) + ", list size: " + list.size());
    }

    private synchronized void a(String str, d dVar) {
        CreativeInfo a2;
        Logger.d(this.f9248a, "pending ci check started, sdkPackageName = " + str + ", adInfoKey = " + dVar);
        if (dVar == null) {
            Logger.d(this.f9248a, "pending ci check - no activity key");
        } else {
            e eVar = this.F.get(dVar);
            if (eVar == null) {
                Logger.d(this.f9248a, "pending ci check - no banner info");
            } else {
                CreativeInfo i = eVar.i();
                if (i == null || i.af()) {
                    if (dVar.c != null) {
                        Logger.d(this.f9248a, "pending ci check - activity key : " + dVar);
                        AdNetworkDiscovery f = CreativeInfoManager.f(str);
                        if (f != null && !CreativeInfoManager.a(str, AdNetworkConfiguration.SHOULD_EXTRACT_AD_ID_FROM_BANNER_WEB_VIEW, false) && (a2 = f.a((Object) (dVar.f9356b + "_" + dVar.c + "_" + str))) != null) {
                            Logger.d(this.f9248a, "pending ci check - discovery class returned a ci: " + a2);
                            if (a2.G() == null) {
                                String string = eVar.r().getString("ad_format");
                                Logger.d(this.f9248a, "pending ci check - set ad format: " + string);
                                a2.o(string);
                            }
                            if (a2.m() == null) {
                                a2.e(dVar.c);
                            }
                            Logger.d(this.f9248a, "pending ci check - CI event ID set");
                        }
                    }
                    List<o> list = this.G.get(str);
                    if (list != null) {
                        Logger.d(this.f9248a, "pending ci check - sdk: " + str + ", no. of pending candidates: " + list.size());
                        Iterator<o> it = list.iterator();
                        while (true) {
                            if (!it.hasNext()) {
                                break;
                            }
                            o next = it.next();
                            Logger.d(this.f9248a, "pending ci check - pending candidate: " + next);
                            CreativeInfo creativeInfo = next.f9390a;
                            if (a(creativeInfo, eVar)) {
                                Logger.d(this.f9248a, "pending ci check - creative info found by WebView/eventID, CI: " + creativeInfo);
                                b(creativeInfo, eVar);
                                if (creativeInfo.m() == null) {
                                    creativeInfo.e(dVar.c);
                                    creativeInfo.f(true);
                                }
                                if (a(dVar.f9355a, dVar.e, next)) {
                                    list.remove(next);
                                } else if (creativeInfo.B()) {
                                    Logger.d(this.f9248a, "pending ci check - unreal match and event id set happened, setting ci event id back to null");
                                    creativeInfo.e((String) null);
                                    creativeInfo.f(false);
                                }
                            }
                        }
                    } else {
                        Logger.d(this.f9248a, "pending ci check - there are no pending candidates");
                    }
                } else {
                    Logger.d(this.f9248a, "pending ci check - CI already exist");
                }
            }
        }
    }

    private synchronized void a(String str, d dVar, String str2, Bundle bundle, long j) {
        if (this.I.contains(dVar.c)) {
            Logger.d(this.f9248a, "handle DID_DISPLAY - impression with id " + dVar.c + " has already been reported, ignoring. ");
        } else {
            Logger.d(this.f9248a, "handle DID_DISPLAY package=" + str + " banner key=" + dVar);
            Activity a2 = a(bundle);
            e eVar = this.F.get(dVar);
            if (eVar != null) {
                Logger.d(this.f9248a, "Banner info already exists, package=" + str + " activity banner=" + eVar);
                eVar.y = this.d;
                if (eVar.A == null || eVar.B == null) {
                    eVar.a(b(a2));
                }
            } else {
                b(dVar);
                eVar = a(a2, str, dVar.c, bundle);
                this.F.put(dVar, eVar);
                Logger.d(this.f9248a, "New activity banner created for " + str + ", banner key is " + dVar + ", current activity banners size is " + this.F.size());
            }
            eVar.L = str2;
            eVar.ag = j;
            a(eVar, false, "handleDidDisplay");
        }
    }

    public synchronized void a(String str, String str2, d dVar, WeakReference<View> weakReference) {
        e eVar;
        Logger.d(this.f9248a, "monitor impression started for " + str + ", adInfoKey = " + dVar + ", creativeId = " + str2);
        if (weakReference != null && weakReference.get() != null && (eVar = this.F.get(dVar)) != null) {
            a(str, dVar);
            eVar.L = str2;
            eVar.ae = true;
            eVar.ah = 0.0f;
            if (weakReference.get().getWidth() > 0 && weakReference.get().getHeight() > 0) {
                eVar.ah = weakReference.get().getWidth() / weakReference.get().getHeight();
            }
            a(weakReference, eVar);
        }
    }

    private synchronized void a(String str, String str2, String str3, d dVar, Bundle bundle, long j) {
        if (this.I.contains(dVar.c)) {
            Logger.d(this.f9248a, "handle WILL_DISPLAY - impression with id " + dVar.c + " has already been reported, ignoring. ");
        } else {
            Activity a2 = a(bundle);
            Logger.d(this.f9248a, "handle WILL_DISPLAY - adActivity = " + a2);
            Logger.d(this.f9248a, "handle WILL_DISPLAY - image count for " + this.c.name() + " is " + BrandSafetyUtils.b(this.c) + ", impressions to report(" + this.y.keySet().size() + ") = " + this.y.keySet());
            if (f(str, str2)) {
                e eVar = this.F.get(dVar);
                if (eVar == null) {
                    eVar = a(a2, str2, dVar.c, bundle);
                    this.F.put(dVar, eVar);
                    Logger.d(this.f9248a, "New activity banner created for " + str2 + ", banner key is " + dVar + ", current activity banners size is " + this.F.size());
                } else {
                    if (eVar.z == null) {
                        eVar.z = bundle;
                    }
                    if (eVar.A == null || eVar.B == null) {
                        eVar.a(b(a2));
                    }
                }
                eVar.X = true;
                eVar.ad = true;
                eVar.af = j;
                a(eVar, false, "handleWillDisplay");
            } else {
                this.d++;
            }
            b bVar = new b(str, str2, str3, dVar, bundle);
            bVar.g = this.A.scheduleAtFixedRate(bVar, 0L, 1000L, TimeUnit.MILLISECONDS);
        }
    }

    private void a(WeakReference<View> weakReference, e eVar) {
        a aVar = new a(eVar, weakReference, this.e);
        eVar.ak = aVar;
        CreativeInfo i = eVar.i();
        if (i != null && i.v() && h(eVar.c())) {
            Logger.d(this.f9248a, "set Impression Handler Task If Needed : task set but not started since the ad is a video ad and the video hasn't finished yet. " + eVar);
            return;
        }
        int X = SafeDK.getInstance().X() * 1000;
        Logger.d(this.f9248a, "start taking screenshots for view: " + weakReference.get().toString() + ", samplingInterval = " + X);
        aVar.d = this.A.scheduleAtFixedRate(aVar, 500L, X, TimeUnit.MILLISECONDS);
        Logger.d(this.f9248a, "set Impression Handler Task If Needed : task created and started : " + eVar);
    }

    public synchronized void a(List<WeakReference<View>> list, d dVar) {
        boolean z;
        Iterator<Map.Entry<d, e>> it = this.F.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<d, e> next = it.next();
            if (next.getKey().equals(dVar)) {
                Logger.d(this.f9248a, "Skipping banner info of new impression, key=" + next.getKey());
            } else if (next.getKey().f9355a.equals(dVar.f9355a)) {
                Logger.d(this.f9248a, "Check to report banner info, adInfoKey=" + next.getKey());
                e value = next.getValue();
                if (value.J != null) {
                    Logger.d(this.f9248a, "Looking for completed banners to report, WebView=" + value.J);
                    if (list != null) {
                        for (WeakReference<View> weakReference : list) {
                            String a2 = BrandSafetyUtils.a(weakReference.get());
                            if (value.J.equals(a2)) {
                                Logger.d(this.f9248a, "WebView address still active, WebView=" + a2);
                                z = true;
                                break;
                            }
                        }
                    }
                }
                z = false;
                if (!z) {
                    a(value, true, "reportCompletedBanners");
                    it.remove();
                    b(value);
                }
            } else {
                Logger.d(this.f9248a, "Skipping banner info of another adUnitId, key=" + next.getKey());
            }
        }
    }

    public boolean a(int i) {
        boolean b2 = BrandSafetyUtils.b(i);
        Logger.d(this.f9248a, "should stop sampling, max uniformed pixels count=" + i + ", return value=" + b2);
        return b2;
    }

    public static boolean a(View view) {
        return view.getClass().getName().equals(com.safedk.android.analytics.brandsafety.creatives.discoveries.d.j);
    }

    private boolean a(final View view, String str, final String str2, final d dVar) {
        e eVar;
        String b2;
        final AdNetworkDiscovery f = CreativeInfoManager.f(str);
        if (f == null) {
            Logger.d(this.f9248a, "extract ad ID from view - no discovery object for: " + str);
            return false;
        }
        boolean a2 = CreativeInfoManager.a(str, AdNetworkConfiguration.SHOULD_EXTRACT_AD_ID_FROM_BANNER_WEB_VIEW, false);
        boolean a3 = CreativeInfoManager.a(str, AdNetworkConfiguration.AD_ID_EXTRACTED_FROM_BANNER_WEB_VIEW_IS_MAX_CREATIVE_ID, false);
        boolean a4 = CreativeInfoManager.a(str, AdNetworkConfiguration.SHOULD_SCAN_BANNER_OBJECT_USING_REFLECTION, false);
        boolean a5 = CreativeInfoManager.a(str, AdNetworkConfiguration.SUPPORTS_NATIVE_BANNERS_USING_BANNER_KEY, false);
        e eVar2 = this.F.get(dVar);
        if (a2) {
            Logger.d(this.f9248a, "extract ad ID from view - should extract: " + a2);
            if (eVar2 != null && eVar2.i() == null && (b2 = f.b(view)) != null) {
                Logger.d(this.f9248a, "extract ad ID from view - ad ID extracted from view: " + b2);
                if (a3 && str2 != null && !str2.equals(b2)) {
                    Logger.d(this.f9248a, "extract ad ID from view - value extracted (" + b2 + ") from widget is not equal to creative ID (" + str2 + ")");
                    return true;
                }
                Logger.d(this.f9248a, "extract ad ID from view - attempting to locate ci by ad ID value " + b2);
                CreativeInfo a6 = f.a((Object) b2);
                if (a6 != null) {
                    Logger.d(this.f9248a, "extract ad ID from view - CI found, ad ID = " + b2 + ", view : " + view.toString() + ", ci : " + a6);
                    a6.a((Object) view);
                    a6.e(dVar.c);
                    a6.g(dVar.f9356b);
                    b(a6, eVar2);
                    Logger.d(this.f9248a, "extract ad ID from view - ci placementId set to " + dVar.f9356b + ", event ID : " + dVar.c + " , ad type  = " + a6.I());
                    a(new o(a6, CreativeInfo.n, b2));
                } else {
                    Logger.d(this.f9248a, "extract ad ID from view - CI not found, adId = " + b2);
                }
            }
        } else if (a4) {
            e eVar3 = this.F.get(dVar);
            if (eVar3 != null && eVar3.j().isEmpty()) {
                this.A.execute(new Runnable() {
                    @Override
                    public void run() {
                        List<CreativeInfo> a7 = f.a(view, str2);
                        if (a7 == null) {
                            Logger.d(BannerFinder.this.f9248a, "extract ad ID from view - reflect CI not found");
                            return;
                        }
                        for (CreativeInfo creativeInfo : a7) {
                            Logger.d(BannerFinder.this.f9248a, "extract ad ID from view - reflect CI found, view : " + view.toString() + ", ci : " + creativeInfo);
                            creativeInfo.a((Object) view);
                            creativeInfo.a(BannerFinder.this.c);
                            creativeInfo.e(dVar.c);
                            creativeInfo.g(dVar.f9356b);
                            if (creativeInfo.J() == null) {
                                creativeInfo.q(creativeInfo.L());
                            }
                            Logger.d(BannerFinder.this.f9248a, "extract ad ID from view - reflect ci placement ID set to " + dVar.f9356b + ", event ID : " + dVar.c);
                            BannerFinder.this.a(new o(creativeInfo, CreativeInfo.n, null));
                        }
                    }
                });
            }
        } else if (a5 && (eVar = this.F.get(dVar)) != null && eVar.j().isEmpty() && a(str, view) && eVar.D()) {
            com.safedk.android.utils.l.b(this.f9248a, "extract ad ID from view - info :" + eVar + ", ci : " + eVar.j());
            Logger.d(this.f9248a, "extract ad ID from view - attempting to find CI by adInfoKey " + dVar);
            this.A.execute(new Runnable() {
                @Override
                public void run() {
                    CreativeInfo a7 = f.a((Object) (dVar.f9356b + "_" + dVar.c + "_" + dVar.d));
                    if (a7 == null) {
                        Logger.d(BannerFinder.this.f9248a, "extract ad ID from view - reflect CI not found");
                        return;
                    }
                    Logger.d(BannerFinder.this.f9248a, "extract ad ID from view -  find CI by key found, adInfoKey : " + dVar + ", creativeInfo : " + a7);
                    a7.a((Object) view);
                    a7.a(BannerFinder.this.c);
                    a7.e(dVar.c);
                    a7.g(dVar.f9356b);
                    if (a7.J() == null) {
                        a7.q(a7.L());
                    }
                    Logger.d(BannerFinder.this.f9248a, "extract ad ID from view - reflect ci placement ID set to " + dVar.f9356b + ", event ID : " + dVar.c);
                    BannerFinder.this.a(new o(a7, CreativeInfo.n, null));
                }
            });
        }
        return false;
    }

    private boolean a(c cVar, String str, String str2) {
        if (cVar != null) {
            String c = com.safedk.android.utils.l.c(str, "clcode");
            Logger.d(this.f9248a, "check ad click URL validity - clcode: " + c + ", view address: " + str2 + ", views hierarchy: " + cVar.x());
            CreativeInfo i = cVar.i();
            if ((c != null && i != null && !i.J().equals(c)) || cVar.x() == null || str2 == null || !cVar.x().contains(str2)) {
                Logger.d(this.f9248a, "check ad click URL validity - ad ID or view address does not match. clcode: " + c + ", view address: " + str2 + ", views hierarchy: " + cVar.x());
                return false;
            }
        }
        return true;
    }

    private boolean a(CreativeInfo creativeInfo, e eVar) {
        if (eVar == null) {
            Logger.d(this.f9248a, "verify matching - banner info is null");
            return false;
        } else if (eVar.u == null) {
            Logger.d(this.f9248a, "verify matching - banner info maxSdk is null");
            return false;
        } else if (creativeInfo == null) {
            Logger.d(this.f9248a, "verify matching - creative info is null");
            return false;
        } else {
            String O = creativeInfo.O();
            if (!eVar.u.equals(O)) {
                Logger.d(this.f9248a, "verify matching  - sdks does not match, ci sdk is: " + O + " and banner sdk is: " + eVar.u);
                return false;
            }
            Logger.d(this.f9248a, "verify matching - ci sdk is: " + O);
            Logger.d(this.f9248a, "verify matching - banner info: " + eVar);
            if (eVar.K == null || creativeInfo.m() == null || eVar.K.equals(creativeInfo.m())) {
                return a(creativeInfo.ac(), creativeInfo.ad(), eVar);
            }
            Logger.d(this.f9248a, "verify matching - incompatible event ID, ci: " + creativeInfo.m() + ", info: " + eVar.K);
            return false;
        }
    }

    public static boolean a(String str, MaxAdView maxAdView) {
        List<WeakReference<MaxAdView>> list = L.get(str);
        if (maxAdView != null && list != null) {
            for (WeakReference<MaxAdView> weakReference : list) {
                if (weakReference != null && maxAdView == weakReference.get()) {
                    weakReference.clear();
                    list.remove(weakReference);
                    Logger.d("BannerFinder", "remove Max ad view: " + maxAdView + ", address: " + BrandSafetyUtils.a(maxAdView) + ", list size: " + list.size());
                    if (list.isEmpty()) {
                        L.remove(str);
                        Logger.d("BannerFinder", "remove Max ad view: removing adUnitId: " + str + " from maxAdViews");
                    }
                    return true;
                }
            }
        }
        return false;
    }

    private boolean a(String str, String str2, e eVar) {
        if (str2 == null || MediaPlayer.class.getCanonicalName().equals(str)) {
            Logger.d(this.f9248a, "verify matching object skipped, event ID: " + eVar.K + ", object address: " + str2 + ", object type: " + str);
            return true;
        } else if (eVar.x() == null || !eVar.x().contains(str2)) {
            Logger.d(this.f9248a, "verify matching object failed, event ID: " + eVar.K + ", object address: " + str2 + ", views hierarchy: " + eVar.x());
            return false;
        } else {
            Logger.d(this.f9248a, "verify matching object done, event ID: " + eVar.K + ", object address: " + str2 + ", views hierarchy: " + eVar.x());
            return true;
        }
    }

    private synchronized boolean a(String str, String str2, o oVar) {
        boolean z;
        e eVar;
        com.safedk.android.utils.l.b(this.f9248a, "set CI started, adUnitId=" + str + " matchingInfo=" + (oVar == null ? "null" : oVar.toString()));
        if (oVar == null) {
            Logger.d(this.f9248a, "set CI - no matching info");
            z = false;
        } else {
            CreativeInfo creativeInfo = oVar.f9390a;
            if (creativeInfo != null) {
                d dVar = new d(creativeInfo.i() != null ? creativeInfo.i() : str, creativeInfo.D(), creativeInfo.m(), creativeInfo.O(), str2);
                Logger.d(this.f9248a, "set CI - activity key: " + dVar);
                Iterator<d> it = this.F.keySet().iterator();
                while (true) {
                    if (!it.hasNext()) {
                        eVar = null;
                        break;
                    }
                    d next = it.next();
                    if (dVar.a(next, creativeInfo)) {
                        eVar = this.F.get(next);
                        break;
                    }
                }
                com.safedk.android.utils.l.b(this.f9248a, "set CI - current activity banner: " + (eVar == null ? "null" : eVar) + ", current activity banners: " + this.F);
                if (eVar != null) {
                    if (!eVar.aa && StatsReporter.b().a(creativeInfo, eVar)) {
                        eVar.aa = true;
                    }
                    CreativeInfo i = eVar.i();
                    if (i != null) {
                        Logger.d(this.f9248a, "set CI - previous CI id: " + i.J());
                        if (i.J() != null && i.J().equals(creativeInfo.J())) {
                            CreativeInfoManager.b(i);
                            com.safedk.android.utils.l.b(this.f9248a, "set CI - already matched, same ad ID. current match: " + creativeInfo.V() + ", previous match: " + i.V());
                        }
                    }
                    creativeInfo.a(oVar.f9391b, oVar.c);
                    if (!TextUtils.isEmpty(eVar.J) && creativeInfo.S() != null && !creativeInfo.S().contains("wv=" + eVar.J)) {
                        creativeInfo.t("wv=" + eVar.J);
                    }
                    eVar.a(creativeInfo);
                    a(eVar.h());
                    eVar.h().d();
                    Logger.d(this.f9248a, "set CI - CI is set for activity banner " + dVar + ". CI : " + creativeInfo);
                    if (h(eVar.c()) && creativeInfo.v() && eVar.ak != null && !eVar.G && eVar.ak.d != null) {
                        eVar.ak.d.cancel(false);
                        eVar.ak = null;
                        Logger.d(this.f9248a, "set CI - canceling running impressionHandlerTask (ad is a video ad) " + eVar);
                    }
                    i(creativeInfo.ad());
                    if (eVar.I == AdNetworkDiscovery.WebViewResourceMatchingMethod.WEBVIEW_LOOKUP && eVar.J != null) {
                        com.safedk.android.utils.l.b(this.f9248a, "set CI - attach resources to CI, webview address: " + eVar.J + " , ci: " + creativeInfo);
                        com.safedk.android.analytics.brandsafety.creatives.e.a(eVar.J, creativeInfo);
                    }
                    if (i != null && i.J() != null && i.J().equals(creativeInfo.J())) {
                        Iterator<String> it2 = i.q().iterator();
                        while (it2.hasNext()) {
                            String next2 = it2.next();
                            if (!creativeInfo.q().contains(next2)) {
                                Logger.d(this.f9248a, "set CI - added resource URL " + next2 + " to CI");
                                creativeInfo.q().add(next2);
                            }
                        }
                        Iterator<String> it3 = i.p().iterator();
                        while (it3.hasNext()) {
                            String next3 = it3.next();
                            if (!creativeInfo.p().contains(next3)) {
                                Logger.d(this.f9248a, "set CI - added DSP URL " + next3 + " to CI");
                                creativeInfo.p().add(next3);
                            }
                        }
                    }
                    b(eVar, creativeInfo);
                    a(eVar, false, "setCreativeInfo");
                    z = true;
                } else {
                    com.safedk.android.utils.l.b(this.f9248a, "set CI - no activity banner, cannot set CI. current activity banners: " + this.F);
                }
            } else {
                Logger.d(this.f9248a, "set CI - no CI");
            }
            z = false;
        }
        return z;
    }

    private List<String> b(List<WeakReference<View>> list) {
        ArrayList arrayList = new ArrayList();
        for (WeakReference<View> weakReference : list) {
            if (weakReference == null || weakReference.get() == null) {
                arrayList.add("");
            } else {
                arrayList.add(BrandSafetyUtils.a(weakReference.get()));
            }
        }
        return arrayList;
    }

    private void b(CreativeInfo creativeInfo, e eVar) {
        BrandSafetyUtils.AdType adType;
        Logger.d(this.f9248a, "update ad format : started, sdk = " + creativeInfo.O() + ", initial ad type = " + creativeInfo.G() + " , bannerInfo = " + eVar);
        if (CreativeInfoManager.a(creativeInfo.O(), AdNetworkConfiguration.SET_AD_FORMAT_FROM_APPLOVIN_BUNDLE, false)) {
            Logger.d(this.f9248a, "update ad type. bannerInfo.isMrecAd : " + eVar.E());
            if (eVar.E()) {
                Logger.d(this.f9248a, "update ad type. Mrec identified");
                adType = BrandSafetyUtils.AdType.MREC;
            } else {
                Logger.d(this.f9248a, "update ad type. Banner identified");
                adType = BrandSafetyUtils.AdType.BANNER;
            }
            creativeInfo.o(adType.name());
            Logger.d(this.f9248a, "update ad type. ad type set to " + adType.name());
        }
    }

    private synchronized void b(d dVar) {
        Iterator<Map.Entry<d, e>> it = this.F.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<d, e> next = it.next();
            d key = next.getKey();
            e value = next.getValue();
            if (key.f9355a.equals(dVar.f9355a) && key.f9356b.equals(dVar.f9356b) && !key.c.equals(dVar.c) && !value.X) {
                Logger.d(this.f9248a, "report undetected banner started for AdInfoKey=" + key);
                a(value, true, "reportUndetectedBannerIfNeeded");
                it.remove();
                b(value);
            }
        }
    }

    private void b(e eVar) {
        try {
            Logger.d(this.f9248a, "clean started, currentActivityBanners size is " + this.F.size());
            Logger.d(this.f9248a, "adding to reported impressions map. id =  " + eVar.K);
            this.I.add(eVar.K);
            if (eVar != null) {
                eVar.Z = true;
                if (eVar.ab != null) {
                    eVar.ab.cancel(false);
                }
                for (l lVar : eVar.g()) {
                    if (lVar.f9387b != null && lVar.f9387b.f9378b != null) {
                        lVar.c = lVar.f9387b.f9378b;
                        Logger.d(this.f9248a, "set last impression screenshot filename to " + lVar.f9387b.f9378b);
                    }
                }
                if (eVar.j().isEmpty()) {
                    com.safedk.android.analytics.brandsafety.creatives.e.a(eVar.J);
                    SafeDKWebAppInterface.a(eVar.J);
                    return;
                }
                for (CreativeInfo creativeInfo : eVar.j()) {
                    if (creativeInfo != null) {
                        String ad = creativeInfo.ad();
                        com.safedk.android.analytics.brandsafety.creatives.e.a(ad, creativeInfo);
                        com.safedk.android.analytics.brandsafety.creatives.e.a(ad);
                        SafeDKWebAppInterface.a(ad);
                    }
                }
            }
        } catch (Throwable th) {
            Logger.e(this.f9248a, "Error in clean " + th.getMessage(), th);
            new CrashReporter().caughtException(th);
        }
    }

    public WeakReference<View> c(List<WeakReference<View>> list) {
        WeakReference<View> weakReference = null;
        for (WeakReference<View> weakReference2 : list) {
            Logger.d(this.f9248a, "select monitor view: iterating view is " + weakReference2.get());
            if (weakReference == null) {
                Logger.d(this.f9248a, "select monitor view: setting view " + weakReference2.get());
            } else if (weakReference2.get() instanceof WebView) {
                Logger.d(this.f9248a, "select monitor view: re-setting view " + weakReference2.get());
                weakReference.clear();
            } else {
                Logger.d(this.f9248a, "select monitor view: clearing view " + weakReference2.get());
                weakReference2.clear();
                weakReference2 = weakReference;
            }
            weakReference = weakReference2;
        }
        return weakReference;
    }

    private void c(Activity activity) {
        String a2 = BrandSafetyUtils.a(com.safedk.android.internal.b.getInstance().getForegroundActivity().getClass().getName(), true);
        String a3 = BrandSafetyUtils.a(activity.getClass().getName(), true);
        if (a3 == null || a3.equals(a2)) {
            return;
        }
        Logger.d(this.f9248a, "compareAdActivityToForeground found ad activity different than foreground, foreground address is: " + a2 + ", and activity address is: " + a3);
    }

    private synchronized void c(d dVar) {
        e eVar = this.F.get(dVar);
        if (eVar != null) {
            Logger.d(this.f9248a, "handle DID_HIDE, placementId=" + dVar.f9356b);
            eVar.Z = true;
        }
    }

    private static void d() {
        e eVar;
        J = new PersistentConcurrentHashMap("SafeDKRedirects." + com.safedk.android.utils.l.a(SafeDK.getInstance().l()));
        Logger.d("BannerFinder", "handle saved redirects from previous session, found " + J.size() + " redirects");
        ArrayList arrayList = new ArrayList();
        for (String str : J.keySet()) {
            RedirectData redirectData = J.get(str);
            if (redirectData != null && (redirectData.f9242a || redirectData.f9243b)) {
                redirectData.a("UnmatchedRedirectWebview=" + str);
                if (redirectData.k == BrandSafetyEvent.AdFormatType.MREC) {
                    eVar = new r(redirectData.i, redirectData.j);
                } else {
                    if (redirectData.k == null) {
                        redirectData.k = BrandSafetyEvent.AdFormatType.BANNER;
                        redirectData.a("UnmatchedRedirectFallback=BANNER");
                    }
                    eVar = new e(redirectData.i, redirectData.j);
                }
                BrandSafetyEvent a2 = a(eVar, new l(redirectData), true, false, 0L, (String) null);
                a2.c(true);
                a2.a(SafeDK.getInstance().e());
                arrayList.add(a2);
            }
        }
        if (StatsCollector.c() == null) {
            Logger.w("BannerFinder", "handle saved redirects from previous session, cannot report brand safety event");
            return;
        }
        StatsCollector.c().a(arrayList);
        J.clear();
    }

    private synchronized void d(d dVar) {
        Logger.d(this.f9248a, "handle DID_CLICKED started, adInfoKey = " + dVar);
        e eVar = this.F.get(dVar);
        if (eVar == null) {
            Logger.d(this.f9248a, "handle DID_CLICKED current activity banner is null");
        } else if (eVar.C == null || !CreativeInfoManager.a(eVar.c(), AdNetworkConfiguration.SHOULD_IGNORE_BANNER_MULTI_AD_DID_CLICK_EVENT, false)) {
            eVar.a(true);
            if (eVar.e() != null) {
                Logger.d(this.f9248a, "handle DID_CLICKED current activity banner already have click url");
            } else if (K == null) {
                Logger.d(this.f9248a, "handle DID_CLICKED current click url candidate is null");
            } else if (K.f9362a == 0) {
                Logger.d(this.f9248a, "handle DID_CLICKED current click url candidate has zero timestamp");
            } else if (!a(eVar, K.f9363b, K.c)) {
                Logger.d(this.f9248a, "handle DID_CLICKED ad click url is not valid");
            } else if (System.currentTimeMillis() - K.f9362a < 5000) {
                Logger.d(this.f9248a, "handle DID_CLICKED setting click URL to " + K.f9363b);
                eVar.c(K.f9363b);
                K = null;
            } else {
                Logger.d(this.f9248a, "handle DID_CLICKED click url candidate's timestamp is not within the time range");
            }
            a(eVar, false, "handleDidClicked");
        } else {
            Logger.d(this.f9248a, "handle DID_CLICKED current activity banner multi ad");
        }
    }

    private void g(String str, String str2) {
        K = new h(System.currentTimeMillis(), str, str2);
    }

    private boolean k(String str) {
        for (e eVar : this.F.values()) {
            if (eVar.J != null && eVar.J.equals(str) && eVar.i() != null) {
                return true;
            }
        }
        return false;
    }

    public Activity a(Context context) {
        Context context2 = context;
        while (context2 instanceof ContextWrapper) {
            if (context2 instanceof Activity) {
                return (Activity) context2;
            }
            context2 = ((ContextWrapper) context2).getBaseContext();
            Logger.d(this.f9248a, "getActivity: now context type is: " + context2.getClass().getName());
        }
        return null;
    }

    @Override
    protected c a(String str, String str2, String str3, BrandSafetyUtils.ScreenShotOrientation screenShotOrientation, String str4, String str5) {
        return new e(str, str2, str3, screenShotOrientation, str4, str5);
    }

    protected e a(Activity activity, String str, int i, String str2, Bundle bundle, String str3) {
        e eVar = new e(b(com.safedk.android.internal.b.getInstance().getForegroundActivity()), str, i, str2, bundle, str3);
        eVar.ac = new WeakReference<>(activity);
        return eVar;
    }

    @Override
    public synchronized List<CreativeInfo> a(String str, String str2) {
        List<CreativeInfo> list;
        Iterator<e> it = this.F.values().iterator();
        while (true) {
            if (it.hasNext()) {
                e next = it.next();
                if (next.J != null && next.J.equals(str2) && next.u != null && next.u.equals(str) && next.X) {
                    list = next.k();
                    break;
                }
            } else {
                List<o> list2 = this.G.get(str);
                ArrayList arrayList = new ArrayList();
                if (list2 != null) {
                    for (o oVar : list2) {
                        if (oVar.f9390a != null && oVar.f9390a.ad() != null && oVar.f9390a.ad().equals(str2)) {
                            arrayList.add(oVar.f9390a);
                        }
                    }
                }
                if (!arrayList.isEmpty()) {
                    Logger.d(this.f9248a, "get current CIs for webview address: " + str2 + ", found " + arrayList.size() + " pending CIs");
                }
                list = arrayList;
            }
        }
        return list;
    }

    @Override
    public synchronized void a(Activity activity) {
        com.safedk.android.utils.l.b(this.f9248a, "start monitoring of redirect/expand, activity: " + activity + ", current activity banners: " + this.F);
        e a2 = CreativeInfoManager.a(activity);
        if (a2 != null) {
            a2.an = activity.toString();
            l h = a2.h();
            if (h != null && h.d != null) {
                h.d.a("redirectActivityName=" + a2.an);
            }
        }
    }

    protected void a(ViewGroup viewGroup, e eVar) {
        Logger.d(this.f9248a, "collect banner text started. view : " + viewGroup + ", bannerInfo : " + eVar);
        if (viewGroup == null) {
            return;
        }
        if (eVar.D()) {
            Logger.d(this.f9248a, "collect banner text - ad is a native ad: " + viewGroup + ", child count is: " + viewGroup.getChildCount());
            return;
        }
        Logger.d(this.f9248a, "collect banner text - view is: " + viewGroup + ", child count is: " + viewGroup.getChildCount());
        int i = 0;
        while (true) {
            int i2 = i;
            if (i2 >= viewGroup.getChildCount()) {
                return;
            }
            View childAt = viewGroup.getChildAt(i2);
            Logger.d(this.f9248a, "collect banner text - child view " + i2 + " is: " + childAt);
            if (childAt instanceof TextView) {
                Logger.d(this.f9248a, "collect banner text - text box found. view " + childAt);
                if (eVar != null && eVar.i() != null) {
                    TextView textView = (TextView) childAt;
                    eVar.i().w("text:" + textView.getText().toString());
                    Logger.d(this.f9248a, "collect banner text - added text " + textView.getText().toString());
                }
            } else if (childAt instanceof ViewGroup) {
                a((ViewGroup) childAt, eVar);
            }
            i = i2 + 1;
        }
    }

    protected void a(ViewGroup viewGroup, String str, String str2, String str3, d dVar, List<WeakReference<View>> list, List<v> list2, List<String> list3, List<String> list4, int i, boolean z, boolean z2) {
        boolean z3;
        boolean z4;
        if (viewGroup == null) {
            return;
        }
        int i2 = i + 1;
        int i3 = 0;
        while (i3 < viewGroup.getChildCount()) {
            View childAt = viewGroup.getChildAt(i3);
            String a2 = BrandSafetyUtils.a(childAt);
            list3.add(a2);
            list4.add("h" + i2 + "c" + (i3 + 1) + ":" + childAt);
            if (a(childAt, str, str3, dVar)) {
                return;
            }
            if (TextUtils.isEmpty(str2)) {
                z3 = true;
            } else if (str2.equals(a2)) {
                Logger.d(this.f9248a, "scan for banner views - verified by ad network view address received from Max: " + str2 + ", view: " + childAt);
                z3 = true;
            } else {
                z3 = z;
            }
            if (z3) {
                a(viewGroup, str, dVar);
            }
            if (z3 && (childAt instanceof WebView)) {
                a(childAt, str, list, list2);
                return;
            }
            if (z3 && a(str, childAt)) {
                a(childAt, str, list, list2);
                z4 = true;
            } else {
                z4 = z2;
            }
            if ((childAt instanceof TextView) && z4) {
                e eVar = this.F.get(dVar);
                if (eVar != null && eVar.i() != null && !eVar.D()) {
                    TextView textView = (TextView) childAt;
                    eVar.i().w("text:" + textView.getText().toString());
                    Logger.d(this.f9248a, "scan for banner views - added text " + textView.getText().toString());
                }
            } else if (childAt instanceof ViewGroup) {
                a((ViewGroup) childAt, str, str2, str3, dVar, list, list2, list3, list4, i2, z3, z4);
            }
            i3++;
            z2 = z4;
            z = z3;
        }
    }

    protected void a(ViewGroup viewGroup, List<v> list, List<String> list2, int i) {
        if (viewGroup == null) {
            return;
        }
        int i2 = i + 1;
        int i3 = 0;
        while (true) {
            int i4 = i3;
            if (i4 >= viewGroup.getChildCount()) {
                return;
            }
            View childAt = viewGroup.getChildAt(i4);
            list2.add("h" + i2 + "c" + (i4 + 1) + ":" + childAt);
            if (childAt instanceof WebView) {
                list.add(new v(BrandSafetyUtils.a(childAt), childAt.getClass().getName(), childAt.getWidth(), childAt.getHeight()));
                Logger.d(this.f9248a, "found expanded view: " + childAt + ": width: " + childAt.getWidth() + " height: " + childAt.getHeight() + " sdk: " + childAt.getClass().getName());
            } else if (childAt instanceof ViewGroup) {
                a((ViewGroup) childAt, list, list2, i2);
            }
            i3 = i4 + 1;
        }
    }

    public void a(CreativeInfo creativeInfo) {
        for (d dVar : this.F.keySet()) {
            this.F.get(dVar).h().d();
            e eVar = this.F.get(new d(dVar.f9355a, creativeInfo.D(), creativeInfo.m(), creativeInfo.O(), dVar.e));
            if (eVar != null && eVar.C == null) {
                eVar.C = UUID.randomUUID().toString();
            }
        }
    }

    protected void a(CreativeInfo creativeInfo, o oVar) {
        ArrayList arrayList;
        String O = creativeInfo.O();
        Logger.d(this.f9248a, "set CI details - adding as pending, sdk: " + O + " matching info: " + oVar);
        List<o> list = this.G.get(O);
        if (list == null) {
            ArrayList arrayList2 = new ArrayList();
            this.G.put(O, arrayList2);
            arrayList = arrayList2;
        } else {
            arrayList = list;
        }
        HashSet hashSet = new HashSet();
        for (o oVar2 : arrayList) {
            if (oVar2.f9390a != null) {
                hashSet.add(oVar2.f9390a.J());
            }
        }
        if (hashSet.contains(oVar.f9390a.J())) {
            Logger.d(this.f9248a, "add as pending - CI with ad id: " + oVar.f9390a.J() + " already in pending list, not adding");
        } else {
            arrayList.add(oVar);
        }
    }

    @Override
    public synchronized void a(l lVar) {
        Logger.d(this.f9248a, "remove impression screenshots started");
        if (lVar != null) {
            if (lVar.c != null) {
                Logger.d(this.f9248a, "Calling remove ad files, filename = " + lVar.c);
                BrandSafetyUtils.c(lVar.c);
                lVar.c = null;
            } else {
                Logger.d(this.f9248a, "lastActivityImpressionScreenshotFilename is null");
            }
        }
        this.z.clear();
    }

    @Override
    public synchronized void a(String str) {
        for (e eVar : this.F.values()) {
            eVar.Z = true;
        }
    }

    void a(String str, String str2, d dVar, String str3, List<WeakReference<View>> list, List<String> list2) {
        try {
            List<WeakReference<MaxAdView>> list3 = L.get(dVar.f9355a);
            if (list3 != null) {
                for (WeakReference<MaxAdView> weakReference : list3) {
                    if (weakReference.get() != null) {
                        Logger.d(this.f9248a, "find banner impression - sdk: " + str + ", ad unit id: " + dVar.f9355a + ", max ad view: " + weakReference.get().toString() + ", address: " + BrandSafetyUtils.a(weakReference.get()));
                        ArrayList arrayList = new ArrayList();
                        ArrayList arrayList2 = new ArrayList();
                        list2.add(BrandSafetyUtils.a(weakReference.get()));
                        arrayList2.add("h1c1:" + weakReference.get().toString());
                        a(weakReference.get(), str, BrandSafetyUtils.k(str3), str2, dVar, list, arrayList, list2, arrayList2, 1, false, false);
                        if (!list.isEmpty()) {
                            Logger.d(this.f9248a, "find banner impression - found views: " + arrayList);
                            com.safedk.android.utils.l.b(this.f9248a, "find banner impression - views hierarchy: " + arrayList2);
                            return;
                        }
                        Logger.d(this.f9248a, "find banner impression - no new views found for top view: " + weakReference.get().toString());
                    } else {
                        Logger.d(this.f9248a, "find banner impression - sdk: " + str + ", ad unit id: " + dVar.f9355a + ", no max ad view found");
                        if (weakReference.get() != null) {
                            a(dVar.f9355a, weakReference.get());
                        }
                    }
                }
            }
        } catch (Throwable th) {
            Logger.e(this.f9248a, "Failed while scanning the screen for banners", th);
            new CrashReporter().caughtException(th);
        }
    }

    @Override
    public synchronized void a(String str, String str2, String str3) {
        Logger.d(this.f9248a, "set ad click URL started, sdkPackageName: " + str2 + ", url: " + str + ", view address: " + str3);
        List<CreativeInfo> a2 = a(str2, str3);
        if (a2 != null) {
            for (CreativeInfo creativeInfo : a2) {
                if (creativeInfo.ad().equals(str3)) {
                    Logger.d(this.f9248a, "check ad click URL validity - view address: " + str3 + ", updating click_url in pending CIs list. url = " + str + ", adId = " + creativeInfo.J());
                    creativeInfo.s(str);
                }
            }
        }
        if (str != null) {
            Iterator<e> it = this.F.values().iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                e next = it.next();
                if (next != null && next.c() != null && SdksMapping.isSameSdkByPackages(next.c(), str2) && a(next, str, str3)) {
                    if (!next.d()) {
                        Logger.d(this.f9248a, "set ad click URL - current activity banner is not marked as clicked, setting candidate: " + str);
                        g(str, str3);
                    } else if (next.e() == null) {
                        com.safedk.android.utils.l.b(this.f9248a, "set ad click URL - no click URL yet, setting click URL: " + str + ", CI: " + next.i());
                        if (next.c(str)) {
                            a(next, false, "setCurrentAdClickURL");
                        }
                    } else {
                        com.safedk.android.utils.l.b(this.f9248a, "set ad click URL - click URL already set: " + next.e() + ", CI: " + next.i());
                    }
                }
            }
        }
    }

    public void a(String str, String str2, String str3, d dVar, Bundle bundle) {
        Activity a2 = a(bundle);
        if (this.I.contains(dVar.c)) {
            Logger.d(this.f9248a, "handle REVENUE_EVENT - impression with id " + dVar.c + " has already been reported, ignoring. ");
        } else if (!f(str, str2)) {
            this.d++;
        } else {
            e eVar = this.F.get(dVar);
            if (eVar == null) {
                eVar = a(a2, str2, dVar.c, bundle);
                this.F.put(dVar, eVar);
                Logger.d(this.f9248a, "New activity banner created for " + str2 + ", banner key is " + dVar + ", current activity banners size is " + this.F.size());
            } else {
                if (eVar.z == null) {
                    eVar.z = bundle;
                }
                if (eVar.A == null || eVar.B == null) {
                    eVar.a(b(a2));
                }
            }
            if (eVar != null) {
                if (bundle.getString("revenue_event") != null) {
                    eVar.O = bundle.getString("revenue_event");
                } else {
                    eVar.O = "unknown";
                }
                eVar.L = str3;
                a(eVar, false, "handleRevenueEvent");
                Logger.d(this.f9248a, "Revenue event set to " + bundle.getString("revenue_event") + " for eventId " + dVar.c);
                eVar.X = true;
            }
        }
    }

    @Override
    public void a(String str, String str2, boolean z) {
    }

    protected boolean a(View view, String str, List<WeakReference<View>> list, List<v> list2) {
        String a2 = BrandSafetyUtils.a(view);
        Logger.d(this.f9248a, "handle ad view - view is an instance of " + view.getClass().getName() + " : " + a2 + ", class : " + view.getClass().getCanonicalName());
        String sdkPackageByClass = SdksMapping.getSdkPackageByClass(view.getClass().getName());
        Logger.d(this.f9248a, "handle ad view - sdk of view: " + sdkPackageByClass + ", sdk: " + str);
        if ((a(view) || sdkPackageByClass == null || sdkPackageByClass.equals(str)) && !k(a2)) {
            list2.add(new v(a2, view.getClass().getName(), view.getWidth(), view.getHeight()));
            list.add(new WeakReference<>(view));
            Logger.d(this.f9248a, "found view: " + view + ": width: " + view.getWidth() + " height: " + view.getHeight() + " sdk: " + view.getClass().getName());
            if (view instanceof WebView) {
                return true;
            }
        }
        Logger.d(this.f9248a, "view is not a valid instance of web view, or web view already matched, view: " + view);
        return false;
    }

    protected boolean a(e eVar) {
        if (eVar != null) {
            if (SafeDK.getInstance().I()) {
                Logger.d(this.f9248a, "SafeDK Config item 'AlwaysTakeScreenshot' is true. taking screenshot");
                return true;
            }
            CreativeInfo i = eVar.i();
            if (i == null) {
                Logger.d(this.f9248a, "not taking screenshot, no creative info yet");
            } else {
                boolean a2 = CreativeInfoManager.a(eVar.u, AdNetworkConfiguration.DETECT_MULTIPLE_ADS_BY_WEB_VIEW_CHANGE, false);
                if (!i.af() || a2) {
                    Logger.d(this.f9248a, "Banner ad, taking screenshot");
                    return true;
                }
                Logger.d(this.f9248a, "not taking screenshot, multi ad, sdk: " + eVar.u);
            }
        }
        return false;
    }

    @Override
    public synchronized boolean a(o oVar) {
        boolean z;
        CreativeInfo creativeInfo;
        try {
            com.safedk.android.utils.l.b(this.f9248a, "set CI details started. matchingInfo = " + oVar.toString());
            creativeInfo = oVar.f9390a;
        } catch (Throwable th) {
            Logger.e(this.f9248a, "set CI details exception: " + th.getMessage(), th);
        }
        if (creativeInfo != null) {
            Logger.d(this.f9248a, "set CI details - CI exists in matchingInfo, sdk = " + creativeInfo.O());
            creativeInfo.g(BrandSafetyUtils.ScreenShotOrientation.PORTRAIT.equals(BrandSafetyUtils.c()));
            Logger.d(this.f9248a, "set CI details - starting to iterate over current activity banners");
            Iterator<d> it = this.F.keySet().iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                d next = it.next();
                e eVar = this.F.get(next);
                if (a(creativeInfo, eVar)) {
                    Logger.d(this.f9248a, "set CI details - matched by webView/eventID, CI: " + creativeInfo);
                    if (creativeInfo.m() == null) {
                        Logger.d(this.f9248a, "set CI details - updated creative info eventId to " + next.c + ", banner key = " + next);
                        creativeInfo.e(next.c);
                        creativeInfo.f(true);
                    }
                    if (creativeInfo.G() == null) {
                        String string = eVar.r().getString("ad_format");
                        Logger.d(this.f9248a, "set CI details - set ad format: " + string);
                        creativeInfo.o(string);
                    }
                    if (CreativeInfoManager.a(creativeInfo.O(), AdNetworkConfiguration.SDK_USES_PLACEMENT_ID_ARRAY, false)) {
                        Logger.d(this.f9248a, "set CI details - SDK_USES_PLACEMENT_ID_ARRAY config item is true");
                        if (!creativeInfo.D().equals(next.f9356b)) {
                            Logger.d(this.f9248a, "set CI details - updated creative info placementId to " + next.f9356b + ", banner key = " + next);
                            creativeInfo.g(next.f9356b);
                        }
                    }
                    if (a(next.f9355a, next.e, oVar)) {
                        z = true;
                        break;
                    } else if (creativeInfo.B()) {
                        Logger.d(this.f9248a, "set CI details - unreal match and event id set happened, setting ci event id back to null");
                        creativeInfo.f(false);
                        creativeInfo.e((String) null);
                    }
                }
            }
        }
        z = false;
        return z;
    }

    @Override
    public e a(String str, RedirectDetails redirectDetails, m mVar, boolean z, boolean z2, boolean z3) {
        String str2;
        Logger.d(this.f9248a, "handle " + (z ? "auto " : "") + redirectDetails.d.name().toLowerCase() + " for " + str + " " + this.c.name() + ", view address: " + redirectDetails.e + ", requested URL: " + redirectDetails.f + ", redirect URL: " + mVar.c);
        RedirectData redirectData = new RedirectData(str, BrandSafetyUtils.a(redirectDetails.c));
        if (z) {
            if (redirectDetails.d == RedirectDetails.RedirectType.REDIRECT) {
                String str3 = mVar.e;
                if (TextUtils.isEmpty(str3)) {
                    str2 = z2 ? "external" : "internal";
                } else {
                    redirectData.a("actualRedirectType=" + (z2 ? "external" : "internal"));
                    str2 = str3;
                }
                redirectData.a(redirectDetails.f, mVar.c, str2);
            } else if (redirectDetails.d == RedirectDetails.RedirectType.EXPAND) {
                redirectData.a(redirectDetails.f, mVar.c, true, mVar.d);
                redirectData.a("expandedWebviewAddress=" + mVar.d);
            }
        } else if (redirectDetails.d == RedirectDetails.RedirectType.EXPAND) {
            redirectData.a(redirectDetails.f, mVar.c, false, mVar.d);
            redirectData.a("expandedWebviewAddress=" + mVar.d);
        }
        if ((z && redirectData.f9242a) || redirectData.f9243b) {
            redirectData.a("orgRedirectMethod=" + redirectDetails.g);
            if (redirectDetails.h != null) {
                redirectData.a("prev " + redirectDetails.h);
            }
            if (mVar.f != null) {
                redirectData.a("prev " + mVar.f);
            }
            for (e eVar : this.F.values()) {
                if (eVar.m != null && eVar.m.contains(redirectDetails.e) && eVar.u != null && eVar.u.equals(str) && eVar.X) {
                    if (!z3) {
                        Logger.d(this.f9248a, "RedirectRawData:auto=" + z + "|" + redirectDetails + "|" + mVar);
                        eVar.e("RedirectRawData:auto=" + z + "|" + redirectDetails + "|" + mVar);
                        return eVar;
                    }
                    if (redirectData.k == null) {
                        redirectData.k = BrandSafetyUtils.a(this.c);
                    }
                    if (redirectData.f9243b) {
                        eVar.al = true;
                    }
                    l h = eVar.h();
                    if (h != null) {
                        h.a(redirectData);
                        a(eVar, false, "handleRedirect");
                        return eVar;
                    }
                }
            }
            if (z3) {
                Logger.d(this.f9248a, "handle " + (z ? "auto " : "") + redirectDetails.d.name().toLowerCase() + " for " + str + " " + this.c.name() + ", no banner info found, add to pending, webview: " + redirectDetails.e);
                J.put(redirectDetails.e, redirectData);
            }
        }
        return null;
    }

    @Override
    public synchronized List<CreativeInfo> b(String str, String str2) {
        ArrayList arrayList;
        arrayList = new ArrayList();
        for (e eVar : this.F.values()) {
            if (eVar.am != null && eVar.am.equals(str2) && eVar.u != null && eVar.u.equals(str) && eVar.X) {
                arrayList.add(eVar.i());
            }
        }
        return arrayList;
    }

    @Override
    public void b(l lVar) {
        a(lVar);
    }

    @Override
    public synchronized void b(String str) {
        Iterator<e> it = this.F.values().iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            e next = it.next();
            if (next.al && next.an != null && next.an.equals(str)) {
                break;
            }
        }
    }

    @Override
    public void b(String str, String str2, String str3) {
    }

    @Override
    public synchronized List<CreativeInfo> c(String str, String str2) {
        ArrayList arrayList;
        List<CreativeInfo> j;
        Iterator<e> it = this.F.values().iterator();
        while (true) {
            if (it.hasNext()) {
                e next = it.next();
                if (next != null && (j = next.j()) != null && !j.isEmpty() && j.get(0) != null && j.get(0).J().equals(str2)) {
                    arrayList = j;
                    break;
                }
            } else {
                List<o> list = this.G.get(str);
                if (list != null) {
                    ArrayList arrayList2 = new ArrayList();
                    for (o oVar : list) {
                        if (oVar.f9390a != null && oVar.f9390a.J().equals(str2)) {
                            arrayList2.add(oVar.f9390a);
                        }
                    }
                    arrayList = arrayList2;
                } else {
                    arrayList = new ArrayList();
                }
            }
        }
        return arrayList;
    }

    @Override
    public boolean c(String str, String str2, String str3) {
        l h;
        String h2 = CreativeInfoManager.h();
        for (e eVar : this.F.values()) {
            if (str2 != null && str2.equals(eVar.J) && (h = eVar.h()) != null && h.d != null && str3 != null && (str3.equals(h.d.d) || str3.equals(h2))) {
                Logger.d(this.f9248a, "redirect url was loaded to the ad web view: " + str2 + " url: " + str3);
                h.c().a(true);
                return true;
            }
        }
        return false;
    }

    protected boolean f(String str, String str2) {
        boolean a2 = CreativeInfoManager.a(str2, AdNetworkConfiguration.SUPPORTS_BANNER_IMPRESSION_TRACKING, false);
        String a3 = CreativeInfoManager.a(str2, AdNetworkConfiguration.AD_NETWORK_TO_IGNORE, (String) null);
        Logger.d(this.f9248a, "sdk " + str2 + ": config item SUPPORTS_BANNER_IMPRESSION_TRACKING is " + a2 + ", config item AD_NETWORK_TO_IGNORE is " + a3);
        if (!a2 || str.equals(a3)) {
            Logger.d(this.f9248a, "Banners tracking is not supported for this ad network (" + str + ")");
            return false;
        }
        return true;
    }

    @Override
    public void g() {
        Logger.d(this.f9248a, "on background started");
        CreativeInfoManager.j();
    }

    @Override
    public String getCommunicatorId() {
        return AppLovinBridge.f9171a;
    }

    @Override
    public void h() {
        Logger.d(this.f9248a, "on foreground started");
    }

    protected boolean h(String str) {
        return false;
    }

    public void i(String str) {
        for (e eVar : this.F.values()) {
            if (eVar.J != null && eVar.J.equals(str) && eVar.i() == null) {
                Logger.d(this.f9248a, "handle multiple impressions - reset webview data in: " + eVar);
                eVar.J = null;
                eVar.ae = false;
            }
        }
    }

    public void j(String str) {
        Logger.d(this.f9248a, "stop taking screenshots started, address = " + str);
        for (e eVar : this.F.values()) {
            Logger.d(this.f9248a, "stop taking screenshots - checking banner info address = " + eVar.J);
            if (eVar.J != null && eVar.J.equals(str)) {
                Logger.d(this.f9248a, "stop taking screenshots - address found. setting requestNoSamplingReceived. banner info address = " + eVar.J);
                eVar.N = true;
                for (l lVar : eVar.g()) {
                    if (lVar.c() != null && str != null && str.equals(lVar.c().ad())) {
                        a(lVar);
                        if (lVar.f9387b != null && lVar.f9387b.f9378b != null) {
                            Logger.d(this.f9248a, "stop taking screenshots - removing hash and file " + lVar.f9387b.f9378b);
                            BrandSafetyUtils.c(lVar.f9387b.f9378b);
                            lVar.f9387b.f9377a = null;
                        }
                    }
                }
            }
        }
    }

    @Override
    public synchronized void onMessageReceived(AppLovinCommunicatorMessage appLovinCommunicatorMessage) {
        String string;
        if (SafeDK.getInstance().o() && SafeDK.getInstance().p()) {
            Bundle messageData = appLovinCommunicatorMessage.getMessageData();
            if (messageData.containsKey("revenue_event") && messageData.containsKey("ad_format") && this.f9249b.contains(messageData.getString("ad_format"))) {
                Logger.d(this.f9248a, "Revenue event detected : " + messageData);
                string = "revenue_event";
            } else {
                string = messageData.getString("type");
            }
            String string2 = messageData.getString("ad_format");
            String string3 = messageData.getString(BrandSafetyEvent.k);
            String string4 = messageData.getString(BrandSafetyEvent.l);
            String string5 = messageData.getString("id", null);
            if (string5 == null) {
                Logger.d(this.f9248a, "No eventId in data bundle, cannot match");
            }
            String string6 = messageData.getString(BrandSafetyEvent.ad);
            String b2 = CreativeInfoManager.b(string6);
            long currentTimeMillis = System.currentTimeMillis();
            long b3 = com.safedk.android.utils.l.b(currentTimeMillis);
            String string7 = messageData.containsKey("creative_id") ? messageData.getString("creative_id") : null;
            if (this.f9249b.contains(string2)) {
                Logger.d(this.f9248a, "Max message received, package: " + b2 + ", ts (seconds): " + b3 + ", message received: " + appLovinCommunicatorMessage.getMessageData());
                d dVar = new d(string4, string3, string5, b2, string6);
                if ("WILL_DISPLAY".equals(string)) {
                    if (b2 != null && f(string6, b2)) {
                        Logger.d(this.f9248a, "WILL_DISPLAY event for package=" + b2 + " banner key=" + dVar + ", slot count=" + this.d);
                        CreativeInfoManager.a(b2, string3, string7, string5, string2);
                    }
                    a(string6, b2, string7, dVar, messageData, currentTimeMillis);
                } else if ("revenue_event".equals(string)) {
                    if (b2 != null && f(string6, b2)) {
                        Logger.d(this.f9248a, "REVENUE_EVENT event for package=" + b2 + " banner key=" + dVar + ", slot count=" + this.d);
                    }
                    a(string6, b2, string7, dVar, messageData);
                } else if ("DID_CLICKED".equals(string)) {
                    if (f(string6, b2)) {
                        Logger.d(this.f9248a, "DID_CLICKED event starting, currentActivityBanners keys (" + this.F.keySet() + ") = " + this.F.keySet());
                        e eVar = this.F.get(dVar);
                        Logger.d(this.f9248a, "DID_CLICKED event currentActivityBanner = " + eVar);
                        if (eVar != null) {
                            if (eVar.D()) {
                                DetectTouchUtils.b(eVar.J, com.safedk.android.utils.h.i);
                            } else if (string6 != null && string6.endsWith("_BIDDING")) {
                                DetectTouchUtils.b(eVar.J, b2);
                            }
                            String str = this.f9248a;
                            StringBuilder append = new StringBuilder().append("DID_CLICKED event for package=");
                            if (b2 != null) {
                                string6 = b2;
                            }
                            Logger.d(str, append.append(string6).append(", slot count=").append(this.d).toString());
                            d(dVar);
                        } else {
                            Logger.d(this.f9248a, "DID_CLICKED event cannot find banner key " + dVar);
                        }
                    }
                } else if ("WILL_LOAD".equals(string)) {
                    if (b2 != null && f(string6, b2)) {
                        Logger.d(this.f9248a, "WILL_LOAD event for package=" + b2 + " banner key=" + dVar + ", slot count=" + this.d);
                        com.safedk.android.analytics.brandsafety.creatives.e.b(b2, string3);
                    }
                } else if ("DID_HIDE".equals(string)) {
                    if (b2 != null && f(string6, b2)) {
                        Logger.d(this.f9248a, "DID_HIDE event for package=" + b2 + " banner key=" + dVar + ", slot count=" + this.d);
                        c(dVar);
                    }
                } else if ("DID_LOAD".equals(string)) {
                    if (b2 != null && f(string6, b2)) {
                        Logger.d(this.f9248a, "DID_LOAD event for package=" + b2 + " banner key=" + dVar + ", slot count=" + this.d);
                    }
                } else if ("DID_DISPLAY".equals(string)) {
                    if (b2 != null && f(string6, b2)) {
                        Logger.d(this.f9248a, "DID_DISPLAY event for package=" + b2 + " banner key=" + dVar + ", slot count=" + this.d);
                        a(b2, dVar, string7, messageData, currentTimeMillis);
                    }
                } else if ("DID_FAIL_DISPLAY".equals(string) && b2 != null && f(string6, b2)) {
                    Logger.d(this.f9248a, "DID_FAIL_DISPLAY event for package=" + b2 + " banner key=" + dVar + ", slot count=" + this.d);
                    a(dVar);
                }
            }
        }
    }
}