13Poker by gametower unlimited gems v0.4版本的 MD5 值为:51324fc0f195c34821074948ab266846

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


package com.flurry.android;

import android.app.Activity;
import android.app.KeyguardManager;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import android.view.ViewGroup;
import com.adfonic.android.view.task.UrlOpenerTask;
import com.flurry.android.AdRequest;
import com.flurry.org.apache.avro.io.BinaryDecoder;
import com.flurry.org.apache.avro.io.BinaryEncoder;
import com.flurry.org.apache.avro.io.DecoderFactory;
import com.flurry.org.apache.avro.io.EncoderFactory;
import com.flurry.org.apache.avro.specific.SpecificDatumReader;
import com.flurry.org.apache.avro.specific.SpecificDatumWriter;
import com.flurry.org.apache.avro.specific.SpecificRecordBase;
import com.xbtsol.jynvrt161024.IVastConstant;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
public class FlurryAds implements IFlurryAds, au {
    private static List<Integer> gR;
    private static DecoderFactory gS;
    private static el gT;
    private static FlurryAds hF;
    static String p = "FlurryAgent";
    private String aC;
    private Map<ReportedIdType, ByteBuffer> aH;
    private long aL;
    private long aM;
    private ea gU;
    private String gZ;
    private Map<String, String> hA;
    private AdUnit hB;
    private fm hC;
    private final Map<String, String> hD;
    private final Set<String> hE;
    private boolean hG;
    private dz hH;
    private volatile Location hf;
    private volatile Map<String, String> hg;
    private cw hh;
    private AdUnit hi;
    private long hj;
    aa hk;
    private String hl;
    private Handler hm;
    gv hn;
    private ICustomAdNetworkHandler hp;
    private final m hq;
    private final ba hr;
    private FlurryAdListener hs;
    private int ht;
    private final List<Activity> hu;
    private boolean gV = false;
    private boolean gW = false;
    private File gX = null;
    private File gY = null;
    private byte[] ha = null;
    private boolean hb = true;
    private boolean hc = false;
    private volatile String hd = null;
    private volatile String he = null;
    ca ho = ca.aq();
    volatile List<cw> hv = new CopyOnWriteArrayList();
    private volatile Map<String, cw> hw = new HashMap();
    private volatile List<cw> hx = new ArrayList();
    private volatile List<String> hy = new ArrayList();
    private volatile boolean hz = false;

    public static boolean b(FlurryAds flurryAds) {
        flurryAds.gV = true;
        return true;
    }

    FlurryAds() {
        HashMap hashMap = new HashMap();
        hashMap.put("open", "directOpen");
        hashMap.put(IVastConstant.EVENT_EXPAND, "doExpand");
        hashMap.put(IVastConstant.EVENT_COLLAPSE, "doCollapse");
        this.hD = Collections.unmodifiableMap(hashMap);
        HashSet hashSet = new HashSet();
        hashSet.addAll(Arrays.asList("notifyUser", "nextFrame", "closeAd", "expandAd", "collapseAd", "verifyURL"));
        this.hE = Collections.unmodifiableSet(hashSet);
        HandlerThread handlerThread = new HandlerThread("FlurryAdThread");
        handlerThread.start();
        this.hm = new Handler(handlerThread.getLooper());
        this.hk = new aa();
        gR = Arrays.asList(0, 1, 2, 3, 4, 5);
        gS = new DecoderFactory();
        gT = new el(this);
        this.gU = new ea(this);
        this.hn = new gv();
        this.aC = Build.VERSION.RELEASE;
        this.gZ = Build.DEVICE;
        this.hg = new HashMap();
        this.hq = new l();
        this.hr = new i();
        this.hu = new ArrayList();
    }

    public static FlurryAds getInstance() {
        if (hF == null) {
            hF = new FlurryAds();
        }
        return hF;
    }

    private synchronized void m(Context context) {
        if (!this.hG) {
            this.gX = context.getFileStreamPath(".flurryadlog." + Integer.toString(FlurryAgent.y().hashCode(), 16));
            this.gY = context.getFileStreamPath(".flurryfreqcap." + Integer.toString(FlurryAgent.y().hashCode(), 16));
            this.hb = b(context, "market://details?id=" + context.getPackageName(), "android.intent.action.VIEW");
            this.hl = "";
            this.ha = FlurryAgent.an.fetchHashedImei(context);
            bo();
            cy.c(p, "Attempting to load FreqCap data");
            bp();
            this.hG = true;
        }
    }

    public static boolean getAd(Context context, String str, ViewGroup viewGroup, FlurryAdSize flurryAdSize, long j) {
        if (context == null) {
            cy.d(p, "Context passed to getAd was null.");
            return false;
        } else if (str == null) {
            cy.d(p, "Ad space name passed to getAd was null.");
            return false;
        } else if (str.length() == 0) {
            cy.d(p, "Ad space name passed to getAd was empty.");
            return false;
        } else if (viewGroup == null) {
            cy.d(p, "ViewGroup passed to getAd was null.");
            return false;
        } else if (flurryAdSize == null) {
            cy.d(p, "FlurryAdSize passed to getAd was null.");
            return false;
        } else {
            getInstance().m(context);
            try {
                return hF.a(context, str, flurryAdSize, viewGroup, j);
            } catch (Throwable th) {
                cy.b(p, "", th);
                return false;
            }
        }
    }

    public static void initializeAds(Context context) {
        if (context == null) {
            cy.d(p, "Context passed to initializeAds was null.");
            return;
        }
        getInstance().m(context);
        try {
            hF.p(context);
        } catch (Throwable th) {
            cy.b(p, "", th);
        }
    }

    public static boolean isAdAvailable(Context context, String str, FlurryAdSize flurryAdSize, long j) {
        if (context == null) {
            cy.d(p, "Context passed to isAdAvailable was null.");
            return false;
        } else if (str == null) {
            cy.d(p, "Ad space name passed to isAdAvailable was null.");
            return false;
        } else if (str.length() == 0) {
            cy.d(p, "Ad space name passed to isAdAvailable was empty.");
            return false;
        } else if (flurryAdSize == null) {
            cy.d(p, "FlurryAdSize passed to isAdAvailable was null.");
            return false;
        } else {
            getInstance().m(context);
            try {
                return hF.a(context, str, flurryAdSize, j);
            } catch (Throwable th) {
                cy.b(p, "", th);
                return false;
            }
        }
    }

    public static boolean isAdReady(String str) {
        if (str == null) {
            cy.d(p, "Ad space name passed to isAdReady was null.");
            return false;
        } else if (str.length() == 0) {
            cy.d(p, "Ad space name passed to isAdReady was empty.");
            return false;
        } else {
            return getInstance().hn.Q(str);
        }
    }

