曹妃甸核酸检测平台.apk(点击下载) / LogReport.java


package com.sina.weibo.sdk.statistic;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.sina.weibo.sdk.net.ConnectionFactory;
import com.sina.weibo.sdk.net.NetStateManager;
import com.sina.weibo.sdk.utils.LogUtil;
import com.sina.weibo.sdk.utils.MD5;
import com.sina.weibo.sdk.utils.Utility;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPOutputStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* access modifiers changed from: package-private */
public class LogReport {
    private static final int CONNECTION_TIMEOUT = 25000;
    private static final String PRIVATE_CODE = "dqwef1864il4c9m6";
    private static final int SOCKET_TIMEOUT = 20000;
    private static String UPLOADTIME = "uploadtime";
    private static String mAid = null;
    private static String mAppkey = null;
    private static String mBaseUrl = "https://api.weibo.com/2/proxy/sdk/statistic.json";
    private static String mChannel;
    private static String mKeyHash;
    public static LogReport mLogReport;
    private static String mPackageName;
    private static JSONObject mParams;
    private static String mVersionName;

    public LogReport(Context context) {
        try {
            if (mPackageName == null) {
                mPackageName = context.getPackageName();
            }
            mAppkey = StatisticConfig.getAppkey(context);
            checkAid(context);
            mKeyHash = Utility.getSign(context, mPackageName);
            mVersionName = LogBuilder.getVersion(context);
            mChannel = StatisticConfig.getChannel(context);
        } catch (Exception e2) {
            LogUtil.e(WBAgent.TAG, e2.toString());
        }
        initCommonParams();
    }

    private static void checkAid(Context context) {
        if (TextUtils.isEmpty(mAid)) {
            mAid = Utility.getAid(context, mAppkey);
        }
        if (mParams == null) {
            mParams = new JSONObject();
        }
        try {
            mParams.put("aid", mAid);
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
    }

    public static String getPackageName() {
        return mPackageName;
    }

    private static String getSign(String str, String str2, long j) {
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(str)) {
            sb.append(str);
        }
        sb.append(str2);
        sb.append(PRIVATE_CODE);
        sb.append(j);
        String hexdigest = MD5.hexdigest(sb.toString());
        String substring = hexdigest.substring(hexdigest.length() - 6);
        String hexdigest2 = MD5.hexdigest(substring + substring.substring(0, 4));
        return substring + hexdigest2.substring(hexdigest2.length() + -1);
    }

    public static long getTime(Context context) {
        return context.getSharedPreferences(UPLOADTIME, 0).getLong("lasttime", 0);
    }

