APKPure.apk(点击下载) / h.java


package e.g.a.h0.a;

import android.text.TextUtils;
import androidx.recyclerview.widget.RecyclerView;
import androidx.work.WorkRequest;
import com.apkpure.aegon.application.AegonApplication;
import com.apkpure.aegon.application.RealApplicationLike;
import com.apkpure.aegon.statistics.beacon.BeaconReportConfig;
import com.google.android.gms.common.internal.ImagesContract;
import com.tencent.beacon.base.net.BResponse;
import com.tencent.beacon.base.net.RequestType;
import com.tencent.beacon.base.net.adapter.AbstractNetAdapter;
import com.tencent.beacon.base.net.call.Callback;
import com.tencent.beacon.base.net.call.JceRequestEntity;
import com.tencent.beacon.base.net.call.e;
import com.tencent.beacon.base.net.d;
import com.tencent.beacon.e.g;
import com.tencent.beacon.pack.EventRecordV2;
import com.tencent.beacon.pack.RequestPackageV2;
import com.tencent.beacon.pack.ResponsePackageV2;
import com.tencent.beacon.pack.b;
import e.g.a.e.f.d2;
import e.g.a.e.f.i;
import e.g.a.h0.b.j;
import e.g.a.i0.f2.a;
import e.g.a.i0.q0;
import e.g.a.i0.y;
import i.i.g.c;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.json.JSONObject;

public class h extends AbstractNetAdapter {
    public static final Long b = 1L;
    public static final Long c = 100L;
    public static final Long d = 100L;

    /* renamed from: e  reason: collision with root package name */
    public static final Long f5973e = Long.valueOf((long) WorkRequest.MIN_BACKOFF_MILLIS);

    /* renamed from: f  reason: collision with root package name */
    public static final byte[] f5974f = {31, -117, 8, 0, 0, 0, 0, 0, 2, -1, 99, 100, 56, 33, -58, 103, 104, 104, -87, 103, 104, 98, -82, 103, 104, -96, 103, 100, 98, -84, -52, -64, -64, 88, -5, 90, 100, -50, 59, 51, -10, -30, -46, -28, -28, -44, -30, 98, 0, -72, -59, 109, 68, 37, 0, 0, 0};

    /* renamed from: g  reason: collision with root package name */
    public static String f5975g;

    /* renamed from: h  reason: collision with root package name */
    public static String f5976h = "first_open;AppClickToDownload;AppStartDownload;AppContinueDownload;AppSuccDownload;AppDownloadConnectionSucc;AppFailDownload;AppPauseDownload;AppClickToInstall;AppStartInstall;AppCancelInstall;AppFailInstall;AppSuccInstall;AppOnlineExhibit;AppOnlineVastEvents";

    /* renamed from: i  reason: collision with root package name */
    public static ArrayList<String> f5977i = new ArrayList<>();

    /* renamed from: j  reason: collision with root package name */
    public static boolean f5978j;

    /* renamed from: k  reason: collision with root package name */
    public static boolean f5979k;

    /* renamed from: l  reason: collision with root package name */
    public static String f5980l = f();

    /* renamed from: m  reason: collision with root package name */
    public static final Set<String> f5981m = Collections.synchronizedSet(new HashSet());

    /* renamed from: n  reason: collision with root package name */
    public static final Set<String> f5982n = Collections.synchronizedSet(new HashSet());

    /* renamed from: a  reason: collision with root package name */
    public ResponsePackageV2 f5983a;

    public h() {
        i();
        if (TextUtils.isEmpty(f5975g)) {
            f5975g = "https://r.apkpure.net/appReport?pro=1";
        }
        f5975g = f5975g;
        int i2 = AegonApplication.f1165e;
        d2 f2 = d2.f(RealApplicationLike.getContext());
        e eVar = new e(this);
        Objects.requireNonNull(f2);
        a.d().post(new i(f2, eVar));
    }

