正在查看: Fancy Optimizer v4.6.3 应用的 VungleApiClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Fancy Optimizer v4.6.3 应用的 VungleApiClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.vungle.warren;
import android.annotation.SuppressLint;
import android.app.UiModeManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.provider.Settings;
import android.security.NetworkSecurityPolicy;
import android.support.v4.media.b;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.webkit.URLUtil;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.PermissionChecker;
import androidx.core.util.Consumer;
import androidx.core.util.a;
import com.google.android.gms.common.GoogleApiAvailabilityLight;
import com.google.gson.g;
import com.google.gson.j;
import com.unity3d.services.core.request.metrics.MetricCommonTags;
import com.vungle.warren.PrivacyManager;
import com.vungle.warren.error.VungleException;
import com.vungle.warren.model.AdvertisementDBAdapter;
import com.vungle.warren.model.AdvertisingInfo;
import com.vungle.warren.model.CacheBust;
import com.vungle.warren.model.CacheBustDBAdapter;
import com.vungle.warren.model.Cookie;
import com.vungle.warren.model.JsonUtil;
import com.vungle.warren.model.ReportDBAdapter;
import com.vungle.warren.model.SessionData;
import com.vungle.warren.model.VisionDataDBAdapter;
import com.vungle.warren.network.APIFactory;
import com.vungle.warren.network.Call;
import com.vungle.warren.network.Response;
import com.vungle.warren.network.VungleApi;
import com.vungle.warren.omsdk.OMInjector;
import com.vungle.warren.persistence.CacheManager;
import com.vungle.warren.persistence.DatabaseHelper;
import com.vungle.warren.persistence.Repository;
import com.vungle.warren.session.SessionAttribute;
import com.vungle.warren.session.SessionEvent;
import com.vungle.warren.utility.TimeoutProvider;
import com.vungle.warren.utility.platform.Platform;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import no.MediaType;
import no.RequestBody;
import no.t;
import no.u;
import no.v;
import no.x;
import no.y;
import no.z;
import ro.f;
import yo.d;
import yo.e;
import yo.l;
import yo.s;
public class VungleApiClient {
private static final String AMAZON_ADVERTISING_ID = "amazon_advertising_id";
public static final String ANDROID_ID = "android_id";
private static String BASE_URL = null;
public static final String GAID = "gaid";
private static final String ID = "id";
public static final String IFA = "ifa";
private static final String TAG = "com.vungle.warren.VungleApiClient";
protected static WrapperFramework WRAPPER_FRAMEWORK_SELECTED;
private static String headerUa;
private static Set<t> logInterceptors;
private static Set<t> networkInterceptors;
private VungleApi api;
private j appBody;
private j baseDeviceInfo;
private String biLoggingEndpoint;
private String cacheBustEndpoint;
private CacheManager cacheManager;
private u client;
private Context context;
private boolean enableOm;
private VungleApi gzipApi;
private Boolean isGooglePlayServicesAvailable;
private String logEndpoint;
private String newEndpoint;
private final OMInjector omInjector;
private final Platform platform;
private String reportAdEndpoint;
private Repository repository;
private String requestAdEndpoint;
private String riEndpoint;
private VungleApi timeoutApi;
private TimeoutProvider timeoutProvider;
private boolean willPlayAdEnabled;
private String willPlayAdEndpoint;
private int willPlayAdTimeout;
private Map<String, Long> retryAfterDataMap = new ConcurrentHashMap();
private String uaString = System.getProperty("http.agent");
public static class ClearTextTrafficException extends IOException {
public ClearTextTrafficException(String str) {
super(str);
}
}
@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 String EDGE = "edge";
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 class GzipRequestInterceptor implements t {
private static final String CONTENT_ENCODING = "Content-Encoding";
private static final String GZIP = "gzip";
private RequestBody gzip(final RequestBody requestBody) throws IOException {
final d dVar = new d();
l lVar = new l(dVar);
Logger logger = s.a;
yo.u uVar = new yo.u(lVar);
requestBody.writeTo(uVar);
uVar.close();
return new RequestBody() {
@Override
public long contentLength() {
return dVar.d;
}
@Override
public MediaType contentType() {
return requestBody.contentType();
}
@Override
public void writeTo(@NonNull e eVar) throws IOException {
eVar.h(dVar.t());
}
};
}
@Override
@NonNull
public y intercept(@NonNull t.a aVar) throws IOException {
f fVar = (f) aVar;
x xVar = fVar.e;
if (xVar.d == null || xVar.a(CONTENT_ENCODING) != null) {
return fVar.a(xVar);
}
x.a aVar2 = new x.a(xVar);
aVar2.c.f(CONTENT_ENCODING, GZIP);
aVar2.b(xVar.b, gzip(xVar.d));
return fVar.a(aVar2.a());
}
}
@Keep
public enum WrapperFramework {
admob,
air,
cocos2dx,
corona,
dfp,
heyzap,
marmalade,
mopub,
unity,
fyber,
ironsource,
upsight,
appodeal,
aerserv,
adtoapp,
tapdaq,
vunglehbs,
max,
none
}
static {
headerUa = (Platform.MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? "VungleAmazon/" : "VungleDroid/").concat(BuildConfig.VERSION_NAME);
BASE_URL = "https://ads.api.vungle.com/";
networkInterceptors = new HashSet();
logInterceptors = new HashSet();
}
public VungleApiClient(@NonNull Context context, @NonNull CacheManager cacheManager, @NonNull Repository repository, @NonNull OMInjector oMInjector, @NonNull Platform platform) {
this.cacheManager = cacheManager;
this.context = context.getApplicationContext();
this.repository = repository;
this.omInjector = oMInjector;
this.platform = platform;
t tVar = new t() {
@Override
public y intercept(t.a aVar) throws IOException {
f fVar = (f) aVar;
x xVar = fVar.e;
String e = xVar.a.e();
Long l = (Long) VungleApiClient.this.retryAfterDataMap.get(e);
if (l != null) {
long seconds = TimeUnit.MILLISECONDS.toSeconds(l.longValue() - System.currentTimeMillis());
if (seconds > 0) {
y.a aVar2 = new y.a();
aVar2.a = xVar;
aVar2.f.a("Retry-After", String.valueOf(seconds));
aVar2.c = 500;
aVar2.b = v.HTTP_1_1;
aVar2.d = "Server is busy";
aVar2.g = z.create(MediaType.b("application/json; charset=utf-8"), "{\"Error\":\"Retry-After\"}");
return aVar2.a();
}
VungleApiClient.this.retryAfterDataMap.remove(e);
}
y a = fVar.a(xVar);
int i = a.e;
if (i == 429 || i == 500 || i == 502 || i == 503) {
String c = a.h.c("Retry-After");
if (!TextUtils.isEmpty(c)) {
try {
long parseLong = Long.parseLong(c);
if (parseLong > 0) {
VungleApiClient.this.retryAfterDataMap.put(e, Long.valueOf((parseLong * 1000) + System.currentTimeMillis()));
}
} catch (NumberFormatException unused) {
Log.d(VungleApiClient.TAG, "Retry-After value is not an valid value");
}
}
}
return a;
}
};
u.b bVar = new u.b();
bVar.e.add(tVar);
this.client = new u(bVar);
bVar.e.add(new GzipRequestInterceptor());
u uVar = new u(bVar);
APIFactory aPIFactory = new APIFactory(this.client, BASE_URL);
Vungle vungle = Vungle._instance;
this.api = aPIFactory.createAPI(vungle.appID);
this.gzipApi = new APIFactory(uVar, BASE_URL).createAPI(vungle.appID);
this.timeoutProvider = (TimeoutProvider) ServiceLocator.getInstance(context).getService(TimeoutProvider.class);
}
private String getConnectionTypeDetail(int i) {
switch (i) {
case 1:
return ConnectionTypeDetail.GPRS;
case 2:
return ConnectionTypeDetail.EDGE;
case 3:
case 10:
case 11:
default:
return "unknown";
case 4:
return ConnectionTypeDetail.WCDMA;
case 5:
return ConnectionTypeDetail.CDMA_EVDO_0;
case 6:
return ConnectionTypeDetail.CDMA_EVDO_A;
case 7:
return ConnectionTypeDetail.CDMA_1XRTT;
case 8:
return ConnectionTypeDetail.HSDPA;
case 9:
return ConnectionTypeDetail.HSUPA;
case VungleException.NO_AUTO_CACHED_PLACEMENT:
return ConnectionTypeDetail.CDMA_EVDO_B;
case VungleException.PLACEMENT_NOT_FOUND:
return ConnectionTypeDetail.LTE;
case VungleException.SERVER_RETRY_ERROR:
return ConnectionTypeDetail.HRPD;
}
}
@SuppressLint({"HardwareIds", "NewApi"})
private j getDeviceBody() throws IllegalStateException {
return getDeviceBody(false);
}
private j getExtBody() {
Cookie cookie = (Cookie) this.repository.load(Cookie.CONFIG_EXTENSION, Cookie.class).get(this.timeoutProvider.getTimeout(), TimeUnit.MILLISECONDS);
String string = cookie != null ? cookie.getString(Cookie.CONFIG_EXTENSION) : "";
if (TextUtils.isEmpty(string)) {
return null;
}
j jVar = new j();
jVar.q(Cookie.CONFIG_EXTENSION, string);
return jVar;
}
public static String getHeaderUa() {
return headerUa;
}
private String getUserAgentFromCookie() {
Cookie cookie = (Cookie) this.repository.load(Cookie.USER_AGENT_ID_COOKIE, Cookie.class).get();
if (cookie == null) {
return System.getProperty("http.agent");
}
String string = cookie.getString(Cookie.USER_AGENT_ID_COOKIE);
return TextUtils.isEmpty(string) ? System.getProperty("http.agent") : string;
}
private j getUserBody() {
String str;
String str2;
long j;
String str3;
j jVar = new j();
Cookie cookie = (Cookie) this.repository.load(Cookie.CONSENT_COOKIE, Cookie.class).get(this.timeoutProvider.getTimeout(), TimeUnit.MILLISECONDS);
if (cookie != null) {
str = cookie.getString("consent_status");
str2 = cookie.getString("consent_source");
j = cookie.getLong(VisionDataDBAdapter.VisionDataColumns.COLUMN_TIMESTAMP).longValue();
str3 = cookie.getString("consent_message_version");
} else {
str = "unknown";
str2 = "no_interaction";
j = 0;
str3 = "";
}
j jVar2 = new j();
jVar2.q("consent_status", str);
jVar2.q("consent_source", str2);
jVar2.p("consent_timestamp", Long.valueOf(j));
jVar2.q("consent_message_version", TextUtils.isEmpty(str3) ? "" : str3);
jVar.n(jVar2, "gdpr");
Cookie cookie2 = (Cookie) this.repository.load(Cookie.CCPA_COOKIE, Cookie.class).get();
String string = cookie2 != null ? cookie2.getString(Cookie.CCPA_CONSENT_STATUS) : "opted_in";
j jVar3 = new j();
jVar3.q(ReportDBAdapter.ReportColumns.COLUMN_REPORT_STATUS, string);
jVar.n(jVar3, "ccpa");
if (PrivacyManager.getInstance().getCoppaStatus() != PrivacyManager.COPPA.COPPA_NOTSET) {
j jVar4 = new j();
jVar4.o(Cookie.COPPA_STATUS_KEY, Boolean.valueOf(PrivacyManager.getInstance().getCoppaStatus().getValue()));
jVar.n(jVar4, Cookie.COPPA_KEY);
}
return jVar;
}
private void initUserAgentLazy() {
this.platform.getUserAgentLazy(new Consumer<String>() {
public void accept(String str) {
if (str == null) {
Log.e(VungleApiClient.TAG, "Cannot Get UserAgent. Setting Default Device UserAgent");
} else {
VungleApiClient.this.uaString = str;
}
}
});
}
public static void setHeaderUa(String str) {
headerUa = str;
}
@VisibleForTesting
public void addPlaySvcAvailabilityInCookie(boolean z) throws DatabaseHelper.DBException {
Cookie cookie = new Cookie(Cookie.IS_PLAY_SERVICE_AVAILABLE);
cookie.putValue(Cookie.IS_PLAY_SERVICE_AVAILABLE, Boolean.valueOf(z));
this.repository.save(cookie);
}
public Call<j> cacheBust(long j) {
if (this.cacheBustEndpoint == null) {
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
j jVar = new j();
jVar.n(getDeviceBody(), "device");
jVar.n(this.appBody, "app");
jVar.n(getUserBody(), "user");
j jVar2 = new j();
jVar2.p(Cookie.LAST_CACHE_BUST, Long.valueOf(j));
jVar.n(jVar2, "request");
return this.gzipApi.cacheBust(getHeaderUa(), this.cacheBustEndpoint, jVar);
}
public boolean canCallWillPlayAd() {
return this.willPlayAdEnabled && !TextUtils.isEmpty(this.willPlayAdEndpoint);
}
public Response config() throws VungleException, IOException {
j jVar = new j();
jVar.n(getDeviceBody(true), "device");
jVar.n(this.appBody, "app");
jVar.n(getUserBody(), "user");
j extBody = getExtBody();
if (extBody != null) {
jVar.n(extBody, "ext");
}
Response<j> execute = this.api.config(getHeaderUa(), jVar).execute();
if (!execute.isSuccessful()) {
return execute;
}
j body = execute.body();
String str = TAG;
Log.d(str, "Config Response: " + body);
if (JsonUtil.hasNonNull(body, "sleep")) {
Log.e(str, "Error Initializing Vungle. Please try again. " + (JsonUtil.hasNonNull(body, "info") ? body.s("info").m() : ""));
throw new VungleException(3);
}
if (!JsonUtil.hasNonNull(body, "endpoints")) {
Log.e(str, "Error Initializing Vungle. Please try again. ");
throw new VungleException(3);
}
j v = body.v("endpoints");
no.s l = no.s.l(v.s("new").m());
no.s l2 = no.s.l(v.s("ads").m());
no.s l3 = no.s.l(v.s("will_play_ad").m());
no.s l4 = no.s.l(v.s("report_ad").m());
no.s l5 = no.s.l(v.s("ri").m());
no.s l6 = no.s.l(v.s("log").m());
no.s l7 = no.s.l(v.s(CacheBustDBAdapter.CacheBustColumns.TABLE_NAME).m());
no.s l8 = no.s.l(v.s("sdk_bi").m());
if (l == null || l2 == null || l3 == null || l4 == null || l5 == null || l6 == null || l7 == null || l8 == null) {
Log.e(str, "Error Initializing Vungle. Please try again. ");
throw new VungleException(3);
}
this.newEndpoint = l.i;
this.requestAdEndpoint = l2.i;
this.willPlayAdEndpoint = l3.i;
this.reportAdEndpoint = l4.i;
this.riEndpoint = l5.i;
this.logEndpoint = l6.i;
this.cacheBustEndpoint = l7.i;
this.biLoggingEndpoint = l8.i;
j v2 = body.v("will_play_ad");
this.willPlayAdTimeout = v2.s("request_timeout").i();
this.willPlayAdEnabled = v2.s("enabled").f();
this.enableOm = JsonUtil.getAsBoolean(body.v("viewability"), "om", false);
if (this.willPlayAdEnabled) {
Log.v(str, "willPlayAd is enabled, generating a timeout client.");
u uVar = this.client;
uVar.getClass();
u.b bVar = new u.b(uVar);
bVar.a(this.willPlayAdTimeout, TimeUnit.MILLISECONDS);
this.timeoutApi = new APIFactory(new u(bVar), "https://api.vungle.com/").createAPI(Vungle._instance.appID);
}
if (getOmEnabled()) {
this.omInjector.init();
} else {
SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.OM_SDK).addData(SessionAttribute.ENABLED, false).build());
}
return execute;
}
public boolean getOmEnabled() {
return this.enableOm;
}
@VisibleForTesting
public Boolean getPlayServicesAvailabilityFromAPI() {
Boolean bool = null;
try {
GoogleApiAvailabilityLight googleApiAvailabilityLight = GoogleApiAvailabilityLight.getInstance();
if (googleApiAvailabilityLight == null) {
return null;
}
bool = Boolean.valueOf(googleApiAvailabilityLight.isGooglePlayServicesAvailable(this.context) == 0);
addPlaySvcAvailabilityInCookie(bool.booleanValue());
return bool;
} catch (Exception unused) {
Log.w(TAG, "Unexpected exception from Play services lib.");
return bool;
} catch (NoClassDefFoundError unused2) {
Log.w(TAG, "Play services Not available");
Boolean bool2 = Boolean.FALSE;
try {
addPlaySvcAvailabilityInCookie(false);
return bool2;
} catch (DatabaseHelper.DBException unused3) {
Log.w(TAG, "Failure to write GPS availability to DB");
return bool2;
}
}
}
@VisibleForTesting
public Boolean getPlayServicesAvailabilityFromCookie() {
Cookie cookie = (Cookie) this.repository.load(Cookie.IS_PLAY_SERVICE_AVAILABLE, Cookie.class).get(this.timeoutProvider.getTimeout(), TimeUnit.MILLISECONDS);
if (cookie != null) {
return cookie.getBoolean(Cookie.IS_PLAY_SERVICE_AVAILABLE);
}
return null;
}
public long getRetryAfterHeaderValue(Response response) {
try {
return Long.parseLong(response.headers().c("Retry-After")) * 1000;
} catch (NumberFormatException unused) {
return 0L;
}
}
public void init() {
init(this.context);
}
@VisibleForTesting
public Boolean isGooglePlayServicesAvailable() {
if (this.isGooglePlayServicesAvailable == null) {
this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromCookie();
}
if (this.isGooglePlayServicesAvailable == null) {
this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromAPI();
}
return this.isGooglePlayServicesAvailable;
}
@VisibleForTesting
public void overrideApi(VungleApi vungleApi) {
this.api = vungleApi;
}
public boolean pingTPAT(String str) throws ClearTextTrafficException, MalformedURLException {
if (TextUtils.isEmpty(str) || no.s.l(str) == null) {
SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.TPAT).addData(SessionAttribute.SUCCESS, false).addData(SessionAttribute.REASON, "Invalid URL").addData(SessionAttribute.URL, str).build());
throw new MalformedURLException(b.l("Invalid URL : ", str));
}
try {
if (!(Build.VERSION.SDK_INT >= 24 ? a.y(NetworkSecurityPolicy.getInstance(), new URL(str).getHost()) : NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted()) && URLUtil.isHttpUrl(str)) {
SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.TPAT).addData(SessionAttribute.SUCCESS, false).addData(SessionAttribute.REASON, "Clear Text Traffic is blocked").addData(SessionAttribute.URL, str).build());
throw new ClearTextTrafficException("Clear Text Traffic is blocked");
}
try {
Response<Void> execute = this.api.pingTPAT(this.uaString, str).execute();
if (execute == null) {
SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.TPAT).addData(SessionAttribute.SUCCESS, false).addData(SessionAttribute.REASON, "Error on pinging TPAT").addData(SessionAttribute.URL, str).build());
return true;
}
if (execute.isSuccessful()) {
return true;
}
SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.TPAT).addData(SessionAttribute.SUCCESS, false).addData(SessionAttribute.REASON, execute.code() + ": " + execute.message()).addData(SessionAttribute.URL, str).build());
return true;
} catch (IOException e) {
SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.TPAT).addData(SessionAttribute.SUCCESS, false).addData(SessionAttribute.REASON, e.getMessage()).addData(SessionAttribute.URL, str).build());
Log.d(TAG, "Error on pinging TPAT");
return false;
}
} catch (MalformedURLException unused) {
SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.TPAT).addData(SessionAttribute.SUCCESS, false).addData(SessionAttribute.REASON, "Invalid URL").addData(SessionAttribute.URL, str).build());
throw new MalformedURLException(b.l("Invalid URL : ", str));
}
}
public Call<j> reportAd(j jVar) {
if (this.reportAdEndpoint == null) {
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
j jVar2 = new j();
jVar2.n(getDeviceBody(), "device");
jVar2.n(this.appBody, "app");
jVar2.n(jVar, "request");
jVar2.n(getUserBody(), "user");
j extBody = getExtBody();
if (extBody != null) {
jVar2.n(extBody, "ext");
}
return this.gzipApi.reportAd(getHeaderUa(), this.reportAdEndpoint, jVar2);
}
public Call<j> reportNew() throws IllegalStateException {
if (this.newEndpoint == null) {
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
HashMap hashMap = new HashMap(2);
g s = this.appBody.s("id");
hashMap.put(AdvertisementDBAdapter.AdvertisementColumns.COLUMN_APP_ID, s != null ? s.m() : "");
j deviceBody = getDeviceBody();
if (PrivacyManager.getInstance().shouldSendAdIds()) {
g s2 = deviceBody.s(IFA);
hashMap.put(IFA, s2 != null ? s2.m() : "");
}
return this.api.reportNew(getHeaderUa(), this.newEndpoint, hashMap);
}
public Call<j> requestAd(String str, String str2, boolean z, @Nullable j jVar) throws IllegalStateException {
if (this.requestAdEndpoint == null) {
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
j jVar2 = new j();
jVar2.n(getDeviceBody(), "device");
jVar2.n(this.appBody, "app");
j userBody = getUserBody();
if (jVar != null) {
userBody.n(jVar, "vision");
}
jVar2.n(userBody, "user");
j extBody = getExtBody();
if (extBody != null) {
jVar2.n(extBody, "ext");
}
j jVar3 = new j();
com.google.gson.e eVar = new com.google.gson.e();
eVar.o(str);
jVar3.n(eVar, "placements");
jVar3.o("header_bidding", Boolean.valueOf(z));
if (!TextUtils.isEmpty(str2)) {
jVar3.q("ad_size", str2);
}
jVar2.n(jVar3, "request");
return this.gzipApi.ads(getHeaderUa(), this.requestAdEndpoint, jVar2);
}
public Call<j> ri(j jVar) {
if (this.riEndpoint == null) {
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
j jVar2 = new j();
jVar2.n(getDeviceBody(), "device");
jVar2.n(this.appBody, "app");
jVar2.n(jVar, "request");
jVar2.n(getUserBody(), "user");
j extBody = getExtBody();
if (extBody != null) {
jVar2.n(extBody, "ext");
}
return this.api.ri(getHeaderUa(), this.riEndpoint, jVar2);
}
public Call<j> sendAnalytics(Collection<CacheBust> collection) {
if (this.biLoggingEndpoint == null) {
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
if (collection == null || collection.isEmpty()) {
throw new IllegalArgumentException("Cannot send analytics when bust and session data is empty");
}
j jVar = new j();
jVar.n(getDeviceBody(), "device");
jVar.n(this.appBody, "app");
j jVar2 = new j();
com.google.gson.e eVar = new com.google.gson.e(collection.size());
for (CacheBust cacheBust : collection) {
for (int i = 0; i < cacheBust.getEventIds().length; i++) {
j jVar3 = new j();
jVar3.q("target", cacheBust.getIdType() == 1 ? "campaign" : VisionDataDBAdapter.VisionDataColumns.COLUMN_CREATIVE);
jVar3.q("id", cacheBust.getId());
jVar3.q("event_id", cacheBust.getEventIds()[i]);
eVar.n(jVar3);
}
}
if (eVar.size() > 0) {
jVar2.n(eVar, CacheBustDBAdapter.CacheBustColumns.TABLE_NAME);
}
jVar.n(jVar2, "request");
return this.gzipApi.sendBiAnalytics(getHeaderUa(), this.biLoggingEndpoint, jVar);
}
public Call<j> sendLog(j jVar) {
if (this.logEndpoint != null) {
return this.gzipApi.sendLog(getHeaderUa(), this.logEndpoint, jVar);
}
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
public Call<j> sendSessionDataAnalytics(@NonNull com.google.gson.e eVar) {
if (this.biLoggingEndpoint == null) {
throw new IllegalStateException("API Client not configured yet! Must call /config first.");
}
j jVar = new j();
jVar.n(getDeviceBody(), "device");
jVar.n(this.appBody, "app");
j jVar2 = new j();
jVar2.n(eVar, "session_events");
jVar.n(jVar2, "request");
return this.gzipApi.sendBiAnalytics(getHeaderUa(), this.biLoggingEndpoint, jVar);
}
public void setAppId(String str) {
setAppId(str, this.appBody);
}
public Call<j> willPlayAd(String str, boolean z, String str2) {
j jVar = new j();
jVar.n(getDeviceBody(), "device");
jVar.n(this.appBody, "app");
jVar.n(getUserBody(), "user");
j jVar2 = new j();
j jVar3 = new j();
jVar3.q("reference_id", str);
jVar3.o("is_auto_cached", Boolean.valueOf(z));
jVar2.n(jVar3, "placement");
jVar2.q(AdvertisementDBAdapter.AdvertisementColumns.COLUMN_AD_TOKEN, str2);
jVar.n(jVar2, "request");
return this.timeoutApi.willPlayAd(getHeaderUa(), this.willPlayAdEndpoint, jVar);
}
@SuppressLint({"HardwareIds", "NewApi"})
private synchronized j getDeviceBody(boolean z) throws IllegalStateException {
j r;
String str;
NetworkInfo activeNetworkInfo;
r = this.baseDeviceInfo.r();
j jVar = new j();
AdvertisingInfo advertisingInfo = this.platform.getAdvertisingInfo();
boolean z2 = advertisingInfo.limitAdTracking;
String str2 = advertisingInfo.advertisingId;
if (PrivacyManager.getInstance().shouldSendAdIds()) {
if (str2 != null) {
jVar.q(Platform.MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? AMAZON_ADVERTISING_ID : GAID, str2);
r.q(IFA, str2);
} else {
String androidId = this.platform.getAndroidId();
r.q(IFA, !TextUtils.isEmpty(androidId) ? androidId : "");
if (!TextUtils.isEmpty(androidId)) {
jVar.q(ANDROID_ID, androidId);
}
}
}
if (!PrivacyManager.getInstance().shouldSendAdIds() || z) {
}
boolean z3 = false;
r.p("lmt", Integer.valueOf(z2 ? 1 : 0));
jVar.o("is_google_play_services_available", Boolean.valueOf(Boolean.TRUE.equals(isGooglePlayServicesAvailable())));
String appSetId = this.platform.getAppSetId();
if (!TextUtils.isEmpty(appSetId)) {
jVar.q("app_set_id", appSetId);
}
Context context = this.context;
Intent registerReceiver = context != null ? context.registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED")) : null;
if (registerReceiver != null) {
int intExtra = registerReceiver.getIntExtra("level", -1);
int intExtra2 = registerReceiver.getIntExtra("scale", -1);
if (intExtra > 0 && intExtra2 > 0) {
jVar.p("battery_level", Float.valueOf(intExtra / intExtra2));
}
int intExtra3 = registerReceiver.getIntExtra(ReportDBAdapter.ReportColumns.COLUMN_REPORT_STATUS, -1);
if (intExtra3 == -1) {
str = "UNKNOWN";
} else {
if (intExtra3 != 2 && intExtra3 != 5) {
str = "NOT_CHARGING";
}
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 = "UNKNOWN";
}
jVar.q("battery_state", str);
PowerManager powerManager = (PowerManager) this.context.getSystemService("power");
jVar.p("battery_saver_enabled", Integer.valueOf((powerManager == null || !powerManager.isPowerSaveMode()) ? 0 : 1));
if (PermissionChecker.checkCallingOrSelfPermission(this.context, "android.permission.ACCESS_NETWORK_STATE") == 0) {
String str3 = "NONE";
String str4 = "unknown";
ConnectivityManager connectivityManager = (ConnectivityManager) this.context.getSystemService("connectivity");
if (connectivityManager != null && (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) != null) {
int type = activeNetworkInfo.getType();
if (type != 0) {
str3 = (type == 1 || type == 6) ? "WIFI" : type != 7 ? type != 9 ? "UNKNOWN" : "ETHERNET" : "BLUETOOTH";
} else {
str3 = "MOBILE";
str4 = getConnectionTypeDetail(activeNetworkInfo.getSubtype());
}
}
jVar.q("connection_type", str3);
jVar.q("connection_type_detail", str4);
if (Build.VERSION.SDK_INT >= 24) {
if (connectivityManager.isActiveNetworkMetered()) {
int c = android.support.v4.media.session.a.c(connectivityManager);
jVar.q("data_saver_status", c != 1 ? c != 2 ? c != 3 ? "UNKNOWN" : "ENABLED" : "WHITELISTED" : "DISABLED");
jVar.p("network_metered", 1);
} else {
jVar.q("data_saver_status", "NOT_APPLICABLE");
jVar.p("network_metered", 0);
}
}
}
jVar.q("locale", Locale.getDefault().toString());
jVar.q("language", Locale.getDefault().getLanguage());
jVar.q("time_zone", TimeZone.getDefault().getID());
AudioManager audioManager = (AudioManager) this.context.getSystemService("audio");
if (audioManager != null) {
int streamMaxVolume = audioManager.getStreamMaxVolume(3);
int streamVolume = audioManager.getStreamVolume(3);
jVar.p("volume_level", Float.valueOf(streamVolume / streamMaxVolume));
jVar.p("sound_enabled", Integer.valueOf(streamVolume > 0 ? 1 : 0));
}
File cache = this.cacheManager.getCache();
cache.getPath();
if (cache.exists() && cache.isDirectory()) {
jVar.p("storage_bytes_available", Long.valueOf(this.cacheManager.getBytesAvailable()));
}
jVar.o("is_tv", Boolean.valueOf(Platform.MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? this.context.getApplicationContext().getPackageManager().hasSystemFeature("amazon.hardware.fire_tv") : ((UiModeManager) this.context.getSystemService("uimode")).getCurrentModeType() == 4));
int i = Build.VERSION.SDK_INT;
jVar.p("os_api_level", Integer.valueOf(i));
jVar.p("app_target_sdk_version", Integer.valueOf(this.context.getApplicationInfo().targetSdkVersion));
if (i >= 24) {
jVar.p("app_min_sdk_version", Integer.valueOf(androidx.core.os.b.a(this.context.getApplicationInfo())));
}
try {
if (i >= 26) {
if (this.context.checkCallingOrSelfPermission("android.permission.REQUEST_INSTALL_PACKAGES") == 0) {
z3 = androidx.core.widget.b.w(this.context.getApplicationContext().getPackageManager());
}
} else if (Settings.Secure.getInt(this.context.getContentResolver(), "install_non_market_apps") == 1) {
z3 = true;
}
} catch (Settings.SettingNotFoundException e) {
Log.e(TAG, "isInstallNonMarketAppsEnabled Settings not found", e);
}
jVar.o("is_sideload_enabled", Boolean.valueOf(z3));
jVar.p("sd_card_available", Integer.valueOf(Environment.getExternalStorageState().equals("mounted") ? 1 : 0));
jVar.q("os_name", Build.FINGERPRINT);
jVar.q("vduid", "");
r.q("ua", this.uaString);
j jVar2 = new j();
j jVar3 = new j();
jVar2.n(jVar3, "vungle");
r.n(jVar2, "ext");
jVar3.n(jVar, Platform.MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? "amazon" : MetricCommonTags.METRIC_COMMON_TAG_PLATFORM_ANDROID);
return r;
}
private void setAppId(String str, j jVar) {
jVar.q("id", str);
}
@VisibleForTesting
public synchronized void init(Context context) {
String str;
j jVar = new j();
jVar.q("bundle", context.getPackageName());
try {
str = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException unused) {
str = null;
}
if (str == null) {
str = "1.0";
}
jVar.q("ver", str);
j jVar2 = new j();
String str2 = Build.MANUFACTURER;
jVar2.q("make", str2);
jVar2.q("model", Build.MODEL);
jVar2.q("osv", Build.VERSION.RELEASE);
jVar2.q("carrier", ((TelephonyManager) context.getSystemService("phone")).getNetworkOperatorName());
jVar2.q("os", Platform.MANUFACTURER_AMAZON.equals(str2) ? "amazon" : MetricCommonTags.METRIC_COMMON_TAG_PLATFORM_ANDROID);
DisplayMetrics displayMetrics = new DisplayMetrics();
((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
jVar2.p("w", Integer.valueOf(displayMetrics.widthPixels));
jVar2.p("h", Integer.valueOf(displayMetrics.heightPixels));
try {
String userAgent = this.platform.getUserAgent();
this.uaString = userAgent;
jVar2.q("ua", userAgent);
initUserAgentLazy();
} catch (Exception e) {
Log.e(TAG, "Cannot Get UserAgent. Setting Default Device UserAgent." + e.getLocalizedMessage());
}
this.baseDeviceInfo = jVar2;
this.appBody = jVar;
this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromAPI();
}
}