Files
rr3-apk/decompiled-community/sources/com/vungle/ads/internal/network/VungleApiClient.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

1030 lines
48 KiB
Java

package com.vungle.ads.internal.network;
import android.app.UiModeManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.PowerManager;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.PermissionChecker;
import androidx.core.util.Consumer;
import com.applovin.sdk.AppLovinEventTypes;
import com.google.android.gms.common.GoogleApiAvailabilityLight;
import com.ironsource.nb;
import com.mbridge.msdk.foundation.entity.b;
import com.vungle.ads.AnalyticsClient;
import com.vungle.ads.BuildConfig;
import com.vungle.ads.ServiceLocator;
import com.vungle.ads.TimeIntervalMetric;
import com.vungle.ads.VungleAdSize;
import com.vungle.ads.VungleAds;
import com.vungle.ads.fpd.FirstPartyData;
import com.vungle.ads.internal.ConfigManager;
import com.vungle.ads.internal.model.AdPayload;
import com.vungle.ads.internal.model.AdvertisingInfo;
import com.vungle.ads.internal.model.AppNode;
import com.vungle.ads.internal.model.CommonRequestBody;
import com.vungle.ads.internal.model.ConfigPayload;
import com.vungle.ads.internal.model.Cookie;
import com.vungle.ads.internal.model.DeviceNode;
import com.vungle.ads.internal.persistence.FilePreferences;
import com.vungle.ads.internal.platform.AndroidPlatform;
import com.vungle.ads.internal.platform.Platform;
import com.vungle.ads.internal.privacy.COPPA;
import com.vungle.ads.internal.privacy.PrivacyManager;
import com.vungle.ads.internal.protos.Sdk;
import com.vungle.ads.internal.signals.SignalManager;
import com.vungle.ads.internal.util.FileUtility;
import com.vungle.ads.internal.util.Logger;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import kotlin.Lazy;
import kotlin.LazyKt__LazyJVMKt;
import kotlin.LazyThreadSafetyMode;
import kotlin.Unit;
import kotlin.collections.CollectionsKt__CollectionsJVMKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlin.text.StringsKt__StringsJVMKt;
import kotlinx.serialization.DeserializationStrategy;
import kotlinx.serialization.SerializersKt;
import kotlinx.serialization.StringFormat;
import kotlinx.serialization.json.Json;
import kotlinx.serialization.json.JsonBuilder;
import kotlinx.serialization.json.JsonKt;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.Buffer;
import okio.BufferedSink;
import okio.GzipSink;
import okio.Okio;
/* loaded from: classes4.dex */
public final class VungleApiClient {
private static final String BASE_URL;
public static final Companion Companion;
private static final String MANUFACTURER_AMAZON = "Amazon";
private static final String TAG = "VungleApiClient";
private static VungleAds.WrapperFramework WRAPPER_FRAMEWORK_SELECTED;
private static String headerUa;
private static final Json json;
private static final Set<Interceptor> logInterceptors;
private static final Set<Interceptor> networkInterceptors;
private AdvertisingInfo advertisingInfo;
private VungleApi api;
private AppNode appBody;
private final Context applicationContext;
private DeviceNode baseDeviceInfo;
private final FilePreferences filePreferences;
private VungleApi gzipApi;
private Boolean isGooglePlayServicesAvailable;
private final Platform platform;
private Interceptor responseInterceptor;
private Map<String, Long> retryAfterDataMap;
private final Lazy signalManager$delegate;
private String uaString;
@VisibleForTesting
public static /* synthetic */ void getAppBody$vungle_ads_release$annotations() {
}
@VisibleForTesting
public static /* synthetic */ void getGzipApi$vungle_ads_release$annotations() {
}
@VisibleForTesting
public static /* synthetic */ void getResponseInterceptor$vungle_ads_release$annotations() {
}
@VisibleForTesting
public static /* synthetic */ void getRetryAfterDataMap$vungle_ads_release$annotations() {
}
public final AppNode getAppBody$vungle_ads_release() {
return this.appBody;
}
public final String getConnectionTypeDetail(int i) {
if (i == 1) {
return "gprs";
}
if (i == 2) {
return "edge";
}
if (i == 20) {
return "5g";
}
switch (i) {
case 4:
return "wcdma";
case 5:
return "cdma_evdo_0";
case 6:
return "cdma_evdo_a";
case 7:
return "cdma_1xrtt";
case 8:
return "hsdpa";
case 9:
return "hsupa";
default:
switch (i) {
case 12:
return "cdma_evdo_b";
case 13:
return "lte";
case 14:
return "hrpd";
default:
return "unknown";
}
}
}
public final VungleApi getGzipApi$vungle_ads_release() {
return this.gzipApi;
}
public final Interceptor getResponseInterceptor$vungle_ads_release() {
return this.responseInterceptor;
}
public final Map<String, Long> getRetryAfterDataMap$vungle_ads_release() {
return this.retryAfterDataMap;
}
public final void setAppBody$vungle_ads_release(AppNode appNode) {
this.appBody = appNode;
}
public final void setGzipApi$vungle_ads_release(VungleApi vungleApi) {
Intrinsics.checkNotNullParameter(vungleApi, "<set-?>");
this.gzipApi = vungleApi;
}
public final void setResponseInterceptor$vungle_ads_release(Interceptor interceptor) {
Intrinsics.checkNotNullParameter(interceptor, "<set-?>");
this.responseInterceptor = interceptor;
}
public final void setRetryAfterDataMap$vungle_ads_release(Map<String, Long> map) {
Intrinsics.checkNotNullParameter(map, "<set-?>");
this.retryAfterDataMap = map;
}
public VungleApiClient(final Context applicationContext, Platform platform, FilePreferences filePreferences) {
Lazy lazy;
Intrinsics.checkNotNullParameter(applicationContext, "applicationContext");
Intrinsics.checkNotNullParameter(platform, "platform");
Intrinsics.checkNotNullParameter(filePreferences, "filePreferences");
this.applicationContext = applicationContext;
this.platform = platform;
this.filePreferences = filePreferences;
this.uaString = System.getProperty("http.agent");
ServiceLocator.Companion companion = ServiceLocator.Companion;
lazy = LazyKt__LazyJVMKt.lazy(LazyThreadSafetyMode.SYNCHRONIZED, new Function0() { // from class: com.vungle.ads.internal.network.VungleApiClient$special$$inlined$inject$1
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(0);
}
/* JADX WARN: Type inference failed for: r0v2, types: [com.vungle.ads.internal.signals.SignalManager, java.lang.Object] */
@Override // kotlin.jvm.functions.Function0
public final SignalManager invoke() {
return ServiceLocator.Companion.getInstance(applicationContext).getService(SignalManager.class);
}
});
this.signalManager$delegate = lazy;
this.retryAfterDataMap = new ConcurrentHashMap();
this.responseInterceptor = new Interceptor() { // from class: com.vungle.ads.internal.network.VungleApiClient$$ExternalSyntheticLambda0
@Override // okhttp3.Interceptor
public final okhttp3.Response intercept(Interceptor.Chain chain) {
okhttp3.Response m3944responseInterceptor$lambda0;
m3944responseInterceptor$lambda0 = VungleApiClient.m3944responseInterceptor$lambda0(VungleApiClient.this, chain);
return m3944responseInterceptor$lambda0;
}
};
OkHttpClient.Builder proxySelector = new OkHttpClient.Builder().addInterceptor(this.responseInterceptor).proxySelector(new ProxySelector() { // from class: com.vungle.ads.internal.network.VungleApiClient$builder$1
@Override // java.net.ProxySelector
public List<Proxy> select(URI uri) {
try {
List<Proxy> select = ProxySelector.getDefault().select(uri);
Intrinsics.checkNotNullExpressionValue(select, "{\n …ri)\n }");
return select;
} catch (Exception unused) {
return CollectionsKt__CollectionsJVMKt.listOf(Proxy.NO_PROXY);
}
}
@Override // java.net.ProxySelector
public void connectFailed(URI uri, SocketAddress socketAddress, IOException iOException) {
try {
ProxySelector.getDefault().connectFailed(uri, socketAddress, iOException);
} catch (Exception unused) {
}
}
});
OkHttpClient build = proxySelector.build();
OkHttpClient build2 = proxySelector.addInterceptor(new GzipRequestInterceptor()).build();
this.api = new VungleApiImpl(build);
this.gzipApi = new VungleApiImpl(build2);
}
public static final class Companion {
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
private Companion() {
}
public final String getBASE_URL$vungle_ads_release() {
return VungleApiClient.BASE_URL;
}
public final VungleAds.WrapperFramework getWRAPPER_FRAMEWORK_SELECTED$vungle_ads_release() {
return VungleApiClient.WRAPPER_FRAMEWORK_SELECTED;
}
public final void setWRAPPER_FRAMEWORK_SELECTED$vungle_ads_release(VungleAds.WrapperFramework wrapperFramework) {
VungleApiClient.WRAPPER_FRAMEWORK_SELECTED = wrapperFramework;
}
public final String getHeaderUa() {
return VungleApiClient.headerUa;
}
public final void setHeaderUa(String str) {
Intrinsics.checkNotNullParameter(str, "<set-?>");
VungleApiClient.headerUa = str;
}
/* JADX INFO: Access modifiers changed from: private */
public final String defaultHeader() {
StringBuilder sb = new StringBuilder();
sb.append(Intrinsics.areEqual("Amazon", Build.MANUFACTURER) ? "VungleAmazon/" : "VungleDroid/");
sb.append(BuildConfig.VERSION_NAME);
return sb.toString();
}
public final void reset$vungle_ads_release() {
setWRAPPER_FRAMEWORK_SELECTED$vungle_ads_release(null);
setHeaderUa(defaultHeader());
}
}
static {
Companion companion = new Companion(null);
Companion = companion;
BASE_URL = "https://config.ads.vungle.com/";
headerUa = companion.defaultHeader();
networkInterceptors = new HashSet();
logInterceptors = new HashSet();
json = JsonKt.Json$default((Json) null, new Function1() { // from class: com.vungle.ads.internal.network.VungleApiClient$Companion$json$1
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Object invoke(Object obj) {
invoke((JsonBuilder) obj);
return Unit.INSTANCE;
}
public final void invoke(JsonBuilder Json) {
Intrinsics.checkNotNullParameter(Json, "$this$Json");
Json.setIgnoreUnknownKeys(true);
Json.setEncodeDefaults(true);
Json.setExplicitNulls(false);
}
}, 1, (Object) null);
}
private final SignalManager getSignalManager() {
return (SignalManager) this.signalManager$delegate.getValue();
}
/* JADX INFO: Access modifiers changed from: private */
/* renamed from: responseInterceptor$lambda-0, reason: not valid java name */
public static final okhttp3.Response m3944responseInterceptor$lambda0(VungleApiClient this$0, Interceptor.Chain chain) {
Intrinsics.checkNotNullParameter(this$0, "this$0");
Intrinsics.checkNotNullParameter(chain, "chain");
Request request = chain.request();
try {
try {
okhttp3.Response proceed = chain.proceed(request);
String str = proceed.headers().get("Retry-After");
if (str != null && str.length() != 0) {
try {
long parseLong = Long.parseLong(str);
if (parseLong > 0) {
String encodedPath = request.url().encodedPath();
long currentTimeMillis = (parseLong * 1000) + System.currentTimeMillis();
if (StringsKt__StringsJVMKt.endsWith$default(encodedPath, b.JSON_KEY_ADS, false, 2, null)) {
String placementID = this$0.getPlacementID(request.body());
if (placementID.length() > 0) {
this$0.retryAfterDataMap.put(placementID, Long.valueOf(currentTimeMillis));
}
}
}
} catch (Exception unused) {
Logger.Companion.d(TAG, "Retry-After value is not an valid value");
}
}
return proceed;
} catch (Exception e) {
Logger.Companion.e(TAG, "Exception: " + e.getMessage() + " for " + request.url());
return this$0.defaultErrorResponse(request);
}
} catch (OutOfMemoryError unused2) {
Logger.Companion.e(TAG, "OOM for " + request.url());
return this$0.defaultErrorResponse(request);
}
}
private final okhttp3.Response defaultErrorResponse(Request request) {
return new Response.Builder().request(request).code(500).protocol(Protocol.HTTP_1_1).message("Server is busy").body(ResponseBody.Companion.create("{\"Error\":\"Server is busy\"}", MediaType.Companion.parse("application/json; charset=utf-8"))).build();
}
private final String getPlacementID(RequestBody requestBody) {
List<String> placements;
try {
StringFormat stringFormat = json;
String bodyToString = bodyToString(requestBody);
DeserializationStrategy serializer = SerializersKt.serializer(stringFormat.getSerializersModule(), Reflection.typeOf(CommonRequestBody.class));
Intrinsics.checkNotNull(serializer, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<T of kotlinx.serialization.internal.Platform_commonKt.cast>");
CommonRequestBody.RequestParam request = ((CommonRequestBody) stringFormat.decodeFromString(serializer, bodyToString)).getRequest();
if (request == null || (placements = request.getPlacements()) == null) {
return "";
}
String str = placements.get(0);
return str == null ? "" : str;
} catch (Exception unused) {
return "";
}
}
private final String bodyToString(RequestBody requestBody) {
try {
Buffer buffer = new Buffer();
if (requestBody == null) {
return "";
}
requestBody.writeTo(buffer);
return buffer.readUtf8();
} catch (Exception unused) {
return "";
}
}
public final boolean checkIsRetryAfterActive(String placementID) {
Intrinsics.checkNotNullParameter(placementID, "placementID");
Long l = this.retryAfterDataMap.get(placementID);
if ((l != null ? l.longValue() : 0L) > System.currentTimeMillis()) {
return true;
}
this.retryAfterDataMap.remove(placementID);
return false;
}
public final long getRetryAfterHeaderValue(String placementID) {
Intrinsics.checkNotNullParameter(placementID, "placementID");
Long l = this.retryAfterDataMap.get(placementID);
if (l != null) {
return l.longValue();
}
return 0L;
}
public static final class GzipRequestInterceptor implements Interceptor {
private static final String CONTENT_ENCODING = "Content-Encoding";
public static final Companion Companion = new Companion(null);
private static final String GZIP = "gzip";
@Override // okhttp3.Interceptor
public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
Intrinsics.checkNotNullParameter(chain, "chain");
Request request = chain.request();
RequestBody body = request.body();
if (body == null || request.header("Content-Encoding") != null) {
return chain.proceed(request);
}
return chain.proceed(request.newBuilder().header("Content-Encoding", GZIP).method(request.method(), gzip(body)).build());
}
private final RequestBody gzip(final RequestBody requestBody) throws IOException {
final Buffer buffer = new Buffer();
BufferedSink buffer2 = Okio.buffer(new GzipSink(buffer));
requestBody.writeTo(buffer2);
buffer2.close();
return new RequestBody() { // from class: com.vungle.ads.internal.network.VungleApiClient$GzipRequestInterceptor$gzip$1
@Override // okhttp3.RequestBody
public MediaType contentType() {
return RequestBody.this.contentType();
}
@Override // okhttp3.RequestBody
public long contentLength() {
return buffer.size();
}
@Override // okhttp3.RequestBody
public void writeTo(BufferedSink sink) throws IOException {
Intrinsics.checkNotNullParameter(sink, "sink");
sink.write(buffer.snapshot());
}
};
}
public static final class Companion {
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
private Companion() {
}
}
}
public final synchronized void initialize(String appId) {
PackageInfo packageInfo;
PackageManager.PackageInfoFlags of;
try {
Intrinsics.checkNotNullParameter(appId, "appId");
this.api.setAppId(appId);
this.gzipApi.setAppId(appId);
String str = "1.0";
try {
if (Build.VERSION.SDK_INT >= 33) {
PackageManager packageManager = this.applicationContext.getPackageManager();
String packageName = this.applicationContext.getPackageName();
of = PackageManager.PackageInfoFlags.of(0L);
packageInfo = packageManager.getPackageInfo(packageName, of);
Intrinsics.checkNotNullExpressionValue(packageInfo, "{\n ap… )\n }");
} else {
packageInfo = this.applicationContext.getPackageManager().getPackageInfo(this.applicationContext.getPackageName(), 0);
Intrinsics.checkNotNullExpressionValue(packageInfo, "{\n ap… )\n }");
}
String str2 = packageInfo.versionName;
Intrinsics.checkNotNullExpressionValue(str2, "packageInfo.versionName");
str = str2;
} catch (Exception unused) {
}
this.baseDeviceInfo = getBasicDeviceBody(this.applicationContext);
String packageName2 = this.applicationContext.getPackageName();
Intrinsics.checkNotNullExpressionValue(packageName2, "applicationContext.packageName");
this.appBody = new AppNode(packageName2, str, appId);
this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromAPI();
} catch (Throwable th) {
throw th;
}
}
public final Call<ConfigPayload> config() throws IOException {
AppNode appNode = this.appBody;
if (appNode == null) {
return null;
}
CommonRequestBody commonRequestBody = new CommonRequestBody(getDeviceBody$vungle_ads_release(true), appNode, getUserBody$default(this, false, 1, null), (CommonRequestBody.RequestExt) null, (CommonRequestBody.RequestParam) null, 24, (DefaultConstructorMarker) null);
CommonRequestBody.RequestExt extBody$default = getExtBody$default(this, false, 1, null);
if (extBody$default != null) {
commonRequestBody.setExt(extBody$default);
}
FileUtility fileUtility = FileUtility.INSTANCE;
String str = BASE_URL;
if (!fileUtility.isValidUrl(str)) {
str = "https://config.ads.vungle.com/";
}
if (!StringsKt__StringsJVMKt.endsWith$default(str, "/", false, 2, null)) {
str = str + '/';
}
return this.api.config(headerUa, str + "config", commonRequestBody);
}
public final Call<AdPayload> requestAd(String placement, VungleAdSize vungleAdSize) throws IllegalStateException {
Intrinsics.checkNotNullParameter(placement, "placement");
ConfigManager configManager = ConfigManager.INSTANCE;
String adsEndpoint = configManager.getAdsEndpoint();
if (adsEndpoint == null || adsEndpoint.length() == 0) {
return null;
}
CommonRequestBody requestBody = requestBody(!configManager.signalsDisabled(), configManager.fpdEnabled());
CommonRequestBody.RequestParam requestParam = new CommonRequestBody.RequestParam(CollectionsKt__CollectionsJVMKt.listOf(placement), (CommonRequestBody.AdSizeParam) null, (Long) null, (String) null, (String) null, (String) null, 62, (DefaultConstructorMarker) null);
if (vungleAdSize != null) {
requestParam.setAdSize(new CommonRequestBody.AdSizeParam(vungleAdSize.getWidth(), vungleAdSize.getHeight()));
}
requestBody.setRequest(requestParam);
return this.gzipApi.ads(headerUa, adsEndpoint, requestBody);
}
public final Call<Void> ri(CommonRequestBody.RequestParam request) {
AppNode appNode;
Intrinsics.checkNotNullParameter(request, "request");
String riEndpoint = ConfigManager.INSTANCE.getRiEndpoint();
if (riEndpoint == null || riEndpoint.length() == 0 || (appNode = this.appBody) == null) {
return null;
}
CommonRequestBody commonRequestBody = new CommonRequestBody(getDeviceBody(), appNode, getUserBody$default(this, false, 1, null), (CommonRequestBody.RequestExt) null, (CommonRequestBody.RequestParam) null, 24, (DefaultConstructorMarker) null);
commonRequestBody.setRequest(request);
CommonRequestBody.RequestExt extBody$default = getExtBody$default(this, false, 1, null);
if (extBody$default != null) {
commonRequestBody.setExt(extBody$default);
}
return this.api.ri(headerUa, riEndpoint, commonRequestBody);
}
/* JADX WARN: Code restructure failed: missing block: B:25:0x007c, code lost:
r9 = r9.raw();
*/
/* JADX WARN: Code restructure failed: missing block: B:26:0x0080, code lost:
if (r9 == null) goto L31;
*/
/* JADX WARN: Code restructure failed: missing block: B:27:0x0082, code lost:
r0 = java.lang.Integer.valueOf(r9.code());
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final com.vungle.ads.internal.load.BaseAdLoader.ErrorInfo pingTPAT(java.lang.String r9) {
/*
Method dump skipped, instructions count: 282
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: com.vungle.ads.internal.network.VungleApiClient.pingTPAT(java.lang.String):com.vungle.ads.internal.load.BaseAdLoader$ErrorInfo");
}
public final void reportMetrics(BlockingQueue<Sdk.SDKMetric.Builder> metrics, final AnalyticsClient.RequestListener requestListener) {
Intrinsics.checkNotNullParameter(metrics, "metrics");
Intrinsics.checkNotNullParameter(requestListener, "requestListener");
String metricsEndpoint = ConfigManager.INSTANCE.getMetricsEndpoint();
if (metricsEndpoint == null || metricsEndpoint.length() == 0) {
requestListener.onFailure();
return;
}
for (Sdk.SDKMetric.Builder builder : metrics) {
String connectionType = getConnectionType();
if (connectionType != null) {
builder.setConnectionType(connectionType);
}
String connectionTypeDetail = getConnectionTypeDetail();
if (connectionTypeDetail != null) {
builder.setConnectionTypeDetail(connectionTypeDetail);
}
}
ArrayList arrayList = new ArrayList();
Iterator<Sdk.SDKMetric.Builder> it = metrics.iterator();
while (it.hasNext()) {
arrayList.add(it.next().build());
}
Sdk.MetricBatch build = Sdk.MetricBatch.newBuilder().addAllMetrics(arrayList).build();
RequestBody.Companion companion = RequestBody.Companion;
MediaType parse = MediaType.Companion.parse("application/x-protobuf");
byte[] byteArray = build.toByteArray();
Intrinsics.checkNotNullExpressionValue(byteArray, "batch.toByteArray()");
this.api.sendMetrics(headerUa, metricsEndpoint, RequestBody.Companion.create$default(companion, parse, byteArray, 0, 0, 12, (Object) null)).enqueue(new Callback<Void>() { // from class: com.vungle.ads.internal.network.VungleApiClient$reportMetrics$3
@Override // com.vungle.ads.internal.network.Callback
public void onResponse(Call<Void> call, Response<Void> response) {
AnalyticsClient.RequestListener.this.onSuccess();
}
@Override // com.vungle.ads.internal.network.Callback
public void onFailure(Call<Void> call, Throwable th) {
AnalyticsClient.RequestListener.this.onFailure();
}
});
}
public final void reportErrors(BlockingQueue<Sdk.SDKError.Builder> errors, final AnalyticsClient.RequestListener requestListener) {
Intrinsics.checkNotNullParameter(errors, "errors");
Intrinsics.checkNotNullParameter(requestListener, "requestListener");
String errorLoggingEndpoint = ConfigManager.INSTANCE.getErrorLoggingEndpoint();
if (errorLoggingEndpoint == null || errorLoggingEndpoint.length() == 0) {
requestListener.onFailure();
return;
}
for (Sdk.SDKError.Builder builder : errors) {
String connectionType = getConnectionType();
if (connectionType != null) {
builder.setConnectionType(connectionType);
}
String connectionTypeDetail = getConnectionTypeDetail();
if (connectionTypeDetail != null) {
builder.setConnectionTypeDetail(connectionTypeDetail);
builder.setConnectionTypeDetailAndroid(connectionTypeDetail);
}
}
ArrayList arrayList = new ArrayList();
Iterator<Sdk.SDKError.Builder> it = errors.iterator();
while (it.hasNext()) {
arrayList.add(it.next().build());
}
Sdk.SDKErrorBatch build = Sdk.SDKErrorBatch.newBuilder().addAllErrors(arrayList).build();
RequestBody.Companion companion = RequestBody.Companion;
byte[] byteArray = build.toByteArray();
Intrinsics.checkNotNullExpressionValue(byteArray, "batch.toByteArray()");
this.api.sendErrors(headerUa, errorLoggingEndpoint, companion.create(byteArray, MediaType.Companion.parse("application/x-protobuf"), 0, build.toByteArray().length)).enqueue(new Callback<Void>() { // from class: com.vungle.ads.internal.network.VungleApiClient$reportErrors$3
@Override // com.vungle.ads.internal.network.Callback
public void onResponse(Call<Void> call, Response<Void> response) {
AnalyticsClient.RequestListener.this.onSuccess();
}
@Override // com.vungle.ads.internal.network.Callback
public void onFailure(Call<Void> call, Throwable th) {
AnalyticsClient.RequestListener.this.onFailure();
}
});
}
public final void sendAdMarkup(String adMarkup, String endpoint) {
Intrinsics.checkNotNullParameter(adMarkup, "adMarkup");
Intrinsics.checkNotNullParameter(endpoint, "endpoint");
this.api.sendAdMarkup(endpoint, RequestBody.Companion.create(adMarkup, MediaType.Companion.parse(nb.L))).enqueue(new Callback<Void>() { // from class: com.vungle.ads.internal.network.VungleApiClient$sendAdMarkup$1
@Override // com.vungle.ads.internal.network.Callback
public void onFailure(Call<Void> call, Throwable th) {
}
@Override // com.vungle.ads.internal.network.Callback
public void onResponse(Call<Void> call, Response<Void> response) {
}
});
}
private final void initUserAgentLazy() {
final TimeIntervalMetric timeIntervalMetric = new TimeIntervalMetric(Sdk.SDKMetric.SDKMetricType.USER_AGENT_LOAD_DURATION_MS);
timeIntervalMetric.markStart();
this.platform.getUserAgentLazy(new Consumer<String>() { // from class: com.vungle.ads.internal.network.VungleApiClient$initUserAgentLazy$1
@Override // androidx.core.util.Consumer
public void accept(String str) {
if (str == null) {
Logger.Companion.e("VungleApiClient", "Cannot Get UserAgent. Setting Default Device UserAgent");
AnalyticsClient.INSTANCE.logError$vungle_ads_release(7, "Fail to get user agent.", (r13 & 4) != 0 ? null : null, (r13 & 8) != 0 ? null : null, (r13 & 16) != 0 ? null : null);
} else {
TimeIntervalMetric.this.markEnd();
AnalyticsClient.INSTANCE.logMetric$vungle_ads_release(TimeIntervalMetric.this.getMetricType(), (r15 & 2) != 0 ? 0L : TimeIntervalMetric.this.calculateIntervalDuration(), (r15 & 4) != 0 ? null : null, (r15 & 8) != 0 ? null : null, (r15 & 16) != 0 ? null : null, (r15 & 32) == 0 ? null : null);
this.uaString = str;
}
}
});
}
@VisibleForTesting
public final void addPlaySvcAvailabilityInCookie(boolean z) {
this.filePreferences.put(Cookie.IS_PLAY_SERVICE_AVAILABLE, z).apply();
}
@VisibleForTesting
public final Boolean getPlayServicesAvailabilityFromCookie() {
return this.filePreferences.getBoolean(Cookie.IS_PLAY_SERVICE_AVAILABLE);
}
@VisibleForTesting
public final Boolean getPlayServicesAvailabilityFromAPI() {
Boolean bool = null;
try {
GoogleApiAvailabilityLight googleApiAvailabilityLight = GoogleApiAvailabilityLight.getInstance();
Intrinsics.checkNotNullExpressionValue(googleApiAvailabilityLight, "getInstance()");
bool = Boolean.valueOf(googleApiAvailabilityLight.isGooglePlayServicesAvailable(this.applicationContext) == 0);
addPlaySvcAvailabilityInCookie(bool.booleanValue());
return bool;
} catch (Exception unused) {
Logger.Companion.w(TAG, "Unexpected exception from Play services lib.");
return bool;
} catch (NoClassDefFoundError unused2) {
Logger.Companion.w(TAG, "Play services Not available");
Boolean bool2 = Boolean.FALSE;
try {
addPlaySvcAvailabilityInCookie(false);
return bool2;
} catch (Exception unused3) {
Logger.Companion.w(TAG, "Failure to write GPS availability to DB");
return bool2;
}
}
}
private final DeviceNode getBasicDeviceBody(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
Object systemService = context.getSystemService("window");
Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.view.WindowManager");
Display defaultDisplay = ((WindowManager) systemService).getDefaultDisplay();
if (defaultDisplay != null) {
defaultDisplay.getMetrics(displayMetrics);
}
String MANUFACTURER = Build.MANUFACTURER;
Intrinsics.checkNotNullExpressionValue(MANUFACTURER, "MANUFACTURER");
String MODEL = Build.MODEL;
Intrinsics.checkNotNullExpressionValue(MODEL, "MODEL");
String RELEASE = Build.VERSION.RELEASE;
Intrinsics.checkNotNullExpressionValue(RELEASE, "RELEASE");
DeviceNode deviceNode = new DeviceNode(MANUFACTURER, MODEL, RELEASE, AndroidPlatform.Companion.getCarrierName$vungle_ads_release(context), Intrinsics.areEqual("Amazon", MANUFACTURER) ? "amazon" : "android", displayMetrics.widthPixels, displayMetrics.heightPixels, this.uaString, (String) null, (Integer) null, (DeviceNode.VungleExt) null, 1792, (DefaultConstructorMarker) null);
try {
String userAgent = this.platform.getUserAgent();
this.uaString = userAgent;
deviceNode.setUa(userAgent);
initUserAgentLazy();
AdvertisingInfo advertisingInfo = this.advertisingInfo;
if (advertisingInfo == null) {
advertisingInfo = this.platform.getAdvertisingInfo();
}
this.advertisingInfo = advertisingInfo;
} catch (Exception e) {
Logger.Companion.e(TAG, "Cannot Get UserAgent. Setting Default Device UserAgent." + e.getLocalizedMessage());
}
return deviceNode;
}
public static /* synthetic */ CommonRequestBody requestBody$default(VungleApiClient vungleApiClient, boolean z, boolean z2, int i, Object obj) throws IllegalStateException {
if ((i & 1) != 0) {
z = false;
}
if ((i & 2) != 0) {
z2 = false;
}
return vungleApiClient.requestBody(z, z2);
}
public final CommonRequestBody requestBody(boolean z, boolean z2) throws IllegalStateException {
CommonRequestBody commonRequestBody = new CommonRequestBody(getDeviceBody(), this.appBody, getUserBody(z2), (CommonRequestBody.RequestExt) null, (CommonRequestBody.RequestParam) null, 24, (DefaultConstructorMarker) null);
CommonRequestBody.RequestExt extBody = getExtBody(z);
if (extBody != null) {
commonRequestBody.setExt(extBody);
}
return commonRequestBody;
}
private final DeviceNode getDeviceBody() throws IllegalStateException {
return getDeviceBody$vungle_ads_release(false);
}
@VisibleForTesting
public final synchronized DeviceNode getDeviceBody$vungle_ads_release(boolean z) throws IllegalStateException {
DeviceNode copy;
DeviceNode.VungleExt vungleExt;
String str;
try {
DeviceNode deviceNode = this.baseDeviceInfo;
if (deviceNode == null) {
deviceNode = getBasicDeviceBody(this.applicationContext);
this.baseDeviceInfo = deviceNode;
}
copy = r2.copy((r24 & 1) != 0 ? r2.make : null, (r24 & 2) != 0 ? r2.model : null, (r24 & 4) != 0 ? r2.osv : null, (r24 & 8) != 0 ? r2.carrier : null, (r24 & 16) != 0 ? r2.os : null, (r24 & 32) != 0 ? r2.w : 0, (r24 & 64) != 0 ? r2.h : 0, (r24 & 128) != 0 ? r2.ua : null, (r24 & 256) != 0 ? r2.ifa : null, (r24 & 512) != 0 ? r2.lmt : null, (r24 & 1024) != 0 ? deviceNode.ext : null);
DeviceNode.VungleExt vungleExt2 = new DeviceNode.VungleExt(false, (String) null, (Integer) null, 0.0f, (String) null, 0, (String) null, (String) null, (String) null, (String) null, (String) null, 0.0f, 0, false, 0, false, (String) null, (String) null, 262143, (DefaultConstructorMarker) null);
AdvertisingInfo advertisingInfo = this.advertisingInfo;
if (advertisingInfo == null) {
advertisingInfo = this.platform.getAdvertisingInfo();
}
this.advertisingInfo = advertisingInfo;
String advertisingId = advertisingInfo != null ? advertisingInfo.getAdvertisingId() : null;
AdvertisingInfo advertisingInfo2 = this.advertisingInfo;
Boolean valueOf = advertisingInfo2 != null ? Boolean.valueOf(advertisingInfo2.getLimitAdTracking()) : null;
PrivacyManager privacyManager = PrivacyManager.INSTANCE;
if (!privacyManager.shouldSendAdIds()) {
vungleExt = vungleExt2;
} else if (advertisingId != null) {
if (Intrinsics.areEqual("Amazon", Build.MANUFACTURER)) {
vungleExt = vungleExt2;
vungleExt.setAmazonAdvertisingId(advertisingId);
} else {
vungleExt = vungleExt2;
vungleExt.setGaid(advertisingId);
}
copy.setIfa(advertisingId);
} else {
vungleExt = vungleExt2;
copy.setIfa("");
}
if (z || !privacyManager.shouldSendAdIds()) {
copy.setIfa(null);
vungleExt.setGaid(null);
vungleExt.setAmazonAdvertisingId(null);
}
Boolean bool = Boolean.TRUE;
boolean z2 = false;
copy.setLmt(Intrinsics.areEqual(valueOf, bool) ? 1 : 0);
vungleExt.setGooglePlayServicesAvailable(Intrinsics.areEqual(bool, isGooglePlayServicesAvailable()));
if (privacyManager.allowDeviceIDFromTCF() != PrivacyManager.DeviceIdAllowed.DISABLE_ID) {
String appSetId = this.platform.getAppSetId();
if (appSetId != null) {
vungleExt.setAppSetId(appSetId);
}
Integer appSetIdScope = this.platform.getAppSetIdScope();
if (appSetIdScope != null) {
vungleExt.setAppSetIdScope(Integer.valueOf(appSetIdScope.intValue()));
}
}
Intent registerReceiver = this.applicationContext.registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
if (registerReceiver != null) {
int intExtra = registerReceiver.getIntExtra(AppLovinEventTypes.USER_COMPLETED_LEVEL, -1);
int intExtra2 = registerReceiver.getIntExtra("scale", -1);
if (intExtra > 0 && intExtra2 > 0) {
vungleExt.setBatteryLevel(intExtra / intExtra2);
}
int intExtra3 = registerReceiver.getIntExtra("status", -1);
if (intExtra3 == -1) {
str = "UNKNOWN";
} else if (intExtra3 == 2 || intExtra3 == 5) {
int intExtra4 = registerReceiver.getIntExtra("plugged", -1);
str = intExtra4 != 1 ? intExtra4 != 2 ? intExtra4 != 4 ? "BATTERY_PLUGGED_OTHERS" : "BATTERY_PLUGGED_WIRELESS" : "BATTERY_PLUGGED_USB" : "BATTERY_PLUGGED_AC";
} else {
str = "NOT_CHARGING";
}
} else {
str = "UNKNOWN";
}
vungleExt.setBatteryState(str);
Object systemService = this.applicationContext.getSystemService("power");
Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.os.PowerManager");
vungleExt.setBatterySaverEnabled(((PowerManager) systemService).isPowerSaveMode() ? 1 : 0);
String connectionType = getConnectionType();
if (connectionType != null) {
vungleExt.setConnectionType(connectionType);
}
String connectionTypeDetail = getConnectionTypeDetail();
if (connectionTypeDetail != null) {
vungleExt.setConnectionTypeDetail(connectionTypeDetail);
}
vungleExt.setLocale(Locale.getDefault().toString());
vungleExt.setLanguage(Locale.getDefault().getLanguage());
vungleExt.setTimeZone(TimeZone.getDefault().getID());
vungleExt.setVolumeLevel(this.platform.getVolumeLevel());
vungleExt.setSoundEnabled(this.platform.isSoundEnabled() ? 1 : 0);
if (Intrinsics.areEqual("Amazon", Build.MANUFACTURER)) {
z2 = this.applicationContext.getPackageManager().hasSystemFeature("amazon.hardware.fire_tv");
} else {
Object systemService2 = this.applicationContext.getSystemService("uimode");
Intrinsics.checkNotNull(systemService2, "null cannot be cast to non-null type android.app.UiModeManager");
if (((UiModeManager) systemService2).getCurrentModeType() == 4) {
z2 = true;
}
}
vungleExt.setTv(z2);
vungleExt.setSideloadEnabled(this.platform.isSideLoaded());
vungleExt.setSdCardAvailable(this.platform.isSdCardPresent() ? 1 : 0);
copy.setUa(this.uaString);
copy.setExt(vungleExt);
} catch (Throwable th) {
throw th;
}
return copy;
}
public static /* synthetic */ CommonRequestBody.User getUserBody$default(VungleApiClient vungleApiClient, boolean z, int i, Object obj) {
if ((i & 1) != 0) {
z = false;
}
return vungleApiClient.getUserBody(z);
}
private final CommonRequestBody.User getUserBody(boolean z) {
CommonRequestBody.User user = new CommonRequestBody.User((CommonRequestBody.GDPR) null, (CommonRequestBody.CCPA) null, (CommonRequestBody.COPPA) null, (FirstPartyData) null, (CommonRequestBody.IAB) null, 31, (DefaultConstructorMarker) null);
PrivacyManager privacyManager = PrivacyManager.INSTANCE;
user.setGdpr(new CommonRequestBody.GDPR(privacyManager.getConsentStatus(), privacyManager.getConsentSource(), privacyManager.getConsentTimestamp(), privacyManager.getConsentMessageVersion()));
user.setCcpa(new CommonRequestBody.CCPA(privacyManager.getCcpaStatus()));
if (privacyManager.getCoppaStatus() != COPPA.COPPA_NOTSET) {
user.setCoppa(new CommonRequestBody.COPPA(privacyManager.getCoppaStatus().getValue()));
}
if (privacyManager.shouldSendTCFString()) {
user.setIab(new CommonRequestBody.IAB(privacyManager.getIABTCFString()));
}
if (z) {
user.setFpd(VungleAds.firstPartyData);
}
return user;
}
public static /* synthetic */ CommonRequestBody.RequestExt getExtBody$default(VungleApiClient vungleApiClient, boolean z, int i, Object obj) {
if ((i & 1) != 0) {
z = false;
}
return vungleApiClient.getExtBody(z);
}
private final CommonRequestBody.RequestExt getExtBody(boolean z) {
String generateSignals;
String configExtension = ConfigManager.INSTANCE.getConfigExtension();
if (configExtension != null && configExtension.length() == 0) {
configExtension = this.filePreferences.getString(Cookie.CONFIG_EXTENSION);
}
if (z) {
try {
generateSignals = getSignalManager().generateSignals();
} catch (Exception e) {
Logger.Companion.e(TAG, "Couldn't convert signals for sending. Error: " + e.getMessage());
}
if ((configExtension != null || configExtension.length() == 0) && (generateSignals == null || generateSignals.length() == 0)) {
return null;
}
return new CommonRequestBody.RequestExt(configExtension, generateSignals, Long.valueOf(ConfigManager.INSTANCE.configLastValidatedTimestamp()));
}
generateSignals = null;
if (configExtension != null) {
}
return null;
}
@Retention(RetentionPolicy.SOURCE)
public @interface ConnectionTypeDetail {
public static final String CDMA_1XRTT = "cdma_1xrtt";
public static final String CDMA_EVDO_0 = "cdma_evdo_0";
public static final String CDMA_EVDO_A = "cdma_evdo_a";
public static final String CDMA_EVDO_B = "cdma_evdo_b";
public static final Companion Companion = Companion.$$INSTANCE;
public static final String EDGE = "edge";
public static final String FIFTH_G = "5g";
public static final String GPRS = "gprs";
public static final String HRPD = "hrpd";
public static final String HSDPA = "hsdpa";
public static final String HSUPA = "hsupa";
public static final String LTE = "lte";
public static final String UNKNOWN = "unknown";
public static final String WCDMA = "wcdma";
public static final class Companion {
static final /* synthetic */ Companion $$INSTANCE = new Companion();
public static final String CDMA_1XRTT = "cdma_1xrtt";
public static final String CDMA_EVDO_0 = "cdma_evdo_0";
public static final String CDMA_EVDO_A = "cdma_evdo_a";
public static final String CDMA_EVDO_B = "cdma_evdo_b";
public static final String EDGE = "edge";
public static final String FIFTH_G = "5g";
public static final String GPRS = "gprs";
public static final String HRPD = "hrpd";
public static final String HSDPA = "hsdpa";
public static final String HSUPA = "hsupa";
public static final String LTE = "lte";
public static final String UNKNOWN = "unknown";
public static final String WCDMA = "wcdma";
private Companion() {
}
}
}
@VisibleForTesting
public final Boolean isGooglePlayServicesAvailable() {
if (this.isGooglePlayServicesAvailable == null) {
this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromCookie();
}
if (this.isGooglePlayServicesAvailable == null) {
this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromAPI();
}
return this.isGooglePlayServicesAvailable;
}
private final String getConnectionType() {
if (PermissionChecker.checkCallingOrSelfPermission(this.applicationContext, "android.permission.ACCESS_NETWORK_STATE") != 0) {
return null;
}
Object systemService = this.applicationContext.getSystemService("connectivity");
Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.net.ConnectivityManager");
NetworkInfo activeNetworkInfo = ((ConnectivityManager) systemService).getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return "NONE";
}
int type = activeNetworkInfo.getType();
return type != 0 ? (type == 1 || type == 6) ? "WIFI" : type != 7 ? type != 9 ? "UNKNOWN" : "ETHERNET" : "BLUETOOTH" : "MOBILE";
}
public final String getConnectionTypeDetail() {
if (PermissionChecker.checkCallingOrSelfPermission(this.applicationContext, "android.permission.ACCESS_NETWORK_STATE") != 0) {
return null;
}
Object systemService = this.applicationContext.getSystemService("connectivity");
Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.net.ConnectivityManager");
NetworkInfo activeNetworkInfo = ((ConnectivityManager) systemService).getActiveNetworkInfo();
return activeNetworkInfo != null ? getConnectionTypeDetail(activeNetworkInfo.getSubtype()) : "unknown";
}
}