aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/http/HttpClient.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpClient.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpClient.java
index e62be056..cde0675c 100644
--- a/src/main/java/de/thedevstack/conversationsplus/http/HttpClient.java
+++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpClient.java
@@ -1,5 +1,6 @@
package de.thedevstack.conversationsplus.http;
+import android.os.PowerManager;
import android.support.annotation.NonNull;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
@@ -36,6 +37,7 @@ import okio.Source;
*
*/
public final class HttpClient implements Http {
+ private static final long RETRIEVE_HEAD_WAKELOCK_TIMEOUT = 2000;
private static HttpClient INSTANCE;
private static final String LOGTAG = "http-client";
@@ -54,7 +56,7 @@ public final class HttpClient implements Http {
private static OkHttpClient.Builder getBuilder(boolean interactive) {
OkHttpClient.Builder builder = INSTANCE.client.newBuilder();
- INSTANCE.initTrustManager(builder, interactive);
+ initTrustManager(builder, interactive);
return builder;
}
@@ -85,7 +87,21 @@ public final class HttpClient implements Http {
//.addHeader(HEADER_NAME_ACCEPT_ENCODING, "")
.head()
.build();
- client.newCall(request).enqueue(callback);
+ Call call = client.newCall(request);
+ PowerManager.WakeLock wakeLock = ConversationsPlusApplication.createPartialWakeLock("http-retrieve-head-" + call.hashCode());
+ try {
+ wakeLock.acquire(RETRIEVE_HEAD_WAKELOCK_TIMEOUT);
+ Response response = call.execute();
+ if (response.isSuccessful()) {
+ callback.onResponse(call, response);
+ }
+ } catch (IOException e) {
+ callback.onFailure(call, e);
+ } finally {
+ if (wakeLock.isHeld()) {
+ wakeLock.release();
+ }
+ }
}
private HttpClient() {