From 704503b9f5d70f8977d401551316aba9e12d3c1c Mon Sep 17 00:00:00 2001 From: ligi Date: Sun, 27 Aug 2017 19:45:20 +0200 Subject: [PATCH] Use okhttp 3.8.1 --- android/build.gradle | 2 +- .../functions/InputStreamProvider.kt | 5 ++++- .../ui/ExtractURLAsIphoneActivity.kt | 17 ++++++++++------- .../ligi/passandroid/ui/PassViewActivityBase.kt | 15 +++++++++------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 8325fc59..4a863be0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -162,7 +162,7 @@ dependencies { forFDroidCompile 'com.github.ligi.snackengage:snackengage-playrate:0.13' forAmazonCompile 'com.github.ligi.snackengage:snackengage-amazonrate:0.13' - compile 'com.squareup.okhttp3:okhttp:3.7.0' + compile 'com.squareup.okhttp3:okhttp:3.8.1' compile 'com.larswerkman:HoloColorPicker:1.5' compile 'com.google.code.findbugs:jsr305:3.0.2' compile 'com.squareup.moshi:moshi:1.4.0' diff --git a/android/src/main/java/org/ligi/passandroid/functions/InputStreamProvider.kt b/android/src/main/java/org/ligi/passandroid/functions/InputStreamProvider.kt index c7888e74..212f06da 100644 --- a/android/src/main/java/org/ligi/passandroid/functions/InputStreamProvider.kt +++ b/android/src/main/java/org/ligi/passandroid/functions/InputStreamProvider.kt @@ -63,7 +63,10 @@ private fun fromOKHttp(uri: Uri): InputStreamWithSource? { val response = client.newCall(request).execute() - return InputStreamWithSource(uri.toString(), response.body().byteStream()) + val body = response.body() + if (body != null) { + return InputStreamWithSource(uri.toString(), body.byteStream()) + } } catch (e: MalformedURLException) { App.tracker.trackException("MalformedURLException in ImportAsyncTask", e, false) } catch (e: IOException) { diff --git a/android/src/main/java/org/ligi/passandroid/ui/ExtractURLAsIphoneActivity.kt b/android/src/main/java/org/ligi/passandroid/ui/ExtractURLAsIphoneActivity.kt index be3ec80c..defcc63d 100644 --- a/android/src/main/java/org/ligi/passandroid/ui/ExtractURLAsIphoneActivity.kt +++ b/android/src/main/java/org/ligi/passandroid/ui/ExtractURLAsIphoneActivity.kt @@ -38,16 +38,19 @@ class ExtractURLAsIphoneActivity : PassAndroidActivity() { requestBuilder.header("User-Agent", IPHONE_USER_AGENT) val body = client.newCall(requestBuilder.build()).execute().body() - val bodyString = body.string() - body.close() - val url = extractURL(bodyString) ?: return null + if (body != null) { + val bodyString = body.string() + body.close() - if (!url.startsWith("http")) { - return intent.data.scheme + "://" + intent.data.host + "/" + url + val url = extractURL(bodyString) ?: return null + + if (!url.startsWith("http")) { + return intent.data.scheme + "://" + intent.data.host + "/" + url + } + + return url } - - return url } catch (e: IOException) { tracker.trackException("ExtractURLAsIphoneActivity", e, false) } catch (e: URISyntaxException) { diff --git a/android/src/main/java/org/ligi/passandroid/ui/PassViewActivityBase.kt b/android/src/main/java/org/ligi/passandroid/ui/PassViewActivityBase.kt index 68742a02..c6f812a8 100644 --- a/android/src/main/java/org/ligi/passandroid/ui/PassViewActivityBase.kt +++ b/android/src/main/java/org/ligi/passandroid/ui/PassViewActivityBase.kt @@ -184,12 +184,15 @@ open class PassViewActivityBase : PassAndroidActivity() { val response: Response try { response = client.newCall(request).execute() - val inputStreamWithSource = InputStreamWithSource(url, response.body().byteStream()) - val spec = InputStreamUnzipControllerSpec(inputStreamWithSource, this@PassViewActivityBase, passStore, - MyUnzipSuccessCallback(dlg), - MyUnzipFailCallback(dlg)) - spec.overwrite = true - UnzipPassController.processInputStream(spec) + val body = response.body() + if (body != null) { + val inputStreamWithSource = InputStreamWithSource(url, body.byteStream()) + val spec = InputStreamUnzipControllerSpec(inputStreamWithSource, this@PassViewActivityBase, passStore, + MyUnzipSuccessCallback(dlg), + MyUnzipFailCallback(dlg)) + spec.overwrite = true + UnzipPassController.processInputStream(spec) + } } catch (e: IOException) { e.printStackTrace() }