号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0

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


package com.baidu.bottom;

import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.text.TextUtils;
import com.baidu.mobstat.SendStrategyEnum;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.util.Timer;
import java.util.zip.GZIPOutputStream;
import org.apache.http.protocol.HTTP;

public class br {
    private static br a = new br();
    private Timer e;
    private WeakReference<Context> h;
    private Handler i;
    private boolean b = false;
    private SendStrategyEnum c = SendStrategyEnum.APP_START;
    private int d = 1;
    private int f = 0;
    private boolean g = false;

    public static br a() {
        return a;
    }

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

    private void e(Context context) {
        if (context == null) {
            cq.a("initContext context = " + ((Object) null));
        }
        if (this.h == null && context != null) {
            this.h = new WeakReference<>(context);
        }
    }

    public void a(int i) {
        if (i >= 0 && i <= 30) {
            this.f = i;
        }
    }

    public void a(Context context) {
        e(context);
        SendStrategyEnum sendStrategyEnum = SendStrategyEnum.APP_START;
        try {
            String a2 = ct.a(context, "BaiduMobAd_EXCEPTION_LOG");
            if (!TextUtils.isEmpty(a2)) {
                if ("true".equals(a2)) {
                    bm.a().a(context);
                    bd.a().a(context, true);
                } else if ("false".equals(a2)) {
                    bd.a().a(context, false);
                }
            }
        } catch (Exception e) {
            cq.a(e);
        }
        try {
            String a3 = ct.a(context, "BaiduMobAd_SEND_STRATEGY");
            if (!TextUtils.isEmpty(a3)) {
                if (a3.equals(SendStrategyEnum.APP_START.name())) {
                    sendStrategyEnum = SendStrategyEnum.APP_START;
                    bd.a().a(context, sendStrategyEnum.ordinal());
                } else if (a3.equals(SendStrategyEnum.ONCE_A_DAY.name())) {
                    sendStrategyEnum = SendStrategyEnum.ONCE_A_DAY;
                    bd.a().a(context, sendStrategyEnum.ordinal());
                    bd.a().b(context, 24);
                } else if (a3.equals(SendStrategyEnum.SET_TIME_INTERVAL.name())) {
                    sendStrategyEnum = SendStrategyEnum.SET_TIME_INTERVAL;
                    bd.a().a(context, sendStrategyEnum.ordinal());
                }
            }
        } catch (Exception e2) {
            cq.a(e2);
            sendStrategyEnum = sendStrategyEnum;
        }
        try {
            String a4 = ct.a(context, "BaiduMobAd_TIME_INTERVAL");
            if (!TextUtils.isEmpty(a4)) {
                int parseInt = Integer.parseInt(a4);
                if (sendStrategyEnum.ordinal() == SendStrategyEnum.SET_TIME_INTERVAL.ordinal() && parseInt > 0 && parseInt <= 24) {
                    bd.a().b(context, parseInt);
                }
            }
        } catch (Exception e3) {
            cq.a(e3);
        }
        try {
            String a5 = ct.a(context, "BaiduMobAd_ONLY_WIFI");
            if (!TextUtils.isEmpty(a5)) {
                if ("true".equals(a5)) {
                    bd.a().b(context, true);
                } else if ("false".equals(a5)) {
                    bd.a().b(context, false);
                }
            }
        } catch (Exception e4) {
            cq.a(e4);
        }
    }

    public void a(Context context, SendStrategyEnum sendStrategyEnum, int i, boolean z) {
        if (sendStrategyEnum.equals(SendStrategyEnum.SET_TIME_INTERVAL)) {
            if (i > 0 && i <= 24) {
                this.d = i;
                this.c = SendStrategyEnum.SET_TIME_INTERVAL;
                bd.a().a(context, this.c.ordinal());
                bd.a().b(context, this.d);
            } else {
                cq.c("timeInterval is invalid, new strategy does not work");
            }
        } else {
            this.c = sendStrategyEnum;
            bd.a().a(context, this.c.ordinal());
            if (sendStrategyEnum.equals(SendStrategyEnum.ONCE_A_DAY)) {
                bd.a().b(context, 24);
            }
        }
        this.b = z;
        bd.a().b(context, this.b);
        cq.a("sstype is:" + this.c.name() + " And timeInterval is:" + this.d + " And mOnlyWifi:" + this.b);
    }

    public void a(boolean z, Context context) {
        e(context);
        this.g = z;
        cq.a("APP_ANALYSIS_EXCEPTION is:" + this.g);
        bd.a().a(context, this.g);
    }

    public void b(Context context) {
        e(context);
        Context context2 = context == null ? this.h.get() : context;
        if (context2 != null) {
            this.i.post(new bs(this, context2));
        }
    }

    public void c(Context context) {
        bd.a().a(context, System.currentTimeMillis());
    }

    public void d(Context context) {
        Context applicationContext = context.getApplicationContext();
        long j = this.d * 3600000;
        this.e = new Timer();
        this.e.schedule(new bu(this, applicationContext), j, j);
    }

    public void f(Context context) {
        if (!this.b || ct.m(context)) {
            this.i.post(new bv(this, context));
        }
    }

    public boolean b(Context context, String str) {
        boolean z = false;
        if (!this.b || ct.m(context)) {
            try {
                a(context, "https://hmma.baidu.com/app.gif", str);
                z = true;
            } catch (Exception e) {
                cq.c(e);
            }
            cq.a("send log data over. result = " + z + "; data=" + str);
        }
        return z;
    }

    public void a(Context context, String str) {
        if (context != null && !TextUtils.isEmpty(str)) {
            this.i.post(new bw(this, context, str));
        }
    }

    private String a(Context context, String str, String str2) {
        return b(context, str, str2);
    }

    private String b(Context context, String str, String str2) {
        HttpURLConnection d = ck.d(context, str);
        d.setDoOutput(true);
        d.setInstanceFollowRedirects(false);
        d.setUseCaches(false);
        d.setRequestProperty(HTTP.CONTENT_TYPE, "gzip");
        d.connect();
        cq.a("AdUtil.httpPost connected");
        try {
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(d.getOutputStream())));
            bufferedWriter.write(str2);
            bufferedWriter.flush();
            bufferedWriter.close();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(d.getInputStream()));
            StringBuilder sb = new StringBuilder();
            for (String readLine = bufferedReader.readLine(); readLine != null; readLine = bufferedReader.readLine()) {
                sb.append(readLine);
            }
            int contentLength = d.getContentLength();
            if (d.getResponseCode() != 200 || contentLength != 0) {
                throw new IOException("http code = " + d.getResponseCode() + "; contentResponse = " + ((Object) sb));
            }
            return sb.toString();
        } finally {
            d.disconnect();
        }
    }
}