Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.broadcast.BroadcastError;
import com.unity3d.services.core.broadcast.BroadcastMonitor;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import org.json.JSONArray;
import org.json.JSONException;
/* loaded from: classes4.dex */
public class Broadcast {
@WebViewExposed
public static void addBroadcastListener(String str, JSONArray jSONArray, WebViewCallback webViewCallback) {
addBroadcastListener(str, null, jSONArray, webViewCallback);
}
@WebViewExposed
public static void addBroadcastListener(String str, String str2, JSONArray jSONArray, WebViewCallback webViewCallback) {
try {
if (jSONArray.length() > 0) {
String[] strArr = new String[jSONArray.length()];
for (int i = 0; i < jSONArray.length(); i++) {
strArr[i] = jSONArray.getString(i);
}
BroadcastMonitor.getInstance().addBroadcastListener(str, str2, strArr);
}
webViewCallback.invoke(new Object[0]);
} catch (JSONException unused) {
webViewCallback.error(BroadcastError.JSON_ERROR, new Object[0]);
}
}
@WebViewExposed
public static void removeBroadcastListener(String str, WebViewCallback webViewCallback) {
BroadcastMonitor.getInstance().removeBroadcastListener(str);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void removeAllBroadcastListeners(WebViewCallback webViewCallback) {
BroadcastMonitor.getInstance().removeAllBroadcastListeners();
webViewCallback.invoke(new Object[0]);
}
}

View File

@@ -0,0 +1,363 @@
package com.unity3d.services.core.api;
import android.annotation.TargetApi;
import android.media.MediaMetadataRetriever;
import android.util.Base64;
import android.util.SparseArray;
import com.unity3d.services.core.cache.CacheDirectory;
import com.unity3d.services.core.cache.CacheDirectoryType;
import com.unity3d.services.core.cache.CacheError;
import com.unity3d.services.core.cache.CacheThread;
import com.unity3d.services.core.device.Device;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.request.WebRequestError;
import com.unity3d.services.core.webview.bridge.SharedInstances;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class Cache {
@WebViewExposed
public static void download(String str, String str2, JSONArray jSONArray, Boolean bool, WebViewCallback webViewCallback) {
if (CacheThread.isActive()) {
webViewCallback.error(CacheError.FILE_ALREADY_CACHING, new Object[0]);
return;
}
if (!Device.isActiveNetworkConnected()) {
webViewCallback.error(CacheError.NO_INTERNET, new Object[0]);
return;
}
try {
CacheThread.download(str, fileIdToFilename(str2), Request.getHeadersMap(jSONArray), bool.booleanValue(), SharedInstances.INSTANCE.getWebViewEventSender());
webViewCallback.invoke(new Object[0]);
} catch (Exception e) {
DeviceLog.exception("Error mapping headers for the request", e);
webViewCallback.error(WebRequestError.MAPPING_HEADERS_FAILED, str, str2);
}
}
@WebViewExposed
public static void stop(WebViewCallback webViewCallback) {
if (!CacheThread.isActive()) {
webViewCallback.error(CacheError.NOT_CACHING, new Object[0]);
} else {
CacheThread.cancel();
webViewCallback.invoke(new Object[0]);
}
}
@WebViewExposed
public static void isCaching(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(CacheThread.isActive()));
}
@WebViewExposed
public static void getFileContent(String str, String str2, WebViewCallback webViewCallback) {
String encodeToString;
String fileIdToFilename = fileIdToFilename(str);
File file = new File(fileIdToFilename);
if (!file.exists()) {
webViewCallback.error(CacheError.FILE_NOT_FOUND, str, fileIdToFilename);
return;
}
try {
byte[] readFileBytes = Utilities.readFileBytes(file);
if (str2 == null) {
webViewCallback.error(CacheError.UNSUPPORTED_ENCODING, str, fileIdToFilename, str2);
return;
}
if (str2.equals("UTF-8")) {
encodeToString = Charset.forName("UTF-8").decode(ByteBuffer.wrap(readFileBytes)).toString();
} else if (str2.equals("Base64")) {
encodeToString = Base64.encodeToString(readFileBytes, 2);
} else {
webViewCallback.error(CacheError.UNSUPPORTED_ENCODING, str, fileIdToFilename, str2);
return;
}
webViewCallback.invoke(encodeToString);
} catch (IOException e) {
webViewCallback.error(CacheError.FILE_IO_ERROR, str, fileIdToFilename, e.getMessage() + ", " + e.getClass().getName());
}
}
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:55:0x0067 -> B:25:0x0079). Please report as a decompilation issue!!! */
@WebViewExposed
public static void setFileContent(String str, String str2, String str3, WebViewCallback webViewCallback) {
FileOutputStream fileOutputStream;
String fileIdToFilename = fileIdToFilename(str);
try {
byte[] bytes = str3.getBytes("UTF-8");
if (str2 != null && str2.length() > 0) {
if (str2.equals("Base64")) {
bytes = Base64.decode(str3, 2);
} else if (!str2.equals("UTF-8")) {
webViewCallback.error(CacheError.UNSUPPORTED_ENCODING, str, fileIdToFilename, str2);
return;
}
}
FileOutputStream fileOutputStream2 = null;
try {
try {
try {
fileOutputStream = new FileOutputStream(fileIdToFilename);
} catch (Throwable th) {
th = th;
}
} catch (FileNotFoundException unused) {
} catch (IOException unused2) {
}
} catch (Exception e) {
DeviceLog.exception("Error closing FileOutputStream", e);
}
try {
fileOutputStream.write(bytes);
fileOutputStream.flush();
try {
fileOutputStream.close();
} catch (Exception e2) {
DeviceLog.exception("Error closing FileOutputStream", e2);
}
webViewCallback.invoke(new Object[0]);
} catch (FileNotFoundException unused3) {
fileOutputStream2 = fileOutputStream;
webViewCallback.error(CacheError.FILE_NOT_FOUND, str, fileIdToFilename, str2);
if (fileOutputStream2 != null) {
fileOutputStream2.close();
}
} catch (IOException unused4) {
fileOutputStream2 = fileOutputStream;
webViewCallback.error(CacheError.FILE_IO_ERROR, str, fileIdToFilename, str2);
if (fileOutputStream2 != null) {
fileOutputStream2.close();
}
} catch (Throwable th2) {
th = th2;
fileOutputStream2 = fileOutputStream;
if (fileOutputStream2 != null) {
try {
fileOutputStream2.close();
} catch (Exception e3) {
DeviceLog.exception("Error closing FileOutputStream", e3);
}
}
throw th;
}
} catch (UnsupportedEncodingException unused5) {
webViewCallback.error(CacheError.UNSUPPORTED_ENCODING, str, fileIdToFilename, str2);
}
}
@WebViewExposed
public static void getFiles(WebViewCallback webViewCallback) {
File cacheDirectory = SdkProperties.getCacheDirectory();
if (cacheDirectory == null) {
return;
}
DeviceLog.debug("Unity Ads cache: checking app directory for Unity Ads cached files");
File[] listFiles = cacheDirectory.listFiles(new FilenameFilter() { // from class: com.unity3d.services.core.api.Cache.1
@Override // java.io.FilenameFilter
public boolean accept(File file, String str) {
return str.startsWith(SdkProperties.getCacheFilePrefix());
}
});
if (listFiles == null || listFiles.length == 0) {
webViewCallback.invoke(new JSONArray());
}
try {
JSONArray jSONArray = new JSONArray();
for (File file : listFiles) {
String substring = file.getName().substring(SdkProperties.getCacheFilePrefix().length());
DeviceLog.debug("Unity Ads cache: found " + substring + ", " + file.length() + " bytes");
jSONArray.put(getFileJson(substring));
}
webViewCallback.invoke(jSONArray);
} catch (JSONException e) {
DeviceLog.exception("Error creating JSON", e);
webViewCallback.error(CacheError.JSON_ERROR, new Object[0]);
}
}
@WebViewExposed
public static void getFileInfo(String str, WebViewCallback webViewCallback) {
try {
webViewCallback.invoke(getFileJson(str));
} catch (JSONException e) {
DeviceLog.exception("Error creating JSON", e);
webViewCallback.error(CacheError.JSON_ERROR, new Object[0]);
}
}
@WebViewExposed
public static void getFilePath(String str, WebViewCallback webViewCallback) {
if (new File(fileIdToFilename(str)).exists()) {
webViewCallback.invoke(fileIdToFilename(str));
} else {
webViewCallback.error(CacheError.FILE_NOT_FOUND, new Object[0]);
}
}
@WebViewExposed
public static void deleteFile(String str, WebViewCallback webViewCallback) {
if (new File(fileIdToFilename(str)).delete()) {
webViewCallback.invoke(new Object[0]);
} else {
webViewCallback.error(CacheError.FILE_IO_ERROR, new Object[0]);
}
}
@WebViewExposed
public static void getHash(String str, WebViewCallback webViewCallback) {
webViewCallback.invoke(Utilities.Sha256(str));
}
@WebViewExposed
public static void setTimeouts(Integer num, Integer num2, WebViewCallback webViewCallback) {
CacheThread.setConnectTimeout(num.intValue());
CacheThread.setReadTimeout(num2.intValue());
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void getTimeouts(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(CacheThread.getConnectTimeout()), Integer.valueOf(CacheThread.getReadTimeout()));
}
@WebViewExposed
public static void setProgressInterval(Integer num, WebViewCallback webViewCallback) {
CacheThread.setProgressInterval(num.intValue());
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void getProgressInterval(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(CacheThread.getProgressInterval()));
}
@WebViewExposed
public static void getFreeSpace(WebViewCallback webViewCallback) {
webViewCallback.invoke(Long.valueOf(Device.getFreeSpace(SdkProperties.getCacheDirectory())));
}
@WebViewExposed
public static void getTotalSpace(WebViewCallback webViewCallback) {
webViewCallback.invoke(Long.valueOf(Device.getTotalSpace(SdkProperties.getCacheDirectory())));
}
@WebViewExposed
public static void getMetaData(String str, JSONArray jSONArray, WebViewCallback webViewCallback) {
try {
SparseArray<String> metaData = getMetaData(fileIdToFilename(str), jSONArray);
JSONArray jSONArray2 = new JSONArray();
for (int i = 0; i < metaData.size(); i++) {
JSONArray jSONArray3 = new JSONArray();
jSONArray3.put(metaData.keyAt(i));
jSONArray3.put(metaData.valueAt(i));
jSONArray2.put(jSONArray3);
}
webViewCallback.invoke(jSONArray2);
} catch (IOException e) {
webViewCallback.error(CacheError.FILE_IO_ERROR, e.getMessage());
} catch (RuntimeException e2) {
webViewCallback.error(CacheError.INVALID_ARGUMENT, e2.getMessage());
} catch (JSONException e3) {
webViewCallback.error(CacheError.JSON_ERROR, e3.getMessage());
}
}
@WebViewExposed
public static void getCacheDirectoryType(WebViewCallback webViewCallback) {
CacheDirectory cacheDirectoryObject = SdkProperties.getCacheDirectoryObject();
if (cacheDirectoryObject == null || cacheDirectoryObject.getCacheDirectory(ClientProperties.getApplicationContext()) == null) {
webViewCallback.error(CacheError.CACHE_DIRECTORY_NULL, new Object[0]);
return;
}
if (!cacheDirectoryObject.getCacheDirectory(ClientProperties.getApplicationContext()).exists()) {
webViewCallback.error(CacheError.CACHE_DIRECTORY_DOESNT_EXIST, new Object[0]);
return;
}
CacheDirectoryType type = cacheDirectoryObject.getType();
if (type == null) {
webViewCallback.error(CacheError.CACHE_DIRECTORY_TYPE_NULL, new Object[0]);
} else {
webViewCallback.invoke(type.name());
}
}
@WebViewExposed
public static void getCacheDirectoryExists(WebViewCallback webViewCallback) {
File cacheDirectory = SdkProperties.getCacheDirectory();
if (cacheDirectory == null) {
webViewCallback.error(CacheError.CACHE_DIRECTORY_NULL, new Object[0]);
} else {
webViewCallback.invoke(Boolean.valueOf(cacheDirectory.exists()));
}
}
@WebViewExposed
public static void recreateCacheDirectory(WebViewCallback webViewCallback) {
if (SdkProperties.getCacheDirectory().exists()) {
webViewCallback.error(CacheError.CACHE_DIRECTORY_EXISTS, new Object[0]);
return;
}
SdkProperties.setCacheDirectory(null);
if (SdkProperties.getCacheDirectory() == null) {
webViewCallback.error(CacheError.CACHE_DIRECTORY_NULL, new Object[0]);
} else {
webViewCallback.invoke(new Object[0]);
}
}
@TargetApi(10)
private static SparseArray<String> getMetaData(String str, JSONArray jSONArray) throws JSONException, IOException, RuntimeException {
File file = new File(str);
SparseArray<String> sparseArray = new SparseArray<>();
if (file.exists()) {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(file.getAbsolutePath());
for (int i = 0; i < jSONArray.length(); i++) {
int i2 = jSONArray.getInt(i);
String extractMetadata = mediaMetadataRetriever.extractMetadata(i2);
if (extractMetadata != null) {
sparseArray.put(i2, extractMetadata);
}
}
return sparseArray;
}
throw new IOException("File: " + file.getAbsolutePath() + " doesn't exist");
}
private static String fileIdToFilename(String str) {
if (SdkProperties.getCacheDirectory() == null) {
return "";
}
return SdkProperties.getCacheDirectory() + "/" + SdkProperties.getCacheFilePrefix() + str;
}
private static JSONObject getFileJson(String str) throws JSONException {
JSONObject jSONObject = new JSONObject();
jSONObject.put("id", str);
File file = new File(fileIdToFilename(str));
if (file.exists()) {
jSONObject.put("found", true);
jSONObject.put("size", file.length());
jSONObject.put("mtime", file.lastModified());
} else {
jSONObject.put("found", false);
}
return jSONObject;
}
}

View File

@@ -0,0 +1,13 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.properties.MadeWithUnityDetector;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
/* loaded from: classes4.dex */
public class ClassDetection {
@WebViewExposed
public static void isMadeWithUnity(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(MadeWithUnityDetector.isMadeWithUnity()));
}
}

View File

@@ -0,0 +1,14 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.connectivity.ConnectivityMonitor;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
/* loaded from: classes4.dex */
public class Connectivity {
@WebViewExposed
public static void setConnectionMonitoring(Boolean bool, WebViewCallback webViewCallback) {
ConnectivityMonitor.setConnectionMonitoring(bool.booleanValue());
webViewCallback.invoke(new Object[0]);
}
}

View File

@@ -0,0 +1,533 @@
package com.unity3d.services.core.api;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import com.unity3d.ads.core.data.datasource.AndroidDynamicDeviceInfoDataSource;
import com.unity3d.services.core.device.Device;
import com.unity3d.services.core.device.DeviceError;
import com.unity3d.services.core.device.VolumeChangeMonitor;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class DeviceInfo {
private static final VolumeChangeMonitor volumeChangeMonitor = (VolumeChangeMonitor) Utilities.getService(VolumeChangeMonitor.class);
public enum StorageType {
EXTERNAL,
INTERNAL
}
@WebViewExposed
public static void getAdvertisingTrackingId(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getAdvertisingTrackingId());
}
@WebViewExposed
public static void getLimitAdTrackingFlag(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.isLimitAdTrackingEnabled()));
}
@WebViewExposed
public static void getOpenAdvertisingTrackingId(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getOpenAdvertisingTrackingId());
}
@WebViewExposed
public static void getLimitOpenAdTrackingFlag(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.isLimitOpenAdTrackingEnabled()));
}
@WebViewExposed
public static void getApiLevel(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getApiLevel()));
}
@WebViewExposed
public static void getExtensionVersion(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getExtensionVersion()));
}
@WebViewExposed
public static void getOsVersion(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getOsVersion());
}
@WebViewExposed
public static void getManufacturer(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getManufacturer());
}
@WebViewExposed
public static void getModel(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getModel());
}
@WebViewExposed
public static void getScreenLayout(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getScreenLayout()));
}
@WebViewExposed
public static void getDisplayMetricDensity(WebViewCallback webViewCallback) {
webViewCallback.invoke(Float.valueOf(Device.getDisplayMetricDensity()));
}
@WebViewExposed
public static void getScreenDensity(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getScreenDensity()));
}
@WebViewExposed
public static void getScreenWidth(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getScreenWidth()));
}
@WebViewExposed
public static void getScreenHeight(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getScreenHeight()));
}
@WebViewExposed
public static void getTimeZone(Boolean bool, WebViewCallback webViewCallback) {
webViewCallback.invoke(TimeZone.getDefault().getDisplayName(bool.booleanValue(), 0, Locale.US));
}
@WebViewExposed
public static void getTimeZoneOffset(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000));
}
@WebViewExposed
public static void getConnectionType(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getConnectionType());
}
@WebViewExposed
public static void getNetworkType(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getNetworkType()));
}
@WebViewExposed
public static void getNetworkMetered(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.getNetworkMetered()));
}
@WebViewExposed
public static void getNetworkOperator(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getNetworkOperator());
}
@WebViewExposed
public static void getNetworkOperatorName(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getNetworkOperatorName());
}
@WebViewExposed
public static void getNetworkCountryISO(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getNetworkCountryISO());
}
@WebViewExposed
public static void isRooted(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.isRooted()));
}
@WebViewExposed
public static void isAdbEnabled(WebViewCallback webViewCallback) {
Boolean isAdbEnabled = Device.isAdbEnabled();
if (isAdbEnabled != null) {
webViewCallback.invoke(isAdbEnabled);
} else {
webViewCallback.error(DeviceError.COULDNT_GET_ADB_STATUS, new Object[0]);
}
}
@WebViewExposed
public static void getPackageInfo(WebViewCallback webViewCallback) {
if (ClientProperties.getApplicationContext() != null) {
String appName = ClientProperties.getAppName();
try {
webViewCallback.invoke(Device.getPackageInfo(ClientProperties.getApplicationContext().getPackageManager()));
return;
} catch (PackageManager.NameNotFoundException unused) {
webViewCallback.error(DeviceError.APPLICATION_INFO_NOT_AVAILABLE, appName);
return;
} catch (JSONException e) {
webViewCallback.error(DeviceError.JSON_ERROR, e.getMessage());
return;
}
}
webViewCallback.error(DeviceError.APPLICATION_CONTEXT_NULL, new Object[0]);
}
@WebViewExposed
public static void getUniqueEventId(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getUniqueEventId());
}
@WebViewExposed
public static void getHeadset(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.isWiredHeadsetOn()));
}
@WebViewExposed
public static void getSystemProperty(String str, String str2, WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getSystemProperty(str, str2));
}
@WebViewExposed
public static void getRingerMode(WebViewCallback webViewCallback) {
int ringerMode = Device.getRingerMode();
if (ringerMode > -1) {
webViewCallback.invoke(Integer.valueOf(ringerMode));
return;
}
if (ringerMode == -2) {
webViewCallback.error(DeviceError.AUDIOMANAGER_NULL, Integer.valueOf(ringerMode));
return;
}
if (ringerMode == -1) {
webViewCallback.error(DeviceError.APPLICATION_CONTEXT_NULL, Integer.valueOf(ringerMode));
return;
}
DeviceLog.error("Unhandled ringerMode error: " + ringerMode);
}
@WebViewExposed
public static void getSystemLanguage(WebViewCallback webViewCallback) {
webViewCallback.invoke(Locale.getDefault().toString());
}
@WebViewExposed
public static void getDeviceVolume(Integer num, WebViewCallback webViewCallback) {
int streamVolume = Device.getStreamVolume(num.intValue());
if (streamVolume > -1) {
webViewCallback.invoke(Integer.valueOf(streamVolume));
return;
}
if (streamVolume == -2) {
webViewCallback.error(DeviceError.AUDIOMANAGER_NULL, Integer.valueOf(streamVolume));
return;
}
if (streamVolume == -1) {
webViewCallback.error(DeviceError.APPLICATION_CONTEXT_NULL, Integer.valueOf(streamVolume));
return;
}
DeviceLog.error("Unhandled deviceVolume error: " + streamVolume);
}
@WebViewExposed
public static void getDeviceMaxVolume(Integer num, WebViewCallback webViewCallback) {
int streamMaxVolume = Device.getStreamMaxVolume(num.intValue());
if (streamMaxVolume > -1) {
webViewCallback.invoke(Integer.valueOf(streamMaxVolume));
return;
}
if (streamMaxVolume == -2) {
webViewCallback.error(DeviceError.AUDIOMANAGER_NULL, Integer.valueOf(streamMaxVolume));
return;
}
if (streamMaxVolume == -1) {
webViewCallback.error(DeviceError.APPLICATION_CONTEXT_NULL, Integer.valueOf(streamMaxVolume));
return;
}
DeviceLog.error("Unhandled deviceMaxVolume error: " + streamMaxVolume);
}
@WebViewExposed
public static void registerVolumeChangeListener(Integer num, WebViewCallback webViewCallback) {
volumeChangeMonitor.registerVolumeChangeListener(num.intValue());
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void unregisterVolumeChangeListener(Integer num, WebViewCallback webViewCallback) {
volumeChangeMonitor.unregisterVolumeChangeListener(num.intValue());
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void getScreenBrightness(WebViewCallback webViewCallback) {
int screenBrightness = Device.getScreenBrightness();
if (screenBrightness > -1) {
webViewCallback.invoke(Integer.valueOf(screenBrightness));
return;
}
if (screenBrightness == -1) {
webViewCallback.error(DeviceError.APPLICATION_CONTEXT_NULL, Integer.valueOf(screenBrightness));
return;
}
DeviceLog.error("Unhandled screenBrightness error: " + screenBrightness);
}
private static StorageType getStorageTypeFromString(String str) {
try {
return StorageType.valueOf(str);
} catch (IllegalArgumentException e) {
DeviceLog.exception("Illegal argument: " + str, e);
return null;
}
}
/* renamed from: com.unity3d.services.core.api.DeviceInfo$1, reason: invalid class name */
public static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] $SwitchMap$com$unity3d$services$core$api$DeviceInfo$StorageType;
static {
int[] iArr = new int[StorageType.values().length];
$SwitchMap$com$unity3d$services$core$api$DeviceInfo$StorageType = iArr;
try {
iArr[StorageType.INTERNAL.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$unity3d$services$core$api$DeviceInfo$StorageType[StorageType.EXTERNAL.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
private static File getFileForStorageType(StorageType storageType) {
int i = AnonymousClass1.$SwitchMap$com$unity3d$services$core$api$DeviceInfo$StorageType[storageType.ordinal()];
if (i == 1) {
return ClientProperties.getApplicationContext().getCacheDir();
}
if (i == 2) {
return ClientProperties.getApplicationContext().getExternalCacheDir();
}
DeviceLog.error("Unhandled storagetype: " + storageType);
return null;
}
@WebViewExposed
public static void getFreeSpace(String str, WebViewCallback webViewCallback) {
StorageType storageTypeFromString = getStorageTypeFromString(str);
if (storageTypeFromString == null) {
webViewCallback.error(DeviceError.INVALID_STORAGETYPE, str);
return;
}
long freeSpace = Device.getFreeSpace(getFileForStorageType(storageTypeFromString));
if (freeSpace > -1) {
webViewCallback.invoke(Long.valueOf(freeSpace));
} else {
webViewCallback.error(DeviceError.COULDNT_GET_STORAGE_LOCATION, Long.valueOf(freeSpace));
}
}
@WebViewExposed
public static void getTotalSpace(String str, WebViewCallback webViewCallback) {
StorageType storageTypeFromString = getStorageTypeFromString(str);
if (storageTypeFromString == null) {
webViewCallback.error(DeviceError.INVALID_STORAGETYPE, str);
return;
}
long totalSpace = Device.getTotalSpace(getFileForStorageType(storageTypeFromString));
if (totalSpace > -1) {
webViewCallback.invoke(Long.valueOf(totalSpace));
} else {
webViewCallback.error(DeviceError.COULDNT_GET_STORAGE_LOCATION, Long.valueOf(totalSpace));
}
}
@WebViewExposed
public static void getBatteryLevel(WebViewCallback webViewCallback) {
webViewCallback.invoke(Float.valueOf(Device.getBatteryLevel()));
}
@WebViewExposed
public static void getBatteryStatus(WebViewCallback webViewCallback) {
webViewCallback.invoke(Integer.valueOf(Device.getBatteryStatus()));
}
@WebViewExposed
public static void getFreeMemory(WebViewCallback webViewCallback) {
webViewCallback.invoke(Long.valueOf(Device.getFreeMemory()));
}
@WebViewExposed
public static void getTotalMemory(WebViewCallback webViewCallback) {
webViewCallback.invoke(Long.valueOf(Device.getTotalMemory()));
}
@WebViewExposed
public static void getGLVersion(WebViewCallback webViewCallback) {
String gLVersion = Device.getGLVersion();
if (gLVersion != null) {
webViewCallback.invoke(gLVersion);
} else {
webViewCallback.error(DeviceError.COULDNT_GET_GL_VERSION, new Object[0]);
}
}
@WebViewExposed
public static void getApkDigest(WebViewCallback webViewCallback) {
try {
webViewCallback.invoke(Device.getApkDigest());
} catch (Exception e) {
webViewCallback.error(DeviceError.COULDNT_GET_DIGEST, e.toString());
}
}
@WebViewExposed
public static void getCertificateFingerprint(WebViewCallback webViewCallback) {
String certificateFingerprint = Device.getCertificateFingerprint();
if (certificateFingerprint != null) {
webViewCallback.invoke(certificateFingerprint);
} else {
webViewCallback.error(DeviceError.COULDNT_GET_FINGERPRINT, new Object[0]);
}
}
@WebViewExposed
public static void getBoard(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getBoard());
}
@WebViewExposed
public static void getBootloader(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getBootloader());
}
@WebViewExposed
public static void getBrand(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getBrand());
}
@WebViewExposed
public static void getDevice(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getDevice());
}
@WebViewExposed
public static void getHardware(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getHardware());
}
@WebViewExposed
public static void getHost(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getHost());
}
@WebViewExposed
public static void getProduct(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getProduct());
}
@WebViewExposed
public static void getFingerprint(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getFingerprint());
}
@WebViewExposed
public static void getSupportedAbis(WebViewCallback webViewCallback) {
JSONArray jSONArray = new JSONArray();
Iterator<String> it = Device.getSupportedAbis().iterator();
while (it.hasNext()) {
jSONArray.put(it.next());
}
webViewCallback.invoke(jSONArray);
}
@WebViewExposed
public static void getSensorList(WebViewCallback webViewCallback) {
JSONArray jSONArray = new JSONArray();
List<Sensor> sensorList = Device.getSensorList();
if (sensorList != null) {
for (Sensor sensor : sensorList) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("name", sensor.getName());
jSONObject.put("type", sensor.getType());
jSONObject.put("vendor", sensor.getVendor());
jSONObject.put("maximumRange", sensor.getMaximumRange());
jSONObject.put("power", sensor.getPower());
jSONObject.put("version", sensor.getVersion());
jSONObject.put("resolution", sensor.getResolution());
jSONObject.put("minDelay", sensor.getMinDelay());
jSONArray.put(jSONObject);
} catch (JSONException e) {
webViewCallback.error(DeviceError.JSON_ERROR, e.getMessage());
return;
}
}
}
webViewCallback.invoke(jSONArray);
}
@WebViewExposed
public static void getProcessInfo(WebViewCallback webViewCallback) {
JSONObject jSONObject = new JSONObject();
Map<String, String> processInfo = Device.getProcessInfo();
if (processInfo != null) {
try {
if (processInfo.containsKey(AndroidDynamicDeviceInfoDataSource.KEY_STAT_CONTENT)) {
jSONObject.put(AndroidDynamicDeviceInfoDataSource.KEY_STAT_CONTENT, processInfo.get(AndroidDynamicDeviceInfoDataSource.KEY_STAT_CONTENT));
}
if (processInfo.containsKey("uptime")) {
jSONObject.put("uptime", processInfo.get("uptime"));
}
} catch (Exception e) {
DeviceLog.exception("Error while constructing process info", e);
}
}
webViewCallback.invoke(jSONObject);
}
@WebViewExposed
public static void isUSBConnected(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.isUSBConnected()));
}
@WebViewExposed
public static void getCPUCount(WebViewCallback webViewCallback) {
webViewCallback.invoke(Long.valueOf(Device.getCPUCount()));
}
@WebViewExposed
public static void getUptime(WebViewCallback webViewCallback) {
webViewCallback.invoke(Long.valueOf(Device.getUptime()));
}
@WebViewExposed
public static void getElapsedRealtime(WebViewCallback webViewCallback) {
webViewCallback.invoke(Long.valueOf(Device.getElapsedRealtime()));
}
@WebViewExposed
public static void getBuildId(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getBuildId());
}
@WebViewExposed
public static void getBuildVersionIncremental(WebViewCallback webViewCallback) {
webViewCallback.invoke(Device.getBuildVersionIncremental());
}
@WebViewExposed
public static void hasX264HWDecoder(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.hasX264Decoder()));
}
@WebViewExposed
public static void hasX265HWDecoder(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.hasX265Decoder()));
}
@WebViewExposed
public static void hasAV1HWDecoder(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(Device.hasAV1Decoder()));
}
}

View File

@@ -0,0 +1,19 @@
package com.unity3d.services.core.api;
/* loaded from: classes4.dex */
public enum DownloadLatestWebViewStatus {
INIT_QUEUE_NULL(0),
INIT_QUEUE_NOT_EMPTY(1),
MISSING_LATEST_CONFIG(2),
BACKGROUND_DOWNLOAD_STARTED(3);
private final int value;
public int getValue() {
return this.value;
}
DownloadLatestWebViewStatus(int i) {
this.value = i;
}
}

View File

