TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c

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


package com.tencent.wxop.stat;

import android.content.Context;
import com.tencent.wxop.stat.common.StatConstants;
import com.tencent.wxop.stat.common.StatLogger;
import java.lang.Thread;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONException;
import org.json.JSONObject;
public class StatServiceImpl {
    private static com.tencent.wxop.stat.common.e d;
    private static volatile Map<com.tencent.wxop.stat.event.c, Long> e = new ConcurrentHashMap();
    private static volatile Map<String, Properties> f = new ConcurrentHashMap();
    private static volatile Map<Integer, Integer> g = new ConcurrentHashMap(10);
    private static volatile long h = 0;
    private static volatile long i = 0;
    private static volatile long j = 0;
    private static String k = "";
    private static volatile int l = 0;
    private static volatile String m = "";
    private static volatile String n = "";
    private static Map<String, Long> o = new ConcurrentHashMap();
    private static Map<String, Long> p = new ConcurrentHashMap();
    private static StatLogger q = com.tencent.wxop.stat.common.l.b();
    private static Thread.UncaughtExceptionHandler r = null;
    private static volatile boolean s = true;
    static volatile int f97532a = 0;
    static volatile long f97533b = 0;
    private static Context t = null;
    static volatile long f97534c = 0;

    public static int a(Context context, boolean z, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        long currentTimeMillis = System.currentTimeMillis();
        boolean z2 = z && currentTimeMillis - i >= ((long) StatConfig.getSessionTimoutMillis());
        i = currentTimeMillis;
        if (j == 0) {
            j = com.tencent.wxop.stat.common.l.c();
        }
        if (currentTimeMillis >= j) {
            j = com.tencent.wxop.stat.common.l.c();
            if (au.a(context).b(context).d() != 1) {
                au.a(context).b(context).a(1);
            }
            StatConfig.b(0);
            f97532a = 0;
            k = com.tencent.wxop.stat.common.l.a(0);
            z2 = true;
        }
        String str = k;
        if (com.tencent.wxop.stat.common.l.a(statSpecifyReportedInfo)) {
            str = statSpecifyReportedInfo.getAppKey() + k;
        }
        if (p.containsKey(str) ? z2 : true) {
            if (com.tencent.wxop.stat.common.l.a(statSpecifyReportedInfo)) {
                a(context, statSpecifyReportedInfo);
            } else if (StatConfig.c() < StatConfig.getMaxDaySessionNumbers()) {
                com.tencent.wxop.stat.common.l.v(context);
                a(context, (StatSpecifyReportedInfo) null);
            } else {
                q.e("Exceed StatConfig.getMaxDaySessionNumbers().");
            }
            p.put(str, 1L);
        }
        if (s) {
            testSpeed(context);
            s = false;
        }
        return l;
    }

    static synchronized void a(Context context) {
        synchronized (StatServiceImpl.class) {
            if (context != null) {
                if (d == null && b(context)) {
                    Context applicationContext = context.getApplicationContext();
                    t = applicationContext;
                    d = new com.tencent.wxop.stat.common.e();
                    k = com.tencent.wxop.stat.common.l.a(0);
                    h = System.currentTimeMillis() + StatConfig.i;
                    d.a(new l(applicationContext));
                }
            }
        }
    }

    static void a(Context context, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (c(context) != null) {
            if (StatConfig.isDebugEnable()) {
                q.d("start new session.");
            }
            if (statSpecifyReportedInfo == null || l == 0) {
                l = com.tencent.wxop.stat.common.l.a();
            }
            StatConfig.a(0);
            StatConfig.b();
            new aq(new com.tencent.wxop.stat.event.k(context, l, b(), statSpecifyReportedInfo)).a();
        }
    }

