Files
rr3-apk/decompiled-community/sources/com/google/firebase/remoteconfig/internal/ConfigFetchHttpClient.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

272 lines
12 KiB
Java

package com.google.firebase.remoteconfig.internal;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import androidx.annotation.Keep;
import androidx.core.content.pm.PackageInfoCompat;
import com.ea.nimble.ApplicationEnvironment;
import com.google.android.gms.common.util.AndroidUtilsLight;
import com.google.android.gms.common.util.Hex;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException;
import com.google.firebase.remoteconfig.internal.ConfigContainer;
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
import com.ironsource.nb;
import com.ironsource.v8;
import com.mbridge.msdk.foundation.download.Command;
import com.unity3d.ads.core.domain.HandleInvocationsFromAdViewer;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes3.dex */
public class ConfigFetchHttpClient {
public static final Pattern GMP_APP_ID_PATTERN = Pattern.compile("^[^:]+:([0-9]+):(android|ios|web):([0-9a-f]+)");
public final String apiKey;
public final String appId;
public final long connectTimeoutInSeconds;
public final Context context;
public final String namespace;
public final String projectNumber;
public final long readTimeoutInSeconds;
public ConfigFetchHttpClient(Context context, String str, String str2, String str3, long j, long j2) {
this.context = context;
this.appId = str;
this.apiKey = str2;
this.projectNumber = extractProjectNumberFromAppId(str);
this.namespace = str3;
this.connectTimeoutInSeconds = j;
this.readTimeoutInSeconds = j2;
}
public static String extractProjectNumberFromAppId(String str) {
Matcher matcher = GMP_APP_ID_PATTERN.matcher(str);
if (matcher.matches()) {
return matcher.group(1);
}
return null;
}
public HttpURLConnection createHttpURLConnection() {
try {
return (HttpURLConnection) new URL(getFetchUrl(this.projectNumber, this.namespace)).openConnection();
} catch (IOException e) {
throw new FirebaseRemoteConfigException(e.getMessage());
}
}
@Keep
public ConfigFetchHandler.FetchResponse fetch(HttpURLConnection httpURLConnection, String str, String str2, Map<String, String> map, String str3, Map<String, String> map2, Long l, Date date) throws FirebaseRemoteConfigException {
setUpUrlConnection(httpURLConnection, str3, str2, map2);
try {
try {
setFetchRequestBody(httpURLConnection, createFetchRequestBody(str, str2, map, l).toString().getBytes(nb.N));
httpURLConnection.connect();
int responseCode = httpURLConnection.getResponseCode();
if (responseCode != 200) {
throw new FirebaseRemoteConfigServerException(responseCode, httpURLConnection.getResponseMessage());
}
String headerField = httpURLConnection.getHeaderField(Command.HTTP_HEADER_ETAG);
JSONObject fetchResponseBody = getFetchResponseBody(httpURLConnection);
try {
httpURLConnection.getInputStream().close();
} catch (IOException unused) {
}
ConfigContainer extractConfigs = extractConfigs(fetchResponseBody, date);
if (!backendHasUpdates(fetchResponseBody)) {
return ConfigFetchHandler.FetchResponse.forBackendHasNoUpdates(date, extractConfigs);
}
return ConfigFetchHandler.FetchResponse.forBackendUpdatesFetched(extractConfigs, headerField);
} finally {
httpURLConnection.disconnect();
try {
httpURLConnection.getInputStream().close();
} catch (IOException unused2) {
}
}
} catch (IOException | JSONException e) {
throw new FirebaseRemoteConfigClientException("The client had an error while calling the backend!", e);
}
}
public final void setUpUrlConnection(HttpURLConnection httpURLConnection, String str, String str2, Map map) {
httpURLConnection.setDoOutput(true);
TimeUnit timeUnit = TimeUnit.SECONDS;
httpURLConnection.setConnectTimeout((int) timeUnit.toMillis(this.connectTimeoutInSeconds));
httpURLConnection.setReadTimeout((int) timeUnit.toMillis(this.readTimeoutInSeconds));
httpURLConnection.setRequestProperty("If-None-Match", str);
setCommonRequestHeaders(httpURLConnection, str2);
setCustomRequestHeaders(httpURLConnection, map);
}
public final String getFetchUrl(String str, String str2) {
return String.format("https://firebaseremoteconfig.googleapis.com/v1/projects/%s/namespaces/%s:fetch", str, str2);
}
public final void setCommonRequestHeaders(HttpURLConnection httpURLConnection, String str) {
httpURLConnection.setRequestProperty("X-Goog-Api-Key", this.apiKey);
httpURLConnection.setRequestProperty("X-Android-Package", this.context.getPackageName());
httpURLConnection.setRequestProperty("X-Android-Cert", getFingerprintHashForPackage());
httpURLConnection.setRequestProperty("X-Google-GFE-Can-Retry", "yes");
httpURLConnection.setRequestProperty("X-Goog-Firebase-Installations-Auth", str);
httpURLConnection.setRequestProperty("Content-Type", nb.L);
httpURLConnection.setRequestProperty("Accept", nb.L);
}
public final void setCustomRequestHeaders(HttpURLConnection httpURLConnection, Map map) {
for (Map.Entry entry : map.entrySet()) {
httpURLConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
}
}
public final String getFingerprintHashForPackage() {
try {
Context context = this.context;
byte[] packageCertificateHashBytes = AndroidUtilsLight.getPackageCertificateHashBytes(context, context.getPackageName());
if (packageCertificateHashBytes == null) {
Log.e("FirebaseRemoteConfig", "Could not get fingerprint hash for package: " + this.context.getPackageName());
return null;
}
return Hex.bytesToStringUppercase(packageCertificateHashBytes, false);
} catch (PackageManager.NameNotFoundException e) {
Log.e("FirebaseRemoteConfig", "No such package: " + this.context.getPackageName(), e);
return null;
}
}
public final JSONObject createFetchRequestBody(String str, String str2, Map map, Long l) {
HashMap hashMap = new HashMap();
if (str == null) {
throw new FirebaseRemoteConfigClientException("Fetch failed: Firebase installation id is null.");
}
hashMap.put("appInstanceId", str);
hashMap.put("appInstanceIdToken", str2);
hashMap.put("appId", this.appId);
Locale locale = this.context.getResources().getConfiguration().locale;
hashMap.put(ApplicationEnvironment.NIMBLE_PARAMETER_COUNTRY_CODE, locale.getCountry());
int i = Build.VERSION.SDK_INT;
hashMap.put("languageCode", locale.toLanguageTag());
hashMap.put("platformVersion", Integer.toString(i));
hashMap.put("timeZone", TimeZone.getDefault().getID());
try {
PackageInfo packageInfo = this.context.getPackageManager().getPackageInfo(this.context.getPackageName(), 0);
if (packageInfo != null) {
hashMap.put(v8.i.W, packageInfo.versionName);
hashMap.put("appBuild", Long.toString(PackageInfoCompat.getLongVersionCode(packageInfo)));
}
} catch (PackageManager.NameNotFoundException unused) {
}
hashMap.put(HandleInvocationsFromAdViewer.KEY_PACKAGE_NAME, this.context.getPackageName());
hashMap.put("sdkVersion", "22.0.0");
hashMap.put("analyticsUserProperties", new JSONObject(map));
if (l != null) {
hashMap.put("firstOpenTime", convertToISOString(l.longValue()));
}
return new JSONObject(hashMap);
}
public final String convertToISOString(long j) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return simpleDateFormat.format(Long.valueOf(j));
}
public final void setFetchRequestBody(HttpURLConnection httpURLConnection, byte[] bArr) {
httpURLConnection.setFixedLengthStreamingMode(bArr.length);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(httpURLConnection.getOutputStream());
bufferedOutputStream.write(bArr);
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
public final JSONObject getFetchResponseBody(URLConnection uRLConnection) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(uRLConnection.getInputStream(), nb.N));
StringBuilder sb = new StringBuilder();
while (true) {
int read = bufferedReader.read();
if (read != -1) {
sb.append((char) read);
} else {
return new JSONObject(sb.toString());
}
}
}
public final boolean backendHasUpdates(JSONObject jSONObject) {
try {
return !jSONObject.get("state").equals("NO_CHANGE");
} catch (JSONException unused) {
return true;
}
}
public static ConfigContainer extractConfigs(JSONObject jSONObject, Date date) {
JSONObject jSONObject2;
JSONArray jSONArray;
JSONObject jSONObject3;
try {
ConfigContainer.Builder withFetchTime = ConfigContainer.newBuilder().withFetchTime(date);
JSONArray jSONArray2 = null;
try {
jSONObject2 = jSONObject.getJSONObject("entries");
} catch (JSONException unused) {
jSONObject2 = null;
}
if (jSONObject2 != null) {
withFetchTime = withFetchTime.replaceConfigsWith(jSONObject2);
}
try {
jSONArray = jSONObject.getJSONArray("experimentDescriptions");
} catch (JSONException unused2) {
jSONArray = null;
}
if (jSONArray != null) {
withFetchTime = withFetchTime.withAbtExperiments(jSONArray);
}
try {
jSONObject3 = jSONObject.getJSONObject("personalizationMetadata");
} catch (JSONException unused3) {
jSONObject3 = null;
}
if (jSONObject3 != null) {
withFetchTime = withFetchTime.withPersonalizationMetadata(jSONObject3);
}
String string = jSONObject.has("templateVersion") ? jSONObject.getString("templateVersion") : null;
if (string != null) {
withFetchTime.withTemplateVersionNumber(Long.parseLong(string));
}
try {
jSONArray2 = jSONObject.getJSONArray("rolloutMetadata");
} catch (JSONException unused4) {
}
if (jSONArray2 != null) {
withFetchTime = withFetchTime.withRolloutMetadata(jSONArray2);
}
return withFetchTime.build();
} catch (JSONException e) {
throw new FirebaseRemoteConfigClientException("Fetch failed: fetch response could not be parsed.", e);
}
}
}