1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

make the new merged changes from bitfire compile

This commit is contained in:
theScrabi 2018-07-17 09:31:39 +02:00 committed by davigonz
parent 7bc9a885b0
commit 4968ca6e62
14 changed files with 164 additions and 96 deletions

View File

@ -24,6 +24,7 @@ dependencies {
// Used for network and database debuging // Used for network and database debuging
debugApi 'com.facebook.stetho:stetho:1.5.0' debugApi 'com.facebook.stetho:stetho:1.5.0'
debugApi 'com.facebook.stetho:stetho-okhttp3:1.5.0' debugApi 'com.facebook.stetho:stetho-okhttp3:1.5.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.51"
} }
android { android {

@ -1 +1 @@
Subproject commit c6c06a144a1eaf3a75035dfe8700c42b86b0d223 Subproject commit da434d7693db7d4cfd434ee22d0d336f37f4b6f8

View File

@ -36,6 +36,7 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
import com.owncloud.android.lib.common.http.HttpClient; import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.http.HttpConstants;
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod; import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
import com.owncloud.android.lib.common.http.methods.webdav.CopyMethod;
import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.network.RedirectionPath;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.status.OwnCloudVersion;

View File

@ -52,9 +52,11 @@ public abstract class HttpBaseMethod {
protected RequestBody mRequestBody; protected RequestBody mRequestBody;
protected Response mResponse; protected Response mResponse;
protected Call mCall; protected Call mCall;
protected URL mUrl;
protected HttpBaseMethod (URL url) { protected HttpBaseMethod (URL url) {
mOkHttpClient = HttpClient.getOkHttpClient(); mOkHttpClient = HttpClient.getOkHttpClient();
mUrl = url;
mRequest = new Request.Builder() mRequest = new Request.Builder()
.url(HttpUrl.parse(url.toString())) .url(HttpUrl.parse(url.toString()))
.build(); .build();

View File

@ -3,7 +3,10 @@ package com.owncloud.android.lib.common.http.methods.webdav;
import java.net.URL; import java.net.URL;
import at.bitfire.dav4android.exception.UnauthorizedException; import at.bitfire.dav4android.exception.UnauthorizedException;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.Response;
public class CopyMethod extends DavMethod { public class CopyMethod extends DavMethod {
@ -19,10 +22,10 @@ public class CopyMethod extends DavMethod {
@Override @Override
public int onExecute() throws Exception { public int onExecute() throws Exception {
try { try {
mDavResource.copy(destinationUrl, forceOverride); mDavResource.copy(destinationUrl, forceOverride, response -> {
mResponse = response;
mRequest = mDavResource.getRequest(); return Unit.INSTANCE;
mResponse = mDavResource.getResponse(); });
} catch (UnauthorizedException davException) { } catch (UnauthorizedException davException) {
// Do nothing, we will use the 401 code to handle the situation // Do nothing, we will use the 401 code to handle the situation

View File

@ -30,6 +30,7 @@ import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
import java.net.URL; import java.net.URL;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.DavOCResource; import at.bitfire.dav4android.DavOCResource;
import at.bitfire.dav4android.DavResource; import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.exception.RedirectException; import at.bitfire.dav4android.exception.RedirectException;
@ -47,14 +48,14 @@ public abstract class DavMethod extends HttpBaseMethod {
super(url); super(url);
mDavResource = new DavOCResource( mDavResource = new DavOCResource(
mOkHttpClient, mOkHttpClient,
HttpUrl.parse(url.toString())); HttpUrl.parse(mUrl.toString()),
mDavResource.setFollowRedirects(false); Constants.INSTANCE.getLog());
} }
@Override @Override
public void abort() { public void abort() {
mDavResource.cancelCall(); //TODO: abort here
} }
@Override @Override
@ -62,7 +63,6 @@ public abstract class DavMethod extends HttpBaseMethod {
try { try {
return onExecute(); return onExecute();
} catch(RedirectException e) { } catch(RedirectException e) {
mResponse = getDavResource().getResponse();
return getStatusCode(); return getStatusCode();
} }
} }
@ -74,22 +74,38 @@ public abstract class DavMethod extends HttpBaseMethod {
// Connection parameters // Connection parameters
@Override @Override
public void setReadTimeout(long readTimeout, TimeUnit timeUnit) { public void setReadTimeout(long readTimeout, TimeUnit timeUnit) {
mDavResource.setReadTimeout(readTimeout, timeUnit); super.setReadTimeout(readTimeout, timeUnit);
mDavResource = new DavOCResource(
mOkHttpClient,
HttpUrl.parse(mUrl.toString()),
Constants.INSTANCE.getLog());
} }
@Override @Override
public void setConnectionTimeout(long connectionTimeout, TimeUnit timeUnit) { public void setConnectionTimeout(long connectionTimeout, TimeUnit timeUnit) {
mDavResource.setConnectionTimeout(connectionTimeout, timeUnit); super.setConnectionTimeout(connectionTimeout, timeUnit);
mDavResource = new DavOCResource(
mOkHttpClient,
HttpUrl.parse(mUrl.toString()),
Constants.INSTANCE.getLog());
} }
@Override @Override
public void setFollowRedirects(boolean followRedirects) { public void setFollowRedirects(boolean followRedirects) {
mDavResource.setFollowRedirects(followRedirects); super.setFollowRedirects(followRedirects);
mDavResource = new DavOCResource(
mOkHttpClient,
HttpUrl.parse(mUrl.toString()),
Constants.INSTANCE.getLog());
} }
@Override @Override
public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure) { public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure) {
mDavResource.setRetryOnConnectionFailure(retryOnConnectionFailure); super.setRetryOnConnectionFailure(retryOnConnectionFailure);
mDavResource = new DavOCResource(
mOkHttpClient,
HttpUrl.parse(mUrl.toString()),
Constants.INSTANCE.getLog());
} }
////////////////////////////// //////////////////////////////
@ -98,20 +114,19 @@ public abstract class DavMethod extends HttpBaseMethod {
@Override @Override
public boolean getRetryOnConnectionFailure() { public boolean getRetryOnConnectionFailure() {
return mDavResource.isRetryOnConnectionFailure(); return false; //TODO: implement me
} }
@Override @Override
public boolean isAborted() { public boolean isAborted() {
return mDavResource.isCallAborted(); return true; //TODO: implement me
} }
public void setUrl(URL url) {
public DavResource getDavResource() { mUrl = url;
return mDavResource; mDavResource = new DavOCResource(
} mOkHttpClient,
HttpUrl.parse(mUrl.toString()),
public void setUrl(HttpUrl url) { Constants.INSTANCE.getLog());
mDavResource = new DavOCResource(mOkHttpClient, url);
} }
} }

View File

@ -3,6 +3,9 @@ package com.owncloud.android.lib.common.http.methods.webdav;
import java.net.URL; import java.net.URL;
import at.bitfire.dav4android.exception.UnauthorizedException; import at.bitfire.dav4android.exception.UnauthorizedException;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import okhttp3.Response;
public class MkColMethod extends DavMethod { public class MkColMethod extends DavMethod {
public MkColMethod(URL url) { public MkColMethod(URL url) {
@ -12,10 +15,10 @@ public class MkColMethod extends DavMethod {
@Override @Override
public int onExecute() throws Exception { public int onExecute() throws Exception {
try { try {
mDavResource.mkCol(null); mDavResource.mkCol(null, response -> {
mResponse = response;
mRequest = mDavResource.getRequest(); return Unit.INSTANCE;
mResponse = mDavResource.getResponse(); });
} catch (UnauthorizedException davException) { } catch (UnauthorizedException davException) {
// Do nothing, we will use the 401 code to handle the situation // Do nothing, we will use the 401 code to handle the situation

View File

@ -5,6 +5,9 @@ import com.owncloud.android.lib.common.http.HttpConstants;
import java.net.URL; import java.net.URL;
import at.bitfire.dav4android.exception.UnauthorizedException; import at.bitfire.dav4android.exception.UnauthorizedException;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import okhttp3.Response;
public class MoveMethod extends DavMethod { public class MoveMethod extends DavMethod {
final String destinationUrl; final String destinationUrl;
@ -23,11 +26,10 @@ public class MoveMethod extends DavMethod {
destinationUrl, destinationUrl,
forceOverride, forceOverride,
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER) super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> {
); mResponse = response;
return Unit.INSTANCE;
mRequest = mDavResource.getRequest(); });
mResponse = mDavResource.getResponse();
} catch (UnauthorizedException davException) { } catch (UnauthorizedException davException) {
// Do nothing, we will use the 401 code to handle the situation // Do nothing, we will use the 401 code to handle the situation

View File

@ -26,14 +26,13 @@ package com.owncloud.android.lib.common.http.methods.webdav;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.Set; import java.util.ArrayList;
import java.util.List;
import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.Property; import at.bitfire.dav4android.Property;
import at.bitfire.dav4android.Response;
import at.bitfire.dav4android.exception.DavException; import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.dav4android.exception.UnauthorizedException; import at.bitfire.dav4android.exception.UnauthorizedException;
import okhttp3.HttpUrl; import kotlin.Unit;
/** /**
* Propfind calls wrapper * Propfind calls wrapper
@ -41,28 +40,48 @@ import okhttp3.HttpUrl;
*/ */
public class PropfindMethod extends DavMethod { public class PropfindMethod extends DavMethod {
private int mDepth; // request
private Property.Name[] mProperties; private final int mDepth;
private Set<DavResource> mMembers; private final Property.Name[] mPropertiesToRequest;
public PropfindMethod(URL url, int depth, Property.Name[] properties) { // response
private final List<Response> mMembers;
private Response mRoot;
public PropfindMethod(URL url, int depth, Property.Name[] propertiesToRequest) {
super(url); super(url);
mDepth = depth; mDepth = depth;
mProperties = properties; mPropertiesToRequest = propertiesToRequest;
}; mMembers = new ArrayList<>();
mRoot = null;
}
@Override @Override
public int onExecute() throws IOException, HttpException, DavException { public int onExecute() throws IOException, DavException {
try { try {
mDavResource.propfind(mDepth, mProperties); mDavResource.propfind(mDepth, mPropertiesToRequest,
mMembers = mDavResource.getMembers(); (Response response, Response.HrefRelation hrefRelation) -> {
switch (hrefRelation) {
case MEMBER:
mMembers.add(response);
break;
case SELF:
mRoot = response;
break;
case OTHER:
default:
}
return Unit.INSTANCE;
}, response -> {
mResponse = response;
return Unit.INSTANCE;
});
} catch (UnauthorizedException davException) { } catch (UnauthorizedException davException) {
// Do nothing, we will use the 401 code to handle the situation // Do nothing, we will use the 401 code to handle the situation
return davException.getCode();
} }
mRequest = mDavResource.getRequest();
mResponse = mDavResource.getResponse();
return super.getStatusCode(); return super.getStatusCode();
} }
@ -70,7 +89,11 @@ public class PropfindMethod extends DavMethod {
return mDepth; return mDepth;
} }
public Set<DavResource> getMembers() { public List<Response> getMembers() {
return mMembers; return mMembers;
} }
public Response getRoot() {
return mRoot;
}
} }

View File

@ -32,8 +32,11 @@ import java.net.URL;
import at.bitfire.dav4android.exception.DavException; import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException; import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.dav4android.exception.UnauthorizedException; import at.bitfire.dav4android.exception.UnauthorizedException;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response;
/** /**
* Put calls wrapper * Put calls wrapper
@ -51,16 +54,12 @@ public class PutMethod extends DavMethod {
mDavResource.put( mDavResource.put(
mRequestBody, mRequestBody,
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER), super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
// Save a file not known to exist, guaranteeing that another upload didn't happen
// before, losing the data of the previous put
true,
super.getRequestHeader(HttpConstants.CONTENT_TYPE_HEADER), super.getRequestHeader(HttpConstants.CONTENT_TYPE_HEADER),
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER) super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> {
); mResponse = response;
return Unit.INSTANCE;
mRequest = mDavResource.getRequest(); });
mResponse = mDavResource.getResponse();
} catch (UnauthorizedException davException) { } catch (UnauthorizedException davException) {
// Do nothing, we will use the 401 code to handle the situation // Do nothing, we will use the 401 code to handle the situation

View File

@ -87,10 +87,9 @@ public class ReadRemoteFileOperation extends RemoteOperation<RemoteFile> {
if (status == HttpConstants.HTTP_MULTI_STATUS if (status == HttpConstants.HTTP_MULTI_STATUS
|| status == HttpConstants.HTTP_OK) { || status == HttpConstants.HTTP_OK) {
// Parse response
final DavResource resource = propfind.getDavResource();
final RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName()); final RemoteFile file = new RemoteFile(propfind.getRoot(),
client.getAccount().getDisplayName());
result = new RemoteOperationResult<>(OK); result = new RemoteOperationResult<>(OK);
result.setData(file); result.setData(file);

View File

@ -38,6 +38,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import at.bitfire.dav4android.DavResource; import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.Response;
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
@ -88,11 +89,11 @@ public class ReadRemoteFolderOperation extends RemoteOperation<ArrayList<RemoteF
// parse data from remote folder // parse data from remote folder
mFolderAndFiles.add( mFolderAndFiles.add(
new RemoteFile(propfindMethod.getDavResource(), client.getAccount().getDisplayName()) new RemoteFile(propfindMethod.getRoot(), client.getAccount().getDisplayName())
); );
// loop to update every child // loop to update every child
for (DavResource resource : propfindMethod.getMembers()) { for (Response resource : propfindMethod.getMembers()) {
RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName()); RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName());
mFolderAndFiles.add(file); mFolderAndFiles.add(file);
} }

View File

@ -30,9 +30,12 @@ import android.os.Parcelable;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
import at.bitfire.dav4android.DavResource; import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.Property;
import at.bitfire.dav4android.PropertyCollection; import at.bitfire.dav4android.PropertyCollection;
import at.bitfire.dav4android.Response;
import at.bitfire.dav4android.property.CreationDate; import at.bitfire.dav4android.property.CreationDate;
import at.bitfire.dav4android.property.GetContentLength; import at.bitfire.dav4android.property.GetContentLength;
import at.bitfire.dav4android.property.GetContentType; import at.bitfire.dav4android.property.GetContentType;
@ -183,36 +186,45 @@ public class RemoteFile implements Parcelable, Serializable {
throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path); throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
} }
mRemotePath = path; mRemotePath = path;
mCreationTimestamp = 0;
mLength = 0;
mMimeType = "DIR";
mQuotaUsedBytes = BigDecimal.ZERO;
mQuotaAvailableBytes = BigDecimal.ZERO;
mPrivateLink = null;
} }
public RemoteFile(final DavResource davResource, String displayName) { public RemoteFile(final Response davResource, String displayName) {
this(getRemotePathFromUrl(davResource.getLocation(), displayName)); this(getRemotePathFromUrl(davResource.getHref(), displayName));
final PropertyCollection properties = davResource.getProperties(); final List<Property> properties = davResource.getProperties();
this.setCreationTimestamp(properties.get(CreationDate.class) != null
? Long.parseLong(properties.get(CreationDate.class).getCreationDate()) for(Property property : properties) {
: 0); if(property instanceof CreationDate)
this.setLength(properties.get(GetContentLength.class) != null this.setCreationTimestamp(
? properties.get(GetContentLength.class).getContentLength() Long.parseLong(((CreationDate) property).getCreationDate()));
: 0); if(property instanceof GetContentLength)
this.setMimeType(properties.get(GetContentType.class) != null this.setLength(((GetContentLength) property).getContentLength());
? properties.get(GetContentType.class).getType() if(property instanceof GetContentType)
: "DIR"); this.setMimeType(((GetContentType) property).getType());
this.setModifiedTimestamp(properties.get(GetLastModified.class).getLastModified()); if(property instanceof GetLastModified)
this.setEtag(properties.get(GetETag.class).getETag()); this.setModifiedTimestamp(((GetLastModified) property).getLastModified());
this.setPermissions(properties.get(OCPermissions.class).getPermission()); if(property instanceof GetETag)
this.setRemoteId(properties.get(OCId.class).getId()); this.setEtag(((GetETag) property).getETag());
this.setSize(properties.get(OCSize.class).getSize()); if(property instanceof OCPermissions)
this.setQuotaUsedBytes(properties.get(QuotaUsedBytes.class) != null this.setPermissions(((OCPermissions) property).getPermission());
? BigDecimal.valueOf( if(property instanceof OCId)
properties.get(QuotaUsedBytes.class).getQuotaUsedBytes()) this.setRemoteId(((OCId) property).getId());
: BigDecimal.ZERO); if(property instanceof OCSize)
this.setQuotaAvailableBytes(properties.get(QuotaAvailableBytes.class) != null this.setSize(((OCSize) property).getSize());
? BigDecimal.valueOf( if(property instanceof QuotaUsedBytes)
properties.get(QuotaAvailableBytes.class).getQuotaAvailableBytes()) this.setQuotaUsedBytes(
: BigDecimal.ZERO); BigDecimal.valueOf(((QuotaUsedBytes) property).getQuotaUsedBytes()));
this.setPrivateLink(properties.get(OCPrivatelink.class) != null if(property instanceof QuotaAvailableBytes)
? properties.get(OCPrivatelink.class).getLink() this.setQuotaAvailableBytes(
: null); BigDecimal.valueOf(((QuotaAvailableBytes) property).getQuotaAvailableBytes()));
if(property instanceof OCPrivatelink)
this.setPrivateLink(((OCPrivatelink) property).getLink());
}
} }

View File

@ -37,7 +37,9 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import java.net.URL; import java.net.URL;
import java.util.List;
import at.bitfire.dav4android.Property;
import at.bitfire.dav4android.PropertyCollection; import at.bitfire.dav4android.PropertyCollection;
import at.bitfire.dav4android.property.QuotaAvailableBytes; import at.bitfire.dav4android.property.QuotaAvailableBytes;
import at.bitfire.dav4android.property.QuotaUsedBytes; import at.bitfire.dav4android.property.QuotaUsedBytes;
@ -90,13 +92,12 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation<GetRemoteUserQu
PropfindMethod propfindMethod = new PropfindMethod( PropfindMethod propfindMethod = new PropfindMethod(
new URL(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), new URL(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
DEPTH_0, DEPTH_0,
DavUtils.getQuotaPropSet() DavUtils.getQuotaPropSet());
);
int status = client.executeHttpMethod(propfindMethod); int status = client.executeHttpMethod(propfindMethod);
if (isSuccess(status)) { if (isSuccess(status)) {
RemoteQuota remoteQuota = readData(propfindMethod.getDavResource().getProperties()); RemoteQuota remoteQuota = readData(propfindMethod.getRoot().getProperties());
result = new RemoteOperationResult<>(OK); result = new RemoteOperationResult<>(OK);
@ -139,10 +140,16 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation<GetRemoteUserQu
* @param properties WebDAV properties containing quota data * @param properties WebDAV properties containing quota data
* @return new {@link RemoteQuota} instance representing the data read from the server * @return new {@link RemoteQuota} instance representing the data read from the server
*/ */
private RemoteQuota readData(PropertyCollection properties) { private RemoteQuota readData(List<Property> properties) {
long quotaAvailable = 0;
long quotaUsed = 0;
long quotaAvailable = properties.get(QuotaAvailableBytes.class).getQuotaAvailableBytes(); for(Property property : properties) {
long quotaUsed = properties.get(QuotaUsedBytes.class).getQuotaUsedBytes(); if(property instanceof QuotaAvailableBytes)
quotaAvailable = ((QuotaAvailableBytes) property).getQuotaAvailableBytes();
if(property instanceof QuotaUsedBytes)
quotaUsed = ((QuotaUsedBytes) property).getQuotaUsedBytes();
}
// If there's a special case, quota available will contain a negative code // If there's a special case, quota available will contain a negative code
// -1, PENDING: Not computed yet, e.g. external storage mounted but folder sizes need scanning // -1, PENDING: Not computed yet, e.g. external storage mounted but folder sizes need scanning