    public static void fetchAd(Context context, String str, ViewGroup viewGroup, FlurryAdSize flurryAdSize) {
        if (context == null) {
            cy.d(p, "Context passed to fetchAd was null.");
        } else if (str == null) {
            cy.d(p, "Ad space name passed to fetchAd was null.");
        } else if (str.length() == 0) {
            cy.d(p, "Ad space name passed to fetchAd was empty.");
        } else if (viewGroup == null) {
            cy.d(p, "ViewGroup passed to fetchAd was null.");
        } else if (flurryAdSize == null) {
            cy.d(p, "FlurryAdSize passed to fetchAd was null.");
        } else {
            getInstance().m(context);
            try {
                FlurryAds flurryAds = hF;
                if (o(context)) {
                    if (flurryAds.c(context, str) && !n(context)) {
                        flurryAds.g(context, str);
                    } else if (!n(context)) {
                        new bi(flurryAds, context, str, flurryAdSize, viewGroup, true, false).execute(new Void[0]);
                    }
                } else if (flurryAds.hs != null) {
                    flurryAds.hs.spaceDidFailToReceiveAd(str.toString());
                }
            } catch (Throwable th) {
                cy.b(p, "", th);
            }
        }
    }

    public static void displayAd(Context context, String str, ViewGroup viewGroup) {
        if (context == null) {
            cy.d(p, "Context passed to displayAd was null.");
        } else if (str == null) {
            cy.d(p, "Ad space name passed to displayAd was null.");
        } else if (str.length() == 0) {
            cy.d(p, "Ad space name passed to displayAd was empty.");
        } else if (viewGroup == null) {
            cy.d(p, "ViewGroup  passed to displayAd was null.");
        } else {
            getInstance().m(context);
            try {
                hF.b(context, str, viewGroup);
            } catch (Throwable th) {
                cy.b(p, "", th);
            }
        }
    }

    public static void removeAd(Context context, String str, ViewGroup viewGroup) {
        if (context == null) {
            cy.d(p, "Context passed to removeAd was null.");
        } else if (str == null) {
            cy.d(p, "Ad space name passed to removeAd was null.");
        } else if (str.length() == 0) {
            cy.d(p, "Ad space name passed to removeAd was empty.");
        } else if (viewGroup == null) {
            cy.d(p, "ViewGroup passed to removeAd was null.");
        } else {
            getInstance().m(context);
            try {
                FlurryAds flurryAds = hF;
                String str2 = "_removeAd(context = " + context + ", adSpaceName = " + str + ")";
                v O = flurryAds.hn.O(str);
                if (O != null) {
                    O.stop();
                    ViewGroup h = O.h();
                    if (h != null) {
                        O.removeAllViews();
                        h.removeView(O);
                    }
                    flurryAds.C(str);
                    flurryAds.hn.d(O);
                    return;
                }
                flurryAds.C(str);
            } catch (Throwable th) {
                cy.b(p, "", th);
            }
        }
    }

    public static void setAdListener(FlurryAdListener flurryAdListener) {
        getInstance().hs = flurryAdListener;
    }

    public static void setLocation(float f, float f2) {
        getInstance().hf = Location.bS().setLat(f).setLon(f2).build();
    }

    public static void clearLocation() {
        getInstance().hf = null;
    }

    public static void setCustomAdNetworkHandler(ICustomAdNetworkHandler iCustomAdNetworkHandler) {
        if (iCustomAdNetworkHandler == null) {
            cy.d(p, "ICustomAdNetworkHandler passed to setCustomAdNetworkHandler was null.");
        } else {
            getInstance().hp = iCustomAdNetworkHandler;
        }
    }

