京东到家.apk(点击下载) / h.java


package c.t.m.g;

import android.net.wifi.ScanResult;
import android.os.Looper;
import android.os.Message;
import android.util.Base64;
import c.t.m.g.bw;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import kotlin.text.Typography;

/* compiled from: TML */
public class h extends av implements ao, Runnable {

    /* renamed from: c  reason: collision with root package name */
    private volatile boolean f168c = false;
    private List<String> d = new ArrayList();
    private s e = new s(8192, 5);
    private volatile an f;
    private File g;
    private String h = "wf4_bf";
    private String i = "wf4";
    private StringBuilder j = new StringBuilder(100);

    @Override // c.t.m.g.ay
    public String b() {
        return "WifiInfoPro";
    }

    public h(File file) {
        this.g = file;
        if (bu.a()) {
            bu.a("WifiInfoPro", "data dir:" + this.g.getAbsolutePath());
        }
    }

    public void a(List<ScanResult> list) {
        if (e() && !bz.a((Collection) list)) {
            Message obtainMessage = d().obtainMessage(102);
            obtainMessage.obj = list;
            a(obtainMessage, 0);
        }
    }

    @Override // c.t.m.g.ay
    public int a(Looper looper) {
        a(100, 0);
        return 0;
    }

    @Override // c.t.m.g.ay
    public void a() {
        bq.b(d());
        a(101, 0);
    }

    /* JADX WARNING: Removed duplicated region for block: B:36:0x00e4  */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x0116 A[RETURN] */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x0117  */
    @Override // c.t.m.g.av
    public void a(Message message) throws Exception {
        if (this.g != null) {
            boolean z = false;
            switch (message.what) {
                case 100:
                    this.f = new an(new File(this.g, this.i));
                    this.f.a(this);
                    byte[] b = bn.b(new File(this.g, this.h));
                    long longValue = ((Long) cb.b("LocationSDK", "log_fc_wf_bf_create_t_ms", (Object) 0L)).longValue();
                    long currentTimeMillis = System.currentTimeMillis();
                    if (currentTimeMillis - longValue >= 2592000000L || bz.a(b)) {
                        cb.a("LocationSDK", "log_fc_wf_bf_create_t_ms", Long.valueOf(currentTimeMillis));
                        bu.a("WifiInfoPro", "bf reset.");
                    } else {
                        this.e.a(b);
                        bu.a("WifiInfoPro", "bf init.");
                    }
                    a(103, 300000);
                    bn.a(new File(this.g, this.h), this.e.a(), false);
                    a(104, 300000);
                    return;
                case 101:
                    b(this.d);
                    bn.a(new File(this.g, this.h), this.e.a(), false);
                    if (this.f != null) {
                        this.f.a();
                        this.f = null;
                    }
                    bq.b(d(), 103);
                    if (message.what != 101 && e()) {
                        a(103, 1800000);
                    }
                    long currentTimeMillis2 = System.currentTimeMillis();
                    long longValue2 = ((Long) cb.b("LocationSDK", "log_fc_wf_up_t_ms", (Object) 0L)).longValue();
                    bw.a a = bw.a();
                    if (a == bw.a.NETWORK_WIFI || (a == bw.a.NETWORK_MOBILE && (j.f || j.g))) {
                        z = true;
                    }
                    if (bu.a()) {
                        bu.a("WifiInfoPro", "lastUpT:" + longValue2 + ",deltaT:" + (currentTimeMillis2 - longValue2) + ",network status:" + a + ",isUpload:" + z);
                    }
                    if (!z) {
                        int i2 = (longValue2 > 0 ? 1 : (longValue2 == 0 ? 0 : -1));
                        if (i2 != 0 && currentTimeMillis2 - longValue2 >= 86400000) {
                            bo.a("th_loc_task_t_consume", this);
                            cb.a("LocationSDK", "log_fc_wf_up_t_ms", Long.valueOf(currentTimeMillis2));
                            return;
                        } else if (i2 == 0) {
                            cb.a("LocationSDK", "log_fc_wf_up_t_ms", Long.valueOf(currentTimeMillis2));
                            return;
                        } else {
                            return;
                        }
                    } else {
                        return;
                    }
                case 102:
                    for (ScanResult scanResult : (List) message.obj) {
                        if (!this.e.b(scanResult.BSSID)) {
                            this.e.a(scanResult.BSSID);
                            this.d.add(a(scanResult));
                        }
                    }
                    if (bu.a()) {
                        bu.a("WifiInfoPro", "wf list size:" + this.d.size());
                    }
                    if (this.d.size() >= 30) {
                        b(this.d);
                        return;
                    }
                    return;
                case 103:
                    bq.b(d(), 103);
                    a(103, 1800000);
                    long currentTimeMillis22 = System.currentTimeMillis();
                    long longValue22 = ((Long) cb.b("LocationSDK", "log_fc_wf_up_t_ms", (Object) 0L)).longValue();
                    bw.a a2 = bw.a();
                    z = true;
                    if (bu.a()) {
                    }
                    if (!z) {
                    }
                    break;
                case 104:
                    bn.a(new File(this.g, this.h), this.e.a(), false);
                    a(104, 300000);
                    return;
                default:
                    return;
            }
        }
    }

