diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java index 9c8cda5544..32aa250997 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java @@ -56,13 +56,14 @@ class HTTPRequest implements Callback { mNativePtr = nativePtr; try { - // Don't try a request if we aren't connected - if (!Mapbox.isConnected()) { + HttpUrl httpUrl = HttpUrl.parse(resourceUrl); + final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE); + + // Don't try a request to remote server if we aren't connected + if (!Mapbox.isConnected() && !host.equals("127.0.0.1") && !host.equals("localhost")) { throw new NoRouteToHostException("No Internet connection available."); } - HttpUrl httpUrl = HttpUrl.parse(resourceUrl); - final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE); if (host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn") || host.endsWith(".mapbox.cn")) { if (httpUrl.querySize() == 0) { @@ -84,7 +85,14 @@ class HTTPRequest implements Callback { } mRequest = builder.build(); mCall = mClient.newCall(mRequest); - mCall.enqueue(this); + + // TODO remove code block for workaround in #10303 + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) { + mCall.enqueue(this); + } else { + // Calling execute instead of enqueue is a workaround for #10303 + onResponse(mCall, mCall.execute()); + } } catch (Exception exception) { onFailure(exception); } @@ -109,13 +117,11 @@ class HTTPRequest implements Callback { @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()) { - Timber.v(String.format("[HTTP] Request was successful (code = %d).", response.code())); + Timber.v("[HTTP] Request was successful (code = %s).", response.code()); } else { // We don't want to call this unsuccessful because a 304 isn't really an error String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information"; - Timber.d(String.format( - "[HTTP] Request with response code = %d: %s", - response.code(), message)); + Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message); } byte[] body; @@ -160,15 +166,12 @@ class HTTPRequest implements Callback { String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request"; if (type == TEMPORARY_ERROR) { - Timber.d(String.format(MapboxConstants.MAPBOX_LOCALE, - "Request failed due to a temporary error: %s", errorMessage)); + Timber.d("Request failed due to a temporary error: %s", errorMessage); } else if (type == CONNECTION_ERROR) { - Timber.i(String.format(MapboxConstants.MAPBOX_LOCALE, - "Request failed due to a connection error: %s", errorMessage)); + Timber.i("Request failed due to a connection error: %s", errorMessage); } else { // PERMANENT_ERROR - Timber.w(String.format(MapboxConstants.MAPBOX_LOCALE, - "Request failed due to a permanent error: %s", errorMessage)); + Timber.w("Request failed due to a permanent error: %s", errorMessage); } mLock.lock(); |