@@ -0,0 +1,259 @@
package com.unity3d.services.core.api;
import android.app.Activity;
import android.net.Uri;
import com.facebook.share.internal.ShareConstants;
import com.unity3d.ads.core.domain.HandleInvocationsFromAdViewer;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import java.lang.ref.WeakReference;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class Intent {
private static WeakReference<Activity> _activeActivity;
public enum IntentError {
COULDNT_PARSE_EXTRAS,
COULDNT_PARSE_CATEGORIES,
INTENT_WAS_NULL,
JSON_EXCEPTION,
ACTIVITY_WAS_NULL
}
@WebViewExposed
public static void launch(JSONObject jSONObject, WebViewCallback webViewCallback) {
android.content.Intent intent;
String str = (String) jSONObject.opt("className");
String str2 = (String) jSONObject.opt(HandleInvocationsFromAdViewer.KEY_PACKAGE_NAME);
String str3 = (String) jSONObject.opt("action");
String str4 = (String) jSONObject.opt(ShareConstants.MEDIA_URI);
String str5 = (String) jSONObject.opt("mimeType");
JSONArray jSONArray = (JSONArray) jSONObject.opt("categories");
Integer num = (Integer) jSONObject.opt("flags");
JSONArray jSONArray2 = (JSONArray) jSONObject.opt("extras");
if (str2 != null && str == null && str3 == null && str5 == null) {
intent = ClientProperties.getApplicationContext().getPackageManager().getLaunchIntentForPackage(str2);
if (intent != null && num.intValue() > -1) {
intent.addFlags(num.intValue());
}
} else {
android.content.Intent intent2 = new android.content.Intent();
if (str != null && str2 != null) {
intent2.setClassName(str2, str);
} else if (str2 != null) {
intent2.setPackage(str2);
}
if (str3 != null) {
intent2.setAction(str3);
}
if (str4 != null && str5 != null) {
intent2.setDataAndType(Uri.parse(str4), str5);
} else if (str4 != null) {
intent2.setData(Uri.parse(str4));
} else if (str5 != null) {
intent2.setType(str5);
}
if (num != null && num.intValue() > -1) {
intent2.setFlags(num.intValue());
}
if (!setCategories(intent2, jSONArray)) {
webViewCallback.error(IntentError.COULDNT_PARSE_CATEGORIES, jSONArray);
}
if (!setExtras(intent2, jSONArray2)) {
webViewCallback.error(IntentError.COULDNT_PARSE_EXTRAS, jSONArray2);
}
intent = intent2;
}
if (intent != null) {
if (getStartingActivity() != null) {
getStartingActivity().startActivity(intent);
webViewCallback.invoke(new Object[0]);
return;
} else {
webViewCallback.error(IntentError.ACTIVITY_WAS_NULL, new Object[0]);
return;
}
}
webViewCallback.error(IntentError.INTENT_WAS_NULL, new Object[0]);
}
private static boolean setCategories(android.content.Intent intent, JSONArray jSONArray) {
if (jSONArray == null || jSONArray.length() <= 0) {
return true;
}
for (int i = 0; i < jSONArray.length(); i++) {
try {
intent.addCategory(jSONArray.getString(i));
} catch (Exception e) {
DeviceLog.exception("Couldn't parse categories for intent", e);
return false;
}
}
return true;
}
private static boolean setExtras(android.content.Intent intent, JSONArray jSONArray) {
if (jSONArray == null) {
return true;
}
for (int i = 0; i < jSONArray.length(); i++) {
try {
JSONObject jSONObject = jSONArray.getJSONObject(i);
if (!setExtra(intent, jSONObject.getString("key"), jSONObject.get("value"))) {
return false;
}
} catch (Exception e) {
DeviceLog.exception("Couldn't parse extras", e);
return false;
}
}
return true;
}
private static boolean setExtra(android.content.Intent intent, String str, Object obj) {
if (obj instanceof String) {
intent.putExtra(str, (String) obj);
return true;
}
if (obj instanceof Integer) {
intent.putExtra(str, ((Integer) obj).intValue());
return true;
}
if (obj instanceof Double) {
intent.putExtra(str, ((Double) obj).doubleValue());
return true;
}
if (obj instanceof Boolean) {
intent.putExtra(str, ((Boolean) obj).booleanValue());
return true;
}
DeviceLog.error("Unable to parse launch intent extra " + str);
return false;
}
private static Activity getStartingActivity() {
WeakReference<Activity> weakReference = _activeActivity;
if (weakReference != null && weakReference.get() != null) {
return _activeActivity.get();
}
if (ClientProperties.getActivity() != null) {
return ClientProperties.getActivity();
}
return null;
}
public static void setActiveActivity(Activity activity) {
if (activity == null) {
_activeActivity = null;
} else {
_activeActivity = new WeakReference<>(activity);
}
}
public static void removeActiveActivity(Activity activity) {
WeakReference<Activity> weakReference = _activeActivity;
if (weakReference == null || weakReference.get() == null || activity == null || !activity.equals(_activeActivity.get())) {
return;
}
_activeActivity = null;
}
@WebViewExposed
public static void canOpenIntent(JSONObject jSONObject, WebViewCallback webViewCallback) {
try {
webViewCallback.invoke(Boolean.valueOf(checkIntentResolvable(intentFromMetadata(jSONObject))));
} catch (IntentException e) {
DeviceLog.exception("Couldn't resolve intent", e);
webViewCallback.error(e.getError(), e.getField());
}
}
@WebViewExposed
public static void canOpenIntents(JSONArray jSONArray, WebViewCallback webViewCallback) {
JSONObject jSONObject = new JSONObject();
int length = jSONArray.length();
for (int i = 0; i < length; i++) {
JSONObject optJSONObject = jSONArray.optJSONObject(i);
try {
jSONObject.put(optJSONObject.optString("id"), checkIntentResolvable(intentFromMetadata(optJSONObject)));
} catch (IntentException e) {
DeviceLog.exception("Exception parsing intent", e);
webViewCallback.error(e.getError(), e.getField());
return;
} catch (JSONException e2) {
webViewCallback.error(IntentError.JSON_EXCEPTION, e2.getMessage());
return;
}
}
webViewCallback.invoke(jSONObject);
}
private static boolean checkIntentResolvable(android.content.Intent intent) {
return ClientProperties.getApplicationContext().getPackageManager().resolveActivity(intent, 0) != null;
}
private static android.content.Intent intentFromMetadata(JSONObject jSONObject) throws IntentException {
String str = (String) jSONObject.opt("className");
String str2 = (String) jSONObject.opt(HandleInvocationsFromAdViewer.KEY_PACKAGE_NAME);
String str3 = (String) jSONObject.opt("action");
String str4 = (String) jSONObject.opt(ShareConstants.MEDIA_URI);
String str5 = (String) jSONObject.opt("mimeType");
JSONArray jSONArray = (JSONArray) jSONObject.opt("categories");
Integer num = (Integer) jSONObject.opt("flags");
JSONArray jSONArray2 = (JSONArray) jSONObject.opt("extras");
if (str2 != null && str == null && str3 == null && str5 == null) {
android.content.Intent launchIntentForPackage = ClientProperties.getApplicationContext().getPackageManager().getLaunchIntentForPackage(str2);
if (launchIntentForPackage == null || num.intValue() <= -1) {
return launchIntentForPackage;
}
launchIntentForPackage.addFlags(num.intValue());
return launchIntentForPackage;
}
android.content.Intent intent = new android.content.Intent();
if (str != null && str2 != null) {
intent.setClassName(str2, str);
}
if (str3 != null) {
intent.setAction(str3);
}
if (str4 != null) {
intent.setData(Uri.parse(str4));
}
if (str5 != null) {
intent.setType(str5);
}
if (num != null && num.intValue() > -1) {
intent.setFlags(num.intValue());
}
if (!setCategories(intent, jSONArray)) {
throw new IntentException(IntentError.COULDNT_PARSE_CATEGORIES, jSONArray);
}
if (setExtras(intent, jSONArray2)) {
return intent;
}
throw new IntentException(IntentError.COULDNT_PARSE_EXTRAS, jSONArray2);
}
public static class IntentException extends Exception {
private IntentError error;
private Object field;
public IntentError getError() {
return this.error;
}
public Object getField() {
return this.field;
}
public IntentException(IntentError intentError, Object obj) {
this.error = intentError;
this.field = obj;
}
}
}

View File

@@ -0,0 +1,62 @@
package com.unity3d.services.core.api;
import android.annotation.TargetApi;
import com.unity3d.services.core.lifecycle.LifecycleError;
import com.unity3d.services.core.lifecycle.LifecycleListener;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
@TargetApi(14)
/* loaded from: classes4.dex */
public class Lifecycle {
private static LifecycleListener _listener;
public static LifecycleListener getLifecycleListener() {
return _listener;
}
public static void setLifecycleListener(LifecycleListener lifecycleListener) {
_listener = lifecycleListener;
}
@WebViewExposed
public static void register(JSONArray jSONArray, WebViewCallback webViewCallback) {
if (ClientProperties.getApplication() != null) {
if (getLifecycleListener() == null) {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < jSONArray.length(); i++) {
try {
arrayList.add((String) jSONArray.get(i));
} catch (JSONException unused) {
webViewCallback.error(LifecycleError.JSON_ERROR, new Object[0]);
return;
}
}
setLifecycleListener(new LifecycleListener(arrayList));
ClientProperties.getApplication().registerActivityLifecycleCallbacks(getLifecycleListener());
webViewCallback.invoke(new Object[0]);
return;
}
webViewCallback.error(LifecycleError.LISTENER_NOT_NULL, new Object[0]);
return;
}
webViewCallback.error(LifecycleError.APPLICATION_NULL, new Object[0]);
}
@WebViewExposed
public static void unregister(WebViewCallback webViewCallback) {
if (ClientProperties.getApplication() != null) {
if (getLifecycleListener() != null) {
ClientProperties.getApplication().unregisterActivityLifecycleCallbacks(getLifecycleListener());
setLifecycleListener(null);
}
webViewCallback.invoke(new Object[0]);
return;
}
webViewCallback.error(LifecycleError.APPLICATION_NULL, new Object[0]);
}
}

View File

@@ -0,0 +1,75 @@
package com.unity3d.services.core.api;
import android.annotation.TargetApi;
import android.content.Context;
import com.unity3d.services.ads.adunit.AdUnitError;
import com.unity3d.services.ads.api.AdUnit;
import com.unity3d.services.core.device.DeviceError;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import java.util.ArrayList;
import org.json.JSONArray;
/* loaded from: classes4.dex */
public class Permissions {
@WebViewExposed
public static void getPermissions(WebViewCallback webViewCallback) {
if (ClientProperties.getApplicationContext() == null) {
webViewCallback.error(DeviceError.APPLICATION_CONTEXT_NULL, new Object[0]);
return;
}
try {
JSONArray jSONArray = new JSONArray();
Context applicationContext = ClientProperties.getApplicationContext();
String[] strArr = applicationContext.getPackageManager().getPackageInfo(applicationContext.getPackageName(), 4096).requestedPermissions;
if (strArr != null) {
for (String str : strArr) {
jSONArray.put(str);
}
webViewCallback.invoke(jSONArray);
return;
}
webViewCallback.error(PermissionsError.NO_REQUESTED_PERMISSIONS, new Object[0]);
} catch (Exception e) {
webViewCallback.error(PermissionsError.COULDNT_GET_PERMISSIONS, e.getMessage());
}
}
@WebViewExposed
public static void checkPermission(String str, WebViewCallback webViewCallback) {
if (ClientProperties.getApplicationContext() == null) {
webViewCallback.error(DeviceError.APPLICATION_CONTEXT_NULL, new Object[0]);
return;
}
try {
Context applicationContext = ClientProperties.getApplicationContext();
webViewCallback.invoke(Integer.valueOf(applicationContext.getPackageManager().checkPermission(str, applicationContext.getPackageName())));
} catch (Exception e) {
webViewCallback.error(PermissionsError.ERROR_CHECKING_PERMISSION, e.getMessage());
}
}
@WebViewExposed
@TargetApi(23)
public static void requestPermissions(JSONArray jSONArray, Integer num, WebViewCallback webViewCallback) {
if (AdUnit.getAdUnitActivity() == null) {
webViewCallback.error(AdUnitError.ADUNIT_NULL, new Object[0]);
return;
}
if (jSONArray == null || jSONArray.length() < 1) {
webViewCallback.error(PermissionsError.NO_REQUESTED_PERMISSIONS, new Object[0]);
return;
}
try {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < jSONArray.length(); i++) {
arrayList.add(jSONArray.getString(i));
}
AdUnit.getAdUnitActivity().requestPermissions((String[]) arrayList.toArray(new String[arrayList.size()]), num.intValue());
webViewCallback.invoke(new Object[0]);
} catch (Exception e) {
webViewCallback.error(PermissionsError.ERROR_REQUESTING_PERMISSIONS, e.getMessage());
}
}
}

View File

@@ -0,0 +1,9 @@
package com.unity3d.services.core.api;
/* loaded from: classes4.dex */
enum PermissionsError {
COULDNT_GET_PERMISSIONS,
NO_REQUESTED_PERMISSIONS,
ERROR_CHECKING_PERMISSION,
ERROR_REQUESTING_PERMISSIONS
}

View File

@@ -0,0 +1,100 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.preferences.AndroidPreferences;
import com.unity3d.services.core.preferences.PreferencesError;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
/* loaded from: classes4.dex */
public class Preferences {
@WebViewExposed
public static void hasKey(String str, String str2, WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(AndroidPreferences.hasKey(str, str2)));
}
@WebViewExposed
public static void getString(String str, String str2, WebViewCallback webViewCallback) {
String string = AndroidPreferences.getString(str, str2);
if (string != null) {
webViewCallback.invoke(string);
} else {
webViewCallback.error(PreferencesError.COULDNT_GET_VALUE, str, str2);
}
}
@WebViewExposed
public static void getInt(String str, String str2, WebViewCallback webViewCallback) {
Integer integer = AndroidPreferences.getInteger(str, str2);
if (integer != null) {
webViewCallback.invoke(integer);
} else {
webViewCallback.error(PreferencesError.COULDNT_GET_VALUE, str, str2);
}
}
@WebViewExposed
public static void getLong(String str, String str2, WebViewCallback webViewCallback) {
Long l = AndroidPreferences.getLong(str, str2);
if (l != null) {
webViewCallback.invoke(l);
} else {
webViewCallback.error(PreferencesError.COULDNT_GET_VALUE, str, str2);
}
}
@WebViewExposed
public static void getBoolean(String str, String str2, WebViewCallback webViewCallback) {
Boolean bool = AndroidPreferences.getBoolean(str, str2);
if (bool != null) {
webViewCallback.invoke(bool);
} else {
webViewCallback.error(PreferencesError.COULDNT_GET_VALUE, str, str2);
}
}
@WebViewExposed
public static void getFloat(String str, String str2, WebViewCallback webViewCallback) {
Float f = AndroidPreferences.getFloat(str, str2);
if (f != null) {
webViewCallback.invoke(f);
} else {
webViewCallback.error(PreferencesError.COULDNT_GET_VALUE, str, str2);
}
}
@WebViewExposed
public static void setString(String str, String str2, String str3, WebViewCallback webViewCallback) {
AndroidPreferences.setString(str, str2, str3);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void setInt(String str, String str2, Integer num, WebViewCallback webViewCallback) {
AndroidPreferences.setInteger(str, str2, num);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void setLong(String str, String str2, Long l, WebViewCallback webViewCallback) {
AndroidPreferences.setLong(str, str2, l);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void setBoolean(String str, String str2, Boolean bool, WebViewCallback webViewCallback) {
AndroidPreferences.setBoolean(str, str2, bool);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void setFloat(String str, String str2, Double d, WebViewCallback webViewCallback) {
AndroidPreferences.setFloat(str, str2, d);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void removeKey(String str, String str2, WebViewCallback webViewCallback) {
AndroidPreferences.removeKey(str, str2);
webViewCallback.invoke(new Object[0]);
}
}

View File

@@ -0,0 +1,161 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.request.IWebRequestListener;
import com.unity3d.services.core.request.WebRequest;
import com.unity3d.services.core.request.WebRequestError;
import com.unity3d.services.core.request.WebRequestEvent;
import com.unity3d.services.core.request.WebRequestThread;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
/* loaded from: classes4.dex */
public class Request {
@WebViewExposed
public static void get(final String str, String str2, JSONArray jSONArray, Integer num, Integer num2, WebViewCallback webViewCallback) {
if (jSONArray != null && jSONArray.length() == 0) {
jSONArray = null;
}
try {
WebRequestThread.request(str2, WebRequest.RequestType.GET, getHeadersMap(jSONArray), null, num, num2, new IWebRequestListener() { // from class: com.unity3d.services.core.api.Request.1
@Override // com.unity3d.services.core.request.IWebRequestListener
public void onComplete(String str3, String str4, int i, Map<String, List<String>> map) {
try {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.COMPLETE, str, str3, str4, Integer.valueOf(i), Request.getResponseHeadersMap(map));
} catch (Exception e) {
DeviceLog.exception("Error parsing response headers", e);
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.FAILED, str, str3, "Error parsing response headers");
}
}
@Override // com.unity3d.services.core.request.IWebRequestListener
public void onFailed(String str3, String str4) {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.FAILED, str, str3, str4);
}
});
webViewCallback.invoke(str);
} catch (Exception e) {
DeviceLog.exception("Error mapping headers for the request", e);
webViewCallback.error(WebRequestError.MAPPING_HEADERS_FAILED, str);
}
}
@WebViewExposed
public static void post(final String str, String str2, String str3, JSONArray jSONArray, Integer num, Integer num2, WebViewCallback webViewCallback) {
String str4 = (str3 == null || str3.length() != 0) ? str3 : null;
if (jSONArray != null && jSONArray.length() == 0) {
jSONArray = null;
}
try {
WebRequestThread.request(str2, WebRequest.RequestType.POST, getHeadersMap(jSONArray), str4, num, num2, new IWebRequestListener() { // from class: com.unity3d.services.core.api.Request.2
@Override // com.unity3d.services.core.request.IWebRequestListener
public void onComplete(String str5, String str6, int i, Map<String, List<String>> map) {
try {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.COMPLETE, str, str5, str6, Integer.valueOf(i), Request.getResponseHeadersMap(map));
} catch (Exception e) {
DeviceLog.exception("Error parsing response headers", e);
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.FAILED, str, str5, "Error parsing response headers");
}
}
@Override // com.unity3d.services.core.request.IWebRequestListener
public void onFailed(String str5, String str6) {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.FAILED, str, str5, str6);
}
});
webViewCallback.invoke(str);
} catch (Exception e) {
DeviceLog.exception("Error mapping headers for the request", e);
webViewCallback.error(WebRequestError.MAPPING_HEADERS_FAILED, str);
}
}
@WebViewExposed
public static void head(final String str, String str2, JSONArray jSONArray, Integer num, Integer num2, WebViewCallback webViewCallback) {
if (jSONArray != null && jSONArray.length() == 0) {
jSONArray = null;
}
try {
WebRequestThread.request(str2, WebRequest.RequestType.HEAD, getHeadersMap(jSONArray), num, num2, new IWebRequestListener() { // from class: com.unity3d.services.core.api.Request.3
@Override // com.unity3d.services.core.request.IWebRequestListener
public void onComplete(String str3, String str4, int i, Map<String, List<String>> map) {
try {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.COMPLETE, str, str3, str4, Integer.valueOf(i), Request.getResponseHeadersMap(map));
} catch (Exception e) {
DeviceLog.exception("Error parsing response headers", e);
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.FAILED, str, str3, "Error parsing response headers");
}
}
@Override // com.unity3d.services.core.request.IWebRequestListener
public void onFailed(String str3, String str4) {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.REQUEST, WebRequestEvent.FAILED, str, str3, str4);
}
});
webViewCallback.invoke(str);
} catch (Exception e) {
DeviceLog.exception("Error mapping headers for the request", e);
webViewCallback.error(WebRequestError.MAPPING_HEADERS_FAILED, str);
}
}
@WebViewExposed
public static void setConcurrentRequestCount(Integer num, WebViewCallback webViewCallback) {
WebRequestThread.setConcurrentRequestCount(num.intValue());
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void setMaximumPoolSize(Integer num, WebViewCallback webViewCallback) {
WebRequestThread.setMaximumPoolSize(num.intValue());
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void setKeepAliveTime(Integer num, WebViewCallback webViewCallback) {
WebRequestThread.setKeepAliveTime(num.longValue());
webViewCallback.invoke(new Object[0]);
}
public static JSONArray getResponseHeadersMap(Map<String, List<String>> map) {
JSONArray jSONArray = new JSONArray();
if (map != null && map.size() > 0) {
for (String str : map.keySet()) {
JSONArray jSONArray2 = null;
for (String str2 : map.get(str)) {
JSONArray jSONArray3 = new JSONArray();
jSONArray3.put(str);
jSONArray3.put(str2);
jSONArray2 = jSONArray3;
}
jSONArray.put(jSONArray2);
}
}
return jSONArray;
}
public static HashMap<String, List<String>> getHeadersMap(JSONArray jSONArray) throws JSONException {
if (jSONArray == null) {
return null;
}
HashMap<String, List<String>> hashMap = new HashMap<>();
for (int i = 0; i < jSONArray.length(); i++) {
JSONArray jSONArray2 = (JSONArray) jSONArray.get(i);
List<String> list = hashMap.get(jSONArray2.getString(0));
if (list == null) {
list = new ArrayList<>();
}
list.add(jSONArray2.getString(1));
hashMap.put(jSONArray2.getString(0), list);
}
return hashMap;
}
}

View File

@@ -0,0 +1,36 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.request.IResolveHostListener;
import com.unity3d.services.core.request.ResolveHostError;
import com.unity3d.services.core.request.ResolveHostEvent;
import com.unity3d.services.core.request.WebRequestThread;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
/* loaded from: classes4.dex */
public class Resolve {
@WebViewExposed
public static void resolve(final String str, String str2, WebViewCallback webViewCallback) {
if (WebRequestThread.resolve(str2, new IResolveHostListener() { // from class: com.unity3d.services.core.api.Resolve.1
@Override // com.unity3d.services.core.request.IResolveHostListener
public void onResolve(String str3, String str4) {
if (WebViewApp.getCurrentApp() != null) {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.RESOLVE, ResolveHostEvent.COMPLETE, str, str3, str4);
}
}
@Override // com.unity3d.services.core.request.IResolveHostListener
public void onFailed(String str3, ResolveHostError resolveHostError, String str4) {
if (WebViewApp.getCurrentApp() != null) {
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.RESOLVE, ResolveHostEvent.FAILED, str, str3, resolveHostError.name(), str4);
}
}
})) {
webViewCallback.invoke(str);
} else {
webViewCallback.error(ResolveHostError.INVALID_HOST, str);
}
}
}

View File

