MD5 校验值:facd8e3913e14e36e7daf9e69fbd45cb
HTTPClient.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.revenuecat.purchases.common; import D2.u; import android.os.Build; import com.google.firebase.crashlytics.internal.metadata.UserMetadata; import com.revenuecat.purchases.Store; import com.revenuecat.purchases.VerificationResult; import com.revenuecat.purchases.common.diagnostics.DiagnosticsTracker; import com.revenuecat.purchases.common.networking.ETagManager; import com.revenuecat.purchases.common.networking.Endpoint; import com.revenuecat.purchases.common.networking.HTTPRequest; import com.revenuecat.purchases.common.networking.HTTPResult; import com.revenuecat.purchases.common.networking.MapConverter; import com.revenuecat.purchases.common.networking.RCHTTPStatusCodes; import com.revenuecat.purchases.common.verification.SignatureVerificationException; import com.revenuecat.purchases.common.verification.SignatureVerificationMode; import com.revenuecat.purchases.common.verification.SigningManager; import com.revenuecat.purchases.interfaces.StorefrontProvider; import com.revenuecat.purchases.strings.NetworkStrings; import com.revenuecat.purchases.utils.MapExtensionsKt; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.StringWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; import k2.C0329h; import kotlin.jvm.internal.f; import kotlin.jvm.internal.k; import l2.y; import org.json.JSONObject; public final class HTTPClient { public static final Companion Companion = new Companion(null); public static final int NO_STATUS_CODE = -1; private final AppConfig appConfig; private final DateProvider dateProvider; private final DiagnosticsTracker diagnosticsTrackerIfEnabled; private final ETagManager eTagManager; private final MapConverter mapConverter; private final SigningManager signingManager; private final StorefrontProvider storefrontProvider; public static final class Companion { private Companion() { } public Companion(f fVar) { this(); } } public class WhenMappings { public static final int[] $EnumSwitchMapping$0; static { int[] iArr = new int[Store.values().length]; try { iArr[Store.AMAZON.ordinal()] = 1; } catch (NoSuchFieldError unused) { } $EnumSwitchMapping$0 = iArr; } } public HTTPClient(AppConfig appConfig, ETagManager eTagManager, DiagnosticsTracker diagnosticsTracker, SigningManager signingManager, StorefrontProvider storefrontProvider, DateProvider dateProvider, MapConverter mapConverter) { k.e(appConfig, "appConfig"); k.e(eTagManager, "eTagManager"); k.e(signingManager, "signingManager"); k.e(storefrontProvider, "storefrontProvider"); k.e(dateProvider, "dateProvider"); k.e(mapConverter, "mapConverter"); this.appConfig = appConfig; this.eTagManager = eTagManager; this.diagnosticsTrackerIfEnabled = diagnosticsTracker; this.signingManager = signingManager; this.storefrontProvider = storefrontProvider; this.dateProvider = dateProvider; this.mapConverter = mapConverter; } public HTTPClient(AppConfig appConfig, ETagManager eTagManager, DiagnosticsTracker diagnosticsTracker, SigningManager signingManager, StorefrontProvider storefrontProvider, DateProvider dateProvider, MapConverter mapConverter, int i, f fVar) { this(appConfig, eTagManager, diagnosticsTracker, signingManager, storefrontProvider, (i & 32) != 0 ? new DefaultDateProvider() : dateProvider, (i & 64) != 0 ? new MapConverter() : mapConverter); } private final BufferedReader buffer(InputStream inputStream) { return new BufferedReader(new InputStreamReader(inputStream)); } private final BufferedWriter buffer(OutputStream outputStream) { return new BufferedWriter(new OutputStreamWriter(outputStream)); } private final HttpURLConnection getConnection(HTTPRequest hTTPRequest) { URLConnection openConnection = hTTPRequest.getFullURL().openConnection(); k.c(openConnection, "null cannot be cast to non-null type java.net.HttpURLConnection"); HttpURLConnection httpURLConnection = (HttpURLConnection) openConnection; for (Map.Entry<String, String> entry : hTTPRequest.getHeaders().entrySet()) { httpURLConnection.addRequestProperty(entry.getKey(), entry.getValue()); } JSONObject body = hTTPRequest.getBody(); if (body != null) { httpURLConnection.setDoOutput(true); httpURLConnection.setRequestMethod("POST"); OutputStream os = httpURLConnection.getOutputStream(); k.d(os, "os"); BufferedWriter buffer = buffer(os); String jSONObject = body.toString(); k.d(jSONObject, "body.toString()"); writeFully(buffer, jSONObject); } return httpURLConnection; } private final String getETagHeader(URLConnection uRLConnection) { return uRLConnection.getHeaderField("X-RevenueCat-ETag"); } private final Map<String, String> getHeaders(Map<String, String> map, String str, boolean z3, String str2, boolean z4, String str3) { return MapExtensionsKt.filterNotNullValues(y.x0(y.x0(y.v0(new C0329h("Content-Type", "application/json"), new C0329h("X-Platform", getXPlatformHeader()), new C0329h("X-Platform-Flavor", this.appConfig.getPlatformInfo().getFlavor()), new C0329h("X-Platform-Flavor-Version", this.appConfig.getPlatformInfo().getVersion()), new C0329h("X-Platform-Version", String.valueOf(Build.VERSION.SDK_INT)), new C0329h("X-Version", "7.2.5"), new C0329h("X-Client-Locale", this.appConfig.getLanguageTag()), new C0329h("X-Client-Version", this.appConfig.getVersionName()), new C0329h("X-Client-Bundle-ID", this.appConfig.getPackageName()), new C0329h("X-Observer-Mode-Enabled", this.appConfig.getFinishTransactions() ? "false" : "true"), new C0329h("X-Nonce", str2), new C0329h(HTTPRequest.POST_PARAMS_HASH, str3), new C0329h("X-Custom-Entitlements-Computation", this.appConfig.getCustomEntitlementComputation() ? "true" : null), new C0329h("X-Storefront", this.storefrontProvider.getStorefront())), map), this.eTagManager.getETagHeaders$purchases_defaultsRelease(str, z4, z3))); } private final InputStream getInputStream(HttpURLConnection httpURLConnection) { try { return httpURLConnection.getInputStream(); } catch (Exception e) { if (!(e instanceof IllegalArgumentException ? true : e instanceof IOException)) { throw e; } LogWrapperKt.log(LogIntent.WARNING, String.format(NetworkStrings.PROBLEM_CONNECTING, Arrays.copyOf(new Object[]{e.getMessage()}, 1))); return httpURLConnection.getErrorStream(); } } private final Date getRequestDateHeader(URLConnection uRLConnection) { String requestTimeHeader = getRequestTimeHeader(uRLConnection); if (requestTimeHeader != null) { return new Date(Long.parseLong(requestTimeHeader)); } return null; } private final String getRequestTimeHeader(URLConnection uRLConnection) { String headerField = uRLConnection.getHeaderField(HTTPResult.REQUEST_TIME_HEADER_NAME); if (headerField == null || !(!u.M(headerField))) { return null; } return headerField; } private final String getXPlatformHeader() { return WhenMappings.$EnumSwitchMapping$0[this.appConfig.getStore().ordinal()] == 1 ? "amazon" : "android"; } private final HTTPResult performCall(URL url, Endpoint endpoint, Map<String, ? extends Object> map, List<C0329h> list, Map<String, String> map2, boolean z3) { String str; HttpURLConnection connection; InputStream inputStream; String readFully; JSONObject convertToJSON$purchases_defaultsRelease = map != null ? this.mapConverter.convertToJSON$purchases_defaultsRelease(map) : null; String path = endpoint.getPath(); String e = com.google.android.gms.internal.play_billing.a.e("/v1", path); boolean shouldVerifyEndpoint = this.signingManager.shouldVerifyEndpoint(endpoint); boolean z4 = shouldVerifyEndpoint && endpoint.getNeedsNonceToPerformSigning(); try { URL url2 = new URL(url, e); String createRandomNonce = z4 ? this.signingManager.createRandomNonce() : null; try { if (list != null) { if ((shouldVerifyEndpoint ? list : null) != null) { str = this.signingManager.getPostParamsForSigningHeaderIfNeeded(endpoint, list); connection = getConnection(new HTTPRequest(url2, getHeaders(map2, e, z3, createRandomNonce, shouldVerifyEndpoint, str), convertToJSON$purchases_defaultsRelease)); inputStream = getInputStream(connection); LogUtilsKt.debugLog(String.format(NetworkStrings.API_REQUEST_STARTED, Arrays.copyOf(new Object[]{connection.getRequestMethod(), path}, 2))); int responseCode = connection.getResponseCode(); readFully = inputStream == null ? readFully(inputStream) : null; if (inputStream != null) { inputStream.close(); } connection.disconnect(); LogUtilsKt.debugLog(String.format(NetworkStrings.API_REQUEST_COMPLETED, Arrays.copyOf(new Object[]{connection.getRequestMethod(), path, Integer.valueOf(responseCode)}, 3))); if (readFully != null) { throw new IOException(NetworkStrings.HTTP_RESPONSE_PAYLOAD_NULL); } VerificationResult verifyResponse = (shouldVerifyEndpoint && RCHTTPStatusCodes.INSTANCE.isSuccessful(responseCode)) ? verifyResponse(e, connection, readFully, createRandomNonce, str) : VerificationResult.NOT_REQUESTED; if (verifyResponse == VerificationResult.FAILED && (this.signingManager.getSignatureVerificationMode() instanceof SignatureVerificationMode.Enforced)) { throw new SignatureVerificationException(path); } return this.eTagManager.getHTTPResultFromCacheOrBackend$purchases_defaultsRelease(responseCode, readFully, getETagHeader(connection), e, z3, getRequestDateHeader(connection), verifyResponse); } } LogUtilsKt.debugLog(String.format(NetworkStrings.API_REQUEST_STARTED, Arrays.copyOf(new Object[]{connection.getRequestMethod(), path}, 2))); int responseCode2 = connection.getResponseCode(); if (inputStream == null) { } if (inputStream != null) { } connection.disconnect(); LogUtilsKt.debugLog(String.format(NetworkStrings.API_REQUEST_COMPLETED, Arrays.copyOf(new Object[]{connection.getRequestMethod(), path, Integer.valueOf(responseCode2)}, 3))); if (readFully != null) { } } catch (Throwable th) { if (inputStream != null) { inputStream.close(); } connection.disconnect(); throw th; } str = null; connection = getConnection(new HTTPRequest(url2, getHeaders(map2, e, z3, createRandomNonce, shouldVerifyEndpoint, str), convertToJSON$purchases_defaultsRelease)); inputStream = getInputStream(connection); } catch (MalformedURLException e4) { throw new RuntimeException(e4); } } public static HTTPResult performRequest$default(HTTPClient hTTPClient, URL url, Endpoint endpoint, Map map, List list, Map map2, boolean z3, int i, Object obj) { if ((i & 32) != 0) { z3 = false; } return hTTPClient.performRequest(url, endpoint, map, list, map2, z3); } private final String readFully(InputStream inputStream) { BufferedReader buffer = buffer(inputStream); k.e(buffer, "<this>"); StringWriter stringWriter = new StringWriter(); char[] cArr = new char[UserMetadata.MAX_INTERNAL_KEY_SIZE]; for (int read = buffer.read(cArr); read >= 0; read = buffer.read(cArr)) { stringWriter.write(cArr, 0, read); } String stringWriter2 = stringWriter.toString(); k.d(stringWriter2, "buffer.toString()"); return stringWriter2; } private final void trackHttpRequestPerformedIfNeeded(Endpoint endpoint, Date date, boolean z3, HTTPResult hTTPResult) { VerificationResult verificationResult; DiagnosticsTracker diagnosticsTracker = this.diagnosticsTrackerIfEnabled; if (diagnosticsTracker != null) { long between = DurationExtensionsKt.between(E2.b.Companion, date, this.dateProvider.getNow()); int responseCode = z3 ? hTTPResult != null ? hTTPResult.getResponseCode() : RCHTTPStatusCodes.NOT_MODIFIED : -1; HTTPResult.Origin origin = hTTPResult != null ? hTTPResult.getOrigin() : null; if (hTTPResult == null || (verificationResult = hTTPResult.getVerificationResult()) == null) { verificationResult = VerificationResult.NOT_REQUESTED; } diagnosticsTracker.m57trackHttpRequestPerformedNcHsxvU(endpoint, between, z3 && RCHTTPStatusCodes.INSTANCE.isSuccessful(responseCode), responseCode, origin, verificationResult); } } private final VerificationResult verifyResponse(String str, URLConnection uRLConnection, String str2, String str3, String str4) { return this.signingManager.verifyResponse(str, uRLConnection.getHeaderField(HTTPResult.SIGNATURE_HEADER_NAME), str3, str2, getRequestTimeHeader(uRLConnection), getETagHeader(uRLConnection), str4); } private final void writeFully(BufferedWriter bufferedWriter, String str) { bufferedWriter.write(str); bufferedWriter.flush(); } public final void clearCaches() { this.eTagManager.clearCaches$purchases_defaultsRelease(); } public final SigningManager getSigningManager() { return this.signingManager; } public final HTTPResult performRequest(URL baseURL, Endpoint endpoint, Map<String, ? extends Object> map, List<C0329h> list, Map<String, String> requestHeaders, boolean z3) { k.e(baseURL, "baseURL"); k.e(endpoint, "endpoint"); k.e(requestHeaders, "requestHeaders"); if (this.appConfig.getForceServerErrors()) { LogUtilsKt.warnLog("Forcing server error for request to " + endpoint.getPath()); return new HTTPResult(500, "", HTTPResult.Origin.BACKEND, null, VerificationResult.NOT_REQUESTED); } Date now = this.dateProvider.getNow(); try { HTTPResult performCall = performCall(baseURL, endpoint, map, list, requestHeaders, z3); trackHttpRequestPerformedIfNeeded(endpoint, now, true, performCall); if (performCall != null) { return performCall; } LogWrapperKt.log(LogIntent.WARNING, NetworkStrings.ETAG_RETRYING_CALL); return performRequest(baseURL, endpoint, map, list, requestHeaders, true); } catch (Throwable th) { trackHttpRequestPerformedIfNeeded(endpoint, now, false, null); throw th; } } }