1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-18 20:03:00 +00:00

Merge branch 'master' into master

This commit is contained in:
mendhak
2016-08-10 18:11:28 +01:00
committed by GitHub
132 changed files with 804 additions and 457 deletions
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,6 +31,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;
@@ -46,6 +47,8 @@ public class OwnCloudAccount {
private Uri mBaseUri;
private OwnCloudCredentials mCredentials;
private String mDisplayName;
private String mSavedAccountName;
@@ -68,10 +71,40 @@ public class OwnCloudAccount {
mSavedAccount = savedAccount;
mSavedAccountName = savedAccount.name;
mCredentials = null; // load of credentials is delayed
AccountManager ama = AccountManager.get(context.getApplicationContext());
String baseUrl = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_OC_BASE_URL);
if (baseUrl == null ) {
throw new AccountNotFoundException(mSavedAccount, "Account not found", null);
}
mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount));
mCredentials = null;
mDisplayName = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME);
}
/**
* Constructor for non yet saved OC accounts.
*
* @param baseUri URI to the OC server to get access to.
* @param credentials Credentials to authenticate in the server. NULL is valid for anonymous credentials.
*/
public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) {
if (baseUri == null) {
throw new IllegalArgumentException("Parameter 'baseUri' cannot be null");
}
mSavedAccount = null;
mSavedAccountName = null;
mBaseUri = baseUri;
mCredentials = credentials != null ?
credentials : OwnCloudCredentialsFactory.getAnonymousCredentials();
String username = mCredentials.getUsername();
if (username != null) {
mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username);
}
}
/**
* Method for deferred load of account attributes from AccountManager
*
@@ -94,53 +127,6 @@ public class OwnCloudAccount {
}
}
/*
public OwnCloudAccount(Account savedAccount, Context context)
throws AccountNotFoundException, AuthenticatorException,
IOException, OperationCanceledException {
if (savedAccount == null) {
throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null");
}
if (context == null) {
throw new IllegalArgumentException("Parameter 'context' cannot be null");
}
mSavedAccountName = savedAccount.name;
mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount));
mCredentials = AccountUtils.getCredentialsForAccount(context, savedAccount);
if (mCredentials == null) {
mCredentials = OwnCloudCredentialsFactory.getAnonymousCredentials();
}
}
*/
/**
* Constructor for non yet saved OC accounts.
*
* @param baseUri URI to the OC server to get access to.
* @param credentials Credentials to authenticate in the server. NULL is valid for anonymous credentials.
*/
public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) {
if (baseUri == null) {
throw new IllegalArgumentException("Parameter 'baseUri' cannot be null");
}
mSavedAccount = null;
mSavedAccountName = null;
mBaseUri = baseUri;
mCredentials = credentials != null ?
credentials : OwnCloudCredentialsFactory.getAnonymousCredentials();
String username = mCredentials.getUsername();
if (username != null) {
mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username);
}
}
public boolean isAnonymous() {
return (mCredentials == null);
} // TODO no more
public Uri getBaseUri() {
return mBaseUri;
}
@@ -153,5 +139,16 @@ public class OwnCloudAccount {
return mSavedAccountName;
}
public String getDisplayName() {
if (mDisplayName != null && mDisplayName.length() > 0) {
return mDisplayName;
} else if (mCredentials != null) {
return mCredentials.getUsername();
} else if (mSavedAccount != null) {
return AccountUtils.getUsernameForAccount(mSavedAccount);
} else {
return null;
}
}
}
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -47,6 +47,7 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials {
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
client.getParams().setAuthenticationPreemptive(true);
client.getParams().setCredentialCharset(OwnCloudCredentialsFactory.CREDENTIAL_CHARSET);
client.getState().setCredentials(
AuthScope.ANY,
new UsernamePasswordCredentials(mUsername, mPassword)
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -49,6 +49,7 @@ public class OwnCloudBearerCredentials implements OwnCloudCredentials {
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
client.getParams().setAuthenticationPreemptive(true);
client.getParams().setCredentialCharset(OwnCloudCredentialsFactory.CREDENTIAL_CHARSET);
client.getState().setCredentials(
AuthScope.ANY,
new BearerCredentials(mAccessToken)
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2012 Bartek Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -36,14 +36,13 @@ import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.http.HttpStatus;
import org.apache.http.params.CoreProtocolPNames;
import android.net.Uri;
@@ -60,6 +59,7 @@ public class OwnCloudClient extends HttpClient {
public static final int MAX_REDIRECTIONS_COUNT = 3;
private static final String PARAM_SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header";
private static final boolean PARAM_SINGLE_COOKIE_HEADER_VALUE = true;
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
private static byte[] sExhaustBuffer = new byte[1024];
@@ -89,7 +89,7 @@ public class OwnCloudClient extends HttpClient {
String userAgent = OwnCloudClientManagerFactory.getUserAgent();
getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
getParams().setParameter(
CoreProtocolPNames.PROTOCOL_VERSION,
PARAM_PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
getParams().setCookiePolicy(
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -53,7 +53,7 @@ public class OwnCloudClientFactory {
/** Default timeout for establishing a connection */
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
/**
* Creates a OwnCloudClient setup for an ownCloud account
*
@@ -83,7 +83,7 @@ public class OwnCloudClientFactory {
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
String username = account.name.substring(0, account.name.lastIndexOf('@'));
String username = AccountUtils.getUsernameForAccount(account);
if (isOauth2) {
String accessToken = am.blockingGetAuthToken(
account,
@@ -137,7 +137,7 @@ public class OwnCloudClientFactory {
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
String username = account.name.substring(0, account.name.lastIndexOf('@'));
String username = AccountUtils.getUsernameForAccount(account);
if (isOauth2) { // TODO avoid a call to getUserData here
AccountManagerFuture<Bundle> future = am.getAuthToken(
account,
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,8 @@ package com.owncloud.android.lib.common;
public class OwnCloudCredentialsFactory {
public static final String CREDENTIAL_CHARSET = "UTF-8";
private static OwnCloudAnonymousCredentials sAnonymousCredentials;
public static OwnCloudCredentials newBasicCredentials(String username, String password) {
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,6 +41,7 @@ public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
@Override
public void applyTo(OwnCloudClient client) {
client.getParams().setAuthenticationPreemptive(false);
client.getParams().setCredentialCharset(OwnCloudCredentialsFactory.CREDENTIAL_CHARSET);
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
client.setFollowRedirects(false);
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2012 Bartek Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -145,7 +145,23 @@ public class AccountUtils {
return baseurl;
}
/**
* Get the username corresponding to an OC account.
*
* @param account An OC account
* @return Username for the given account, extracted from the account.name
*/
public static String getUsernameForAccount(Account account) {
String username = null;
try {
username = account.name.substring(0, account.name.lastIndexOf('@'));
} catch (Exception e) {
Log_OC.e(TAG, "Couldn't get a username for the given account", e);
}
return username;
}
/**
*
@@ -168,7 +184,7 @@ public class AccountUtils {
account,
AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
String username = account.name.substring(0, account.name.lastIndexOf('@'));
String username = AccountUtils.getUsernameForAccount(account);
if (isOauth2) {
String accessToken = am.blockingGetAuthToken(
@@ -363,6 +379,12 @@ public class AccountUtils {
* OC account version
*/
public static final String KEY_OC_ACCOUNT_VERSION = "oc_account_version";
/**
* User's display name
*/
public static final String KEY_DISPLAY_NAME = "oc_display_name";
}
}
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,6 +25,7 @@
package com.owncloud.android.lib.common.network;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
@@ -58,7 +59,9 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres
Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private ByteBuffer mBuffer = ByteBuffer.allocate(4096);
public ChunkFromFileChannelRequestEntity(final FileChannel channel, final String contentType, long chunkSize, final File file) {
public ChunkFromFileChannelRequestEntity(
final FileChannel channel, final String contentType, long chunkSize, final File file
) {
super();
if (channel == null) {
throw new IllegalArgumentException("File may not be null");
@@ -119,15 +122,20 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres
public void writeRequest(final OutputStream out) throws IOException {
int readCount = 0;
Iterator<OnDatatransferProgressListener> it = null;
try {
try {
mChannel.position(mOffset);
long size = mFile.length();
if (size == 0) size = -1;
long maxCount = Math.min(mOffset + mChunkSize, mChannel.size());
while (mChannel.position() < maxCount) {
readCount = mChannel.read(mBuffer);
out.write(mBuffer.array(), 0, readCount);
try {
out.write(mBuffer.array(), 0, readCount);
} catch (IOException io) {
// work-around try catch to filter exception in writing
throw new FileRequestEntity.WriteException(io);
}
mBuffer.clear();
if (mTransferred < maxCount) { // condition to avoid accumulate progress for repeated chunks
mTransferred += readCount;
@@ -139,12 +147,21 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres
}
}
}
} catch (IOException io) {
Log_OC.e(TAG, io.getMessage());
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
// any read problem will be handled as if the file is not there
if (io instanceof FileNotFoundException) {
throw io;
} else {
FileNotFoundException fnf = new FileNotFoundException("Exception reading source file");
fnf.initCause(io);
throw fnf;
}
} catch (FileRequestEntity.WriteException we) {
throw we.getWrapped();
}
}
}
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2012 Bartek Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -26,6 +26,7 @@
package com.owncloud.android.lib.common.network;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
@@ -100,12 +101,9 @@ public class FileRequestEntity implements RequestEntity, ProgressiveDataTransfer
@Override
public void writeRequest(final OutputStream out) throws IOException {
//byte[] tmp = new byte[4096];
ByteBuffer tmp = ByteBuffer.allocate(4096);
int readResult = 0;
// TODO(bprzybylski): each mem allocation can throw OutOfMemoryError we need to handle it
// globally in some fashionable manner
RandomAccessFile raf = new RandomAccessFile(mFile, "r");
FileChannel channel = raf.getChannel();
Iterator<OnDatatransferProgressListener> it = null;
@@ -114,7 +112,12 @@ public class FileRequestEntity implements RequestEntity, ProgressiveDataTransfer
if (size == 0) size = -1;
try {
while ((readResult = channel.read(tmp)) >= 0) {
out.write(tmp.array(), 0, readResult);
try {
out.write(tmp.array(), 0, readResult);
} catch (IOException io) {
// work-around try catch to filter exception in writing
throw new WriteException(io);
}
tmp.clear();
transferred += readResult;
synchronized (mDataTransferListeners) {
@@ -124,14 +127,39 @@ public class FileRequestEntity implements RequestEntity, ProgressiveDataTransfer
}
}
}
} catch (IOException io) {
Log_OC.e("FileRequestException", io.getMessage());
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
// any read problem will be handled as if the file is not there
if (io instanceof FileNotFoundException) {
throw io;
} else {
FileNotFoundException fnf = new FileNotFoundException("Exception reading source file");
fnf.initCause(io);
throw fnf;
}
} catch (WriteException we) {
throw we.getWrapped();
} finally {
channel.close();
raf.close();
try {
channel.close();
raf.close();
} catch (IOException io) {
// ignore failures closing source file
}
}
}
protected static class WriteException extends Exception {
IOException mWrapped;
WriteException(IOException wrapped) {
mWrapped = wrapped;
}
public IOException getWrapped() {
return mWrapped;
}
}
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2012 Bartek Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -2,7 +2,7 @@
*
* @author David A. Velasco
*
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +27,7 @@
package com.owncloud.android.lib.common.network;
import org.apache.http.HttpStatus;
import org.apache.commons.httpclient.HttpStatus;
import java.util.Arrays;
@@ -53,7 +53,6 @@ public class RedirectionPath {
private String[] mLocations = null;
private int mLastLocation = -1;
private int maxRedirections;
/**
* Public constructor.
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2012 Bartek Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -306,7 +306,8 @@ public abstract class RemoteOperation implements Runnable {
* to trigger authentication update */
if (mCallerActivity != null && mAccount != null && mContext != null &&
!result.isSuccess() &&
(result.getCode() == ResultCode.UNAUTHORIZED || result.isIdPRedirection())) {
ResultCode.UNAUTHORIZED.equals(result.getCode())
) {
/// possible fail due to lack of authorization
// in an operation performed in foreground
OwnCloudCredentials cred = mClient.getCredentials();
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,6 +25,7 @@
package com.owncloud.android.lib.common.operations;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
@@ -108,7 +109,10 @@ public class RemoteOperationResult implements Serializable {
PARTIAL_MOVE_DONE,
PARTIAL_COPY_DONE,
SHARE_WRONG_PARAMETER,
WRONG_SERVER_RESPONSE, INVALID_CHARACTER_DETECT_IN_SERVER
WRONG_SERVER_RESPONSE,
INVALID_CHARACTER_DETECT_IN_SERVER,
DELAYED_FOR_WIFI,
LOCAL_FILE_NOT_FOUND
}
private boolean mSuccess = false;
@@ -180,6 +184,9 @@ public class RemoteOperationResult implements Serializable {
}
}
}
if (isIdPRedirection()) {
mCode = ResultCode.UNAUTHORIZED; // overrides default ResultCode.UNKNOWN
}
}
public RemoteOperationResult(boolean success, String bodyResponse, int httpCode) {
@@ -254,6 +261,9 @@ public class RemoteOperationResult implements Serializable {
mCode = ResultCode.SSL_ERROR;
}
} else if (e instanceof FileNotFoundException) {
mCode = ResultCode.LOCAL_FILE_NOT_FOUND;
} else {
mCode = ResultCode.UNKNOWN_ERROR;
}
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,8 +36,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,7 +25,7 @@ package com.owncloud.android.lib.resources.files;
import java.util.ArrayList;
import org.apache.http.HttpStatus;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,7 @@ package com.owncloud.android.lib.resources.files;
import java.util.ArrayList;
import org.apache.http.HttpStatus;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,9 +32,11 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.http.HttpStatus;
import org.apache.commons.httpclient.params.HttpMethodParams;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.network.FileRequestEntity;
@@ -87,8 +89,16 @@ public class UploadRemoteFileOperation extends RemoteOperation {
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
DefaultHttpMethodRetryHandler oldRetryHandler =
(DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER);
try {
// prevent that uploads are retried automatically by network library
client.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(0, false)
);
mPutMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
if (mCancellationRequested.get()) {
@@ -114,6 +124,12 @@ public class UploadRemoteFileOperation extends RemoteOperation {
} else {
result = new RemoteOperationResult(e);
}
} finally {
// reset previous retry handler
client.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER,
oldRetryHandler
);
}
return result;
}
@@ -1,7 +1,7 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,8 +26,8 @@
package com.owncloud.android.lib.resources.shares;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.http.HttpStatus;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -30,8 +30,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
/**
* Get the data about a Share resource, known its remote ID.
@@ -2,7 +2,7 @@
*
* @author masensio
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -34,8 +34,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -78,7 +78,7 @@ public class GetRemoteShareesOperation extends RemoteOperation{
// Arguments - constant values
private static final String VALUE_FORMAT = "json";
private static final String VALUE_ITEM_TYPE = "search"; // to get the server search for users / groups
private static final String VALUE_ITEM_TYPE = "file"; // to get the server search for users / groups
// JSON Node names
@@ -87,15 +87,12 @@ public class GetRemoteShareesOperation extends RemoteOperation{
private static final String NODE_EXACT = "exact";
private static final String NODE_USERS = "users";
private static final String NODE_GROUPS = "groups";
private static final String NODE_REMOTES = "remotes";
public static final String NODE_VALUE = "value";
public static final String PROPERTY_LABEL = "label";
public static final String PROPERTY_SHARE_TYPE = "shareType";
public static final String PROPERTY_SHARE_WITH = "shareWith";
// Result types
public static final Byte USER_TYPE = 0;
public static final Byte GROUP_TYPE = 1;
private String mSearchString;
private int mPage;
private int mPerPage;
@@ -146,17 +143,21 @@ public class GetRemoteShareesOperation extends RemoteOperation{
JSONObject respExact = respData.getJSONObject(NODE_EXACT);
JSONArray respExactUsers = respExact.getJSONArray(NODE_USERS);
JSONArray respExactGroups = respExact.getJSONArray(NODE_GROUPS);
JSONArray respExactRemotes = respExact.getJSONArray(NODE_REMOTES);
JSONArray respPartialUsers = respData.getJSONArray(NODE_USERS);
JSONArray respPartialGroups = respData.getJSONArray(NODE_GROUPS);
JSONArray respPartialRemotes = respData.getJSONArray(NODE_REMOTES);
JSONArray[] jsonResults = {
respExactUsers,
respExactGroups,
respExactRemotes,
respPartialUsers,
respPartialGroups
respPartialGroups,
respPartialRemotes
};
ArrayList<Object> data = new ArrayList<Object>(); // For result data
for (int i=0; i<4; i++) {
for (int i=0; i<6; i++) {
for(int j=0; j< jsonResults[i].length(); j++){
JSONObject jsonResult = jsonResults[i].getJSONObject(j);
data.add(jsonResult);
@@ -1,7 +1,7 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,9 +26,9 @@
package com.owncloud.android.lib.resources.shares;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -1,7 +1,7 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,8 +26,8 @@
package com.owncloud.android.lib.resources.shares;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,11 +40,13 @@ import com.owncloud.android.lib.resources.files.FileUtils;
*
*/
public class OCShare implements Parcelable, Serializable {
/** Generated - should be refreshed every time the class changes!! */
private static final long serialVersionUID = 4124975224281327921L;
private static final String TAG = OCShare.class.getSimpleName();
/**
* Generated - should be refreshed every time the class changes!!
*/
private static final long serialVersionUID = 4124975224281327921L;
private static final String TAG = OCShare.class.getSimpleName();
public static final int DEFAULT_PERMISSION = -1;
public static final int READ_PERMISSION_FLAG = 1;
@@ -53,14 +55,33 @@ public class OCShare implements Parcelable, Serializable {
public static final int DELETE_PERMISSION_FLAG = 8;
public static final int SHARE_PERMISSION_FLAG = 16;
public static final int MAXIMUM_PERMISSIONS_FOR_FILE =
READ_PERMISSION_FLAG +
UPDATE_PERMISSION_FLAG +
SHARE_PERMISSION_FLAG
READ_PERMISSION_FLAG +
UPDATE_PERMISSION_FLAG +
SHARE_PERMISSION_FLAG
;
public static final int MAXIMUM_PERMISSIONS_FOR_FOLDER =
MAXIMUM_PERMISSIONS_FOR_FILE +
CREATE_PERMISSION_FLAG +
DELETE_PERMISSION_FLAG
MAXIMUM_PERMISSIONS_FOR_FILE +
CREATE_PERMISSION_FLAG +
DELETE_PERMISSION_FLAG
;
public static final int FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 =
READ_PERMISSION_FLAG +
UPDATE_PERMISSION_FLAG
;
public static final int FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 =
READ_PERMISSION_FLAG +
UPDATE_PERMISSION_FLAG +
SHARE_PERMISSION_FLAG
;
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 =
READ_PERMISSION_FLAG +
UPDATE_PERMISSION_FLAG +
CREATE_PERMISSION_FLAG +
DELETE_PERMISSION_FLAG
;
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 =
FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 +
SHARE_PERMISSION_FLAG
;
private long mId;
@@ -1,7 +1,7 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -43,7 +43,8 @@ public enum ShareType {
GROUP (1),
PUBLIC_LINK (3),
EMAIL (4),
CONTACT (5);
CONTACT (5),
FEDERATED (6);
private int value;
@@ -72,6 +73,8 @@ public enum ShareType {
return EMAIL;
case 5:
return CONTACT;
case 6:
return FEDERATED;
}
return null;
}
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -353,7 +353,6 @@ public class ShareXMLParser {
share.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME));
} else if (name.equalsIgnoreCase(NODE_URL)) {
share.setShareType(ShareType.PUBLIC_LINK);
String value = readNode(parser, NODE_URL);
share.setShareLink(value);
@@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,28 +25,28 @@
package com.owncloud.android.lib.resources.shares;
import android.net.Uri;
import android.util.Pair;
import android.net.Uri;
import android.util.Pair;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.http.HttpStatus;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
/**
* Updates parameters of an existing Share resource, known its remote ID.
*
* <p/>
* Allow updating several parameters, triggering a request to the server per parameter.
*/
@@ -57,42 +57,57 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
private static final String PARAM_PASSWORD = "password";
private static final String PARAM_EXPIRATION_DATE = "expireDate";
private static final String PARAM_PERMISSIONS = "permissions";
private static final String PARAM_PUBLIC_UPLOAD = "publicUpload";
private static final String FORMAT_EXPIRATION_DATE = "yyyy-MM-dd";
private static final String ENTITY_CONTENT_TYPE = "application/x-www-form-urlencoded";
private static final String ENTITY_CONTENT_TYPE = "application/x-www-form-urlencoded";
private static final String ENTITY_CHARSET = "UTF-8";
/** Identifier of the share to update */
/**
* Identifier of the share to update
*/
private long mRemoteId;
/** Password to set for the public link */
/**
* Password to set for the public link
*/
private String mPassword;
/** Expiration date to set for the public link */
/**
* Expiration date to set for the public link
*/
private long mExpirationDateInMillis;
/** Access permissions for the file bound to the share */
/**
* Access permissions for the file bound to the share
*/
private int mPermissions;
/**
* Upload permissions for the public link (only folders)
*/
private Boolean mPublicUpload;
/**
* Constructor. No update is initialized by default, need to be applied with setters below.
*
* @param remoteId Identifier of the share to update.
* @param remoteId Identifier of the share to update.
*/
public UpdateRemoteShareOperation(long remoteId) {
mRemoteId = remoteId;
mPassword = null; // no update
mExpirationDateInMillis = 0; // no update
mPublicUpload = null;
}
/**
* Set password to update in Share resource.
*
* @param password Password to set to the target share.
* Empty string clears the current password.
* Null results in no update applied to the password.
* @param password Password to set to the target share.
* Empty string clears the current password.
* Null results in no update applied to the password.
*/
public void setPassword(String password) {
mPassword = password;
@@ -102,10 +117,10 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
/**
* Set expiration date to update in Share resource.
*
* @param expirationDateInMillis Expiration date to set to the target share.
* A negative value clears the current expiration date.
* Zero value (start-of-epoch) results in no update done on
* the expiration date.
* @param expirationDateInMillis Expiration date to set to the target share.
* A negative value clears the current expiration date.
* Zero value (start-of-epoch) results in no update done on
* the expiration date.
*/
public void setExpirationDate(long expirationDateInMillis) {
mExpirationDateInMillis = expirationDateInMillis;
@@ -115,13 +130,23 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
/**
* Set permissions to update in Share resource.
*
* @param permissions Permissions date to set to the target share.
* Values <= 0 result in no update applied to the permissions.
* @param permissions Permissions to set to the target share.
* Values <= 0 result in no update applied to the permissions.
*/
public void setPermissions(int permissions) {
mPermissions = permissions;
}
/**
* Enable upload permissions to update in Share resource.
*
* @param publicUpload Upload permission to set to the target share.
* Null results in no update applied to the upload permission.
*/
public void setPublicUpload(Boolean publicUpload) {
mPublicUpload = publicUpload;
}
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
@@ -150,17 +175,15 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions)));
}
/* TODO complete rest of parameters
if (mPublicUpload != null) {
parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString());
parametersToUpdate.add(new Pair(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)));
}
*/
/// perform required PUT requests
PutMethod put = null;
String uriString = null;
try{
try {
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1));
@@ -174,9 +197,9 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
put = new PutMethod(uriString);
put.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
put.setRequestEntity(new StringRequestEntity(
parameter.first + "=" + parameter.second,
ENTITY_CONTENT_TYPE,
ENTITY_CHARSET
parameter.first + "=" + parameter.second,
ENTITY_CONTENT_TYPE,
ENTITY_CHARSET
));
status = client.executeMethod(put);
@@ -195,6 +218,9 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
} else {
result = new RemoteOperationResult(false, status, put.getResponseHeaders());
}
if (!result.isSuccess()) {
break;
}
}
} catch (Exception e) {
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
* @author masensio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,8 +32,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import java.util.ArrayList;
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2012 Bartek Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -36,7 +36,9 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
0x04000000);
public static final OwnCloudVersion owncloud_v4_5 = new OwnCloudVersion(
0x04050000);
public static final int MINIMUN_VERSION_FOR_CHUNKED_UPLOADS = 0x04050000; // 4.5
public static final int MINIMUM_VERSION_FOR_SHARING_API = 0x05001B00; // 5.0.27
public static final int MINIMUM_VERSION_WITH_FORBIDDEN_CHARS = 0x08010000; // 8.1
@@ -48,9 +50,11 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
public static final int VERSION_8 = 0x08000000; // 8.0
public static final int MINIMUM_VERSION_CAPABILITIES_API = 0x08010000; // 8.1
private static final int MINIMUM_VERSION_WITH_NOT_RESHAREABLE_FEDERATED = 0x09010000; // 9.1
private static final int MAX_DOTS = 3;
// format is in version
// 0xAABBCCDD
// for version AA.BB.CC.DD
@@ -125,8 +129,12 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
return versionValue;
}
public boolean isChunkedUploadSupported() {
return (mVersion >= MINIMUN_VERSION_FOR_CHUNKED_UPLOADS);
}
public boolean isSharedSupported() {
return (mVersion >= MINIMUM_VERSION_FOR_SHARING_API);
}
@@ -150,6 +158,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
public boolean isVersionWithCapabilitiesAPI(){
return (mVersion>= MINIMUM_VERSION_CAPABILITIES_API);
}
public boolean isNotReshareableFederatedSupported() {
return (mVersion >= MINIMUM_VERSION_WITH_NOT_RESHAREABLE_FEDERATED);
}
}
@@ -0,0 +1,129 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.resources.users;
import java.util.ArrayList;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.JSONObject;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
/**
* Gets information (id, display name, and e-mail address) about the user logged in.
*
* @author masensio
* @author David A. Velasco
*/
public class GetRemoteUserInfoOperation extends RemoteOperation {
private static final String TAG = GetRemoteUserInfoOperation.class.getSimpleName();
// OCS Route
private static final String OCS_ROUTE = "/index.php/ocs/cloud/user?format=json";
// JSON Node names
private static final String NODE_OCS = "ocs";
private static final String NODE_DATA = "data";
private static final String NODE_ID = "id";
private static final String NODE_DISPLAY_NAME = "display-name";
private static final String NODE_EMAIL = "email";
public GetRemoteUserInfoOperation() {
}
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status = -1;
GetMethod get = null;
//Get the user
try {
get = new GetMethod(client.getBaseUri() + OCS_ROUTE);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);
if (isSuccess(status)) {
String response = get.getResponseBodyAsString();
Log_OC.d(TAG, "Successful response: " + response);
// Parse the response
JSONObject respJSON = new JSONObject(response);
JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
JSONObject respData = respOCS.getJSONObject(NODE_DATA);
UserInfo userInfo = new UserInfo();
userInfo.mId = respData.getString(NODE_ID);
userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME);
userInfo.mEmail = respData.getString(NODE_EMAIL);
// Result
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
// Username in result.data
ArrayList<Object> data = new ArrayList<Object>();
data.add(userInfo);
result.setData(data);
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting user information ");
if (response != null) {
Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
} else {
Log_OC.e(TAG, "*** status code: " + status);
}
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Exception while getting OC user information", e);
} finally {
if (get != null) {
get.releaseConnection();
}
}
return result;
}
private boolean isSuccess(int status) {
return (status == HttpStatus.SC_OK);
}
public static class UserInfo {
public String mId = "";
public String mDisplayName = "";
public String mEmail = "";
}
}
@@ -1,130 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.resources.users;
import java.util.ArrayList;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
/**
* @author masensio
*
* Get the UserName for a SAML connection, from a JSON with the format:
* id
* display-name
* email
*/
public class GetRemoteUserNameOperation extends RemoteOperation {
private static final String TAG = GetRemoteUserNameOperation.class.getSimpleName();
// OCS Route
private static final String OCS_ROUTE ="/index.php/ocs/cloud/user?format=json";
// JSON Node names
private static final String NODE_OCS = "ocs";
private static final String NODE_DATA = "data";
private static final String NODE_ID = "id";
private static final String NODE_DISPLAY_NAME= "display-name";
private static final String NODE_EMAIL= "email";
private String mUserName;
public String getUserName() {
return mUserName;
}
public GetRemoteUserNameOperation() {
}
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status = -1;
GetMethod get = null;
//Get the user
try {
get = new GetMethod(client.getBaseUri() + OCS_ROUTE);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);
if(isSuccess(status)) {
String response = get.getResponseBodyAsString();
Log_OC.d(TAG, "Successful response: " + response);
// Parse the response
JSONObject respJSON = new JSONObject(response);
JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
JSONObject respData = respOCS.getJSONObject(NODE_DATA);
String id = respData.getString(NODE_ID);
String displayName = respData.getString(NODE_DISPLAY_NAME);
String email = respData.getString(NODE_EMAIL);
// Result
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
// Username in result.data
ArrayList<Object> data = new ArrayList<Object>();
data.add(displayName);
result.setData(data);
mUserName = displayName;
Log_OC.d(TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email);
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting user information ");
if (response != null) {
Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
} else {
Log_OC.e(TAG, "*** status code: " + status);
}
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Exception while getting OC user information", e);
} finally {
get.releaseConnection();
}
return result;
}
private boolean isSuccess(int status) {
return (status == HttpStatus.SC_OK);
}
}