    private static byte[] gzipLogs(String str) {
        if (str == null || str.length() == 0) {
            return null;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            byte[] bytes = str.getBytes("utf-8");
            GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
            gZIPOutputStream.write(bytes);
            gZIPOutputStream.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        return byteArrayOutputStream.toByteArray();
    }

    private static JSONObject initCommonParams() {
        if (mParams == null) {
            mParams = new JSONObject();
        }
        try {
            mParams.put("appkey", mAppkey);
            mParams.put(LogBuilder.KEY_PLATFORM, "Android");
            mParams.put("packagename", mPackageName);
            mParams.put("key_hash", mKeyHash);
            mParams.put("version", mVersionName);
            mParams.put("channel", mChannel);
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return mParams;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:41:0x0105, code lost:
        if (r0 != null) goto L_0x0107;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:42:0x0107, code lost:
        r0.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:44:0x010e, code lost:
        if (r0 == null) goto L_0x0111;
     */
    /* JADX WARNING: Removed duplicated region for block: B:48:0x0114 A[SYNTHETIC, Splitter:B:48:0x0114] */
    private static boolean requestHttpExecute(String str, String str2, JSONObject jSONObject, JSONArray jSONArray, Context context) {
        Throwable th;
        UnsupportedEncodingException e2;
        IOException e3;
        if (TextUtils.isEmpty(mAppkey)) {
            LogUtil.e(WBAgent.TAG, "unexpected null AppKey");
            return false;
        }
        ByteArrayOutputStream byteArrayOutputStream = null;
        if (jSONObject == null) {
            try {
                jSONObject = initCommonParams();
            } catch (UnsupportedEncodingException e4) {
                e2 = e4;
            } catch (IOException e5) {
                e3 = e5;
                try {
                    e3.printStackTrace();
                } catch (Throwable th2) {
                    th = th2;
                    if (byteArrayOutputStream != null) {
                    }
                    throw th;
                }
            }
        }
        try {
            jSONObject.put("time", System.currentTimeMillis() / 1000);
            jSONObject.put("length", jSONArray.length());
            jSONObject.put("sign", getSign(jSONObject.getString("aid"), jSONObject.getString("appkey"), jSONObject.getLong("time")));
            jSONObject.put("content", jSONArray);
            LogUtil.d(WBAgent.TAG, "post content--- " + jSONObject.toString());
        } catch (JSONException e6) {
            e6.printStackTrace();
        }
        HttpURLConnection createConnect = ConnectionFactory.createConnect(str + "?" + "source=" + mAppkey, context);
        ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
        try {
            byteArrayOutputStream2.write(StatisticConfig.isNeedGizp() ? gzipLogs(jSONObject.toString()) : jSONObject.toString().getBytes());
            setPost(createConnect);
            createConnect.connect();
            DataOutputStream dataOutputStream = new DataOutputStream(createConnect.getOutputStream());
            dataOutputStream.write(gzipLogs(jSONObject.toString()));
            dataOutputStream.flush();
            dataOutputStream.close();
            int responseCode = createConnect.getResponseCode();
            if (responseCode == 200) {
                createConnect.getResponseMessage();
                try {
                    byteArrayOutputStream2.close();
                } catch (IOException unused) {
                }
                return true;
            }
            LogUtil.i(WBAgent.TAG, "status code = " + responseCode);
            try {
                byteArrayOutputStream2.close();
            } catch (IOException unused2) {
            }
            return false;
        } catch (UnsupportedEncodingException e7) {
            e2 = e7;
            byteArrayOutputStream = byteArrayOutputStream2;
            e2.printStackTrace();
        } catch (IOException e8) {
            e3 = e8;
            byteArrayOutputStream = byteArrayOutputStream2;
            e3.printStackTrace();
        } catch (Throwable th3) {
            th = th3;
            byteArrayOutputStream = byteArrayOutputStream2;
            if (byteArrayOutputStream != null) {
                try {
                    byteArrayOutputStream.close();
                } catch (IOException unused3) {
                }
            }
            throw th;
        }
    }

    public static void setPackageName(String str) {
        mPackageName = str;
    }

    private static void setPost(HttpURLConnection httpURLConnection) {
        try {
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
            httpURLConnection.setRequestProperty("Charset", "UTF-8");
        } catch (Exception unused) {
        }
    }

    private static void updateTime(Context context, Long l) {
        SharedPreferences.Editor edit = context.getSharedPreferences(UPLOADTIME, 0).edit();
        edit.putLong("lasttime", l.longValue());
        edit.commit();
    }

    public static synchronized void uploadAppLogs(Context context, String str) {
        synchronized (LogReport.class) {
            if (mLogReport == null) {
                mLogReport = new LogReport(context);
            }
            if (!NetStateManager.isNetworkConnected(context)) {
                LogUtil.i(WBAgent.TAG, "network is not connected");
                LogFileUtil.writeToFile(LogFileUtil.getAppLogPath(LogFileUtil.ANALYTICS_FILE_NAME), str, true);
                return;
            }
            List<JSONArray> validUploadLogs = LogBuilder.getValidUploadLogs(str);
            if (validUploadLogs == null) {
                LogUtil.i(WBAgent.TAG, "applogs is null");
                return;
            }
            ArrayList<JSONArray> arrayList = new ArrayList();
            checkAid(context);
            for (JSONArray jSONArray : validUploadLogs) {
                if (!requestHttpExecute(mBaseUrl, "POST", mParams, jSONArray, context)) {
                    arrayList.add(jSONArray);
                    LogUtil.e(WBAgent.TAG, "upload applogs error");
                } else {
                    updateTime(context, Long.valueOf(System.currentTimeMillis()));
                }
            }
            LogFileUtil.delete(LogFileUtil.getAppLogPath(LogFileUtil.ANALYTICS_FILE_NAME));
            if (arrayList.size() > 0) {
                for (JSONArray jSONArray2 : arrayList) {
                    LogFileUtil.writeToFile(LogFileUtil.getAppLogPath(LogFileUtil.ANALYTICS_FILE_NAME), jSONArray2.toString(), true);
                    LogUtil.d(WBAgent.TAG, "save failed_log");
                }
            }
        }
    }
}