@@ -0,0 +1,114 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.configuration.InitializeThread;
import com.unity3d.services.core.configuration.PrivacyConfigStorage;
import com.unity3d.services.core.device.Device;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.properties.Session;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
/* loaded from: classes4.dex */
public class Sdk {
@WebViewExposed
public static void loadComplete(WebViewCallback webViewCallback) {
DeviceLog.debug("Web Application loaded");
WebViewApp.getCurrentApp().setWebAppLoaded(true);
Object[] objArr = new Object[18];
objArr[0] = ClientProperties.getGameId();
objArr[1] = Boolean.valueOf(SdkProperties.isTestMode());
objArr[2] = ClientProperties.getAppName();
objArr[3] = ClientProperties.getAppVersion();
objArr[4] = Integer.valueOf(SdkProperties.getVersionCode());
objArr[5] = SdkProperties.getVersionName();
objArr[6] = Boolean.valueOf(ClientProperties.isAppDebuggable());
objArr[7] = SdkProperties.getConfigUrl();
objArr[8] = WebViewApp.getCurrentApp().getConfiguration().getWebViewUrl();
objArr[9] = WebViewApp.getCurrentApp().getConfiguration().getWebViewHash();
objArr[10] = WebViewApp.getCurrentApp().getConfiguration().getWebViewVersion();
objArr[11] = Long.valueOf(SdkProperties.getInitializationTime());
objArr[12] = Boolean.valueOf(SdkProperties.isReinitialized());
objArr[13] = Boolean.TRUE;
objArr[14] = Boolean.valueOf(SdkProperties.getLatestConfiguration() != null);
objArr[15] = Long.valueOf(Device.getElapsedRealtime());
objArr[16] = WebViewApp.getCurrentApp().getConfiguration().getStateId();
objArr[17] = PrivacyConfigStorage.getInstance().getPrivacyConfig().getPrivacyStatus().toLowerCase();
webViewCallback.invoke(objArr);
}
@WebViewExposed
public static void initComplete(WebViewCallback webViewCallback) {
DeviceLog.debug("Web Application initialized");
SdkProperties.setInitialized(true);
WebViewApp.getCurrentApp().setWebAppInitialized(true);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void initError(String str, Integer num, WebViewCallback webViewCallback) {
WebViewApp.getCurrentApp().setWebAppFailureMessage(str);
WebViewApp.getCurrentApp().setWebAppFailureCode(num.intValue());
WebViewApp.getCurrentApp().setWebAppInitialized(false);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void getTrrData(WebViewCallback webViewCallback) {
webViewCallback.invoke(WebViewApp.getCurrentApp().getConfiguration().getRawConfigData().toString());
}
@WebViewExposed
public static void getSharedSessionID(WebViewCallback webViewCallback) {
webViewCallback.invoke(Session.Default.getId());
}
@WebViewExposed
public static void setDebugMode(Boolean bool, WebViewCallback webViewCallback) {
SdkProperties.setDebugMode(bool.booleanValue());
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void getDebugMode(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(SdkProperties.getDebugMode()));
}
@WebViewExposed
public static void logError(String str, WebViewCallback webViewCallback) {
DeviceLog.error(str);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void logWarning(String str, WebViewCallback webViewCallback) {
DeviceLog.warning(str);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void logInfo(String str, WebViewCallback webViewCallback) {
DeviceLog.info(str);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void logDebug(String str, WebViewCallback webViewCallback) {
DeviceLog.debug(str);
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void reinitialize(WebViewCallback webViewCallback) {
SdkProperties.setReinitialized(true);
InitializeThread.initialize(WebViewApp.getCurrentApp().getConfiguration());
}
@WebViewExposed
public static void downloadLatestWebView(WebViewCallback webViewCallback) {
DeviceLog.debug("Unity Ads init: WebView called download");
webViewCallback.invoke(Integer.valueOf(InitializeThread.downloadLatestWebView().getValue()));
}
}

View File

@@ -0,0 +1,36 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.sensorinfo.SensorInfoError;
import com.unity3d.services.core.sensorinfo.SensorInfoListener;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class SensorInfo {
@WebViewExposed
public static void startAccelerometerUpdates(Integer num, WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(SensorInfoListener.startAccelerometerListener(num.intValue())));
}
@WebViewExposed
public static void stopAccelerometerUpdates(WebViewCallback webViewCallback) {
SensorInfoListener.stopAccelerometerListener();
webViewCallback.invoke(new Object[0]);
}
@WebViewExposed
public static void isAccelerometerActive(WebViewCallback webViewCallback) {
webViewCallback.invoke(Boolean.valueOf(SensorInfoListener.isAccelerometerListenerActive()));
}
@WebViewExposed
public static void getAccelerometerData(WebViewCallback webViewCallback) {
JSONObject accelerometerData = SensorInfoListener.getAccelerometerData();
if (accelerometerData != null) {
webViewCallback.invoke(accelerometerData);
} else {
webViewCallback.error(SensorInfoError.ACCELEROMETER_DATA_NOT_AVAILABLE, new Object[0]);
}
}
}

View File

@@ -0,0 +1,154 @@
package com.unity3d.services.core.api;
import com.unity3d.services.core.device.StorageError;
import com.unity3d.services.core.device.StorageManager;
import com.unity3d.services.core.webview.bridge.WebViewCallback;
import com.unity3d.services.core.webview.bridge.WebViewExposed;
import java.util.Collection;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class Storage {
@WebViewExposed
public static void set(String str, String str2, Integer num, WebViewCallback webViewCallback) {
set(str, str2, (Object) num, webViewCallback);
}
@WebViewExposed
public static void set(String str, String str2, Boolean bool, WebViewCallback webViewCallback) {
set(str, str2, (Object) bool, webViewCallback);
}
@WebViewExposed
public static void set(String str, String str2, Long l, WebViewCallback webViewCallback) {
set(str, str2, (Object) l, webViewCallback);
}
@WebViewExposed
public static void set(String str, String str2, Double d, WebViewCallback webViewCallback) {
set(str, str2, (Object) d, webViewCallback);
}
@WebViewExposed
public static void set(String str, String str2, String str3, WebViewCallback webViewCallback) {
set(str, str2, (Object) str3, webViewCallback);
}
@WebViewExposed
public static void set(String str, String str2, JSONObject jSONObject, WebViewCallback webViewCallback) {
set(str, str2, (Object) jSONObject, webViewCallback);
}
@WebViewExposed
public static void set(String str, String str2, JSONArray jSONArray, WebViewCallback webViewCallback) {
set(str, str2, (Object) jSONArray, webViewCallback);
}
public static void set(String str, String str2, Object obj, WebViewCallback webViewCallback) {
com.unity3d.services.core.device.Storage storage = getStorage(str);
if (storage != null) {
if (storage.set(str2, obj)) {
webViewCallback.invoke(str2);
return;
} else {
webViewCallback.error(StorageError.COULDNT_SET_VALUE, str2);
return;
}
}
webViewCallback.error(StorageError.COULDNT_GET_STORAGE, str, str2);
}
@WebViewExposed
public static void get(String str, String str2, WebViewCallback webViewCallback) {
com.unity3d.services.core.device.Storage storage = getStorage(str);
if (storage != null) {
Object obj = storage.get(str2);
if (obj == null) {
webViewCallback.error(StorageError.COULDNT_GET_VALUE, str2);
return;
} else {
webViewCallback.invoke(obj);
return;
}
}
webViewCallback.error(StorageError.COULDNT_GET_STORAGE, str, str2);
}
@WebViewExposed
public static void getKeys(String str, String str2, Boolean bool, WebViewCallback webViewCallback) {
com.unity3d.services.core.device.Storage storage = getStorage(str);
if (storage != null) {
List<String> keys = storage.getKeys(str2, bool.booleanValue());
if (keys != null) {
webViewCallback.invoke(new JSONArray((Collection) keys));
return;
} else {
webViewCallback.invoke(new JSONArray());
return;
}
}
webViewCallback.error(StorageError.COULDNT_GET_STORAGE, str, str2);
}
@WebViewExposed
public static void read(String str, WebViewCallback webViewCallback) {
com.unity3d.services.core.device.Storage storage = getStorage(str);
if (storage != null) {
storage.readStorage();
webViewCallback.invoke(str);
} else {
webViewCallback.error(StorageError.COULDNT_GET_STORAGE, str);
}
}
@WebViewExposed
public static void write(String str, WebViewCallback webViewCallback) {
com.unity3d.services.core.device.Storage storage = getStorage(str);
if (storage != null) {
if (storage.writeStorage()) {
webViewCallback.invoke(str);
return;
} else {
webViewCallback.error(StorageError.COULDNT_WRITE_STORAGE_TO_CACHE, str);
return;
}
}
webViewCallback.error(StorageError.COULDNT_GET_STORAGE, str);
}
@WebViewExposed
public static void clear(String str, WebViewCallback webViewCallback) {
com.unity3d.services.core.device.Storage storage = getStorage(str);
if (storage != null) {
if (storage.clearStorage()) {
webViewCallback.invoke(str);
return;
} else {
webViewCallback.error(StorageError.COULDNT_CLEAR_STORAGE, str);
return;
}
}
webViewCallback.error(StorageError.COULDNT_GET_STORAGE, str);
}
@WebViewExposed
public static void delete(String str, String str2, WebViewCallback webViewCallback) {
com.unity3d.services.core.device.Storage storage = getStorage(str);
if (storage != null) {
if (storage.delete(str2)) {
webViewCallback.invoke(str);
return;
} else {
webViewCallback.error(StorageError.COULDNT_DELETE_VALUE, str);
return;
}
}
webViewCallback.error(StorageError.COULDNT_GET_STORAGE, str);
}
private static com.unity3d.services.core.device.Storage getStorage(String str) {
return StorageManager.getStorage(StorageManager.StorageType.valueOf(str));
}
}

View File

@@ -0,0 +1,6 @@
package com.unity3d.services.core.broadcast;
/* loaded from: classes4.dex */
public enum BroadcastError {
JSON_ERROR
}

View File

@@ -0,0 +1,6 @@
package com.unity3d.services.core.broadcast;
/* loaded from: classes4.dex */
public enum BroadcastEvent {
ACTION
}

View File

@@ -0,0 +1,45 @@
package com.unity3d.services.core.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class BroadcastEventReceiver extends BroadcastReceiver {
private String _name;
public BroadcastEventReceiver(String str) {
this._name = str;
}
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action == null) {
return;
}
String dataString = intent.getDataString() != null ? intent.getDataString() : "";
JSONObject jSONObject = new JSONObject();
try {
if (intent.getExtras() != null) {
Bundle extras = intent.getExtras();
for (String str : extras.keySet()) {
jSONObject.put(str, extras.get(str));
}
}
} catch (JSONException e) {
DeviceLog.debug("JSONException when composing extras for broadcast action " + action + ": " + e.getMessage());
}
WebViewApp currentApp = WebViewApp.getCurrentApp();
if (currentApp == null || !currentApp.isWebAppLoaded()) {
return;
}
currentApp.sendEvent(WebViewEventCategory.BROADCAST, BroadcastEvent.ACTION, this._name, action, dataString, jSONObject);
}
}

View File

@@ -0,0 +1,71 @@
package com.unity3d.services.core.broadcast;
import android.content.Context;
import android.content.IntentFilter;
import com.unity3d.services.core.properties.ClientProperties;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/* loaded from: classes4.dex */
public class BroadcastMonitor {
private static BroadcastMonitor _instance;
private final Context _context;
private Map<String, BroadcastEventReceiver> _eventReceivers;
public static synchronized BroadcastMonitor getInstance() {
BroadcastMonitor broadcastMonitor;
synchronized (BroadcastMonitor.class) {
try {
if (_instance == null) {
_instance = new BroadcastMonitor(ClientProperties.getApplicationContext());
}
broadcastMonitor = _instance;
} catch (Throwable th) {
throw th;
}
}
return broadcastMonitor;
}
private BroadcastMonitor(Context context) {
this._context = context;
}
public void addBroadcastListener(String str, String str2, String[] strArr) {
removeBroadcastListener(str);
IntentFilter intentFilter = new IntentFilter();
for (String str3 : strArr) {
intentFilter.addAction(str3);
}
if (str2 != null) {
intentFilter.addDataScheme(str2);
}
if (this._eventReceivers == null) {
this._eventReceivers = new HashMap();
}
BroadcastEventReceiver broadcastEventReceiver = new BroadcastEventReceiver(str);
this._eventReceivers.put(str, broadcastEventReceiver);
this._context.registerReceiver(broadcastEventReceiver, intentFilter);
}
public void removeBroadcastListener(String str) {
Map<String, BroadcastEventReceiver> map = this._eventReceivers;
if (map == null || !map.containsKey(str)) {
return;
}
this._context.unregisterReceiver(this._eventReceivers.get(str));
this._eventReceivers.remove(str);
}
public void removeAllBroadcastListeners() {
Map<String, BroadcastEventReceiver> map = this._eventReceivers;
if (map != null) {
Iterator<String> it = map.keySet().iterator();
while (it.hasNext()) {
this._context.unregisterReceiver(this._eventReceivers.get(it.next()));
}
this._eventReceivers = null;
}
}
}

View File

@@ -0,0 +1,126 @@
package com.unity3d.services.core.cache;
import android.content.Context;
import android.os.Environment;
import com.unity3d.services.core.log.DeviceLog;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/* loaded from: classes4.dex */
public class CacheDirectory {
private static final String TEST_FILE_NAME = "UnityAdsTest.txt";
private String _cacheDirName;
private boolean _initialized = false;
private File _cacheDirectory = null;
private CacheDirectoryType _type = null;
public CacheDirectoryType getType() {
return this._type;
}
public CacheDirectory(String str) {
this._cacheDirName = str;
}
public synchronized File getCacheDirectory(Context context) {
File file;
if (context == null) {
return null;
}
if (this._initialized) {
return this._cacheDirectory;
}
this._initialized = true;
if ("mounted".equals(Environment.getExternalStorageState())) {
try {
file = createCacheDirectory(context.getExternalCacheDir(), this._cacheDirName);
} catch (Exception e) {
DeviceLog.exception("Creating external cache directory failed", e);
file = null;
}
if (testCacheDirectory(file)) {
createNoMediaFile(file);
this._cacheDirectory = file;
this._type = CacheDirectoryType.EXTERNAL;
DeviceLog.debug("Unity Ads is using external cache directory: " + file.getAbsolutePath());
return this._cacheDirectory;
}
} else {
DeviceLog.debug("External media not mounted");
}
File filesDir = context.getFilesDir();
if (testCacheDirectory(filesDir)) {
this._cacheDirectory = filesDir;
this._type = CacheDirectoryType.INTERNAL;
DeviceLog.debug("Unity Ads is using internal cache directory: " + filesDir.getAbsolutePath());
return this._cacheDirectory;
}
DeviceLog.error("Unity Ads failed to initialize cache directory");
return null;
}
public File createCacheDirectory(File file, String str) {
if (file == null) {
return null;
}
File file2 = new File(file, str);
file2.mkdirs();
if (file2.isDirectory()) {
return file2;
}
return null;
}
public boolean testCacheDirectory(File file) {
if (file != null && file.isDirectory()) {
try {
byte[] bytes = "test".getBytes("UTF-8");
int length = bytes.length;
byte[] bArr = new byte[length];
File file2 = new File(file, TEST_FILE_NAME);
FileOutputStream fileOutputStream = new FileOutputStream(file2);
try {
fileOutputStream.write(bytes);
fileOutputStream.flush();
fileOutputStream.close();
FileInputStream fileInputStream = new FileInputStream(file2);
try {
int read = fileInputStream.read(bArr, 0, length);
fileInputStream.close();
if (!file2.delete()) {
DeviceLog.debug("Failed to delete testfile " + file2.getAbsoluteFile());
return false;
}
if (read != length) {
DeviceLog.debug("Read buffer size mismatch");
return false;
}
if (new String(bArr, "UTF-8").equals("test")) {
return true;
}
DeviceLog.debug("Read buffer content mismatch");
return false;
} finally {
}
} finally {
}
} catch (Exception e) {
DeviceLog.debug("Unity Ads exception while testing cache directory " + file.getAbsolutePath() + ": " + e.getMessage());
}
}
return false;
}
private void createNoMediaFile(File file) {
try {
if (new File(file, ".nomedia").createNewFile()) {
DeviceLog.debug("Successfully created .nomedia file");
} else {
DeviceLog.debug("Using existing .nomedia file");
}
} catch (Exception e) {
DeviceLog.exception("Failed to create .nomedia file", e);
}
}
}

View File

@@ -0,0 +1,7 @@
package com.unity3d.services.core.cache;
/* loaded from: classes4.dex */
public enum CacheDirectoryType {
EXTERNAL,
INTERNAL
}

View File

@@ -0,0 +1,22 @@
package com.unity3d.services.core.cache;
/* loaded from: classes4.dex */
public enum CacheError {
FILE_IO_ERROR,
FILE_NOT_FOUND,
FILE_ALREADY_CACHING,
NOT_CACHING,
JSON_ERROR,
NO_INTERNET,
MALFORMED_URL,
NETWORK_ERROR,
ILLEGAL_STATE,
INVALID_ARGUMENT,
UNSUPPORTED_ENCODING,
FILE_STATE_WRONG,
CACHE_DIRECTORY_NULL,
CACHE_DIRECTORY_TYPE_NULL,
CACHE_DIRECTORY_EXISTS,
CACHE_DIRECTORY_DOESNT_EXIST,
UNKNOWN_ERROR
}

View File

@@ -0,0 +1,10 @@
package com.unity3d.services.core.cache;
/* loaded from: classes4.dex */
public enum CacheEvent {
DOWNLOAD_STARTED,
DOWNLOAD_PROGRESS,
DOWNLOAD_END,
DOWNLOAD_STOPPED,
DOWNLOAD_ERROR
}

View File

@@ -0,0 +1,23 @@
package com.unity3d.services.core.cache;
import com.unity3d.services.core.webview.WebViewEventCategory;
import com.unity3d.services.core.webview.bridge.IEventSender;
import java.io.Serializable;
import java.util.Arrays;
import kotlin.jvm.internal.Intrinsics;
/* loaded from: classes4.dex */
public final class CacheEventSender implements Serializable {
private final IEventSender eventSender;
public CacheEventSender(IEventSender eventSender) {
Intrinsics.checkNotNullParameter(eventSender, "eventSender");
this.eventSender = eventSender;
}
public final boolean sendEvent(CacheEvent eventId, Object... params) {
Intrinsics.checkNotNullParameter(eventId, "eventId");
Intrinsics.checkNotNullParameter(params, "params");
return this.eventSender.sendEvent(WebViewEventCategory.CACHE, eventId, Arrays.copyOf(params, params.length));
}
}

View File

@@ -0,0 +1,118 @@
package com.unity3d.services.core.cache;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import com.facebook.share.internal.ShareConstants;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.webview.bridge.IEventSender;
import java.util.HashMap;
import java.util.List;
/* loaded from: classes4.dex */
public class CacheThread extends Thread {
public static final int MSG_DOWNLOAD = 1;
private static int _connectTimeout = 30000;
private static CacheThreadHandler _handler = null;
private static int _progressInterval = 0;
private static int _readTimeout = 30000;
private static boolean _ready = false;
private static final Object _readyLock = new Object();
public static int getConnectTimeout() {
return _connectTimeout;
}
public static int getProgressInterval() {
return _progressInterval;
}
public static int getReadTimeout() {
return _readTimeout;
}
public static void setConnectTimeout(int i) {
_connectTimeout = i;
}
public static void setProgressInterval(int i) {
_progressInterval = i;
}
public static void setReadTimeout(int i) {
_readTimeout = i;
}
private static void init() {
CacheThread cacheThread = new CacheThread();
cacheThread.setName("UnityAdsCacheThread");
cacheThread.start();
while (!_ready) {
try {
Object obj = _readyLock;
synchronized (obj) {
obj.wait();
}
} catch (InterruptedException unused) {
DeviceLog.debug("Couldn't synchronize thread");
Thread.currentThread().interrupt();
}
}
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
Looper.prepare();
_handler = new CacheThreadHandler();
_ready = true;
Object obj = _readyLock;
synchronized (obj) {
obj.notifyAll();
}
Looper.loop();
}
public static synchronized void download(String str, String str2, HashMap<String, List<String>> hashMap, boolean z, IEventSender iEventSender) {
synchronized (CacheThread.class) {
try {
if (!_ready) {
init();
}
Bundle bundle = new Bundle();
bundle.putString(ShareConstants.FEED_SOURCE_PARAM, str);
bundle.putString("target", str2);
bundle.putInt("connectTimeout", _connectTimeout);
bundle.putInt("readTimeout", _readTimeout);
bundle.putInt("progressInterval", _progressInterval);
bundle.putBoolean("append", z);
bundle.putSerializable("cacheEventSender", new CacheEventSender(iEventSender));
if (hashMap != null) {
for (String str3 : hashMap.keySet()) {
bundle.putStringArray(str3, (String[]) hashMap.get(str3).toArray(new String[hashMap.get(str3).size()]));
}
}
Message message = new Message();
message.what = 1;
message.setData(bundle);
_handler.setCancelStatus(false);
_handler.sendMessage(message);
} catch (Throwable th) {
throw th;
}
}
}
public static boolean isActive() {
if (_ready) {
return _handler.isActive();
}
return false;
}
public static void cancel() {
if (_ready) {
_handler.removeMessages(1);
_handler.setCancelStatus(true);
}
}
}

View File

@@ -0,0 +1,114 @@
package com.unity3d.services.core.cache;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import com.facebook.share.internal.ShareConstants;
import com.unity3d.services.core.api.Request;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.request.WebRequest;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes4.dex */
class CacheThreadHandler extends Handler {
private WebRequest _currentRequest = null;
private boolean _canceled = false;
private boolean _active = false;
public boolean isActive() {
return this._active;
}
@Override // android.os.Handler
public void handleMessage(Message message) {
HashMap<String, List<String>> hashMap;
Bundle data = message.getData();
String string = data.getString(ShareConstants.FEED_SOURCE_PARAM);
data.remove(ShareConstants.FEED_SOURCE_PARAM);
String string2 = data.getString("target");
data.remove("target");
int i = data.getInt("connectTimeout");
data.remove("connectTimeout");
int i2 = data.getInt("readTimeout");
data.remove("readTimeout");
int i3 = data.getInt("progressInterval");
data.remove("progressInterval");
boolean z = data.getBoolean("append", false);
data.remove("append");
CacheEventSender cacheEventSender = (CacheEventSender) data.getSerializable("cacheEventSender");
data.remove("cacheEventSender");
if (data.size() > 0) {
DeviceLog.debug("There are headers left in data, reading them");
HashMap<String, List<String>> hashMap2 = new HashMap<>();
for (String str : data.keySet()) {
hashMap2.put(str, Arrays.asList(data.getStringArray(str)));
}
hashMap = hashMap2;
} else {
hashMap = null;
}
File file = new File(string2);
if ((z && !file.exists()) || (!z && file.exists())) {
this._active = false;
cacheEventSender.sendEvent(CacheEvent.DOWNLOAD_ERROR, CacheError.FILE_STATE_WRONG, string, string2, Boolean.valueOf(z), Boolean.valueOf(file.exists()));
} else {
if (message.what != 1) {
return;
}
downloadFile(string, string2, i, i2, i3, hashMap, z, cacheEventSender);
}
}
public void setCancelStatus(boolean z) {
WebRequest webRequest;
this._canceled = z;
if (!z || (webRequest = this._currentRequest) == null) {
return;
}
this._active = false;
webRequest.cancel();
}
/* JADX ERROR: Type inference failed
jadx.core.utils.exceptions.JadxOverflowException: Type inference error: updates count limit reached
at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:59)
at jadx.core.utils.ErrorsCounter.error(ErrorsCounter.java:31)
at jadx.core.dex.attributes.nodes.NotificationAttrNode.addError(NotificationAttrNode.java:19)
at jadx.core.dex.visitors.typeinference.TypeInferenceVisitor.visit(TypeInferenceVisitor.java:77)
*/
private void downloadFile(java.lang.String r26, java.lang.String r27, int r28, int r29, int r30, java.util.HashMap<java.lang.String, java.util.List<java.lang.String>> r31, boolean r32, com.unity3d.services.core.cache.CacheEventSender r33) {
/*
Method dump skipped, instructions count: 896
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: com.unity3d.services.core.cache.CacheThreadHandler.downloadFile(java.lang.String, java.lang.String, int, int, int, java.util.HashMap, boolean, com.unity3d.services.core.cache.CacheEventSender):void");
}
private void postProcessDownload(long j, String str, File file, long j2, long j3, boolean z, int i, Map<String, List<String>> map, CacheEventSender cacheEventSender) {
long elapsedRealtime = SystemClock.elapsedRealtime() - j;
if (!file.setReadable(true, false)) {
DeviceLog.debug("Unity Ads cache: could not set file readable!");
}
if (!z) {
DeviceLog.debug("Unity Ads cache: File " + file.getName() + " of " + j2 + " bytes downloaded in " + elapsedRealtime + "ms");
cacheEventSender.sendEvent(CacheEvent.DOWNLOAD_END, str, Long.valueOf(j2), Long.valueOf(j3), Long.valueOf(elapsedRealtime), Integer.valueOf(i), Request.getResponseHeadersMap(map));
return;
}
DeviceLog.debug("Unity Ads cache: downloading of " + str + " stopped");
cacheEventSender.sendEvent(CacheEvent.DOWNLOAD_STOPPED, str, Long.valueOf(j2), Long.valueOf(j3), Long.valueOf(elapsedRealtime), Integer.valueOf(i), Request.getResponseHeadersMap(map));
}
private WebRequest getWebRequest(String str, int i, int i2, HashMap<String, List<String>> hashMap) throws MalformedURLException {
HashMap hashMap2 = new HashMap();
if (hashMap != null) {
hashMap2.putAll(hashMap);
}
return new WebRequest(str, "GET", hashMap2, i, i2);
}
}

View File

@@ -0,0 +1,31 @@
package com.unity3d.services.core.configuration;
import android.content.Context;
import androidx.startup.Initializer;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
import java.util.List;
import kotlin.Unit;
import kotlin.collections.CollectionsKt__CollectionsKt;
import kotlin.jvm.internal.Intrinsics;
/* loaded from: classes4.dex */
public final class AdsSdkInitializer implements Initializer<Unit> {
@Override // androidx.startup.Initializer
public /* bridge */ /* synthetic */ Unit create(Context context) {
create2(context);
return Unit.INSTANCE;
}
/* renamed from: create, reason: avoid collision after fix types in other method */
public void create2(Context context) {
Intrinsics.checkNotNullParameter(context, "context");
ClientProperties.setApplicationContext(context.getApplicationContext());
SdkProperties.setAppInitializationTimeSinceEpoch(System.currentTimeMillis());
}
@Override // androidx.startup.Initializer
public List<Class<? extends Initializer<?>>> dependencies() {
return CollectionsKt__CollectionsKt.emptyList();
}
}

View File

@@ -0,0 +1,425 @@
package com.unity3d.services.core.configuration;
import com.facebook.AuthenticationTokenClaims;
import com.ironsource.ad;
import com.mbridge.msdk.playercommon.exoplayer2.source.chunk.ChunkedTrackBlacklistUtil;
import com.unity3d.ads.core.domain.AndroidBoldExperimentHandler;
import com.unity3d.services.ads.configuration.AdsModuleConfiguration;
import com.unity3d.services.ads.gmascar.utils.ScarConstants;
import com.unity3d.services.analytics.core.configuration.AnalyticsModuleConfiguration;
import com.unity3d.services.banners.configuration.BannersModuleConfiguration;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.network.core.HttpClient;
import com.unity3d.services.core.network.mapper.WebRequestToHttpRequestKt;
import com.unity3d.services.core.network.model.HttpRequest;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.store.core.configuration.StoreModuleConfiguration;
import java.io.File;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class Configuration {
private String _configUrl;
private ConfigurationRequestFactory _configurationRequestFactory;
private int _connectedEventThresholdInMs;
private boolean _delayWebViewUpdate;
private ExperimentsReader _experimentReader;
private String _filteredJsonString;
private int _loadTimeout;
private int _maxRetries;
private int _maximumConnectedEvents;
private double _metricSampleRate;
private Boolean _metricsEnabled;
private String _metricsUrl;
private final Class<?>[] _moduleConfigurationList;
private Map<String, IModuleConfiguration> _moduleConfigurations;
private long _networkErrorTimeout;
private int _privacyRequestWaitTimeout;
private JSONObject _rawJsonData;
private int _resetWebAppTimeout;
private long _retryDelay;
private double _retryScalingFactor;
private String _sTkn;
private String _scarBiddingUrl;
private String _sdkVersion;
private int _showTimeout;
private String _src;
private String _stateId;
private int _tokenTimeout;
private String _unifiedAuctionToken;
private Class[] _webAppApiClassList;
private long _webViewAppCreateTimeout;
private int _webViewBridgeTimeout;
private String _webViewData;
private String _webViewHash;
private String _webViewUrl;
private String _webViewVersion;
public Boolean areMetricsEnabledForCurrentSession() {
return this._metricsEnabled;
}
public String getConfigUrl() {
return this._configUrl;
}
public int getConnectedEventThreshold() {
return this._connectedEventThresholdInMs;
}
public boolean getDelayWebViewUpdate() {
return this._delayWebViewUpdate;
}
public ExperimentsReader getExperimentsReader() {
return this._experimentReader;
}
public String getFilteredJsonString() {
return this._filteredJsonString;
}
public int getLoadTimeout() {
return this._loadTimeout;
}
public int getMaxRetries() {
return this._maxRetries;
}
public int getMaximumConnectedEvents() {
return this._maximumConnectedEvents;
}
public double getMetricSampleRate() {
return this._metricSampleRate;
}
public String getMetricsUrl() {
return this._metricsUrl;
}
public Class[] getModuleConfigurationList() {
return this._moduleConfigurationList;
}
public long getNetworkErrorTimeout() {
return this._networkErrorTimeout;
}
public int getPrivacyRequestWaitTimeout() {
return this._privacyRequestWaitTimeout;
}
public JSONObject getRawConfigData() {
return this._rawJsonData;
}
public int getResetWebappTimeout() {
return this._resetWebAppTimeout;
}
public long getRetryDelay() {
return this._retryDelay;
}
public double getRetryScalingFactor() {
return this._retryScalingFactor;
}
public String getScarBiddingUrl() {
return this._scarBiddingUrl;
}
public String getSdkVersion() {
return this._sdkVersion;
}
public String getSessionToken() {
return this._sTkn;
}
public int getShowTimeout() {
return this._showTimeout;
}
public String getSrc() {
String str = this._src;
return str != null ? str : "";
}
public String getStateId() {
String str = this._stateId;
return str != null ? str : "";
}
public int getTokenTimeout() {
return this._tokenTimeout;
}
public String getUnifiedAuctionToken() {
return this._unifiedAuctionToken;
}
public long getWebViewAppCreateTimeout() {
return this._webViewAppCreateTimeout;
}
public int getWebViewBridgeTimeout() {
return this._webViewBridgeTimeout;
}
public String getWebViewData() {
return this._webViewData;
}
public String getWebViewHash() {
return this._webViewHash;
}
public String getWebViewUrl() {
return this._webViewUrl;
}
public String getWebViewVersion() {
return this._webViewVersion;
}
public void setWebViewData(String str) {
this._webViewData = str;
}
public void setWebViewHash(String str) {
this._webViewHash = str;
}
public void setWebViewUrl(String str) {
this._webViewUrl = str;
}
public Configuration() {
this._moduleConfigurationList = new Class[]{CoreModuleConfiguration.class, AdsModuleConfiguration.class, AnalyticsModuleConfiguration.class, BannersModuleConfiguration.class, StoreModuleConfiguration.class};
this._experimentReader = new ExperimentsReader();
setOptionalFields(new JSONObject(), false);
}
public Configuration(String str) {
this(str, new Experiments());
}
public Configuration(JSONObject jSONObject) throws MalformedURLException, JSONException {
this._moduleConfigurationList = new Class[]{CoreModuleConfiguration.class, AdsModuleConfiguration.class, AnalyticsModuleConfiguration.class, BannersModuleConfiguration.class, StoreModuleConfiguration.class};
this._experimentReader = new ExperimentsReader();
handleConfigurationData(jSONObject, false);
}
public Configuration(String str, ExperimentsReader experimentsReader) {
this(str, experimentsReader.getCurrentlyActiveExperiments());
this._experimentReader = experimentsReader;
}
public Configuration(String str, IExperiments iExperiments) {
this();
this._configUrl = str;
this._configurationRequestFactory = new ConfigurationRequestFactory(this);
this._experimentReader.updateLocalExperiments(iExperiments);
}
public Class[] getWebAppApiClassList() {
if (this._webAppApiClassList == null) {
createWebAppApiClassList();
}
return this._webAppApiClassList;
}
public IExperiments getExperiments() {
return this._experimentReader.getCurrentlyActiveExperiments();
}
public IModuleConfiguration getModuleConfiguration(Class cls) {
Map<String, IModuleConfiguration> map = this._moduleConfigurations;
if (map != null && map.containsKey(cls)) {
return this._moduleConfigurations.get(cls);
}
try {
IModuleConfiguration iModuleConfiguration = (IModuleConfiguration) cls.newInstance();
if (iModuleConfiguration != null) {
if (this._moduleConfigurations == null) {
HashMap hashMap = new HashMap();
this._moduleConfigurations = hashMap;
hashMap.put(cls.getName(), iModuleConfiguration);
}
return iModuleConfiguration;
}
} catch (Exception unused) {
}
return null;
}
public void makeRequest() throws Exception {
if (this._configUrl == null) {
throw new MalformedURLException("Base URL is null");
}
HttpRequest httpRequest = WebRequestToHttpRequestKt.toHttpRequest(this._configurationRequestFactory.getWebRequest());
InitializeEventsMetricSender.getInstance().didConfigRequestStart();
try {
handleConfigurationData(new JSONObject(((HttpClient) Utilities.getService(HttpClient.class)).executeBlocking(httpRequest).getBody().toString()), true);
InitializeEventsMetricSender.getInstance().didConfigRequestEnd(true);
saveToDisk();
} catch (Exception e) {
InitializeEventsMetricSender.getInstance().didConfigRequestEnd(false);
throw e;
}
}
/* JADX WARN: Removed duplicated region for block: B:31:0x0068 */
/* JADX WARN: Removed duplicated region for block: B:8:0x0017 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void handleConfigurationData(org.json.JSONObject r5, boolean r6) throws java.net.MalformedURLException, org.json.JSONException {
/*
r4 = this;
java.lang.String r0 = "hash"
java.lang.String r1 = "url"
r2 = 0
boolean r3 = r5.isNull(r1) // Catch: org.json.JSONException -> L10
if (r3 != 0) goto L10
java.lang.String r1 = r5.getString(r1) // Catch: org.json.JSONException -> L10
goto L11
L10:
r1 = r2
L11:
boolean r3 = android.text.TextUtils.isEmpty(r1)
if (r3 != 0) goto L68
r4._webViewUrl = r1
boolean r1 = r5.isNull(r0) // Catch: org.json.JSONException -> L28
if (r1 != 0) goto L24
java.lang.String r0 = r5.getString(r0) // Catch: org.json.JSONException -> L28
goto L25
L24:
r0 = r2
L25:
r4._webViewHash = r0 // Catch: org.json.JSONException -> L28
goto L2a
L28:
r4._webViewHash = r2
L2a:
java.lang.String r0 = "tkn"
boolean r1 = r5.isNull(r0)
if (r1 != 0) goto L37
java.lang.String r0 = r5.optString(r0)
goto L38
L37:
r0 = r2
L38:
r4._unifiedAuctionToken = r0
java.lang.String r0 = "sid"
boolean r1 = r5.isNull(r0)
if (r1 != 0) goto L47
java.lang.String r0 = r5.optString(r0)
goto L48
L47:
r0 = r2
L48:
r4._stateId = r0
java.lang.String r0 = "sTkn"
boolean r1 = r5.isNull(r0)
if (r1 != 0) goto L56
java.lang.String r2 = r5.optString(r0)
L56:
r4._sTkn = r2
r4.setOptionalFields(r5, r6)
org.json.JSONObject r6 = r4.getFilteredConfigJson(r5)
java.lang.String r6 = r6.toString()
r4._filteredJsonString = r6
r4._rawJsonData = r5
return
L68:
java.net.MalformedURLException r5 = new java.net.MalformedURLException
java.lang.String r6 = "WebView URL is null or empty"
r5.<init>(r6)
throw r5
*/
throw new UnsupportedOperationException("Method not decompiled: com.unity3d.services.core.configuration.Configuration.handleConfigurationData(org.json.JSONObject, boolean):void");
}
private void setOptionalFields(JSONObject jSONObject, boolean z) {
IExperiments experiments;
this._webViewVersion = jSONObject.optString("version", null);
this._delayWebViewUpdate = jSONObject.optBoolean("dwu", false);
this._resetWebAppTimeout = jSONObject.optInt("rwt", 10000);
this._maxRetries = jSONObject.optInt("mr", 6);
this._retryDelay = jSONObject.optLong("rd", 5000L);
this._retryScalingFactor = jSONObject.optDouble("rcf", 2.0d);
this._connectedEventThresholdInMs = jSONObject.optInt("cet", 10000);
this._maximumConnectedEvents = jSONObject.optInt("mce", 500);
this._networkErrorTimeout = jSONObject.optLong("net", ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS);
this._sdkVersion = jSONObject.optString(ad.M, "");
this._showTimeout = jSONObject.optInt("sto", 10000);
this._loadTimeout = jSONObject.optInt("lto", 30000);
this._webViewBridgeTimeout = jSONObject.optInt("wto", 5000);
this._metricsUrl = jSONObject.optString("murl", "");
this._metricSampleRate = jSONObject.optDouble("msr", 100.0d);
this._webViewAppCreateTimeout = jSONObject.optLong("wct", ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS);
this._tokenTimeout = jSONObject.optInt("tto", 5000);
this._privacyRequestWaitTimeout = jSONObject.optInt("prwto", 3000);
this._src = jSONObject.optString("src", null);
this._scarBiddingUrl = jSONObject.optString("scurl", ScarConstants.SCAR_PRD_BIDDING_ENDPOINT);
this._metricsEnabled = Boolean.valueOf(this._metricSampleRate >= ((double) (new Random().nextInt(99) + 1)));
if (jSONObject.has(AndroidBoldExperimentHandler.EXPO_NODE_NAME)) {
experiments = new ExperimentObjects(jSONObject.optJSONObject(AndroidBoldExperimentHandler.EXPO_NODE_NAME));
} else {
experiments = new Experiments(jSONObject.optJSONObject(AuthenticationTokenClaims.JSON_KEY_EXP));
}
if (z) {
this._experimentReader.updateRemoteExperiments(experiments);
} else {
this._experimentReader.updateLocalExperiments(experiments);
}
}
private void createWebAppApiClassList() {
ArrayList arrayList = new ArrayList();
for (Class cls : getModuleConfigurationList()) {
IModuleConfiguration moduleConfiguration = getModuleConfiguration(cls);
if (moduleConfiguration != null && moduleConfiguration.getWebAppApiClassList() != null) {
arrayList.addAll(Arrays.asList(moduleConfiguration.getWebAppApiClassList()));
}
}
this._webAppApiClassList = (Class[]) arrayList.toArray(new Class[arrayList.size()]);
}
public void saveToDisk() {
Utilities.writeFile(new File(SdkProperties.getLocalConfigurationFilepath()), getFilteredJsonString());
}
public void deleteFromDisk() {
File file = new File(SdkProperties.getLocalConfigurationFilepath());
if (file.exists()) {
file.delete();
}
}
private JSONObject getFilteredConfigJson(JSONObject jSONObject) throws JSONException {
JSONObject jSONObject2 = new JSONObject();
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
Object opt = jSONObject.opt(next);
if (!next.equalsIgnoreCase("tkn") && !next.equalsIgnoreCase(ad.L0) && !next.equalsIgnoreCase("srr") && !next.equalsIgnoreCase("sTkn")) {
jSONObject2.put(next, opt);
}
}
return jSONObject2;
}
}

View File

@@ -0,0 +1,7 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public enum ConfigurationFailure {
NETWORK_FAILURE,
INVALID_DATA
}

View File

@@ -0,0 +1,65 @@
package com.unity3d.services.core.configuration;
import com.unity3d.ads.core.domain.BoldExperimentHandler;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.network.core.HttpClient;
import com.unity3d.services.core.network.mapper.WebRequestToHttpRequestKt;
import com.unity3d.services.core.network.model.HttpRequest;
import com.unity3d.services.core.network.model.HttpResponse;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import com.unity3d.services.core.request.metrics.TSIMetric;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class ConfigurationLoader implements IConfigurationLoader {
private final BoldExperimentHandler _boldExperimentHandler = (BoldExperimentHandler) Utilities.getService(BoldExperimentHandler.class);
private final ConfigurationRequestFactory _configurationRequestFactory;
private final HttpClient _httpClient;
private final Configuration _localConfiguration;
private final SDKMetricsSender _sdkMetricsSender;
@Override // com.unity3d.services.core.configuration.IConfigurationLoader
public Configuration getLocalConfiguration() {
return this._localConfiguration;
}
public ConfigurationLoader(ConfigurationRequestFactory configurationRequestFactory, SDKMetricsSender sDKMetricsSender, HttpClient httpClient) {
this._localConfiguration = configurationRequestFactory.getConfiguration();
this._configurationRequestFactory = configurationRequestFactory;
this._sdkMetricsSender = sDKMetricsSender;
this._httpClient = httpClient;
}
@Override // com.unity3d.services.core.configuration.IConfigurationLoader
public void loadConfiguration(IConfigurationLoaderListener iConfigurationLoaderListener) throws Exception {
try {
HttpRequest httpRequest = WebRequestToHttpRequestKt.toHttpRequest(this._configurationRequestFactory.getWebRequest());
InitializeEventsMetricSender.getInstance().didConfigRequestStart();
HttpResponse executeBlocking = this._httpClient.executeBlocking(httpRequest);
String obj = executeBlocking.getBody().toString();
if (executeBlocking.getStatusCode() / 100 != 2) {
iConfigurationLoaderListener.onError("Non 2xx HTTP status received from ads configuration request.");
return;
}
try {
this._boldExperimentHandler.invoke(obj);
this._localConfiguration.handleConfigurationData(new JSONObject(obj), true);
sendConfigMetrics(this._localConfiguration.getUnifiedAuctionToken(), this._localConfiguration.getStateId());
iConfigurationLoaderListener.onSuccess(this._localConfiguration);
} catch (Exception unused) {
iConfigurationLoaderListener.onError("Could not create web request");
}
} catch (Exception e) {
iConfigurationLoaderListener.onError("Could not create web request: " + e);
}
}
private void sendConfigMetrics(String str, String str2) {
if (str == null || str.isEmpty()) {
this._sdkMetricsSender.sendMetric(TSIMetric.newMissingToken());
}
if (str2 == null || str2.isEmpty()) {
this._sdkMetricsSender.sendMetric(TSIMetric.newMissingStateId());
}
}
}

View File

@@ -0,0 +1,47 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.webview.WebViewApp;
import java.io.File;
import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class ConfigurationReader {
private Configuration _localConfiguration;
public Configuration getCurrentConfiguration() {
if (getRemoteConfiguration() != null) {
return getRemoteConfiguration();
}
Configuration localConfiguration = getLocalConfiguration();
return localConfiguration != null ? localConfiguration : new Configuration();
}
private Configuration getRemoteConfiguration() {
if (WebViewApp.getCurrentApp() == null) {
return null;
}
return WebViewApp.getCurrentApp().getConfiguration();
}
private Configuration getLocalConfiguration() {
Configuration configuration = this._localConfiguration;
if (configuration != null) {
return configuration;
}
File file = new File(SdkProperties.getLocalConfigurationFilepath());
if (file.exists()) {
try {
this._localConfiguration = new Configuration(new JSONObject(new String(Utilities.readFileBytes(file))));
} catch (IOException | JSONException unused) {
DeviceLog.debug("Unable to read configuration from storage");
this._localConfiguration = null;
}
}
return this._localConfiguration;
}
}

View File

@@ -0,0 +1,43 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.device.reader.IDeviceInfoDataContainer;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.request.WebRequest;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.HashMap;
import org.apache.http.protocol.HTTP;
/* loaded from: classes4.dex */
public class ConfigurationRequestFactory {
private final Configuration _configuration;
private final IDeviceInfoDataContainer _deviceInfoDataContainer;
public Configuration getConfiguration() {
return this._configuration;
}
public ConfigurationRequestFactory(Configuration configuration) {
this(configuration, null);
}
public ConfigurationRequestFactory(Configuration configuration, IDeviceInfoDataContainer iDeviceInfoDataContainer) {
this._configuration = configuration;
this._deviceInfoDataContainer = iDeviceInfoDataContainer;
}
public WebRequest getWebRequest() throws MalformedURLException {
String configUrl = this._configuration.getConfigUrl();
if (configUrl == null) {
throw new MalformedURLException("Base URL is null");
}
StringBuilder sb = new StringBuilder(configUrl);
HashMap hashMap = new HashMap();
hashMap.put(HTTP.CONTENT_ENCODING, Collections.singletonList("gzip"));
WebRequest webRequest = new WebRequest(sb.toString(), "POST", hashMap);
IDeviceInfoDataContainer iDeviceInfoDataContainer = this._deviceInfoDataContainer;
webRequest.setBody(iDeviceInfoDataContainer != null ? iDeviceInfoDataContainer.getDeviceData() : null);
DeviceLog.debug("Requesting configuration with: " + ((Object) sb));
return webRequest;
}
}

View File

@@ -0,0 +1,144 @@
package com.unity3d.services.core.configuration;
import android.content.Context;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.core.api.Broadcast;
import com.unity3d.services.core.api.Cache;
import com.unity3d.services.core.api.ClassDetection;
import com.unity3d.services.core.api.Connectivity;
import com.unity3d.services.core.api.DeviceInfo;
import com.unity3d.services.core.api.Intent;
import com.unity3d.services.core.api.Lifecycle;
import com.unity3d.services.core.api.Permissions;
import com.unity3d.services.core.api.Preferences;
import com.unity3d.services.core.api.Request;
import com.unity3d.services.core.api.Resolve;
import com.unity3d.services.core.api.Sdk;
import com.unity3d.services.core.api.SensorInfo;
import com.unity3d.services.core.api.Storage;
import com.unity3d.services.core.broadcast.BroadcastMonitor;
import com.unity3d.services.core.cache.CacheThread;
import com.unity3d.services.core.connectivity.ConnectivityMonitor;
import com.unity3d.services.core.device.AdvertisingId;
import com.unity3d.services.core.device.Device;
import com.unity3d.services.core.device.OpenAdvertisingId;
import com.unity3d.services.core.device.StorageManager;
import com.unity3d.services.core.device.VolumeChange;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.request.WebRequestThread;
import com.unity3d.services.core.request.metrics.Metric;
import com.unity3d.services.core.request.metrics.SDKMetrics;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import java.util.ArrayList;
/* loaded from: classes4.dex */
public class CoreModuleConfiguration implements IModuleConfiguration {
@Override // com.unity3d.services.core.configuration.IModuleConfiguration
public Class[] getWebAppApiClassList() {
return new Class[]{Broadcast.class, Cache.class, Connectivity.class, DeviceInfo.class, ClassDetection.class, Storage.class, Sdk.class, Request.class, Resolve.class, Intent.class, Lifecycle.class, Preferences.class, SensorInfo.class, Permissions.class};
}
@Override // com.unity3d.services.core.configuration.IModuleConfiguration
public boolean resetState(Configuration configuration) {
BroadcastMonitor.getInstance().removeAllBroadcastListeners();
CacheThread.cancel();
WebRequestThread.cancel();
ConnectivityMonitor.stopAll();
StorageManager.init(ClientProperties.getApplicationContext());
AdvertisingId.init(ClientProperties.getApplicationContext());
OpenAdvertisingId.init(ClientProperties.getApplicationContext());
((VolumeChange) Utilities.getService(VolumeChange.class)).clearAllListeners();
return true;
}
@Override // com.unity3d.services.core.configuration.IModuleConfiguration
public boolean initErrorState(Configuration configuration, ErrorState errorState, final String str) {
final UnityAds.UnityAdsInitializationError unityAdsInitializationError;
SDKMetrics.setConfiguration(configuration);
int i = AnonymousClass3.$SwitchMap$com$unity3d$services$core$configuration$ErrorState[errorState.ordinal()];
if (i == 1) {
unityAdsInitializationError = UnityAds.UnityAdsInitializationError.INTERNAL_ERROR;
} else if (i == 2) {
unityAdsInitializationError = UnityAds.UnityAdsInitializationError.AD_BLOCKER_DETECTED;
} else {
unityAdsInitializationError = UnityAds.UnityAdsInitializationError.INTERNAL_ERROR;
str = "Unity Ads failed to initialize due to internal error";
}
InitializationNotificationCenter.getInstance().triggerOnSdkInitializationFailed(str, errorState, 0);
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.services.core.configuration.CoreModuleConfiguration.1
@Override // java.lang.Runnable
public void run() {
SdkProperties.notifyInitializationFailed(unityAdsInitializationError, str);
}
});
return true;
}
/* renamed from: com.unity3d.services.core.configuration.CoreModuleConfiguration$3, reason: invalid class name */
public static /* synthetic */ class AnonymousClass3 {
static final /* synthetic */ int[] $SwitchMap$com$unity3d$services$core$configuration$ErrorState;
static {
int[] iArr = new int[ErrorState.values().length];
$SwitchMap$com$unity3d$services$core$configuration$ErrorState = iArr;
try {
iArr[ErrorState.CreateWebApp.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$unity3d$services$core$configuration$ErrorState[ErrorState.InitModules.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
@Override // com.unity3d.services.core.configuration.IModuleConfiguration
public boolean initCompleteState(Configuration configuration) {
SDKMetrics.setConfiguration(configuration);
InitializationNotificationCenter.getInstance().triggerOnSdkInitialized();
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.services.core.configuration.CoreModuleConfiguration.2
@Override // java.lang.Runnable
public void run() {
SdkProperties.notifyInitializationComplete();
}
});
collectMetrics(configuration);
return true;
}
private void collectMetrics(Configuration configuration) {
ArrayList arrayList = new ArrayList();
if (Device.hasX264Decoder()) {
arrayList.add(new Metric("native_device_decoder_x264_success"));
} else {
arrayList.add(new Metric("native_device_decoder_x264_failure"));
}
if (Device.hasX265Decoder()) {
arrayList.add(new Metric("native_device_decoder_x265_success"));
} else {
arrayList.add(new Metric("native_device_decoder_x265_failure"));
}
if (Device.hasAV1Decoder()) {
arrayList.add(new Metric("native_device_decoder_av1_success"));
} else {
arrayList.add(new Metric("native_device_decoder_av1_failure"));
}
SDKMetricsSender sDKMetricsSender = (SDKMetricsSender) Utilities.getService(SDKMetricsSender.class);
sDKMetricsSender.sendMetrics(arrayList);
checkForPC(configuration, sDKMetricsSender);
}
private void checkForPC(Configuration configuration, SDKMetricsSender sDKMetricsSender) {
Context applicationContext;
if (!configuration.getExperiments().isPCCheckEnabled() || (applicationContext = ClientProperties.getApplicationContext()) == null) {
return;
}
if (applicationContext.getPackageManager().hasSystemFeature("com.google.android.play.feature.HPE_EXPERIENCE")) {
sDKMetricsSender.sendMetric(new Metric("native_device_is_pc_success"));
} else {
sDKMetricsSender.sendMetric(new Metric("native_device_is_pc_failure"));
}
}
}

View File

@@ -0,0 +1,58 @@
package com.unity3d.services.core.configuration;
import android.webkit.JavascriptInterface;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.webview.bridge.WebViewBridgeInterface;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
/* loaded from: classes4.dex */
public class EnvironmentCheck {
public static boolean isEnvironmentOk() {
return testProGuard() && testCacheDirectory();
}
public static boolean testProGuard() {
try {
Method method = WebViewBridgeInterface.class.getMethod("handleInvocation", String.class);
Method method2 = WebViewBridgeInterface.class.getMethod("handleCallback", String.class, String.class, String.class);
if (hasJavascriptInterface(method) && hasJavascriptInterface(method2)) {
DeviceLog.debug("Unity Ads ProGuard check OK");
return true;
}
DeviceLog.error("Unity Ads ProGuard check fail: missing @JavascriptInterface annotations in Unity Ads web bridge");
return false;
} catch (ClassNotFoundException e) {
DeviceLog.exception("Unity Ads ProGuard check fail: Unity Ads web bridge class not found", e);
return false;
} catch (NoSuchMethodException e2) {
DeviceLog.exception("Unity Ads ProGuard check fail: Unity Ads web bridge methods not found", e2);
return false;
} catch (Exception e3) {
DeviceLog.exception("Unknown exception during Unity Ads ProGuard check: " + e3.getMessage(), e3);
return true;
}
}
public static boolean testCacheDirectory() {
if (SdkProperties.getCacheDirectory() != null) {
DeviceLog.debug("Unity Ads cache directory check OK");
return true;
}
DeviceLog.error("Unity Ads cache directory check fail: no working cache directory available");
return false;
}
private static boolean hasJavascriptInterface(Method method) {
Annotation[] annotations = method.getAnnotations();
if (annotations != null) {
for (Annotation annotation : annotations) {
if (annotation instanceof JavascriptInterface) {
return true;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,28 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public enum ErrorState {
CreateWebApp("create_webapp"),
NetworkConfigRequest("network_config"),
NetworkWebviewRequest("network_webview"),
InvalidHash("invalid_hash"),
CreateWebview("create_webview"),
MalformedWebviewRequest("malformed_webview"),
ResetWebApp("reset_webapp"),
LoadCache("load_cache"),
InitModules("init_modules"),
CreateWebviewTimeout("create_webview_timeout"),
CreateWebviewGameIdDisabled("create_webview_game_id_disabled"),
CreateWebviewConfigError("create_webview_config_error"),
CreateWebviewInvalidArgument("create_webview_invalid_arg");
private String _stateMetricName;
public String getMetricName() {
return this._stateMetricName;
}
ErrorState(String str) {
this._stateMetricName = str;
}
}

View File

@@ -0,0 +1,7 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public enum ExperimentAppliedRule {
NEXT,
IMMEDIATE
}

View File

@@ -0,0 +1,37 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.log.DeviceLog;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class ExperimentObject {
private static final String APPLIED_KEY = "applied";
private static final String VALUE_KEY = "value";
private final JSONObject _experimentData;
public ExperimentObject(JSONObject jSONObject) {
this._experimentData = jSONObject == null ? new JSONObject() : jSONObject;
}
public String getStringValue() {
return this._experimentData.optString("value");
}
public boolean getBooleanValue() {
return this._experimentData.optBoolean("value");
}
public ExperimentAppliedRule getAppliedRule() {
ExperimentAppliedRule experimentAppliedRule = ExperimentAppliedRule.NEXT;
String optString = this._experimentData.optString(APPLIED_KEY);
if (optString.isEmpty()) {
return experimentAppliedRule;
}
try {
return ExperimentAppliedRule.valueOf(optString.toUpperCase());
} catch (IllegalArgumentException unused) {
DeviceLog.warning("Invalid rule %s for experiment", optString);
return experimentAppliedRule;
}
}
}

View File

@@ -0,0 +1,153 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.ads.gmascar.managers.ScarBiddingManagerType;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class ExperimentObjects extends ExperimentsBase {
private final Map<String, ExperimentObject> _experimentObjects = new HashMap();
private final JSONObject _experimentObjetsData;
@Override // com.unity3d.services.core.configuration.IExperiments
public JSONObject getExperimentsAsJson() {
return this._experimentObjetsData;
}
public ExperimentObjects(JSONObject jSONObject) {
if (jSONObject != null) {
this._experimentObjetsData = jSONObject;
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
this._experimentObjects.put(next, new ExperimentObject(jSONObject.optJSONObject(next)));
}
return;
}
this._experimentObjetsData = new JSONObject();
}
public ExperimentObject getExperimentObject(String str) {
return this._experimentObjects.get(str);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean shouldNativeTokenAwaitPrivacy() {
return getExperimentValueOrDefault("tsi_prw");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebAssetAdCaching() {
return getExperimentValueOrDefault("wac");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebGestureNotRequired() {
return getExperimentValueOrDefault("wgr");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isScarInitEnabled() {
return getExperimentValueOrDefault("scar_init");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isJetpackLifecycle() {
return getExperimentValueOrDefault("gjl");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isOkHttpEnabled() {
return getExperimentValueOrDefault("okhttp");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebMessageEnabled() {
return getExperimentValueOrDefault("jwm");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebViewAsyncDownloadEnabled() {
return getExperimentValueOrDefault("wad");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isNativeShowTimeoutDisabled() {
return getExperimentValueOrDefault("nstd");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isNativeLoadTimeoutDisabled() {
return getExperimentValueOrDefault("nltd");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isCaptureHDRCapabilitiesEnabled() {
return getExperimentValueOrDefault("hdrc");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isScarBannerHbEnabled() {
return getExperimentValueOrDefault("scar_bn");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public String getScarBiddingManager() {
return getExperimentValue("scar_bm", ScarBiddingManagerType.DISABLED.getName());
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isPCCheckEnabled() {
return getExperimentValueOrDefault("pc_check");
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isBoldSdkNextSessionEnabled() {
return getExperimentValueOrDefault(ExperimentsBase.EXP_TAG_IS_BOLD_NEXT_SESSION);
}
private String getExperimentValue(String str, String str2) {
ExperimentObject experimentObject = getExperimentObject(str);
return experimentObject != null ? experimentObject.getStringValue() : str2;
}
private boolean getExperimentValue(String str, boolean z) {
ExperimentObject experimentObject = getExperimentObject(str);
return experimentObject != null ? experimentObject.getBooleanValue() : z;
}
private boolean getExperimentValueOrDefault(String str) {
return getExperimentValue(str, false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public Map<String, String> getExperimentTags() {
HashMap hashMap = new HashMap();
for (Map.Entry<String, ExperimentObject> entry : this._experimentObjects.entrySet()) {
hashMap.put(entry.getKey(), entry.getValue().getStringValue());
}
return hashMap;
}
@Override // com.unity3d.services.core.configuration.IExperiments
public JSONObject getCurrentSessionExperiments() {
return getExperimentWithAppliedRule(ExperimentAppliedRule.IMMEDIATE);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public JSONObject getNextSessionExperiments() {
return getExperimentWithAppliedRule(ExperimentAppliedRule.NEXT);
}
private JSONObject getExperimentWithAppliedRule(ExperimentAppliedRule experimentAppliedRule) {
HashMap hashMap = new HashMap();
for (Map.Entry<String, ExperimentObject> entry : this._experimentObjects.entrySet()) {
if (entry.getValue().getAppliedRule() == experimentAppliedRule) {
hashMap.put(entry.getKey(), entry.getValue().getStringValue());
}
}
return new JSONObject(hashMap);
}
}

View File

@@ -0,0 +1,151 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.ads.gmascar.managers.ScarBiddingManagerType;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class Experiments extends ExperimentsBase {
private static final Set<String> NEXT_SESSION_FLAGS = new HashSet(Collections.singletonList("tsi_prw"));
private final JSONObject _experimentData;
@Override // com.unity3d.services.core.configuration.IExperiments
public JSONObject getExperimentsAsJson() {
return this._experimentData;
}
public Experiments() {
this(null);
}
public Experiments(JSONObject jSONObject) {
if (jSONObject == null) {
this._experimentData = new JSONObject();
} else {
this._experimentData = jSONObject;
}
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean shouldNativeTokenAwaitPrivacy() {
return this._experimentData.optBoolean("tsi_prw", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebAssetAdCaching() {
return this._experimentData.optBoolean("wac", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebGestureNotRequired() {
return this._experimentData.optBoolean("wgr", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isScarInitEnabled() {
return this._experimentData.optBoolean("scar_init", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isScarBannerHbEnabled() {
return this._experimentData.optBoolean("scar_bn", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public String getScarBiddingManager() {
return this._experimentData.optString("scar_bm", ScarBiddingManagerType.DISABLED.getName());
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isJetpackLifecycle() {
return this._experimentData.optBoolean("gjl", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isOkHttpEnabled() {
return this._experimentData.optBoolean("okhttp", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebMessageEnabled() {
return this._experimentData.optBoolean("jwm", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isWebViewAsyncDownloadEnabled() {
return this._experimentData.optBoolean("wad", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isNativeShowTimeoutDisabled() {
return this._experimentData.optBoolean("nstd", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isNativeLoadTimeoutDisabled() {
return this._experimentData.optBoolean("nltd", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isCaptureHDRCapabilitiesEnabled() {
return this._experimentData.optBoolean("hdrc", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isPCCheckEnabled() {
return this._experimentData.optBoolean("pc_check", false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public boolean isBoldSdkNextSessionEnabled() {
return this._experimentData.optBoolean(ExperimentsBase.EXP_TAG_IS_BOLD_NEXT_SESSION, false);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public Map<String, String> getExperimentTags() {
HashMap hashMap = new HashMap();
Iterator<String> keys = this._experimentData.keys();
while (keys.hasNext()) {
String next = keys.next();
hashMap.put(next, String.valueOf(this._experimentData.opt(next)));
}
return hashMap;
}
@Override // com.unity3d.services.core.configuration.IExperiments
public JSONObject getNextSessionExperiments() {
if (this._experimentData == null) {
return null;
}
HashMap hashMap = new HashMap();
Iterator<String> keys = this._experimentData.keys();
while (keys.hasNext()) {
String next = keys.next();
if (NEXT_SESSION_FLAGS.contains(next)) {
hashMap.put(next, String.valueOf(this._experimentData.optBoolean(next)));
}
}
return new JSONObject(hashMap);
}
@Override // com.unity3d.services.core.configuration.IExperiments
public JSONObject getCurrentSessionExperiments() {
if (this._experimentData == null) {
return null;
}
HashMap hashMap = new HashMap();
Iterator<String> keys = this._experimentData.keys();
while (keys.hasNext()) {
String next = keys.next();
if (!NEXT_SESSION_FLAGS.contains(next)) {
hashMap.put(next, String.valueOf(this._experimentData.optBoolean(next)));
}
}
return new JSONObject(hashMap);
}
}

View File

@@ -0,0 +1,21 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public abstract class ExperimentsBase implements IExperiments {
static final boolean EXP_DEFAULT_VALUE = false;
static final String EXP_TAG_HDR_CAPABILITIES = "hdrc";
public static final String EXP_TAG_IS_BOLD_NEXT_SESSION = "boldSdkNextSessionEnabled";
static final String EXP_TAG_IS_PC_CHECK_ENABLED = "pc_check";
static final String EXP_TAG_JETPACK_LIFECYCLE = "gjl";
static final String EXP_TAG_LOAD_TIMEOUT_DISABLED = "nltd";
static final String EXP_TAG_OK_HTTP = "okhttp";
static final String EXP_TAG_SCAR_BIDDING_MANAGER = "scar_bm";
static final String EXP_TAG_SCAR_HB_BN = "scar_bn";
static final String EXP_TAG_SCAR_INIT = "scar_init";
static final String EXP_TAG_SHOW_TIMEOUT_DISABLED = "nstd";
static final String EXP_TAG_WEBVIEW_ASYNC_DOWNLOAD = "wad";
static final String EXP_TAG_WEB_AD_ASSET_CACHING = "wac";
static final String EXP_TAG_WEB_GESTURE_NOT_REQUIRED = "wgr";
static final String EXP_TAG_WEB_MESSAGE = "jwm";
static final String TSI_TAG_NATIVE_TOKEN_AWAIT_PRIVACY = "tsi_prw";
}

View File

@@ -0,0 +1,38 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import org.json.JSONException;
/* loaded from: classes4.dex */
public class ExperimentsReader {
private IExperiments _localExperiments;
private IExperiments _remoteExperiments;
public synchronized void updateLocalExperiments(IExperiments iExperiments) {
this._localExperiments = iExperiments;
}
public synchronized void updateRemoteExperiments(IExperiments iExperiments) {
this._remoteExperiments = iExperiments;
}
public synchronized IExperiments getCurrentlyActiveExperiments() {
IExperiments iExperiments = this._remoteExperiments;
if (iExperiments == null && this._localExperiments == null) {
return new Experiments();
}
if (iExperiments == null) {
return this._localExperiments;
}
if (this._localExperiments == null) {
this._localExperiments = new Experiments();
}
try {
return new Experiments(Utilities.mergeJsonObjects(this._localExperiments.getNextSessionExperiments(), this._remoteExperiments.getCurrentSessionExperiments()));
} catch (JSONException unused) {
DeviceLog.error("Couldn't get active experiments, reverting to default experiments");
return new Experiments();
}
}
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public interface IConfigurationLoader {
Configuration getLocalConfiguration();
void loadConfiguration(IConfigurationLoaderListener iConfigurationLoaderListener) throws Exception;
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public interface IConfigurationLoaderListener {
void onError(String str);
void onSuccess(Configuration configuration);
}

View File

@@ -0,0 +1,45 @@
package com.unity3d.services.core.configuration;
import java.util.Map;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public interface IExperiments {
JSONObject getCurrentSessionExperiments();
Map<String, String> getExperimentTags();
JSONObject getExperimentsAsJson();
JSONObject getNextSessionExperiments();
String getScarBiddingManager();
boolean isBoldSdkNextSessionEnabled();
boolean isCaptureHDRCapabilitiesEnabled();
boolean isJetpackLifecycle();
boolean isNativeLoadTimeoutDisabled();
boolean isNativeShowTimeoutDisabled();
boolean isOkHttpEnabled();
boolean isPCCheckEnabled();
boolean isScarBannerHbEnabled();
boolean isScarInitEnabled();
boolean isWebAssetAdCaching();
boolean isWebGestureNotRequired();
boolean isWebMessageEnabled();
boolean isWebViewAsyncDownloadEnabled();
boolean shouldNativeTokenAwaitPrivacy();
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public interface IInitializationListener {
void onSdkInitializationFailed(String str, ErrorState errorState, int i);
void onSdkInitialized();
}

View File

@@ -0,0 +1,12 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public interface IInitializationNotificationCenter {
void addListener(IInitializationListener iInitializationListener);
void removeListener(IInitializationListener iInitializationListener);
void triggerOnSdkInitializationFailed(String str, ErrorState errorState, int i);
void triggerOnSdkInitialized();
}

View File

@@ -0,0 +1,41 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.request.metrics.Metric;
import java.util.Map;
/* loaded from: classes4.dex */
public interface IInitializeEventsMetricSender {
Long configRequestDuration();
void didConfigRequestEnd(boolean z);
void didConfigRequestStart();
void didInitStart();
void didPrivacyConfigRequestEnd(boolean z);
void didPrivacyConfigRequestStart();
Long duration();
Map<String, String> getRetryTags();
Long initializationStartTimeStamp();
void onRetryConfig();
void onRetryWebview();
Long privacyConfigDuration();
void sdkDidInitialize();
void sdkInitializeFailed(String str, ErrorState errorState);
void sdkTokenDidBecomeAvailableWithConfig(boolean z);
void sendMetric(Metric metric);
Long tokenDuration();
}

View File

@@ -0,0 +1,12 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public interface IModuleConfiguration {
Class[] getWebAppApiClassList();
boolean initCompleteState(Configuration configuration);
boolean initErrorState(Configuration configuration, ErrorState errorState, String str);
boolean resetState(Configuration configuration);
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public interface IPrivacyConfigurationListener {
void onError(PrivacyCallError privacyCallError, String str);
void onSuccess(PrivacyConfig privacyConfig);
}

View File

@@ -0,0 +1,19 @@
package com.unity3d.services.core.configuration;
import com.facebook.share.internal.ShareConstants;
/* loaded from: classes4.dex */
public enum InitRequestType {
PRIVACY(ShareConstants.WEB_DIALOG_PARAM_PRIVACY),
TOKEN("token_srr");
private String _callType;
public String getCallType() {
return this._callType;
}
InitRequestType(String str) {
this._callType = str;
}
}

View File

@@ -0,0 +1,107 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/* loaded from: classes4.dex */
public class InitializationNotificationCenter implements IInitializationNotificationCenter {
private static InitializationNotificationCenter instance;
private HashMap<Integer, IInitializationListener> _sdkListeners = new HashMap<>();
public static InitializationNotificationCenter getInstance() {
if (instance == null) {
instance = new InitializationNotificationCenter();
}
return instance;
}
@Override // com.unity3d.services.core.configuration.IInitializationNotificationCenter
public void addListener(IInitializationListener iInitializationListener) {
synchronized (this._sdkListeners) {
if (iInitializationListener != null) {
try {
this._sdkListeners.put(new Integer(iInitializationListener.hashCode()), iInitializationListener);
} catch (Throwable th) {
throw th;
}
}
}
}
@Override // com.unity3d.services.core.configuration.IInitializationNotificationCenter
public void removeListener(IInitializationListener iInitializationListener) {
synchronized (this._sdkListeners) {
if (iInitializationListener != null) {
try {
removeListener(new Integer(iInitializationListener.hashCode()));
} catch (Throwable th) {
throw th;
}
}
}
}
@Override // com.unity3d.services.core.configuration.IInitializationNotificationCenter
public void triggerOnSdkInitialized() {
synchronized (this._sdkListeners) {
try {
ArrayList arrayList = new ArrayList();
for (final Map.Entry<Integer, IInitializationListener> entry : this._sdkListeners.entrySet()) {
if (entry.getValue() != null) {
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.services.core.configuration.InitializationNotificationCenter.1
@Override // java.lang.Runnable
public void run() {
((IInitializationListener) entry.getValue()).onSdkInitialized();
}
});
} else {
arrayList.add(entry.getKey());
}
}
Iterator it = arrayList.iterator();
while (it.hasNext()) {
this._sdkListeners.remove((Integer) it.next());
}
} catch (Throwable th) {
throw th;
}
}
}
@Override // com.unity3d.services.core.configuration.IInitializationNotificationCenter
public void triggerOnSdkInitializationFailed(String str, final ErrorState errorState, final int i) {
synchronized (this._sdkListeners) {
try {
final String str2 = "SDK Failed to Initialize due to " + str;
DeviceLog.error(str2);
ArrayList arrayList = new ArrayList();
for (final Map.Entry<Integer, IInitializationListener> entry : this._sdkListeners.entrySet()) {
if (entry.getValue() != null) {
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.services.core.configuration.InitializationNotificationCenter.2
@Override // java.lang.Runnable
public void run() {
((IInitializationListener) entry.getValue()).onSdkInitializationFailed(str2, errorState, i);
}
});
} else {
arrayList.add(entry.getKey());
}
}
Iterator it = arrayList.iterator();
while (it.hasNext()) {
this._sdkListeners.remove((Integer) it.next());
}
} catch (Throwable th) {
throw th;
}
}
}
private void removeListener(Integer num) {
this._sdkListeners.remove(num);
}
}

View File

@@ -0,0 +1,210 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.request.metrics.Metric;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import com.unity3d.services.core.request.metrics.TSIMetric;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/* loaded from: classes4.dex */
public class InitializeEventsMetricSender implements IInitializeEventsMetricSender, IInitializationListener {
private static InitializeEventsMetricSender _instance;
private long _startTime = 0;
private long _privacyConfigStartTime = 0;
private long _privacyConfigEndTime = 0;
private long _configStartTime = 0;
private long _configEndTime = 0;
private int _configRetryCount = 0;
private int _webviewRetryCount = 0;
private boolean _initMetricSent = false;
private boolean _tokenMetricSent = false;
private final SDKMetricsSender _sdkMetricsSender = (SDKMetricsSender) Utilities.getService(SDKMetricsSender.class);
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void onRetryConfig() {
this._configRetryCount++;
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void onRetryWebview() {
this._webviewRetryCount++;
}
public static IInitializeEventsMetricSender getInstance() {
if (_instance == null) {
_instance = new InitializeEventsMetricSender();
}
return _instance;
}
private InitializeEventsMetricSender() {
InitializationNotificationCenter.getInstance().addListener(this);
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void didInitStart() {
this._startTime = System.nanoTime();
this._configRetryCount = 0;
this._webviewRetryCount = 0;
sendMetric(TSIMetric.newInitStarted());
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void didConfigRequestStart() {
this._configStartTime = System.nanoTime();
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void didConfigRequestEnd(boolean z) {
this._configEndTime = System.nanoTime();
sendConfigResolutionRequestIfNeeded(z);
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void didPrivacyConfigRequestStart() {
this._privacyConfigStartTime = System.nanoTime();
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void didPrivacyConfigRequestEnd(boolean z) {
this._privacyConfigEndTime = System.nanoTime();
sendPrivacyResolutionRequestIfNeeded(z);
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public synchronized void sdkDidInitialize() {
if (initializationStartTimeStamp().longValue() == 0) {
DeviceLog.debug("sdkDidInitialize called before didInitStart, skipping metric");
}
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public Long initializationStartTimeStamp() {
return Long.valueOf(this._startTime);
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public synchronized void sdkInitializeFailed(String str, ErrorState errorState) {
if (this._startTime == 0) {
DeviceLog.debug("sdkInitializeFailed called before didInitStart, skipping metric");
}
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public synchronized void sdkTokenDidBecomeAvailableWithConfig(boolean z) {
try {
if (!this._tokenMetricSent) {
sendTokenAvailabilityMetricWithConfig(z);
if (z) {
sendTokenResolutionRequestMetricIfNeeded();
}
this._tokenMetricSent = true;
}
} catch (Throwable th) {
throw th;
}
}
private void sendTokenAvailabilityMetricWithConfig(boolean z) {
Metric newTokenAvailabilityLatencyWebview;
if (this._startTime == 0) {
DeviceLog.debug("sendTokenAvailabilityMetricWithConfig called before didInitStart, skipping metric");
return;
}
Long valueOf = Long.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - this._startTime));
Map<String, String> retryTags = getRetryTags();
if (z) {
newTokenAvailabilityLatencyWebview = TSIMetric.newTokenAvailabilityLatencyConfig(valueOf, retryTags);
} else {
newTokenAvailabilityLatencyWebview = TSIMetric.newTokenAvailabilityLatencyWebview(valueOf, retryTags);
}
sendMetric(newTokenAvailabilityLatencyWebview);
}
private void sendTokenResolutionRequestMetricIfNeeded() {
if (this._configStartTime == 0) {
DeviceLog.debug("sendTokenResolutionRequestMetricIfNeeded called before didInitStart, skipping metric");
} else {
sendMetric(TSIMetric.newTokenResolutionRequestLatency(tokenDuration(), getRetryTags()));
}
}
private void sendPrivacyResolutionRequestIfNeeded(boolean z) {
if (this._privacyConfigStartTime == 0 || this._privacyConfigEndTime == 0) {
DeviceLog.debug("sendPrivacyResolutionRequestIfNeeded called with invalid timestamps, skipping metric");
} else {
sendMetric(getPrivacyRequestMetric(z));
}
}
private Metric getPrivacyRequestMetric(boolean z) {
if (z) {
return TSIMetric.newPrivacyRequestLatencySuccess(privacyConfigDuration());
}
return TSIMetric.newPrivacyRequestLatencyFailure(privacyConfigDuration());
}
private void sendConfigResolutionRequestIfNeeded(boolean z) {
if (this._configStartTime == 0 || this._configEndTime == 0) {
DeviceLog.debug("sendConfigResolutionRequestIfNeeded called with invalid timestamps, skipping metric");
} else if (z) {
sendMetric(TSIMetric.newConfigRequestLatencySuccess(configRequestDuration()));
} else {
sendMetric(TSIMetric.newConfigRequestLatencyFailure(configRequestDuration()));
}
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public Long duration() {
return Long.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - this._startTime));
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public Long tokenDuration() {
return Long.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - this._configStartTime));
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public Long privacyConfigDuration() {
return Long.valueOf(TimeUnit.NANOSECONDS.toMillis(this._privacyConfigEndTime - this._privacyConfigStartTime));
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public Long configRequestDuration() {
return Long.valueOf(TimeUnit.NANOSECONDS.toMillis(this._configEndTime - this._configStartTime));
}
public Map<String, String> getErrorStateTags(ErrorState errorState) {
Map<String, String> retryTags = getRetryTags();
retryTags.put("stt", errorState.getMetricName());
return retryTags;
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public Map<String, String> getRetryTags() {
return new HashMap<String, String>() { // from class: com.unity3d.services.core.configuration.InitializeEventsMetricSender.1
{
put("c_retry", String.valueOf(InitializeEventsMetricSender.this._configRetryCount));
put("wv_retry", String.valueOf(InitializeEventsMetricSender.this._webviewRetryCount));
}
};
}
@Override // com.unity3d.services.core.configuration.IInitializeEventsMetricSender
public void sendMetric(Metric metric) {
this._sdkMetricsSender.sendMetric(metric);
}
@Override // com.unity3d.services.core.configuration.IInitializationListener
public void onSdkInitialized() {
sdkDidInitialize();
}
@Override // com.unity3d.services.core.configuration.IInitializationListener
public void onSdkInitializationFailed(String str, ErrorState errorState, int i) {
sdkInitializeFailed(str, errorState);
}
}

View File

@@ -0,0 +1,883 @@
package com.unity3d.services.core.configuration;
import android.annotation.TargetApi;
import android.os.ConditionVariable;
import android.text.TextUtils;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.ads.token.TokenStorage;
import com.unity3d.services.core.api.DownloadLatestWebViewStatus;
import com.unity3d.services.core.api.Lifecycle;
import com.unity3d.services.core.connectivity.ConnectivityMonitor;
import com.unity3d.services.core.connectivity.IConnectivityListener;
import com.unity3d.services.core.device.reader.DeviceInfoDataFactory;
import com.unity3d.services.core.lifecycle.CachedLifecycle;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.network.core.HttpClient;
import com.unity3d.services.core.network.model.HttpRequest;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.request.metrics.Metric;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import com.unity3d.services.core.request.metrics.TSIMetric;
import com.unity3d.services.core.webview.WebView;
import com.unity3d.services.core.webview.WebViewApp;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class InitializeThread extends Thread {
private static InitializeThread _thread;
private InitializeState _state;
private String _stateName;
private long _stateStartTimestamp;
private boolean _stopThread = false;
private boolean _didRetry = false;
private final SDKMetricsSender _sdkMetricsSender = (SDKMetricsSender) Utilities.getService(SDKMetricsSender.class);
private int getStatePrefixLength() {
return 15;
}
public void quit() {
this._stopThread = true;
}
private InitializeThread(InitializeState initializeState) {
this._state = initializeState;
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
while (true) {
try {
InitializeState initializeState = this._state;
if (initializeState == null || this._stopThread) {
break;
}
try {
handleStateStartMetrics(initializeState);
InitializeState execute = this._state.execute();
this._state = execute;
handleStateEndMetrics(execute);
} catch (Exception e) {
DeviceLog.exception("Unity Ads SDK encountered an error during initialization, cancel initialization", e);
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.services.core.configuration.InitializeThread.1
@Override // java.lang.Runnable
public void run() {
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INTERNAL_ERROR, "Unity Ads SDK encountered an error during initialization, cancel initialization");
}
});
this._state = new InitializeStateForceReset();
} catch (OutOfMemoryError e2) {
DeviceLog.exception("Unity Ads SDK failed to initialize due to application doesn't have enough memory to initialize Unity Ads SDK", new Exception(e2));
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.services.core.configuration.InitializeThread.2
@Override // java.lang.Runnable
public void run() {
SdkProperties.notifyInitializationFailed(UnityAds.UnityAdsInitializationError.INTERNAL_ERROR, "Unity Ads SDK failed to initialize due to application doesn't have enough memory to initialize Unity Ads SDK");
}
});
this._state = new InitializeStateForceReset();
}
} catch (OutOfMemoryError unused) {
}
}
_thread = null;
}
public static synchronized void initialize(Configuration configuration) {
synchronized (InitializeThread.class) {
if (_thread == null) {
InitializeEventsMetricSender.getInstance().didInitStart();
CachedLifecycle.register();
InitializeThread initializeThread = new InitializeThread(new InitializeStateLoadConfigFile(configuration));
_thread = initializeThread;
initializeThread.setName("UnityAdsInitializeThread");
_thread.start();
}
}
}
public static synchronized void reset() {
synchronized (InitializeThread.class) {
if (_thread == null) {
InitializeThread initializeThread = new InitializeThread(new InitializeStateForceReset());
_thread = initializeThread;
initializeThread.setName("UnityAdsResetThread");
_thread.start();
}
}
}
public static synchronized DownloadLatestWebViewStatus downloadLatestWebView() {
synchronized (InitializeThread.class) {
if (_thread != null) {
return DownloadLatestWebViewStatus.INIT_QUEUE_NOT_EMPTY;
}
if (SdkProperties.getLatestConfiguration() == null) {
return DownloadLatestWebViewStatus.MISSING_LATEST_CONFIG;
}
InitializeThread initializeThread = new InitializeThread(new InitializeStateCheckForCachedWebViewUpdate(SdkProperties.getLatestConfiguration()));
_thread = initializeThread;
initializeThread.setName("UnityAdsDownloadThread");
_thread.start();
return DownloadLatestWebViewStatus.BACKGROUND_DOWNLOAD_STARTED;
}
}
private void handleStateStartMetrics(InitializeState initializeState) {
if (isRetryState(initializeState)) {
this._didRetry = true;
} else {
if (!this._didRetry) {
this._stateStartTimestamp = System.nanoTime();
}
this._didRetry = false;
}
this._stateName = getMetricNameForState(initializeState);
}
private void handleStateEndMetrics(InitializeState initializeState) {
if (this._stateName == null || isRetryState(initializeState) || this._stateName.equals("native_retry_state")) {
return;
}
this._sdkMetricsSender.sendMetric(new Metric(this._stateName, Long.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - this._stateStartTimestamp)), getMetricTagsForState()));
}
private Map<String, String> getMetricTagsForState() {
return InitializeEventsMetricSender.getInstance().getRetryTags();
}
private String getMetricNameForState(InitializeState initializeState) {
if (initializeState == null) {
return null;
}
String simpleName = initializeState.getClass().getSimpleName();
if (simpleName.length() == 0) {
return null;
}
String lowerCase = simpleName.substring(getStatePrefixLength()).toLowerCase();
StringBuilder sb = new StringBuilder(lowerCase.length() + 13);
sb.append("native_");
sb.append(lowerCase);
sb.append("_state");
return sb.toString();
}
private boolean isRetryState(InitializeState initializeState) {
return initializeState instanceof InitializeStateRetry;
}
public static abstract class InitializeState {
public abstract InitializeState execute();
private InitializeState() {
}
}
public static class InitializeStateLoadConfigFile extends InitializeState {
private Configuration _configuration;
public InitializeStateLoadConfigFile(Configuration configuration) {
super();
this._configuration = configuration;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.debug("Unity Ads init: Loading Config File Parameters");
File file = new File(SdkProperties.getLocalConfigurationFilepath());
if (!file.exists()) {
return new InitializeStateReset(this._configuration);
}
try {
this._configuration = new Configuration(new JSONObject(new String(Utilities.readFileBytes(file))));
} catch (Exception unused) {
DeviceLog.debug("Unity Ads init: Using default configuration parameters");
}
return new InitializeStateReset(this._configuration);
}
}
public static class InitializeStateReset extends InitializeState {
private Configuration _configuration;
private int _resetWebAppTimeout;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateReset(Configuration configuration) {
super();
this._configuration = configuration;
this._resetWebAppTimeout = configuration.getResetWebappTimeout();
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.debug("Unity Ads init: starting init");
final ConditionVariable conditionVariable = new ConditionVariable();
final WebViewApp currentApp = WebViewApp.getCurrentApp();
if (currentApp != null) {
currentApp.resetWebViewAppInitialization();
if (currentApp.getWebView() != null) {
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.services.core.configuration.InitializeThread.InitializeStateReset.1
@Override // java.lang.Runnable
public void run() {
WebView webView = currentApp.getWebView();
if (webView != null) {
webView.destroy();
currentApp.setWebView(null);
}
conditionVariable.open();
}
});
if (!conditionVariable.block(this._resetWebAppTimeout)) {
return new InitializeStateError(ErrorState.ResetWebApp, new Exception("Reset failed on opening ConditionVariable"), this._configuration);
}
}
}
unregisterLifecycleCallbacks();
SdkProperties.setCacheDirectory(null);
if (SdkProperties.getCacheDirectory() == null) {
return new InitializeStateError(ErrorState.ResetWebApp, new Exception("Cache directory is NULL"), this._configuration);
}
SdkProperties.setInitialized(false);
for (Class cls : this._configuration.getModuleConfigurationList()) {
IModuleConfiguration moduleConfiguration = this._configuration.getModuleConfiguration(cls);
if (moduleConfiguration != null) {
moduleConfiguration.resetState(this._configuration);
}
}
return new InitializeStateInitModules(this._configuration);
}
@TargetApi(14)
private void unregisterLifecycleCallbacks() {
if (Lifecycle.getLifecycleListener() != null) {
if (ClientProperties.getApplication() != null) {
ClientProperties.getApplication().unregisterActivityLifecycleCallbacks(Lifecycle.getLifecycleListener());
}
Lifecycle.setLifecycleListener(null);
}
}
}
public static class InitializeStateForceReset extends InitializeStateReset {
public InitializeStateForceReset() {
super(new Configuration());
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeStateReset, com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
SdkProperties.setInitializeState(SdkProperties.InitializationState.NOT_INITIALIZED);
super.execute();
return null;
}
}
public static class InitializeStateInitModules extends InitializeState {
private Configuration _configuration;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateInitModules(Configuration configuration) {
super();
this._configuration = configuration;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
return new InitializeStateConfig(this._configuration);
}
}
public static class InitializeStateConfig extends InitializeState {
private Configuration _configuration;
private Configuration _localConfig;
private int _maxRetries;
private InitializeState _nextState;
private int _retries;
private long _retryDelay;
private double _scalingFactor;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateConfig(Configuration configuration) {
super();
this._configuration = new Configuration(SdkProperties.getConfigUrl(), configuration.getExperimentsReader());
this._retries = 0;
this._retryDelay = configuration.getRetryDelay();
this._maxRetries = configuration.getMaxRetries();
this._scalingFactor = configuration.getRetryScalingFactor();
this._localConfig = configuration;
this._nextState = null;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.info("Unity Ads init: load configuration from " + SdkProperties.getConfigUrl());
return executeWithLoader();
}
public InitializeState executeLegacy(Configuration configuration) {
try {
configuration.makeRequest();
if (configuration.getDelayWebViewUpdate()) {
return new InitializeStateLoadCacheConfigAndWebView(configuration, this._localConfig);
}
return new InitializeStateLoadCache(configuration);
} catch (Exception e) {
if (this._retries < this._maxRetries) {
this._retryDelay = (long) (this._retryDelay * this._scalingFactor);
this._retries++;
InitializeEventsMetricSender.getInstance().onRetryConfig();
return new InitializeStateRetry(this, this._retryDelay);
}
return new InitializeStateNetworkError(ErrorState.NetworkConfigRequest, e, this, this._localConfig);
}
}
public InitializeState executeWithLoader() {
final SDKMetricsSender sDKMetricsSender = (SDKMetricsSender) Utilities.getService(SDKMetricsSender.class);
HttpClient httpClient = (HttpClient) Utilities.getService(HttpClient.class);
PrivacyConfigStorage privacyConfigStorage = PrivacyConfigStorage.getInstance();
DeviceInfoDataFactory deviceInfoDataFactory = new DeviceInfoDataFactory(sDKMetricsSender);
PrivacyConfigurationLoader privacyConfigurationLoader = new PrivacyConfigurationLoader(new ConfigurationLoader(new ConfigurationRequestFactory(this._configuration, deviceInfoDataFactory.getDeviceInfoData(InitRequestType.TOKEN)), sDKMetricsSender, httpClient), new ConfigurationRequestFactory(this._configuration, deviceInfoDataFactory.getDeviceInfoData(InitRequestType.PRIVACY)), privacyConfigStorage, httpClient);
final Configuration configuration = new Configuration(SdkProperties.getConfigUrl());
try {
privacyConfigurationLoader.loadConfiguration(new IConfigurationLoaderListener() { // from class: com.unity3d.services.core.configuration.InitializeThread.InitializeStateConfig.1
@Override // com.unity3d.services.core.configuration.IConfigurationLoaderListener
public void onSuccess(Configuration configuration2) {
InitializeStateConfig.this._configuration = configuration2;
InitializeStateConfig.this._configuration.saveToDisk();
if (InitializeStateConfig.this._configuration.getDelayWebViewUpdate()) {
InitializeStateConfig initializeStateConfig = InitializeStateConfig.this;
initializeStateConfig._nextState = new InitializeStateLoadCacheConfigAndWebView(initializeStateConfig._configuration, InitializeStateConfig.this._localConfig);
}
((TokenStorage) Utilities.getService(TokenStorage.class)).setInitToken(InitializeStateConfig.this._configuration.getUnifiedAuctionToken());
InitializeStateConfig initializeStateConfig2 = InitializeStateConfig.this;
initializeStateConfig2._nextState = new InitializeStateLoadCache(initializeStateConfig2._configuration);
}
@Override // com.unity3d.services.core.configuration.IConfigurationLoaderListener
public void onError(String str) {
sDKMetricsSender.sendMetric(TSIMetric.newEmergencySwitchOff());
InitializeStateConfig initializeStateConfig = InitializeStateConfig.this;
initializeStateConfig._nextState = initializeStateConfig.executeLegacy(configuration);
}
});
return this._nextState;
} catch (Exception e) {
int i = this._retries;
if (i < this._maxRetries) {
this._retryDelay = (long) (this._retryDelay * this._scalingFactor);
this._retries = i + 1;
InitializeEventsMetricSender.getInstance().onRetryConfig();
return new InitializeStateRetry(this, this._retryDelay);
}
return new InitializeStateNetworkError(ErrorState.NetworkConfigRequest, e, this, this._configuration);
}
}
}
public static class InitializeStateLoadCache extends InitializeState {
private Configuration _configuration;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateLoadCache(Configuration configuration) {
super();
this._configuration = configuration;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.debug("Unity Ads init: check if webapp can be loaded from local cache");
try {
byte[] readFileBytes = Utilities.readFileBytes(new File(SdkProperties.getLocalWebViewFile()));
String Sha256 = Utilities.Sha256(readFileBytes);
if (Sha256 != null && Sha256.equals(this._configuration.getWebViewHash())) {
try {
String str = new String(readFileBytes, "UTF-8");
DeviceLog.info("Unity Ads init: webapp loaded from local cache");
return new InitializeStateCreate(this._configuration, str);
} catch (Exception e) {
return new InitializeStateError(ErrorState.LoadCache, e, this._configuration);
}
}
return new InitializeStateLoadWeb(this._configuration);
} catch (Exception e2) {
DeviceLog.debug("Unity Ads init: webapp not found in local cache: " + e2.getMessage());
return new InitializeStateLoadWeb(this._configuration);
}
}
}
public static class InitializeStateLoadWeb extends InitializeState {
private Configuration _configuration;
private HttpClient _httpClient;
private int _maxRetries;
private int _retries;
private long _retryDelay;
private double _scalingFactor;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateLoadWeb(Configuration configuration) {
super();
this._httpClient = (HttpClient) Utilities.getService(HttpClient.class);
this._configuration = configuration;
this._retries = 0;
this._retryDelay = configuration.getRetryDelay();
this._maxRetries = configuration.getMaxRetries();
this._scalingFactor = configuration.getRetryScalingFactor();
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.info("Unity Ads init: loading webapp from " + this._configuration.getWebViewUrl());
try {
try {
String obj = this._httpClient.executeBlocking(new HttpRequest(this._configuration.getWebViewUrl())).getBody().toString();
String webViewHash = this._configuration.getWebViewHash();
if (webViewHash != null && !Utilities.Sha256(obj).equals(webViewHash)) {
return new InitializeStateError(ErrorState.InvalidHash, new Exception("Invalid webViewHash"), this._configuration);
}
if (webViewHash != null) {
Utilities.writeFile(new File(SdkProperties.getLocalWebViewFile()), obj);
}
return new InitializeStateCreate(this._configuration, obj);
} catch (Exception e) {
int i = this._retries;
if (i < this._maxRetries) {
this._retryDelay = (long) (this._retryDelay * this._scalingFactor);
this._retries = i + 1;
InitializeEventsMetricSender.getInstance().onRetryWebview();
return new InitializeStateRetry(this, this._retryDelay);
}
return new InitializeStateNetworkError(ErrorState.NetworkWebviewRequest, e, this, this._configuration);
}
} catch (Exception e2) {
DeviceLog.exception("Malformed URL", e2);
return new InitializeStateError(ErrorState.MalformedWebviewRequest, e2, this._configuration);
}
}
}
public static class InitializeStateCreate extends InitializeState {
private Configuration _configuration;
private String _webViewData;
public Configuration getConfiguration() {
return this._configuration;
}
public String getWebData() {
return this._webViewData;
}
public InitializeStateCreate(Configuration configuration, String str) {
super();
this._configuration = configuration;
this._webViewData = str;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.debug("Unity Ads init: creating webapp");
Configuration configuration = this._configuration;
configuration.setWebViewData(this._webViewData);
try {
ErrorState create = WebViewApp.create(configuration, false);
if (create == null) {
return new InitializeStateComplete(this._configuration);
}
String webAppFailureMessage = WebViewApp.getCurrentApp().getWebAppFailureMessage() != null ? WebViewApp.getCurrentApp().getWebAppFailureMessage() : "Unity Ads WebApp creation failed";
DeviceLog.error(webAppFailureMessage);
return new InitializeStateError(create, new Exception(webAppFailureMessage), this._configuration);
} catch (IllegalThreadStateException e) {
DeviceLog.exception("Illegal Thread", e);
return new InitializeStateError(ErrorState.CreateWebApp, e, this._configuration);
}
}
}
public static class InitializeStateCreateWithRemote extends InitializeState {
private Configuration _configuration;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateCreateWithRemote(Configuration configuration) {
super();
this._configuration = configuration;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.debug("Unity Ads init: creating webapp");
try {
ErrorState create = WebViewApp.create(this._configuration, true);
if (create == null) {
return new InitializeStateComplete(this._configuration);
}
String webAppFailureMessage = WebViewApp.getCurrentApp().getWebAppFailureMessage() != null ? WebViewApp.getCurrentApp().getWebAppFailureMessage() : "Unity Ads WebApp creation failed";
DeviceLog.error(webAppFailureMessage);
return new InitializeStateError(create, new Exception(webAppFailureMessage), this._configuration);
} catch (IllegalThreadStateException e) {
DeviceLog.exception("Illegal Thread", e);
return new InitializeStateError(ErrorState.CreateWebApp, e, this._configuration);
}
}
}
public static class InitializeStateComplete extends InitializeState {
private Configuration _configuration;
public InitializeStateComplete(Configuration configuration) {
super();
this._configuration = configuration;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
for (Class cls : this._configuration.getModuleConfigurationList()) {
IModuleConfiguration moduleConfiguration = this._configuration.getModuleConfiguration(cls);
if (moduleConfiguration != null) {
moduleConfiguration.initCompleteState(this._configuration);
}
}
return null;
}
}
public static class InitializeStateError extends InitializeState {
protected Configuration _configuration;
ErrorState _errorState;
Exception _exception;
public InitializeStateError(ErrorState errorState, Exception exc, Configuration configuration) {
super();
this._errorState = errorState;
this._exception = exc;
this._configuration = configuration;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.error("Unity Ads init: halting init in " + this._errorState.getMetricName() + ": " + this._exception.getMessage());
for (Class cls : this._configuration.getModuleConfigurationList()) {
IModuleConfiguration moduleConfiguration = this._configuration.getModuleConfiguration(cls);
if (moduleConfiguration != null) {
moduleConfiguration.initErrorState(this._configuration, this._errorState, this._exception.getMessage());
}
}
return null;
}
}
public static class InitializeStateNetworkError extends InitializeStateError implements IConnectivityListener {
private static long _lastConnectedEventTimeMs;
private static int _receivedConnectedEvents;
private ConditionVariable _conditionVariable;
private int _connectedEventThreshold;
private InitializeState _erroredState;
private int _maximumConnectedEvents;
private long _networkErrorTimeout;
private ErrorState _state;
public InitializeStateNetworkError(ErrorState errorState, Exception exc, InitializeState initializeState, Configuration configuration) {
super(errorState, exc, configuration);
this._state = errorState;
_receivedConnectedEvents = 0;
_lastConnectedEventTimeMs = 0L;
this._erroredState = initializeState;
this._networkErrorTimeout = configuration.getNetworkErrorTimeout();
this._maximumConnectedEvents = configuration.getMaximumConnectedEvents();
this._connectedEventThreshold = configuration.getConnectedEventThreshold();
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeStateError, com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.error("Unity Ads init: network error, waiting for connection events");
this._conditionVariable = new ConditionVariable();
ConnectivityMonitor.addListener(this);
if (this._conditionVariable.block(this._networkErrorTimeout)) {
ConnectivityMonitor.removeListener(this);
return this._erroredState;
}
ConnectivityMonitor.removeListener(this);
return new InitializeStateError(this._state, new Exception("No connected events within the timeout!"), this._configuration);
}
@Override // com.unity3d.services.core.connectivity.IConnectivityListener
public void onConnected() {
_receivedConnectedEvents++;
DeviceLog.debug("Unity Ads init got connected event");
if (shouldHandleConnectedEvent()) {
this._conditionVariable.open();
}
if (_receivedConnectedEvents > this._maximumConnectedEvents) {
ConnectivityMonitor.removeListener(this);
}
_lastConnectedEventTimeMs = System.currentTimeMillis();
}
@Override // com.unity3d.services.core.connectivity.IConnectivityListener
public void onDisconnected() {
DeviceLog.debug("Unity Ads init got disconnected event");
}
private boolean shouldHandleConnectedEvent() {
return System.currentTimeMillis() - _lastConnectedEventTimeMs >= ((long) this._connectedEventThreshold) && _receivedConnectedEvents <= this._maximumConnectedEvents;
}
}
public static class InitializeStateRetry extends InitializeState {
long _delay;
InitializeState _state;
public InitializeStateRetry(InitializeState initializeState, long j) {
super();
this._state = initializeState;
this._delay = j;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.debug("Unity Ads init: retrying in " + this._delay + " milliseconds");
try {
Thread.sleep(this._delay);
} catch (Exception e) {
DeviceLog.exception("Init retry interrupted", e);
Thread.currentThread().interrupt();
}
return this._state;
}
}
public static class InitializeStateLoadCacheConfigAndWebView extends InitializeState {
private Configuration _configuration;
private Configuration _localConfig;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateLoadCacheConfigAndWebView(Configuration configuration, Configuration configuration2) {
super();
this._configuration = configuration;
this._localConfig = configuration2;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
try {
return new InitializeStateCheckForUpdatedWebView(this._configuration, InitializeThread.loadCachedFileToByteArray(new File(SdkProperties.getLocalWebViewFile())), this._localConfig);
} catch (Exception unused) {
return new InitializeStateCleanCache(this._configuration, new InitializeStateLoadWeb(this._configuration));
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public static byte[] loadCachedFileToByteArray(File file) throws IOException {
if (file != null && file.exists()) {
try {
return Utilities.readFileBytes(file);
} catch (IOException unused) {
throw new IOException("could not read from file");
}
}
throw new IOException("file not found");
}
public static class InitializeStateCleanCache extends InitializeState {
private Configuration _configuration;
private InitializeState _nextState;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateCleanCache(Configuration configuration, InitializeState initializeState) {
super();
this._configuration = configuration;
this._nextState = initializeState;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
try {
File file = new File(SdkProperties.getLocalConfigurationFilepath());
File file2 = new File(SdkProperties.getLocalWebViewFile());
file.delete();
file2.delete();
} catch (Exception e) {
DeviceLog.error("Failure trying to clean cache: " + e.getMessage());
}
return this._nextState;
}
}
public static class InitializeStateCleanCacheIgnoreError extends InitializeStateCleanCache {
public InitializeStateCleanCacheIgnoreError(Configuration configuration, InitializeState initializeState) {
super(configuration, initializeState);
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeStateCleanCache, com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
try {
InitializeState execute = super.execute();
if (execute instanceof InitializeStateError) {
return null;
}
return execute;
} catch (Exception unused) {
return null;
}
}
}
public static class InitializeStateCheckForUpdatedWebView extends InitializeState {
private Configuration _configuration;
private Configuration _localWebViewConfiguration;
private byte[] _localWebViewData;
public InitializeStateCheckForUpdatedWebView(Configuration configuration, byte[] bArr, Configuration configuration2) {
super();
this._configuration = configuration;
this._localWebViewData = bArr;
this._localWebViewConfiguration = configuration2;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
try {
String Sha256 = Utilities.Sha256(this._localWebViewData);
if (!Sha256.equals(this._configuration.getWebViewHash())) {
SdkProperties.setLatestConfiguration(this._configuration);
}
if (!TextUtils.isEmpty(Sha256)) {
Configuration configuration = this._localWebViewConfiguration;
if (configuration != null && configuration.getWebViewHash() != null && this._localWebViewConfiguration.getWebViewHash().equals(Sha256) && SdkProperties.getVersionName().equals(this._localWebViewConfiguration.getSdkVersion())) {
return new InitializeStateCreate(this._localWebViewConfiguration, new String(this._localWebViewData, "UTF-8"));
}
Configuration configuration2 = this._configuration;
if (configuration2 != null && configuration2.getWebViewHash().equals(Sha256)) {
return new InitializeStateCreate(this._configuration, new String(this._localWebViewData, "UTF-8"));
}
}
} catch (Exception unused) {
}
return new InitializeStateCleanCache(this._configuration, new InitializeStateLoadWeb(this._configuration));
}
}
public static class InitializeStateDownloadWebView extends InitializeState {
private Configuration _configuration;
private HttpClient _httpClient;
private int _retries;
private long _retryDelay;
public InitializeStateDownloadWebView(Configuration configuration) {
super();
this._httpClient = (HttpClient) Utilities.getService(HttpClient.class);
this._configuration = configuration;
this._retries = 0;
this._retryDelay = configuration.getRetryDelay();
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
DeviceLog.info("Unity Ads init: downloading webapp from " + this._configuration.getWebViewUrl());
try {
try {
String obj = this._httpClient.executeBlocking(new HttpRequest(this._configuration.getWebViewUrl())).getBody().toString();
String webViewHash = this._configuration.getWebViewHash();
if (obj == null || webViewHash == null || !Utilities.Sha256(obj).equals(webViewHash)) {
return null;
}
return new InitializeStateUpdateCache(this._configuration, obj);
} catch (Exception unused) {
if (this._retries >= this._configuration.getMaxRetries()) {
return null;
}
long retryScalingFactor = (long) (this._retryDelay * this._configuration.getRetryScalingFactor());
this._retryDelay = retryScalingFactor;
this._retries++;
return new InitializeStateRetry(this, retryScalingFactor);
}
} catch (Exception e) {
DeviceLog.exception("Malformed URL", e);
return null;
}
}
}
public static class InitializeStateUpdateCache extends InitializeState {
private Configuration _configuration;
private String _webViewData;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateUpdateCache(Configuration configuration, String str) {
super();
this._configuration = configuration;
this._webViewData = str;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
if (this._configuration != null && this._webViewData != null) {
try {
Utilities.writeFile(new File(SdkProperties.getLocalWebViewFile()), this._webViewData);
Utilities.writeFile(new File(SdkProperties.getLocalConfigurationFilepath()), this._configuration.getFilteredJsonString());
} catch (Exception unused) {
return new InitializeStateCleanCacheIgnoreError(this._configuration, null);
}
}
return null;
}
}
public static class InitializeStateCheckForCachedWebViewUpdate extends InitializeState {
private Configuration _configuration;
public Configuration getConfiguration() {
return this._configuration;
}
public InitializeStateCheckForCachedWebViewUpdate(Configuration configuration) {
super();
this._configuration = configuration;
}
@Override // com.unity3d.services.core.configuration.InitializeThread.InitializeState
public InitializeState execute() {
try {
byte[] loadCachedFileToByteArray = InitializeThread.loadCachedFileToByteArray(new File(SdkProperties.getLocalWebViewFile()));
if (Utilities.Sha256(loadCachedFileToByteArray).equals(this._configuration.getWebViewHash())) {
return new InitializeStateUpdateCache(this._configuration, new String(loadCachedFileToByteArray, "UTF-8"));
}
} catch (Exception unused) {
}
return new InitializeStateDownloadWebView(this._configuration);
}
}
}

View File

@@ -0,0 +1,7 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public enum PrivacyCallError {
NETWORK_ISSUE,
LOCKED_423
}

View File

@@ -0,0 +1,39 @@
package com.unity3d.services.core.configuration;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class PrivacyConfig {
private PrivacyConfigStatus _privacyConfigStatus;
private boolean _shouldSendNonBehavioral;
public PrivacyConfigStatus getPrivacyStatus() {
return this._privacyConfigStatus;
}
public boolean shouldSendNonBehavioral() {
return this._shouldSendNonBehavioral;
}
public PrivacyConfig() {
this(PrivacyConfigStatus.UNKNOWN);
}
public PrivacyConfig(JSONObject jSONObject) {
parsePrivacyResponse(jSONObject);
}
public PrivacyConfig(PrivacyConfigStatus privacyConfigStatus) {
this._privacyConfigStatus = privacyConfigStatus;
this._shouldSendNonBehavioral = false;
}
public boolean allowedToSendPii() {
return this._privacyConfigStatus.equals(PrivacyConfigStatus.ALLOWED);
}
private void parsePrivacyResponse(JSONObject jSONObject) {
this._privacyConfigStatus = jSONObject.optBoolean("pas", false) ? PrivacyConfigStatus.ALLOWED : PrivacyConfigStatus.DENIED;
this._shouldSendNonBehavioral = jSONObject.optBoolean("snb", false);
}
}

View File

@@ -0,0 +1,12 @@
package com.unity3d.services.core.configuration;
/* loaded from: classes4.dex */
public enum PrivacyConfigStatus {
UNKNOWN,
ALLOWED,
DENIED;
public String toLowerCase() {
return name().toLowerCase();
}
}

View File

@@ -0,0 +1,37 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.misc.IObserver;
import com.unity3d.services.core.misc.Observable;
/* loaded from: classes4.dex */
public class PrivacyConfigStorage extends Observable<PrivacyConfig> {
private static PrivacyConfigStorage _instance;
private PrivacyConfig _privacyConfig = new PrivacyConfig();
private PrivacyConfigStorage() {
}
public static PrivacyConfigStorage getInstance() {
if (_instance == null) {
_instance = new PrivacyConfigStorage();
}
return _instance;
}
public synchronized PrivacyConfig getPrivacyConfig() {
return this._privacyConfig;
}
@Override // com.unity3d.services.core.misc.Observable
public synchronized void registerObserver(IObserver<PrivacyConfig> iObserver) {
super.registerObserver(iObserver);
if (this._privacyConfig.getPrivacyStatus() != PrivacyConfigStatus.UNKNOWN) {
iObserver.updated(this._privacyConfig);
}
}
public synchronized void setPrivacyConfig(PrivacyConfig privacyConfig) {
this._privacyConfig = privacyConfig;
notifyObservers(privacyConfig);
}
}

View File

@@ -0,0 +1,82 @@
package com.unity3d.services.core.configuration;
import com.unity3d.services.core.extensions.AbortRetryException;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.network.core.HttpClient;
import com.unity3d.services.core.network.mapper.WebRequestToHttpRequestKt;
import com.unity3d.services.core.network.model.HttpRequest;
import com.unity3d.services.core.network.model.HttpResponse;
import com.unity3d.services.core.properties.ClientProperties;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class PrivacyConfigurationLoader implements IConfigurationLoader {
private final IConfigurationLoader _configurationLoader;
private final ConfigurationRequestFactory _configurationRequestFactory;
private final HttpClient _httpClient;
private final PrivacyConfigStorage _privacyConfigStorage;
public PrivacyConfigurationLoader(IConfigurationLoader iConfigurationLoader, ConfigurationRequestFactory configurationRequestFactory, PrivacyConfigStorage privacyConfigStorage, HttpClient httpClient) {
this._configurationLoader = iConfigurationLoader;
this._configurationRequestFactory = configurationRequestFactory;
this._privacyConfigStorage = privacyConfigStorage;
this._httpClient = httpClient;
}
@Override // com.unity3d.services.core.configuration.IConfigurationLoader
public void loadConfiguration(IConfigurationLoaderListener iConfigurationLoaderListener) throws Exception {
final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
if (this._privacyConfigStorage.getPrivacyConfig().getPrivacyStatus() == PrivacyConfigStatus.UNKNOWN) {
load(new IPrivacyConfigurationListener() { // from class: com.unity3d.services.core.configuration.PrivacyConfigurationLoader.1
@Override // com.unity3d.services.core.configuration.IPrivacyConfigurationListener
public void onSuccess(PrivacyConfig privacyConfig) {
PrivacyConfigurationLoader.this._privacyConfigStorage.setPrivacyConfig(privacyConfig);
}
@Override // com.unity3d.services.core.configuration.IPrivacyConfigurationListener
public void onError(PrivacyCallError privacyCallError, String str) {
DeviceLog.warning("Couldn't fetch privacy configuration: " + str);
PrivacyConfigurationLoader.this._privacyConfigStorage.setPrivacyConfig(new PrivacyConfig());
if (privacyCallError == PrivacyCallError.LOCKED_423) {
atomicBoolean.set(true);
}
}
});
}
if (atomicBoolean.get()) {
throw new AbortRetryException("Game is disabled");
}
this._configurationLoader.loadConfiguration(iConfigurationLoaderListener);
}
@Override // com.unity3d.services.core.configuration.IConfigurationLoader
public Configuration getLocalConfiguration() {
return this._configurationLoader.getLocalConfiguration();
}
private void load(IPrivacyConfigurationListener iPrivacyConfigurationListener) throws Exception {
try {
HttpRequest httpRequest = WebRequestToHttpRequestKt.toHttpRequest(this._configurationRequestFactory.getWebRequest());
InitializeEventsMetricSender.getInstance().didPrivacyConfigRequestStart();
HttpResponse executeBlocking = this._httpClient.executeBlocking(httpRequest);
try {
if (executeBlocking.getStatusCode() / 100 == 2) {
InitializeEventsMetricSender.getInstance().didPrivacyConfigRequestEnd(true);
iPrivacyConfigurationListener.onSuccess(new PrivacyConfig(new JSONObject(executeBlocking.getBody().toString())));
} else if (executeBlocking.getStatusCode() == 423) {
InitializeEventsMetricSender.getInstance().didPrivacyConfigRequestEnd(false);
iPrivacyConfigurationListener.onError(PrivacyCallError.LOCKED_423, "Game ID is disabled " + ClientProperties.getGameId());
} else {
InitializeEventsMetricSender.getInstance().didPrivacyConfigRequestEnd(false);
iPrivacyConfigurationListener.onError(PrivacyCallError.NETWORK_ISSUE, "Privacy request failed with code: " + executeBlocking.getStatusCode());
}
} catch (Exception unused) {
InitializeEventsMetricSender.getInstance().didPrivacyConfigRequestEnd(false);
iPrivacyConfigurationListener.onError(PrivacyCallError.NETWORK_ISSUE, "Could not create web request");
}
} catch (Exception e) {
iPrivacyConfigurationListener.onError(PrivacyCallError.NETWORK_ISSUE, "Could not create web request: " + e);
}
}
}

View File

@@ -0,0 +1,42 @@
package com.unity3d.services.core.connectivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.unity3d.services.core.properties.ClientProperties;
/* loaded from: classes4.dex */
public class ConnectivityChangeReceiver extends BroadcastReceiver {
private static ConnectivityChangeReceiver _receiver;
public static void register() {
if (_receiver == null) {
_receiver = new ConnectivityChangeReceiver();
ClientProperties.getApplicationContext().registerReceiver(_receiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
}
}
public static void unregister() {
if (_receiver != null) {
ClientProperties.getApplicationContext().unregisterReceiver(_receiver);
_receiver = null;
}
}
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
NetworkInfo activeNetworkInfo;
if (intent.getBooleanExtra("noConnectivity", false)) {
ConnectivityMonitor.disconnected();
return;
}
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null || !activeNetworkInfo.isConnected()) {
return;
}
ConnectivityMonitor.connected();
}
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.connectivity;
/* loaded from: classes4.dex */
public enum ConnectivityEvent {
CONNECTED,
DISCONNECTED,
NETWORK_CHANGE
}

View File

@@ -0,0 +1,203 @@
package com.unity3d.services.core.connectivity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/* loaded from: classes4.dex */
public class ConnectivityMonitor {
private static int _connected = -1;
private static Set<IConnectivityListener> _listeners = null;
private static boolean _listening = false;
private static int _networkType = -1;
private static boolean _webappMonitoring = false;
private static boolean _wifi = false;
public static void setConnectionMonitoring(boolean z) {
_webappMonitoring = z;
updateListeningStatus();
}
public static void addListener(IConnectivityListener iConnectivityListener) {
if (_listeners == null) {
_listeners = Collections.newSetFromMap(new ConcurrentHashMap());
}
_listeners.add(iConnectivityListener);
updateListeningStatus();
}
public static void removeListener(IConnectivityListener iConnectivityListener) {
Set<IConnectivityListener> set = _listeners;
if (set == null) {
return;
}
set.remove(iConnectivityListener);
updateListeningStatus();
}
public static void stopAll() {
_listeners = null;
_webappMonitoring = false;
updateListeningStatus();
}
private static void updateListeningStatus() {
Set<IConnectivityListener> set;
if (_webappMonitoring || ((set = _listeners) != null && !set.isEmpty())) {
startListening();
} else {
stopListening();
}
}
private static void startListening() {
if (_listening) {
return;
}
_listening = true;
initConnectionStatus();
ConnectivityNetworkCallback.register();
}
private static void stopListening() {
if (_listening) {
_listening = false;
ConnectivityNetworkCallback.unregister();
}
}
private static void initConnectionStatus() {
ConnectivityManager connectivityManager = (ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity");
if (connectivityManager == null) {
return;
}
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
_connected = 0;
return;
}
_connected = 1;
boolean z = activeNetworkInfo.getType() == 1;
_wifi = z;
if (z) {
return;
}
try {
_networkType = ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkType();
} catch (SecurityException unused) {
DeviceLog.warning("Unity Ads was not able to get current network type due to missing permission");
}
}
public static void connected() {
if (_connected == 1) {
return;
}
DeviceLog.debug("Unity Ads connectivity change: connected");
initConnectionStatus();
Set<IConnectivityListener> set = _listeners;
if (set != null) {
Iterator<IConnectivityListener> it = set.iterator();
while (it.hasNext()) {
it.next().onConnected();
}
}
sendToWebview(ConnectivityEvent.CONNECTED, _wifi, _networkType);
}
public static void disconnected() {
if (_connected == 0) {
return;
}
_connected = 0;
DeviceLog.debug("Unity Ads connectivity change: disconnected");
Set<IConnectivityListener> set = _listeners;
if (set != null) {
Iterator<IConnectivityListener> it = set.iterator();
while (it.hasNext()) {
it.next().onDisconnected();
}
}
sendToWebview(ConnectivityEvent.DISCONNECTED, false, 0);
}
public static void connectionStatusChanged() {
NetworkInfo activeNetworkInfo;
int i;
if (_connected == 1 && (activeNetworkInfo = ((ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")).getActiveNetworkInfo()) != null && activeNetworkInfo.isConnected()) {
boolean z = activeNetworkInfo.getType() == 1;
try {
i = ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkType();
} catch (SecurityException unused) {
DeviceLog.warning("Unity Ads was not able to get current network type due to missing permission");
i = -1;
}
boolean z2 = _wifi;
if (z == z2 && (i == _networkType || z2)) {
return;
}
_wifi = z;
_networkType = i;
DeviceLog.debug("Unity Ads connectivity change: network change");
sendToWebview(ConnectivityEvent.NETWORK_CHANGE, z, i);
}
}
private static void sendToWebview(ConnectivityEvent connectivityEvent, boolean z, int i) {
WebViewApp currentApp;
if (_webappMonitoring && (currentApp = WebViewApp.getCurrentApp()) != null && currentApp.isWebAppLoaded()) {
int i2 = AnonymousClass1.$SwitchMap$com$unity3d$services$core$connectivity$ConnectivityEvent[connectivityEvent.ordinal()];
if (i2 == 1) {
if (z) {
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.CONNECTED, Boolean.valueOf(z), 0);
return;
} else {
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.CONNECTED, Boolean.valueOf(z), Integer.valueOf(i));
return;
}
}
if (i2 == 2) {
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.DISCONNECTED, new Object[0]);
} else {
if (i2 != 3) {
return;
}
if (z) {
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.NETWORK_CHANGE, Boolean.valueOf(z), 0);
} else {
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.NETWORK_CHANGE, Boolean.valueOf(z), Integer.valueOf(i));
}
}
}
}
/* renamed from: com.unity3d.services.core.connectivity.ConnectivityMonitor$1, reason: invalid class name */
public static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] $SwitchMap$com$unity3d$services$core$connectivity$ConnectivityEvent;
static {
int[] iArr = new int[ConnectivityEvent.values().length];
$SwitchMap$com$unity3d$services$core$connectivity$ConnectivityEvent = iArr;
try {
iArr[ConnectivityEvent.CONNECTED.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$unity3d$services$core$connectivity$ConnectivityEvent[ConnectivityEvent.DISCONNECTED.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$com$unity3d$services$core$connectivity$ConnectivityEvent[ConnectivityEvent.NETWORK_CHANGE.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
}
}
}

View File

@@ -0,0 +1,53 @@
package com.unity3d.services.core.connectivity;
import android.annotation.TargetApi;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import com.unity3d.services.core.properties.ClientProperties;
@TargetApi(21)
/* loaded from: classes4.dex */
public class ConnectivityNetworkCallback extends ConnectivityManager.NetworkCallback {
private static ConnectivityNetworkCallback _impl;
public static synchronized void register() {
synchronized (ConnectivityNetworkCallback.class) {
if (_impl == null) {
_impl = new ConnectivityNetworkCallback();
((ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")).registerNetworkCallback(new NetworkRequest.Builder().build(), _impl);
}
}
}
public static synchronized void unregister() {
synchronized (ConnectivityNetworkCallback.class) {
if (_impl != null) {
((ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")).unregisterNetworkCallback(_impl);
_impl = null;
}
}
}
@Override // android.net.ConnectivityManager.NetworkCallback
public void onAvailable(Network network) {
ConnectivityMonitor.connected();
}
@Override // android.net.ConnectivityManager.NetworkCallback
public void onLost(Network network) {
ConnectivityMonitor.disconnected();
}
@Override // android.net.ConnectivityManager.NetworkCallback
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
ConnectivityMonitor.connectionStatusChanged();
}
@Override // android.net.ConnectivityManager.NetworkCallback
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
ConnectivityMonitor.connectionStatusChanged();
}
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.connectivity;
/* loaded from: classes4.dex */
public interface IConnectivityListener {
void onConnected();
void onDisconnected();
}

View File

@@ -0,0 +1,193 @@
package com.unity3d.services.core.device;
import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import com.unity3d.services.core.log.DeviceLog;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@TargetApi(9)
/* loaded from: classes4.dex */
public class AdvertisingId {
private static final String ADVERTISING_ID_SERVICE_NAME = "com.google.android.gms.ads.identifier.internal.IAdvertisingIdService";
private static AdvertisingId instance;
private String advertisingIdentifier = null;
private boolean limitedAdvertisingTracking = false;
private static AdvertisingId getInstance() {
if (instance == null) {
instance = new AdvertisingId();
}
return instance;
}
public static void init(Context context) {
getInstance().fetchAdvertisingId(context);
}
public static String getAdvertisingTrackingId() {
return getInstance().advertisingIdentifier;
}
public static boolean getLimitedAdTracking() {
return getInstance().limitedAdvertisingTracking;
}
private void fetchAdvertisingId(Context context) {
boolean z;
GoogleAdvertisingServiceConnection googleAdvertisingServiceConnection = new GoogleAdvertisingServiceConnection();
Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
intent.setPackage("com.google.android.gms");
try {
z = context.bindService(intent, googleAdvertisingServiceConnection, 1);
} catch (Exception e) {
DeviceLog.exception("Couldn't bind to identifier service intent", e);
z = false;
}
try {
if (z) {
try {
GoogleAdvertisingInfo create = GoogleAdvertisingInfo.GoogleAdvertisingInfoBinder.create(googleAdvertisingServiceConnection.getBinder());
this.advertisingIdentifier = create.getId();
this.limitedAdvertisingTracking = create.getEnabled(true);
} catch (Exception e2) {
DeviceLog.exception("Couldn't get advertising info", e2);
if (!z) {
return;
}
}
}
if (!z) {
return;
}
context.unbindService(googleAdvertisingServiceConnection);
} catch (Throwable th) {
if (z) {
context.unbindService(googleAdvertisingServiceConnection);
}
throw th;
}
}
public interface GoogleAdvertisingInfo extends IInterface {
boolean getEnabled(boolean z) throws RemoteException;
String getId() throws RemoteException;
public static abstract class GoogleAdvertisingInfoBinder extends Binder implements GoogleAdvertisingInfo {
public static GoogleAdvertisingInfo create(IBinder iBinder) {
if (iBinder == null) {
return null;
}
IInterface queryLocalInterface = iBinder.queryLocalInterface(AdvertisingId.ADVERTISING_ID_SERVICE_NAME);
if (queryLocalInterface != null && (queryLocalInterface instanceof GoogleAdvertisingInfo)) {
return (GoogleAdvertisingInfo) queryLocalInterface;
}
return new GoogleAdvertisingInfoImplementation(iBinder);
}
@Override // android.os.Binder
public boolean onTransact(int i, Parcel parcel, Parcel parcel2, int i2) throws RemoteException {
if (i == 1) {
parcel.enforceInterface(AdvertisingId.ADVERTISING_ID_SERVICE_NAME);
String id = getId();
parcel2.writeNoException();
parcel2.writeString(id);
return true;
}
if (i == 2) {
parcel.enforceInterface(AdvertisingId.ADVERTISING_ID_SERVICE_NAME);
boolean enabled = getEnabled(parcel.readInt() != 0);
parcel2.writeNoException();
parcel2.writeInt(enabled ? 1 : 0);
return true;
}
return super.onTransact(i, parcel, parcel2, i2);
}
public static class GoogleAdvertisingInfoImplementation implements GoogleAdvertisingInfo {
private final IBinder _binder;
@Override // android.os.IInterface
public IBinder asBinder() {
return this._binder;
}
public GoogleAdvertisingInfoImplementation(IBinder iBinder) {
this._binder = iBinder;
}
@Override // com.unity3d.services.core.device.AdvertisingId.GoogleAdvertisingInfo
public String getId() throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken(AdvertisingId.ADVERTISING_ID_SERVICE_NAME);
this._binder.transact(1, obtain, obtain2, 0);
obtain2.readException();
return obtain2.readString();
} finally {
obtain2.recycle();
obtain.recycle();
}
}
@Override // com.unity3d.services.core.device.AdvertisingId.GoogleAdvertisingInfo
public boolean getEnabled(boolean z) throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken(AdvertisingId.ADVERTISING_ID_SERVICE_NAME);
obtain.writeInt(z ? 1 : 0);
this._binder.transact(2, obtain, obtain2, 0);
obtain2.readException();
return obtain2.readInt() != 0;
} finally {
obtain2.recycle();
obtain.recycle();
}
}
}
}
}
public class GoogleAdvertisingServiceConnection implements ServiceConnection {
private final BlockingQueue<IBinder> _binderQueue;
boolean _consumed;
@Override // android.content.ServiceConnection
public void onServiceDisconnected(ComponentName componentName) {
}
private GoogleAdvertisingServiceConnection() {
this._consumed = false;
this._binderQueue = new LinkedBlockingQueue();
}
@Override // android.content.ServiceConnection
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
try {
this._binderQueue.put(iBinder);
} catch (InterruptedException unused) {
DeviceLog.debug("Couldn't put service to binder que");
Thread.currentThread().interrupt();
}
}
public IBinder getBinder() throws InterruptedException {
if (this._consumed) {
throw new IllegalStateException();
}
this._consumed = true;
return this._binderQueue.take();
}
}
}

View File

@@ -0,0 +1,749 @@
package com.unity3d.services.core.device;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ConfigurationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.SystemClock;
import android.os.ext.SdkExtensions;
import android.provider.Settings;
import android.support.v4.media.session.PlaybackStateCompat;
import android.telephony.TelephonyManager;
import com.applovin.sdk.AppLovinEventTypes;
import com.facebook.internal.security.CertificateUtil;
import com.ironsource.r8;
import com.ironsource.v8;
import com.unity3d.ads.core.data.datasource.AndroidDynamicDeviceInfoDataSource;
import com.unity3d.ads.core.data.datasource.AndroidStaticDeviceInfoDataSource;
import com.unity3d.ads.core.domain.HandleInvocationsFromAdViewer;
import com.unity3d.services.UnityAdsConstants;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.preferences.AndroidPreferences;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.request.metrics.Metric;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class Device {
private static ConcurrentHashMap<String, Boolean> _reportedWarning = new ConcurrentHashMap<>();
private static SDKMetricsSender sdkMetricsSender = (SDKMetricsSender) Utilities.getService(SDKMetricsSender.class);
public enum MemoryInfoType {
TOTAL_MEMORY,
FREE_MEMORY
}
public static int getApiLevel() {
return Build.VERSION.SDK_INT;
}
public static int getExtensionVersion() {
int extensionVersion;
if (Build.VERSION.SDK_INT < 30) {
return -1;
}
extensionVersion = SdkExtensions.getExtensionVersion(30);
return extensionVersion;
}
public static String getOsVersion() {
return Build.VERSION.RELEASE;
}
public static String getManufacturer() {
return Build.MANUFACTURER;
}
public static String getModel() {
return Build.MODEL;
}
public static int getScreenLayout() {
if (ClientProperties.getApplicationContext() != null) {
return ClientProperties.getApplicationContext().getResources().getConfiguration().screenLayout;
}
return -1;
}
public static String getAdvertisingTrackingId() {
return AdvertisingId.getAdvertisingTrackingId();
}
public static boolean isLimitAdTrackingEnabled() {
return AdvertisingId.getLimitedAdTracking();
}
public static String getOpenAdvertisingTrackingId() {
return OpenAdvertisingId.getOpenAdvertisingTrackingId();
}
public static boolean isLimitOpenAdTrackingEnabled() {
return OpenAdvertisingId.getLimitedOpenAdTracking();
}
public static boolean isUsingWifi() {
ConnectivityManager connectivityManager;
if (ClientProperties.getApplicationContext() == null || (connectivityManager = (ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")) == null) {
return false;
}
TelephonyManager telephonyManager = (TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone");
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && connectivityManager.getBackgroundDataSetting() && connectivityManager.getActiveNetworkInfo().isConnected() && telephonyManager != null && activeNetworkInfo.getType() == 1 && activeNetworkInfo.isConnected();
}
public static String getIdfi() {
String string = AndroidPreferences.getString(UnityAdsConstants.Preferences.PREF_NAME_IDFI, UnityAdsConstants.Preferences.PREF_KEY_IDFI);
if (string == null) {
string = getAuid();
}
if (string != null) {
return string;
}
String uniqueEventId = getUniqueEventId();
AndroidPreferences.setString(UnityAdsConstants.Preferences.PREF_NAME_IDFI, UnityAdsConstants.Preferences.PREF_KEY_IDFI, uniqueEventId);
return uniqueEventId;
}
public static String getAuid() {
return AndroidPreferences.getString(UnityAdsConstants.Preferences.PREF_NAME_AUID, "auid");
}
public static String getConnectionType() {
return isUsingWifi() ? "wifi" : isActiveNetworkConnected() ? r8.g : "none";
}
public static int getNetworkType() {
if (ClientProperties.getApplicationContext() == null) {
return -1;
}
try {
return ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkType();
} catch (SecurityException unused) {
if (_reportedWarning.containsKey("getNetworkType")) {
return -1;
}
DeviceLog.warning("Unity Ads was not able to get current network type due to missing permission");
_reportedWarning.put("getNetworkType", Boolean.TRUE);
return -1;
}
}
public static boolean getNetworkMetered() {
ConnectivityManager connectivityManager;
if (ClientProperties.getApplicationContext() == null || (connectivityManager = (ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")) == null) {
return false;
}
return connectivityManager.isActiveNetworkMetered();
}
public static String getNetworkOperator() {
return ClientProperties.getApplicationContext() != null ? ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkOperator() : "";
}
public static String getNetworkOperatorName() {
return ClientProperties.getApplicationContext() != null ? ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkOperatorName() : "";
}
public static String getNetworkCountryISO() {
return ClientProperties.getApplicationContext() != null ? ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkCountryIso() : "";
}
public static float getDisplayMetricDensity() {
if (ClientProperties.getApplicationContext() != null) {
return ClientProperties.getApplicationContext().getResources().getDisplayMetrics().density;
}
return -1.0f;
}
public static int getScreenDensity() {
if (ClientProperties.getApplicationContext() != null) {
return ClientProperties.getApplicationContext().getResources().getDisplayMetrics().densityDpi;
}
return -1;
}
public static int getScreenWidth() {
if (ClientProperties.getApplicationContext() != null) {
return ClientProperties.getApplicationContext().getResources().getDisplayMetrics().widthPixels;
}
return -1;
}
public static int getScreenHeight() {
if (ClientProperties.getApplicationContext() != null) {
return ClientProperties.getApplicationContext().getResources().getDisplayMetrics().heightPixels;
}
return -1;
}
public static boolean isActiveNetworkConnected() {
ConnectivityManager connectivityManager;
NetworkInfo activeNetworkInfo;
return (ClientProperties.getApplicationContext() == null || (connectivityManager = (ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")) == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null || !activeNetworkInfo.isConnected()) ? false : true;
}
public static String getUniqueEventId() {
return UUID.randomUUID().toString();
}
public static boolean isWiredHeadsetOn() {
if (ClientProperties.getApplicationContext() != null) {
return ((AudioManager) ClientProperties.getApplicationContext().getSystemService("audio")).isWiredHeadsetOn();
}
return false;
}
public static String getSystemProperty(String str, String str2) {
if (str2 != null) {
return System.getProperty(str, str2);
}
return System.getProperty(str);
}
public static int getRingerMode() {
if (ClientProperties.getApplicationContext() == null) {
return -1;
}
AudioManager audioManager = (AudioManager) ClientProperties.getApplicationContext().getSystemService("audio");
if (audioManager != null) {
return audioManager.getRingerMode();
}
return -2;
}
public static int getStreamVolume(int i) {
if (ClientProperties.getApplicationContext() == null) {
return -1;
}
AudioManager audioManager = (AudioManager) ClientProperties.getApplicationContext().getSystemService("audio");
if (audioManager != null) {
return audioManager.getStreamVolume(i);
}
return -2;
}
public static int getStreamMaxVolume(int i) {
if (ClientProperties.getApplicationContext() == null) {
return -1;
}
AudioManager audioManager = (AudioManager) ClientProperties.getApplicationContext().getSystemService("audio");
if (audioManager != null) {
return audioManager.getStreamMaxVolume(i);
}
return -2;
}
public static int getScreenBrightness() {
if (ClientProperties.getApplicationContext() != null) {
return Settings.System.getInt(ClientProperties.getApplicationContext().getContentResolver(), "screen_brightness", -1);
}
return -1;
}
public static long getFreeSpace(File file) {
if (file == null || !file.exists()) {
return -1L;
}
return Math.round(file.getFreeSpace() / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID);
}
public static long getTotalSpace(File file) {
if (file == null || !file.exists()) {
return -1L;
}
return Math.round(file.getTotalSpace() / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID);
}
public static float getBatteryLevel() {
Intent registerReceiver;
if (ClientProperties.getApplicationContext() == null || (registerReceiver = ClientProperties.getApplicationContext().registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"))) == null) {
return -1.0f;
}
return registerReceiver.getIntExtra(AppLovinEventTypes.USER_COMPLETED_LEVEL, -1) / registerReceiver.getIntExtra("scale", -1);
}
public static int getBatteryStatus() {
Intent registerReceiver;
if (ClientProperties.getApplicationContext() == null || (registerReceiver = ClientProperties.getApplicationContext().registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"))) == null) {
return -1;
}
return registerReceiver.getIntExtra("status", -1);
}
public static long getTotalMemory() {
return getMemoryInfo(MemoryInfoType.TOTAL_MEMORY);
}
public static long getFreeMemory() {
return getMemoryInfo(MemoryInfoType.FREE_MEMORY);
}
/* renamed from: com.unity3d.services.core.device.Device$1, reason: invalid class name */
public static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] $SwitchMap$com$unity3d$services$core$device$Device$MemoryInfoType;
static {
int[] iArr = new int[MemoryInfoType.values().length];
$SwitchMap$com$unity3d$services$core$device$Device$MemoryInfoType = iArr;
try {
iArr[MemoryInfoType.TOTAL_MEMORY.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$unity3d$services$core$device$Device$MemoryInfoType[MemoryInfoType.FREE_MEMORY.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
/* JADX WARN: Removed duplicated region for block: B:31:0x005f A[EXC_TOP_SPLITTER, SYNTHETIC] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private static long getMemoryInfo(com.unity3d.services.core.device.Device.MemoryInfoType r6) {
/*
java.lang.String r0 = "Error closing RandomAccessFile"
int[] r1 = com.unity3d.services.core.device.Device.AnonymousClass1.$SwitchMap$com$unity3d$services$core$device$Device$MemoryInfoType
int r2 = r6.ordinal()
r1 = r1[r2]
r2 = 1
if (r1 == r2) goto L11
r2 = 2
if (r1 == r2) goto L11
r2 = -1
L11:
r1 = 0
java.io.RandomAccessFile r3 = new java.io.RandomAccessFile // Catch: java.lang.Throwable -> L37 java.io.IOException -> L39
java.lang.String r4 = "/proc/meminfo"
java.lang.String r5 = "r"
r3.<init>(r4, r5) // Catch: java.lang.Throwable -> L37 java.io.IOException -> L39
r4 = 0
L1c:
if (r4 >= r2) goto L2a
java.lang.String r1 = r3.readLine() // Catch: java.lang.Throwable -> L25 java.io.IOException -> L28
int r4 = r4 + 1
goto L1c
L25:
r6 = move-exception
r1 = r3
goto L5d
L28:
r1 = move-exception
goto L3c
L2a:
long r1 = getMemoryValueFromString(r1) // Catch: java.lang.Throwable -> L25 java.io.IOException -> L28
r3.close() // Catch: java.io.IOException -> L32
goto L36
L32:
r6 = move-exception
com.unity3d.services.core.log.DeviceLog.exception(r0, r6)
L36:
return r1
L37:
r6 = move-exception
goto L5d
L39:
r2 = move-exception
r3 = r1
r1 = r2
L3c:
java.lang.StringBuilder r2 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L25
r2.<init>() // Catch: java.lang.Throwable -> L25
java.lang.String r4 = "Error while reading memory info: "
r2.append(r4) // Catch: java.lang.Throwable -> L25
r2.append(r6) // Catch: java.lang.Throwable -> L25
java.lang.String r6 = r2.toString() // Catch: java.lang.Throwable -> L25
com.unity3d.services.core.log.DeviceLog.exception(r6, r1) // Catch: java.lang.Throwable -> L25
if (r3 == 0) goto L5a
r3.close() // Catch: java.io.IOException -> L56
goto L5a
L56:
r6 = move-exception
com.unity3d.services.core.log.DeviceLog.exception(r0, r6)
L5a:
r0 = -1
return r0
L5d:
if (r1 == 0) goto L67
r1.close() // Catch: java.io.IOException -> L63
goto L67
L63:
r1 = move-exception
com.unity3d.services.core.log.DeviceLog.exception(r0, r1)
L67:
throw r6
*/
throw new UnsupportedOperationException("Method not decompiled: com.unity3d.services.core.device.Device.getMemoryInfo(com.unity3d.services.core.device.Device$MemoryInfoType):long");
}
private static long getMemoryValueFromString(String str) {
if (str == null) {
return -1L;
}
Matcher matcher = Pattern.compile("(\\d+)").matcher(str);
String str2 = "";
while (matcher.find()) {
str2 = matcher.group(1);
}
return Long.parseLong(str2);
}
public static boolean isRooted() {
try {
return searchPathForBinary("su");
} catch (Exception e) {
DeviceLog.exception("Rooted check failed", e);
return false;
}
}
public static Boolean isAdbEnabled() {
if (getApiLevel() < 17) {
return oldAdbStatus();
}
return newAdbStatus();
}
private static Boolean oldAdbStatus() {
try {
return Boolean.valueOf(1 == Settings.Secure.getInt(ClientProperties.getApplicationContext().getContentResolver(), "adb_enabled", 0));
} catch (Exception e) {
DeviceLog.exception("Problems fetching adb enabled status", e);
return null;
}
}
@TargetApi(17)
private static Boolean newAdbStatus() {
try {
return Boolean.valueOf(1 == Settings.Global.getInt(ClientProperties.getApplicationContext().getContentResolver(), "adb_enabled", 0));
} catch (Exception e) {
DeviceLog.exception("Problems fetching adb enabled status", e);
return null;
}
}
public static JSONObject getPackageInfo(PackageManager packageManager) throws PackageManager.NameNotFoundException, JSONException {
String appName = ClientProperties.getAppName();
PackageInfo packageInfo = packageManager.getPackageInfo(appName, 0);
JSONObject jSONObject = new JSONObject();
jSONObject.put("installer", packageManager.getInstallerPackageName(appName));
jSONObject.put(v8.i.X, packageInfo.firstInstallTime);
jSONObject.put(v8.i.V, packageInfo.lastUpdateTime);
jSONObject.put("versionCode", packageInfo.versionCode);
jSONObject.put("versionName", packageInfo.versionName);
jSONObject.put(HandleInvocationsFromAdViewer.KEY_PACKAGE_NAME, packageInfo.packageName);
return jSONObject;
}
private static boolean searchPathForBinary(String str) {
File[] listFiles;
for (String str2 : System.getenv(AndroidStaticDeviceInfoDataSource.ENVIRONMENT_VARIABLE_PATH).split(CertificateUtil.DELIMITER)) {
File file = new File(str2);
if (file.exists() && file.isDirectory() && (listFiles = file.listFiles()) != null) {
for (File file2 : listFiles) {
if (file2.getName().equals(str)) {
return true;
}
}
}
}
return false;
}
public static String getGLVersion() {
ActivityManager activityManager;
ConfigurationInfo deviceConfigurationInfo;
if (ClientProperties.getApplicationContext() == null || (activityManager = (ActivityManager) ClientProperties.getApplicationContext().getSystemService("activity")) == null || (deviceConfigurationInfo = activityManager.getDeviceConfigurationInfo()) == null) {
return null;
}
return deviceConfigurationInfo.getGlEsVersion();
}
public static String getApkDigest() throws Exception {
String packageCodePath = ClientProperties.getApplicationContext().getPackageCodePath();
long nanoTime = System.nanoTime();
FileInputStream fileInputStream = null;
try {
File file = new File(packageCodePath);
long length = file.length() / PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED;
FileInputStream fileInputStream2 = new FileInputStream(file);
try {
String Sha256 = Utilities.Sha256(fileInputStream2);
try {
fileInputStream2.close();
} catch (IOException unused) {
}
if (TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - nanoTime) > 5000) {
sdkMetricsSender.sendMetric(new Metric("native_device_info_apk_digest_timeout", Long.valueOf(length)));
}
sdkMetricsSender.sendMetric(new Metric("native_device_info_apk_size", Long.valueOf(length)));
return Sha256;
} catch (Throwable th) {
th = th;
fileInputStream = fileInputStream2;
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException unused2) {
}
}
throw th;
}
} catch (Throwable th2) {
th = th2;
}
}
public static String getCertificateFingerprint() {
try {
Signature[] signatureArr = ClientProperties.getApplicationContext().getPackageManager().getPackageInfo(ClientProperties.getApplicationContext().getPackageName(), 64).signatures;
if (signatureArr == null || signatureArr.length < 1) {
return null;
}
return Utilities.toHexString(MessageDigest.getInstance(AndroidStaticDeviceInfoDataSource.ALGORITHM_SHA1).digest(((X509Certificate) CertificateFactory.getInstance(AndroidStaticDeviceInfoDataSource.CERTIFICATE_TYPE_X509).generateCertificate(new ByteArrayInputStream(signatureArr[0].toByteArray()))).getEncoded()));
} catch (Exception e) {
DeviceLog.exception("Exception when signing certificate fingerprint", e);
return null;
}
}
public static String getBoard() {
return Build.BOARD;
}
public static String getBootloader() {
return Build.BOOTLOADER;
}
public static String getBrand() {
return Build.BRAND;
}
public static String getDevice() {
return Build.DEVICE;
}
public static String getHardware() {
return Build.HARDWARE;
}
public static String getHost() {
return Build.HOST;
}
public static String getProduct() {
return Build.PRODUCT;
}
public static String getFingerprint() {
return Build.FINGERPRINT;
}
public static ArrayList<String> getSupportedAbis() {
if (getApiLevel() < 21) {
return getOldAbiList();
}
return getNewAbiList();
}
public static List<Sensor> getSensorList() {
if (ClientProperties.getApplicationContext() != null) {
return ((SensorManager) ClientProperties.getApplicationContext().getSystemService("sensor")).getSensorList(-1);
}
return null;
}
public static boolean isUSBConnected() {
Intent registerReceiver;
if (ClientProperties.getApplicationContext() == null || (registerReceiver = ClientProperties.getApplicationContext().registerReceiver(null, new IntentFilter(AndroidDynamicDeviceInfoDataSource.INTENT_USB_STATE))) == null) {
return false;
}
return registerReceiver.getBooleanExtra(AndroidDynamicDeviceInfoDataSource.USB_EXTRA_CONNECTED, false);
}
public static long getCPUCount() {
return Runtime.getRuntime().availableProcessors();
}
public static long getUptime() {
return SystemClock.uptimeMillis();
}
public static long getElapsedRealtime() {
return SystemClock.elapsedRealtime();
}
public static String getBuildId() {
return Build.ID;
}
public static String getBuildVersionIncremental() {
return Build.VERSION.INCREMENTAL;
}
private static ArrayList<String> getOldAbiList() {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(Build.CPU_ABI);
arrayList.add(Build.CPU_ABI2);
return arrayList;
}
@TargetApi(21)
private static ArrayList<String> getNewAbiList() {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.addAll(Arrays.asList(Build.SUPPORTED_ABIS));
return arrayList;
}
/* JADX WARN: Removed duplicated region for block: B:24:0x003b A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:33:0x001f -> B:8:0x0038). Please report as a decompilation issue!!! */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static java.util.Map<java.lang.String, java.lang.String> getProcessInfo() {
/*
java.lang.String r0 = "Error closing RandomAccessFile"
java.util.HashMap r1 = new java.util.HashMap
r1.<init>()
r2 = 0
java.io.RandomAccessFile r3 = new java.io.RandomAccessFile // Catch: java.lang.Throwable -> L28 java.io.IOException -> L2a
java.lang.String r4 = "/proc/self/stat"
java.lang.String r5 = "r"
r3.<init>(r4, r5) // Catch: java.lang.Throwable -> L28 java.io.IOException -> L2a
java.lang.String r2 = r3.readLine() // Catch: java.lang.Throwable -> L23 java.io.IOException -> L26
java.lang.String r4 = "stat"
r1.put(r4, r2) // Catch: java.lang.Throwable -> L23 java.io.IOException -> L26
r3.close() // Catch: java.io.IOException -> L1e
goto L38
L1e:
r2 = move-exception
com.unity3d.services.core.log.DeviceLog.exception(r0, r2)
goto L38
L23:
r1 = move-exception
r2 = r3
goto L39
L26:
r2 = move-exception
goto L2e
L28:
r1 = move-exception
goto L39
L2a:
r3 = move-exception
r6 = r3
r3 = r2
r2 = r6
L2e:
java.lang.String r4 = "Error while reading processor info: "
com.unity3d.services.core.log.DeviceLog.exception(r4, r2) // Catch: java.lang.Throwable -> L23
if (r3 == 0) goto L38
r3.close() // Catch: java.io.IOException -> L1e
L38:
return r1
L39:
if (r2 == 0) goto L43
r2.close() // Catch: java.io.IOException -> L3f
goto L43
L3f:
r2 = move-exception
com.unity3d.services.core.log.DeviceLog.exception(r0, r2)
L43:
throw r1
*/
throw new UnsupportedOperationException("Method not decompiled: com.unity3d.services.core.device.Device.getProcessInfo():java.util.Map");
}
public static boolean hasX264Decoder() {
return selectAllDecodeCodecs("video/avc").size() > 0;
}
public static boolean hasX265Decoder() {
return selectAllDecodeCodecs("video/hevc").size() > 0;
}
public static boolean hasAV1Decoder() {
return selectAllDecodeCodecs(MimeTypes.VIDEO_AV1).size() > 0;
}
public static List<MediaCodecInfo> selectAllDecodeCodecs(String str) {
ArrayList arrayList = new ArrayList();
int codecCount = MediaCodecList.getCodecCount();
for (int i = 0; i < codecCount; i++) {
MediaCodecInfo codecInfoAt = MediaCodecList.getCodecInfoAt(i);
if (!codecInfoAt.isEncoder()) {
for (String str2 : codecInfoAt.getSupportedTypes()) {
if (str2.equalsIgnoreCase(str) && isHardwareAccelerated(codecInfoAt, str)) {
arrayList.add(codecInfoAt);
}
}
}
}
return arrayList;
}
private static boolean isHardwareAccelerated(MediaCodecInfo mediaCodecInfo, String str) {
if (getApiLevel() >= 29) {
return isHardwareAcceleratedV29(mediaCodecInfo);
}
return !isSoftwareOnly(mediaCodecInfo, str);
}
@TargetApi(29)
private static boolean isHardwareAcceleratedV29(MediaCodecInfo mediaCodecInfo) {
boolean isHardwareAccelerated;
isHardwareAccelerated = mediaCodecInfo.isHardwareAccelerated();
return isHardwareAccelerated;
}
private static boolean isSoftwareOnly(MediaCodecInfo mediaCodecInfo, String str) {
if (getApiLevel() >= 29) {
return isSoftwareOnlyV29(mediaCodecInfo);
}
String lowerCase = mediaCodecInfo.getName().toLowerCase();
if (lowerCase.startsWith("arc.")) {
return false;
}
return lowerCase.startsWith("omx.google.") || lowerCase.startsWith("omx.ffmpeg.") || (lowerCase.startsWith("omx.sec.") && lowerCase.contains(".sw.")) || lowerCase.equals("omx.qcom.video.decoder.hevcswvdec") || lowerCase.startsWith("c2.android.") || lowerCase.startsWith("c2.google.") || !(lowerCase.startsWith("omx.") || lowerCase.startsWith("c2."));
}
@TargetApi(29)
private static boolean isSoftwareOnlyV29(MediaCodecInfo mediaCodecInfo) {
boolean isSoftwareOnly;
isSoftwareOnly = mediaCodecInfo.isSoftwareOnly();
return isSoftwareOnly;
}
}

View File

@@ -0,0 +1,15 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public enum DeviceError {
APPLICATION_CONTEXT_NULL,
APPLICATION_INFO_NOT_AVAILABLE,
AUDIOMANAGER_NULL,
INVALID_STORAGETYPE,
COULDNT_GET_STORAGE_LOCATION,
COULDNT_GET_GL_VERSION,
JSON_ERROR,
COULDNT_GET_DIGEST,
COULDNT_GET_FINGERPRINT,
COULDNT_GET_ADB_STATUS
}

View File

@@ -0,0 +1,6 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public enum DeviceInfoEvent {
VOLUME_CHANGED
}

View File

@@ -0,0 +1,11 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public class MimeTypes {
public static final String BASE_TYPE_AUDIO = "audio";
public static final String BASE_TYPE_VIDEO = "video";
public static final String VIDEO_AV1 = "video/av01";
public static final String VIDEO_H264 = "video/avc";
public static final String VIDEO_H265 = "video/hevc";
public static final String VIDEO_WEBM = "video/webm";
}

View File

@@ -0,0 +1,184 @@
package com.unity3d.services.core.device;
import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import com.unity3d.services.core.log.DeviceLog;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@TargetApi(9)
/* loaded from: classes4.dex */
public class OpenAdvertisingId {
private static final String HW_DEVICE_NAME = "HUAWEI";
private static final String HW_OPEN_ADVERTISING_ID_SERVICE_NAME = "com.uodis.opendevice.aidl.OpenDeviceIdentifierService";
private static OpenAdvertisingId instance;
private String openAdvertisingIdentifier = null;
private boolean limitedOpenAdTracking = false;
private static OpenAdvertisingId getInstance() {
if (instance == null) {
instance = new OpenAdvertisingId();
}
return instance;
}
public static void init(Context context) {
if (Build.MANUFACTURER.toUpperCase().equals(HW_DEVICE_NAME)) {
getInstance().fetchOAId(context);
}
}
public static String getOpenAdvertisingTrackingId() {
return getInstance().openAdvertisingIdentifier;
}
public static boolean getLimitedOpenAdTracking() {
return getInstance().limitedOpenAdTracking;
}
private void fetchOAId(Context context) {
HWAdvertisingServiceConnection hWAdvertisingServiceConnection = new HWAdvertisingServiceConnection();
Intent intent = new Intent("com.uodis.opendevice.OPENIDS_SERVICE");
intent.setPackage("com.huawei.hwid");
try {
try {
if (context.bindService(intent, hWAdvertisingServiceConnection, 1)) {
try {
HWAdvertisingInfo create = HWAdvertisingInfo.HWAdvertisingInfoBinder.create(hWAdvertisingServiceConnection.getBinder());
this.openAdvertisingIdentifier = create.getId();
this.limitedOpenAdTracking = create.getEnabled(true);
} catch (Exception e) {
DeviceLog.exception("Couldn't get openAdvertising info", e);
}
}
} finally {
context.unbindService(hWAdvertisingServiceConnection);
}
} catch (Exception e2) {
DeviceLog.exception("Couldn't bind to identifier service intent", e2);
}
}
public interface HWAdvertisingInfo extends IInterface {
boolean getEnabled(boolean z) throws RemoteException;
String getId() throws RemoteException;
public static abstract class HWAdvertisingInfoBinder extends Binder implements HWAdvertisingInfo {
public static HWAdvertisingInfo create(IBinder iBinder) {
if (iBinder == null) {
return null;
}
IInterface queryLocalInterface = iBinder.queryLocalInterface(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME);
if (queryLocalInterface != null && (queryLocalInterface instanceof HWAdvertisingInfo)) {
return (HWAdvertisingInfo) queryLocalInterface;
}
return new HWAdvertisingInfoImplementation(iBinder);
}
@Override // android.os.Binder
public boolean onTransact(int i, Parcel parcel, Parcel parcel2, int i2) throws RemoteException {
if (i == 1) {
parcel.enforceInterface(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME);
String id = getId();
parcel2.writeNoException();
parcel2.writeString(id);
return true;
}
if (i == 2) {
parcel.enforceInterface(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME);
boolean enabled = getEnabled(parcel.readInt() != 0);
parcel2.writeNoException();
parcel2.writeInt(enabled ? 1 : 0);
return true;
}
return super.onTransact(i, parcel, parcel2, i2);
}
public static class HWAdvertisingInfoImplementation implements HWAdvertisingInfo {
private final IBinder _binder;
@Override // android.os.IInterface
public IBinder asBinder() {
return this._binder;
}
public HWAdvertisingInfoImplementation(IBinder iBinder) {
this._binder = iBinder;
}
@Override // com.unity3d.services.core.device.OpenAdvertisingId.HWAdvertisingInfo
public String getId() throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME);
this._binder.transact(1, obtain, obtain2, 0);
obtain2.readException();
return obtain2.readString();
} finally {
obtain2.recycle();
obtain.recycle();
}
}
@Override // com.unity3d.services.core.device.OpenAdvertisingId.HWAdvertisingInfo
public boolean getEnabled(boolean z) throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME);
obtain.writeInt(z ? 1 : 0);
this._binder.transact(2, obtain, obtain2, 0);
obtain2.readException();
return obtain2.readInt() != 0;
} finally {
obtain2.recycle();
obtain.recycle();
}
}
}
}
}
public class HWAdvertisingServiceConnection implements ServiceConnection {
private final BlockingQueue<IBinder> _binderQueue;
boolean _consumed;
@Override // android.content.ServiceConnection
public void onServiceDisconnected(ComponentName componentName) {
}
private HWAdvertisingServiceConnection() {
this._consumed = false;
this._binderQueue = new LinkedBlockingQueue();
}
@Override // android.content.ServiceConnection
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
try {
this._binderQueue.put(iBinder);
} catch (InterruptedException unused) {
DeviceLog.debug("Couldn't put service to binder que");
Thread.currentThread().interrupt();
}
}
public IBinder getBinder() throws InterruptedException {
if (this._consumed) {
throw new IllegalStateException();
}
this._consumed = true;
return this._binderQueue.take();
}
}
}

View File

@@ -0,0 +1,133 @@
package com.unity3d.services.core.device;
import com.unity3d.services.core.device.StorageManager;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.JsonStorage;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.webview.WebViewApp;
import com.unity3d.services.core.webview.WebViewEventCategory;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.List;
import kotlin.collections.CollectionsKt__CollectionsKt;
import kotlin.collections.CollectionsKt___CollectionsKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
import kotlin.text.Charsets;
import kotlinx.coroutines.flow.MutableStateFlow;
import kotlinx.coroutines.flow.StateFlowKt;
import org.json.JSONObject;
@SourceDebugExtension({"SMAP\nStorage.kt\nKotlin\n*S Kotlin\n*F\n+ 1 Storage.kt\ncom/unity3d/services/core/device/Storage\n+ 2 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n*L\n1#1,100:1\n1855#2,2:101\n*S KotlinDebug\n*F\n+ 1 Storage.kt\ncom/unity3d/services/core/device/Storage\n*L\n78#1:101,2\n*E\n"})
/* loaded from: classes4.dex */
public final class Storage extends JsonStorage {
public static final Companion Companion = new Companion(null);
private static final MutableStateFlow onStorageEventCallbacks = StateFlowKt.MutableStateFlow(CollectionsKt__CollectionsKt.emptyList());
private final String _targetFileName;
private final StorageManager.StorageType type;
public final StorageManager.StorageType getType() {
return this.type;
}
public Storage(String _targetFileName, StorageManager.StorageType type) {
Intrinsics.checkNotNullParameter(_targetFileName, "_targetFileName");
Intrinsics.checkNotNullParameter(type, "type");
this._targetFileName = _targetFileName;
this.type = type;
}
public final synchronized boolean readStorage() {
byte[] readFileBytes;
boolean z = false;
try {
try {
readFileBytes = Utilities.readFileBytes(new File(this._targetFileName));
} catch (FileNotFoundException e) {
DeviceLog.debug("Storage JSON file not found in local cache:", e);
}
} catch (Exception e2) {
DeviceLog.debug("Failed to read storage JSON file:", e2);
}
if (readFileBytes == null) {
return false;
}
setData(new JSONObject(new String(readFileBytes, Charsets.UTF_8)));
z = true;
return z;
}
public final synchronized boolean initStorage() {
readStorage();
super.initData();
return true;
}
public final synchronized boolean writeStorage() {
File file = new File(this._targetFileName);
if (getData() == null) {
return false;
}
return Utilities.writeFile(file, getData().toString());
}
public final synchronized boolean clearStorage() {
clearData();
return new File(this._targetFileName).delete();
}
public final synchronized boolean storageFileExists() {
return new File(this._targetFileName).exists();
}
public final synchronized void sendEvent(StorageEvent storageEvent, Object obj) {
List list = (List) onStorageEventCallbacks.getValue();
if (!list.isEmpty()) {
Intrinsics.checkNotNull(storageEvent);
StorageEventInfo storageEventInfo = new StorageEventInfo(storageEvent, this.type, obj);
Iterator it = list.iterator();
while (it.hasNext()) {
((Function1) it.next()).invoke(storageEventInfo);
}
return;
}
if (WebViewApp.getCurrentApp() == null || !WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.STORAGE, storageEvent, this.type.name(), obj)) {
DeviceLog.debug("Couldn't send storage event to WebApp");
}
}
@SourceDebugExtension({"SMAP\nStorage.kt\nKotlin\n*S Kotlin\n*F\n+ 1 Storage.kt\ncom/unity3d/services/core/device/Storage$Companion\n+ 2 StateFlow.kt\nkotlinx/coroutines/flow/StateFlowKt\n*L\n1#1,100:1\n230#2,5:101\n230#2,5:106\n*S KotlinDebug\n*F\n+ 1 Storage.kt\ncom/unity3d/services/core/device/Storage$Companion\n*L\n96#1:101,5\n97#1:106,5\n*E\n"})
public static final class Companion {
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
private Companion() {
}
public final void addStorageEventCallback(Function1 callback) {
Object value;
List plus;
Intrinsics.checkNotNullParameter(callback, "callback");
MutableStateFlow mutableStateFlow = Storage.onStorageEventCallbacks;
do {
value = mutableStateFlow.getValue();
plus = CollectionsKt___CollectionsKt.plus((List) value, callback);
} while (!mutableStateFlow.compareAndSet(value, plus));
}
public final void removeStorageEventCallback(Function1 callback) {
Object value;
List minus;
Intrinsics.checkNotNullParameter(callback, "callback");
MutableStateFlow mutableStateFlow = Storage.onStorageEventCallbacks;
do {
value = mutableStateFlow.getValue();
minus = CollectionsKt___CollectionsKt.minus((List) value, callback);
} while (!mutableStateFlow.compareAndSet(value, minus));
}
}
}

View File

@@ -0,0 +1,11 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public enum StorageError {
COULDNT_SET_VALUE,
COULDNT_GET_VALUE,
COULDNT_WRITE_STORAGE_TO_CACHE,
COULDNT_CLEAR_STORAGE,
COULDNT_GET_STORAGE,
COULDNT_DELETE_VALUE
}

View File

@@ -0,0 +1,11 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public enum StorageEvent {
SET,
DELETE,
CLEAR,
WRITE,
READ,
INIT
}

View File

@@ -0,0 +1,83 @@
package com.unity3d.services.core.device;
import com.unity3d.services.core.device.StorageManager;
import kotlin.jvm.internal.Intrinsics;
/* loaded from: classes4.dex */
public final class StorageEventInfo {
private final StorageEvent eventType;
private final StorageManager.StorageType storageType;
private final Object value;
public static /* synthetic */ StorageEventInfo copy$default(StorageEventInfo storageEventInfo, StorageEvent storageEvent, StorageManager.StorageType storageType, Object obj, int i, Object obj2) {
if ((i & 1) != 0) {
storageEvent = storageEventInfo.eventType;
}
if ((i & 2) != 0) {
storageType = storageEventInfo.storageType;
}
if ((i & 4) != 0) {
obj = storageEventInfo.value;
}
return storageEventInfo.copy(storageEvent, storageType, obj);
}
public final StorageEvent component1() {
return this.eventType;
}
public final StorageManager.StorageType component2() {
return this.storageType;
}
public final Object component3() {
return this.value;
}
public final StorageEventInfo copy(StorageEvent eventType, StorageManager.StorageType storageType, Object obj) {
Intrinsics.checkNotNullParameter(eventType, "eventType");
Intrinsics.checkNotNullParameter(storageType, "storageType");
return new StorageEventInfo(eventType, storageType, obj);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof StorageEventInfo)) {
return false;
}
StorageEventInfo storageEventInfo = (StorageEventInfo) obj;
return this.eventType == storageEventInfo.eventType && this.storageType == storageEventInfo.storageType && Intrinsics.areEqual(this.value, storageEventInfo.value);
}
public final StorageEvent getEventType() {
return this.eventType;
}
public final StorageManager.StorageType getStorageType() {
return this.storageType;
}
public final Object getValue() {
return this.value;
}
public int hashCode() {
int hashCode = ((this.eventType.hashCode() * 31) + this.storageType.hashCode()) * 31;
Object obj = this.value;
return hashCode + (obj == null ? 0 : obj.hashCode());
}
public String toString() {
return "StorageEventInfo(eventType=" + this.eventType + ", storageType=" + this.storageType + ", value=" + this.value + ')';
}
public StorageEventInfo(StorageEvent eventType, StorageManager.StorageType storageType, Object obj) {
Intrinsics.checkNotNullParameter(eventType, "eventType");
Intrinsics.checkNotNullParameter(storageType, "storageType");
this.eventType = eventType;
this.storageType = storageType;
this.value = obj;
}
}

View File

@@ -0,0 +1,128 @@
package com.unity3d.services.core.device;
import android.content.Context;
import com.unity3d.services.core.properties.SdkProperties;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* loaded from: classes4.dex */
public class StorageManager {
private static final Map<StorageType, String> _storageFileMap = Collections.synchronizedMap(new HashMap());
private static final List<Storage> _storages = Collections.synchronizedList(new ArrayList());
public enum StorageType {
PRIVATE,
PUBLIC
}
public static boolean init(Context context) {
File filesDir;
if (context == null || (filesDir = context.getFilesDir()) == null) {
return false;
}
StorageType storageType = StorageType.PUBLIC;
addStorageLocation(storageType, filesDir + "/" + SdkProperties.getLocalStorageFilePrefix() + "public-data.json");
if (!setupStorage(storageType)) {
return false;
}
StorageType storageType2 = StorageType.PRIVATE;
addStorageLocation(storageType2, filesDir + "/" + SdkProperties.getLocalStorageFilePrefix() + "private-data.json");
return setupStorage(storageType2);
}
public static void initStorage(StorageType storageType) {
if (hasStorage(storageType)) {
Storage storage = getStorage(storageType);
if (storage != null) {
storage.initStorage();
return;
}
return;
}
Map<StorageType, String> map = _storageFileMap;
if (map.containsKey(storageType)) {
Storage storage2 = new Storage(map.get(storageType), storageType);
storage2.initStorage();
_storages.add(storage2);
}
}
private static boolean setupStorage(StorageType storageType) {
if (hasStorage(storageType)) {
return true;
}
initStorage(storageType);
Storage storage = getStorage(storageType);
if (storage != null && !storage.storageFileExists()) {
storage.writeStorage();
}
return storage != null;
}
public static Storage getStorage(StorageType storageType) {
List<Storage> list = _storages;
if (list == null) {
return null;
}
synchronized (list) {
try {
for (Storage storage : list) {
if (storage.getType().equals(storageType)) {
return storage;
}
}
return null;
} finally {
}
}
}
public static boolean hasStorage(StorageType storageType) {
List<Storage> list = _storages;
if (list == null) {
return false;
}
synchronized (list) {
try {
Iterator<Storage> it = list.iterator();
while (it.hasNext()) {
if (it.next().getType().equals(storageType)) {
return true;
}
}
return false;
} finally {
}
}
}
public static synchronized void addStorageLocation(StorageType storageType, String str) {
synchronized (StorageManager.class) {
Map<StorageType, String> map = _storageFileMap;
if (!map.containsKey(storageType)) {
map.put(storageType, str);
}
}
}
public static synchronized void removeStorage(StorageType storageType) {
synchronized (StorageManager.class) {
try {
if (getStorage(storageType) != null) {
_storages.remove(getStorage(storageType));
}
Map<StorageType, String> map = _storageFileMap;
if (map != null) {
map.remove(storageType);
}
} catch (Throwable th) {
throw th;
}
}
}
}

View File

@@ -0,0 +1,7 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public enum TokenType {
TOKEN_NATIVE,
TOKEN_REMOTE
}

View File

@@ -0,0 +1,14 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public interface VolumeChange {
void clearAllListeners();
void registerListener(VolumeChangeListener volumeChangeListener);
void startObserving();
void stopObserving();
void unregisterListener(VolumeChangeListener volumeChangeListener);
}

View File

@@ -0,0 +1,96 @@
package com.unity3d.services.core.device;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import com.unity3d.services.core.properties.ClientProperties;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.Intrinsics;
/* loaded from: classes4.dex */
public final class VolumeChangeContentObserver implements VolumeChange {
private ContentObserver contentObserver;
private List<VolumeChangeListener> listeners = new ArrayList();
@Override // com.unity3d.services.core.device.VolumeChange
public synchronized void startObserving() {
ContentResolver contentResolver;
if (this.contentObserver != null) {
return;
}
final Handler handler = new Handler(Looper.getMainLooper());
this.contentObserver = new ContentObserver(handler) { // from class: com.unity3d.services.core.device.VolumeChangeContentObserver$startObserving$1
@Override // android.database.ContentObserver
public boolean deliverSelfNotifications() {
return false;
}
@Override // android.database.ContentObserver
public void onChange(boolean z, Uri uri) {
VolumeChangeContentObserver.this.triggerListeners();
}
};
Context applicationContext = ClientProperties.getApplicationContext();
if (applicationContext != null && (contentResolver = applicationContext.getContentResolver()) != null) {
Uri uri = Settings.System.CONTENT_URI;
ContentObserver contentObserver = this.contentObserver;
Intrinsics.checkNotNull(contentObserver, "null cannot be cast to non-null type android.database.ContentObserver");
contentResolver.registerContentObserver(uri, true, contentObserver);
}
}
@Override // com.unity3d.services.core.device.VolumeChange
public synchronized void stopObserving() {
ContentResolver contentResolver;
try {
if (this.contentObserver == null) {
return;
}
Context applicationContext = ClientProperties.getApplicationContext();
if (applicationContext != null && (contentResolver = applicationContext.getContentResolver()) != null) {
ContentObserver contentObserver = this.contentObserver;
Intrinsics.checkNotNull(contentObserver);
contentResolver.unregisterContentObserver(contentObserver);
}
this.contentObserver = null;
} catch (Throwable th) {
throw th;
}
}
@Override // com.unity3d.services.core.device.VolumeChange
public synchronized void registerListener(VolumeChangeListener volumeChangeListener) {
Intrinsics.checkNotNullParameter(volumeChangeListener, "volumeChangeListener");
if (!this.listeners.contains(volumeChangeListener)) {
startObserving();
this.listeners.add(volumeChangeListener);
}
}
@Override // com.unity3d.services.core.device.VolumeChange
public synchronized void unregisterListener(VolumeChangeListener volumeChangeListener) {
Intrinsics.checkNotNullParameter(volumeChangeListener, "volumeChangeListener");
this.listeners.remove(volumeChangeListener);
if (this.listeners.isEmpty()) {
stopObserving();
}
}
@Override // com.unity3d.services.core.device.VolumeChange
public synchronized void clearAllListeners() {
this.listeners.clear();
stopObserving();
}
/* JADX INFO: Access modifiers changed from: private */
public final synchronized void triggerListeners() {
for (VolumeChangeListener volumeChangeListener : this.listeners) {
volumeChangeListener.onVolumeChanged(Device.getStreamVolume(volumeChangeListener.getStreamType()));
}
}
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.device;
/* loaded from: classes4.dex */
public interface VolumeChangeListener {
int getStreamType();
void onVolumeChanged(int i);
}

View File

@@ -0,0 +1,51 @@
package com.unity3d.services.core.device;
import android.util.SparseArray;
import com.unity3d.services.core.webview.WebViewEventCategory;
import com.unity3d.services.core.webview.bridge.IEventSender;
import kotlin.jvm.internal.Intrinsics;
/* loaded from: classes4.dex */
public final class VolumeChangeMonitor {
private final IEventSender eventSender;
private final VolumeChange volumeChange;
private final SparseArray<VolumeChangeListener> volumeChangeListeners;
public VolumeChangeMonitor(IEventSender eventSender, VolumeChange volumeChange) {
Intrinsics.checkNotNullParameter(eventSender, "eventSender");
Intrinsics.checkNotNullParameter(volumeChange, "volumeChange");
this.eventSender = eventSender;
this.volumeChange = volumeChange;
this.volumeChangeListeners = new SparseArray<>();
}
public final void registerVolumeChangeListener(final int i) {
if (this.volumeChangeListeners.get(i) == null) {
VolumeChangeListener volumeChangeListener = new VolumeChangeListener() { // from class: com.unity3d.services.core.device.VolumeChangeMonitor$registerVolumeChangeListener$listener$1
@Override // com.unity3d.services.core.device.VolumeChangeListener
public int getStreamType() {
return i;
}
@Override // com.unity3d.services.core.device.VolumeChangeListener
public void onVolumeChanged(int i2) {
IEventSender iEventSender;
iEventSender = VolumeChangeMonitor.this.eventSender;
iEventSender.sendEvent(WebViewEventCategory.DEVICEINFO, DeviceInfoEvent.VOLUME_CHANGED, Integer.valueOf(getStreamType()), Integer.valueOf(i2), Integer.valueOf(Device.getStreamMaxVolume(i)));
}
};
this.volumeChangeListeners.append(i, volumeChangeListener);
this.volumeChange.registerListener(volumeChangeListener);
}
}
public final void unregisterVolumeChangeListener(int i) {
if (this.volumeChangeListeners.get(i) != null) {
VolumeChangeListener listener = this.volumeChangeListeners.get(i);
VolumeChange volumeChange = this.volumeChange;
Intrinsics.checkNotNullExpressionValue(listener, "listener");
volumeChange.unregisterListener(listener);
this.volumeChangeListeners.remove(i);
}
}
}

View File

@@ -0,0 +1,54 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.configuration.ConfigurationReader;
import com.unity3d.services.core.configuration.InitRequestType;
import com.unity3d.services.core.configuration.PrivacyConfigStorage;
import com.unity3d.services.core.device.reader.builder.DeviceInfoReaderBuilder;
import com.unity3d.services.core.device.reader.builder.DeviceInfoReaderPrivacyBuilder;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
/* loaded from: classes4.dex */
public class DeviceInfoDataFactory {
private final SDKMetricsSender _sdkMetricsSender;
public DeviceInfoDataFactory(SDKMetricsSender sDKMetricsSender) {
this._sdkMetricsSender = sDKMetricsSender;
}
/* renamed from: com.unity3d.services.core.device.reader.DeviceInfoDataFactory$1, reason: invalid class name */
public static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] $SwitchMap$com$unity3d$services$core$configuration$InitRequestType;
static {
int[] iArr = new int[InitRequestType.values().length];
$SwitchMap$com$unity3d$services$core$configuration$InitRequestType = iArr;
try {
iArr[InitRequestType.TOKEN.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$unity3d$services$core$configuration$InitRequestType[InitRequestType.PRIVACY.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
public IDeviceInfoDataContainer getDeviceInfoData(InitRequestType initRequestType) {
int i = AnonymousClass1.$SwitchMap$com$unity3d$services$core$configuration$InitRequestType[initRequestType.ordinal()];
if (i == 1) {
return getTokenDeviceInfoData();
}
if (i != 2) {
return null;
}
return getPrivacyDeviceInfoData();
}
private IDeviceInfoDataContainer getPrivacyDeviceInfoData() {
return new DeviceInfoReaderCompressor(new DeviceInfoReaderPrivacyBuilder(new ConfigurationReader(), PrivacyConfigStorage.getInstance(), GameSessionIdReader.getInstance()).build());
}
private IDeviceInfoDataContainer getTokenDeviceInfoData() {
return new DeviceInfoReaderCompressorWithMetrics(new DeviceInfoReaderCompressor(new DeviceInfoReaderBuilder(new ConfigurationReader(), PrivacyConfigStorage.getInstance(), GameSessionIdReader.getInstance()).build()), this._sdkMetricsSender);
}
}

View File

@@ -0,0 +1,48 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.log.DeviceLog;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.zip.GZIPOutputStream;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class DeviceInfoReaderCompressor implements IDeviceInfoDataCompressor {
public final IDeviceInfoReader _deviceInfoReader;
public DeviceInfoReaderCompressor(IDeviceInfoReader iDeviceInfoReader) {
this._deviceInfoReader = iDeviceInfoReader;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoDataContainer
public byte[] getDeviceData() {
return compressDeviceInfo(getDeviceInfo());
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoDataContainer
public Map<String, Object> getDeviceInfo() {
return this._deviceInfoReader.getDeviceInfoData();
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoDataCompressor
public byte[] compressDeviceInfo(Map<String, Object> map) {
if (map != null) {
String jSONObject = new JSONObject(map).toString();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(jSONObject.length());
try {
GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
gZIPOutputStream.write(jSONObject.getBytes());
gZIPOutputStream.flush();
gZIPOutputStream.close();
byteArrayOutputStream.close();
return byteArrayOutputStream.toByteArray();
} catch (IOException unused) {
DeviceLog.error("Error occurred while trying to compress device data.");
return null;
}
}
DeviceLog.error("Invalid DeviceInfoData: Expected non null map provided by reader");
return null;
}
}

View File

@@ -0,0 +1,57 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import com.unity3d.services.core.request.metrics.TSIMetric;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/* loaded from: classes4.dex */
public class DeviceInfoReaderCompressorWithMetrics implements IDeviceInfoDataCompressor {
private final IDeviceInfoDataCompressor _deviceInfoDataCompressor;
private long _endTime;
private final SDKMetricsSender _sdkMetricsSender;
private long _startTimeCompression;
private long _startTimeInfo;
public DeviceInfoReaderCompressorWithMetrics(IDeviceInfoDataCompressor iDeviceInfoDataCompressor, SDKMetricsSender sDKMetricsSender) {
this._deviceInfoDataCompressor = iDeviceInfoDataCompressor;
this._sdkMetricsSender = sDKMetricsSender;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoDataContainer
public byte[] getDeviceData() {
if (this._deviceInfoDataCompressor == null) {
return new byte[0];
}
this._startTimeInfo = System.nanoTime();
byte[] compressDeviceInfo = compressDeviceInfo(getDeviceInfo());
sendDeviceInfoMetrics();
return compressDeviceInfo;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoDataContainer
public Map<String, Object> getDeviceInfo() {
return this._deviceInfoDataCompressor.getDeviceInfo();
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoDataCompressor
public byte[] compressDeviceInfo(Map<String, Object> map) {
this._startTimeCompression = System.nanoTime();
byte[] compressDeviceInfo = this._deviceInfoDataCompressor.compressDeviceInfo(map);
this._endTime = System.nanoTime();
return compressDeviceInfo;
}
private long getDeviceInfoCollectionDuration() {
return TimeUnit.NANOSECONDS.toMillis(this._startTimeCompression - this._startTimeInfo);
}
private long getCompressionDuration() {
return TimeUnit.NANOSECONDS.toMillis(this._endTime - this._startTimeCompression);
}
private void sendDeviceInfoMetrics() {
this._sdkMetricsSender.sendMetric(TSIMetric.newDeviceInfoCollectionLatency(Long.valueOf(getDeviceInfoCollectionDuration())));
this._sdkMetricsSender.sendMetric(TSIMetric.newDeviceInfoCompressionLatency(Long.valueOf(getCompressionDuration())));
}
}

View File

@@ -0,0 +1,79 @@
package com.unity3d.services.core.device.reader;
import android.webkit.WebSettings;
import com.ea.nimble.ApplicationEnvironment;
import com.glu.plugins.gluanalytics.AnalyticsData;
import com.ironsource.v8;
import com.unity3d.ads.core.data.datasource.AndroidStaticDeviceInfoDataSource;
import com.unity3d.services.core.configuration.InitRequestType;
import com.unity3d.services.core.device.Device;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
/* loaded from: classes4.dex */
public class DeviceInfoReaderExtended implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
public DeviceInfoReaderExtended(IDeviceInfoReader iDeviceInfoReader) {
this._deviceInfoReader = iDeviceInfoReader;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
deviceInfoData.put("bundleId", ClientProperties.getAppName());
deviceInfoData.put("encrypted", Boolean.valueOf(ClientProperties.isAppDebuggable()));
deviceInfoData.put("rooted", Boolean.valueOf(Device.isRooted()));
deviceInfoData.put(AnalyticsData.S_OS_VERSION, Device.getOsVersion());
deviceInfoData.put("deviceModel", Device.getModel());
deviceInfoData.put("language", Locale.getDefault().toString());
deviceInfoData.put(v8.i.t, Device.getConnectionType());
deviceInfoData.put("screenHeight", Integer.valueOf(Device.getScreenHeight()));
deviceInfoData.put("screenWidth", Integer.valueOf(Device.getScreenWidth()));
deviceInfoData.put("deviceMake", Device.getManufacturer());
deviceInfoData.put("screenDensity", Integer.valueOf(Device.getScreenDensity()));
deviceInfoData.put("screenSize", Integer.valueOf(Device.getScreenLayout()));
deviceInfoData.put(ApplicationEnvironment.NIMBLE_PARAMETER_LIMIT_AD_TRACKING, Boolean.valueOf(Device.isLimitAdTrackingEnabled()));
deviceInfoData.put("networkOperator", Device.getNetworkOperator());
deviceInfoData.put("volume", Integer.valueOf(Device.getStreamVolume(1)));
deviceInfoData.put("deviceFreeSpace", Long.valueOf(Device.getFreeSpace(ClientProperties.getApplicationContext().getCacheDir())));
deviceInfoData.put("apiLevel", String.valueOf(Device.getApiLevel()));
deviceInfoData.put("networkType", Integer.valueOf(Device.getNetworkType()));
deviceInfoData.put("bundleVersion", ClientProperties.getAppVersion());
try {
deviceInfoData.put("timeZone", TimeZone.getDefault().getDisplayName(false, 0, Locale.US));
} catch (AssertionError e) {
DeviceLog.error("Could not read timeZone information: %s", e.getMessage());
}
deviceInfoData.put("timeZoneOffset", Integer.valueOf(TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000));
try {
deviceInfoData.put("webviewUa", WebSettings.getDefaultUserAgent(ClientProperties.getApplicationContext()));
} catch (Exception e2) {
DeviceLog.exception("Error getting webview user agent", e2);
}
deviceInfoData.put("networkOperatorName", Device.getNetworkOperatorName());
deviceInfoData.put("wiredHeadset", Boolean.valueOf(Device.isWiredHeadsetOn()));
deviceInfoData.put("versionCode", Integer.valueOf(SdkProperties.getVersionCode()));
deviceInfoData.put("stores", AndroidStaticDeviceInfoDataSource.STORE_GOOGLE);
deviceInfoData.put("appStartTime", Long.valueOf(SdkProperties.getInitializationTimeEpoch() / 1000));
deviceInfoData.put("sdkVersionName", SdkProperties.getVersionName());
deviceInfoData.put("eventTimeStamp", Long.valueOf(System.currentTimeMillis() / 1000));
deviceInfoData.put("cpuCount", Long.valueOf(Device.getCPUCount()));
deviceInfoData.put("usbConnected", Boolean.valueOf(Device.isUSBConnected()));
deviceInfoData.put("apkDeveloperSigningCertificateHash", Device.getCertificateFingerprint());
deviceInfoData.put("deviceUpTime", Long.valueOf(Device.getUptime()));
deviceInfoData.put("deviceElapsedRealtime", Long.valueOf(Device.getElapsedRealtime()));
deviceInfoData.put("adbEnabled", Device.isAdbEnabled());
deviceInfoData.put("androidFingerprint", Device.getFingerprint());
deviceInfoData.put("batteryStatus", Integer.valueOf(Device.getBatteryStatus()));
deviceInfoData.put(v8.i.Y, Float.valueOf(Device.getBatteryLevel()));
deviceInfoData.put("networkMetered", Boolean.valueOf(Device.getNetworkMetered()));
deviceInfoData.put("test", Boolean.valueOf(SdkProperties.isTestMode()));
deviceInfoData.put("callType", InitRequestType.TOKEN.getCallType());
return deviceInfoData;
}
}

View File

@@ -0,0 +1,39 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.misc.IJsonStorageReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class DeviceInfoReaderFilterProvider {
private static final String FILTER_EXCLUDE_KEY = "exclude";
private static final String UNIFIED_CONFIG_KEY = "unifiedconfig";
private IJsonStorageReader _storage;
public DeviceInfoReaderFilterProvider(IJsonStorageReader iJsonStorageReader) {
this._storage = iJsonStorageReader;
}
public List<String> getFilterList() {
Object opt;
ArrayList arrayList = new ArrayList();
IJsonStorageReader iJsonStorageReader = this._storage;
if (iJsonStorageReader == null || iJsonStorageReader.getData() == null || (opt = this._storage.getData().opt("unifiedconfig")) == null || !(opt instanceof JSONObject)) {
return arrayList;
}
Object opt2 = ((JSONObject) opt).opt(FILTER_EXCLUDE_KEY);
return opt2 instanceof String ? trimWhiteSpaces(Arrays.asList(((String) opt2).split(","))) : arrayList;
}
private List<String> trimWhiteSpaces(List<String> list) {
ArrayList arrayList = new ArrayList();
Iterator<String> it = list.iterator();
while (it.hasNext()) {
arrayList.add(it.next().trim());
}
return arrayList;
}
}

View File

@@ -0,0 +1,28 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.device.Device;
import java.util.Map;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
@SourceDebugExtension({"SMAP\nDeviceInfoReaderWithAuid.kt\nKotlin\n*S Kotlin\n*F\n+ 1 DeviceInfoReaderWithAuid.kt\ncom/unity3d/services/core/device/reader/DeviceInfoReaderWithAuid\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,13:1\n1#2:14\n*E\n"})
/* loaded from: classes4.dex */
public final class DeviceInfoReaderWithAuid implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
public DeviceInfoReaderWithAuid(IDeviceInfoReader _deviceInfoReader) {
Intrinsics.checkNotNullParameter(_deviceInfoReader, "_deviceInfoReader");
this._deviceInfoReader = _deviceInfoReader;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
Intrinsics.checkNotNullExpressionValue(deviceInfoData, "_deviceInfoReader.deviceInfoData");
String auid = Device.getAuid();
if (auid != null) {
deviceInfoData.put("auid", auid);
}
return deviceInfoData;
}
}

View File

@@ -0,0 +1,25 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.device.reader.pii.NonBehavioralFlag;
import com.unity3d.services.core.device.reader.pii.NonBehavioralFlagReader;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithBehavioralFlag implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final NonBehavioralFlagReader _nonBehavioralFlagReader;
public DeviceInfoReaderWithBehavioralFlag(IDeviceInfoReader iDeviceInfoReader, NonBehavioralFlagReader nonBehavioralFlagReader) {
this._deviceInfoReader = iDeviceInfoReader;
this._nonBehavioralFlagReader = nonBehavioralFlagReader;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
if (this._nonBehavioralFlagReader.getUserNonBehavioralFlag() != NonBehavioralFlag.UNKNOWN) {
deviceInfoData.put(JsonStorageKeyNames.USER_NON_BEHAVIORAL_KEY, Boolean.valueOf(this._nonBehavioralFlagReader.getUserNonBehavioralFlag() == NonBehavioralFlag.TRUE));
}
return deviceInfoData;
}
}

View File

@@ -0,0 +1,24 @@
package com.unity3d.services.core.device.reader;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithExtras implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final Map<String, String> _extras;
public DeviceInfoReaderWithExtras(IDeviceInfoReader iDeviceInfoReader, Map<String, String> map) {
this._deviceInfoReader = iDeviceInfoReader;
this._extras = map;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, String> map;
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
if (deviceInfoData != null && (map = this._extras) != null) {
deviceInfoData.putAll(map);
}
return deviceInfoData;
}
}

View File

@@ -0,0 +1,29 @@
package com.unity3d.services.core.device.reader;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithFilter implements IDeviceInfoReader {
IDeviceInfoReader _deviceInfoReader;
List<String> _keysToExclude;
public DeviceInfoReaderWithFilter(IDeviceInfoReader iDeviceInfoReader, List<String> list) {
this._deviceInfoReader = iDeviceInfoReader;
this._keysToExclude = list;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
List<String> list = this._keysToExclude;
if (list != null) {
Iterator<String> it = list.iterator();
while (it.hasNext()) {
deviceInfoData.remove(it.next());
}
}
return deviceInfoData;
}
}

View File

@@ -0,0 +1,22 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.lifecycle.LifecycleCache;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithLifecycle implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final LifecycleCache _lifecycleCache;
public DeviceInfoReaderWithLifecycle(IDeviceInfoReader iDeviceInfoReader, LifecycleCache lifecycleCache) {
this._deviceInfoReader = iDeviceInfoReader;
this._lifecycleCache = lifecycleCache;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
deviceInfoData.put("appActive", Boolean.valueOf(this._lifecycleCache.isAppActive()));
return deviceInfoData;
}
}

View File

@@ -0,0 +1,36 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import com.unity3d.services.core.request.metrics.TSIMetric;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithMetrics implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final SDKMetricsSender _sdkMetricsSender;
public DeviceInfoReaderWithMetrics(IDeviceInfoReader iDeviceInfoReader, SDKMetricsSender sDKMetricsSender) {
this._deviceInfoReader = iDeviceInfoReader;
this._sdkMetricsSender = sDKMetricsSender;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
IDeviceInfoReader iDeviceInfoReader = this._deviceInfoReader;
if (iDeviceInfoReader == null) {
return null;
}
Map<String, Object> deviceInfoData = iDeviceInfoReader.getDeviceInfoData();
sendMetrics(deviceInfoData);
return deviceInfoData;
}
private void sendMetrics(Map<String, Object> map) {
if (map != null) {
Object obj = map.get(JsonStorageKeyNames.GAME_SESSION_ID_NORMALIZED_KEY);
if ((obj instanceof Long) && ((Long) obj).longValue() == 0) {
this._sdkMetricsSender.sendMetric(TSIMetric.newMissingGameSessionId());
}
}
}
}

View File

@@ -0,0 +1,46 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.configuration.PrivacyConfigStorage;
import com.unity3d.services.core.device.reader.pii.PiiDataProvider;
import com.unity3d.services.core.device.reader.pii.PiiTrackingStatusReader;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithPrivacy implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final PiiDataProvider _piiDataProvider;
private final PiiTrackingStatusReader _piiTrackingStatusReader;
private final PrivacyConfigStorage _privacyConfigStorage;
public DeviceInfoReaderWithPrivacy(IDeviceInfoReader iDeviceInfoReader, PrivacyConfigStorage privacyConfigStorage, PiiDataProvider piiDataProvider, PiiTrackingStatusReader piiTrackingStatusReader) {
this._deviceInfoReader = iDeviceInfoReader;
this._privacyConfigStorage = privacyConfigStorage;
this._piiDataProvider = piiDataProvider;
this._piiTrackingStatusReader = piiTrackingStatusReader;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
PrivacyConfigStorage privacyConfigStorage = this._privacyConfigStorage;
if (privacyConfigStorage != null && privacyConfigStorage.getPrivacyConfig() != null) {
if (this._privacyConfigStorage.getPrivacyConfig().allowedToSendPii()) {
deviceInfoData.putAll(getPiiAttributesFromDevice());
}
if (this._privacyConfigStorage.getPrivacyConfig().shouldSendNonBehavioral()) {
deviceInfoData.put(JsonStorageKeyNames.USER_NON_BEHAVIORAL_KEY, Boolean.valueOf(this._piiTrackingStatusReader.getUserNonBehavioralFlag()));
}
}
return deviceInfoData;
}
private Map<String, Object> getPiiAttributesFromDevice() {
HashMap hashMap = new HashMap();
String advertisingTrackingId = this._piiDataProvider.getAdvertisingTrackingId();
if (advertisingTrackingId != null) {
hashMap.put(JsonStorageKeyNames.ADVERTISING_TRACKING_ID_NORMALIZED_KEY, advertisingTrackingId);
}
return hashMap;
}
}

View File

@@ -0,0 +1,25 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.configuration.InitRequestType;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithRequestType implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final InitRequestType _initRequestType;
public DeviceInfoReaderWithRequestType(IDeviceInfoReader iDeviceInfoReader, InitRequestType initRequestType) {
this._deviceInfoReader = iDeviceInfoReader;
this._initRequestType = initRequestType;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
InitRequestType initRequestType = this._initRequestType;
if (initRequestType != null) {
deviceInfoData.put("callType", initRequestType.toString().toLowerCase());
}
return deviceInfoData;
}
}

View File

@@ -0,0 +1,22 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.properties.Session;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithSessionId implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final Session _session;
public DeviceInfoReaderWithSessionId(IDeviceInfoReader iDeviceInfoReader, Session session) {
this._deviceInfoReader = iDeviceInfoReader;
this._session = session;
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
deviceInfoData.put("sessionId", this._session.getId());
return deviceInfoData;
}
}

View File

@@ -0,0 +1,30 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.misc.IJsonStorageReader;
import com.unity3d.services.core.misc.JsonFlattener;
import com.unity3d.services.core.misc.JsonFlattenerRules;
import com.unity3d.services.core.misc.JsonStorageAggregator;
import com.unity3d.services.core.misc.Utilities;
import csdk.gluads.Consts;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/* loaded from: classes4.dex */
public class DeviceInfoReaderWithStorageInfo implements IDeviceInfoReader {
private final IDeviceInfoReader _deviceInfoReader;
private final JsonFlattenerRules _jsonFlattenerRules;
private final List<IJsonStorageReader> _storageReaders;
public DeviceInfoReaderWithStorageInfo(IDeviceInfoReader iDeviceInfoReader, JsonFlattenerRules jsonFlattenerRules, IJsonStorageReader... iJsonStorageReaderArr) {
this._deviceInfoReader = iDeviceInfoReader;
this._jsonFlattenerRules = jsonFlattenerRules;
this._storageReaders = Arrays.asList(iJsonStorageReaderArr);
}
@Override // com.unity3d.services.core.device.reader.IDeviceInfoReader
public Map<String, Object> getDeviceInfoData() {
Map<String, Object> deviceInfoData = this._deviceInfoReader.getDeviceInfoData();
return deviceInfoData != null ? Utilities.combineJsonIntoMap(deviceInfoData, new JsonFlattener(new JsonStorageAggregator(this._storageReaders).getData()).flattenJson(Consts.STRING_PERIOD, this._jsonFlattenerRules)) : deviceInfoData;
}
}

View File

@@ -0,0 +1,69 @@
package com.unity3d.services.core.device.reader;
import com.unity3d.services.core.device.Storage;
import com.unity3d.services.core.device.StorageManager;
import com.unity3d.services.core.properties.ClientProperties;
import java.util.UUID;
/* loaded from: classes4.dex */
public class GameSessionIdReader implements IGameSessionIdReader {
private static final int GAME_SESSION_ID_LENGTH = 12;
private static volatile GameSessionIdReader _instance;
private Long gameSessionId;
private GameSessionIdReader() {
}
public static GameSessionIdReader getInstance() {
if (_instance == null) {
synchronized (GameSessionIdReader.class) {
try {
if (_instance == null) {
_instance = new GameSessionIdReader();
}
} finally {
}
}
}
return _instance;
}
@Override // com.unity3d.services.core.device.reader.IGameSessionIdReader
public synchronized Long getGameSessionId() {
try {
if (this.gameSessionId == null) {
generate();
}
} catch (Throwable th) {
throw th;
}
return this.gameSessionId;
}
@Override // com.unity3d.services.core.device.reader.IGameSessionIdReader
public synchronized Long getGameSessionIdAndStore() {
try {
if (this.gameSessionId == null) {
generate();
store();
}
} catch (Throwable th) {
throw th;
}
return this.gameSessionId;
}
private void generate() {
UUID randomUUID = UUID.randomUUID();
this.gameSessionId = Long.valueOf((Long.toString(randomUUID.getMostSignificantBits()) + Long.toString(randomUUID.getLeastSignificantBits())).replace("-", "").substring(0, 12));
}
private void store() {
Storage storage;
if (!StorageManager.init(ClientProperties.getApplicationContext()) || (storage = StorageManager.getStorage(StorageManager.StorageType.PRIVATE)) == null) {
return;
}
storage.set(JsonStorageKeyNames.GAME_SESSION_ID_NORMALIZED_KEY, this.gameSessionId);
storage.writeStorage();
}
}

View File

@@ -0,0 +1,93 @@
package com.unity3d.services.core.device.reader;
import android.app.Activity;
import android.view.Display;
import android.view.WindowManager;
import com.unity3d.services.core.configuration.ExperimentsReader;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.request.metrics.Metric;
import com.unity3d.services.core.request.metrics.SDKMetricsSender;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
/* loaded from: classes4.dex */
public class HdrInfoReader implements IHdrInfoReader {
private static final AtomicBoolean _hdrMetricsCaptured = new AtomicBoolean(false);
private static volatile HdrInfoReader _instance;
private final SDKMetricsSender _sdkMetricsSender = (SDKMetricsSender) Utilities.getService(SDKMetricsSender.class);
private HdrInfoReader() {
}
public static HdrInfoReader getInstance() {
if (_instance == null) {
synchronized (HdrInfoReader.class) {
try {
if (_instance == null) {
_instance = new HdrInfoReader();
}
} finally {
}
}
}
return _instance;
}
@Override // com.unity3d.services.core.device.reader.IHdrInfoReader
public void captureHDRCapabilityMetrics(Activity activity, ExperimentsReader experimentsReader) {
if (activity != null && experimentsReader.getCurrentlyActiveExperiments().isCaptureHDRCapabilitiesEnabled()) {
if (_hdrMetricsCaptured.compareAndSet(false, true)) {
ArrayList arrayList = new ArrayList(5);
Display.HdrCapabilities hdrCapabilities = ((WindowManager) activity.getSystemService("window")).getDefaultDisplay().getHdrCapabilities();
boolean z = false;
boolean z2 = false;
boolean z3 = false;
boolean z4 = false;
for (int i : hdrCapabilities.getSupportedHdrTypes()) {
if (i == 1) {
z = true;
} else if (i == 2) {
z2 = true;
} else if (i == 3) {
z4 = true;
} else if (i == 4) {
z3 = true;
}
}
long round = Math.round(hdrCapabilities.getDesiredMaxAverageLuminance());
long round2 = Math.round(hdrCapabilities.getDesiredMaxLuminance());
long round3 = Math.round(hdrCapabilities.getDesiredMinLuminance());
arrayList.add(new Metric("native_device_hdr_lum_max_average", Long.valueOf(round)));
arrayList.add(new Metric("native_device_hdr_lum_max", Long.valueOf(round2)));
arrayList.add(new Metric("native_device_hdr_lum_min", Long.valueOf(round3)));
boolean isScreenHdr = activity.getResources().getConfiguration().isScreenHdr();
if (z) {
arrayList.add(new Metric("native_device_hdr_dolby_vision_success"));
} else {
arrayList.add(new Metric("native_device_hdr_dolby_vision_failure"));
}
if (z2) {
arrayList.add(new Metric("native_device_hdr_hdr10_success"));
} else {
arrayList.add(new Metric("native_device_hdr_hdr10_failure"));
}
if (z3) {
arrayList.add(new Metric("native_device_hdr_hdr10_plus_success"));
} else {
arrayList.add(new Metric("native_device_hdr_hdr10_plus_failure"));
}
if (z4) {
arrayList.add(new Metric("native_device_hdr_hlg_success"));
} else {
arrayList.add(new Metric("native_device_hdr_hlg_failure"));
}
if (isScreenHdr) {
arrayList.add(new Metric("native_device_hdr_screen_hdr_success"));
} else {
arrayList.add(new Metric("native_device_hdr_screen_hdr_failure"));
}
this._sdkMetricsSender.sendMetrics(arrayList);
}
}
}
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.device.reader;
import java.util.Map;
/* loaded from: classes4.dex */
public interface IDeviceInfoDataCompressor extends IDeviceInfoDataContainer {
byte[] compressDeviceInfo(Map<String, Object> map);
}

View File

@@ -0,0 +1,10 @@
package com.unity3d.services.core.device.reader;
import java.util.Map;
/* loaded from: classes4.dex */
public interface IDeviceInfoDataContainer {
byte[] getDeviceData();
Map<String, Object> getDeviceInfo();
}

View File

@@ -0,0 +1,8 @@
package com.unity3d.services.core.device.reader;
import java.util.Map;
/* loaded from: classes4.dex */
public interface IDeviceInfoReader {
Map<String, Object> getDeviceInfoData();
}

Some files were not shown because too many files have changed in this diff Show More