    public static BResponse a(String str, String str2, Map<String, String> map, byte[] bArr, boolean z) throws IOException {
        IOException e2;
        Throwable th;
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        httpURLConnection.setConnectTimeout(AbstractNetAdapter.CONNECT_TIMEOUT);
        httpURLConnection.setReadTimeout(AbstractNetAdapter.READ_TIMEOUT);
        httpURLConnection.setRequestMethod(str2);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setDoInput(true);
        for (Map.Entry<String, String> entry : map.entrySet()) {
            httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
        }
        httpURLConnection.setInstanceFollowRedirects(z);
        httpURLConnection.connect();
        q0.a("BeaconHttpAdapter", "url: " + str + " openFollowRedirects: " + z);
        OutputStream outputStream = httpURLConnection.getOutputStream();
        if (!(outputStream == null || bArr == null)) {
            outputStream.write(bArr);
            outputStream.close();
        }
        int responseCode = httpURLConnection.getResponseCode();
        String responseMessage = httpURLConnection.getResponseMessage();
        InputStream inputStream = httpURLConnection.getInputStream();
        ByteArrayOutputStream byteArrayOutputStream = null;
        try {
            ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
            try {
                byte[] bArr2 = new byte[RecyclerView.a0.FLAG_MOVED];
                while (true) {
                    int read = inputStream.read(bArr2);
                    if (read != -1) {
                        byteArrayOutputStream2.write(bArr2, 0, read);
                    } else {
                        byteArrayOutputStream2.flush();
                        byte[] byteArray = byteArrayOutputStream2.toByteArray();
                        byteArrayOutputStream2.close();
                        inputStream.close();
                        byteArrayOutputStream2.close();
                        inputStream.close();
                        return new BResponse(httpURLConnection.getHeaderFields(), responseCode, responseMessage, byteArray);
                    }
                }
            } catch (IOException e3) {
                e2 = e3;
                byteArrayOutputStream = byteArrayOutputStream2;
                byteArrayOutputStream.close();
                inputStream.close();
                throw e2;
            } catch (Throwable th2) {
                th = th2;
                byteArrayOutputStream = byteArrayOutputStream2;
                byteArrayOutputStream.close();
                inputStream.close();
                throw th;
            }
        } catch (IOException e4) {
            e2 = e4;
            byteArrayOutputStream.close();
            inputStream.close();
            throw e2;
        } catch (Throwable th3) {
            th = th3;
            byteArrayOutputStream.close();
            inputStream.close();
            throw th;
        }
    }

    public static String f() {
        int i2 = AegonApplication.f1165e;
        String F = c.F(RealApplicationLike.getApplication(), "report_beacon_type");
        return TextUtils.isEmpty(F) ? "3" : F;
    }

    public static synchronized void i() {
        synchronized (h.class) {
            f5979k = j.c("logReportSampleBeacon", c.longValue(), d.longValue());
            f5978j = j.c("logReportSampleEs", b.longValue(), f5973e.longValue());
            f5980l = f();
            int i2 = AegonApplication.f1165e;
            String F = c.F(RealApplicationLike.getContext(), "needReportKey");
            if (!TextUtils.isEmpty(F)) {
                f5976h = F;
            }
            String[] split = f5976h.split(";");
            f5977i.clear();
            for (String str : split) {
                f5977i.add(str);
            }
            for (int i3 = 1; i3 <= 4; i3++) {
                f5977i.add("DownloadDetailError" + i3);
            }
            f5977i.add("StartAppCost1");
            q0.a("BeaconHttpAdapter", "updateNeedReport:" + f5977i.toString() + ",needReportBeacon:" + f5979k + ",reportType:" + f5980l + ",needReportEs:" + f5978j);
        }
    }

    public final BResponse b(JceRequestEntity jceRequestEntity, boolean z) throws IOException {
        BResponse bResponse = null;
        if (!f5979k) {
            return null;
        }
        String url = jceRequestEntity.getUrl();
        if (!Objects.equals(jceRequestEntity.getDomain(), BeaconReportConfig.getUploadHost())) {
            url = BeaconReportConfig.getRequestUrlReplacedHost(jceRequestEntity);
        } else if (z) {
            if (url.contains("svibeacon.onezapp.com")) {
                url = url.replace("svibeacon.onezapp.com", "report.apkpure.net");
            } else if (url.contains("report.apkpure.net")) {
                url = url.replace("report.apkpure.net", "svibeacon.onezapp.com");
            }
        }
        try {
            bResponse = a(url, "POST", jceRequestEntity.getHeader(), jceRequestEntity.getContent(), false);
            Set<String> set = f5981m;
            if (!set.contains(url)) {
                set.add(url);
                g(url, bResponse.code + "_" + bResponse.msg);
            }
            if (bResponse.code != 200 && !z) {
                return b(jceRequestEntity, true);
            }
        } catch (Throwable th) {
            String message = th.getMessage();
            Set<String> set2 = f5982n;
            if (!set2.contains(message)) {
                set2.add(message);
                g(url, message);
            }
            if (!z) {
                return b(jceRequestEntity, true);
            }
        }
        return bResponse;
    }

