diff --git a/app/src/main/java/org/mian/gitnex/clients/IssuesService.java b/app/src/main/java/org/mian/gitnex/clients/IssuesService.java
index 28d26ac7..999b9ad7 100644
--- a/app/src/main/java/org/mian/gitnex/clients/IssuesService.java
+++ b/app/src/main/java/org/mian/gitnex/clients/IssuesService.java
@@ -26,48 +26,49 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class IssuesService {
- public static S createService(Class serviceClass, String instanceURL, Context ctx) {
+ public static S createService(Class serviceClass, String instanceURL, Context ctx) {
- final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
- File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
- int cacheSize = 50 * 1024 * 1024; // 50MB
- Cache cache = new Cache(httpCacheDirectory, cacheSize);
+ final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
+ File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
+ int cacheSize = 50 * 1024 * 1024; // 50MB
+ Cache cache = new Cache(httpCacheDirectory, cacheSize);
- HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
- logging.setLevel(HttpLoggingInterceptor.Level.BODY);
+ HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
+ logging.setLevel(HttpLoggingInterceptor.Level.BODY);
- try {
- SSLContext sslContext = SSLContext.getInstance("TLS");
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
- MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
- sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
+ MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
+ sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
- OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
+ OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
- @NonNull
- @Override
- public Response intercept(@NonNull Chain chain) throws IOException {
+ @NonNull
+ @Override
+ public Response intercept(@NonNull Chain chain) throws IOException {
- Request request = chain.request();
- if(connToInternet) {
- request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
- }
- else {
- request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
- }
- return chain.proceed(request);
- }
- }).build();
+ Request request = chain.request();
+ if(connToInternet) {
+ request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
+ }
+ else {
+ request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
+ }
+ return chain.proceed(request);
+ }
+ }).build();
- Retrofit.Builder builder = new Retrofit.Builder().baseUrl(instanceURL).client(okHttpClient).addConverterFactory(GsonConverterFactory.create());
+ Retrofit.Builder builder = new Retrofit.Builder().baseUrl(instanceURL).client(okHttpClient).addConverterFactory(GsonConverterFactory.create());
- Retrofit retrofit = builder.build();
- return retrofit.create(serviceClass);
- }
- catch(Exception e) {
- Log.e("onFailure", e.toString());
- }
+ Retrofit retrofit = builder.build();
+ return retrofit.create(serviceClass);
+ }
+ catch(Exception e) {
+ Log.e("onFailure", e.toString());
+ }
+
+ return null;
+ }
- return null;
- }
}
diff --git a/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java b/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java
index 50731225..bf2beb96 100644
--- a/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java
+++ b/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java
@@ -26,48 +26,49 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class PullRequestsService {
- public static S createService(Class serviceClass, String instanceURL, Context ctx) {
+ public static S createService(Class serviceClass, String instanceURL, Context ctx) {
- final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
- File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
- int cacheSize = 50 * 1024 * 1024; // 50MB
- Cache cache = new Cache(httpCacheDirectory, cacheSize);
+ final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
+ File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
+ int cacheSize = 50 * 1024 * 1024; // 50MB
+ Cache cache = new Cache(httpCacheDirectory, cacheSize);
- HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
- logging.setLevel(HttpLoggingInterceptor.Level.BODY);
+ HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
+ logging.setLevel(HttpLoggingInterceptor.Level.BODY);
- try {
- SSLContext sslContext = SSLContext.getInstance("TLS");
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
- MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
- sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
+ MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
+ sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
- OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
+ OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
- @NonNull
- @Override
- public Response intercept(@NonNull Chain chain) throws IOException {
+ @NonNull
+ @Override
+ public Response intercept(@NonNull Chain chain) throws IOException {
- Request request = chain.request();
- if(connToInternet) {
- request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
- }
- else {
- request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
- }
- return chain.proceed(request);
- }
- }).build();
+ Request request = chain.request();
+ if(connToInternet) {
+ request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
+ }
+ else {
+ request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
+ }
+ return chain.proceed(request);
+ }
+ }).build();
- Retrofit.Builder builder = new Retrofit.Builder().baseUrl(instanceURL).client(okHttpClient).addConverterFactory(GsonConverterFactory.create());
+ Retrofit.Builder builder = new Retrofit.Builder().baseUrl(instanceURL).client(okHttpClient).addConverterFactory(GsonConverterFactory.create());
- Retrofit retrofit = builder.build();
- return retrofit.create(serviceClass);
- }
- catch(Exception e) {
- Log.e("onFailure", e.toString());
- }
+ Retrofit retrofit = builder.build();
+ return retrofit.create(serviceClass);
+ }
+ catch(Exception e) {
+ Log.e("onFailure", e.toString());
+ }
+
+ return null;
+ }
- return null;
- }
}
diff --git a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java
index a2794ec7..9e677ff9 100644
--- a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java
+++ b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java
@@ -24,60 +24,56 @@ import retrofit2.converter.scalars.ScalarsConverterFactory;
public class RetrofitClient {
- private Retrofit retrofit;
+ private Retrofit retrofit;
- private RetrofitClient(String instanceUrl, Context ctx) {
- final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
- int cacheSize = 50 * 1024 * 1024; // 50MB
- File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
- Cache cache = new Cache(httpCacheDirectory, cacheSize);
+ private RetrofitClient(String instanceUrl, Context ctx) {
- HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
- logging.setLevel(HttpLoggingInterceptor.Level.BODY);
+ final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
+ int cacheSize = 50 * 1024 * 1024; // 50MB
+ File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
+ Cache cache = new Cache(httpCacheDirectory, cacheSize);
- try {
- SSLContext sslContext = SSLContext.getInstance("TLS");
+ HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
+ logging.setLevel(HttpLoggingInterceptor.Level.BODY);
- MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
- sslContext.init(null, new X509TrustManager[] { memorizingTrustManager }, new SecureRandom());
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
- OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
- .cache(cache)
- //.addInterceptor(logging)
- .sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
- .hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
- .addInterceptor(chain -> {
+ MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
+ sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
- Request request = chain.request();
- if(connToInternet) {
- request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
- }
- else {
- request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
- }
- return chain.proceed(request);
- });
+ OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder().cache(cache)
+ //.addInterceptor(logging)
+ .sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(chain -> {
- Retrofit.Builder builder = new Retrofit.Builder()
- .baseUrl(instanceUrl)
- .client(okHttpClient.build())
- .addConverterFactory(ScalarsConverterFactory.create())
- .addConverterFactory(GsonConverterFactory.create());
+ Request request = chain.request();
+ if(connToInternet) {
+ request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
+ }
+ else {
+ request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
+ }
+ return chain.proceed(request);
+ });
- retrofit = builder.build();
+ Retrofit.Builder builder = new Retrofit.Builder().baseUrl(instanceUrl).client(okHttpClient.build()).addConverterFactory(ScalarsConverterFactory.create()).addConverterFactory(GsonConverterFactory.create());
- }
- catch(Exception e) {
- Log.e("onFailure", e.toString());
- }
- }
+ retrofit = builder.build();
- public static synchronized RetrofitClient getInstance(String instanceUrl, Context ctx) {
- return new RetrofitClient(instanceUrl, ctx);
- }
+ }
+ catch(Exception e) {
+ Log.e("onFailure", e.toString());
+ }
+ }
- public ApiInterface getApiInterface() {
- return retrofit.create(ApiInterface.class);
- }
+ public static synchronized RetrofitClient getInstance(String instanceUrl, Context ctx) {
+
+ return new RetrofitClient(instanceUrl, ctx);
+ }
+
+ public ApiInterface getApiInterface() {
+
+ return retrofit.create(ApiInterface.class);
+ }
}
diff --git a/app/src/main/java/org/mian/gitnex/helpers/MemorizingActivity.java b/app/src/main/java/org/mian/gitnex/helpers/MemorizingActivity.java
index 1de5c9fa..a787a007 100644
--- a/app/src/main/java/org/mian/gitnex/helpers/MemorizingActivity.java
+++ b/app/src/main/java/org/mian/gitnex/helpers/MemorizingActivity.java
@@ -14,6 +14,7 @@ public class MemorizingActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
+
super.onCreate(savedInstanceState);
Intent intent = getIntent();
@@ -34,7 +35,9 @@ public class MemorizingActivity extends Activity {
}
private void onSendResult(int decisionId, int decision) {
+
MemorizingTrustManager.interactResult(decisionId, decision);
finish();
}
+
}
\ No newline at end of file
diff --git a/app/src/main/java/org/mian/gitnex/helpers/MemorizingTrustManager.java b/app/src/main/java/org/mian/gitnex/helpers/MemorizingTrustManager.java
index 033cd9b7..bef13f21 100644
--- a/app/src/main/java/org/mian/gitnex/helpers/MemorizingTrustManager.java
+++ b/app/src/main/java/org/mian/gitnex/helpers/MemorizingTrustManager.java
@@ -46,9 +46,10 @@ import javax.net.ssl.X509TrustManager;
*/
public class MemorizingTrustManager implements X509TrustManager {
+
private final static String DECISION_INTENT = "de.duenndns.ssl.DECISION";
- final static String DECISION_INTENT_ID = DECISION_INTENT + ".decisionId";
- final static String DECISION_INTENT_CERT = DECISION_INTENT + ".cert";
+ final static String DECISION_INTENT_ID = DECISION_INTENT + ".decisionId";
+ final static String DECISION_INTENT_CERT = DECISION_INTENT + ".cert";
private final static Logger LOGGER = Logger.getLogger(MemorizingTrustManager.class.getName());
final static String DECISION_TITLE_ID = DECISION_INTENT + ".titleId";
@@ -69,44 +70,49 @@ public class MemorizingTrustManager implements X509TrustManager {
private X509TrustManager defaultTrustManager;
private X509TrustManager appTrustManager;
- /** Creates an instance of the MemorizingTrustManager class that falls back to a custom TrustManager.
- *
+ /**
+ * Creates an instance of the MemorizingTrustManager class that falls back to a custom TrustManager.
+ *
* You need to supply the application context. This has to be one of: - * - Application - * - Activity - * - Service - * + * - Application + * - Activity + * - Service + *
* The context is used for file management, to display the dialog / * notification and for obtaining translated strings. * - * @param m Context for the application. + * @param m Context for the application. * @param defaultTrustManager Delegate trust management to this TM. If null, the user must accept every certificate. */ public MemorizingTrustManager(Context m, X509TrustManager defaultTrustManager) { + init(m); this.appTrustManager = getTrustManager(appKeyStore); this.defaultTrustManager = defaultTrustManager; } - /** Creates an instance of the MemorizingTrustManager class using the system X509TrustManager. - * + /** + * Creates an instance of the MemorizingTrustManager class using the system X509TrustManager. + *
* You need to supply the application context. This has to be one of: - * - Application - * - Activity - * - Service - * + * - Application + * - Activity + * - Service + *
* The context is used for file management, to display the dialog / * notification and for obtaining translated strings. * * @param m Context for the application. */ public MemorizingTrustManager(Context m) { + init(m); this.appTrustManager = getTrustManager(appKeyStore); this.defaultTrustManager = getTrustManager(null); } private void init(Context m) { + context = m; masterHandler = new Handler(m.getMainLooper()); notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); @@ -115,11 +121,11 @@ public class MemorizingTrustManager implements X509TrustManager { appKeyStore = loadAppKeyStore(); } - + /** * Returns a X509TrustManager list containing a new instance of * TrustManagerFactory. - * + *
* This function is meant for convenience only. You can use it * as follows to integrate TrustManagerFactory for HTTPS sockets: * @@ -129,31 +135,34 @@ public class MemorizingTrustManager implements X509TrustManager { * new java.security.SecureRandom()); * HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); * + * * @param c Activity or Service to show the Dialog / Notification */ public static X509TrustManager[] getInstanceList(Context c) { - return new X509TrustManager[] { new MemorizingTrustManager(c) }; + + return new X509TrustManager[]{new MemorizingTrustManager(c)}; } /** * Binds an Activity to the MTM for displaying the query dialog. - * + *
* This is useful if your connection is run from a service that is * triggered by user interaction -- in such cases the activity is * visible and the user tends to ignore the service notification. - * + *
* You should never have a hidden activity bound to MTM! Use this * function in onResume() and @see unbindDisplayActivity in onPause(). * * @param act Activity to be bound */ private void bindDisplayActivity(Activity act) { + foregroundAct = act; } /** * Removes an Activity from the MTM display stack. - * + *
* Always call this function when the Activity added with
* {@link #bindDisplayActivity(Activity)} is hidden.
*
@@ -161,8 +170,9 @@ public class MemorizingTrustManager implements X509TrustManager {
*/
public void unbindDisplayActivity(Activity act) {
// do not remove if it was overridden by a different activity
- if (foregroundAct == act)
+ if(foregroundAct == act) {
foregroundAct = null;
+ }
}
/**
@@ -171,9 +181,11 @@ public class MemorizingTrustManager implements X509TrustManager {
* @return an {@link Enumeration} of all certificates
*/
private Enumeration