    private void b(List<String> list) throws IOException {
        if (!(this.f168c || bz.a((Collection) list) || bz.a(this.f))) {
            long length = this.f.b().length();
            if (bu.a()) {
                bu.a("WifiInfoPro", "wf file len:" + length);
            }
            if (length <= 51200) {
                StringBuilder sb = new StringBuilder(500);
                sb.append("1|");
                sb.append(list.size());
                for (String str : list) {
                    sb.append('|');
                    sb.append(str);
                }
                this.f.a(sb.toString());
            }
            list.clear();
        }
    }

    private String a(ScanResult scanResult) {
        this.j.setLength(0);
        try {
            StringBuilder sb = this.j;
            sb.append(scanResult.BSSID);
            sb.append(',');
            StringBuilder sb2 = this.j;
            sb2.append(Base64.encodeToString(scanResult.SSID.getBytes("UTF-8"), 2));
            sb2.append(',');
            StringBuilder sb3 = this.j;
            sb3.append(scanResult.frequency);
            sb3.append(',');
            this.j.append(Base64.encodeToString(scanResult.capabilities.getBytes("UTF-8"), 2));
        } catch (Throwable unused) {
            this.j.setLength(0);
        }
        return this.j.toString();
    }

    @Override // c.t.m.g.ao
    public byte[] a(byte[] bArr) {
        byte[] a = bk.a(bg.a(bArr), bk.a("fc_wf_up"));
        if (!bz.a(a)) {
            byte[] encode = Base64.encode(a, 2);
            if (!bz.a(encode)) {
                String str = new String(encode);
                try {
                    return (str + Typography.dollar).getBytes("UTF-8");
                } catch (Throwable unused) {
                }
            }
        }
        return new byte[0];
    }

    public void run() {
        try {
            this.f168c = true;
            if (this.f != null) {
                this.f.a();
                this.f = null;
            }
            final File file = new File(this.g, this.i);
            if (bu.a()) {
                bu.a("WifiInfoPro", "upload:" + file.getName() + "," + file.length());
            }
            byte[] a = bg.a(bn.b(file));
            String str = j.h ? "https://testdatalbs.sparta.html5.qq.com/tr?wf4" : "https://analytics.map.qq.com/?wf4";
            if (!j.e) {
                str = str.replace("https:", "http:");
            }
            j.k.a(str, a, new ap() {
                /* class c.t.m.g.h.AnonymousClass1 */

                @Override // c.t.m.g.ap
                public void a(String str) {
                    file.delete();
                    if (bu.a()) {
                        bu.a("WifiInfoPro", "upload suc & del:" + str);
                    }
                }

                @Override // c.t.m.g.ap
                public void b(String str) {
                    if (bu.a()) {
                        bu.a("WifiInfoPro", "upload failed:" + str);
                    }
                }
            });
            if (e()) {
                this.f = new an(new File(this.g, this.i));
                this.f.a(this);
            }
        } catch (Throwable th) {
            this.f168c = false;
            throw th;
        }
        this.f168c = false;
    }
}