Initial commit
This commit is contained in:
96
sources/com/unity3d/ads/configuration/Configuration.java
Normal file
96
sources/com/unity3d/ads/configuration/Configuration.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package com.unity3d.ads.configuration;
|
||||
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.metadata.MediationMetaData;
|
||||
import com.unity3d.ads.properties.SdkProperties;
|
||||
import com.unity3d.ads.request.NetworkIOException;
|
||||
import com.unity3d.ads.request.WebRequest;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class Configuration {
|
||||
private String _url;
|
||||
private Class[] _webAppApiClassList;
|
||||
private String _webViewData;
|
||||
private String _webViewHash;
|
||||
private String _webViewUrl;
|
||||
private String _webViewVersion;
|
||||
|
||||
public Configuration() {
|
||||
}
|
||||
|
||||
protected String buildQueryString() {
|
||||
return "?ts=" + System.currentTimeMillis() + "&sdkVersion=" + SdkProperties.getVersionCode() + "&sdkVersionName=" + SdkProperties.getVersionName();
|
||||
}
|
||||
|
||||
public String getConfigUrl() {
|
||||
return this._url;
|
||||
}
|
||||
|
||||
public Class[] getWebAppApiClassList() {
|
||||
return this._webAppApiClassList;
|
||||
}
|
||||
|
||||
public String getWebViewData() {
|
||||
return this._webViewData;
|
||||
}
|
||||
|
||||
public String getWebViewHash() {
|
||||
return this._webViewHash;
|
||||
}
|
||||
|
||||
public String getWebViewUrl() {
|
||||
return this._webViewUrl;
|
||||
}
|
||||
|
||||
public String getWebViewVersion() {
|
||||
return this._webViewVersion;
|
||||
}
|
||||
|
||||
protected void makeRequest() throws IOException, JSONException, IllegalStateException, NetworkIOException {
|
||||
if (this._url == null) {
|
||||
throw new MalformedURLException("Base URL is null");
|
||||
}
|
||||
String str = this._url + buildQueryString();
|
||||
DeviceLog.debug("Requesting configuration with: " + str);
|
||||
JSONObject jSONObject = new JSONObject(new WebRequest(str, "GET", null).makeRequest());
|
||||
this._webViewUrl = jSONObject.getString("url");
|
||||
if (!jSONObject.isNull("hash")) {
|
||||
this._webViewHash = jSONObject.getString("hash");
|
||||
}
|
||||
if (jSONObject.has(MediationMetaData.KEY_VERSION)) {
|
||||
this._webViewVersion = jSONObject.getString(MediationMetaData.KEY_VERSION);
|
||||
}
|
||||
String str2 = this._webViewUrl;
|
||||
if (str2 == null || str2.isEmpty()) {
|
||||
throw new MalformedURLException("Invalid data. Web view URL is null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfigUrl(String str) {
|
||||
this._url = str;
|
||||
}
|
||||
|
||||
public void setWebAppApiClassList(Class[] clsArr) {
|
||||
this._webAppApiClassList = clsArr;
|
||||
}
|
||||
|
||||
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(String str) {
|
||||
this._url = str;
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.unity3d.ads.configuration;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum ConfigurationFailure {
|
||||
NETWORK_FAILURE,
|
||||
INVALID_DATA
|
||||
}
|
62
sources/com/unity3d/ads/configuration/EnvironmentCheck.java
Normal file
62
sources/com/unity3d/ads/configuration/EnvironmentCheck.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.unity3d.ads.configuration;
|
||||
|
||||
import android.os.Build;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.properties.SdkProperties;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class EnvironmentCheck {
|
||||
private static boolean hasJavascriptInterface(Method method) {
|
||||
if (Build.VERSION.SDK_INT < 17) {
|
||||
return true;
|
||||
}
|
||||
Annotation[] annotations = method.getAnnotations();
|
||||
if (annotations != null) {
|
||||
for (Annotation annotation : annotations) {
|
||||
if (annotation instanceof JavascriptInterface) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isEnvironmentOk() {
|
||||
return testProGuard() && testCacheDirectory();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static boolean testProGuard() {
|
||||
try {
|
||||
Class<?> cls = Class.forName("com.unity3d.ads.webview.bridge.WebViewBridgeInterface");
|
||||
Method method = cls.getMethod("handleInvocation", String.class);
|
||||
Method method2 = cls.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;
|
||||
}
|
||||
}
|
||||
}
|
478
sources/com/unity3d/ads/configuration/InitializeThread.java
Normal file
478
sources/com/unity3d/ads/configuration/InitializeThread.java
Normal file
@@ -0,0 +1,478 @@
|
||||
package com.unity3d.ads.configuration;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.os.ConditionVariable;
|
||||
import com.unity3d.ads.IUnityAdsListener;
|
||||
import com.unity3d.ads.UnityAds;
|
||||
import com.unity3d.ads.api.Lifecycle;
|
||||
import com.unity3d.ads.broadcast.BroadcastMonitor;
|
||||
import com.unity3d.ads.cache.CacheThread;
|
||||
import com.unity3d.ads.connectivity.ConnectivityMonitor;
|
||||
import com.unity3d.ads.connectivity.IConnectivityListener;
|
||||
import com.unity3d.ads.device.AdvertisingId;
|
||||
import com.unity3d.ads.device.StorageManager;
|
||||
import com.unity3d.ads.device.VolumeChange;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.misc.Utilities;
|
||||
import com.unity3d.ads.placement.Placement;
|
||||
import com.unity3d.ads.properties.ClientProperties;
|
||||
import com.unity3d.ads.properties.SdkProperties;
|
||||
import com.unity3d.ads.request.WebRequest;
|
||||
import com.unity3d.ads.request.WebRequestThread;
|
||||
import com.unity3d.ads.webview.WebViewApp;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class InitializeThread extends Thread {
|
||||
private static InitializeThread _thread;
|
||||
private InitializeState _state;
|
||||
private boolean _stopThread = false;
|
||||
|
||||
private static abstract class InitializeState {
|
||||
private InitializeState() {
|
||||
}
|
||||
|
||||
public abstract InitializeState execute();
|
||||
}
|
||||
|
||||
public static class InitializeStateAdBlockerCheck extends InitializeState {
|
||||
private InetAddress _address;
|
||||
private Configuration _configuration;
|
||||
|
||||
public InitializeStateAdBlockerCheck(Configuration configuration) {
|
||||
super();
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
InetAddress inetAddress;
|
||||
DeviceLog.debug("Unity Ads init: checking for ad blockers");
|
||||
try {
|
||||
final String host = new URL(this._configuration.getConfigUrl()).getHost();
|
||||
final ConditionVariable conditionVariable = new ConditionVariable();
|
||||
new Thread() { // from class: com.unity3d.ads.configuration.InitializeThread.InitializeStateAdBlockerCheck.1
|
||||
@Override // java.lang.Thread, java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
InitializeStateAdBlockerCheck.this._address = InetAddress.getByName(host);
|
||||
conditionVariable.open();
|
||||
} catch (Exception e) {
|
||||
DeviceLog.exception("Couldn't get address. Host: " + host, e);
|
||||
conditionVariable.open();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
if (!conditionVariable.block(2000L) || (inetAddress = this._address) == null || !inetAddress.isLoopbackAddress()) {
|
||||
return new InitializeStateConfig(this._configuration);
|
||||
}
|
||||
DeviceLog.error("Unity Ads init: halting init because Unity Ads config resolves to loopback address (due to ad blocker?)");
|
||||
final IUnityAdsListener listener = UnityAds.getListener();
|
||||
if (listener == null) {
|
||||
return null;
|
||||
}
|
||||
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.ads.configuration.InitializeThread.InitializeStateAdBlockerCheck.2
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
listener.onUnityAdsError(UnityAds.UnityAdsError.AD_BLOCKER_DETECTED, "Unity Ads config server resolves to loopback address (due to ad blocker?)");
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} catch (MalformedURLException unused) {
|
||||
return new InitializeStateConfig(this._configuration);
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return this._configuration;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateComplete extends InitializeState {
|
||||
public InitializeStateComplete() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateConfig extends InitializeState {
|
||||
private Configuration _configuration;
|
||||
private int _maxRetries;
|
||||
private int _retries;
|
||||
private int _retryDelay;
|
||||
|
||||
public InitializeStateConfig(Configuration configuration) {
|
||||
super();
|
||||
this._retries = 0;
|
||||
this._maxRetries = 6;
|
||||
this._retryDelay = 5;
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
DeviceLog.info("Unity Ads init: load configuration from " + SdkProperties.getConfigUrl());
|
||||
try {
|
||||
this._configuration.makeRequest();
|
||||
return new InitializeStateLoadCache(this._configuration);
|
||||
} catch (Exception e) {
|
||||
int i = this._retries;
|
||||
if (i >= this._maxRetries) {
|
||||
return new InitializeStateNetworkError(e, this);
|
||||
}
|
||||
this._retryDelay *= 2;
|
||||
this._retries = i + 1;
|
||||
return new InitializeStateRetry(this, this._retryDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateCreate extends InitializeState {
|
||||
private Configuration _configuration;
|
||||
private String _webViewData;
|
||||
|
||||
public InitializeStateCreate(Configuration configuration, String str) {
|
||||
super();
|
||||
this._configuration = configuration;
|
||||
this._webViewData = str;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
DeviceLog.debug("Unity Ads init: creating webapp");
|
||||
Configuration configuration = this._configuration;
|
||||
configuration.setWebViewData(this._webViewData);
|
||||
try {
|
||||
if (WebViewApp.create(configuration)) {
|
||||
return new InitializeStateComplete();
|
||||
}
|
||||
DeviceLog.error("Unity Ads WebApp creation failed!");
|
||||
return new InitializeStateError("create webapp", new Exception("Creation of WebApp failed!"));
|
||||
} catch (IllegalThreadStateException e) {
|
||||
DeviceLog.exception("Illegal Thread", e);
|
||||
return new InitializeStateError("create webapp", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return this._configuration;
|
||||
}
|
||||
|
||||
public String getWebData() {
|
||||
return this._webViewData;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateError extends InitializeState {
|
||||
Exception _exception;
|
||||
String _state;
|
||||
|
||||
public InitializeStateError(String str, Exception exc) {
|
||||
super();
|
||||
this._state = str;
|
||||
this._exception = exc;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
DeviceLog.error("Unity Ads init: halting init in " + this._state + ": " + this._exception.getMessage());
|
||||
final IUnityAdsListener listener = UnityAds.getListener();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Init failed in ");
|
||||
sb.append(this._state);
|
||||
final String sb2 = sb.toString();
|
||||
if (UnityAds.getListener() == null) {
|
||||
return null;
|
||||
}
|
||||
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.ads.configuration.InitializeThread.InitializeStateError.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
listener.onUnityAdsError(UnityAds.UnityAdsError.INITIALIZE_FAILED, sb2);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateForceReset extends InitializeStateReset {
|
||||
public InitializeStateForceReset() {
|
||||
super(new Configuration());
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeStateReset, com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
super.execute();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateLoadCache extends InitializeState {
|
||||
private Configuration _configuration;
|
||||
|
||||
public InitializeStateLoadCache(Configuration configuration) {
|
||||
super();
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.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())) {
|
||||
return new InitializeStateLoadWeb(this._configuration);
|
||||
}
|
||||
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 (UnsupportedEncodingException e) {
|
||||
return new InitializeStateError("load cache", e);
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
DeviceLog.debug("Unity Ads init: webapp not found in local cache: " + e2.getMessage());
|
||||
return new InitializeStateLoadWeb(this._configuration);
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return this._configuration;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateLoadWeb extends InitializeState {
|
||||
private Configuration _configuration;
|
||||
private int _maxRetries;
|
||||
private int _retries;
|
||||
private int _retryDelay;
|
||||
|
||||
public InitializeStateLoadWeb(Configuration configuration) {
|
||||
super();
|
||||
this._retries = 0;
|
||||
this._maxRetries = 6;
|
||||
this._retryDelay = 5;
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
DeviceLog.info("Unity Ads init: loading webapp from " + this._configuration.getWebViewUrl());
|
||||
try {
|
||||
try {
|
||||
String makeRequest = new WebRequest(this._configuration.getWebViewUrl(), "GET", null).makeRequest();
|
||||
String webViewHash = this._configuration.getWebViewHash();
|
||||
if (webViewHash != null && !Utilities.Sha256(makeRequest).equals(webViewHash)) {
|
||||
return new InitializeStateError("load web", new Exception("Invalid webViewHash"));
|
||||
}
|
||||
if (webViewHash != null) {
|
||||
Utilities.writeFile(new File(SdkProperties.getLocalWebViewFile()), makeRequest);
|
||||
}
|
||||
return new InitializeStateCreate(this._configuration, makeRequest);
|
||||
} catch (Exception e) {
|
||||
int i = this._retries;
|
||||
if (i >= this._maxRetries) {
|
||||
return new InitializeStateNetworkError(e, this);
|
||||
}
|
||||
this._retryDelay *= 2;
|
||||
this._retries = i + 1;
|
||||
return new InitializeStateRetry(this, this._retryDelay);
|
||||
}
|
||||
} catch (MalformedURLException e2) {
|
||||
DeviceLog.exception("Malformed URL", e2);
|
||||
return new InitializeStateError("make webrequest", e2);
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return this._configuration;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateNetworkError extends InitializeStateError implements IConnectivityListener {
|
||||
protected static final int CONNECTED_EVENT_THRESHOLD_MS = 10000;
|
||||
protected static final int MAX_CONNECTED_EVENTS = 500;
|
||||
private static long _lastConnectedEventTimeMs;
|
||||
private static int _receivedConnectedEvents;
|
||||
private ConditionVariable _conditionVariable;
|
||||
private InitializeState _erroredState;
|
||||
|
||||
public InitializeStateNetworkError(Exception exc, InitializeState initializeState) {
|
||||
super("network error", exc);
|
||||
this._erroredState = initializeState;
|
||||
}
|
||||
|
||||
private boolean shouldHandleConnectedEvent() {
|
||||
return System.currentTimeMillis() - _lastConnectedEventTimeMs >= 10000 && _receivedConnectedEvents <= 500;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeStateError, com.unity3d.ads.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(600000L)) {
|
||||
ConnectivityMonitor.removeListener(this);
|
||||
return this._erroredState;
|
||||
}
|
||||
ConnectivityMonitor.removeListener(this);
|
||||
return new InitializeStateError("network error", new Exception("No connected events within the timeout!"));
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.connectivity.IConnectivityListener
|
||||
public void onConnected() {
|
||||
_receivedConnectedEvents++;
|
||||
DeviceLog.debug("Unity Ads init got connected event");
|
||||
if (shouldHandleConnectedEvent()) {
|
||||
this._conditionVariable.open();
|
||||
}
|
||||
if (_receivedConnectedEvents > 500) {
|
||||
ConnectivityMonitor.removeListener(this);
|
||||
}
|
||||
_lastConnectedEventTimeMs = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.connectivity.IConnectivityListener
|
||||
public void onDisconnected() {
|
||||
DeviceLog.debug("Unity Ads init got disconnected event");
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateReset extends InitializeState {
|
||||
private Configuration _configuration;
|
||||
|
||||
public InitializeStateReset(Configuration configuration) {
|
||||
super();
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
private void unregisterLifecycleCallbacks() {
|
||||
if (Lifecycle.getLifecycleListener() != null) {
|
||||
if (ClientProperties.getApplication() != null) {
|
||||
ClientProperties.getApplication().unregisterActivityLifecycleCallbacks(Lifecycle.getLifecycleListener());
|
||||
}
|
||||
Lifecycle.setLifecycleListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
boolean z;
|
||||
DeviceLog.debug("Unity Ads init: starting init");
|
||||
final ConditionVariable conditionVariable = new ConditionVariable();
|
||||
final WebViewApp currentApp = WebViewApp.getCurrentApp();
|
||||
if (currentApp != null) {
|
||||
currentApp.setWebAppLoaded(false);
|
||||
currentApp.setWebAppInitialized(false);
|
||||
if (currentApp.getWebView() != null) {
|
||||
Utilities.runOnUiThread(new Runnable() { // from class: com.unity3d.ads.configuration.InitializeThread.InitializeStateReset.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
currentApp.getWebView().destroy();
|
||||
currentApp.setWebView(null);
|
||||
conditionVariable.open();
|
||||
}
|
||||
});
|
||||
z = conditionVariable.block(10000L);
|
||||
} else {
|
||||
z = true;
|
||||
}
|
||||
if (!z) {
|
||||
return new InitializeStateError("reset webapp", new Exception("Reset failed on opening ConditionVariable"));
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT > 13) {
|
||||
unregisterLifecycleCallbacks();
|
||||
}
|
||||
SdkProperties.setCacheDirectory(null);
|
||||
if (SdkProperties.getCacheDirectory() == null) {
|
||||
return new InitializeStateError("reset webapp", new Exception("Cache directory is NULL"));
|
||||
}
|
||||
SdkProperties.setInitialized(false);
|
||||
Placement.reset();
|
||||
BroadcastMonitor.removeAllBroadcastListeners();
|
||||
CacheThread.cancel();
|
||||
WebRequestThread.cancel();
|
||||
ConnectivityMonitor.stopAll();
|
||||
StorageManager.init(ClientProperties.getApplicationContext());
|
||||
AdvertisingId.init(ClientProperties.getApplicationContext());
|
||||
VolumeChange.clearAllListeners();
|
||||
this._configuration.setConfigUrl(SdkProperties.getConfigUrl());
|
||||
return new InitializeStateAdBlockerCheck(this._configuration);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InitializeStateRetry extends InitializeState {
|
||||
int _delay;
|
||||
InitializeState _state;
|
||||
|
||||
public InitializeStateRetry(InitializeState initializeState, int i) {
|
||||
super();
|
||||
this._state = initializeState;
|
||||
this._delay = i;
|
||||
}
|
||||
|
||||
@Override // com.unity3d.ads.configuration.InitializeThread.InitializeState
|
||||
public InitializeState execute() {
|
||||
DeviceLog.debug("Unity Ads init: retrying in " + this._delay + " seconds");
|
||||
try {
|
||||
Thread.sleep(this._delay * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
DeviceLog.exception("Init retry interrupted", e);
|
||||
}
|
||||
return this._state;
|
||||
}
|
||||
}
|
||||
|
||||
private InitializeThread(InitializeState initializeState) {
|
||||
this._state = initializeState;
|
||||
}
|
||||
|
||||
public static synchronized void initialize(Configuration configuration) {
|
||||
synchronized (InitializeThread.class) {
|
||||
if (_thread == null) {
|
||||
_thread = new InitializeThread(new InitializeStateReset(configuration));
|
||||
_thread.setName("UnityAdsInitializeThread");
|
||||
_thread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void reset() {
|
||||
synchronized (InitializeThread.class) {
|
||||
if (_thread == null) {
|
||||
_thread = new InitializeThread(new InitializeStateForceReset());
|
||||
_thread.setName("UnityAdsResetThread");
|
||||
_thread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void quit() {
|
||||
this._stopThread = true;
|
||||
}
|
||||
|
||||
@Override // java.lang.Thread, java.lang.Runnable
|
||||
public void run() {
|
||||
while (true) {
|
||||
InitializeState initializeState = this._state;
|
||||
if (initializeState == null || (initializeState instanceof InitializeStateComplete) || this._stopThread) {
|
||||
break;
|
||||
} else {
|
||||
this._state = initializeState.execute();
|
||||
}
|
||||
}
|
||||
_thread = null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user