    public final BResponse c(JceRequestEntity jceRequestEntity) throws IOException {
        RequestPackageV2 requestPackageV2;
        jceRequestEntity.getHeader().put("Content-Type", "application/octet-stream; charset=UTF-8");
        if (f5978j || j.b()) {
            return a(f5975g, "POST", jceRequestEntity.getHeader(), jceRequestEntity.getContent(), false);
        }
        if (jceRequestEntity.getType() != RequestType.EVENT) {
            return null;
        }
        System.currentTimeMillis();
        byte[] content = jceRequestEntity.getContent();
        if (content == null) {
            requestPackageV2 = null;
        } else {
            byte[] h2 = h(content);
            requestPackageV2 = new RequestPackageV2();
            requestPackageV2.readFrom(new com.tencent.beacon.pack.a(h2));
        }
        ArrayList arrayList = new ArrayList();
        Iterator<EventRecordV2> it = requestPackageV2.events.iterator();
        while (it.hasNext()) {
            EventRecordV2 next = it.next();
            if (f5977i.contains(next.eventCode) || (!TextUtils.isEmpty(next.eventCode) && next.eventCode.startsWith("first_open"))) {
                arrayList.add(next);
            }
        }
        if (arrayList.isEmpty()) {
            return null;
        }
        requestPackageV2.events.clear();
        requestPackageV2.events.addAll(arrayList);
        b bVar = new b();
        requestPackageV2.writeTo(bVar);
        return a(f5975g, "POST", jceRequestEntity.getHeader(), d(bVar.b()), false);
    }

    public final byte[] d(byte[] bArr) {
        g b2 = g.b();
        return b2 != null ? com.tencent.beacon.e.b.a().j() ? com.tencent.beacon.base.util.b.b(bArr, 2, 3, b2.a()) : com.tencent.beacon.base.util.b.b(bArr, 2) : bArr;
    }

    public final ResponsePackageV2 e() {
        if (this.f5983a == null) {
            byte[] h2 = h(f5974f);
            ResponsePackageV2 responsePackageV2 = new ResponsePackageV2();
            responsePackageV2.readFrom(new com.tencent.beacon.pack.a(h2));
            this.f5983a = responsePackageV2;
        }
        return this.f5983a;
    }

    public final void g(String str, String str2) {
        HashMap j0 = e.d.a.a.a.j0("return_code", str2, ImagesContract.URL, str);
        y yVar = y.f6585a;
        o.s.c.j.e("deviceCountry", "name");
        j0.put("status", y.d.get("deviceCountry"));
        e.g.a.h0.b.h.p("AppReportResult", j0);
    }

    public final byte[] h(byte[] bArr) {
        return com.tencent.beacon.e.b.a().j() ? com.tencent.beacon.base.util.b.a(bArr, 2, 3, g.b().a()) : com.tencent.beacon.base.util.b.a(bArr, 2);
    }

    @Override // com.tencent.beacon.base.net.adapter.AbstractNetAdapter
    public void request(JceRequestEntity jceRequestEntity, Callback<byte[]> callback) {
        if (jceRequestEntity == null) {
            q0.a("BeaconHttpAdapter", "requestInner return, entity == null");
            return;
        }
        BResponse bResponse = null;
        try {
            String str = f5980l;
            char c2 = 65535;
            int hashCode = str.hashCode();
            if (hashCode != 48) {
                if (hashCode != 50) {
                    if (hashCode == 51) {
                        if (str.equals("3")) {
                            c2 = 2;
                        }
                    }
                } else if (str.equals("2")) {
                    c2 = 1;
                }
            } else if (str.equals("0")) {
                c2 = 0;
            }
            if (c2 == 0) {
                q0.a("BeaconHttpAdapter", "requestInner return, type = REPORT_BEACON_TYPE_NONE");
            } else if (c2 == 1) {
                bResponse = b(jceRequestEntity, false);
            } else if (c2 != 2) {
                BResponse c3 = c(jceRequestEntity);
                if (c3 != null) {
                    JSONObject jSONObject = new JSONObject(new String(c3.body, Charset.defaultCharset()));
                    ResponsePackageV2 e2 = e();
                    e2.serverTime = jSONObject.optLong("serverTime", System.currentTimeMillis());
                    b bVar = new b();
                    e2.writeTo(bVar);
                    c3.body = d(bVar.b());
                    bResponse = c3;
                }
            } else {
                bResponse = b(jceRequestEntity, false);
                c(jceRequestEntity);
            }
            q0.a("BeaconHttpAdapter", "requestInner response = " + bResponse + ", type = " + f5980l + ", requestUrl = " + f5975g + ", entity.getUrl() = " + jceRequestEntity.getUrl() + ", entity.getHeader() = " + jceRequestEntity.getHeader());
            if (bResponse != null) {
                callback.onResponse(bResponse.body);
                return;
            }
            ResponsePackageV2 e3 = e();
            e3.serverTime = System.currentTimeMillis();
            b bVar2 = new b();
            e3.writeTo(bVar2);
            callback.onResponse(d(bVar2.b()));
        } catch (Throwable th) {
            StringBuilder Z = e.d.a.a.a.Z("https other error: ");
            Z.append(th.getMessage());
            callback.onFailure(new d("BeaconHttpAdapter", "499", -1, Z.toString(), th));
        }
    }

    @Override // com.tencent.beacon.base.net.adapter.AbstractNetAdapter
    public void request(e eVar, Callback<BResponse> callback) {
    }
}