    public static void a(Context context, Throwable th) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.reportSdkSelfException() can not be null!");
            } else if (c(context2) != null) {
                d.a(new q(context2, th));
            }
        }
    }

    public static boolean a() {
        if (f97532a >= 2) {
            f97533b = System.currentTimeMillis();
            return true;
        }
        return false;
    }

    public static boolean a(String str) {
        return str == null || str.length() == 0;
    }

    static JSONObject b() {
        JSONObject jSONObject = new JSONObject();
        try {
            JSONObject jSONObject2 = new JSONObject();
            if (StatConfig.f97525b.d != 0) {
                jSONObject2.put("v", StatConfig.f97525b.d);
            }
            jSONObject.put(Integer.toString(StatConfig.f97525b.f97656a), jSONObject2);
            JSONObject jSONObject3 = new JSONObject();
            if (StatConfig.f97524a.d != 0) {
                jSONObject3.put("v", StatConfig.f97524a.d);
            }
            jSONObject.put(Integer.toString(StatConfig.f97524a.f97656a), jSONObject3);
        } catch (JSONException e2) {
            q.e((Throwable) e2);
        }
        return jSONObject;
    }

    public static void b(Context context, StatAccount statAccount, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        try {
            new aq(new com.tencent.wxop.stat.event.a(context, a(context, false, statSpecifyReportedInfo), statAccount, statSpecifyReportedInfo)).a();
        } catch (Throwable th) {
            q.e(th);
            a(context, th);
        }
    }

    static boolean b(Context context) {
        boolean z = false;
        long a2 = com.tencent.wxop.stat.common.q.a(context, StatConfig.f97526c, 0L);
        long b2 = com.tencent.wxop.stat.common.l.b(StatConstants.VERSION);
        boolean z2 = true;
        if (b2 <= a2) {
            q.error("MTA is disable for current version:" + b2 + ",wakeup version:" + a2);
            z2 = false;
        }
        long a3 = com.tencent.wxop.stat.common.q.a(context, StatConfig.d, 0L);
        if (a3 > System.currentTimeMillis()) {
            q.error("MTA is disable for current time:" + System.currentTimeMillis() + ",wakeup time:" + a3);
        } else {
            z = z2;
        }
        StatConfig.setEnableStatService(z);
        return z;
    }

    static com.tencent.wxop.stat.common.e c(Context context) {
        if (d == null) {
            synchronized (StatServiceImpl.class) {
                if (d == null) {
                    a(context);
                }
            }
        }
        return d;
    }

    public static void c() {
        f97532a = 0;
        f97533b = 0L;
    }

    public static void commitEvents(Context context, int i2) {
        if (StatConfig.isEnableStatService()) {
            if (StatConfig.isDebugEnable()) {
                q.i("commitEvents, maxNumber=" + i2);
            }
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.commitEvents() can not be null!");
            } else if (i2 < -1 || i2 == 0) {
                q.error("The maxNumber of StatService.commitEvents() should be -1 or bigger than 0.");
            } else if (!a.a(t).f() || c(context2) == null) {
            } else {
                d.a(new ad(context2, i2));
            }
        }
    }

    public static void d() {
        f97532a++;
        f97533b = System.currentTimeMillis();
        flushDataToDB(t);
    }

    public static void d(Context context) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.sendNetworkDetector() can not be null!");
                return;
            }
            try {
                i.b(context2).a(new com.tencent.wxop.stat.event.h(context2), new t());
            } catch (Throwable th) {
                q.e(th);
            }
        }
    }

    public static void e(Context context) {
        f97534c = System.currentTimeMillis() + (60000 * StatConfig.getSendPeriodMinutes());
        com.tencent.wxop.stat.common.q.b(context, "last_period_ts", f97534c);
        commitEvents(context, -1);
    }

    public static void flushDataToDB(Context context) {
        if (StatConfig.isEnableStatService() && StatConfig.m > 0) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.testSpeed() can not be null!");
            } else {
                au.a(context2).c();
            }
        }
    }

    public static Properties getCommonKeyValueForKVEvent(String str) {
        return f.get(str);
    }

    public static Context getContext(Context context) {
        return context != null ? context : t;
    }

    public static void onLowMemory(Context context) {
        if (StatConfig.isEnableStatService() && c(getContext(context)) != null) {
            d.a(new o(context));
        }
    }

    public static void onPause(Context context, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService() && c(context) != null) {
            d.a(new m(context, statSpecifyReportedInfo));
        }
    }

    public static void onResume(Context context, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService() && c(context) != null) {
            d.a(new aj(context, statSpecifyReportedInfo));
        }
    }

    public static void onStop(Context context, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (c(context2) != null) {
                d.a(new n(context2));
            }
        }
    }

    public static void reportAccount(Context context, StatAccount statAccount, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.e("context is null in reportAccount.");
            } else if (c(context2) != null) {
                d.a(new al(statAccount, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void reportAppMonitorStat(Context context, StatAppMonitor statAppMonitor, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.reportAppMonitorStat() can not be null!");
            } else if (statAppMonitor == null) {
                q.error("The StatAppMonitor of StatService.reportAppMonitorStat() can not be null!");
            } else if (statAppMonitor.getInterfaceName() == null) {
                q.error("The interfaceName of StatAppMonitor on StatService.reportAppMonitorStat() can not be null!");
            } else {
                StatAppMonitor m10608clone = statAppMonitor.m10608clone();
                if (c(context2) != null) {
                    d.a(new aa(context2, statSpecifyReportedInfo, m10608clone));
                }
            }
        }
    }

    public static void reportError(Context context, String str, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.reportError() can not be null!");
            } else if (c(context2) != null) {
                d.a(new p(str, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void reportException(Context context, Throwable th, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.reportException() can not be null!");
            } else if (c(context2) != null) {
                d.a(new r(th, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void reportGameUser(Context context, StatGameUser statGameUser, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.reportGameUser() can not be null!");
            } else if (c(context2) != null) {
                d.a(new am(statGameUser, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void reportQQ(Context context, String str, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("context is null in reportQQ()");
            } else if (c(context2) != null) {
                d.a(new ak(str, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void setCommonKeyValueForKVEvent(String str, Properties properties) {
        if (!com.tencent.wxop.stat.common.l.c(str)) {
            q.e("event_id or commonProp for setCommonKeyValueForKVEvent is invalid.");
        } else if (properties == null || properties.size() <= 0) {
            f.remove(str);
        } else {
            f.put(str, (Properties) properties.clone());
        }
    }

    public static void setContext(Context context) {
        if (context != null) {
            t = context.getApplicationContext();
        }
    }

    public static void setEnvAttributes(Context context, Map<String, String> map) {
        if (map == null || map.size() > 512) {
            q.error("The map in setEnvAttributes can't be null or its size can't exceed 512.");
            return;
        }
        try {
            com.tencent.wxop.stat.common.b.a(context, map);
        } catch (JSONException e2) {
            q.e((Throwable) e2);
        }
    }

    public static void startNewSession(Context context, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.startNewSession() can not be null!");
            } else if (c(context2) != null) {
                d.a(new ai(context2, statSpecifyReportedInfo));
            }
        }
    }

    public static boolean startStatService(Context context, String str, String str2, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        try {
            if (!StatConfig.isEnableStatService()) {
                q.error("MTA StatService is disable.");
                return false;
            }
            if (StatConfig.isDebugEnable()) {
                q.d("MTA SDK version, current: " + StatConstants.VERSION + " ,required: " + str2);
            }
            if (context == null || str2 == null) {
                q.error("Context or mtaSdkVersion in StatService.startStatService() is null, please check it!");
                StatConfig.setEnableStatService(false);
                return false;
            } else if (com.tencent.wxop.stat.common.l.b(StatConstants.VERSION) < com.tencent.wxop.stat.common.l.b(str2)) {
                q.error(("MTA SDK version conflicted, current: " + StatConstants.VERSION + ",required: " + str2) + ". please delete the current SDK and download the latest one. official website: http://mta.qq.com/ or http://mta.oa.com/");
                StatConfig.setEnableStatService(false);
                return false;
            } else {
                String installChannel = StatConfig.getInstallChannel(context);
                if (installChannel == null || installChannel.length() == 0) {
                    StatConfig.setInstallChannel("-");
                }
                if (str != null) {
                    StatConfig.setAppKey(context, str);
                }
                if (c(context) != null) {
                    d.a(new an(context, statSpecifyReportedInfo));
                }
                return true;
            }
        } catch (Throwable th) {
            q.e(th);
            return false;
        }
    }

    public static void stopSession() {
        i = 0L;
    }

    public static void testSpeed(Context context) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.testSpeed() can not be null!");
            } else if (c(context2) != null) {
                d.a(new ae(context2));
            }
        }
    }

    public static void testSpeed(Context context, Map<String, Integer> map, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.testSpeed() can not be null!");
            } else if (map == null || map.size() == 0) {
                q.error("The domainMap of StatService.testSpeed() can not be null or empty!");
            } else {
                HashMap hashMap = new HashMap(map);
                if (c(context2) != null) {
                    d.a(new af(context2, hashMap, statSpecifyReportedInfo));
                }
            }
        }
    }

    public static void trackBeginPage(Context context, String str, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null || str == null || str.length() == 0) {
                q.error("The Context or pageName of StatService.trackBeginPage() can not be null or empty!");
                return;
            }
            String str2 = new String(str);
            if (c(context2) != null) {
                d.a(new w(str2, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void trackCustomBeginEvent(Context context, String str, StatSpecifyReportedInfo statSpecifyReportedInfo, String... strArr) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomBeginEvent() can not be null!");
                return;
            }
            com.tencent.wxop.stat.event.c cVar = new com.tencent.wxop.stat.event.c(str, strArr, null);
            if (c(context2) != null) {
                d.a(new v(str, cVar, context2));
            }
        }
    }

    public static void trackCustomBeginKVEvent(Context context, String str, Properties properties, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomBeginEvent() can not be null!");
                return;
            }
            com.tencent.wxop.stat.event.c cVar = new com.tencent.wxop.stat.event.c(str, null, properties);
            if (c(context2) != null) {
                d.a(new y(str, cVar, context2));
            }
        }
    }

    public static void trackCustomEndEvent(Context context, String str, StatSpecifyReportedInfo statSpecifyReportedInfo, String... strArr) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomEndEvent() can not be null!");
                return;
            }
            com.tencent.wxop.stat.event.c cVar = new com.tencent.wxop.stat.event.c(str, strArr, null);
            if (c(context2) != null) {
                d.a(new x(str, cVar, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void trackCustomEndKVEvent(Context context, String str, Properties properties, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomEndEvent() can not be null!");
                return;
            }
            com.tencent.wxop.stat.event.c cVar = new com.tencent.wxop.stat.event.c(str, null, properties);
            if (c(context2) != null) {
                d.a(new z(str, cVar, context2, statSpecifyReportedInfo));
            }
        }
    }

    public static void trackCustomEvent(Context context, String str, StatSpecifyReportedInfo statSpecifyReportedInfo, String... strArr) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomEvent() can not be null!");
            } else if (a(str)) {
                q.error("The event_id of StatService.trackCustomEvent() can not be null or empty.");
            } else {
                com.tencent.wxop.stat.event.c cVar = new com.tencent.wxop.stat.event.c(str, strArr, null);
                if (c(context2) != null) {
                    d.a(new s(context2, statSpecifyReportedInfo, cVar));
                }
            }
        }
    }

    public static void trackCustomKVEvent(Context context, String str, Properties properties, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomEvent() can not be null!");
            } else if (a(str)) {
                q.error("The event_id of StatService.trackCustomEvent() can not be null or empty.");
            } else {
                com.tencent.wxop.stat.event.c cVar = new com.tencent.wxop.stat.event.c(str, null, properties);
                if (c(context2) != null) {
                    d.a(new u(context2, statSpecifyReportedInfo, cVar));
                }
            }
        }
    }

    public static void trackCustomKVTimeIntervalEvent(Context context, String str, Properties properties, int i2, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomEndEvent() can not be null!");
            } else if (a(str)) {
                q.error("The event_id of StatService.trackCustomEndEvent() can not be null or empty.");
            } else {
                com.tencent.wxop.stat.event.c cVar = new com.tencent.wxop.stat.event.c(str, null, properties);
                if (c(context2) != null) {
                    d.a(new ac(context2, statSpecifyReportedInfo, cVar, i2));
                }
            }
        }
    }

    public static void trackCustomTimeIntervalEvent(Context context, int i2, String str, String... strArr) {
        if (StatConfig.isEnableStatService()) {
            if (i2 <= 0) {
                q.error("The intervalSecond of StatService.trackCustomTimeIntervalEvent() can must bigger than 0!");
                return;
            }
            Context context2 = getContext(context);
            if (context2 == null) {
                q.error("The Context of StatService.trackCustomTimeIntervalEvent() can not be null!");
            } else if (c(context2) != null) {
                d.a(new ab());
            }
        }
    }

    public static void trackEndPage(Context context, String str, StatSpecifyReportedInfo statSpecifyReportedInfo) {
        if (StatConfig.isEnableStatService()) {
            Context context2 = getContext(context);
            if (context2 == null || str == null || str.length() == 0) {
                q.error("The Context or pageName of StatService.trackEndPage() can not be null or empty!");
                return;
            }
            String str2 = new String(str);
            if (c(context2) != null) {
                d.a(new ah(context2, str2, statSpecifyReportedInfo));
            }
        }
    }
}