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

Commit f184347

Browse files
authored
Merge pull request #333 from owncloud/release/1.0.6
[Release] 1.0.6
2 parents 6cb2642 + a7a269a commit f184347

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+772
-1107
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ ownCloud Android Library is available under MIT license. See the file LICENSE.md
4444

4545
#### Third party libraries
4646

47-
ownCloud Android Library uses OkHttp version 3.10, licensed under Apache License and version 2.0. Besides, it uses Dav4Android, licensed under Mozilla Public License, v. 2.0
47+
ownCloud Android Library uses OkHttp version 4.6.0, licensed under Apache License and version 2.0. Besides, it uses Dav4Android, licensed under Mozilla Public License, v. 2.0
4848

4949

5050
### Compatibility
5151

52-
ownCloud Android Library is valid for Android systems from version Android 2.2 (android:minSdkVersion="8" android:targetSdkVersion="19").
52+
ownCloud Android Library is valid for Android systems from version Android 5 (android:minSdkVersion="21" android:targetSdkVersion="29").
5353

5454
ownCloud Android library supports ownCloud server from version 4.5.

owncloudComLibrary/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ apply plugin: 'kotlin-kapt'
44
apply plugin: 'kotlin-allopen'
55

66
dependencies {
7-
api 'com.squareup.okhttp3:okhttp:3.12.0'
7+
api 'com.squareup.okhttp3:okhttp:4.6.0'
88
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
9-
api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1'
9+
api 'com.gitlab.ownclouders:dav4android:oc_support_2.1.5'
1010
api 'com.github.hannesa2:Logcat:1.6.0'
1111
api 'net.openid:appauth:0.7.1'
1212

@@ -29,8 +29,8 @@ android {
2929
minSdkVersion 21
3030
targetSdkVersion 29
3131

32-
versionCode = 10000500
33-
versionName = "1.0.5"
32+
versionCode = 10000600
33+
versionName = "1.0.6"
3434

3535
// This is pretty ugly but manifest placeholders don't seem to work very well when using different modules
3636
// See https://github.com/openid/AppAuth-Android/issues/325

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import android.accounts.AccountsException;
3030
import android.net.Uri;
3131

32-
import at.bitfire.dav4android.exception.HttpException;
32+
import at.bitfire.dav4jvm.exception.HttpException;
3333
import com.owncloud.android.lib.common.accounts.AccountUtils;
3434
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
3535
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
@@ -89,11 +89,6 @@ public void clearCredentials() {
8989
if (!(mCredentials instanceof OwnCloudAnonymousCredentials)) {
9090
mCredentials = OwnCloudCredentialsFactory.getAnonymousCredentials();
9191
}
92-
mCredentials.applyTo(this);
93-
}
94-
95-
void applyCredentials() {
96-
mCredentials.applyTo(this);
9792
}
9893

9994
public int executeHttpMethod(HttpBaseMethod method) throws Exception {
@@ -102,8 +97,17 @@ public int executeHttpMethod(HttpBaseMethod method) throws Exception {
10297
int status;
10398

10499
do {
105-
setRequestId(method);
106-
100+
String requestId = RandomUtils.generateRandomUUID();
101+
102+
// Header to allow tracing requests in apache and ownCloud logs
103+
Timber.d("Executing in request with id %s", requestId);
104+
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
105+
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
106+
method.setRequestHeader(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true");
107+
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
108+
if (mCredentials.getHeaderAuth() != null) {
109+
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
110+
}
107111
status = method.execute();
108112

109113
if (mFollowRedirects) {
@@ -125,8 +129,17 @@ private int executeRedirectedHttpMethod(HttpBaseMethod method) throws Exception
125129
int status;
126130

127131
do {
128-
setRequestId(method);
129-
132+
String requestId = RandomUtils.generateRandomUUID();
133+
134+
// Header to allow tracing requests in apache and ownCloud logs
135+
Timber.d("Executing in request with id %s", requestId);
136+
method.setRequestHeader(OC_X_REQUEST_ID, requestId);
137+
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
138+
method.setRequestHeader(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true");
139+
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
140+
if (mCredentials.getHeaderAuth() != null) {
141+
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
142+
}
130143
status = method.execute();
131144

132145
repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter);
@@ -138,19 +151,6 @@ private int executeRedirectedHttpMethod(HttpBaseMethod method) throws Exception
138151
return status;
139152
}
140153

141-
private void setRequestId(HttpBaseMethod method) {
142-
// Clean previous request id. This is a bit hacky but is the only way to add request headers in WebDAV
143-
// methods by using Dav4Android
144-
deleteHeaderForAllRequests(OC_X_REQUEST_ID);
145-
146-
String requestId = RandomUtils.generateRandomUUID();
147-
148-
// Header to allow tracing requests in apache and ownCloud logs
149-
addHeaderForAllRequests(OC_X_REQUEST_ID, requestId);
150-
151-
Timber.d("Executing in request with id %s", requestId);
152-
}
153-
154154
public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception {
155155
int redirectionsCount = 0;
156156
int status = method.getStatusCode();
@@ -215,9 +215,6 @@ public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception
215215
public void exhaustResponse(InputStream responseBodyAsStream) {
216216
if (responseBodyAsStream != null) {
217217
try {
218-
while (responseBodyAsStream.read(sExhaustBuffer) >= 0) {
219-
;
220-
}
221218
responseBodyAsStream.close();
222219

223220
} catch (IOException io) {
@@ -273,7 +270,6 @@ public final OwnCloudCredentials getCredentials() {
273270
public void setCredentials(OwnCloudCredentials credentials) {
274271
if (credentials != null) {
275272
mCredentials = credentials;
276-
mCredentials.applyTo(this);
277273
} else {
278274
clearCredentials();
279275
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) thr
130130
Timber.v("reusing client for session %s", sessionName);
131131
}
132132

133-
keepCredentialsUpdated(client);
134133
keepCookiesUpdated(context, account, client);
135134
keepUriUpdated(account, client);
136135
}
@@ -177,10 +176,6 @@ public void saveAllClients(Context context, String accountType) {
177176
Timber.d("All sessions saved");
178177
}
179178

180-
private void keepCredentialsUpdated(OwnCloudClient reusedClient) {
181-
reusedClient.applyCredentials();
182-
}
183-
184179
private void keepCookiesUpdated(Context context, OwnCloudAccount account, OwnCloudClient reusedClient) {
185180
AccountManager am = AccountManager.get(context.getApplicationContext());
186181
if (am != null && account.getSavedAccount() != null) {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
*/
2424
package com.owncloud.android.lib.common.authentication;
2525

26-
import com.owncloud.android.lib.common.OwnCloudClient;
27-
import com.owncloud.android.lib.common.http.HttpClient;
28-
import com.owncloud.android.lib.common.http.HttpConstants;
2926
import okhttp3.Credentials;
30-
import okhttp3.internal.Util;
27+
28+
import static java.nio.charset.StandardCharsets.UTF_8;
3129

3230
public class OwnCloudBasicCredentials implements OwnCloudCredentials {
3331

@@ -39,21 +37,6 @@ public OwnCloudBasicCredentials(String username, String password) {
3937
mPassword = password != null ? password : "";
4038
}
4139

42-
public OwnCloudBasicCredentials(String username, String password, boolean preemptiveMode) {
43-
mUsername = username != null ? username : "";
44-
mPassword = password != null ? password : "";
45-
}
46-
47-
@Override
48-
public void applyTo(OwnCloudClient client) {
49-
// Clear previous basic credentials
50-
HttpClient.deleteHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER);
51-
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
52-
53-
HttpClient.addHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER,
54-
Credentials.basic(mUsername, mPassword, Util.UTF_8));
55-
}
56-
5740
@Override
5841
public String getUsername() {
5942
return mUsername;
@@ -64,6 +47,11 @@ public String getAuthToken() {
6447
return mPassword;
6548
}
6649

50+
@Override
51+
public String getHeaderAuth() {
52+
return Credentials.basic(mUsername, mPassword, UTF_8);
53+
}
54+
6755
@Override
6856
public boolean authTokenExpires() {
6957
return false;

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBearerCredentials.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
package com.owncloud.android.lib.common.authentication;
2525

26-
import com.owncloud.android.lib.common.OwnCloudClient;
27-
import com.owncloud.android.lib.common.http.HttpClient;
2826
import com.owncloud.android.lib.common.http.HttpConstants;
2927

3028
public class OwnCloudBearerCredentials implements OwnCloudCredentials {
@@ -37,16 +35,6 @@ public OwnCloudBearerCredentials(String username, String accessToken) {
3735
mAccessToken = accessToken != null ? accessToken : "";
3836
}
3937

40-
@Override
41-
public void applyTo(OwnCloudClient client) {
42-
// Clear previous credentials
43-
HttpClient.deleteHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER);
44-
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
45-
46-
HttpClient.addHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER,
47-
HttpConstants.BEARER_AUTHORIZATION_KEY + mAccessToken);
48-
}
49-
5038
@Override
5139
public String getUsername() {
5240
// not relevant for authentication, but relevant for informational purposes
@@ -58,6 +46,11 @@ public String getAuthToken() {
5846
return mAccessToken;
5947
}
6048

49+
@Override
50+
public String getHeaderAuth() {
51+
return HttpConstants.BEARER_AUTHORIZATION_KEY + mAccessToken;
52+
}
53+
6154
@Override
6255
public boolean authTokenExpires() {
6356
return true;

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentials.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424

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

27-
import com.owncloud.android.lib.common.OwnCloudClient;
28-
2927
public interface OwnCloudCredentials {
3028

31-
void applyTo(OwnCloudClient ownCloudClient);
32-
3329
String getUsername();
3430

3531
String getAuthToken();
3632

33+
String getHeaderAuth();
34+
3735
boolean authTokenExpires();
3836

3937
boolean authTokenCanBeRefreshed();

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ protected OwnCloudAnonymousCredentials() {
5555
}
5656

5757
@Override
58-
public void applyTo(OwnCloudClient client) {
59-
// Clear previous basic credentials
60-
HttpClient.deleteHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER);
61-
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
58+
public String getAuthToken() {
59+
return "";
6260
}
6361

6462
@Override
65-
public String getAuthToken() {
63+
public String getHeaderAuth() {
6664
return "";
6765
}
6866

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626

2727
import android.content.Context;
2828

29-
import com.owncloud.android.lib.common.SingleSessionManager;
30-
import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor;
31-
import com.owncloud.android.lib.common.http.interceptors.RequestHeaderInterceptor;
3229
import com.owncloud.android.lib.common.network.AdvancedX509TrustManager;
3330
import com.owncloud.android.lib.common.network.NetworkUtils;
3431
import okhttp3.Cookie;
@@ -58,7 +55,6 @@
5855
*/
5956
public class HttpClient {
6057
private static OkHttpClient sOkHttpClient;
61-
private static HttpInterceptor sOkHttpInterceptor;
6258
private static Context sContext;
6359
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
6460

@@ -114,7 +110,6 @@ public List<Cookie> loadForRequest(HttpUrl url) {
114110
};
115111

116112
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
117-
.addInterceptor(getOkHttpInterceptor())
118113
.protocols(Arrays.asList(Protocol.HTTP_1_1))
119114
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
120115
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
@@ -134,36 +129,6 @@ public List<Cookie> loadForRequest(HttpUrl url) {
134129
return sOkHttpClient;
135130
}
136131

137-
private static HttpInterceptor getOkHttpInterceptor() {
138-
if (sOkHttpInterceptor == null) {
139-
sOkHttpInterceptor = new HttpInterceptor();
140-
addHeaderForAllRequests(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
141-
addHeaderForAllRequests(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true");
142-
addHeaderForAllRequests(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
143-
}
144-
return sOkHttpInterceptor;
145-
}
146-
147-
/**
148-
* Add header that will be included for all the requests from now on
149-
*
150-
* @param headerName
151-
* @param headerValue
152-
*/
153-
public static void addHeaderForAllRequests(String headerName, String headerValue) {
154-
HttpInterceptor httpInterceptor = getOkHttpInterceptor();
155-
156-
if (getOkHttpInterceptor() != null) {
157-
httpInterceptor.addRequestInterceptor(
158-
new RequestHeaderInterceptor(headerName, headerValue)
159-
);
160-
}
161-
}
162-
163-
public static void deleteHeaderForAllRequests(String headerName) {
164-
getOkHttpInterceptor().deleteRequestHeaderInterceptor(headerName);
165-
}
166-
167132
public Context getContext() {
168133
return sContext;
169134
}

0 commit comments

Comments
 (0)