Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class CancelableThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
private final List<Runnable> _activeRunnable;
|
||||
|
||||
public CancelableThreadPoolExecutor(int i, int i2, long j, TimeUnit timeUnit, LinkedBlockingQueue<Runnable> linkedBlockingQueue) {
|
||||
super(i, i2, j, timeUnit, linkedBlockingQueue);
|
||||
this._activeRunnable = new LinkedList();
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ThreadPoolExecutor
|
||||
protected synchronized void afterExecute(Runnable runnable, Throwable th) {
|
||||
super.afterExecute(runnable, th);
|
||||
this._activeRunnable.remove(runnable);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ThreadPoolExecutor
|
||||
protected synchronized void beforeExecute(Thread thread, Runnable runnable) {
|
||||
super.beforeExecute(thread, runnable);
|
||||
this._activeRunnable.add(runnable);
|
||||
}
|
||||
|
||||
public synchronized void cancel() {
|
||||
for (Runnable runnable : this._activeRunnable) {
|
||||
if (runnable instanceof WebRequestRunnable) {
|
||||
((WebRequestRunnable) runnable).setCancelStatus(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface IResolveHostListener {
|
||||
void onFailed(String str, ResolveHostError resolveHostError, String str2);
|
||||
|
||||
void onResolve(String str, String str2);
|
||||
}
|
11
sources/com/unity3d/ads/request/IWebRequestListener.java
Normal file
11
sources/com/unity3d/ads/request/IWebRequestListener.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface IWebRequestListener {
|
||||
void onComplete(String str, String str2, int i, Map<String, List<String>> map);
|
||||
|
||||
void onFailed(String str, String str2);
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface IWebRequestProgressListener {
|
||||
void onRequestProgress(String str, long j, long j2);
|
||||
|
||||
void onRequestStart(String str, long j, int i, Map<String, List<String>> map);
|
||||
}
|
8
sources/com/unity3d/ads/request/NetworkIOException.java
Normal file
8
sources/com/unity3d/ads/request/NetworkIOException.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class NetworkIOException extends Exception {
|
||||
public NetworkIOException(String str) {
|
||||
super(str);
|
||||
}
|
||||
}
|
9
sources/com/unity3d/ads/request/ResolveHostError.java
Normal file
9
sources/com/unity3d/ads/request/ResolveHostError.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum ResolveHostError {
|
||||
INVALID_HOST,
|
||||
UNKNOWN_HOST,
|
||||
UNEXPECTED_EXCEPTION,
|
||||
TIMEOUT
|
||||
}
|
7
sources/com/unity3d/ads/request/ResolveHostEvent.java
Normal file
7
sources/com/unity3d/ads/request/ResolveHostEvent.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum ResolveHostEvent {
|
||||
COMPLETE,
|
||||
FAILED
|
||||
}
|
258
sources/com/unity3d/ads/request/WebRequest.java
Normal file
258
sources/com/unity3d/ads/request/WebRequest.java
Normal file
@@ -0,0 +1,258 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
import com.tencent.bugly.BuglyStrategy;
|
||||
import com.ubt.jimu.base.util.FileUtil;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WebRequest {
|
||||
private String _body;
|
||||
private boolean _canceled;
|
||||
private int _connectTimeout;
|
||||
private long _contentLength;
|
||||
private Map<String, List<String>> _headers;
|
||||
private IWebRequestProgressListener _progressListener;
|
||||
private int _readTimeout;
|
||||
private String _requestType;
|
||||
private int _responseCode;
|
||||
private Map<String, List<String>> _responseHeaders;
|
||||
private URL _url;
|
||||
|
||||
public enum RequestType {
|
||||
POST,
|
||||
GET,
|
||||
HEAD
|
||||
}
|
||||
|
||||
public WebRequest(String str, String str2, Map<String, List<String>> map) throws MalformedURLException {
|
||||
this(str, str2, map, BuglyStrategy.a.MAX_USERDATA_VALUE_LENGTH, BuglyStrategy.a.MAX_USERDATA_VALUE_LENGTH);
|
||||
}
|
||||
|
||||
private HttpURLConnection getHttpUrlConnectionWithHeaders() throws NetworkIOException {
|
||||
HttpURLConnection httpURLConnection;
|
||||
if (getUrl().toString().startsWith("https://")) {
|
||||
try {
|
||||
httpURLConnection = (HttpsURLConnection) getUrl().openConnection();
|
||||
} catch (IOException e) {
|
||||
throw new NetworkIOException("Open HTTPS connection: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
httpURLConnection = (HttpURLConnection) getUrl().openConnection();
|
||||
} catch (IOException e2) {
|
||||
throw new NetworkIOException("Open HTTP connection: " + e2.getMessage());
|
||||
}
|
||||
}
|
||||
httpURLConnection.setInstanceFollowRedirects(false);
|
||||
httpURLConnection.setConnectTimeout(getConnectTimeout());
|
||||
httpURLConnection.setReadTimeout(getReadTimeout());
|
||||
try {
|
||||
httpURLConnection.setRequestMethod(getRequestType());
|
||||
if (getHeaders() != null && getHeaders().size() > 0) {
|
||||
for (String str : getHeaders().keySet()) {
|
||||
for (String str2 : getHeaders().get(str)) {
|
||||
DeviceLog.debug("Setting header: " + str + "=" + str2);
|
||||
httpURLConnection.setRequestProperty(str, str2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return httpURLConnection;
|
||||
} catch (ProtocolException e3) {
|
||||
throw new NetworkIOException("Set Request Method: " + getRequestType() + ", " + e3.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
this._canceled = true;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return this._body;
|
||||
}
|
||||
|
||||
public int getConnectTimeout() {
|
||||
return this._connectTimeout;
|
||||
}
|
||||
|
||||
public long getContentLength() {
|
||||
return this._contentLength;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getHeaders() {
|
||||
return this._headers;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
URL url = this._url;
|
||||
if (url != null) {
|
||||
return url.getQuery();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getReadTimeout() {
|
||||
return this._readTimeout;
|
||||
}
|
||||
|
||||
public String getRequestType() {
|
||||
return this._requestType;
|
||||
}
|
||||
|
||||
public int getResponseCode() {
|
||||
return this._responseCode;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getResponseHeaders() {
|
||||
return this._responseHeaders;
|
||||
}
|
||||
|
||||
public URL getUrl() {
|
||||
return this._url;
|
||||
}
|
||||
|
||||
public boolean isCanceled() {
|
||||
return this._canceled;
|
||||
}
|
||||
|
||||
public String makeRequest() throws NetworkIOException, IOException, IllegalStateException {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
makeStreamRequest(byteArrayOutputStream);
|
||||
return byteArrayOutputStream.toString("UTF-8");
|
||||
}
|
||||
|
||||
public long makeStreamRequest(OutputStream outputStream) throws NetworkIOException, IOException, IllegalStateException {
|
||||
InputStream errorStream;
|
||||
HttpURLConnection httpUrlConnectionWithHeaders = getHttpUrlConnectionWithHeaders();
|
||||
httpUrlConnectionWithHeaders.setDoInput(true);
|
||||
if (getRequestType().equals(RequestType.POST.name())) {
|
||||
httpUrlConnectionWithHeaders.setDoOutput(true);
|
||||
PrintWriter printWriter = null;
|
||||
try {
|
||||
try {
|
||||
PrintWriter printWriter2 = new PrintWriter((Writer) new OutputStreamWriter(httpUrlConnectionWithHeaders.getOutputStream(), "UTF-8"), true);
|
||||
try {
|
||||
if (getBody() == null) {
|
||||
printWriter2.print(getQuery());
|
||||
} else {
|
||||
printWriter2.print(getBody());
|
||||
}
|
||||
printWriter2.flush();
|
||||
try {
|
||||
printWriter2.close();
|
||||
} catch (Exception e) {
|
||||
DeviceLog.exception("Error closing writer", e);
|
||||
throw e;
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
e = e2;
|
||||
printWriter = printWriter2;
|
||||
DeviceLog.exception("Error while writing POST params", e);
|
||||
throw new NetworkIOException("Error writing POST params: " + e.getMessage());
|
||||
} catch (Throwable th) {
|
||||
th = th;
|
||||
printWriter = printWriter2;
|
||||
if (printWriter != null) {
|
||||
try {
|
||||
printWriter.close();
|
||||
} catch (Exception e3) {
|
||||
DeviceLog.exception("Error closing writer", e3);
|
||||
throw e3;
|
||||
}
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
} catch (Throwable th2) {
|
||||
th = th2;
|
||||
}
|
||||
} catch (IOException e4) {
|
||||
e = e4;
|
||||
}
|
||||
}
|
||||
try {
|
||||
this._responseCode = httpUrlConnectionWithHeaders.getResponseCode();
|
||||
this._contentLength = httpUrlConnectionWithHeaders.getContentLength();
|
||||
if (httpUrlConnectionWithHeaders.getHeaderFields() != null) {
|
||||
this._responseHeaders = httpUrlConnectionWithHeaders.getHeaderFields();
|
||||
}
|
||||
try {
|
||||
errorStream = httpUrlConnectionWithHeaders.getInputStream();
|
||||
} catch (IOException e5) {
|
||||
errorStream = httpUrlConnectionWithHeaders.getErrorStream();
|
||||
if (errorStream == null) {
|
||||
throw new NetworkIOException("Can't open error stream: " + e5.getMessage());
|
||||
}
|
||||
}
|
||||
IWebRequestProgressListener iWebRequestProgressListener = this._progressListener;
|
||||
if (iWebRequestProgressListener != null) {
|
||||
iWebRequestProgressListener.onRequestStart(getUrl().toString(), this._contentLength, this._responseCode, this._responseHeaders);
|
||||
}
|
||||
BufferedInputStream bufferedInputStream = new BufferedInputStream(errorStream);
|
||||
byte[] bArr = new byte[FileUtil.ZIP_BUFFER_SIZE];
|
||||
long j = 0;
|
||||
int i = 0;
|
||||
while (!isCanceled() && i != -1) {
|
||||
try {
|
||||
i = bufferedInputStream.read(bArr);
|
||||
if (i > 0) {
|
||||
outputStream.write(bArr, 0, i);
|
||||
j += i;
|
||||
IWebRequestProgressListener iWebRequestProgressListener2 = this._progressListener;
|
||||
if (iWebRequestProgressListener2 != null) {
|
||||
iWebRequestProgressListener2.onRequestProgress(getUrl().toString(), j, this._contentLength);
|
||||
}
|
||||
}
|
||||
} catch (IOException e6) {
|
||||
throw new NetworkIOException("Network exception: " + e6.getMessage());
|
||||
}
|
||||
}
|
||||
httpUrlConnectionWithHeaders.disconnect();
|
||||
outputStream.flush();
|
||||
return j;
|
||||
} catch (IOException | RuntimeException e7) {
|
||||
throw new NetworkIOException("Response code: " + e7.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setBody(String str) {
|
||||
this._body = str;
|
||||
}
|
||||
|
||||
public void setConnectTimeout(int i) {
|
||||
this._connectTimeout = i;
|
||||
}
|
||||
|
||||
public void setProgressListener(IWebRequestProgressListener iWebRequestProgressListener) {
|
||||
this._progressListener = iWebRequestProgressListener;
|
||||
}
|
||||
|
||||
public void setReadTimeout(int i) {
|
||||
this._readTimeout = i;
|
||||
}
|
||||
|
||||
public WebRequest(String str, String str2, Map<String, List<String>> map, int i, int i2) throws MalformedURLException {
|
||||
this._requestType = RequestType.GET.name();
|
||||
this._responseCode = -1;
|
||||
this._contentLength = -1L;
|
||||
this._canceled = false;
|
||||
this._url = new URL(str);
|
||||
this._requestType = str2;
|
||||
this._headers = map;
|
||||
this._connectTimeout = i;
|
||||
this._readTimeout = i2;
|
||||
}
|
||||
}
|
6
sources/com/unity3d/ads/request/WebRequestError.java
Normal file
6
sources/com/unity3d/ads/request/WebRequestError.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum WebRequestError {
|
||||
MAPPING_HEADERS_FAILED
|
||||
}
|
7
sources/com/unity3d/ads/request/WebRequestEvent.java
Normal file
7
sources/com/unity3d/ads/request/WebRequestEvent.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum WebRequestEvent {
|
||||
COMPLETE,
|
||||
FAILED
|
||||
}
|
107
sources/com/unity3d/ads/request/WebRequestRunnable.java
Normal file
107
sources/com/unity3d/ads/request/WebRequestRunnable.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
import android.os.Bundle;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WebRequestRunnable implements Runnable {
|
||||
private final String _body;
|
||||
private boolean _canceled = false;
|
||||
private final int _connectTimeout;
|
||||
private WebRequest _currentRequest;
|
||||
private final Map<String, List<String>> _headers;
|
||||
private final IWebRequestListener _listener;
|
||||
private final int _readTimeout;
|
||||
private final String _type;
|
||||
private final String _url;
|
||||
|
||||
public WebRequestRunnable(String str, String str2, String str3, int i, int i2, Map<String, List<String>> map, IWebRequestListener iWebRequestListener) {
|
||||
this._url = str;
|
||||
this._type = str2;
|
||||
this._body = str3;
|
||||
this._connectTimeout = i;
|
||||
this._readTimeout = i2;
|
||||
this._headers = map;
|
||||
this._listener = iWebRequestListener;
|
||||
}
|
||||
|
||||
private Map<String, List<String>> getResponseHeaders(Bundle bundle) {
|
||||
if (bundle.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
HashMap hashMap = new HashMap();
|
||||
for (String str : bundle.keySet()) {
|
||||
String[] stringArray = bundle.getStringArray(str);
|
||||
if (stringArray != null) {
|
||||
hashMap.put(str, new ArrayList(Arrays.asList(stringArray)));
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
private void makeRequest(String str, String str2, Map<String, List<String>> map, String str3, int i, int i2) throws MalformedURLException {
|
||||
if (this._canceled) {
|
||||
return;
|
||||
}
|
||||
this._currentRequest = new WebRequest(str, str2, map, i, i2);
|
||||
if (str3 != null) {
|
||||
this._currentRequest.setBody(str3);
|
||||
}
|
||||
try {
|
||||
String makeRequest = this._currentRequest.makeRequest();
|
||||
if (this._currentRequest.isCanceled()) {
|
||||
onFailed("Canceled");
|
||||
return;
|
||||
}
|
||||
Bundle bundle = new Bundle();
|
||||
for (String str4 : this._currentRequest.getResponseHeaders().keySet()) {
|
||||
if (str4 != null && !str4.contentEquals("null")) {
|
||||
String[] strArr = new String[this._currentRequest.getResponseHeaders().get(str4).size()];
|
||||
for (int i3 = 0; i3 < this._currentRequest.getResponseHeaders().get(str4).size(); i3++) {
|
||||
strArr[i3] = this._currentRequest.getResponseHeaders().get(str4).get(i3);
|
||||
}
|
||||
bundle.putStringArray(str4, strArr);
|
||||
}
|
||||
}
|
||||
onSucceed(makeRequest, this._currentRequest.getResponseCode(), getResponseHeaders(bundle));
|
||||
} catch (NetworkIOException | IOException | IllegalStateException e) {
|
||||
DeviceLog.exception("Error completing request", e);
|
||||
onFailed(e.getClass().getName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void onFailed(String str) {
|
||||
this._listener.onFailed(this._url, str);
|
||||
}
|
||||
|
||||
private void onSucceed(String str, int i, Map<String, List<String>> map) {
|
||||
this._listener.onComplete(this._url, str, i, map);
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
DeviceLog.debug("Handling request message: " + this._url + " type=" + this._type);
|
||||
try {
|
||||
makeRequest(this._url, this._type, this._headers, this._body, this._connectTimeout, this._readTimeout);
|
||||
} catch (MalformedURLException e) {
|
||||
DeviceLog.exception("Malformed URL", e);
|
||||
onFailed("Malformed URL");
|
||||
}
|
||||
}
|
||||
|
||||
public void setCancelStatus(boolean z) {
|
||||
WebRequest webRequest;
|
||||
this._canceled = z;
|
||||
if (!this._canceled || (webRequest = this._currentRequest) == null) {
|
||||
return;
|
||||
}
|
||||
webRequest.cancel();
|
||||
}
|
||||
}
|
187
sources/com/unity3d/ads/request/WebRequestThread.java
Normal file
187
sources/com/unity3d/ads/request/WebRequestThread.java
Normal file
@@ -0,0 +1,187 @@
|
||||
package com.unity3d.ads.request;
|
||||
|
||||
import android.os.ConditionVariable;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.request.WebRequest;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WebRequestThread {
|
||||
private static int _corePoolSize = 1;
|
||||
private static long _keepAliveTime = 1000;
|
||||
private static int _maximumPoolSize = 1;
|
||||
private static CancelableThreadPoolExecutor _pool = null;
|
||||
private static LinkedBlockingQueue<Runnable> _queue = null;
|
||||
private static boolean _ready = false;
|
||||
private static final Object _readyLock = new Object();
|
||||
|
||||
public static synchronized void cancel() {
|
||||
synchronized (WebRequestThread.class) {
|
||||
if (_pool != null) {
|
||||
_pool.cancel();
|
||||
Iterator<Runnable> it = _queue.iterator();
|
||||
while (it.hasNext()) {
|
||||
Runnable next = it.next();
|
||||
if (next instanceof WebRequestRunnable) {
|
||||
((WebRequestRunnable) next).setCancelStatus(true);
|
||||
}
|
||||
}
|
||||
_queue.clear();
|
||||
_pool.purge();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized void init() {
|
||||
synchronized (WebRequestThread.class) {
|
||||
_queue = new LinkedBlockingQueue<>();
|
||||
_pool = new CancelableThreadPoolExecutor(_corePoolSize, _maximumPoolSize, _keepAliveTime, TimeUnit.MILLISECONDS, _queue);
|
||||
_pool.prestartAllCoreThreads();
|
||||
_queue.add(new Runnable() { // from class: com.unity3d.ads.request.WebRequestThread.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
boolean unused = WebRequestThread._ready = true;
|
||||
synchronized (WebRequestThread._readyLock) {
|
||||
WebRequestThread._readyLock.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
while (!_ready) {
|
||||
try {
|
||||
synchronized (_readyLock) {
|
||||
_readyLock.wait();
|
||||
}
|
||||
} catch (InterruptedException unused) {
|
||||
DeviceLog.debug("Couldn't synchronize thread");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void request(String str, WebRequest.RequestType requestType, Map<String, List<String>> map, Integer num, Integer num2, IWebRequestListener iWebRequestListener) {
|
||||
synchronized (WebRequestThread.class) {
|
||||
request(str, requestType, map, null, num, num2, iWebRequestListener);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void reset() {
|
||||
synchronized (WebRequestThread.class) {
|
||||
cancel();
|
||||
if (_pool != null) {
|
||||
_pool.shutdown();
|
||||
try {
|
||||
_pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
} catch (InterruptedException unused) {
|
||||
}
|
||||
_queue.clear();
|
||||
_pool = null;
|
||||
_queue = null;
|
||||
_ready = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized boolean resolve(final String str, final IResolveHostListener iResolveHostListener) {
|
||||
synchronized (WebRequestThread.class) {
|
||||
if (str != null) {
|
||||
if (str.length() >= 3) {
|
||||
new Thread(new Runnable() { // from class: com.unity3d.ads.request.WebRequestThread.2
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
final ConditionVariable conditionVariable = new ConditionVariable();
|
||||
Thread thread = null;
|
||||
try {
|
||||
Thread thread2 = new Thread(new Runnable() { // from class: com.unity3d.ads.request.WebRequestThread.2.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
iResolveHostListener.onResolve(str, InetAddress.getByName(str).getHostAddress());
|
||||
} catch (UnknownHostException e) {
|
||||
DeviceLog.exception("Unknown host", e);
|
||||
AnonymousClass2 anonymousClass2 = AnonymousClass2.this;
|
||||
iResolveHostListener.onFailed(str, ResolveHostError.UNKNOWN_HOST, e.getMessage());
|
||||
}
|
||||
conditionVariable.open();
|
||||
}
|
||||
});
|
||||
try {
|
||||
thread2.start();
|
||||
thread = thread2;
|
||||
} catch (Exception e) {
|
||||
e = e;
|
||||
thread = thread2;
|
||||
DeviceLog.exception("Exception while resolving host", e);
|
||||
iResolveHostListener.onFailed(str, ResolveHostError.UNEXPECTED_EXCEPTION, e.getMessage());
|
||||
if (conditionVariable.block(20000L)) {
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
e = e2;
|
||||
}
|
||||
if (conditionVariable.block(20000L) || thread == null) {
|
||||
return;
|
||||
}
|
||||
thread.interrupt();
|
||||
iResolveHostListener.onFailed(str, ResolveHostError.TIMEOUT, "Timeout");
|
||||
}
|
||||
}).start();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
iResolveHostListener.onFailed(str, ResolveHostError.INVALID_HOST, "Host is NULL");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void setConcurrentRequestCount(int i) {
|
||||
synchronized (WebRequestThread.class) {
|
||||
_corePoolSize = i;
|
||||
_maximumPoolSize = _corePoolSize;
|
||||
if (_pool != null) {
|
||||
_pool.setCorePoolSize(_corePoolSize);
|
||||
_pool.setMaximumPoolSize(_maximumPoolSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void setKeepAliveTime(long j) {
|
||||
synchronized (WebRequestThread.class) {
|
||||
_keepAliveTime = j;
|
||||
if (_pool != null) {
|
||||
_pool.setKeepAliveTime(_keepAliveTime, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void setMaximumPoolSize(int i) {
|
||||
synchronized (WebRequestThread.class) {
|
||||
_maximumPoolSize = i;
|
||||
if (_pool != null) {
|
||||
_pool.setMaximumPoolSize(_maximumPoolSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void request(String str, WebRequest.RequestType requestType, Map<String, List<String>> map, String str2, Integer num, Integer num2, IWebRequestListener iWebRequestListener) {
|
||||
synchronized (WebRequestThread.class) {
|
||||
if (!_ready) {
|
||||
init();
|
||||
}
|
||||
if (str != null && str.length() >= 3) {
|
||||
_queue.add(new WebRequestRunnable(str, requestType.name(), str2, num.intValue(), num2.intValue(), map, iWebRequestListener));
|
||||
return;
|
||||
}
|
||||
iWebRequestListener.onFailed(str, "Request is NULL or too short");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user