Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 344c1e1

Browse files
theScrabiabelgardep
authored andcommitted
apply required fixes
1 parent 79e4287 commit 344c1e1

File tree

16 files changed

+55
-42
lines changed

16 files changed

+55
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
.idea/*
66
!.idea/codeStyles/
7+
sample_client/.idea/*
78

89
# files for the dex VM
910
*.dex

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/ConnectionValidator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class ConnectionValidator(
1919
val context: Context,
2020
val clearCookiesOnValidation: Boolean
2121
) {
22-
fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager): Boolean {
22+
fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean {
2323
try {
2424
var validationRetryCount = 0
25-
val client = OwnCloudClient(baseClient.baseUri, null, false, singleSessionManager)
25+
val client = OwnCloudClient(baseClient.baseUri, null, false, singleSessionManager, context)
2626
if (clearCookiesOnValidation) {
2727
client.clearCookies()
2828
} else {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package com.owncloud.android.lib.common;
2727

28+
import android.content.Context;
2829
import android.net.Uri;
2930

3031
import com.owncloud.android.lib.common.accounts.AccountUtils;
@@ -76,7 +77,10 @@ public class OwnCloudClient extends HttpClient {
7677
public OwnCloudClient(Uri baseUri,
7778
ConnectionValidator connectionValidator,
7879
boolean synchronizeRequests,
79-
SingleSessionManager singleSessionManager) {
80+
SingleSessionManager singleSessionManager,
81+
Context context) {
82+
super(context);
83+
8084
if (baseUri == null) {
8185
throw new IllegalArgumentException("Parameter 'baseUri' cannot be NULL");
8286
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.owncloud.android.lib.common;
2626

27+
import android.content.Context;
2728
import android.net.Uri;
2829

2930
import com.owncloud.android.lib.common.http.HttpClient;
@@ -38,11 +39,14 @@ public class OwnCloudClientFactory {
3839
* @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH
3940
* @return A OwnCloudClient object ready to be used
4041
*/
41-
public static OwnCloudClient createOwnCloudClient(Uri uri, boolean followRedirects) {
42-
OwnCloudClient client = new OwnCloudClient(uri);
42+
public static OwnCloudClient createOwnCloudClient(Uri uri,
43+
ConnectionValidator connectionValidator,
44+
boolean followRedirects,
45+
SingleSessionManager singleSessionManager,
46+
Context context) {
47+
OwnCloudClient client = new OwnCloudClient(uri, connectionValidator, true, singleSessionManager, context);
4348

4449
client.setFollowRedirects(followRedirects);
45-
HttpClient.setContext(context);
4650
retrieveCookiesFromMiddleware(client);
4751
return client;
4852
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ public static void setUserAgent(String userAgent) {
7777
sUserAgent = userAgent;
7878
}
7979

80-
private static OwnCloudClient createOwnCloudClient(Uri uri, Context context, ConnectionValidator connectionValidator, SingleSessionManager singleSessionManager) {
81-
OwnCloudClient client = new OwnCloudClient(uri, connectionValidator, true, singleSessionManager);
82-
HttpClient.setContext(context);
83-
80+
private static OwnCloudClient createOwnCloudClient(Uri uri,
81+
Context context,
82+
ConnectionValidator connectionValidator,
83+
SingleSessionManager singleSessionManager) {
84+
OwnCloudClient client = new OwnCloudClient(uri, connectionValidator, true, singleSessionManager, context);
8485
return client;
8586
}
8687

@@ -130,9 +131,9 @@ public OwnCloudClient getClientFor(OwnCloudAccount account,
130131
// no client to reuse - create a new one
131132
client = createOwnCloudClient(
132133
account.getBaseUri(),
133-
context.getApplicationContext(),
134+
context,
134135
connectionValidator,
135-
this);
136+
this); // TODO remove dependency on OwnCloudClientFactory
136137

137138
//the next two lines are a hack because okHttpclient is used as a singleton instead of being an
138139
//injected instance that can be deleted when required

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import javax.net.ssl.SSLSocketFactory;
4242
import javax.net.ssl.TrustManager;
4343
import javax.net.ssl.X509TrustManager;
44-
import java.security.KeyManagementException;
4544
import java.security.NoSuchAlgorithmException;
4645
import java.util.Collections;
4746
import java.util.HashMap;
@@ -55,26 +54,26 @@
5554
*/
5655

5756
public class HttpClient {
58-
private static Context sContext;
57+
private Context mContext;
5958
private HashMap<String, List<Cookie>> mCookieStore = new HashMap<>();
60-
private LogInterceptor mLogInterceptor;
59+
private LogInterceptor mLogInterceptor = new LogInterceptor();
6160

6261
private OkHttpClient mOkHttpClient = null;
6362

64-
protected HttpClient() {
65-
mLogInterceptor = new LogInterceptor();
63+
protected HttpClient(Context context) {
64+
mContext = context;
6665
}
6766

6867
public OkHttpClient getOkHttpClient() {
69-
if(sContext == null) {
68+
if (mContext == null) {
7069
Timber.e("Context not initialized call HttpClient.setContext(applicationContext) in the MainApp.onCrate()");
71-
throw new RuntimeException("Context not initialized call HttpClient.setContext(applicationContext) in the MainApp.onCrate()");
70+
throw new RuntimeException("Context not initialized call HttpClient.setContext(applicationContext) in the" +
71+
" MainApp.onCrate()");
7272
}
73-
if(mOkHttpClient == null) {
73+
if (mOkHttpClient == null) {
7474
try {
7575
final X509TrustManager trustManager = new AdvancedX509TrustManager(
76-
NetworkUtils.getKnownServersStore(sContext));
77-
76+
NetworkUtils.getKnownServersStore(mContext));
7877

7978
final SSLContext sslContext = buildSSLContext();
8079
sslContext.init(null, new TrustManager[]{trustManager}, null);
@@ -84,7 +83,7 @@ public OkHttpClient getOkHttpClient() {
8483
final CookieJar cookieJar = new CookieJarImpl(mCookieStore);
8584
mOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
8685

87-
} catch(NoSuchAlgorithmException nsae){
86+
} catch (NoSuchAlgorithmException nsae) {
8887
Timber.e(nsae, "Could not setup SSL system.");
8988
throw new RuntimeException("Could not setup okHttp client.", nsae);
9089
} catch (Exception e) {
@@ -97,18 +96,18 @@ public OkHttpClient getOkHttpClient() {
9796

9897
private SSLContext buildSSLContext() throws NoSuchAlgorithmException {
9998
try {
100-
return SSLContext.getInstance("TLSv1.3");
99+
return SSLContext.getInstance(TlsVersion.TLS_1_3.javaName());
101100
} catch (NoSuchAlgorithmException tlsv13Exception) {
102101
try {
103102
Timber.w("TLSv1.3 is not supported in this device; falling through TLSv1.2");
104-
return SSLContext.getInstance("TLSv1.2");
103+
return SSLContext.getInstance(TlsVersion.TLS_1_2.javaName());
105104
} catch (NoSuchAlgorithmException tlsv12Exception) {
106105
try {
107106
Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1");
108-
return SSLContext.getInstance("TLSv1.1");
107+
return SSLContext.getInstance(TlsVersion.TLS_1_1.javaName());
109108
} catch (NoSuchAlgorithmException tlsv11Exception) {
110109
Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0");
111-
return SSLContext.getInstance("TLSv1");
110+
return SSLContext.getInstance(TlsVersion.TLS_1_0.javaName());
112111
// should be available in any device; see reference of supported protocols in
113112
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
114113
}
@@ -117,7 +116,7 @@ private SSLContext buildSSLContext() throws NoSuchAlgorithmException {
117116
}
118117

119118
private OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
120-
CookieJar cookieJar) {
119+
CookieJar cookieJar) {
121120
return new OkHttpClient.Builder()
122121
.addNetworkInterceptor(getLogInterceptor())
123122
.addNetworkInterceptor(DebugInterceptorFactory.INSTANCE.getInterceptor())
@@ -133,7 +132,7 @@ private OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X50
133132
}
134133

135134
public Context getContext() {
136-
return sContext;
135+
return mContext;
137136
}
138137

139138
public LogInterceptor getLogInterceptor() {
@@ -144,10 +143,6 @@ public List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
144143
return mCookieStore.get(httpUrl.host());
145144
}
146145

147-
public static void setContext(Context context) {
148-
sContext = context;
149-
}
150-
151146
public void clearCookies() {
152147
mCookieStore.clear();
153148
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/nonwebdav/HttpMethod.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ package com.owncloud.android.lib.common.http.methods.nonwebdav
2525

2626
import com.owncloud.android.lib.common.http.HttpClient
2727
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
28-
import okhttp3.OkHttpClient
2928
import okhttp3.Response
3029
import java.net.URL
3130

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/nonwebdav/PostMethod.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package com.owncloud.android.lib.common.http.methods.nonwebdav
2525

2626
import com.owncloud.android.lib.common.http.HttpClient
27-
import okhttp3.OkHttpClient
2827
import okhttp3.RequestBody
2928
import java.io.IOException
3029
import java.net.URL

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/nonwebdav/PutMethod.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package com.owncloud.android.lib.common.http.methods.nonwebdav
2525

2626
import com.owncloud.android.lib.common.http.HttpClient
27-
import okhttp3.OkHttpClient
2827
import okhttp3.RequestBody
2928
import java.io.IOException
3029
import java.net.URL

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import java.util.concurrent.TimeUnit
4444
*
4545
* @author David González Verdugo
4646
*/
47-
abstract class DavMethod protected constructor(httpClient: HttpClient,url: URL) : HttpBaseMethod(httpClient, url) {
47+
abstract class DavMethod protected constructor(httpClient: HttpClient, url: URL) : HttpBaseMethod(httpClient, url) {
4848
protected var davResource: DavOCResource
4949

5050
override lateinit var response: Response

0 commit comments

Comments
 (0)