鸠摩搜书官方正版 v1.7版本的 MD5 值为:01c9a20d2c415de3233d7f691829edf5

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


package com.a.a;

import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public final class a {
    private Context h;
    private final Handler i;
    private static final a f = new a();
    private static int g = 1;
    private static d j = null;
    private static c k = null;

    public static String f52a = "";
    public static String b = "";
    public static boolean c = true;
    public static boolean d = true;
    private static JSONObject l = null;
    public static boolean e = true;

    private a() {
        HandlerThread handlerThread = new HandlerThread("MobclickAgent");
        handlerThread.start();
        this.i = new Handler(handlerThread.getLooper());
    }

    public static String a(Context context, String str) {
        return o(context).getString(str, "");
    }

    private static String a(Context context, JSONObject jSONObject, String str, boolean z) {
        HttpPost httpPost = new HttpPost(str);
        BasicHttpParams basicHttpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 10000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
        DefaultHttpClient defaultHttpClient = new DefaultHttpClient(basicHttpParams);
        try {
            String a2 = v.a(context);
            if (a2 != null) {
                defaultHttpClient.getParams().setParameter("http.route.default-proxy", new HttpHost(a2, 80));
            }
            String jSONObject2 = jSONObject.toString();
            if (b.c) {
                Log.i("MobclickAgent", jSONObject2);
            }
            if (!b.m || z) {
                ArrayList arrayList = new ArrayList(1);
                arrayList.add(new BasicNameValuePair("content", jSONObject2));
                httpPost.setEntity(new UrlEncodedFormEntity(arrayList, "UTF-8"));
            } else {
                byte[] a3 = u.a("content=" + jSONObject2);
                httpPost.addHeader("Content-Encoding", "deflate");
                httpPost.setEntity(new InputStreamEntity(new ByteArrayInputStream(a3), u.b));
            }
            SharedPreferences.Editor edit = k(context).edit();
            Date date = new Date();
            HttpResponse execute = defaultHttpClient.execute(httpPost);
            long time = new Date().getTime() - date.getTime();
            if (execute.getStatusLine().getStatusCode() != 200) {
                edit.putLong("req_time", -1L);
                return null;
            }
            if (b.c) {
                Log.i("MobclickAgent", "Sent message to " + str);
            }
            edit.putLong("req_time", time);
            edit.commit();
            HttpEntity entity = execute.getEntity();
            if (entity != null) {
                return a(entity.getContent());
            }
            return null;
        } catch (ClientProtocolException e2) {
            if (!b.c) {
                return null;
            }
            Log.i("MobclickAgent", "ClientProtocolException,Failed to send message.", e2);
            e2.printStackTrace();
            return null;
        } catch (IOException e3) {
            if (!b.c) {
                return null;
            }
            Log.i("MobclickAgent", "IOException,Failed to send message.", e3);
            e3.printStackTrace();
            return null;
        }
    }

    private static String a(InputStream inputStream) {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 8192);
        StringBuilder sb = new StringBuilder();
        while (true) {
            try {
                try {
                    String readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        try {
                            inputStream.close();
                            return sb.toString();
                        } catch (IOException e2) {
                            if (!b.c) {
                                return null;
                            }
                            Log.e("MobclickAgent", "Caught IOException in convertStreamToString()", e2);
                            e2.printStackTrace();
                            return null;
                        }
                    }
                    sb.append(String.valueOf(readLine) + "\n");
                } catch (IOException e3) {
                    if (b.c) {
                        Log.e("MobclickAgent", "Caught IOException in convertStreamToString()", e3);
                        e3.printStackTrace();
                    }
                    try {
                        inputStream.close();
                        return null;
                    } catch (IOException e4) {
                        if (!b.c) {
                            return null;
                        }
                        Log.e("MobclickAgent", "Caught IOException in convertStreamToString()", e4);
                        e4.printStackTrace();
                        return null;
                    }
                }
            } catch (Throwable th) {
                try {
                    inputStream.close();
                    throw th;
                } catch (IOException e5) {
                    if (!b.c) {
                        return null;
                    }
                    Log.e("MobclickAgent", "Caught IOException in convertStreamToString()", e5);
                    e5.printStackTrace();
                    return null;
                }
            }
        }
    }

    public static void a(Context context) {
        try {
            if (context != null) {
                new s(context).start();
            } else if (b.c) {
                Log.e("MobclickAgent", "unexpected null context in onPause");
            }
        } catch (Exception e2) {
            if (b.c) {
                Log.e("MobclickAgent", "Exception occurred in Mobclick.onRause(). ");
                e2.printStackTrace();
            }
        }
    }

    public static void a(Context context, String str, String str2) {
        if (str2 == null || str2 == "") {
            if (b.c) {
                Log.e("MobclickAgent", "label is null or empty in onEvent(4p)");
                return;
            }
            return;
        }
        try {
            String a2 = u.a(context);
            if (a2 == null || a2.length() == 0) {
                if (b.c) {
                    Log.e("MobclickAgent", "unexpected empty appkey in onEvent(4p)");
                }
            } else if (context == null) {
                if (b.c) {
                    Log.e("MobclickAgent", "unexpected null context in onEvent(4p)");
                }
            } else if (str != null && str != "") {
                new s(context, a2, str, str2).start();
            } else if (b.c) {
                Log.e("MobclickAgent", "tag is null or empty in onEvent(4p)");
            }
        } catch (Exception e2) {
            if (b.c) {
                Log.e("MobclickAgent", "Exception occurred in Mobclick.onEvent(). ");
                e2.printStackTrace();
            }
        }
    }

    public synchronized void a(Context context, String str, String str2, int i) {
        SharedPreferences m = m(context);
        if (m != null) {
            String string = m.getString("session_id", "");
            String b2 = b();
            String str3 = b2.split(" ")[0];
            String str4 = b2.split(" ")[1];
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("type", "event");
                jSONObject.put("session_id", string);
                jSONObject.put("date", str3);
                jSONObject.put("time", str4);
                jSONObject.put("tag", str);
                if (str2 != null) {
                    jSONObject.put("label", str2);
                }
                jSONObject.put("acc", i);
                this.i.post(new t(context, jSONObject));
            } catch (JSONException e2) {
                if (b.c) {
                    Log.i("MobclickAgent", "json error in emitCustomLogReport");
                    e2.printStackTrace();
                }
            }
        }
    }

    public static void a(Context context, JSONObject jSONObject) {
        int i = 0;
        if (!a("update", context, new String[0])) {
            if (j != null) {
                d dVar = j;
                int i2 = e.b;
                return;
            }
            return;
        }
        if (b.c) {
            Log.i("MobclickAgent", "start to check update info ...");
        }
        String str = null;
        while (true) {
            if (i >= b.l.length) {
                break;
            }
            str = a(context, jSONObject, b.l[i], true);
            if (str == null) {
                i++;
            } else if (b.c) {
                Log.i("MobclickAgent", "get update info succeed: " + str);
            }
        }
        if (str == null) {
            if (b.c) {
                Log.i("MobclickAgent", "get update info failed");
            }
            if (j != null) {
                d dVar2 = j;
                int i3 = e.d;
                return;
            }
            return;
        }
        try {
            JSONObject jSONObject2 = new JSONObject(str);
            l = jSONObject2;
            if (!jSONObject2.getString("update").equals("Yes")) {
                if (j != null) {
                    d dVar3 = j;
                    int i4 = e.b;
                    return;
                }
                return;
            }
            if (j != null) {
                d dVar4 = j;
                int i5 = e.f54a;
            }
            if (e && l != null && l.has("update") && l.optString("update").toLowerCase().equals("yes")) {
                d(context, l).show();
            }
        } catch (Exception e2) {
            if (b.c) {
                Log.i("MobclickAgent", "show update dialog error");
                e2.printStackTrace();
            }
        }
    }

    private static boolean a(String str, Context context, String... strArr) {
        if (context.getPackageManager().checkPermission("android.permission.ACCESS_NETWORK_STATE", context.getPackageName()) == 0 && !u.f(context)) {
            return false;
        }
        if (str == "update" || str == "online_config") {
            return true;
        }
        int p = p(context);
        g = p;
        if (p == 3) {
            return str == "flush";
        }
        if (str == "error") {
            return strArr == null || strArr.length <= 0 || !strArr[0].equals("send_error");
        }
        if (g == 1 && str == "launch") {
            return true;
        }
        if ((g != 2 || str != "terminate") && g != 0) {
            if (g == 4) {
                return !l(context).getString(u.a(), "false").equals("true") && str.equals("launch");
            }
            if (g == 5) {
                return u.d(context)[0].equals("Wi-Fi");
            }
            return false;
        }
        return true;
    }

    private static String b() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    public static void b(Context context) {
        String a2 = u.a(context);
        String e2 = u.e(context);
        try {
            b.h = e2;
            if (context == null) {
                if (b.c) {
                    Log.e("MobclickAgent", "unexpected null context in onResume");
                }
            } else if (a2 != null && a2.length() != 0) {
                new s(context, a2, e2).start();
            } else if (b.c) {
                Log.e("MobclickAgent", "unexpected empty appkey in onResume");
            }
        } catch (Exception e3) {
            if (b.c) {
                Log.e("MobclickAgent", "Exception occurred in Mobclick.onResume(). ");
                e3.printStackTrace();
            }
        }
    }

    public synchronized void b(Context context, String str) {
        synchronized (this) {
            this.h = context;
            SharedPreferences m = m(context);
            if (m != null) {
                if (System.currentTimeMillis() - m.getLong("end_millis", -1L) > b.f53a) {
                    String string = m.getString("session_id", null);
                    if (string != null) {
                        Long valueOf = Long.valueOf(m.getLong("duration", -1L));
                        if (valueOf.longValue() <= 0) {
                            valueOf = 0L;
                        }
                        String b2 = b();
                        String str2 = b2.split(" ")[0];
                        String str3 = b2.split(" ")[1];
                        JSONObject jSONObject = new JSONObject();
                        try {
                            jSONObject.put("type", "terminate");
                            jSONObject.put("session_id", string);
                            jSONObject.put("date", str2);
                            jSONObject.put("time", str3);
                            jSONObject.put("duration", String.valueOf(valueOf.longValue() / 1000));
                            if (b.e) {
                                String string2 = m.getString("activities", "");
                                if (!"".equals(string2)) {
                                    String[] split = string2.split(";");
                                    JSONArray jSONArray = new JSONArray();
                                    for (String str4 : split) {
                                        jSONArray.put(new JSONArray(str4));
                                    }
                                    jSONObject.put("activities", jSONArray);
                                }
                            }
                            this.i.post(new t(context, jSONObject));
                        } catch (JSONException e2) {
                            if (b.c) {
                                Log.e("MobclickAgent", "json error in emitLastEndSessionReport");
                                e2.printStackTrace();
                            }
                        }
                    } else if (b.c) {
                        Log.w("MobclickAgent", "Missing session_id, ignore message in emitLastEndSessionReport");
                    }
                    long currentTimeMillis = System.currentTimeMillis();
                    StringBuilder sb = new StringBuilder();
                    sb.append(currentTimeMillis).append(str).append(u.b(context));
                    String a2 = u.a(sb.toString(), false);
                    SharedPreferences.Editor edit = m.edit();
                    edit.putString("appkey", str);
                    edit.putString("session_id", a2);
                    edit.putLong("start_millis", currentTimeMillis);
                    edit.putLong("end_millis", -1L);
                    edit.putLong("duration", 0L);
                    edit.putString("activities", "");
                    edit.commit();
                    String string3 = m.getString("session_id", null);
                    if (string3 != null) {
                        String b3 = b();
                        String str5 = b3.split(" ")[0];
                        String str6 = b3.split(" ")[1];
                        JSONObject jSONObject2 = new JSONObject();
                        try {
                            jSONObject2.put("type", "launch");
                            jSONObject2.put("session_id", string3);
                            jSONObject2.put("date", str5);
                            jSONObject2.put("time", str6);
                            this.i.post(new t(context, jSONObject2));
                        } catch (JSONException e3) {
                            if (b.c) {
                                Log.e("MobclickAgent", "json error in emitNewSessionReport");
                                e3.printStackTrace();
                            }
                        }
                    } else if (b.c) {
                        Log.i("MobclickAgent", "Missing session_id, ignore message");
                    }
                    if (b.c) {
                        Log.i("MobclickAgent", "Start new session: " + a2);
                    }
                } else {
                    Long valueOf2 = Long.valueOf(System.currentTimeMillis());
                    SharedPreferences.Editor edit2 = m.edit();
                    edit2.putLong("start_millis", valueOf2.longValue());
                    edit2.putLong("end_millis", -1L);
                    edit2.commit();
                    String string4 = m.getString("session_id", null);
                    if (b.c) {
                        Log.i("MobclickAgent", "Extend current session: " + string4);
                    }
                }
            }
        }
    }

    public static void b(Context context, JSONObject jSONObject) {
        if (a("online_config", context, new String[0])) {
            if (b.c) {
                Log.i("MobclickAgent", "start to check onlineConfig info ...");
            }
            String a2 = a(context, jSONObject, "http://www.umeng.com/check_config_update", true);
            if (a2 == null) {
                a2 = a(context, jSONObject, "http://www.umeng.co/check_config_update", true);
            }
            if (a2 == null) {
                if (b.c) {
                    Log.i("MobclickAgent", "get onlineConfig info failed !");
                    return;
                }
                return;
            }
            if (b.c) {
                Log.i("MobclickAgent", "get onlineConfig info succeed !");
            }
            SharedPreferences o = o(context);
            synchronized (b.j) {
                try {
                    JSONObject jSONObject2 = new JSONObject(a2);
                    try {
                        if (jSONObject2.has("last_config_time")) {
                            o.edit().putString("umeng_last_config_time", jSONObject2.getString("last_config_time")).commit();
                        }
                    } catch (Exception e2) {
                        if (b.c) {
                            e2.printStackTrace();
                        }
                    }
                    try {
                        if (jSONObject2.has("report_policy")) {
                            o.edit().putInt("umeng_net_report_policy", jSONObject2.getInt("report_policy")).commit();
                        }
                    } catch (Exception e3) {
                        if (b.c) {
                            e3.printStackTrace();
                        }
                    }
                    try {
                        if (jSONObject2.has("update_internal")) {
                            o.edit().putInt("umeng_update_internal", jSONObject2.getInt("update_internal")).commit();
                        }
                    } catch (Exception e4) {
                        if (b.c) {
                            e4.printStackTrace();
                        }
                    }
                    try {
                        if (jSONObject2.has("online_params")) {
                            JSONObject jSONObject3 = new JSONObject(jSONObject2.getString("online_params"));
                            Iterator<String> keys = jSONObject3.keys();
                            SharedPreferences.Editor edit = o.edit();
                            while (keys.hasNext()) {
                                String next = keys.next();
                                edit.putString(next, jSONObject3.getString(next));
                            }
                            edit.commit();
                            if (k != null) {
                                c cVar = k;
                            }
                            Log.i("MobclickAgent", "get online setting params: " + jSONObject3);
                        }
                    } catch (Exception e5) {
                        if (b.c) {
                            e5.printStackTrace();
                        }
                    }
                } catch (Exception e6) {
                    if (b.c) {
                        Log.i("MobclickAgent", "not json string");
                    }
                }
            }
        }
    }

    public static void c(Context context) {
        try {
            String a2 = u.a(context);
            if (a2 == null || a2.length() == 0) {
                if (b.c) {
                    Log.e("MobclickAgent", "unexpected empty appkey in onError");
                }
            } else if (context != null) {
                new s(context, a2).start();
            } else if (b.c) {
                Log.e("MobclickAgent", "unexpected null context in onError");
            }
        } catch (Exception e2) {
            if (b.c) {
                Log.e("MobclickAgent", "Exception occurred in Mobclick.onError()");
                e2.printStackTrace();
            }
        }
    }

    private synchronized void c(Context context, String str) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("type", "online_config");
            jSONObject.put("appkey", str);
            int i = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
            String packageName = context.getPackageName();
            jSONObject.put("version_code", i);
            jSONObject.put("package", packageName);
            jSONObject.put("sdk_version", "3.2.1");
            jSONObject.put("idmd5", u.b(context));
            jSONObject.put("channel", u.e(context));
            jSONObject.put("report_policy", p(context));
            jSONObject.put("last_config_time", o(context).getString("umeng_last_config_time", ""));
            this.i.post(new t(context, jSONObject));
        } catch (Exception e2) {
            if (b.c) {
                Log.e("MobclickAgent", "exception in onlineConfigInternal");
            }
        }
    }

    public static void c(Context context, JSONObject jSONObject) {
        SharedPreferences k2 = k(context);
        JSONObject c2 = u.c(context);
        long j2 = k2.getLong("req_time", 0L);
        if (j2 != 0) {
            try {
                c2.put("req_time", j2);
            } catch (JSONException e2) {
                if (b.c) {
                    Log.i("MobclickAgent", "json error in tryToSendMessage");
                    e2.printStackTrace();
                }
            }
        }
        k2.edit().putString("header", c2.toString()).commit();
        JSONObject i = i(context);
        JSONObject jSONObject2 = new JSONObject();
        try {
            String string = jSONObject.getString("type");
            if (string == null) {
                return;
            }
            String str = jSONObject.has("subtype") ? (String) jSONObject.remove("subtype") : null;
            if (string != "flush") {
                jSONObject.remove("type");
                if (i == null) {
                    JSONObject jSONObject3 = new JSONObject();
                    JSONArray jSONArray = new JSONArray();
                    jSONArray.put(jSONObject);
                    jSONObject3.put(string, jSONArray);
                    i = jSONObject3;
                } else if (i.isNull(string)) {
                    JSONArray jSONArray2 = new JSONArray();
                    jSONArray2.put(jSONObject);
                    i.put(string, jSONArray2);
                } else {
                    i.getJSONArray(string).put(jSONObject);
                }
            }
            if (i == null) {
                if (b.c) {
                    Log.w("MobclickAgent", "No cache message to flush in tryToSendMessage");
                    return;
                }
                return;
            }
            jSONObject2.put("header", c2);
            jSONObject2.put("body", i);
            if (a(string, context, str)) {
                String str2 = null;
                for (int i2 = 0; i2 < b.k.length && (str2 = a(context, jSONObject2, b.k[i2], false)) == null; i2++) {
                }
                if (str2 != null) {
                    if (b.c) {
                        Log.i("MobclickAgent", "send applog succeed :" + str2);
                    }
                    j(context);
                    if (g == 4) {
                        SharedPreferences.Editor edit = l(context).edit();
                        edit.putString(u.a(), "true");
                        edit.commit();
                        return;
                    }
                    return;
                }
                if (b.c) {
                    Log.i("MobclickAgent", "send applog failed");
                }
            }
            try {
                FileOutputStream openFileOutput = context.openFileOutput(n(context), 0);
                openFileOutput.write(i.toString().getBytes());
                openFileOutput.close();
            } catch (FileNotFoundException e3) {
                if (b.c) {
                    e3.printStackTrace();
                }
            } catch (IOException e4) {
                if (b.c) {
                    e4.printStackTrace();
                }
            }
        } catch (JSONException e5) {
            if (b.c) {
                Log.e("MobclickAgent", "Fail to construct json message in tryToSendMessage.");
                e5.printStackTrace();
            }
            j(context);
        }
    }

    private static AlertDialog d(Context context, JSONObject jSONObject) {
        try {
            String string = jSONObject.has("version") ? jSONObject.getString("version") : "";
            String string2 = jSONObject.has("update_log") ? jSONObject.getString("update_log") : "";
            String string3 = jSONObject.has("path") ? jSONObject.getString("path") : "";
            String str = u.d(context)[0].equals("Wi-Fi") ? "" : String.valueOf(context.getString(u.a(context, "string", "UMGprsCondition"))) + "\n";
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle(context.getString(u.a(context, "string", "UMUpdateTitle"))).setMessage(String.valueOf(str) + context.getString(u.a(context, "string", "UMNewVersion")) + string + "\n" + string2).setCancelable(false).setPositiveButton(context.getString(u.a(context, "string", "UMUpdateNow")), new q(context, string3, string)).setNegativeButton(context.getString(u.a(context, "string", "UMNotNow")), new r());
            AlertDialog create = builder.create();
            create.setCancelable(true);
            return create;
        } catch (Exception e2) {
            if (b.c) {
                Log.e("MobclickAgent", "Fail to create update dialog box.", e2);
                e2.printStackTrace();
            }
            return null;
        }
    }

    public static SharedPreferences d(Context context) {
        return context.getSharedPreferences("mobclick_agent_user_" + context.getPackageName(), 0);
    }

    public static void e(Context context) {
        try {
            if (context == null) {
                Log.e("MobclickAgent", "unexpected null context in updateOnlineConfig");
            } else {
                f.c(context, u.a(context));
            }
        } catch (Exception e2) {
            if (b.c) {
                Log.e("MobclickAgent", "exception in updateOnlineConfig");
            }
        }
    }

    private static String f(Context context) {
        String str;
        Exception e2;
        boolean z = false;
        try {
            String packageName = context.getPackageName();
            ArrayList arrayList = new ArrayList();
            arrayList.add("logcat");
            arrayList.add("-d");
            arrayList.add("-v");
            arrayList.add("raw");
            arrayList.add("-s");
            arrayList.add("AndroidRuntime:E");
            arrayList.add("-p");
            arrayList.add(packageName);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec((String[]) arrayList.toArray(new String[arrayList.size()])).getInputStream()), 1024);
            str = "";
            boolean z2 = false;
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    break;
                }
                String str2 = readLine.indexOf("thread attach failed") < 0 ? String.valueOf(str) + readLine + '\n' : str;
                boolean z3 = (z || readLine.toLowerCase().indexOf("exception") < 0) ? z : true;
                if (z2 || readLine.indexOf(packageName) < 0) {
                    z = z3;
                    str = str2;
                } else {
                    z = z3;
                    z2 = true;
                    str = str2;
                }
            }
            if (str.length() <= 0 || !z || !z2) {
                str = "";
            }
            try {
                Runtime.getRuntime().exec("logcat -c");
            } catch (Exception e3) {
                try {
                    if (b.c) {
                        Log.e("MobclickAgent", "Failed to clear log in exec(logcat -c)");
                        e3.printStackTrace();
                    }
                } catch (Exception e4) {
                    e2 = e4;
                    if (b.c) {
                        Log.e("MobclickAgent", "Failed to catch error log in catchLogError");
                        e2.printStackTrace();
                    }
                    return str;
                }
            }
        } catch (Exception e5) {
            str = "";
            e2 = e5;
        }
        return str;
    }

    public synchronized void g(Context context) {
        if (this.h == context) {
            this.h = context;
            SharedPreferences m = m(context);
            if (m != null) {
                long j2 = m.getLong("start_millis", -1L);
                if (j2 != -1) {
                    long currentTimeMillis = System.currentTimeMillis();
                    long j3 = currentTimeMillis - j2;
                    long j4 = m.getLong("duration", 0L);
                    SharedPreferences.Editor edit = m.edit();
                    if (b.e) {
                        String string = m.getString("activities", "");
                        String name = context.getClass().getName();
                        if (!"".equals(string)) {
                            string = String.valueOf(string) + ";";
                        }
                        String str = String.valueOf(string) + "[" + name + "," + (j3 / 1000) + "]";
                        edit.remove("activities");
                        edit.putString("activities", str);
                    }
                    edit.putLong("start_millis", -1L);
                    edit.putLong("end_millis", currentTimeMillis);
                    edit.putLong("duration", j3 + j4);
                    edit.commit();
                } else if (b.c) {
                    Log.e("MobclickAgent", "onEndSession called before onStartSession");
                }
            }
        } else if (b.c) {
            Log.e("MobclickAgent", "onPause() called without context from corresponding onResume()");
        }
    }

    public synchronized void h(Context context) {
        String f2 = f(context);
        if (f2 != "" && f2.length() <= 10240) {
            String b2 = b();
            String str = b2.split(" ")[0];
            String str2 = b2.split(" ")[1];
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("type", "error");
                jSONObject.put("context", f2);
                jSONObject.put("date", str);
                jSONObject.put("time", str2);
                jSONObject.put("subtype", "cache_error");
                this.i.post(new t(context, jSONObject));
            } catch (JSONException e2) {
                if (b.c) {
                    Log.i("MobclickAgent", "json error in emitErrorReport");
                    e2.printStackTrace();
                }
            }
        }
    }

    private static JSONObject i(Context context) {
        String str;
        try {
            FileInputStream openFileInput = context.openFileInput(n(context));
            String str2 = "";
            byte[] bArr = new byte[16384];
            while (true) {
                str = str2;
                int read = openFileInput.read(bArr);
                if (read == -1) {
                    break;
                }
                str2 = String.valueOf(str) + new String(bArr, 0, read);
            }
            if (str.length() == 0) {
                return null;
            }
            try {
                return new JSONObject(str);
            } catch (JSONException e2) {
                openFileInput.close();
                j(context);
                e2.printStackTrace();
                return null;
            }
        } catch (FileNotFoundException e3) {
            return null;
        } catch (IOException e4) {
            return null;
        }
    }

    private static void j(Context context) {
        context.deleteFile("mobclick_agent_header_" + context.getPackageName());
        context.deleteFile(n(context));
    }

    private static SharedPreferences k(Context context) {
        return context.getSharedPreferences("mobclick_agent_header_" + context.getPackageName(), 0);
    }

    private static SharedPreferences l(Context context) {
        return context.getSharedPreferences("mobclick_agent_update_" + context.getPackageName(), 0);
    }

    private static SharedPreferences m(Context context) {
        return context.getSharedPreferences("mobclick_agent_state_" + context.getPackageName(), 0);
    }

    private static String n(Context context) {
        return "mobclick_agent_cached_" + context.getPackageName();
    }

    private static SharedPreferences o(Context context) {
        return context.getSharedPreferences("mobclick_agent_online_setting_" + context.getPackageName(), 0);
    }

    private static int p(Context context) {
        SharedPreferences o = o(context);
        return (!o.contains("umeng_net_report_policy") || o.getInt("umeng_net_report_policy", -1) == -1) ? o.getInt("umeng_local_report_policy", g) : o.getInt("umeng_net_report_policy", g);
    }
}