抖阴.apk(点击下载) / e.java


package com.youdao.sdk.app.other;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import com.alipay.sdk.widget.c;
import com.lzy.okgo.model.HttpHeaders;
import com.youdao.sdk.app.i;
import com.youdao.sdk.app.other.j;
import com.youdao.sdk.ydtranslate.TranslateSdk;
import java.util.ArrayList;
import java.util.Map;
import java.util.Random;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class e {
    private d a;

    /* renamed from: b  reason: collision with root package name */
    private a f7149b;

    /* renamed from: c  reason: collision with root package name */
    private b f7150c = null;

    /* renamed from: d  reason: collision with root package name */
    private j.a f7151d;

    /* renamed from: e  reason: collision with root package name */
    private Context f7152e;

    class a extends Handler {
        a() {
        }

        public void handleMessage(Message message) {
            int a2;
            int i = message.what;
            if (i == 1) {
                if (e.this.a != null && e.this.a.a() >= 16) {
                    e.this.c();
                }
            } else if (i == 2) {
                e.this.c();
            } else if (i == 3) {
                String str = (String) message.obj;
                if (e.this.a != null && (a2 = e.this.a.a()) < 512 && e.this.a.a(str) > 0) {
                    if (a2 >= 16) {
                        e.this.c();
                    } else if (a2 == 0) {
                        removeMessages(2);
                        sendEmptyMessageDelayed(2, 15000);
                    }
                }
            }
        }
    }

    /* access modifiers changed from: package-private */
    public class b implements Runnable {
        Handler t;

        private b() {
            this.t = null;
        }

        public void run() {
            Looper.prepare();
            this.t = new a();
            Looper.loop();
        }
    }

    public e(Context context, String str) {
        SQLiteDatabase sQLiteDatabase;
        if (context != null) {
            this.f7152e = context.getApplicationContext();
            this.f7149b = new a(context);
            try {
                sQLiteDatabase = context.getApplicationContext().openOrCreateDatabase(str, 0, null);
            } catch (SQLiteException unused) {
                sQLiteDatabase = null;
            }
            if (sQLiteDatabase != null) {
                this.a = new d(sQLiteDatabase);
            }
            this.f7151d = new j.a(context.getApplicationContext());
            this.f7150c = new b();
            new Thread(this.f7150c).start();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private synchronized void c() {
        d dVar = this.a;
        if (dVar != null) {
            if (dVar.a() != 0) {
                long b2 = this.a.b();
                StringBuffer stringBuffer = new StringBuffer();
                Cursor a2 = this.a.a(b2);
                try {
                    stringBuffer.append('[');
                    if (a2.moveToFirst()) {
                        stringBuffer.append(a2.getString(0));
                        while (a2.moveToNext()) {
                            stringBuffer.append(',');
                            stringBuffer.append(a2.getString(0));
                        }
                        stringBuffer.append(']');
                        a2.close();
                        if (b(stringBuffer.toString())) {
                            this.a.b(b2);
                        }
                    }
                } catch (Exception unused) {
                } finally {
                    a2.close();
                }
            }
        }
    }

    private boolean b(String str) {
        ClientConnectionManager clientConnectionManager;
        boolean z = false;
        if (str == null || str.length() <= 0 || this.f7152e == null) {
            return false;
        }
        HttpClient defaultHttpClient = new DefaultHttpClient();
        try {
            HttpPost httpPost = new HttpPost(i.c() ? "http://openapi-sg.youdao.com/log" : "http://openapi.youdao.com/log");
            httpPost.addHeader(HttpHeaders.HEAD_KEY_ACCEPT_ENCODING, "gzip");
            ArrayList arrayList = new ArrayList();
            Map<String, String> b2 = this.f7149b.b();
            TranslateSdk translateSdk = new TranslateSdk();
            int nextInt = new Random().nextInt(1000);
            String sign = translateSdk.sign(this.f7152e, i.f7141b, "", String.valueOf(nextInt));
            b2.put("q", "");
            b2.put("salt", String.valueOf(nextInt));
            b2.put("signType", c.B0);
            b2.put("sign", sign);
            b2.put("batchLog", str);
            b2.put("method", "batchLog");
            b2.put("appKey", i.f7141b);
            String[] c2 = com.youdao.sdk.app.b.c(a(b2));
            arrayList.add(new BasicNameValuePair("s", c2[0]));
            arrayList.add(new BasicNameValuePair("et", c2[1]));
            UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(arrayList, "UTF-8");
            httpPost.setHeader(HttpHeaders.HEAD_KEY_CONTENT_TYPE, "application/x-www-form-urlencoded; charset=utf-8");
            httpPost.setEntity(urlEncodedFormEntity);
            this.f7151d.a(defaultHttpClient);
            if (defaultHttpClient.execute(httpPost).getStatusLine().getStatusCode() / 100 == 2) {
                z = true;
            }
            urlEncodedFormEntity.consumeContent();
            try {
                clientConnectionManager = defaultHttpClient.getConnectionManager();
                clientConnectionManager.shutdown();
            } catch (Exception unused) {
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            clientConnectionManager = defaultHttpClient.getConnectionManager();
        } catch (Throwable th) {
            try {
                defaultHttpClient.getConnectionManager().shutdown();
            } catch (Exception unused2) {
            }
            throw th;
        }
        return z;
    }

    /* access modifiers changed from: package-private */
    public String a(Map<String, String> map) {
        StringBuilder sb = new StringBuilder("");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (!TextUtils.isEmpty(value)) {
                sb.append(key);
                sb.append("=");
                sb.append(Uri.encode(value));
                sb.append(e.a.b.i.a.k);
            }
        }
        return sb.toString();
    }

    public boolean a(String str) {
        b bVar;
        Handler handler;
        d dVar = this.a;
        if ((dVar != null ? dVar.a() : 0) >= 512 || (bVar = this.f7150c) == null || (handler = bVar.t) == null) {
            return false;
        }
        return this.f7150c.t.sendMessage(handler.obtainMessage(3, str));
    }

    public void a() {
        this.a.c();
    }

    public void b() {
        Handler handler;
        b bVar = this.f7150c;
        if (bVar != null && (handler = bVar.t) != null) {
            handler.sendEmptyMessage(1);
        }
    }
}