360手机助手 v5.2.50版本的 MD5 值为:087c008db9e518cd556c792742e6830c

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


package cn.com.iresearch.mapptracker;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Looper;
import android.util.Log;
import cn.com.iresearch.mapptracker.dao.EventInfo;
import cn.com.iresearch.mapptracker.dao.SessionInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class IRMonitor {
    public static String a = "test_android";
    public static String b = "";
    public static boolean c = false;
    public static IRCallBack d = null;
    static int e = 0;
    private static IRMonitor h;
    private cn.com.iresearch.mapptracker.a.a f;
    private Context g;
    private SharedPreferences.Editor j;
    private SharedPreferences i = null;
    private cn.com.iresearch.mapptracker.dao.b k = null;
    private boolean l = true;
    private boolean m = false;
    private long n = 0;
    private long o = 0;
    private int p = 0;
    private int q = 0;
    private List r = new ArrayList();
    private Map s = new HashMap();
    private String t = null;
    private boolean u = false;

    private IRMonitor() {
    }

    private void a(Context context) {
        try {
            if (this.k == null) {
                this.k = new cn.com.iresearch.mapptracker.dao.b();
            }
            new a(this, context).start();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    private void a(boolean z) {
        try {
            if (this.i == null || this.j == null) {
                this.i = h.g.getSharedPreferences("MATSharedPreferences", 0);
                this.j = this.i.edit();
            }
            if (this.t == null || "".equals(this.t)) {
                this.t = h.g.getPackageName();
            }
            if (this.f == null) {
                this.f = cn.com.iresearch.mapptracker.a.a.a(h.g, "_ire");
            }
            if (this.r.isEmpty() || this.r == null) {
                this.r = cn.com.iresearch.mapptracker.b.d.b(h.g, this.t);
            }
            if (this.k == null) {
                a(h.g);
            }
            if (z) {
                return;
            }
            this.p = this.i.getInt("sPage_Count", 0);
            this.q = this.i.getInt("event_Count", 0);
        } catch (Exception e2) {
            if (c) {
                Log.e("MAT_SESSION", "内部初始化失败");
            }
            e2.printStackTrace();
        }
    }

    public static JSONObject b(EventInfo eventInfo) {
        JSONObject jSONObject = new JSONObject();
        try {
            String label = eventInfo.getLabel();
            if (label == null) {
                label = "";
            }
            jSONObject.put("label", label);
            jSONObject.put("event_id", eventInfo.getEvent_id().replace(label, ""));
            jSONObject.put("duration", eventInfo.getDuration());
            jSONObject.put("open_count", eventInfo.getOpen_count());
            jSONObject.put("start_time", eventInfo.getStart_time());
            jSONObject.put("end_time", eventInfo.getEnd_time());
            jSONObject.put("event_params", eventInfo.getEvent_params());
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return jSONObject;
    }

    public static JSONObject b(SessionInfo sessionInfo) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("start_time", sessionInfo.getStart_time());
            jSONObject.put("end_time", sessionInfo.getEnd_time());
            jSONObject.put("duration", sessionInfo.getDuration());
            jSONObject.put("page_name", sessionInfo.getPage_name());
            jSONObject.put("inapp", sessionInfo.getInapp());
            jSONObject.put("sessionid", sessionInfo.getSessionid());
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return jSONObject;
    }

    private void b(Context context) {
        try {
            JSONObject jSONObject = new JSONObject();
            JSONArray jSONArray = new JSONArray();
            jSONObject.put("header", cn.com.iresearch.mapptracker.b.d.e(context));
            jSONObject.put("page_list", jSONArray);
            jSONObject.put("event_list", jSONArray);
            jSONObject.put("lat", "");
            jSONObject.put("lng", "");
            jSONObject.put("open_count", "0");
            jSONObject.put("page_count", "0");
            jSONObject.put("run_time", "0");
            String a2 = this.k.a();
            String jSONObject2 = jSONObject.toString();
            if (cn.com.iresearch.mapptracker.b.d.b(h.g)) {
                new f(this, jSONObject2, a2).start();
            }
        } catch (JSONException e2) {
            if (c) {
                Log.e("MAT_SESSION", "初始化Session失败");
            }
            e2.printStackTrace();
        }
    }

    public static synchronized void b(Object obj) {
        synchronized (IRMonitor.class) {
            if (obj != null) {
                if (h != null && h.j != null) {
                    try {
                        h.f.a(obj);
                        h.p++;
                        h.j.putInt("sPage_Count", h.p).commit();
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                }
            }
        }
    }

    private boolean b() {
        try {
            long j = this.i.getLong("daysend", 0L);
            String a2 = cn.com.iresearch.mapptracker.b.d.a();
            if (!"".equals(a2)) {
                if (Long.valueOf(a2).longValue() - j > 0) {
                    return true;
                }
            }
        } catch (NumberFormatException e2) {
            e2.printStackTrace();
        }
        return false;
    }

    public static void c(IRMonitor iRMonitor) {
        if (iRMonitor.k == null) {
            iRMonitor.k = new cn.com.iresearch.mapptracker.dao.b();
        }
        iRMonitor.k.a(iRMonitor.i.getString("SendDataUrl", "http://m.irs01.com/rec/se?_iwt_t=i&sv=2"));
        iRMonitor.k.b(iRMonitor.i.getString("SendClientUrl", "http://m.irs01.com/rec/cl?_iwt_t=i&sv=2"));
        iRMonitor.k.c(iRMonitor.i.getString("ConfigUrl", "http://m.irs01.com/cfg/appkey-"));
        iRMonitor.k.a(iRMonitor.i.getLong("ConfigExpireTime", 1440L));
        try {
            iRMonitor.k.a(iRMonitor.i.getInt("LimitInterval", 30));
            iRMonitor.k.b(iRMonitor.i.getInt("sendMode", 0));
            iRMonitor.k.c(iRMonitor.i.getInt("LimitCount", 100));
        } catch (Exception e2) {
        }
    }

    public static IRMonitor getInstance(Context context) {
        if (h == null) {
            synchronized (IRMonitor.class) {
                if (h == null) {
                    IRMonitor iRMonitor = new IRMonitor();
                    h = iRMonitor;
                    iRMonitor.g = context.getApplicationContext();
                }
            }
        }
        h.g = context;
        return h;
    }

    public void Init(String str, String str2, boolean z) {
        if (this.i != null) {
            return;
        }
        a = str;
        if (str2 == null) {
            str2 = cn.com.iresearch.mapptracker.b.d.d(h.g);
        }
        b = str2;
        c = z;
        this.i = h.g.getSharedPreferences("MATSharedPreferences", 0);
        this.j = this.i.edit();
        a(h.g);
        if (this.i.getBoolean("isFirstRun", true)) {
            b(h.g);
        }
        a(true);
    }

    public void Init(String str, String str2, boolean z, IRCallBack iRCallBack) {
        if (this.i != null) {
            return;
        }
        a = str;
        if (str2 == null) {
            str2 = cn.com.iresearch.mapptracker.b.d.d(h.g);
        }
        b = str2;
        c = z;
        d = iRCallBack;
        this.i = h.g.getSharedPreferences("MATSharedPreferences", 0);
        this.j = this.i.edit();
        a(h.g);
        if (this.i.getBoolean("isFirstRun", true)) {
            b(h.g);
        }
        a(true);
    }

    public String getMyUid() {
        return cn.com.iresearch.mapptracker.b.d.g(this.g);
    }

    public String getSDKVer() {
        return "2.3.2";
    }

    public void onEvent(String str) {
        onEvent(str, "");
    }

    public void onEvent(String str, String str2) {
        onEvent(str, str2, null);
    }

    public void onEvent(String str, String str2, Map map) {
        try {
            EventInfo eventInfo = new EventInfo();
            eventInfo.setEvent_id(String.valueOf(str) + str2);
            eventInfo.setLabel(str2);
            eventInfo.setStart_time(System.currentTimeMillis() / 1000);
            eventInfo.setEnd_time(0L);
            eventInfo.setDuration(0L);
            eventInfo.setOpen_count(0L);
            eventInfo.setEvent_params(cn.com.iresearch.mapptracker.b.d.a(map));
            new g(true, eventInfo, String.valueOf(str) + str2).start();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public void onEventEnd(String str, String str2) {
        try {
            EventInfo eventInfo = (EventInfo) this.s.get(String.valueOf(str) + str2);
            if (eventInfo == null || !eventInfo.eventisStart) {
                if (c) {
                    Log.e("MAT_EVENT", "请先调用onEventStart!");
                    return;
                }
                return;
            }
            long currentTimeMillis = System.currentTimeMillis() / 1000;
            eventInfo.setEnd_time(currentTimeMillis);
            eventInfo.setDuration(currentTimeMillis - eventInfo.getStart_time());
            if (eventInfo.eventisStart) {
                eventInfo.open_count++;
            }
            eventInfo.eventisStart = false;
            eventInfo.setLabel(str2);
            eventInfo.setStart_time(eventInfo.first_start_time);
            this.s.put(String.valueOf(str) + str2, eventInfo);
            String str3 = "event_id= " + str + str2 + "的事件结束! start_time:" + eventInfo.first_start_time + " end_time:" + eventInfo.getEnd_time() + " duration:" + eventInfo.getDuration() + " 事件发生次数:" + eventInfo.getOpen_count();
            if (c) {
                Log.e("MAT_EVENT", str3);
            }
            new g(false, eventInfo, String.valueOf(str) + str2).start();
        } catch (Exception e2) {
            if (c) {
                Log.e("MAT_EVENT", "事件结束保存失败!");
            }
            e2.printStackTrace();
        }
    }

    public void onEventStart(String str, String str2, Map map) {
        try {
            EventInfo eventInfo = (EventInfo) this.s.get(String.valueOf(str) + str2);
            long currentTimeMillis = System.currentTimeMillis() / 1000;
            if (eventInfo != null) {
                if (eventInfo.event_id.equals(String.valueOf(str) + str2)) {
                    eventInfo.setEvent_params(cn.com.iresearch.mapptracker.b.d.a(map));
                    eventInfo.setStart_time(currentTimeMillis);
                    eventInfo.eventisStart = true;
                    String str3 = "event_id= " + str + str2 + "的事件开始! start_time:" + eventInfo.first_start_time;
                    if (c) {
                        Log.e("MAT_EVENT", str3);
                    }
                    this.s.put(String.valueOf(str) + str2, eventInfo);
                    return;
                }
                return;
            }
            EventInfo eventInfo2 = new EventInfo();
            eventInfo2.event_id = String.valueOf(str) + str2;
            eventInfo2.setEvent_params(cn.com.iresearch.mapptracker.b.d.a(map));
            eventInfo2.setStart_time(currentTimeMillis);
            eventInfo2.first_start_time = currentTimeMillis;
            eventInfo2.eventisStart = true;
            String str4 = "event_id= " + str + str2 + "的事件开始(第一次)! ,start_time: " + eventInfo2.first_start_time;
            if (c) {
                Log.e("MAT_EVENT", str4);
            }
            this.s.put(String.valueOf(str) + str2, eventInfo2);
        } catch (Exception e2) {
            if (c) {
                Log.e("MAT_EVENT", "事件开启失败:\n");
            }
            e2.printStackTrace();
        }
    }

    public void onPause() {
        if (!"main".equals(Thread.currentThread().getName())) {
            if (c) {
                Log.e("MAT_SESSION", "非main线程return");
                return;
            }
            return;
        }
        if (Looper.myLooper() != Looper.getMainLooper()) {
            if (c) {
                Log.e("MAT_SESSION", "非主线程return");
                return;
            }
            return;
        }
        try {
            h.m = false;
            if (this.l) {
                return;
            }
            this.l = true;
            this.o = System.currentTimeMillis() / 1000;
            long j = this.o - this.n;
            if (j >= 1) {
                SessionInfo sessionInfo = new SessionInfo();
                sessionInfo.setStart_time(this.n);
                sessionInfo.setEnd_time(this.o);
                sessionInfo.setDuration(j);
                sessionInfo.setSessionid(String.valueOf((Long.parseLong(cn.com.iresearch.mapptracker.b.d.a()) + 63529) * 5) + ((int) Math.round((Math.random() * 89999.0d) + 10000.0d)));
                if (cn.com.iresearch.mapptracker.b.d.c(h.g.getApplicationContext(), "".equals(h.t) ? cn.com.iresearch.mapptracker.b.d.c(h.g) : h.t)) {
                    String a2 = cn.com.iresearch.mapptracker.b.d.a(h.g.getApplicationContext(), 0);
                    sessionInfo.setPage_name(a2);
                    sessionInfo.setInapp(1L);
                    String str = "在本app中跳转,前一个Activity: " + a2 + " 运行时间:" + j + "s";
                    if (c) {
                        Log.e("MAT_SESSION", str);
                    }
                } else {
                    sessionInfo.setInapp(0L);
                    String a3 = cn.com.iresearch.mapptracker.b.d.a(h.g.getApplicationContext(), 1);
                    if (this.r.contains(a3)) {
                        String str2 = "按HOME键去后台,前一个Activity: " + a3 + " 运行时间:" + j + "s";
                        if (c) {
                            Log.e("MAT_SESSION", str2);
                        }
                    } else {
                        a3 = cn.com.iresearch.mapptracker.b.d.a(h.g.getApplicationContext(), 2);
                        String str3 = "通过激活最近运行程序到后台,前一个Activity: " + a3 + " 运行时间:" + j + "s";
                        if (c) {
                            Log.e("MAT_SESSION", str3);
                        }
                    }
                    sessionInfo.setPage_name(a3);
                }
                if (this.p <= this.k.g()) {
                    new d(sessionInfo).start();
                }
            }
            new e(this).start();
        } catch (Exception e2) {
            if (c) {
                Log.e("MAT_SESSION", "onPause逻辑失败");
            }
            e2.printStackTrace();
        }
    }

    public void onResume() {
        if ("main".equals(Thread.currentThread().getName()) && Looper.myLooper() == Looper.getMainLooper()) {
            try {
                this.l = false;
                a(false);
                this.n = System.currentTimeMillis() / 1000;
                if (this.o == 0) {
                    this.o = this.i.getLong("endPoint", 0L);
                }
                long abs = Math.abs(this.n - this.o);
                long e2 = this.k.e() * 60;
                if (abs > 10 && this.u) {
                    this.u = false;
                }
                if (!this.u && b()) {
                    this.u = true;
                    Context applicationContext = h.g.getApplicationContext();
                    try {
                        JSONObject jSONObject = new JSONObject();
                        JSONArray jSONArray = new JSONArray();
                        jSONObject.put("header", cn.com.iresearch.mapptracker.b.d.e(applicationContext));
                        jSONObject.put("page_list", jSONArray);
                        jSONObject.put("event_list", jSONArray);
                        jSONObject.put("lat", "f");
                        jSONObject.put("lng", "x");
                        jSONObject.put("open_count", "0");
                        jSONObject.put("page_count", "0");
                        jSONObject.put("run_time", "0");
                        String a2 = this.k.a();
                        String jSONObject2 = jSONObject.toString();
                        if (cn.com.iresearch.mapptracker.b.d.b(h.g)) {
                            new c(this, jSONObject2, a2).start();
                        }
                    } catch (JSONException e3) {
                        if (c) {
                            Log.e("MAT_SESSION", "发送一天一条数据失败");
                        }
                        e3.printStackTrace();
                    }
                }
                if (abs < e2 || this.o == 0) {
                    String str = "在后台时间:" + abs + " < 后台阀值:" + e2 + " 不发送数据";
                    if (c) {
                        Log.e("MAT_SESSION", str);
                        return;
                    }
                    return;
                }
                String str2 = "在后台时间:" + abs + " >= 后台阀值:" + e2 + " 发送数据";
                if (c) {
                    Log.e("MAT_SESSION", str2);
                }
                try {
                    List<SessionInfo> b2 = h.f.b(SessionInfo.class);
                    HashMap hashMap = new HashMap();
                    for (SessionInfo sessionInfo : b2) {
                        String substring = sessionInfo.getSessionid().substring(0, sessionInfo.getSessionid().length() - 5);
                        if (hashMap.containsKey(substring)) {
                            ((List) hashMap.get(substring)).add(sessionInfo);
                        } else {
                            ArrayList arrayList = new ArrayList();
                            arrayList.add(sessionInfo);
                            hashMap.put(substring, arrayList);
                        }
                    }
                    for (Map.Entry entry : hashMap.entrySet()) {
                        h.g.getApplicationContext();
                        List list = (List) entry.getValue();
                        String str3 = (String) entry.getKey();
                        if (!h.m) {
                            new b(list, str3).start();
                        }
                    }
                } catch (Exception e4) {
                    if (c) {
                        Log.e("MAT_SESSION", "onResume发送数据异常");
                    }
                    e4.printStackTrace();
                }
            } catch (Exception e5) {
                if (c) {
                    Log.e("MAT_SESSION", "onResume逻辑失败");
                }
                e5.printStackTrace();
            }
        }
    }
}