萝莉来了 v1.2.1版本的 MD5 值为:6055c21e001561c5b114d0da5b392fcb

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


package com.flurry.android;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.location.Criteria;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.ViewGroup;
import cn.iyd.pay.alipay.AlixDefine;
import com.flurry.org.apache.avro.file.DataFileConstants;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.Thread;
import java.net.URLDecoder;
import java.nio.ByteBuffer;
import java.security.DigestOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicInteger;
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 final class FlurryAgent implements LocationListener {
    private static Map<String, String> Z;
    private static final String[] a = {"9774d56d682e549c", "dead00beef"};
    private static volatile String b = null;
    private static volatile String c = "http://data.flurry.com/aap.do";
    private static volatile String d = "https://data.flurry.com/aap.do";
    private static final FlurryAgent e = new FlurryAgent();
    private static long f = 10000;
    private static boolean g = true;
    private static boolean h = false;
    private static boolean i = false;
    private static boolean j = true;
    private static Criteria k = null;
    private static boolean l = false;
    private static AtomicInteger n = new AtomicInteger(0);
    private static AtomicInteger o = new AtomicInteger(0);
    private List<byte[]> A;
    private LocationManager B;
    private String C;
    private boolean E;
    private long F;
    private long H;
    private long I;
    private long J;
    private Long P;
    private int Q;
    private android.location.Location R;
    private boolean U;
    private int V;
    private int X;
    private Map<String, List<String>> Y;
    private Map<String, List<String>> aa;
    private final Handler m;
    private File p;
    private long u;
    private String w;
    private String x;
    private String y;
    private File q = null;
    private File r = null;
    private volatile boolean s = false;
    private volatile boolean t = false;
    private Map<Context, Context> v = new WeakHashMap();
    private boolean z = true;
    private Map<Integer, ByteBuffer> D = new HashMap();
    private List<byte[]> G = new ArrayList();
    private String K = "";
    private String L = "";
    private byte M = -1;
    private String N = "";
    private byte O = -1;
    private Map<String, l> S = new HashMap();
    private List<aq> T = new ArrayList();
    private List<bb> W = new ArrayList();
    private bo ab = new bo();
    private be ac = new be();
    private ah ad = new ah();

    public static void a(FlurryAgent flurryAgent, Context context, boolean z) {
        android.location.Location location = null;
        if (z) {
            try {
                location = flurryAgent.e(context);
            } catch (Throwable th) {
                bm.b("FlurryAgent", "", th);
                return;
            }
        }
        synchronized (flurryAgent) {
            flurryAgent.R = location;
        }
        byte[] f2 = f(context);
        if (f2 != null) {
            flurryAgent.D.put(Integer.valueOf(bo.b), ByteBuffer.wrap(f2));
        }
        flurryAgent.k();
    }

    public static void b(FlurryAgent flurryAgent, Context context) {
        boolean z;
        try {
            synchronized (flurryAgent) {
                z = !flurryAgent.s && SystemClock.elapsedRealtime() - flurryAgent.u > f && flurryAgent.G.size() > 0;
            }
            if (z) {
                flurryAgent.k();
            }
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static boolean a() {
        return e.t && e.s;
    }

    public class FlurryDefaultExceptionHandler implements Thread.UncaughtExceptionHandler {
        private Thread.UncaughtExceptionHandler a = Thread.getDefaultUncaughtExceptionHandler();

        @Override
        public void uncaughtException(Thread thread, Throwable th) {
            try {
                FlurryAgent.e.a(th);
            } catch (Throwable th2) {
                bm.b("FlurryAgent", "", th2);
            }
            if (this.a != null) {
                this.a.uncaughtException(thread, th);
            }
        }
    }

    final void a(Throwable th) {
        th.printStackTrace();
        String str = "";
        StackTraceElement[] stackTrace = th.getStackTrace();
        if (stackTrace != null && stackTrace.length > 0) {
            StringBuilder sb = new StringBuilder();
            if (th.getMessage() != null) {
                sb.append(" (" + th.getMessage() + ")\n");
            }
            for (int i2 = 0; i2 < stackTrace.length; i2++) {
                if (i2 != 0) {
                    sb.append('\n');
                }
                StackTraceElement stackTraceElement = stackTrace[i2];
                sb.append(stackTraceElement.getClassName()).append(".").append(stackTraceElement.getMethodName()).append(":").append(stackTraceElement.getLineNumber());
            }
            str = sb.toString();
        } else if (th.getMessage() != null) {
            str = th.getMessage();
        }
        onError("uncaught", str, th.getClass().toString());
        this.v.clear();
        a((Context) null, true);
    }

    private FlurryAgent() {
        HandlerThread handlerThread = new HandlerThread("FlurryAgent");
        handlerThread.start();
        this.m = new Handler(handlerThread.getLooper());
    }

    private void a(Context context) {
        if (!l) {
            if (!this.ab.g()) {
                bm.a("FlurryAgent", "Initializing Flurry Ads");
                p pVar = new p();
                pVar.a = this.w;
                pVar.b = this.ac;
                pVar.c = this.ad;
                pVar.d = this.K;
                pVar.e = this.L;
                this.ab.a(context, pVar);
                this.ab.l();
                if (Z != null) {
                    this.ab.c(Z);
                }
                bm.a("FlurryAgent", "Flurry Ads initialized");
            }
            this.ab.a(context, this.H, this.I);
            l = true;
        }
    }

    public static boolean getAd(Context context, String str, ViewGroup viewGroup, FlurryAdSize flurryAdSize, long j2) {
        if (context == null) {
            bm.b("FlurryAgent", "Context passed to getAd was null.");
            return false;
        }
        if (str == null) {
            bm.b("FlurryAgent", "Ad space name passed to getAd was null.");
            return false;
        }
        if (str.length() == 0) {
            bm.b("FlurryAgent", "Ad space name passed to getAd was empty.");
            return false;
        }
        if (viewGroup == null) {
            bm.b("FlurryAgent", "ViewGroup passed to getAd was null.");
            return false;
        }
        e.a(context);
        try {
            return e.ab.a(context, str, flurryAdSize, viewGroup, j2);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
            return false;
        }
    }

    public static void initializeAds(Context context) {
        if (context == null) {
            bm.b("FlurryAgent", "Context passed to initializeAds was null.");
            return;
        }
        e.a(context);
        try {
            e.ab.b(context);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static boolean isAdAvailable(Context context, String str, FlurryAdSize flurryAdSize, long j2) {
        if (context == null) {
            bm.b("FlurryAgent", "Context passed to isAdAvailable was null.");
            return false;
        }
        if (str == null) {
            bm.b("FlurryAgent", "Ad space name passed to isAdAvailable was null.");
            return false;
        }
        if (str.length() == 0) {
            bm.b("FlurryAgent", "Ad space name passed to isAdAvailable was empty.");
            return false;
        }
        e.a(context);
        try {
            return e.ab.a(context, str, flurryAdSize, j2);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
            return false;
        }
    }

    public static void fetchAd(Context context, String str, ViewGroup viewGroup, FlurryAdSize flurryAdSize) {
        if (context == null) {
            bm.b("FlurryAgent", "Context passed to fetchAd was null.");
            return;
        }
        if (str == null) {
            bm.b("FlurryAgent", "Ad space name passed to fetchAd was null.");
            return;
        }
        if (str.length() == 0) {
            bm.b("FlurryAgent", "Ad space name passed to fetchAd was empty.");
            return;
        }
        e.a(context);
        try {
            e.ab.a(context, str, viewGroup, flurryAdSize);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void displayAd(Context context, String str, ViewGroup viewGroup) {
        if (context == null) {
            bm.b("FlurryAgent", "Context passed to displayAd was null.");
            return;
        }
        if (str == null) {
            bm.b("FlurryAgent", "Ad space name passed to displayAd was null.");
            return;
        }
        if (str.length() == 0) {
            bm.b("FlurryAgent", "Ad space name passed to displayAd was empty.");
            return;
        }
        e.a(context);
        try {
            e.ab.b(context, str, viewGroup);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void removeAd(Context context, String str, ViewGroup viewGroup) {
        if (context == null) {
            bm.b("FlurryAgent", "Context passed to removeAd was null.");
            return;
        }
        if (str == null) {
            bm.b("FlurryAgent", "Ad space name passed to removeAd was null.");
            return;
        }
        if (str.length() == 0) {
            bm.b("FlurryAgent", "Ad space name passed to removeAd was empty.");
            return;
        }
        if (viewGroup == null) {
            bm.b("FlurryAgent", "ViewGroup passed to removeAd was null.");
            return;
        }
        try {
            e.ab.b(str);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void enableTestAds(boolean z) {
        e.ab.a(z);
    }

    public static void setAdListener(FlurryAdListener flurryAdListener) {
        e.ab.a(flurryAdListener);
    }

    public static void setLocation(float f2, float f3) {
        e.ab.a(f2, f3);
    }

    public static void setCustomAdNetworkHandler(ICustomAdNetworkHandler iCustomAdNetworkHandler) {
        e.ab.a(iCustomAdNetworkHandler);
    }

    public static void setUserCookies(Map<String, String> map) {
        if (l) {
            e.ab.c(map);
        } else {
            Z = map;
        }
    }

    public static void clearUserCookies() {
        if (l) {
            e.ab.h();
        } else {
            Z = null;
        }
    }

    public static void setTargetingKeywords(Map<String, String> map) {
        e.ab.b(map);
    }

    public static void clearTargetingKeywords() {
        if (l) {
            e.ab.f();
        }
    }

    public static void setAdServerUrl(String str) {
        str.endsWith(".do");
        e.ab.c(str);
    }

    public static void setAdLogUrl(String str) {
        str.endsWith(".do");
        e.ab.d(str);
    }

    public static void sendAdLogsToServer() {
        e.ab.j();
    }

    public static void setVersionName(String str) {
        synchronized (e) {
            e.y = str;
        }
    }

    public static int getAgentVersion() {
        return 140;
    }

    public static void setReportLocation(boolean z) {
        synchronized (e) {
            e.z = z;
        }
    }

    public static void setLogEnabled(boolean z) {
        synchronized (e) {
            if (z) {
                bm.b();
            } else {
                bm.a();
            }
        }
    }

    public static void setLogLevel(int i2) {
        synchronized (e) {
            bm.a(i2);
        }
    }

    public static void setContinueSessionMillis(long j2) {
        if (j2 < 5000) {
            bm.b("FlurryAgent", "Invalid time set for session resumption: " + j2);
            return;
        }
        synchronized (e) {
            f = j2;
        }
    }

    public static void setLogEvents(boolean z) {
        synchronized (e) {
            g = z;
        }
    }

    public static void setUseHttps(boolean z) {
        h = z;
    }

    public static void setCaptureUncaughtExceptions(boolean z) {
        synchronized (e) {
            if (e.s) {
                bm.b("FlurryAgent", "Cannot setCaptureUncaughtExceptions after onStartSession");
            } else {
                j = z;
            }
        }
    }

    public static void onStartSession(Context context, String str) {
        if (context == null) {
            throw new NullPointerException("Null context");
        }
        if (str == null || str.length() == 0) {
            throw new IllegalArgumentException("Api key not specified");
        }
        try {
            e.a(context, str);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void onEndSession(Context context) {
        if (context == null) {
            throw new NullPointerException("Null context");
        }
        try {
            e.a(context, false);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void logEvent(String str) {
        try {
            e.a(str, (Map<String, String>) null, false);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "Failed to log event: " + str, th);
        }
    }

    public static void logEvent(String str, Map<String, String> map) {
        try {
            e.a(str, map, false);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "Failed to log event: " + str, th);
        }
    }

    public static void logEvent(String str, boolean z) {
        try {
            e.a(str, (Map<String, String>) null, z);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "Failed to log event: " + str, th);
        }
    }

    public static void logEvent(String str, Map<String, String> map, boolean z) {
        try {
            e.a(str, map, z);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "Failed to log event: " + str, th);
        }
    }

    public static void endTimedEvent(String str) {
        try {
            e.a(str);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "Failed to signify the end of event: " + str, th);
        }
    }

    public static void onError(String str, String str2, String str3) {
        try {
            e.a(str, str2, str3);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void onEvent(String str) {
        try {
            e.a(str, (Map<String, String>) null, false);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void onEvent(String str, Map<String, String> map) {
        try {
            e.a(str, map, false);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static void onPageView() {
        try {
            e.h();
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public static boolean getUseHttps() {
        return h;
    }

    public static void setReportUrl(String str) {
        str.endsWith(".do");
        b = str;
    }

    public static void setLocationCriteria(Criteria criteria) {
        synchronized (e) {
            k = criteria;
        }
    }

    public static void setAge(int i2) {
        if (i2 > 0 && i2 < 110) {
            e.P = Long.valueOf(new Date(new Date(System.currentTimeMillis() - (i2 * 31449600000L)).getYear(), 1, 1).getTime());
        }
    }

    public static void setGender(byte b2) {
        switch (b2) {
            case 0:
            case 1:
                e.O = b2;
                return;
            default:
                e.O = (byte) -1;
                return;
        }
    }

    public static void setUserId(String str) {
        synchronized (e) {
            e.N = ac.a(str);
        }
    }

    public static boolean getForbidPlaintextFallback() {
        return false;
    }

    public static boolean isCaptureUncaughtExceptions() {
        return j;
    }

    public static bo b() {
        return e.ab;
    }

    private synchronized void a(Context context, String str) {
        Bundle extras;
        String str2;
        if (this.w != null && !this.w.equals(str)) {
            bm.b("FlurryAgent", "onStartSession called with different api keys: " + this.w + " and " + str);
        }
        if (this.v.put(context, context) != null) {
            bm.d("FlurryAgent", "onStartSession called with duplicate context, use a specific Activity or Service as context instead of using a global context");
        }
        if (!this.s) {
            bm.a("FlurryAgent", "Initializing Flurry session");
            n.set(0);
            o.set(0);
            this.w = str;
            this.q = context.getFileStreamPath(".flurryagent." + Integer.toString(this.w.hashCode(), 16));
            this.p = context.getFileStreamPath(".flurryb.");
            this.r = context.getFileStreamPath(".flurryinstallreceiver.");
            if (j) {
                Thread.setDefaultUncaughtExceptionHandler(new FlurryDefaultExceptionHandler());
            }
            Context applicationContext = context.getApplicationContext();
            if (this.y == null) {
                this.y = d(applicationContext);
            }
            String packageName = applicationContext.getPackageName();
            if (this.x != null && !this.x.equals(packageName)) {
                bm.b("FlurryAgent", "onStartSession called from different application packages: " + this.x + " and " + packageName);
            }
            this.x = packageName;
            long elapsedRealtime = SystemClock.elapsedRealtime();
            if (elapsedRealtime - this.u > f) {
                bm.a("FlurryAgent", "New session");
                this.H = System.currentTimeMillis();
                this.I = elapsedRealtime;
                this.J = -1L;
                this.N = "";
                this.Q = 0;
                this.R = null;
                this.L = TimeZone.getDefault().getID();
                this.K = Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry();
                this.S = new HashMap();
                this.T = new ArrayList();
                this.U = true;
                this.W = new ArrayList();
                this.V = 0;
                this.X = 0;
                if (l) {
                    this.ab.a(context, this.H, this.I);
                }
                a(new e(this, applicationContext, this.z));
                if ((context instanceof Activity) && (extras = ((Activity) context).getIntent().getExtras()) != null) {
                    bm.a("FlurryAgent", "Launch Options Bundle is present " + extras.toString());
                    this.aa = new HashMap();
                    for (String str3 : extras.keySet()) {
                        if (this.aa.get(str3) == null) {
                            this.aa.put(str3, new ArrayList());
                        }
                        Object obj = extras.get(str3);
                        if (obj.getClass().isInstance("")) {
                            str2 = extras.getString(str3);
                        } else if (obj.getClass().isInstance(0)) {
                            extras.getInt(str3);
                            str2 = Integer.toString(0);
                        } else if (obj.getClass().isInstance(0L)) {
                            str2 = Long.toString(extras.getLong(str3));
                        } else if (!obj.getClass().isInstance(false)) {
                            str2 = "";
                        } else {
                            str2 = Boolean.toString(extras.getBoolean(str3));
                        }
                        this.aa.get(str3).add(str2);
                        bm.a("FlurryAgent", "Launch options Key: " + str3 + ". Its value: " + str2);
                    }
                }
            } else {
                bm.a("FlurryAgent", "Continuing previous session");
                if (!this.G.isEmpty()) {
                    this.G.remove(this.G.size() - 1);
                }
                if (l) {
                    this.ab.a(context);
                }
            }
            this.s = true;
        }
    }

    private synchronized void a(Context context, boolean z) {
        if (context != null) {
            if (this.v.remove(context) == null) {
                bm.d("FlurryAgent", "onEndSession called without context from corresponding onStartSession");
            }
        }
        if (this.s && this.v.isEmpty()) {
            bm.a("FlurryAgent", "Ending session");
            n();
            Context applicationContext = context == null ? null : context.getApplicationContext();
            if (context != null) {
                String packageName = applicationContext.getPackageName();
                if (!this.x.equals(packageName)) {
                    bm.b("FlurryAgent", "onEndSession called from different application package, expected: " + this.x + " actual: " + packageName);
                }
            }
            long elapsedRealtime = SystemClock.elapsedRealtime();
            this.u = elapsedRealtime;
            this.J = elapsedRealtime - this.I;
            if (o() == null) {
                bm.b("FlurryAgent", "Not creating report because of bad Android ID or generated ID is null");
            }
            a(new a(this, z, applicationContext));
            if (l) {
                this.ab.a();
            }
            this.s = false;
        }
    }

    public synchronized void g() {
        DataOutputStream dataOutputStream;
        DataOutputStream dataOutputStream2 = null;
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            dataOutputStream = new DataOutputStream(byteArrayOutputStream);
            try {
                dataOutputStream.writeShort(1);
                dataOutputStream.writeUTF(this.y);
                dataOutputStream.writeLong(this.H);
                dataOutputStream.writeLong(this.J);
                dataOutputStream.writeLong(0L);
                dataOutputStream.writeUTF(this.K);
                dataOutputStream.writeUTF(this.L);
                dataOutputStream.writeByte(this.M);
                dataOutputStream.writeUTF(this.N == null ? "" : this.N);
                if (this.R == null) {
                    dataOutputStream.writeBoolean(false);
                } else {
                    dataOutputStream.writeBoolean(true);
                    dataOutputStream.writeDouble(a(this.R.getLatitude()));
                    dataOutputStream.writeDouble(a(this.R.getLongitude()));
                    dataOutputStream.writeFloat(this.R.getAccuracy());
                }
                dataOutputStream.writeInt(this.X);
                dataOutputStream.writeByte(-1);
                dataOutputStream.writeByte(-1);
                dataOutputStream.writeByte(this.O);
                if (this.P == null) {
                    dataOutputStream.writeBoolean(false);
                } else {
                    dataOutputStream.writeBoolean(true);
                    dataOutputStream.writeLong(this.P.longValue());
                }
                dataOutputStream.writeShort(this.S.size());
                for (Map.Entry<String, l> entry : this.S.entrySet()) {
                    dataOutputStream.writeUTF(entry.getKey());
                    dataOutputStream.writeInt(entry.getValue().a);
                }
                dataOutputStream.writeShort(this.T.size());
                Iterator<aq> it = this.T.iterator();
                while (it.hasNext()) {
                    dataOutputStream.write(it.next().a());
                }
                dataOutputStream.writeBoolean(this.U);
                int i2 = 0;
                int i3 = 0;
                for (int i4 = 0; i4 < this.W.size() && (i3 = i3 + this.W.get(i4).a().length) <= 16000; i4++) {
                    i2++;
                }
                dataOutputStream.writeInt(this.Q);
                dataOutputStream.writeShort(i2);
                for (int i5 = 0; i5 < i2; i5++) {
                    dataOutputStream.write(this.W.get(i5).a());
                }
                dataOutputStream.writeShort(0);
                dataOutputStream.writeShort(0);
                this.G.add(byteArrayOutputStream.toByteArray());
                ac.a(dataOutputStream);
            } catch (IOException e2) {
                e = e2;
                dataOutputStream2 = dataOutputStream;
                try {
                    bm.b("FlurryAgent", "", e);
                    ac.a(dataOutputStream2);
                } catch (Throwable th) {
                    th = th;
                    dataOutputStream = dataOutputStream2;
                    ac.a(dataOutputStream);
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
                ac.a(dataOutputStream);
                throw th;
            }
        } catch (IOException e3) {
            e = e3;
        } catch (Throwable th3) {
            th = th3;
            dataOutputStream = null;
        }
    }

    private static double a(double d2) {
        return Math.round(d2 * 1000.0d) / 1000.0d;
    }

    private void a(an anVar) {
        this.m.post(anVar);
    }

    private synchronized void h() {
        this.X++;
    }

    private synchronized void a(String str, Map<String, String> map, boolean z) {
        if (this.T == null) {
            bm.b("FlurryAgent", "onEvent called before onStartSession.  Event: " + str);
        } else {
            long elapsedRealtime = SystemClock.elapsedRealtime() - this.I;
            String a2 = ac.a(str);
            if (a2.length() != 0) {
                l lVar = this.S.get(a2);
                if (lVar == null) {
                    if (this.S.size() < 100) {
                        l lVar2 = new l();
                        lVar2.a = 1;
                        this.S.put(a2, lVar2);
                        bm.a("FlurryAgent", "Event count incremented: " + a2);
                    } else if (bm.a("FlurryAgent")) {
                        bm.a("FlurryAgent", "Too many different events. Event not counted: " + a2);
                    }
                } else {
                    lVar.a++;
                    bm.a("FlurryAgent", "Event count incremented: " + a2);
                }
                if (g && this.T.size() < 200 && this.V < 16000) {
                    Map<String, String> emptyMap = map == null ? Collections.emptyMap() : map;
                    if (emptyMap.size() > 10) {
                        if (bm.a("FlurryAgent")) {
                            bm.a("FlurryAgent", "MaxEventParams exceeded: " + emptyMap.size());
                        }
                    } else {
                        aq aqVar = new aq(n.incrementAndGet(), a2, emptyMap, elapsedRealtime, z);
                        if (aqVar.a().length + this.V <= 16000) {
                            this.T.add(aqVar);
                            this.V = aqVar.a().length + this.V;
                            bm.a("FlurryAgent", "Logged event: " + a2);
                        } else {
                            this.V = DataFileConstants.DEFAULT_SYNC_INTERVAL;
                            this.U = false;
                            bm.a("FlurryAgent", "Event Log size exceeded. No more event details logged.");
                        }
                    }
                } else {
                    this.U = false;
                }
            }
        }
    }

    private synchronized void a(String str) {
        Iterator<aq> it = this.T.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            aq next = it.next();
            if (next.a(str)) {
                break;
            }
        }
    }

    private synchronized void a(String str, String str2, String str3) {
        if (this.W == null) {
            bm.b("FlurryAgent", "onError called before onStartSession.  Error: " + str);
        } else {
            boolean z = str != null && "uncaught".equals(str);
            this.Q++;
            if (this.W.size() < 50) {
                bb bbVar = new bb(o.incrementAndGet(), Long.valueOf(System.currentTimeMillis()).longValue(), str, str2, str3);
                this.W.add(bbVar);
                bm.a("FlurryAgent", "Error logged: " + bbVar.b());
            } else if (z) {
                int i2 = 0;
                while (true) {
                    if (i2 >= this.W.size()) {
                        break;
                    }
                    bb bbVar2 = this.W.get(i2);
                    if (bbVar2.b() == null || "uncaught".equals(bbVar2.b())) {
                        i2++;
                    } else {
                        this.W.set(i2, new bb(o.incrementAndGet(), Long.valueOf(System.currentTimeMillis()).longValue(), str, str2, str3));
                        break;
                    }
                }
            } else {
                bm.a("FlurryAgent", "Max errors logged. No more errors logged.");
            }
        }
    }

    private synchronized byte[] i() {
        DataOutputStream dataOutputStream;
        DataOutputStream dataOutputStream2;
        byte[] bArr;
        CrcMessageDigest crcMessageDigest;
        ByteArrayOutputStream byteArrayOutputStream;
        DigestOutputStream digestOutputStream;
        try {
            crcMessageDigest = new CrcMessageDigest();
            byteArrayOutputStream = new ByteArrayOutputStream();
            digestOutputStream = new DigestOutputStream(byteArrayOutputStream, crcMessageDigest);
            dataOutputStream2 = new DataOutputStream(digestOutputStream);
        } catch (Throwable th) {
            th = th;
            dataOutputStream = null;
        }
        try {
            dataOutputStream2.writeShort(25);
            dataOutputStream2.writeShort(0);
            dataOutputStream2.writeLong(0L);
            dataOutputStream2.writeShort(0);
            dataOutputStream2.writeShort(3);
            dataOutputStream2.writeShort(140);
            dataOutputStream2.writeLong(System.currentTimeMillis());
            dataOutputStream2.writeUTF(this.w);
            dataOutputStream2.writeUTF(this.y);
            dataOutputStream2.writeShort(this.D.size() + 1);
            dataOutputStream2.writeShort(0);
            dataOutputStream2.writeUTF(o());
            if (!this.D.isEmpty()) {
                for (Map.Entry<Integer, ByteBuffer> entry : this.D.entrySet()) {
                    dataOutputStream2.writeShort(entry.getKey().intValue());
                    byte[] array = entry.getValue().array();
                    dataOutputStream2.writeShort(array.length);
                    dataOutputStream2.write(array);
                }
            }
            dataOutputStream2.writeByte(0);
            dataOutputStream2.writeLong(this.F);
            dataOutputStream2.writeLong(this.H);
            dataOutputStream2.writeShort(6);
            dataOutputStream2.writeUTF("device.model");
            dataOutputStream2.writeUTF(Build.MODEL);
            dataOutputStream2.writeUTF("build.brand");
            dataOutputStream2.writeUTF(Build.BRAND);
            dataOutputStream2.writeUTF("build.id");
            dataOutputStream2.writeUTF(Build.ID);
            dataOutputStream2.writeUTF("version.release");
            dataOutputStream2.writeUTF(Build.VERSION.RELEASE);
            dataOutputStream2.writeUTF("build.device");
            dataOutputStream2.writeUTF(Build.DEVICE);
            dataOutputStream2.writeUTF("build.product");
            dataOutputStream2.writeUTF(Build.PRODUCT);
            int size = this.Y != null ? this.Y.keySet().size() : 0;
            String str = "refMapSize is:  " + size;
            if (size == 0) {
                String str2 = "Referrer file Name if it exists:  " + this.r;
                l();
            }
            dataOutputStream2.writeShort(size);
            if (this.Y != null) {
                for (Map.Entry<String, List<String>> entry2 : this.Y.entrySet()) {
                    String str3 = "Referrer Entry:  " + entry2.getKey() + "=" + entry2.getValue();
                    dataOutputStream2.writeUTF(entry2.getKey());
                    String str4 = "referrer key is :" + entry2.getKey();
                    dataOutputStream2.writeShort(entry2.getValue().size());
                    for (String str5 : entry2.getValue()) {
                        dataOutputStream2.writeUTF(str5);
                        String str6 = "referrer value is :" + str5;
                    }
                }
            }
            dataOutputStream2.writeBoolean(false);
            dataOutputStream2.writeBoolean(false);
            int size2 = this.aa != null ? this.aa.keySet().size() : 0;
            String str7 = "optionsMapSize is:  " + size2;
            dataOutputStream2.writeShort(size2);
            if (this.aa != null) {
                for (Map.Entry<String, List<String>> entry3 : this.aa.entrySet()) {
                    String str8 = "Launch Options Key:  " + entry3.getKey();
                    dataOutputStream2.writeUTF(entry3.getKey());
                    dataOutputStream2.writeShort(entry3.getValue().size());
                    for (String str9 : entry3.getValue()) {
                        dataOutputStream2.writeUTF(str9);
                        String str10 = "Launch Options value is :" + str9;
                    }
                }
            }
            int size3 = this.G.size();
            dataOutputStream2.writeShort(size3);
            for (int i2 = 0; i2 < size3; i2++) {
                dataOutputStream2.write(this.G.get(i2));
            }
            this.A = new ArrayList(this.G);
            digestOutputStream.on(false);
            dataOutputStream2.write(crcMessageDigest.getDigest());
            dataOutputStream2.close();
            bArr = byteArrayOutputStream.toByteArray();
            ac.a(dataOutputStream2);
        } catch (Throwable th2) {
            th = th2;
            dataOutputStream = dataOutputStream2;
            try {
                bm.b("FlurryAgent", "Error when generating report", th);
                ac.a(dataOutputStream);
                bArr = null;
                return bArr;
            } catch (Throwable th3) {
                th = th3;
                dataOutputStream2 = dataOutputStream;
                ac.a(dataOutputStream2);
                throw th;
            }
        }
        return bArr;
    }

    private static String j() {
        if (b != null) {
            return b;
        }
        if (i) {
            return c;
        }
        if (h) {
            return d;
        }
        return c;
    }

    private boolean a(byte[] bArr) {
        boolean z;
        String j2 = j();
        if (j2 == null) {
            return false;
        }
        try {
            z = a(bArr, j2);
        } catch (Exception e2) {
            bm.a("FlurryAgent", "Sending report exception: " + e2.getMessage());
            z = false;
        }
        if (!z && b == null && h && !i) {
            synchronized (e) {
                i = true;
                String j3 = j();
                if (j3 == null) {
                    z = false;
                } else {
                    try {
                        z = a(bArr, j3);
                    } catch (Exception e3) {
                    }
                }
            }
            return z;
        }
        return z;
    }

    private boolean a(byte[] bArr, String str) {
        boolean z = true;
        if (!"local".equals(str)) {
            bm.a("FlurryAgent", "Sending report to: " + str);
            ByteArrayEntity byteArrayEntity = new ByteArrayEntity(bArr);
            byteArrayEntity.setContentType("application/octet-stream");
            HttpPost httpPost = new HttpPost(str);
            httpPost.setEntity(byteArrayEntity);
            BasicHttpParams basicHttpParams = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(basicHttpParams, 10000);
            HttpConnectionParams.setSoTimeout(basicHttpParams, 15000);
            httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false);
            int statusCode = this.ac.a(basicHttpParams).execute(httpPost).getStatusLine().getStatusCode();
            synchronized (this) {
                if (statusCode == 200) {
                    bm.a("FlurryAgent", "Report successful");
                    this.E = true;
                    this.G.removeAll(this.A);
                } else {
                    bm.a("FlurryAgent", "Report failed. HTTP response: " + statusCode);
                    z = false;
                }
                this.A = null;
            }
        }
        return z;
    }

    private void k() {
        try {
            bm.a("FlurryAgent", "generating report");
            byte[] i2 = i();
            if (i2 != null) {
                if (a(i2)) {
                    bm.a("FlurryAgent", "Done sending " + (this.s ? "initial " : "") + "agent report");
                    m();
                }
            } else {
                bm.a("FlurryAgent", "Error generating report");
            }
        } catch (IOException e2) {
            bm.a("FlurryAgent", "", e2);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    public synchronized void b(Context context) {
        String str;
        DataInputStream dataInputStream;
        String c2 = c(context);
        if (this.q.exists()) {
            ?? r1 = "loading persistent data: " + this.q.getAbsolutePath();
            bm.c("FlurryAgent", r1);
            try {
                try {
                    dataInputStream = new DataInputStream(new FileInputStream(this.q));
                    try {
                        if (dataInputStream.readUnsignedShort() == 46586) {
                            a(dataInputStream);
                        } else {
                            bm.a("FlurryAgent", "Unexpected file type");
                        }
                        ac.a(dataInputStream);
                    } catch (Throwable th) {
                        th = th;
                        bm.b("FlurryAgent", "Error when loading persistent file", th);
                        ac.a(dataInputStream);
                        if (!this.t) {
                        }
                        if (!this.t) {
                        }
                        if (c2 != null) {
                        }
                        d(str);
                        this.ab.a(this.C);
                        this.ab.a(this.D);
                        if (!str.startsWith("AND")) {
                            b(context, str);
                        }
                        l();
                    }
                } catch (Throwable th2) {
                    th = th2;
                    ac.a((Closeable) r1);
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                r1 = 0;
                ac.a((Closeable) r1);
                throw th;
            }
            try {
                if (!this.t) {
                    if (this.q.delete()) {
                        bm.a("FlurryAgent", "Deleted persistence file");
                    } else {
                        bm.b("FlurryAgent", "Cannot delete persistence file");
                    }
                }
            } catch (Throwable th4) {
                bm.b("FlurryAgent", "", th4);
            }
        } else {
            bm.c("FlurryAgent", "Agent cache file doesn't exist.");
        }
        if (!this.t) {
            this.E = false;
            this.F = this.H;
            this.t = true;
        }
        if (c2 != null) {
            str = "ID" + Long.toString(Double.doubleToLongBits(Math.random()) + (37 * (System.nanoTime() + (this.w.hashCode() * 37))), 16);
            bm.c("FlurryAgent", "Generated id");
        } else {
            str = c2;
        }
        d(str);
        this.ab.a(this.C);
        this.ab.a(this.D);
        if (!str.startsWith("AND") && !this.p.exists()) {
            b(context, str);
        }
        l();
    }

    private void l() {
        if (this.r.exists()) {
            bm.c("FlurryAgent", "Loading referrer info from file:  " + this.r.getAbsolutePath());
            String a2 = a(this.r);
            if (a2 != null) {
                this.Y = b(a2);
            }
        }
    }

    private static String a(File file) {
        FileInputStream fileInputStream;
        Throwable th;
        StringBuffer stringBuffer;
        try {
            fileInputStream = new FileInputStream(file);
            try {
                try {
                    stringBuffer = new StringBuffer();
                    try {
                        byte[] bArr = new byte[1024];
                        while (true) {
                            int read = fileInputStream.read(bArr);
                            if (read <= 0) {
                                break;
                            }
                            stringBuffer.append(new String(bArr, 0, read));
                        }
                        ac.a(fileInputStream);
                    } catch (Throwable th2) {
                        th = th2;
                        bm.b("FlurryAgent", "Error when loading persistent file", th);
                        ac.a(fileInputStream);
                        if (stringBuffer == null) {
                        }
                    }
                } catch (Throwable th3) {
                    th = th3;
                    stringBuffer = null;
                }
            } catch (Throwable th4) {
                th = th4;
                ac.a(fileInputStream);
                throw th;
            }
        } catch (Throwable th5) {
            fileInputStream = null;
            th = th5;
            ac.a(fileInputStream);
            throw th;
        }
        if (stringBuffer == null) {
            return stringBuffer.toString();
        }
        return null;
    }

    private static Map<String, List<String>> b(String str) {
        HashMap hashMap = new HashMap();
        String[] split = str.split(AlixDefine.split);
        int length = split.length;
        for (int i2 = 0; i2 < length; i2++) {
            String[] split2 = split[i2].split("=");
            if (split2.length != 2) {
                bm.a("FlurryAgent", "Invalid referrer Element: " + split[i2] + " in referrer tag " + str);
            } else {
                String decode = URLDecoder.decode(split2[0]);
                String decode2 = URLDecoder.decode(split2[1]);
                if (hashMap.get(decode) == null) {
                    hashMap.put(decode, new ArrayList());
                }
                ((List) hashMap.get(decode)).add(decode2);
            }
        }
        StringBuilder sb = new StringBuilder();
        if (hashMap.get("utm_source") == null) {
            sb.append("Campaign Source is missing.\n");
        }
        if (hashMap.get("utm_medium") == null) {
            sb.append("Campaign Medium is missing.\n");
        }
        if (hashMap.get("utm_campaign") == null) {
            sb.append("Campaign Name is missing.\n");
        }
        if (sb.length() > 0) {
            Log.w("Detected missing referrer keys", sb.toString());
        }
        return hashMap;
    }

    private synchronized void a(DataInputStream dataInputStream) {
        int i2 = 0;
        synchronized (this) {
            int readUnsignedShort = dataInputStream.readUnsignedShort();
            if (readUnsignedShort > 2) {
                bm.b("FlurryAgent", "Unknown agent file version: " + readUnsignedShort);
                throw new IOException("Unknown agent file version: " + readUnsignedShort);
            }
            if (readUnsignedShort >= 2) {
                String readUTF = dataInputStream.readUTF();
                bm.a("FlurryAgent", "Loading API key: " + c(this.w));
                if (readUTF.equals(this.w)) {
                    String readUTF2 = dataInputStream.readUTF();
                    if (o() == null) {
                        bm.a("FlurryAgent", "Loading phoneId: " + readUTF2);
                    }
                    d(readUTF2);
                    this.E = dataInputStream.readBoolean();
                    this.F = dataInputStream.readLong();
                    bm.a("FlurryAgent", "Loading session reports");
                    while (true) {
                        int readUnsignedShort2 = dataInputStream.readUnsignedShort();
                        if (readUnsignedShort2 == 0) {
                            break;
                        }
                        byte[] bArr = new byte[readUnsignedShort2];
                        dataInputStream.readFully(bArr);
                        this.G.add(0, bArr);
                        i2++;
                        bm.a("FlurryAgent", "Session report added: " + i2);
                    }
                    bm.a("FlurryAgent", "Persistent file loaded");
                    this.t = true;
                } else {
                    bm.a("FlurryAgent", "Api keys do not match, old: " + c(readUTF) + ", new: " + c(this.w));
                }
            } else {
                bm.d("FlurryAgent", "Deleting old file version: " + readUnsignedShort);
            }
        }
    }

    private static String c(String str) {
        if (str != null && str.length() > 4) {
            StringBuilder sb = new StringBuilder();
            for (int i2 = 0; i2 < str.length() - 4; i2++) {
                sb.append('*');
            }
            sb.append(str.substring(str.length() - 4));
            return sb.toString();
        }
        return str;
    }

    public synchronized void m() {
        DataOutputStream dataOutputStream;
        try {
            if (ah.a(this.q)) {
                dataOutputStream = new DataOutputStream(new FileOutputStream(this.q));
                try {
                    try {
                        dataOutputStream.writeShort(46586);
                        dataOutputStream.writeShort(2);
                        dataOutputStream.writeUTF(this.w);
                        dataOutputStream.writeUTF(o());
                        dataOutputStream.writeBoolean(this.E);
                        dataOutputStream.writeLong(this.F);
                        int size = this.G.size() - 1;
                        while (true) {
                            if (size < 0) {
                                break;
                            }
                            byte[] bArr = this.G.get(size);
                            int length = bArr.length;
                            if (length + 2 + dataOutputStream.size() > 50000) {
                                bm.a("FlurryAgent", "discarded sessions: " + size);
                                break;
                            } else {
                                dataOutputStream.writeShort(length);
                                dataOutputStream.write(bArr);
                                size--;
                            }
                        }
                        dataOutputStream.writeShort(0);
                        ac.a(dataOutputStream);
                    } catch (Throwable th) {
                        th = th;
                        bm.b("FlurryAgent", "", th);
                        ac.a(dataOutputStream);
                    }
                } catch (Throwable th2) {
                    th = th2;
                    ac.a(dataOutputStream);
                    throw th;
                }
            } else {
                ac.a((Closeable) null);
            }
        } catch (Throwable th3) {
            th = th3;
            dataOutputStream = null;
        }
    }

    private synchronized void b(Context context, String str) {
        DataOutputStream dataOutputStream;
        this.p = context.getFileStreamPath(".flurryb.");
        if (ah.a(this.p)) {
            try {
                try {
                    dataOutputStream = new DataOutputStream(new FileOutputStream(this.p));
                    try {
                        dataOutputStream.writeInt(1);
                        dataOutputStream.writeUTF(str);
                        ac.a(dataOutputStream);
                    } catch (Throwable th) {
                        th = th;
                        bm.b("FlurryAgent", "Error when saving b file", th);
                        ac.a(dataOutputStream);
                    }
                } catch (Throwable th2) {
                    th = th2;
                    ac.a(dataOutputStream);
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                dataOutputStream = null;
                ac.a(dataOutputStream);
                throw th;
            }
        }
    }

    private String c(Context context) {
        DataInputStream dataInputStream;
        boolean z = false;
        String o2 = o();
        if (o2 == null) {
            String string = Settings.System.getString(context.getContentResolver(), "android_id");
            if (string != null && string.length() > 0 && !string.equals(DataFileConstants.NULL_CODEC)) {
                String[] strArr = a;
                int length = strArr.length;
                int i2 = 0;
                while (true) {
                    if (i2 >= length) {
                        z = true;
                        break;
                    }
                    if (string.equals(strArr[i2])) {
                        break;
                    }
                    i2++;
                }
            }
            if (z) {
                return "AND" + string;
            }
            File fileStreamPath = context.getFileStreamPath(".flurryb.");
            ?? exists = fileStreamPath.exists();
            if (exists != 0) {
                try {
                    try {
                        dataInputStream = new DataInputStream(new FileInputStream(fileStreamPath));
                        try {
                            dataInputStream.readInt();
                            o2 = dataInputStream.readUTF();
                            ac.a(dataInputStream);
                            exists = dataInputStream;
                        } catch (Throwable th) {
                            th = th;
                            bm.b("FlurryAgent", "Error when loading b file", th);
                            ac.a(dataInputStream);
                            exists = dataInputStream;
                            return o2;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        ac.a((Closeable) exists);
                        throw th;
                    }
                } catch (Throwable th3) {
                    th = th3;
                    exists = 0;
                    ac.a((Closeable) exists);
                    throw th;
                }
                return o2;
            }
            return o2;
        }
        return o2;
    }

    private static String d(Context context) {
        String str;
        PackageInfo packageInfo;
        try {
            packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
            str = "Unknown";
        }
        if (packageInfo.versionName != null) {
            str = packageInfo.versionName;
        } else {
            if (packageInfo.versionCode != 0) {
                str = Integer.toString(packageInfo.versionCode);
            }
            str = "Unknown";
        }
        return str;
    }

    private android.location.Location e(Context context) {
        if (context.checkCallingOrSelfPermission("android.permission.ACCESS_FINE_LOCATION") == 0 || context.checkCallingOrSelfPermission("android.permission.ACCESS_COARSE_LOCATION") == 0) {
            LocationManager locationManager = (LocationManager) context.getSystemService("location");
            synchronized (this) {
                if (this.B == null) {
                    this.B = locationManager;
                } else {
                    locationManager = this.B;
                }
            }
            Criteria criteria = k;
            if (criteria == null) {
                criteria = new Criteria();
            }
            String bestProvider = locationManager.getBestProvider(criteria, true);
            if (bestProvider != null) {
                locationManager.requestLocationUpdates(bestProvider, 0L, 0.0f, this, Looper.getMainLooper());
                return locationManager.getLastKnownLocation(bestProvider);
            }
        }
        return null;
    }

    private static byte[] f(Context context) {
        TelephonyManager telephonyManager;
        String deviceId;
        if (context.checkCallingOrSelfPermission("android.permission.READ_PHONE_STATE") == 0 && (telephonyManager = (TelephonyManager) context.getSystemService("phone")) != null && (deviceId = telephonyManager.getDeviceId()) != null && deviceId.trim().length() > 0) {
            try {
                byte[] c2 = ac.c(deviceId);
                if (c2 == null || c2.length != 20) {
                    bm.b("FlurryAgent", "sha1 is not 20 bytes long: " + Arrays.toString(c2));
                } else {
                    return c2;
                }
            } catch (Exception e2) {
            }
        }
        return null;
    }

    private synchronized void n() {
        if (this.B != null) {
            this.B.removeUpdates(this);
        }
    }

    public static String c() {
        return e.w;
    }

    private synchronized String o() {
        return this.C;
    }

    private synchronized void d(String str) {
        if (str != null) {
            this.C = str;
        }
    }

    public static String getPhoneId() {
        return e.o();
    }

    @Override
    public final synchronized void onLocationChanged(android.location.Location location) {
        try {
            this.R = location;
            n();
        } catch (Throwable th) {
            bm.b("FlurryAgent", "", th);
        }
    }

    @Override
    public final void onProviderDisabled(String str) {
    }

    @Override
    public final void onProviderEnabled(String str) {
    }

    @Override
    public final void onStatusChanged(String str, int i2, Bundle bundle) {
    }
}