    public static void setUserCookies(Map<String, String> map) {
        if (map == null) {
            cy.d(p, "userCookies Map passed to setUserCookies was null.");
            return;
        }
        FlurryAds flurryAds = getInstance();
        if (map == null || map.size() <= 0) {
            return;
        }
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (entry.getKey() == null || entry.getValue() == null) {
                cy.g(p, "User cookie keys and values may not be null.");
            } else {
                flurryAds.hg.put(entry.getKey(), entry.getValue());
            }
        }
    }

    public static void clearUserCookies() {
        getInstance().hg.clear();
    }

    public static void setTargetingKeywords(Map<String, String> map) {
        if (map == null) {
            cy.d(p, "targetingKeywords Map passed to setTargetingKeywords was null.");
        } else if (map != null) {
            getInstance().hA = map;
        }
    }

    public static void clearTargetingKeywords() {
        getInstance().hA = null;
    }

    public static void setAdServerUrl(String str) {
        getInstance().hd = str;
    }

    public static void setAdLogUrl(String str) {
        getInstance().he = str;
    }

    @Override
    public void onStartNewSession(Context context, long j, long j2) {
        this.hH = new dz(context);
        this.aL = j;
        this.aM = j2;
        this.hj = 0L;
        this.hc = false;
    }

    @Override
    public void onContinueSession(Context context) {
        this.ho.as();
    }

    @Override
    public void onEndSession(Context context) {
        bl();
    }

    @Override
    public void cleanUpSession(Context context) {
        for (v vVar : this.hn.w(context)) {
            vVar.stop();
            vVar.removeAllViews();
            ViewGroup h = vVar.h();
            if (h != null) {
                h.removeView(vVar);
            }
            this.hn.d(vVar);
        }
    }

    public void onOpenFullScreen(Context context, String str) {
        this.ht++;
        if (1 == this.ht && this.hs != null) {
            this.hs.onAdOpened(str);
        }
    }

    public void onCloseFullScreen(Context context, String str) {
        this.ht--;
        if (this.ht == 0 && this.hs != null) {
            this.hs.onAdClosed(str);
        }
    }

    public final boolean bg() {
        return this.ht != 0;
    }

    public final void a(Activity activity) {
        if (activity != null) {
            this.hu.add(activity);
            Intent intent = activity.getIntent();
            String a2 = a(intent);
            onOpenFullScreen(activity, a2);
            if ((intent == null ? null : (Intent) intent.getParcelableExtra(FlurryFullscreenTakeoverActivity.EXTRA_KEY_TARGETINTENT)) != null && this.hs != null) {
                this.hs.onApplicationExit(a2);
            }
        }
    }

    public final void b(Activity activity) {
        AdUnit adUnit;
        int i;
        if (activity != null) {
            onCloseFullScreen(activity, a(activity.getIntent()));
            this.hu.remove(activity);
            if (1 == this.hu.size()) {
                Activity activity2 = this.hu.get(0);
                if (activity2 instanceof FlurryFullscreenTakeoverActivity) {
                    FlurryFullscreenTakeoverActivity flurryFullscreenTakeoverActivity = (FlurryFullscreenTakeoverActivity) activity2;
                    AdUnit L = flurryFullscreenTakeoverActivity.L();
                    ft aH = flurryFullscreenTakeoverActivity.aH();
                    if (aH != null) {
                        i = aH.U;
                        adUnit = L;
                    } else {
                        i = 0;
                        adUnit = L;
                    }
                } else {
                    adUnit = null;
                    i = 0;
                }
                if (adUnit != null) {
                    if (adUnit.getCombinable().intValue() != 1 || i > 0) {
                        activity2.finish();
                    }
                }
            }
        }
    }

    public final long aJ() {
        return this.aL;
    }

    public static boolean n(Context context) {
        return ((KeyguardManager) context.getSystemService("keyguard")).inKeyguardRestrictedInputMode();
    }

    private static boolean o(Context context) {
        if (context.checkCallingOrSelfPermission("android.permission.ACCESS_NETWORK_STATE") != 0) {
            return true;
        }
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
        boolean z = activeNetworkInfo != null && (activeNetworkInfo.isConnected() || activeNetworkInfo.isRoaming());
        if (!z) {
            cy.g(p, "No connectivity found.");
            return z;
        }
        return z;
    }

    public static String y() {
        return FlurryAgent.y();
    }

    public final synchronized long bh() {
        long elapsedRealtime = SystemClock.elapsedRealtime() - this.aM;
        if (elapsedRealtime <= this.hj) {
            elapsedRealtime = this.hj + 1;
            this.hj = elapsedRealtime;
        }
        this.hj = elapsedRealtime;
        return this.hj;
    }

    @Override
    public void setReportedIds(Map<ReportedIdType, ByteBuffer> map) {
        this.aH = map;
    }

    public final void i(List<cw> list) {
        this.hx = list;
    }

    public static String getPhoneId() {
        return FlurryAgent.getPhoneId();
    }

    public final Map<ReportedIdType, ByteBuffer> bi() {
        return this.aH;
    }

    private Map<CharSequence, CharSequence> bj() {
        HashMap hashMap = new HashMap();
        for (Map.Entry<String, String> entry : this.hA.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (key == null) {
                key = "";
            }
            if (value == null) {
                value = "";
            }
            hashMap.put(key, value);
        }
        return hashMap;
    }

    public static void enableTestAds(boolean z) {
        getInstance().hz = z;
    }

    public final synchronized void a(cw cwVar) {
        if (this.hv.size() < 32767) {
            this.hv.add(cwVar);
            this.hw.put(cwVar.aA(), cwVar);
        }
    }

    public final boolean a(Context context, String str, FlurryAdSize flurryAdSize, ViewGroup viewGroup, long j) {
        if (!c(context, str)) {
            if (o(context) && !n(context)) {
                bi biVar = new bi(this, context, str, flurryAdSize, viewGroup, j == 0, j == 0);
                biVar.execute(new Void[0]);
                if (j > 0) {
                    try {
                        biVar.get(j, TimeUnit.MILLISECONDS);
                        if (c(context, str)) {
                            return a(context, str, viewGroup);
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        return false;
                    } catch (ExecutionException e2) {
                        e2.printStackTrace();
                        return false;
                    } catch (TimeoutException e3) {
                        return false;
                    }
                }
            } else if (!o(context) && this.hs != null) {
                this.hs.spaceDidFailToReceiveAd(str.toString());
            }
            return false;
        } else if (!n(context)) {
            return a(context, str, viewGroup);
        } else {
            return false;
        }
    }

    public final boolean g(Context context, String str) {
        AdUnit j = j(context, str);
        if (j == null) {
            a(ct.a(this, null), "unfilled", true, (Map<String, String>) null);
            if (this.hs != null) {
                this.hs.spaceDidFailToReceiveAd(str.toString());
            }
            return false;
        }
        this.hC = null;
        this.hn.a(str, a(context, j));
        if (this.hs != null) {
            this.hs.spaceDidReceiveAd(str.toString());
            return true;
        }
        return true;
    }

    public final boolean a(Context context, String str, ViewGroup viewGroup) {
        if (!g(context, str)) {
            return false;
        }
        b(context, str, viewGroup);
        return true;
    }

    private void b(Context context, String str, ViewGroup viewGroup) {
        if (!o(context)) {
            if (this.hs != null) {
                this.hs.spaceDidFailToReceiveAd(str.toString());
                return;
            }
            return;
        }
        fm P = this.hn.P(str);
        if (P != null) {
            AdUnit L = P.L();
            onEvent(new gt("requested", Collections.emptyMap(), context, P.L(), this.hw.get(L.getAdFrames().get(0).getAdGuid().toString()), 0), this, 0);
            if (this.hs != null) {
                if (P instanceof ex) {
                    this.hs.shouldDisplayAd(str.toString(), FlurryAdType.WEB_BANNER);
                } else {
                    this.hs.shouldDisplayAd(str.toString(), FlurryAdType.WEB_TAKEOVER);
                }
            }
            P.a(context, viewGroup);
        }
    }

    private static boolean b(Context context, String str, String str2) {
        Intent intent = new Intent(str2);
        intent.setData(Uri.parse(str));
        return fl.a(context, intent);
    }

    public final boolean a(Context context, Intent intent, String str) {
        boolean z;
        Intent intent2;
        if (context == null || intent == null || str == null || !fl.a(context, intent)) {
            return false;
        }
        if (context == null || intent == null) {
            z = false;
        } else {
            z = context.getPackageName().equals(intent.resolveActivity(context.getPackageManager()).getPackageName());
        }
        if (z) {
            intent2 = new Intent(intent);
        } else {
            intent2 = new Intent(context, FlurryFullscreenTakeoverActivity.class);
            intent2.putExtra(FlurryFullscreenTakeoverActivity.EXTRA_KEY_TARGETINTENT, intent);
        }
        if (intent2 != null) {
            intent2.putExtra(FlurryFullscreenTakeoverActivity.EXTRA_KEY_ADSPACENAME, str);
        }
        try {
            context.startActivity(intent2);
            return true;
        } catch (ActivityNotFoundException e) {
            cy.b(p, "Cannot launch Activity", e);
            return false;
        }
    }

    private static String a(Intent intent) {
        if (intent == null) {
            return null;
        }
        return intent.getStringExtra(FlurryFullscreenTakeoverActivity.EXTRA_KEY_ADSPACENAME);
    }

    public final boolean c(Context context, String str, String str2) {
        return a(context, new Intent("android.intent.action.VIEW").setData(Uri.parse(str)), str2);
    }

    public final Map<String, String> bk() {
        Map<String, String> map = this.hg;
        if (this.hH != null) {
            dz dzVar = this.hH;
            String string = dzVar.mContext == null ? "" : dzVar.mContext.getSharedPreferences("FLURRY_SHARED_PREFERENCES", 0).getString("flurry_last_user_id", "");
            if (!TextUtils.isEmpty(string)) {
                map.put("appCloudUserId", string);
            }
        }
        return map;
    }

    public final void d(Context context, String str, String str2) {
        if (str.startsWith("market://details?id=")) {
            if (this.hb) {
                if (!c(context, str, str2)) {
                    cy.d(p, "Cannot launch Google Play url " + str);
                    return;
                }
                return;
            }
            c(context, "https://market.android.com/details?id=" + str.substring("market://details?id=".length()), str2);
            return;
        }
        cy.g(p, "Unexpected Google Play url scheme: " + str);
    }

    public final void a(Context context, String str, boolean z, AdUnit adUnit) {
        this.hm.post(new cr(this, str, adUnit, context, z));
    }

    public final String h(Context context, String str) {
        int i = 0;
        String str2 = str;
        while (true) {
            if (i >= 5) {
                break;
            } else if (Uri.parse(str2).getScheme().equals("http")) {
                if (o(context) && !n(context)) {
                    HttpResponse a2 = fl.a(str2, 10000, 15000, false);
                    if (a2 == null) {
                        continue;
                    } else {
                        int statusCode = a2.getStatusLine().getStatusCode();
                        if (statusCode == 200) {
                            String str3 = "Redirect URL found for: " + str2;
                            return str2;
                        } else if (statusCode < 300 || statusCode >= 400) {
                            break;
                        } else {
                            String str4 = "NumRedirects: " + (i + 1);
                            if (a2.containsHeader("Location")) {
                                str2 = a2.getFirstHeader("Location").getValue();
                            }
                        }
                    }
                } else {
                    try {
                        Thread.sleep(100L);
                    } catch (InterruptedException e) {
                        e.getMessage();
                    }
                }
                i++;
            } else if (!b(context, str2, "android.intent.action.VIEW")) {
                if (!TextUtils.isEmpty(str2) && str2.startsWith(UrlOpenerTask.MARKET_SEARCH)) {
                    return str2;
                }
            } else {
                return str2;
            }
        }
    }

    public static boolean i(Context context, String str) {
        for (int i = 0; i < 5; i++) {
            if (o(context) && !n(context)) {
                HttpResponse a2 = fl.a(str, 10000, 15000, true);
                if (a2 != null && a2.getStatusLine().getStatusCode() == 200) {
                    String str2 = "URL hit succeeded for: " + str;
                    return true;
                }
            } else {
                try {
                    Thread.sleep(100L);
                } catch (InterruptedException e) {
                    e.getMessage();
                }
            }
        }
        return false;
    }

    private String a(cw cwVar, AdUnit adUnit, y yVar, String str) {
        Pattern compile = Pattern.compile(".*?(%\\{\\w+\\}).*?");
        Matcher matcher = compile.matcher(str);
        while (matcher.matches()) {
            str = this.gU.a(cwVar, adUnit, str, matcher.group(1));
            matcher = compile.matcher(str);
        }
        return str;
    }

    private synchronized void a(SdkLogResponse sdkLogResponse) {
        if (sdkLogResponse.getResult().toString().equals("success")) {
            this.hv.removeAll(this.hx);
        }
    }

    private synchronized void p(Context context) {
        if (!this.hc) {
            cy.e(p, "Initializing ads -- requesting ads with precaching enabled on the server");
            int i = 0;
            if (!FlurryAgent.p()) {
                i = 500;
            }
            this.hm.postDelayed(new cm(this, context), i);
            this.hc = true;
        } else {
            cy.e(p, "Initializing ads -- not making a new ad request (for ads with precaching enabled on the server) since one was made already this session");
        }
    }

    private boolean a(Context context, String str, FlurryAdSize flurryAdSize, long j) {
        if (c(context, str)) {
            return true;
        }
        bi biVar = new bi(this, context, str, flurryAdSize, null, false, false);
        biVar.execute(new Void[0]);
        try {
            biVar.get(j, TimeUnit.MILLISECONDS);
            return c(context, str);
        } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
        } catch (ExecutionException e2) {
            e2.printStackTrace();
            return false;
        } catch (TimeoutException e3) {
            return false;
        }
    }

    private AdUnit j(Context context, String str) {
        return this.hk.b(context, str);
    }

    private synchronized void bl() {
        this.hm.post(new ci(this));
    }

    public final void B(String str) {
        byte[] bm = bm();
        if (bm != null) {
            a(bm, str);
        }
    }

    private byte[] bm() {
        List<AdReportedId> bn = bn();
        synchronized (this.hv) {
            List<SdkAdLog> h = gT.h(this.hv);
            if (h.size() == 0) {
                return null;
            }
            SdkLogRequest build = SdkLogRequest.X().setApiKey(FlurryAgent.y()).setAdReportedIds(bn).setSdkAdLogs(h).setTestDevice(false).setAgentTimestamp(System.currentTimeMillis()).build();
            String str = "Got ad log request:" + build.toString();
            SpecificDatumWriter specificDatumWriter = new SpecificDatumWriter(SdkLogRequest.class);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            BinaryEncoder directBinaryEncoder = EncoderFactory.get().directBinaryEncoder(byteArrayOutputStream, null);
            try {
                specificDatumWriter.write(build, directBinaryEncoder);
                directBinaryEncoder.flush();
                return byteArrayOutputStream.toByteArray();
            } catch (IOException e) {
                String str2 = "Error generating adlog request" + e.getMessage();
                return null;
            }
        }
    }

    private List<AdReportedId> bn() {
        ArrayList arrayList = new ArrayList();
        arrayList.add(AdReportedId.bO().setId(ByteBuffer.wrap(FlurryAgent.getPhoneId().getBytes())).setType(0).build());
        byte[] bArr = this.ha;
        if (bArr != null) {
            arrayList.add(AdReportedId.bO().setId(ByteBuffer.wrap(bArr)).setType(ReportedIdType.Sha1Imei.eS).build());
        }
        for (Map.Entry<ReportedIdType, ByteBuffer> entry : this.aH.entrySet()) {
            arrayList.add(AdReportedId.bO().setId(entry.getValue()).setType(entry.getKey().eS).build());
        }
        return arrayList;
    }

    private byte[] a(String str, int i, int i2, int i3, int i4, boolean z, FlurryAdSize flurryAdSize, Context context) {
        gp gpVar;
        List<AdReportedId> bn = bn();
        ArrayList arrayList = new ArrayList();
        for (bl blVar : this.ho.ar()) {
            arrayList.add(FrequencyCapInfo.bK().setIdHash(blVar.ab()).setExpirationTime(blVar.ah()).setNewCap(blVar.ae()).setPreviousCap(blVar.af()).setPreviousCapType(blVar.ag()).setServeTime(blVar.ai()).setViews(blVar.ac()).build());
        }
        AdRequest.Builder adReportedIds = AdRequest.bt().setApiKey(FlurryAgent.y()).setAdSpaceName("").setBindings(gR).setAdReportedIds(bn);
        Location location = this.hf;
        if (location == null) {
            float f = 0.0f;
            float f2 = 0.0f;
            android.location.Location location2 = FlurryAgent.getLocation();
            if (location2 != null) {
                f = (float) location2.getLatitude();
                f2 = (float) location2.getLongitude();
            }
            location = Location.bS().setLat(f).setLon(f2).build();
        }
        AdRequest.Builder canDoSKAppStore = adReportedIds.setLocation(location).setTestDevice(this.hz).setAgentVersion(Integer.toString(FlurryAgent.getAgentVersion())).setSessionId(this.aL).setAdViewContainer(AdViewContainer.B().setScreenHeight(i4).setScreenWidth(i3).setViewHeight(i2).setViewWidth(i).setDensity(context.getResources().getDisplayMetrics().density).build()).setLocale(FlurryAgent.getLocale()).setTimezone(FlurryAgent.z()).setOsVersion(this.aC).setDevicePlatform(this.gZ).setCanDoSKAppStore(false);
        try {
            if (context.checkCallingOrSelfPermission("android.permission.ACCESS_NETWORK_STATE") == 0) {
                ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
                NetworkInfo networkInfo = connectivityManager.getNetworkInfo(1);
                if (networkInfo == null || !networkInfo.isConnected()) {
                    NetworkInfo networkInfo2 = connectivityManager.getNetworkInfo(0);
                    if (networkInfo2 != null && networkInfo2.isConnected()) {
                        gpVar = gp.iQ;
                    }
                } else {
                    gpVar = gp.iP;
                }
                AdRequest build = canDoSKAppStore.setNetworkStatus(gpVar.getValue()).setFrequencyCapInfos(arrayList).setPreferredLanguage(Locale.getDefault().getLanguage()).build();
                if (!z) {
                    build.a(Boolean.valueOf(z));
                } else {
                    build.c(str);
                }
                if (flurryAdSize != null) {
                    build.a(TestAds.bN().setAdspacePlacement(flurryAdSize.getValue()).build());
                }
                if (this.hA != null) {
                    build.c(bj());
                }
                String str2 = "Got ad request: " + build;
                SpecificDatumWriter specificDatumWriter = new SpecificDatumWriter(AdRequest.class);
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                BinaryEncoder directBinaryEncoder = EncoderFactory.get().directBinaryEncoder(byteArrayOutputStream, null);
                specificDatumWriter.write(build, directBinaryEncoder);
                directBinaryEncoder.flush();
                return byteArrayOutputStream.toByteArray();
            }
            specificDatumWriter.write(build, directBinaryEncoder);
            directBinaryEncoder.flush();
            return byteArrayOutputStream.toByteArray();
        } catch (IOException e) {
            e.getMessage();
            return new byte[0];
        }
        gpVar = gp.iO;
        AdRequest build2 = canDoSKAppStore.setNetworkStatus(gpVar.getValue()).setFrequencyCapInfos(arrayList).setPreferredLanguage(Locale.getDefault().getLanguage()).build();
        if (!z) {
        }
        if (flurryAdSize != null) {
        }
        if (this.hA != null) {
        }
        String str22 = "Got ad request: " + build2;
        SpecificDatumWriter specificDatumWriter2 = new SpecificDatumWriter(AdRequest.class);
        ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
        BinaryEncoder directBinaryEncoder2 = EncoderFactory.get().directBinaryEncoder(byteArrayOutputStream2, null);
    }

    private boolean a(byte[] bArr, String str) {
        String str2;
        String str3;
        if (str == null) {
            return false;
        }
        if (str.equals("/v6/getAds.do")) {
            StringBuilder sb = new StringBuilder();
            if (this.hd != null) {
                str3 = this.hd;
            } else {
                str3 = FlurryAgent.getUseHttps() ? "https://ads.flurry.com" : "http://ads.flurry.com";
            }
            str2 = sb.append(str3).append(str).toString();
        } else {
            str2 = (this.he != null ? this.he : FlurryAgent.getUseHttps() ? "https://adlog.flurry.com" : "http://adlog.flurry.com") + str;
        }
        byte[] b = b(bArr, str2);
        if (b != null) {
            try {
                if (str.equals("/postAdLog.do")) {
                    c(b);
                }
            } catch (IOException e) {
                cy.d(p, "IOException: " + e.toString());
            }
        }
        return true;
    }

    private byte[] b(byte[] bArr, String str) {
        ByteArrayEntity byteArrayEntity = new ByteArrayEntity(bArr);
        byteArrayEntity.setContentType("avro/binary");
        HttpPost httpPost = new HttpPost(str);
        httpPost.setEntity(byteArrayEntity);
        httpPost.setHeader("accept", "avro/binary");
        httpPost.setHeader("FM-Checksum", Integer.toString(b(bArr)));
        if (!TextUtils.isEmpty(this.hl)) {
            httpPost.setHeader("Device-UA", this.hl);
        }
        BasicHttpParams basicHttpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 10000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 15000);
        httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false);
        try {
            HttpResponse execute = ch.a(basicHttpParams).execute(httpPost);
            int statusCode = execute.getStatusLine().getStatusCode();
            if (statusCode == 200 && execute.getEntity() != null && execute.getEntity().getContentLength() != 0) {
                cy.e(p, "Request successful");
                byte[] a2 = a(execute.getEntity().getContent());
                byteArrayEntity.consumeContent();
                String num = Integer.toString(b(a2));
                if (!execute.containsHeader("FM-Checksum") || execute.getFirstHeader("FM-Checksum").getValue().equals(num)) {
                    return a2;
                }
            } else {
                String str2 = "Request to url = " + str + " failed with HTTP = " + statusCode;
            }
        } catch (IOException e) {
            cy.a(6, p, "Request to url = " + str + " failed with IOException = " + e.toString(), e);
        }
        return null;
    }

    private static byte[] a(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bArr = new byte[128];
        while (true) {
            int read = inputStream.read(bArr);
            if (read != -1) {
                byteArrayOutputStream.write(bArr, 0, read);
            } else {
                return byteArrayOutputStream.toByteArray();
            }
        }
    }

    private static <A extends SpecificRecordBase> A a(byte[] bArr, Class<A> cls) {
        try {
            return (A) new SpecificDatumReader(cls).read(null, gS.binaryDecoder(new ByteArrayInputStream(bArr), (BinaryDecoder) null));
        } catch (IOException e) {
            String str = "IOException in parseAvroBinary:" + e.getMessage();
            String str2 = "IOException in parseAvroBinary: bytes = " + bArr + " type = " + cls.getSimpleName();
            return null;
        } catch (ClassCastException e2) {
            String str3 = "ClassCastException in parseAvroBinary:" + e2.getMessage();
            String str4 = "ClassCastException in parseAvroBinary: bytes = " + bArr + " type = " + cls.getSimpleName();
            return null;
        }
    }

    private static int b(byte[] bArr) {
        CrcMessageDigest crcMessageDigest = new CrcMessageDigest();
        crcMessageDigest.update(bArr);
        return crcMessageDigest.getChecksum();
    }

    private void c(byte[] bArr) throws IOException {
        SdkLogResponse sdkLogResponse = (SdkLogResponse) a(bArr, SdkLogResponse.class);
        if (sdkLogResponse != null) {
            String str = "Got ad log response: " + sdkLogResponse;
            if (sdkLogResponse.getResult().toString().equals("success")) {
                a(sdkLogResponse);
                return;
            }
            for (CharSequence charSequence : sdkLogResponse.getErrors()) {
                cy.d(p, charSequence.toString());
            }
        }
    }

    @Override
    public synchronized void savePersistentAdLogData() {
        DataOutputStream dataOutputStream;
        try {
            if (an.a(this.gX)) {
                dataOutputStream = new DataOutputStream(new FileOutputStream(this.gX));
                try {
                    synchronized (this.hv) {
                        cg.a(this.hv, dataOutputStream);
                    }
                    fl.a(dataOutputStream);
                } catch (Throwable th) {
                    th = th;
                    cy.b(p, "Error when saving ad log data: ", th);
                    fl.a(dataOutputStream);
                }
            } else {
                fl.a(null);
            }
        } catch (Throwable th2) {
            th = th2;
            dataOutputStream = null;
        }
    }

    private synchronized void bo() {
        new cj(this).execute(new Void[0]);
    }

    @Override
    public synchronized void savePersistentFreqCapData() {
        DataOutputStream dataOutputStream;
        this.ho.as();
        try {
            if (an.a(this.gY)) {
                dataOutputStream = new DataOutputStream(new FileOutputStream(this.gY));
                try {
                    synchronized (this.ho) {
                        a(this.ho, dataOutputStream);
                    }
                    dataOutputStream.writeShort(0);
                    fl.a(dataOutputStream);
                } catch (Throwable th) {
                    th = th;
                    cy.b(p, "", th);
                    fl.a(dataOutputStream);
                }
            } else {
                fl.a(null);
            }
        } catch (Throwable th2) {
            th = th2;
            dataOutputStream = null;
        }
    }

    private synchronized void bp() {
        new ck(this).execute(new Void[0]);
    }

    public final synchronized void a(DataInputStream dataInputStream) throws IOException {
        while (dataInputStream.readShort() != 0) {
            synchronized (this.ho) {
                this.ho.a(new bl(dataInputStream));
            }
        }
        this.gW = true;
    }

    private synchronized void a(ca caVar, DataOutputStream dataOutputStream) {
        for (bl blVar : caVar.ar()) {
            try {
                dataOutputStream.writeShort(1);
                blVar.a(dataOutputStream);
            } catch (IOException e) {
                cy.c(p, "unable to convert freqCap to byte[]: " + blVar.ab());
            }
        }
    }

    private synchronized cw a(cw cwVar, String str, boolean z, Map<String, String> map) {
        String str2 = "changeAdState(" + cwVar + ", " + str + ", " + z + ", " + map + ")";
        synchronized (cwVar) {
            if (!this.hv.contains(cwVar)) {
                this.hv.add(cwVar);
                String str3 = "changeAdState added adLog = " + cwVar;
            }
            cwVar.a(a(str, z, map));
        }
        return cwVar;
    }

    private synchronized gc a(String str, boolean z, Map<String, String> map) {
        return new gc(str, z, bh(), map);
    }

    public final void b(cw cwVar) {
        this.hh = cwVar;
    }

    public final cw bq() {
        return this.hh;
    }

    public final void a(AdUnit adUnit) {
        this.hi = adUnit;
    }

    public final AdUnit br() {
        return this.hi;
    }

    private static List<y> a(AdFrame adFrame, gt gtVar) {
        ArrayList arrayList = new ArrayList();
        List<Callback> callbacks = adFrame.getCallbacks();
        String str = gtVar.jf;
        for (Callback callback : callbacks) {
            if (callback.getEvent().toString().equals(str)) {
                for (CharSequence charSequence : callback.getActions()) {
                    HashMap hashMap = new HashMap();
                    String obj = charSequence.toString();
                    int indexOf = obj.indexOf(63);
                    if (indexOf != -1) {
                        String substring = obj.substring(0, indexOf);
                        String substring2 = obj.substring(indexOf + 1);
                        if (substring2.contains("%{eventParams}")) {
                            substring2 = substring2.replace("%{eventParams}", "");
                            hashMap.putAll(gtVar.bj);
                        }
                        hashMap.putAll(fl.H(substring2));
                        obj = substring;
                    }
                    arrayList.add(new y(obj, hashMap, gtVar));
                }
            }
        }
        return arrayList;
    }

    public void onEvent(gt gtVar, au auVar, int i) {
        y yVar;
        boolean z;
        String str = "onEvent:event=" + gtVar.jf + ",params=" + gtVar.bj;
        List<y> a2 = a(gtVar.T.getAdFrames().get(gtVar.jg), gtVar);
        if (a2.isEmpty()) {
            for (Map.Entry<String, String> entry : this.hD.entrySet()) {
                if (entry.getKey().equals(gtVar.jf)) {
                    a2.add(new y(entry.getValue(), gtVar.bj, gtVar));
                }
            }
        }
        if (gtVar.jf.equals("adWillClose")) {
            Iterator<y> it = a2.iterator();
            while (true) {
                if (it.hasNext()) {
                    if (this.hE.contains(it.next().bi)) {
                        z = true;
                        break;
                    }
                } else {
                    z = false;
                    break;
                }
            }
            if (!z) {
                a2.add(0, new y("closeAd", Collections.emptyMap(), gtVar));
            }
        }
        if (gtVar.jf.equals("renderFailed") && this.hs != null) {
            this.hs.onRenderFailed(gtVar.T.getAdSpace().toString());
        }
        if (gtVar.jf.equals("clicked") && this.hs != null) {
            this.hs.onAdClicked(gtVar.T.getAdSpace().toString());
        }
        if (gtVar.jf.equals("videoCompleted") && this.hs != null) {
            this.hs.onVideoCompleted(gtVar.T.getAdSpace().toString());
        }
        y yVar2 = null;
        for (y yVar3 : a2) {
            if (yVar3.bi.equals("logEvent")) {
                yVar3.bj.put("__sendToServer", "true");
                yVar = yVar3;
            } else {
                yVar = yVar2;
            }
            if (yVar3.bi.equals("loadAdComponents")) {
                for (Map.Entry<String, String> entry2 : yVar3.bk.bj.entrySet()) {
                    yVar3.bj.put(entry2.getKey().toString(), entry2.getValue().toString());
                }
            }
            cy.f(p, yVar3.toString());
            auVar.performAction$3deb3ec3(yVar3, this, i + 1);
            yVar2 = yVar;
        }
        if (yVar2 == null) {
            HashMap hashMap = new HashMap();
            hashMap.put("__sendToServer", "false");
            y yVar4 = new y("logEvent", hashMap, gtVar);
            auVar.performAction$3deb3ec3(yVar4, this, i + 1);
            cy.f(p, yVar4.toString());
        }
    }

    @Override
    public void performAction$3deb3ec3(y yVar, FlurryAds flurryAds, int i) {
        long j;
        int i2;
        String str = "performAction:action=" + yVar.bi + ",params=" + yVar.bj + ",triggering event=" + yVar.bk.jf;
        String str2 = yVar.bi;
        Context context = yVar.bk.Q;
        cw cwVar = yVar.bk.S;
        AdUnit adUnit = yVar.bk.T;
        String obj = adUnit.getAdSpace().toString();
        if (i > 10) {
            String str3 = "Maximum depth for event/action loop exceeded when performing action:" + str2 + "," + yVar.bj + ",triggered by:" + yVar.bk.jf;
        } else if (str2.equals("directOpen")) {
            if (yVar.bj.containsKey("url")) {
                String str4 = yVar.bj.get("url");
                if (str4.startsWith(UrlOpenerTask.MARKET_SEARCH)) {
                    d(context, str4, obj);
                    return;
                } else if ("true".equals(yVar.bj.get("native"))) {
                    c(context, a(cwVar, adUnit, yVar, str4), obj);
                    return;
                } else {
                    Intent intent = new Intent(context, FlurryFullscreenTakeoverActivity.class);
                    intent.putExtra("url", str4);
                    if (fl.a(context, intent)) {
                        a(context, intent, obj);
                        return;
                    }
                    cy.g(p, "Can't start FlurryFullscreenTakeoverActivity, was it declared in the manifest? Falling back to default browser");
                    c(context, str4, obj);
                    return;
                }
            }
            cy.d(p, "failed to perform directOpen action: no url in " + yVar.bk.jf);
        } else if (str2.equals("delete")) {
            if (yVar.bj.containsKey("count")) {
                String str5 = yVar.bj.get("count");
                try {
                    i2 = Integer.parseInt(str5);
                } catch (NumberFormatException e) {
                    String str6 = "caught NumberFormatException with count parameter in deleteAds:" + str5;
                    i2 = -1;
                }
                this.hk.a(context, obj, i2);
            } else if (yVar.bj.containsKey("groupId")) {
                this.hk.a(context, obj, yVar.bj.get("groupId"));
            }
        } else if (str2.equals("processRedirect")) {
            if (yVar.bj.containsKey("url")) {
                String str7 = yVar.bj.get("url");
                if ("true".equals(yVar.bj.get("native"))) {
                    c(context, a(cwVar, adUnit, yVar, str7), obj);
                } else if (!str7.startsWith("http")) {
                    a(context, str7, false, adUnit);
                } else {
                    this.hm.post(new cq(this, context, a(cwVar, adUnit, yVar, str7), true, adUnit));
                }
            }
        } else if (str2.equals("verifyUrl")) {
            if (yVar.bj.containsKey("url")) {
                Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(yVar.bj.get("url"));
                flurryAds.onEvent(new gt(launchIntentForPackage != null && fl.a(context, launchIntentForPackage) ? "urlVerified" : "urlNotVerified", Collections.emptyMap(), context, adUnit, cwVar, yVar.bk.jg), this, i + 1);
            }
        } else if (str2.equals("launchPackage")) {
            if (yVar.bj.containsKey("package")) {
                String str8 = yVar.bj.get("package");
                Intent launchIntentForPackage2 = context.getPackageManager().getLaunchIntentForPackage(str8);
                if (launchIntentForPackage2 == null || !fl.a(context, launchIntentForPackage2)) {
                    a(context, "https://play.google.com/store/apps/details?id=" + str8, false, adUnit);
                } else {
                    a(context, launchIntentForPackage2, adUnit.getAdSpace().toString());
                }
            }
        } else if (str2.equals("sendUrlAsync")) {
            if (yVar.bj.containsKey("url")) {
                String a2 = a(cwVar, adUnit, yVar, yVar.bj.get("url"));
                String str9 = "url after is: " + a2;
                this.hm.post(new cp(this, context, a2));
            }
        } else if (str2.equals("sendAdLogs")) {
            bl();
        } else if (str2.equals("logEvent")) {
            boolean z = yVar.bj.containsKey("__sendToServer") && yVar.bj.get("__sendToServer").equals("true");
            yVar.bj.remove("__sendToServer");
            a(yVar.bk.S, yVar.bk.jf, z, yVar.bj);
        } else if (!str2.equals("nextFrame")) {
            if (str2.equals("nextAdUnit")) {
                v O = this.hn.O(obj);
                if (O != null && yVar.bj.containsKey("delay")) {
                    if ((adUnit == null || adUnit.getAdFrames().size() <= 0) ? false : adUnit.getAdFrames().get(yVar.bk.jg).getAdSpaceLayout().getFormat().toString().equals(AdCreative.kFormatBanner)) {
                        try {
                            j = Long.parseLong(yVar.bj.get("delay"));
                        } catch (NumberFormatException e2) {
                            String str10 = "caught NumberFormatException with delay parameter in nextAdUnit:" + yVar.bj.get("delay");
                            j = 30;
                        }
                        O.a(j * 1000);
                        return;
                    }
                }
                if (O != null) {
                    O.post(new cl(this, context, obj, O));
                } else if (yVar.bk.jf.equals("renderFailed")) {
                    g(context, obj);
                } else {
                    this.hB = j(context, obj);
                    a(context, this.hB);
                }
            } else if (str2.equals("checkCap")) {
                if (yVar.bj.containsKey("idHash")) {
                    String str11 = yVar.bj.get("idHash");
                    bl l = this.ho.l(str11);
                    String str12 = "capNotExhausted";
                    if (l != null && ca.c(l.ah())) {
                        cy.f(p, "Discarding expired frequency cap info for idHash=" + str11);
                        this.ho.m(str11);
                        l = null;
                    }
                    if (l != null && l.ac() >= l.ae()) {
                        cy.f(p, "Frequency cap exhausted for idHash=" + str11);
                        str12 = "capExhausted";
                    }
                    flurryAds.onEvent(new gt(str12, Collections.emptyMap(), context, adUnit, cwVar, yVar.bk.jg), this, i + 1);
                }
            } else if (str2.equals("updateViewCount")) {
                if (yVar.bj.containsKey("idHash")) {
                    bl l2 = this.ho.l(yVar.bj.get("idHash"));
                    if (l2 != null) {
                        l2.ad();
                        cy.f(p, "updateViewCount:idHash=" + l2.ab() + ",newCap=" + l2.ae() + ",prevCap=" + l2.af() + ",views=" + l2.ac());
                        if (l2.ac() > l2.ae()) {
                            String str13 = "FlurryAdAction: !! rendering a capped object: " + l2.ab();
                        }
                    }
                }
            } else {
                String str14 = "Unknown action:" + str2 + ",triggered by:" + yVar.bk.jf;
            }
        }
    }

    private fm a(Context context, AdUnit adUnit) {
        AdNetworkView adFromNetwork;
        this.hB = adUnit;
        if (adUnit == null) {
            return null;
        }
        List<AdFrame> adFrames = adUnit.getAdFrames();
        if (adFrames == null || adFrames.isEmpty()) {
            return null;
        }
        AdFrame adFrame = adFrames.get(0);
        int intValue = adFrame.getBinding().intValue();
        String obj = adFrame.getContent().toString();
        String obj2 = adFrame.getAdSpaceLayout().getFormat().toString();
        String obj3 = adFrame.getAdGuid().toString();
        cw cwVar = this.hw.get(obj3);
        cw a2 = cwVar == null ? ct.a(this, obj3) : cwVar;
        onEvent(new gt("filled", Collections.emptyMap(), context, adUnit, a2, 0), this, 1);
        AdCreative b = ct.b(adFrame.getAdSpaceLayout());
        if (this.hB != null && this.hB == adUnit) {
            this.hC = null;
            ICustomAdNetworkHandler iCustomAdNetworkHandler = this.hp;
            if (intValue == 4 && iCustomAdNetworkHandler != null && (adFromNetwork = iCustomAdNetworkHandler.getAdFromNetwork(context, b, obj)) != null) {
                adFromNetwork.R = this;
                adFromNetwork.S = a2;
                adFromNetwork.U = 0;
                adFromNetwork.T = adUnit;
                this.hC = new ex(adFromNetwork, adUnit);
            } else if (obj2.equals(AdCreative.kFormatTakeover)) {
                this.hh = a2;
                this.hi = adUnit;
                ae a3 = this.hr.a(context, this, a2, adUnit);
                if (a3 != null) {
                    this.hC = new bs(a3, adUnit);
                }
            } else {
                p b2 = this.hq.b(context, this, a2, adUnit);
                if (b2 != null) {
                    this.hC = new ex(b2, adUnit);
                } else {
                    cy.g(p, "Failed to create view for ad network: " + obj + ", network is unsupported on Android, or no ICustomAdNetworkHandler was registered or it failed to return a view.");
                    onEvent(new gt("renderFailed", Collections.emptyMap(), context, adUnit, a2, 0), this, 1);
                }
            }
        }
        return this.hC;
    }

    public final List<AdUnit> a(Context context, String str, ViewGroup viewGroup, boolean z, FlurryAdSize flurryAdSize) {
        Pair create;
        String str2;
        this.ho.as();
        if (Build.VERSION.SDK_INT >= 9) {
            int s = fl.s(context);
            int t = fl.t(context);
            switch (fl.u(context)) {
                case 2:
                    create = Pair.create(Integer.valueOf(t), Integer.valueOf(s));
                    break;
                default:
                    create = Pair.create(Integer.valueOf(s), Integer.valueOf(t));
                    break;
            }
            int intValue = ((Integer) create.first).intValue();
            int intValue2 = ((Integer) create.second).intValue();
            Pair create2 = Pair.create(Integer.valueOf(fl.s(context)), Integer.valueOf(fl.t(context)));
            int intValue3 = ((Integer) create2.first).intValue();
            int intValue4 = ((Integer) create2.second).intValue();
            if (flurryAdSize.equals(FlurryAdSize.BANNER_BOTTOM) || flurryAdSize.equals(FlurryAdSize.BANNER_TOP)) {
                if (viewGroup != null && viewGroup.getHeight() > 0) {
                    intValue4 = fl.a(context, viewGroup.getHeight());
                }
                if (viewGroup != null && viewGroup.getWidth() > 0) {
                    intValue3 = fl.a(context, viewGroup.getWidth());
                }
            }
            byte[] a2 = a(str, intValue3, intValue4, intValue, intValue2, z, flurryAdSize, context);
            if (a2 == null || a2.length < 1) {
                return Collections.emptyList();
            }
            if (this.hd != null) {
                str2 = this.hd + "/v6/getAds.do";
            } else {
                str2 = FlurryAgent.getUseHttps() ? "https://ads.flurry.com/v6/getAds.do" : "http://ads.flurry.com/v6/getAds.do";
            }
            byte[] b = b(a2, str2);
            if (b == null || b.length < 1) {
                return Collections.emptyList();
            }
            AdResponse adResponse = (AdResponse) a(b, AdResponse.class);
            if (adResponse == null) {
                return Collections.emptyList();
            }
            String str3 = "Got ad response: " + adResponse;
            if (adResponse.getErrors().size() > 0) {
                cy.d(p, "Ad server responded with the following error(s):");
                for (CharSequence charSequence : adResponse.getErrors()) {
                    cy.d(p, charSequence.toString());
                }
                return Collections.emptyList();
            } else if (!TextUtils.isEmpty(str) && (adResponse.getAdUnits() == null || adResponse.getAdUnits().size() == 0)) {
                cy.d(p, "Ad server responded but sent no ad units.");
                return Collections.emptyList();
            } else {
                return adResponse.getAdUnits();
            }
        }
        return null;
    }

    public final void b(Context context, List<AdUnit> list) {
        this.hk.a(context, list);
    }

    private boolean c(Context context, String str) {
        return this.hk.c(context, str);
    }

    private void C(String str) {
        this.hn.C(str);
    }
}