From 0f4e5a8f6dbdcfef9d39795e3419045b97939ebc Mon Sep 17 00:00:00 2001 From: jendib Date: Wed, 13 Jan 2016 23:27:39 +0100 Subject: [PATCH] Build against API 23 --- docs-android/app/app.iml | 40 +++++----------- docs-android/app/build.gradle | 11 +++-- .../docs/activity/DocumentEditActivity.java | 2 +- .../docs/activity/DocumentViewActivity.java | 2 +- .../sismics/docs/activity/LoginActivity.java | 3 +- .../sismics/docs/activity/MainActivity.java | 2 +- .../docs/fragment/DocListFragment.java | 2 +- .../docs/fragment/DocShareFragment.java | 2 +- .../listener/JsonHttpResponseHandler.java | 9 ++-- .../model/application/ApplicationContext.java | 3 +- .../sismics/docs/resource/BaseResource.java | 47 ++++++++++++++++++- .../sismics/docs/resource/FileResource.java | 4 +- .../docs/service/FileUploadService.java | 2 +- .../com/sismics/docs/util/PreferenceUtil.java | 3 +- 14 files changed, 81 insertions(+), 51 deletions(-) diff --git a/docs-android/app/app.iml b/docs-android/app/app.iml index 704ef345..70b4cf6c 100644 --- a/docs-android/app/app.iml +++ b/docs-android/app/app.iml @@ -64,21 +64,13 @@ - - - - - - - - - - - + + + @@ -88,41 +80,31 @@ - - - - - - - - - - - - - + + + + + - - + - - - + + \ No newline at end of file diff --git a/docs-android/app/build.gradle b/docs-android/app/build.gradle index 3c2c46fb..b1fdb5e6 100644 --- a/docs-android/app/build.gradle +++ b/docs-android/app/build.gradle @@ -13,12 +13,13 @@ repositories { } android { - compileSdkVersion 22 + compileSdkVersion 23 buildToolsVersion '23.0.2' + useLibrary 'org.apache.http.legacy' defaultConfig { minSdkVersion 14 - targetSdkVersion 22 + targetSdkVersion 23 versionCode 1 versionName "1.0" } @@ -50,9 +51,9 @@ android { dependencies { compile fileTree(dir: 'libs', include: '*.jar') - compile 'com.android.support:appcompat-v7:22.+' - compile 'com.android.support:recyclerview-v7:22.+' - compile 'com.loopj.android:android-async-http:1.4.6' + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:recyclerview-v7:23.1.1' + compile 'com.loopj.android:android-async-http:1.4.9' compile 'it.sephiroth.android.library.imagezoom:imagezoom:1.0.5' compile 'de.greenrobot:eventbus:2.4.1' compile 'com.shamanland:fab:0.0.6' diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java index cea2d4f4..148e61b9 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java @@ -25,7 +25,6 @@ import com.sismics.docs.ui.view.DatePickerView; import com.sismics.docs.ui.view.TagsCompleteTextView; import com.sismics.docs.util.PreferenceUtil; -import org.apache.http.Header; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -36,6 +35,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import cz.msebera.android.httpclient.Header; import de.greenrobot.event.EventBus; /** diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java index d6bc8f12..128fa992 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java @@ -54,7 +54,6 @@ import com.sismics.docs.service.FileUploadService; import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.TagUtil; -import org.apache.http.Header; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -63,6 +62,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import cz.msebera.android.httpclient.Header; import de.greenrobot.event.EventBus; /** diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/LoginActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/LoginActivity.java index dc10323b..e7c83d53 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/LoginActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/LoginActivity.java @@ -22,9 +22,10 @@ import com.sismics.docs.ui.form.validator.Required; import com.sismics.docs.util.DialogUtil; import com.sismics.docs.util.PreferenceUtil; -import org.apache.http.Header; import org.json.JSONObject; +import cz.msebera.android.httpclient.Header; + /** * Login activity. * diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java index 70ec4975..768d384a 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java @@ -31,9 +31,9 @@ import com.sismics.docs.resource.TagResource; import com.sismics.docs.resource.UserResource; import com.sismics.docs.util.PreferenceUtil; -import org.apache.http.Header; import org.json.JSONObject; +import cz.msebera.android.httpclient.Header; import de.greenrobot.event.EventBus; /** diff --git a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java index 3122128b..c647c372 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java +++ b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java @@ -27,9 +27,9 @@ import com.sismics.docs.resource.DocumentResource; import com.sismics.docs.ui.view.DividerItemDecoration; import com.sismics.docs.ui.view.EmptyRecyclerView; -import org.apache.http.Header; import org.json.JSONObject; +import cz.msebera.android.httpclient.Header; import de.greenrobot.event.EventBus; /** diff --git a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocShareFragment.java b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocShareFragment.java index 93cb93d2..d140b5c1 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocShareFragment.java +++ b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocShareFragment.java @@ -26,10 +26,10 @@ import com.sismics.docs.resource.DocumentResource; import com.sismics.docs.resource.ShareResource; import com.sismics.docs.util.PreferenceUtil; -import org.apache.http.Header; import org.json.JSONArray; import org.json.JSONObject; +import cz.msebera.android.httpclient.Header; import de.greenrobot.event.EventBus; /** diff --git a/docs-android/app/src/main/java/com/sismics/docs/listener/JsonHttpResponseHandler.java b/docs-android/app/src/main/java/com/sismics/docs/listener/JsonHttpResponseHandler.java index 207812f2..ee9bb33c 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/listener/JsonHttpResponseHandler.java +++ b/docs-android/app/src/main/java/com/sismics/docs/listener/JsonHttpResponseHandler.java @@ -22,19 +22,20 @@ import android.util.Log; import com.loopj.android.http.TextHttpResponseHandler; -import org.apache.http.Header; -import org.apache.http.HttpStatus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.HttpStatus; + /** * Used to intercept and handle the responses from requests made using {@link com.loopj.android.http.AsyncHttpClient}, with * automatic parsing into a {@link JSONObject} or {@link JSONArray}.

 

This class is * designed to be passed to get, post, put and delete requests with the {@link #onSuccess(int, - * org.apache.http.Header[], org.json.JSONArray)} or {@link #onSuccess(int, - * org.apache.http.Header[], org.json.JSONObject)} methods anonymously overridden.

 

+ * cz.msebera.android.httpclient.Header[], org.json.JSONArray)} or {@link #onSuccess(int, + * cz.msebera.android.httpclient.Header[], org.json.JSONObject)} methods anonymously overridden.

 

* Additionally, you can override the other event methods from the parent class. */ public class JsonHttpResponseHandler extends TextHttpResponseHandler { diff --git a/docs-android/app/src/main/java/com/sismics/docs/model/application/ApplicationContext.java b/docs-android/app/src/main/java/com/sismics/docs/model/application/ApplicationContext.java index d9bea906..3fe032a8 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/model/application/ApplicationContext.java +++ b/docs-android/app/src/main/java/com/sismics/docs/model/application/ApplicationContext.java @@ -8,9 +8,10 @@ import com.sismics.docs.listener.JsonHttpResponseHandler; import com.sismics.docs.resource.UserResource; import com.sismics.docs.util.PreferenceUtil; -import org.apache.http.Header; import org.json.JSONObject; +import cz.msebera.android.httpclient.Header; + /** * Global context of the application. * diff --git a/docs-android/app/src/main/java/com/sismics/docs/resource/BaseResource.java b/docs-android/app/src/main/java/com/sismics/docs/resource/BaseResource.java index d79d8ef7..29e46528 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/resource/BaseResource.java +++ b/docs-android/app/src/main/java/com/sismics/docs/resource/BaseResource.java @@ -54,10 +54,16 @@ public class BaseResource { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); + + // AQuery support only the old Apache HTTP library MySSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - client.setSSLSocketFactory(sf); AbstractAjaxCallback.setSSF(sf); + + // Async HTTP Client uses another HTTP libary + MySSLSocketFactory2 sf2 = new MySSLSocketFactory2(trustStore); + sf2.setHostnameVerifier(MySSLSocketFactory2.ALLOW_ALL_HOSTNAME_VERIFIER); + client.setSSLSocketFactory(sf2); } catch (Exception e) { // NOP } @@ -84,7 +90,7 @@ public class BaseResource { } /** - * Socket factory to allow self-signed certificates. + * Socket factory to allow self-signed certificates for AQuery. * * @author bgamard */ @@ -119,6 +125,43 @@ public class BaseResource { return sslContext.getSocketFactory().createSocket(); } } + + /** + * Socket factory to allow self-signed certificates for Async HTTP Client. + * + * @author bgamard + */ + public static class MySSLSocketFactory2 extends cz.msebera.android.httpclient.conn.ssl.SSLSocketFactory { + SSLContext sslContext = SSLContext.getInstance("TLS"); + + public MySSLSocketFactory2(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { + super(truststore); + + TrustManager tm = new X509TrustManager() { + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + public X509Certificate[] getAcceptedIssuers() { + return null; + } + }; + + sslContext.init(null, new TrustManager[] { tm }, null); + } + + @Override + public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException { + return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose); + } + + @Override + public Socket createSocket() throws IOException { + return sslContext.getSocketFactory().createSocket(); + } + } /** * Returns cleaned API URL. diff --git a/docs-android/app/src/main/java/com/sismics/docs/resource/FileResource.java b/docs-android/app/src/main/java/com/sismics/docs/resource/FileResource.java index 2e594817..2c802b99 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/resource/FileResource.java +++ b/docs-android/app/src/main/java/com/sismics/docs/resource/FileResource.java @@ -58,8 +58,8 @@ public class FileResource extends BaseResource { SyncHttpClient client = new SyncHttpClient(); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); - MySSLSocketFactory sf = new MySSLSocketFactory(trustStore); - sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + MySSLSocketFactory2 sf = new MySSLSocketFactory2(trustStore); + sf.setHostnameVerifier(MySSLSocketFactory2.ALLOW_ALL_HOSTNAME_VERIFIER); client.setSSLSocketFactory(sf); client.setCookieStore(new PersistentCookieStore(context)); client.setUserAgent(USER_AGENT); diff --git a/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java b/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java index 0157c358..79903b77 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java +++ b/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java @@ -15,12 +15,12 @@ import com.sismics.docs.event.FileAddEvent; import com.sismics.docs.listener.JsonHttpResponseHandler; import com.sismics.docs.resource.FileResource; -import org.apache.http.Header; import org.json.JSONObject; import java.io.IOException; import java.io.InputStream; +import cz.msebera.android.httpclient.Header; import de.greenrobot.event.EventBus; /** diff --git a/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java b/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java index 629d7714..581bc139 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java +++ b/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java @@ -7,11 +7,12 @@ import android.preference.PreferenceManager; import com.loopj.android.http.PersistentCookieStore; -import org.apache.http.cookie.Cookie; import org.json.JSONObject; import java.util.List; +import cz.msebera.android.httpclient.cookie.Cookie; + /** * Utility class on preferences. *