小红书.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 com.xiaomi.mipush.sdk.Constants;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

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

    /* renamed from: c  reason: collision with root package name */
    private volatile boolean f10247c = false;

    /* renamed from: d  reason: collision with root package name */
    private List<String> f10248d = new ArrayList();

    /* renamed from: e  reason: collision with root package name */
    private s f10249e = new s(8192, 5);

    /* renamed from: f  reason: collision with root package name */
    private volatile an f10250f;

    /* renamed from: g  reason: collision with root package name */
    private File f10251g;

    /* renamed from: h  reason: collision with root package name */
    private String f10252h = "wf4_bf";

    /* renamed from: i  reason: collision with root package name */
    private String f10253i = "wf4";

    /* renamed from: j  reason: collision with root package name */
    private StringBuilder f10254j = new StringBuilder(100);

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

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

    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 String b() {
        return "WifiInfoPro";
    }

    public void run() {
        try {
            this.f10247c = true;
            if (this.f10250f != null) {
                this.f10250f.a();
                this.f10250f = null;
            }
            final File file = new File(this.f10251g, this.f10253i);
            if (bu.a()) {
                bu.a("WifiInfoPro", "upload:" + file.getName() + "," + file.length());
            }
            byte[] a14 = bg.a(bn.b(file));
            String str = j.f10265h ? "https://testdatalbs.sparta.html5.qq.com/tr?wf4" : "https://analytics.map.qq.com/?wf4";
            if (!j.f10262e) {
                str = str.replace("https:", "http:");
            }
            j.f10268k.a(str, a14, 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.f10250f = new an(new File(this.f10251g, this.f10253i));
                this.f10250f.a(this);
            }
        } catch (Throwable th3) {
            this.f10247c = false;
            throw th3;
        }
        this.f10247c = false;
    }

    @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:0x00e7  */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x0117 A[RETURN] */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x0118  */
    @Override // c.t.m.g.av
    public void a(Message message) throws Exception {
        if (this.f10251g != null) {
            boolean z14 = false;
            switch (message.what) {
                case 100:
                    this.f10250f = new an(new File(this.f10251g, this.f10253i));
                    this.f10250f.a(this);
                    byte[] b14 = bn.b(new File(this.f10251g, this.f10252h));
                    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(b14)) {
                        cb.a("LocationSDK", "log_fc_wf_bf_create_t_ms", Long.valueOf(currentTimeMillis));
                        bu.a("WifiInfoPro", "bf reset.");
                    } else {
                        this.f10249e.a(b14);
                        bu.a("WifiInfoPro", "bf init.");
                    }
                    a(103, Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL);
                    bn.a(new File(this.f10251g, this.f10252h), this.f10249e.a(), false);
                    a(104, Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL);
                    return;
                case 101:
                    b(this.f10248d);
                    bn.a(new File(this.f10251g, this.f10252h), this.f10249e.a(), false);
                    if (this.f10250f != null) {
                        this.f10250f.a();
                        this.f10250f = 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 a14 = bw.a();
                    if (a14 == bw.a.NETWORK_WIFI || (a14 == bw.a.NETWORK_MOBILE && (j.f10263f || j.f10264g))) {
                        z14 = true;
                    }
                    if (bu.a()) {
                        bu.a("WifiInfoPro", "lastUpT:" + longValue2 + ",deltaT:" + (currentTimeMillis2 - longValue2) + ",network status:" + a14 + ",isUpload:" + z14);
                    }
                    if (!z14) {
                        int i10 = (longValue2 > 0 ? 1 : (longValue2 == 0 ? 0 : -1));
                        if (i10 != 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 (i10 == 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.f10249e.b(scanResult.BSSID)) {
                            this.f10249e.a(scanResult.BSSID);
                            this.f10248d.add(a(scanResult));
                        }
                    }
                    if (bu.a()) {
                        bu.a("WifiInfoPro", "wf list size:" + this.f10248d.size());
                    }
                    if (this.f10248d.size() >= 30) {
                        b(this.f10248d);
                        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 a142 = bw.a();
                    z14 = true;
                    if (bu.a()) {
                    }
                    if (!z14) {
                    }
                    break;
                case 104:
                    bn.a(new File(this.f10251g, this.f10252h), this.f10249e.a(), false);
                    a(104, Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL);
                    return;
                default:
                    return;
            }
        }
    }

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

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