mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Merge branch 'release-1.6.0'
This commit is contained in:
commit
d709798359
20
.travis.yml
20
.travis.yml
@ -1,12 +1,16 @@
|
|||||||
language: java
|
language: android
|
||||||
|
android:
|
||||||
|
components:
|
||||||
|
- build-tools-20.0.0
|
||||||
|
- android-19
|
||||||
|
- android-17
|
||||||
|
- android-14
|
||||||
|
- extra-android-support
|
||||||
|
licenses:
|
||||||
|
- 'android-sdk-license-5be876d5'
|
||||||
|
- 'android-sdk-license-598b93a6'
|
||||||
jdk: oraclejdk7
|
jdk: oraclejdk7
|
||||||
before_install:
|
before_install:
|
||||||
- sudo apt-get update -qq
|
|
||||||
- sudo apt-get install -qq libstdc++6:i386 lib32z1 expect
|
|
||||||
- export LICENSES="android-sdk-license-5be876d5|android-sdk-license-598b93a6"
|
|
||||||
- curl -3L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer
|
|
||||||
| bash /dev/stdin --install=$COMPONENTS --accept=$LICENSES
|
|
||||||
- source ~/.android-sdk-installer/env
|
|
||||||
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
|
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
|
||||||
- emulator -avd test -no-skin -no-audio -no-window &
|
- emulator -avd test -no-skin -no-audio -no-window &
|
||||||
- rm pom.xml
|
- rm pom.xml
|
||||||
@ -25,4 +29,4 @@ env:
|
|||||||
- secure: aF4U20Xlu/rfrbxCmoJAiGh1doYTAZ10UEDmajuinT+ZGSJLivuqD7DDY/00sI6IXWg+J1vL+7jJm4JSYusHPg38UHZ4q92k6RmZycW2ATUzZnGT54O5FRnY67MfVwgVpIMK9UOL/6NEciBHEjlIOL0wbKQiJB++1YtBZOQLGL4=
|
- secure: aF4U20Xlu/rfrbxCmoJAiGh1doYTAZ10UEDmajuinT+ZGSJLivuqD7DDY/00sI6IXWg+J1vL+7jJm4JSYusHPg38UHZ4q92k6RmZycW2ATUzZnGT54O5FRnY67MfVwgVpIMK9UOL/6NEciBHEjlIOL0wbKQiJB++1YtBZOQLGL4=
|
||||||
- secure: N+ECSwNg8v2GsAFJ2y/tCiffauHDpN76zuFI2pDqf0fjmCtJZHu4BH5ArXBHjyHKmgn20a/8eZXcwJaH1HsJ80bo7vDJ2miShjGIQ90hPcdmUiB2XVJcew4f04CtvMDH5o7DRt4ykWArlbPL2rhVag0jotlSidolHBwRFnbDhDY=
|
- secure: N+ECSwNg8v2GsAFJ2y/tCiffauHDpN76zuFI2pDqf0fjmCtJZHu4BH5ArXBHjyHKmgn20a/8eZXcwJaH1HsJ80bo7vDJ2miShjGIQ90hPcdmUiB2XVJcew4f04CtvMDH5o7DRt4ykWArlbPL2rhVag0jotlSidolHBwRFnbDhDY=
|
||||||
matrix:
|
matrix:
|
||||||
- COMPONENTS=build-tools-20.0.0,android-19,sys-img-armeabi-v7a-android-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
|
- ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
|
||||||
|
@ -32,7 +32,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
||||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
@ -79,7 +78,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
|||||||
|
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
|
|
||||||
Uri serverUri = Uri.parse(getString(R.string.server_base_url) + AccountUtils.WEBDAV_PATH_4_0);
|
Uri serverUri = Uri.parse(getString(R.string.server_base_url));
|
||||||
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||||
mClient.setCredentials(
|
mClient.setCredentials(
|
||||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||||
|
@ -44,11 +44,11 @@ import org.apache.http.HttpStatus;
|
|||||||
import org.apache.http.params.CoreProtocolPNames;
|
import org.apache.http.params.CoreProtocolPNames;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
|
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
public class OwnCloudClient extends HttpClient {
|
public class OwnCloudClient extends HttpClient {
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
mBaseUri = baseUri;
|
mBaseUri = baseUri;
|
||||||
|
|
||||||
mInstanceNumber = sIntanceCounter++;
|
mInstanceNumber = sIntanceCounter++;
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
|
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
|
||||||
|
|
||||||
getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
|
getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
|
||||||
getParams().setParameter(
|
getParams().setParameter(
|
||||||
@ -125,7 +125,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path));
|
HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path));
|
||||||
try {
|
try {
|
||||||
int status = executeMethod(head);
|
int status = executeMethod(head);
|
||||||
Log.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
|
Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
|
||||||
((status != HttpStatus.SC_OK)?"(FAIL)":""));
|
((status != HttpStatus.SC_OK)?"(FAIL)":""));
|
||||||
exhaustResponse(head.getResponseBodyAsStream());
|
exhaustResponse(head.getResponseBodyAsStream());
|
||||||
return (status == HttpStatus.SC_OK);
|
return (status == HttpStatus.SC_OK);
|
||||||
@ -185,7 +185,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
customRedirectionNeeded = mFollowRedirects;
|
customRedirectionNeeded = mFollowRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
||||||
method.getName() + " " + method.getPath());
|
method.getName() + " " + method.getPath());
|
||||||
|
|
||||||
// logCookiesAtRequest(method.getRequestHeaders(), "before");
|
// logCookiesAtRequest(method.getRequestHeaders(), "before");
|
||||||
@ -204,7 +204,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "Exception occured", e);
|
Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occured", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,14 +222,34 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
location = method.getResponseHeader("location");
|
location = method.getResponseHeader("location");
|
||||||
}
|
}
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber,
|
Log_OC.d(TAG + " #" + mInstanceNumber,
|
||||||
"Location to redirect: " + location.getValue());
|
"Location to redirect: " + location.getValue());
|
||||||
method.setURI(new URI(location.getValue(), true));
|
method.setURI(new URI(location.getValue(), true));
|
||||||
|
Header destination = method.getRequestHeader("Destination");
|
||||||
|
if (destination == null) {
|
||||||
|
destination = method.getRequestHeader("destination");
|
||||||
|
}
|
||||||
|
if (destination != null) {
|
||||||
|
String locationStr = location.getValue();
|
||||||
|
int suffixIndex = locationStr.lastIndexOf(
|
||||||
|
(mCredentials instanceof OwnCloudBearerCredentials) ?
|
||||||
|
AccountUtils.ODAV_PATH :
|
||||||
|
AccountUtils.WEBDAV_PATH_4_0
|
||||||
|
);
|
||||||
|
String redirectionBase = locationStr.substring(0, suffixIndex);
|
||||||
|
|
||||||
|
String destinationStr = destination.getValue();
|
||||||
|
String destinationPath = destinationStr.substring(mBaseUri.toString().length());
|
||||||
|
String redirectedDestination = redirectionBase + destinationPath;
|
||||||
|
|
||||||
|
destination.setValue(redirectedDestination);
|
||||||
|
method.setRequestHeader(destination);
|
||||||
|
}
|
||||||
status = super.executeMethod(method);
|
status = super.executeMethod(method);
|
||||||
redirectionsCount++;
|
redirectionsCount++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "No location to redirect!");
|
Log_OC.d(TAG + " #" + mInstanceNumber, "No location to redirect!");
|
||||||
status = HttpStatus.SC_NOT_FOUND;
|
status = HttpStatus.SC_NOT_FOUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,7 +268,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
responseBodyAsStream.close();
|
responseBodyAsStream.close();
|
||||||
|
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
Log.e(TAG, "Unexpected exception while exhausting not interesting HTTP response;" +
|
Log_OC.e(TAG, "Unexpected exception while exhausting not interesting HTTP response;" +
|
||||||
" will be IGNORED", io);
|
" will be IGNORED", io);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -306,24 +326,24 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (int i=0; i<headers.length; i++) {
|
for (int i=0; i<headers.length; i++) {
|
||||||
if (headers[i].getName().toLowerCase().equals("cookie")) {
|
if (headers[i].getName().toLowerCase().equals("cookie")) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber,
|
Log_OC.d(TAG + " #" + mInstanceNumber,
|
||||||
"Cookies at request (" + when + ") (" + counter++ + "): " +
|
"Cookies at request (" + when + ") (" + counter++ + "): " +
|
||||||
headers[i].getValue());
|
headers[i].getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (counter == 0) {
|
if (counter == 0) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "No cookie at request before");
|
Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at request before");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logCookiesAtState(String string) {
|
private void logCookiesAtState(String string) {
|
||||||
Cookie[] cookies = getState().getCookies();
|
Cookie[] cookies = getState().getCookies();
|
||||||
if (cookies.length == 0) {
|
if (cookies.length == 0) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "No cookie at STATE before");
|
Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE before");
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (before)");
|
Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (before)");
|
||||||
for (int i=0; i<cookies.length; i++) {
|
for (int i=0; i<cookies.length; i++) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber, " (" + i + "):" +
|
Log_OC.d(TAG + " #" + mInstanceNumber, " (" + i + "):" +
|
||||||
"\n name: " + cookies[i].getName() +
|
"\n name: " + cookies[i].getName() +
|
||||||
"\n value: " + cookies[i].getValue() +
|
"\n value: " + cookies[i].getValue() +
|
||||||
"\n domain: " + cookies[i].getDomain() +
|
"\n domain: " + cookies[i].getDomain() +
|
||||||
@ -337,12 +357,12 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (int i=0; i<headers.length; i++) {
|
for (int i=0; i<headers.length; i++) {
|
||||||
if (headers[i].getName().toLowerCase().equals("set-cookie")) {
|
if (headers[i].getName().toLowerCase().equals("set-cookie")) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber,
|
Log_OC.d(TAG + " #" + mInstanceNumber,
|
||||||
"Set-Cookie (" + counter++ + "): " + headers[i].getValue());
|
"Set-Cookie (" + counter++ + "): " + headers[i].getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (counter == 0) {
|
if (counter == 0) {
|
||||||
Log.d(TAG + " #" + mInstanceNumber, "No set-cookie");
|
Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -369,15 +389,15 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void logCookie(Cookie cookie) {
|
private void logCookie(Cookie cookie) {
|
||||||
Log.d(TAG, "Cookie name: "+ cookie.getName() );
|
Log_OC.d(TAG, "Cookie name: "+ cookie.getName() );
|
||||||
Log.d(TAG, " value: "+ cookie.getValue() );
|
Log_OC.d(TAG, " value: "+ cookie.getValue() );
|
||||||
Log.d(TAG, " domain: "+ cookie.getDomain());
|
Log_OC.d(TAG, " domain: "+ cookie.getDomain());
|
||||||
Log.d(TAG, " path: "+ cookie.getPath() );
|
Log_OC.d(TAG, " path: "+ cookie.getPath() );
|
||||||
Log.d(TAG, " version: "+ cookie.getVersion() );
|
Log_OC.d(TAG, " version: "+ cookie.getVersion() );
|
||||||
Log.d(TAG, " expiryDate: " +
|
Log_OC.d(TAG, " expiryDate: " +
|
||||||
(cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
|
(cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
|
||||||
Log.d(TAG, " comment: "+ cookie.getComment() );
|
Log_OC.d(TAG, " comment: "+ cookie.getComment() );
|
||||||
Log.d(TAG, " secure: "+ cookie.getSecure() );
|
Log_OC.d(TAG, " secure: "+ cookie.getSecure() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,11 +27,6 @@ package com.owncloud.android.lib.common;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
|
||||||
import com.owncloud.android.lib.common.network.NetworkUtils;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.AccountManagerFuture;
|
import android.accounts.AccountManagerFuture;
|
||||||
@ -41,7 +36,12 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
||||||
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
|
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||||
|
import com.owncloud.android.lib.common.network.NetworkUtils;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
public class OwnCloudClientFactory {
|
public class OwnCloudClientFactory {
|
||||||
|
|
||||||
@ -192,10 +192,10 @@ public class OwnCloudClientFactory {
|
|||||||
try {
|
try {
|
||||||
NetworkUtils.registerAdvancedSslContext(true, context);
|
NetworkUtils.registerAdvancedSslContext(true, context);
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
Log.e(TAG, "Advanced SSL Context could not be loaded. Default SSL management in the system will be used for HTTPS connections", e);
|
Log_OC.e(TAG, "Advanced SSL Context could not be loaded. Default SSL management in the system will be used for HTTPS connections", e);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "The local server truststore could not be read. Default SSL management in the system will be used for HTTPS connections", e);
|
Log_OC.e(TAG, "The local server truststore could not be read. Default SSL management in the system will be used for HTTPS connections", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager());
|
OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager());
|
||||||
|
@ -25,10 +25,10 @@
|
|||||||
package com.owncloud.android.lib.common;
|
package com.owncloud.android.lib.common;
|
||||||
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
public class SimpleFactoryManager implements OwnCloudClientManager {
|
public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||||
|
|
||||||
@ -36,13 +36,13 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
|
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
|
||||||
Log.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
Log_OC.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
||||||
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
|
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
|
||||||
account.getBaseUri(),
|
account.getBaseUri(),
|
||||||
context.getApplicationContext(),
|
context.getApplicationContext(),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
Log.d(TAG, " new client {" +
|
Log_OC.d(TAG, " new client {" +
|
||||||
(account.getName() != null ?
|
(account.getName() != null ?
|
||||||
account.getName() :
|
account.getName() :
|
||||||
AccountUtils.buildAccountName(
|
AccountUtils.buildAccountName(
|
||||||
|
@ -36,12 +36,10 @@ import android.accounts.AuthenticatorException;
|
|||||||
import android.accounts.OperationCanceledException;
|
import android.accounts.OperationCanceledException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link OwnCloudClientManager}
|
* Implementation of {@link OwnCloudClientManager}
|
||||||
@ -65,7 +63,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
|
public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
|
||||||
Log.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
Log_OC.d(TAG, "getClientFor(OwnCloudAccount ... : ");
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
throw new IllegalArgumentException("Cannot get an OwnCloudClient for a null account");
|
throw new IllegalArgumentException("Cannot get an OwnCloudClient for a null account");
|
||||||
}
|
}
|
||||||
@ -84,17 +82,17 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
if (accountName != null) {
|
if (accountName != null) {
|
||||||
client = mClientsWithUnknownUsername.remove(sessionName);
|
client = mClientsWithUnknownUsername.remove(sessionName);
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
Log.d(TAG, " reusing client {" + sessionName + ", " +
|
Log_OC.d(TAG, " reusing client {" + sessionName + ", " +
|
||||||
client.hashCode() + "}");
|
client.hashCode() + "}");
|
||||||
mClientsWithKnownUsername.put(accountName, client);
|
mClientsWithKnownUsername.put(accountName, client);
|
||||||
Log.d(TAG, " moved client to {" + accountName + ", " +
|
Log_OC.d(TAG, " moved client to {" + accountName + ", " +
|
||||||
client.hashCode() + "}");
|
client.hashCode() + "}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client = mClientsWithUnknownUsername.get(sessionName);
|
client = mClientsWithUnknownUsername.get(sessionName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}");
|
Log_OC.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}");
|
||||||
reusingKnown = true;
|
reusingKnown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,15 +112,15 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
client.setCredentials(account.getCredentials());
|
client.setCredentials(account.getCredentials());
|
||||||
if (accountName != null) {
|
if (accountName != null) {
|
||||||
mClientsWithKnownUsername.put(accountName, client);
|
mClientsWithKnownUsername.put(accountName, client);
|
||||||
Log.d(TAG, " new client {" + accountName + ", " + client.hashCode() + "}");
|
Log_OC.d(TAG, " new client {" + accountName + ", " + client.hashCode() + "}");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mClientsWithUnknownUsername.put(sessionName, client);
|
mClientsWithUnknownUsername.put(sessionName, client);
|
||||||
Log.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}");
|
Log_OC.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!reusingKnown) {
|
if (!reusingKnown) {
|
||||||
Log.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
|
Log_OC.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
|
||||||
}
|
}
|
||||||
keepCredentialsUpdated(account, client);
|
keepCredentialsUpdated(account, client);
|
||||||
keepUriUpdated(account, client);
|
keepUriUpdated(account, client);
|
||||||
@ -144,10 +142,10 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
if (accountName != null) {
|
if (accountName != null) {
|
||||||
client = mClientsWithKnownUsername.remove(accountName);
|
client = mClientsWithKnownUsername.remove(accountName);
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
Log.d(TAG, "Removed client {" + accountName + ", " + client.hashCode() + "}");
|
Log_OC.d(TAG, "Removed client {" + accountName + ", " + client.hashCode() + "}");
|
||||||
return client;
|
return client;
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "No client tracked for {" + accountName + "}");
|
Log_OC.d(TAG, "No client tracked for {" + accountName + "}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,12 +154,12 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
account.getCredentials().getAuthToken());
|
account.getCredentials().getAuthToken());
|
||||||
client = mClientsWithUnknownUsername.remove(sessionName);
|
client = mClientsWithUnknownUsername.remove(sessionName);
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
Log.d(TAG, "Removed client {" + sessionName + ", " + client.hashCode() + "}");
|
Log_OC.d(TAG, "Removed client {" + sessionName + ", " + client.hashCode() + "}");
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
Log.d(TAG, "No client tracked for {" + sessionName + "}");
|
Log_OC.d(TAG, "No client tracked for {" + sessionName + "}");
|
||||||
|
|
||||||
Log.d(TAG, "No client removed");
|
Log_OC.d(TAG, "No client removed");
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,11 +36,11 @@ import android.accounts.AuthenticatorException;
|
|||||||
import android.accounts.OperationCanceledException;
|
import android.accounts.OperationCanceledException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
||||||
|
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;
|
||||||
|
|
||||||
public class AccountUtils {
|
public class AccountUtils {
|
||||||
@ -220,7 +220,7 @@ public class AccountUtils {
|
|||||||
String cookiesString = client.getCookiesString();
|
String cookiesString = client.getCookiesString();
|
||||||
if (cookiesString != "") {
|
if (cookiesString != "") {
|
||||||
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
|
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
|
||||||
// Log.d(TAG, "Saving Cookies: "+ cookiesString );
|
// Log_OC.d(TAG, "Saving Cookies: "+ cookiesString );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ public class AccountUtils {
|
|||||||
*/
|
*/
|
||||||
public static void restoreCookies(Account account, OwnCloudClient client, Context context) {
|
public static void restoreCookies(Account account, OwnCloudClient client, Context context) {
|
||||||
|
|
||||||
Log.d(TAG, "Restoring cookies for " + account.name);
|
Log_OC.d(TAG, "Restoring cookies for " + account.name);
|
||||||
|
|
||||||
// Account Manager
|
// Account Manager
|
||||||
AccountManager am = AccountManager.get(context.getApplicationContext());
|
AccountManager am = AccountManager.get(context.getApplicationContext());
|
||||||
@ -267,7 +267,7 @@ public class AccountUtils {
|
|||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
public static void restoreCookies(String accountName, OwnCloudClient client, Context context) {
|
public static void restoreCookies(String accountName, OwnCloudClient client, Context context) {
|
||||||
Log.d(TAG, "Restoring cookies for " + accountName);
|
Log_OC.d(TAG, "Restoring cookies for " + accountName);
|
||||||
|
|
||||||
// Account Manager
|
// Account Manager
|
||||||
AccountManager am = AccountManager.get(context.getApplicationContext());
|
AccountManager am = AccountManager.get(context.getApplicationContext());
|
||||||
|
@ -30,15 +30,12 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
//import java.security.Provider;
|
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
//import java.util.Enumeration;
|
|
||||||
|
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
//import javax.net.ssl.SSLParameters;
|
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
@ -48,8 +45,7 @@ import org.apache.commons.httpclient.params.HttpConnectionParams;
|
|||||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
||||||
|
|
||||||
//import android.os.Build;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -97,39 +93,39 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
|||||||
/*
|
/*
|
||||||
private void logSslInfo() {
|
private void logSslInfo() {
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
|
||||||
Log.v(TAG, "SUPPORTED SSL PARAMETERS");
|
Log_OC.v(TAG, "SUPPORTED SSL PARAMETERS");
|
||||||
logSslParameters(mSslContext.getSupportedSSLParameters());
|
logSslParameters(mSslContext.getSupportedSSLParameters());
|
||||||
Log.v(TAG, "DEFAULT SSL PARAMETERS");
|
Log_OC.v(TAG, "DEFAULT SSL PARAMETERS");
|
||||||
logSslParameters(mSslContext.getDefaultSSLParameters());
|
logSslParameters(mSslContext.getDefaultSSLParameters());
|
||||||
Log.i(TAG, "CURRENT PARAMETERS");
|
Log_OC.i(TAG, "CURRENT PARAMETERS");
|
||||||
Log.i(TAG, "Protocol: " + mSslContext.getProtocol());
|
Log_OC.i(TAG, "Protocol: " + mSslContext.getProtocol());
|
||||||
}
|
}
|
||||||
Log.i(TAG, "PROVIDER");
|
Log_OC.i(TAG, "PROVIDER");
|
||||||
logSecurityProvider(mSslContext.getProvider());
|
logSecurityProvider(mSslContext.getProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logSecurityProvider(Provider provider) {
|
private void logSecurityProvider(Provider provider) {
|
||||||
Log.i(TAG, "name: " + provider.getName());
|
Log_OC.i(TAG, "name: " + provider.getName());
|
||||||
Log.i(TAG, "version: " + provider.getVersion());
|
Log_OC.i(TAG, "version: " + provider.getVersion());
|
||||||
Log.i(TAG, "info: " + provider.getInfo());
|
Log_OC.i(TAG, "info: " + provider.getInfo());
|
||||||
Enumeration<?> keys = provider.propertyNames();
|
Enumeration<?> keys = provider.propertyNames();
|
||||||
String key;
|
String key;
|
||||||
while (keys.hasMoreElements()) {
|
while (keys.hasMoreElements()) {
|
||||||
key = (String) keys.nextElement();
|
key = (String) keys.nextElement();
|
||||||
Log.i(TAG, " property " + key + " : " + provider.getProperty(key));
|
Log_OC.i(TAG, " property " + key + " : " + provider.getProperty(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logSslParameters(SSLParameters params) {
|
private void logSslParameters(SSLParameters params) {
|
||||||
Log.v(TAG, "Cipher suites: ");
|
Log_OC.v(TAG, "Cipher suites: ");
|
||||||
String [] elements = params.getCipherSuites();
|
String [] elements = params.getCipherSuites();
|
||||||
for (int i=0; i<elements.length ; i++) {
|
for (int i=0; i<elements.length ; i++) {
|
||||||
Log.v(TAG, " " + elements[i]);
|
Log_OC.v(TAG, " " + elements[i]);
|
||||||
}
|
}
|
||||||
Log.v(TAG, "Protocols: ");
|
Log_OC.v(TAG, "Protocols: ");
|
||||||
elements = params.getProtocols();
|
elements = params.getProtocols();
|
||||||
for (int i=0; i<elements.length ; i++) {
|
for (int i=0; i<elements.length ; i++) {
|
||||||
Log.v(TAG, " " + elements[i]);
|
Log_OC.v(TAG, " " + elements[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@ -154,7 +150,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
|||||||
final InetAddress localAddress, final int localPort,
|
final InetAddress localAddress, final int localPort,
|
||||||
final HttpConnectionParams params) throws IOException,
|
final HttpConnectionParams params) throws IOException,
|
||||||
UnknownHostException, ConnectTimeoutException {
|
UnknownHostException, ConnectTimeoutException {
|
||||||
Log.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params);
|
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params);
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
throw new IllegalArgumentException("Parameters may not be null");
|
throw new IllegalArgumentException("Parameters may not be null");
|
||||||
}
|
}
|
||||||
@ -163,7 +159,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
|||||||
//logSslInfo();
|
//logSslInfo();
|
||||||
|
|
||||||
SocketFactory socketfactory = mSslContext.getSocketFactory();
|
SocketFactory socketfactory = mSslContext.getSocketFactory();
|
||||||
Log.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
|
Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
|
||||||
Socket socket = socketfactory.createSocket();
|
Socket socket = socketfactory.createSocket();
|
||||||
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
|
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
|
||||||
SocketAddress remoteaddr = new InetSocketAddress(host, port);
|
SocketAddress remoteaddr = new InetSocketAddress(host, port);
|
||||||
@ -180,7 +176,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
|
|||||||
*/
|
*/
|
||||||
public Socket createSocket(String host, int port) throws IOException,
|
public Socket createSocket(String host, int port) throws IOException,
|
||||||
UnknownHostException {
|
UnknownHostException {
|
||||||
Log.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
|
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
|
||||||
Socket socket = mSslContext.getSocketFactory().createSocket(host, port);
|
Socket socket = mSslContext.getSocketFactory().createSocket(host, port);
|
||||||
verifyPeerIdentity(host, port, socket);
|
verifyPeerIdentity(host, port, socket);
|
||||||
return socket;
|
return socket;
|
||||||
|
@ -38,7 +38,7 @@ import javax.net.ssl.TrustManager;
|
|||||||
import javax.net.ssl.TrustManagerFactory;
|
import javax.net.ssl.TrustManagerFactory;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
import android.util.Log;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
|||||||
try {
|
try {
|
||||||
return (mKnownServersKeyStore.getCertificateAlias(cert) != null);
|
return (mKnownServersKeyStore.getCertificateAlias(cert) != null);
|
||||||
} catch (KeyStoreException e) {
|
} catch (KeyStoreException e) {
|
||||||
Log.d(TAG, "Fail while checking certificate in the known-servers store");
|
Log_OC.d(TAG, "Fail while checking certificate in the known-servers store");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ import org.apache.commons.httpclient.auth.AuthenticationException;
|
|||||||
import org.apache.commons.httpclient.auth.InvalidCredentialsException;
|
import org.apache.commons.httpclient.auth.InvalidCredentialsException;
|
||||||
import org.apache.commons.httpclient.auth.MalformedChallengeException;
|
import org.apache.commons.httpclient.auth.MalformedChallengeException;
|
||||||
|
|
||||||
import android.util.Log;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
|
|||||||
* @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
|
* @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
|
||||||
*/
|
*/
|
||||||
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
|
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
|
||||||
Log.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");
|
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");
|
||||||
|
|
||||||
BearerCredentials bearer = null;
|
BearerCredentials bearer = null;
|
||||||
try {
|
try {
|
||||||
@ -164,7 +164,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
|
|||||||
* @return a basic authorization string
|
* @return a basic authorization string
|
||||||
*/
|
*/
|
||||||
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
|
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
|
||||||
Log.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");
|
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");
|
||||||
|
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
throw new IllegalArgumentException("Method may not be null");
|
throw new IllegalArgumentException("Method may not be null");
|
||||||
@ -208,7 +208,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
|
|||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public static String authenticate(BearerCredentials credentials, String charset) {
|
public static String authenticate(BearerCredentials credentials, String charset) {
|
||||||
Log.d(TAG, "enter BearerAuthScheme.authenticate(BearerCredentials, String)");
|
Log_OC.d(TAG, "enter BearerAuthScheme.authenticate(BearerCredentials, String)");
|
||||||
|
|
||||||
if (credentials == null) {
|
if (credentials == null) {
|
||||||
throw new IllegalArgumentException("Credentials may not be null");
|
throw new IllegalArgumentException("Credentials may not be null");
|
||||||
|
@ -36,8 +36,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,7 +141,7 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
Log.e(TAG, io.getMessage());
|
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);
|
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||||
|
|
||||||
import android.util.Log;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class FileRequestEntity implements RequestEntity, ProgressiveDataTransfer
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
Log.e("FileRequestException", io.getMessage());
|
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);
|
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -45,7 +45,8 @@ import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
|
|||||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
public class NetworkUtils {
|
public class NetworkUtils {
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ public class NetworkUtils {
|
|||||||
//mKnownServersStore = KeyStore.getInstance("BKS");
|
//mKnownServersStore = KeyStore.getInstance("BKS");
|
||||||
mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
File localTrustStoreFile = new File(context.getFilesDir(), LOCAL_TRUSTSTORE_FILENAME);
|
File localTrustStoreFile = new File(context.getFilesDir(), LOCAL_TRUSTSTORE_FILENAME);
|
||||||
Log.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath());
|
Log_OC.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath());
|
||||||
if (localTrustStoreFile.exists()) {
|
if (localTrustStoreFile.exists()) {
|
||||||
InputStream in = new FileInputStream(localTrustStoreFile);
|
InputStream in = new FileInputStream(localTrustStoreFile);
|
||||||
try {
|
try {
|
||||||
@ -175,7 +176,7 @@ public class NetworkUtils {
|
|||||||
public static boolean isCertInKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
public static boolean isCertInKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
||||||
|
|
||||||
KeyStore knownServers = getKnownServersStore(context);
|
KeyStore knownServers = getKnownServersStore(context);
|
||||||
Log.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
|
Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
|
||||||
+ Boolean.toString(knownServers.isCertificateEntry(Integer.toString(cert.hashCode()))));
|
+ Boolean.toString(knownServers.isCertificateEntry(Integer.toString(cert.hashCode()))));
|
||||||
return knownServers.isCertificateEntry(Integer.toString(cert.hashCode()));
|
return knownServers.isCertificateEntry(Integer.toString(cert.hashCode()));
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
|
|
||||||
import android.util.Log;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,19 +80,19 @@ public class ServerNameIndicator {
|
|||||||
if (setHostnameMethod != null) {
|
if (setHostnameMethod != null) {
|
||||||
try {
|
try {
|
||||||
setHostnameMethod.invoke(sslSocket, hostname);
|
setHostnameMethod.invoke(sslSocket, hostname);
|
||||||
Log.i(TAG, "SNI done, hostname: " + hostname);
|
Log_OC.i(TAG, "SNI done, hostname: " + hostname);
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||||
|
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||||
|
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "SNI not supported");
|
Log_OC.i(TAG, "SNI not supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,15 +134,15 @@ public class ServerNameIndicator {
|
|||||||
* @return Method to call to indicate the server name of interest to the server.
|
* @return Method to call to indicate the server name of interest to the server.
|
||||||
*/
|
*/
|
||||||
private static Method initFrom(Class<?> sslSocketClass) {
|
private static Method initFrom(Class<?> sslSocketClass) {
|
||||||
Log.i(TAG, "SSLSocket implementation: " + sslSocketClass.getCanonicalName());
|
Log_OC.i(TAG, "SSLSocket implementation: " + sslSocketClass.getCanonicalName());
|
||||||
Method setHostnameMethod = null;
|
Method setHostnameMethod = null;
|
||||||
try {
|
try {
|
||||||
setHostnameMethod = sslSocketClass.getMethod(METHOD_NAME, String.class);
|
setHostnameMethod = sslSocketClass.getMethod(METHOD_NAME, String.class);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Log.e(TAG, "Could not access to SSLSocket#setHostname(String) method ", e);
|
Log_OC.e(TAG, "Could not access to SSLSocket#setHostname(String) method ", e);
|
||||||
|
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Log.i(TAG, "Could not find SSLSocket#setHostname(String) method - SNI not supported");
|
Log_OC.i(TAG, "Could not find SSLSocket#setHostname(String) method - SNI not supported");
|
||||||
}
|
}
|
||||||
mSingleInstance.set(new ServerNameIndicator(sslSocketClass, setHostnameMethod));
|
mSingleInstance.set(new ServerNameIndicator(sslSocketClass, setHostnameMethod));
|
||||||
return setHostnameMethod;
|
return setHostnameMethod;
|
||||||
|
@ -33,7 +33,8 @@ import org.apache.jackrabbit.webdav.property.DavPropertySet;
|
|||||||
import org.apache.jackrabbit.webdav.xml.Namespace;
|
import org.apache.jackrabbit.webdav.xml.Namespace;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
public class WebdavEntry {
|
public class WebdavEntry {
|
||||||
private static final String NAMESPACE_OC = "http://owncloud.org/ns";
|
private static final String NAMESPACE_OC = "http://owncloud.org/ns";
|
||||||
@ -125,7 +126,7 @@ public class WebdavEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.e("WebdavEntry",
|
Log_OC.e("WebdavEntry",
|
||||||
"General fuckup, no status for webdav response");
|
"General fuckup, no status for webdav response");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,13 @@ package com.owncloud.android.lib.common.operations;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
|
import android.accounts.AccountsException;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||||
@ -33,16 +40,7 @@ import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|||||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.accounts.AccountsException;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,7 +108,7 @@ public abstract class RemoteOperation implements Runnable {
|
|||||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||||
getClientFor(ocAccount, mContext);
|
getClientFor(ocAccount, mContext);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||||
return new RemoteOperationResult(e);
|
return new RemoteOperationResult(e);
|
||||||
}
|
}
|
||||||
return run(mClient);
|
return run(mClient);
|
||||||
@ -266,11 +264,11 @@ public abstract class RemoteOperation implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Error while trying to access to " + mAccount.name, new AccountsException("I/O exception while trying to authorize the account", e));
|
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, new AccountsException("I/O exception while trying to authorize the account", e));
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
|
|
||||||
} catch (AccountsException e) {
|
} catch (AccountsException e) {
|
||||||
Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ import org.apache.commons.httpclient.HttpStatus;
|
|||||||
import org.apache.jackrabbit.webdav.DavException;
|
import org.apache.jackrabbit.webdav.DavException;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
|
||||||
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountsException;
|
import android.accounts.AccountsException;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||||
|
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,7 +98,12 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
ACCOUNT_NOT_THE_SAME,
|
ACCOUNT_NOT_THE_SAME,
|
||||||
INVALID_CHARACTER_IN_NAME,
|
INVALID_CHARACTER_IN_NAME,
|
||||||
SHARE_NOT_FOUND,
|
SHARE_NOT_FOUND,
|
||||||
LOCAL_STORAGE_NOT_REMOVED
|
LOCAL_STORAGE_NOT_REMOVED,
|
||||||
|
FORBIDDEN,
|
||||||
|
SHARE_FORBIDDEN,
|
||||||
|
OK_REDIRECT_TO_NON_SECURE_CONNECTION,
|
||||||
|
INVALID_MOVE_INTO_DESCENDANT,
|
||||||
|
PARTIAL_MOVE_DONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mSuccess = false;
|
private boolean mSuccess = false;
|
||||||
@ -112,7 +117,7 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
|
|
||||||
public RemoteOperationResult(ResultCode code) {
|
public RemoteOperationResult(ResultCode code) {
|
||||||
mCode = code;
|
mCode = code;
|
||||||
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL);
|
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL || code == ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION);
|
||||||
mData = null;
|
mData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,9 +145,12 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
case HttpStatus.SC_INSUFFICIENT_STORAGE:
|
case HttpStatus.SC_INSUFFICIENT_STORAGE:
|
||||||
mCode = ResultCode.QUOTA_EXCEEDED;
|
mCode = ResultCode.QUOTA_EXCEEDED;
|
||||||
break;
|
break;
|
||||||
|
case HttpStatus.SC_FORBIDDEN:
|
||||||
|
mCode = ResultCode.FORBIDDEN;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
mCode = ResultCode.UNHANDLED_HTTP_CODE;
|
mCode = ResultCode.UNHANDLED_HTTP_CODE;
|
||||||
Log.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
|
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,6 +253,10 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
return mCode == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED;
|
return mCode == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRedirectToNonSecureConnection() {
|
||||||
|
return mCode == ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION;
|
||||||
|
}
|
||||||
|
|
||||||
private CertificateCombinedException getCertificateCombinedException(Exception e) {
|
private CertificateCombinedException getCertificateCombinedException(Exception e) {
|
||||||
CertificateCombinedException result = null;
|
CertificateCombinedException result = null;
|
||||||
if (e instanceof CertificateCombinedException) {
|
if (e instanceof CertificateCombinedException) {
|
||||||
@ -366,6 +378,15 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
mRedirectedLocation.toLowerCase().contains("wayf")));
|
mRedirectedLocation.toLowerCase().contains("wayf")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is a non https connection
|
||||||
|
*
|
||||||
|
* @return boolean true/false
|
||||||
|
*/
|
||||||
|
public boolean isNonSecureRedirection() {
|
||||||
|
return (mRedirectedLocation != null && !(mRedirectedLocation.toLowerCase().startsWith("https://")));
|
||||||
|
}
|
||||||
|
|
||||||
public String getAuthenticateHeader() {
|
public String getAuthenticateHeader() {
|
||||||
return mAuthenticate;
|
return mAuthenticate;
|
||||||
}
|
}
|
||||||
|
178
src/com/owncloud/android/lib/common/utils/Log_OC.java
Normal file
178
src/com/owncloud/android/lib/common/utils/Log_OC.java
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
package com.owncloud.android.lib.common.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
|
public class Log_OC {
|
||||||
|
private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
|
||||||
|
private static final String LOG_FOLDER_NAME = "log";
|
||||||
|
private static final long MAX_FILE_SIZE = 1000000; // 1MB
|
||||||
|
|
||||||
|
private static String mOwncloudDataFolderLog = "owncloud_log";
|
||||||
|
|
||||||
|
private static File mLogFile;
|
||||||
|
private static File mFolder;
|
||||||
|
private static BufferedWriter mBuf;
|
||||||
|
|
||||||
|
private static String[] mLogFileNames = {"currentLog.txt", "olderLog.txt"};
|
||||||
|
|
||||||
|
private static boolean isMaxFileSizeReached = false;
|
||||||
|
private static boolean isEnabled = false;
|
||||||
|
|
||||||
|
public static void setLogDataFolder(String logFolder){
|
||||||
|
mOwncloudDataFolderLog = logFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void i(String TAG, String message){
|
||||||
|
|
||||||
|
// Write the log message to the file
|
||||||
|
appendLog(TAG+" : "+ message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void d(String TAG, String message){
|
||||||
|
Log.d(TAG, message);
|
||||||
|
appendLog(TAG + " : " + message);
|
||||||
|
}
|
||||||
|
public static void d(String TAG, String message, Exception e) {
|
||||||
|
Log.d(TAG, message, e);
|
||||||
|
appendLog(TAG + " : " + message + " Exception : "+ e.getStackTrace());
|
||||||
|
}
|
||||||
|
public static void e(String TAG, String message){
|
||||||
|
Log.e(TAG, message);
|
||||||
|
appendLog(TAG + " : " + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void e(String TAG, String message, Throwable e) {
|
||||||
|
Log.e(TAG, message, e);
|
||||||
|
appendLog(TAG+" : " + message +" Exception : " + e.getStackTrace());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void v(String TAG, String message){
|
||||||
|
Log.v(TAG, message);
|
||||||
|
appendLog(TAG+" : "+ message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void w(String TAG, String message) {
|
||||||
|
Log.w(TAG,message);
|
||||||
|
appendLog(TAG+" : "+ message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void wtf(String TAG, String message) {
|
||||||
|
Log.wtf(TAG,message);
|
||||||
|
appendLog(TAG+" : "+ message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start doing logging
|
||||||
|
* @param logPath : path of log file
|
||||||
|
*/
|
||||||
|
public static void startLogging() {
|
||||||
|
String logPath = Environment.getExternalStorageDirectory() + File.separator +
|
||||||
|
mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME;
|
||||||
|
mFolder = new File(logPath);
|
||||||
|
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
||||||
|
|
||||||
|
boolean isFileCreated = false;
|
||||||
|
|
||||||
|
if (!mFolder.exists()) {
|
||||||
|
mFolder.mkdirs();
|
||||||
|
isFileCreated = true;
|
||||||
|
Log.d("LOG_OC", "Log file created");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Create the current log file if does not exist
|
||||||
|
mLogFile.createNewFile();
|
||||||
|
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
||||||
|
isEnabled = true;
|
||||||
|
|
||||||
|
if (isFileCreated) {
|
||||||
|
appendPhoneInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete history logging
|
||||||
|
*/
|
||||||
|
public static void deleteHistoryLogging() {
|
||||||
|
File folderLogs = new File(mFolder + File.separator);
|
||||||
|
if(folderLogs.isDirectory()){
|
||||||
|
String[] myFiles = folderLogs.list();
|
||||||
|
for (int i=0; i<myFiles.length; i++) {
|
||||||
|
File myFile = new File(folderLogs, myFiles[i]);
|
||||||
|
myFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append the info of the device
|
||||||
|
*/
|
||||||
|
private static void appendPhoneInfo() {
|
||||||
|
appendLog("Model : " + android.os.Build.MODEL);
|
||||||
|
appendLog("Brand : " + android.os.Build.BRAND);
|
||||||
|
appendLog("Product : " + android.os.Build.PRODUCT);
|
||||||
|
appendLog("Device : " + android.os.Build.DEVICE);
|
||||||
|
appendLog("Version-Codename : " + android.os.Build.VERSION.CODENAME);
|
||||||
|
appendLog("Version-Release : " + android.os.Build.VERSION.RELEASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append to the log file the info passed
|
||||||
|
* @param text : text for adding to the log file
|
||||||
|
*/
|
||||||
|
private static void appendLog(String text) {
|
||||||
|
|
||||||
|
if (isEnabled) {
|
||||||
|
|
||||||
|
if (isMaxFileSizeReached) {
|
||||||
|
|
||||||
|
// Move current log file info to another file (old logs)
|
||||||
|
File olderFile = new File(mFolder + File.separator + mLogFileNames[1]);
|
||||||
|
if (mLogFile.exists()) {
|
||||||
|
mLogFile.renameTo(olderFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a new file for current log info
|
||||||
|
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
||||||
|
isMaxFileSizeReached = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT).format(Calendar.getInstance().getTime());
|
||||||
|
|
||||||
|
try {
|
||||||
|
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
||||||
|
mBuf.newLine();
|
||||||
|
mBuf.write(timeStamp);
|
||||||
|
mBuf.newLine();
|
||||||
|
mBuf.write(text);
|
||||||
|
mBuf.newLine();
|
||||||
|
mBuf.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if current log file size is bigger than the max file size defined
|
||||||
|
if (mLogFile.length() > MAX_FILE_SIZE) {
|
||||||
|
isMaxFileSizeReached = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getLogFileNames() {
|
||||||
|
return mLogFileNames;
|
||||||
|
}
|
||||||
|
}
|
@ -37,9 +37,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|||||||
import com.owncloud.android.lib.common.network.ChunkFromFileChannelRequestEntity;
|
import com.owncloud.android.lib.common.network.ChunkFromFileChannelRequestEntity;
|
||||||
import com.owncloud.android.lib.common.network.ProgressiveDataTransferer;
|
import com.owncloud.android.lib.common.network.ProgressiveDataTransferer;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation {
|
public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation {
|
||||||
@ -81,7 +79,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
mPutMethod.setRequestEntity(mEntity);
|
mPutMethod.setRequestEntity(mEntity);
|
||||||
status = client.executeMethod(mPutMethod);
|
status = client.executeMethod(mPutMethod);
|
||||||
client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
|
client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
|
||||||
Log.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
|
Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
|
||||||
if (!isSuccess(status))
|
if (!isSuccess(status))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,12 @@ package com.owncloud.android.lib.resources.files;
|
|||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
|
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -87,12 +86,12 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
|
result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
|
||||||
Log.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
||||||
client.exhaustResponse(mkcol.getResponseBodyAsStream());
|
client.exhaustResponse(mkcol.getResponseBodyAsStream());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (mkcol != null)
|
if (mkcol != null)
|
||||||
|
@ -39,14 +39,13 @@ import org.apache.commons.httpclient.HttpException;
|
|||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.OperationCancelledException;
|
import com.owncloud.android.lib.common.operations.OperationCancelledException;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the download of a remote file in the ownCloud server.
|
* Remote operation performing the download of a remote file in the ownCloud server.
|
||||||
@ -84,11 +83,11 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
|||||||
tmpFile.getParentFile().mkdirs();
|
tmpFile.getParentFile().mkdirs();
|
||||||
int status = downloadFile(client, tmpFile);
|
int status = downloadFile(client, tmpFile);
|
||||||
result = new RemoteOperationResult(isSuccess(status), status, (mGet != null ? mGet.getResponseHeaders() : null));
|
result = new RemoteOperationResult(isSuccess(status), status, (mGet != null ? mGet.getResponseHeaders() : null));
|
||||||
Log.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage());
|
Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -27,14 +27,14 @@ package com.owncloud.android.lib.resources.files;
|
|||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.methods.HeadMethod;
|
import org.apache.commons.httpclient.methods.HeadMethod;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operation to check the existence or absence of a path in a remote server.
|
* Operation to check the existence or absence of a path in a remote server.
|
||||||
@ -80,11 +80,11 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
client.exhaustResponse(head.getResponseBodyAsStream());
|
client.exhaustResponse(head.getResponseBodyAsStream());
|
||||||
boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
|
boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
|
||||||
result = new RemoteOperationResult(success, status, head.getResponseHeaders());
|
result = new RemoteOperationResult(success, status, head.getResponseHeaders());
|
||||||
Log.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
|
Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
|
Log_OC.e(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (head != null)
|
if (head != null)
|
||||||
|
@ -26,7 +26,7 @@ package com.owncloud.android.lib.resources.files;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import android.util.Log;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public class FileUtils {
|
|||||||
public static boolean isValidName(String fileName) {
|
public static boolean isValidName(String fileName) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
Log.d("FileUtils", "fileName =======" + fileName);
|
Log_OC.d("FileUtils", "fileName =======" + fileName);
|
||||||
if (fileName.contains(PATH_SEPARATOR) ||
|
if (fileName.contains(PATH_SEPARATOR) ||
|
||||||
fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
|
fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
|
||||||
fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") ||
|
fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") ||
|
||||||
@ -65,7 +65,7 @@ public class FileUtils {
|
|||||||
public static boolean isValidPath(String path) {
|
public static boolean isValidPath(String path) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
Log.d("FileUtils", "path ....... " + path);
|
Log_OC.d("FileUtils", "path ....... " + path);
|
||||||
if (path.contains("\\") || path.contains("<") || path.contains(">") ||
|
if (path.contains("\\") || path.contains("<") || path.contains(">") ||
|
||||||
path.contains(":") || path.contains("\"") || path.contains("|") ||
|
path.contains(":") || path.contains("\"") || path.contains("|") ||
|
||||||
path.contains("?") || path.contains("*")) {
|
path.contains("?") || path.contains("*")) {
|
||||||
|
@ -0,0 +1,213 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2014 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.files;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.jackrabbit.webdav.DavException;
|
||||||
|
import org.apache.jackrabbit.webdav.MultiStatusResponse;
|
||||||
|
import org.apache.jackrabbit.webdav.Status;
|
||||||
|
import org.apache.jackrabbit.webdav.client.methods.MoveMethod;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||||
|
* in the same account.
|
||||||
|
*
|
||||||
|
* Allows renaming the moving file/folder at the same time.
|
||||||
|
*
|
||||||
|
* @author David A. Velasco
|
||||||
|
*/
|
||||||
|
public class MoveRemoteFileOperation extends RemoteOperation {
|
||||||
|
|
||||||
|
private static final String TAG = MoveRemoteFileOperation.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final int MOVE_READ_TIMEOUT = 600000;
|
||||||
|
private static final int MOVE_CONNECTION_TIMEOUT = 5000;
|
||||||
|
|
||||||
|
private String mSrcRemotePath;
|
||||||
|
private String mTargetRemotePath;
|
||||||
|
|
||||||
|
private boolean mOverwrite;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* TODO Paths should finish in "/" in the case of folders. ?
|
||||||
|
*
|
||||||
|
* @param srcRemotePath Remote path of the file/folder to move.
|
||||||
|
* @param targetRemotePath Remove path desired for the file/folder after moving it.
|
||||||
|
*/
|
||||||
|
public MoveRemoteFileOperation(
|
||||||
|
String srcRemotePath, String targetRemotePath, boolean overwrite
|
||||||
|
) {
|
||||||
|
|
||||||
|
mSrcRemotePath = srcRemotePath;
|
||||||
|
mTargetRemotePath = targetRemotePath;
|
||||||
|
mOverwrite = overwrite;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the rename operation.
|
||||||
|
*
|
||||||
|
* @param client Client object to communicate with the remote ownCloud server.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
|
|
||||||
|
/// check parameters
|
||||||
|
if (!FileUtils.isValidPath(mTargetRemotePath)) {
|
||||||
|
return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
||||||
|
// nothing to do!
|
||||||
|
return new RemoteOperationResult(ResultCode.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
||||||
|
return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// perform remote operation
|
||||||
|
//LocalMoveMethod move = null;
|
||||||
|
MoveMethod move = null;
|
||||||
|
RemoteOperationResult result = null;
|
||||||
|
try {
|
||||||
|
move = new MoveMethod(
|
||||||
|
client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath),
|
||||||
|
client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||||
|
mOverwrite
|
||||||
|
);
|
||||||
|
int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT);
|
||||||
|
|
||||||
|
/// process response
|
||||||
|
if (status == HttpStatus.SC_MULTI_STATUS) {
|
||||||
|
result = processPartialError(move);
|
||||||
|
|
||||||
|
} else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) {
|
||||||
|
|
||||||
|
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||||
|
client.exhaustResponse(move.getResponseBodyAsStream());
|
||||||
|
|
||||||
|
|
||||||
|
/// for other errors that could be explicitly handled, check first:
|
||||||
|
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
result = new RemoteOperationResult(
|
||||||
|
isSuccess(status), // move.succeeded()? trustful?
|
||||||
|
status,
|
||||||
|
move.getResponseHeaders()
|
||||||
|
);
|
||||||
|
client.exhaustResponse(move.getResponseBodyAsStream());
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
||||||
|
result.getLogMessage());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
result = new RemoteOperationResult(e);
|
||||||
|
Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
||||||
|
result.getLogMessage(), e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (move != null)
|
||||||
|
move.releaseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes a multistatus response from the OC server to generate an appropriate result.
|
||||||
|
*
|
||||||
|
* In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some
|
||||||
|
* children are moved, some other aren't.
|
||||||
|
*
|
||||||
|
* According to the WebDAV specification, a multistatus response SHOULD NOT include partial
|
||||||
|
* successes (201, 204) nor for descendants of already failed children (424) in the response
|
||||||
|
* entity. But SHOULD NOT != MUST NOT, so take carefully.
|
||||||
|
*
|
||||||
|
* @param move Move operation just finished with a multistatus response
|
||||||
|
* @return A result for the {@link MoveRemoteFileOperation} caller
|
||||||
|
*
|
||||||
|
* @throws IOException If the response body could not be parsed
|
||||||
|
* @throws DavException If the status code is other than MultiStatus or if obtaining
|
||||||
|
* the response XML document fails
|
||||||
|
*/
|
||||||
|
private RemoteOperationResult processPartialError(MoveMethod move)
|
||||||
|
throws IOException, DavException {
|
||||||
|
// Adding a list of failed descendants to the result could be interesting; or maybe not.
|
||||||
|
// For the moment, let's take the easy way.
|
||||||
|
|
||||||
|
/// check that some error really occurred
|
||||||
|
MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses();
|
||||||
|
Status[] status = null;
|
||||||
|
boolean failFound = false;
|
||||||
|
for (int i = 0; i < responses.length && !failFound; i++ ) {
|
||||||
|
status = responses[i].getStatus();
|
||||||
|
failFound = (
|
||||||
|
status != null &&
|
||||||
|
status.length > 0 &&
|
||||||
|
status[0].getStatusCode() > 299
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteOperationResult result;
|
||||||
|
if (failFound) {
|
||||||
|
result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE);
|
||||||
|
} else {
|
||||||
|
result = new RemoteOperationResult(
|
||||||
|
true,
|
||||||
|
HttpStatus.SC_MULTI_STATUS,
|
||||||
|
move.getResponseHeaders()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean isSuccess(int status) {
|
||||||
|
return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -30,13 +30,12 @@ import org.apache.jackrabbit.webdav.DavConstants;
|
|||||||
import org.apache.jackrabbit.webdav.MultiStatus;
|
import org.apache.jackrabbit.webdav.MultiStatus;
|
||||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.WebdavEntry;
|
import com.owncloud.android.lib.common.network.WebdavEntry;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +48,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|||||||
public class ReadRemoteFileOperation extends RemoteOperation {
|
public class ReadRemoteFileOperation extends RemoteOperation {
|
||||||
|
|
||||||
private static final String TAG = ReadRemoteFileOperation.class.getSimpleName();
|
private static final String TAG = ReadRemoteFileOperation.class.getSimpleName();
|
||||||
private static final int SYNC_READ_TIMEOUT = 10000;
|
private static final int SYNC_READ_TIMEOUT = 40000;
|
||||||
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
|
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
|
||||||
|
|
||||||
private String mRemotePath;
|
private String mRemotePath;
|
||||||
@ -82,8 +81,11 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
|||||||
int status;
|
int status;
|
||||||
status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
|
status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
|
||||||
|
|
||||||
boolean isMultiStatus = status == HttpStatus.SC_MULTI_STATUS;
|
boolean isSuccess = (
|
||||||
if (isMultiStatus) {
|
status == HttpStatus.SC_MULTI_STATUS ||
|
||||||
|
status == HttpStatus.SC_OK
|
||||||
|
);
|
||||||
|
if (isSuccess) {
|
||||||
// Parse response
|
// Parse response
|
||||||
MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
|
MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
|
||||||
WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getWebdavUri().getPath());
|
WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getWebdavUri().getPath());
|
||||||
@ -103,7 +105,7 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(), result.getException());
|
Log_OC.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(), result.getException());
|
||||||
} finally {
|
} finally {
|
||||||
if (propfind != null)
|
if (propfind != null)
|
||||||
propfind.releaseConnection();
|
propfind.releaseConnection();
|
||||||
|
@ -31,13 +31,12 @@ import org.apache.jackrabbit.webdav.DavConstants;
|
|||||||
import org.apache.jackrabbit.webdav.MultiStatus;
|
import org.apache.jackrabbit.webdav.MultiStatus;
|
||||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.WebdavEntry;
|
import com.owncloud.android.lib.common.network.WebdavEntry;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the read of remote file or folder in the ownCloud server.
|
* Remote operation performing the read of remote file or folder in the ownCloud server.
|
||||||
@ -80,7 +79,11 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
int status = client.executeMethod(query);
|
int status = client.executeMethod(query);
|
||||||
|
|
||||||
// check and process response
|
// check and process response
|
||||||
if (isMultiStatus(status)) {
|
boolean isSuccess = (
|
||||||
|
status == HttpStatus.SC_MULTI_STATUS ||
|
||||||
|
status == HttpStatus.SC_OK
|
||||||
|
);
|
||||||
|
if (isSuccess) {
|
||||||
// get data from remote folder
|
// get data from remote folder
|
||||||
MultiStatus dataInServer = query.getResponseBodyAsMultiStatus();
|
MultiStatus dataInServer = query.getResponseBodyAsMultiStatus();
|
||||||
readData(dataInServer, client);
|
readData(dataInServer, client);
|
||||||
@ -105,12 +108,12 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
if (query != null)
|
if (query != null)
|
||||||
query.releaseConnection(); // let the connection available for other methods
|
query.releaseConnection(); // let the connection available for other methods
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
Log.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
||||||
} else {
|
} else {
|
||||||
if (result.isException()) {
|
if (result.isException()) {
|
||||||
Log.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), result.getException());
|
Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), result.getException());
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,12 +27,11 @@ package com.owncloud.android.lib.resources.files;
|
|||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the removal of a remote file or folder in the ownCloud server.
|
* Remote operation performing the removal of a remote file or folder in the ownCloud server.
|
||||||
@ -73,11 +72,11 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
delete.getResponseBodyAsString(); // exhaust the response, although not interesting
|
delete.getResponseBodyAsString(); // exhaust the response, although not interesting
|
||||||
result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders());
|
result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders());
|
||||||
Log.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage());
|
Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (delete != null)
|
if (delete != null)
|
||||||
|
@ -28,13 +28,12 @@ import java.io.File;
|
|||||||
|
|
||||||
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
|
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +46,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
private static final String TAG = RenameRemoteFileOperation.class.getSimpleName();
|
private static final String TAG = RenameRemoteFileOperation.class.getSimpleName();
|
||||||
|
|
||||||
private static final int RENAME_READ_TIMEOUT = 10000;
|
private static final int RENAME_READ_TIMEOUT = 600000;
|
||||||
private static final int RENAME_CONNECTION_TIMEOUT = 5000;
|
private static final int RENAME_CONNECTION_TIMEOUT = 5000;
|
||||||
|
|
||||||
private String mOldName;
|
private String mOldName;
|
||||||
@ -109,11 +108,11 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
move.getResponseBodyAsString(); // exhaust response, although not interesting
|
move.getResponseBodyAsString(); // exhaust response, although not interesting
|
||||||
result = new RemoteOperationResult(move.succeeded(), status, move.getResponseHeaders());
|
result = new RemoteOperationResult(move.succeeded(), status, move.getResponseHeaders());
|
||||||
Log.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + result.getLogMessage());
|
Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + result.getLogMessage());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Rename " + mOldRemotePath + " to " + ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " + ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + result.getLogMessage(), e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (move != null)
|
if (move != null)
|
||||||
|
@ -31,12 +31,11 @@ import java.util.ArrayList;
|
|||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new share. This allows sharing with a user or group or as a link.
|
* Creates a new share. This allows sharing with a user or group or as a link.
|
||||||
@ -103,7 +102,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
try {
|
try {
|
||||||
// Post Method
|
// Post Method
|
||||||
post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
||||||
//Log.d(TAG, "URL ------> " + client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
//Log_OC.d(TAG, "URL ------> " + client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
||||||
|
|
||||||
post.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
|
post.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
|
||||||
post.addParameter(PARAM_PATH, mRemoteFilePath);
|
post.addParameter(PARAM_PATH, mRemoteFilePath);
|
||||||
@ -131,7 +130,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
mShares = xmlParser.parseXMLResponse(is);
|
mShares = xmlParser.parseXMLResponse(is);
|
||||||
if (xmlParser.isSuccess()) {
|
if (xmlParser.isSuccess()) {
|
||||||
if (mShares != null) {
|
if (mShares != null) {
|
||||||
Log.d(TAG, "Created " + mShares.size() + " share(s)");
|
Log_OC.d(TAG, "Created " + mShares.size() + " share(s)");
|
||||||
result = new RemoteOperationResult(ResultCode.OK);
|
result = new RemoteOperationResult(ResultCode.OK);
|
||||||
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
||||||
for (OCShare share: mShares) {
|
for (OCShare share: mShares) {
|
||||||
@ -142,6 +141,9 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
} else if (xmlParser.isFileNotFound()){
|
} else if (xmlParser.isFileNotFound()){
|
||||||
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
|
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
|
||||||
|
|
||||||
|
} else if (xmlParser.isFailure()) {
|
||||||
|
result = new RemoteOperationResult(ResultCode.SHARE_FORBIDDEN);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(false, status, post.getResponseHeaders());
|
result = new RemoteOperationResult(false, status, post.getResponseHeaders());
|
||||||
}
|
}
|
||||||
@ -152,7 +154,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Exception while Creating New Share", e);
|
Log_OC.e(TAG, "Exception while Creating New Share", e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (post != null) {
|
if (post != null) {
|
||||||
|
@ -32,12 +32,11 @@ import org.apache.commons.httpclient.NameValuePair;
|
|||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a list shares for a specific file.
|
* Provide a list shares for a specific file.
|
||||||
@ -110,7 +109,7 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
|||||||
ShareXMLParser xmlParser = new ShareXMLParser();
|
ShareXMLParser xmlParser = new ShareXMLParser();
|
||||||
mShares = xmlParser.parseXMLResponse(is);
|
mShares = xmlParser.parseXMLResponse(is);
|
||||||
if (mShares != null) {
|
if (mShares != null) {
|
||||||
Log.d(TAG, "Got " + mShares.size() + " shares");
|
Log_OC.d(TAG, "Got " + mShares.size() + " shares");
|
||||||
result = new RemoteOperationResult(ResultCode.OK);
|
result = new RemoteOperationResult(ResultCode.OK);
|
||||||
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
||||||
for (OCShare share: mShares) {
|
for (OCShare share: mShares) {
|
||||||
@ -129,7 +128,7 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Exception while getting shares", e);
|
Log_OC.e(TAG, "Exception while getting shares", e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (get != null) {
|
if (get != null) {
|
||||||
|
@ -35,8 +35,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +77,7 @@ public class GetRemoteSharesOperation extends RemoteOperation {
|
|||||||
ShareXMLParser xmlParser = new ShareXMLParser();
|
ShareXMLParser xmlParser = new ShareXMLParser();
|
||||||
mShares = xmlParser.parseXMLResponse(is);
|
mShares = xmlParser.parseXMLResponse(is);
|
||||||
if (mShares != null) {
|
if (mShares != null) {
|
||||||
Log.d(TAG, "Got " + mShares.size() + " shares");
|
Log_OC.d(TAG, "Got " + mShares.size() + " shares");
|
||||||
result = new RemoteOperationResult(ResultCode.OK);
|
result = new RemoteOperationResult(ResultCode.OK);
|
||||||
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
||||||
for (OCShare share: mShares) {
|
for (OCShare share: mShares) {
|
||||||
@ -92,7 +91,7 @@ public class GetRemoteSharesOperation extends RemoteOperation {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Exception while getting remote shares ", e);
|
Log_OC.e(TAG, "Exception while getting remote shares ", e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (get != null) {
|
if (get != null) {
|
||||||
|
@ -26,11 +26,11 @@ package com.owncloud.android.lib.resources.shares;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +70,7 @@ public class OCShare implements Parcelable, Serializable {
|
|||||||
public OCShare(String path) {
|
public OCShare(String path) {
|
||||||
resetData();
|
resetData();
|
||||||
if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
|
if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
|
||||||
Log.e(TAG, "Trying to create a OCShare with a non valid path");
|
Log_OC.e(TAG, "Trying to create a OCShare with a non valid path");
|
||||||
throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path);
|
throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path);
|
||||||
}
|
}
|
||||||
mPath = path;
|
mPath = path;
|
||||||
|
@ -30,12 +30,11 @@ import java.io.InputStream;
|
|||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a share
|
* Remove a share
|
||||||
@ -94,13 +93,13 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
|
|||||||
result = new RemoteOperationResult(false, status, delete.getResponseHeaders());
|
result = new RemoteOperationResult(false, status, delete.getResponseHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Unshare " + id + ": " + result.getLogMessage());
|
Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage());
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(false, status, delete.getResponseHeaders());
|
result = new RemoteOperationResult(false, status, delete.getResponseHeaders());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (delete != null)
|
if (delete != null)
|
||||||
|
@ -182,7 +182,7 @@ public class ShareXMLParser {
|
|||||||
*/
|
*/
|
||||||
private void readMeta(XmlPullParser parser) throws XmlPullParserException, IOException {
|
private void readMeta(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||||
parser.require(XmlPullParser.START_TAG, ns, NODE_META);
|
parser.require(XmlPullParser.START_TAG, ns, NODE_META);
|
||||||
//Log.d(TAG, "---- NODE META ---");
|
//Log_OC.d(TAG, "---- NODE META ---");
|
||||||
while (parser.next() != XmlPullParser.END_TAG) {
|
while (parser.next() != XmlPullParser.END_TAG) {
|
||||||
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||||
continue;
|
continue;
|
||||||
@ -214,7 +214,7 @@ public class ShareXMLParser {
|
|||||||
OCShare share = null;
|
OCShare share = null;
|
||||||
|
|
||||||
parser.require(XmlPullParser.START_TAG, ns, NODE_DATA);
|
parser.require(XmlPullParser.START_TAG, ns, NODE_DATA);
|
||||||
//Log.d(TAG, "---- NODE DATA ---");
|
//Log_OC.d(TAG, "---- NODE DATA ---");
|
||||||
while (parser.next() != XmlPullParser.END_TAG) {
|
while (parser.next() != XmlPullParser.END_TAG) {
|
||||||
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||||
continue;
|
continue;
|
||||||
@ -264,7 +264,7 @@ public class ShareXMLParser {
|
|||||||
|
|
||||||
OCShare share = new OCShare();
|
OCShare share = new OCShare();
|
||||||
|
|
||||||
//Log.d(TAG, "---- NODE ELEMENT ---");
|
//Log_OC.d(TAG, "---- NODE ELEMENT ---");
|
||||||
while (parser.next() != XmlPullParser.END_TAG) {
|
while (parser.next() != XmlPullParser.END_TAG) {
|
||||||
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||||
continue;
|
continue;
|
||||||
@ -360,7 +360,7 @@ public class ShareXMLParser {
|
|||||||
private String readNode (XmlPullParser parser, String node) throws XmlPullParserException, IOException{
|
private String readNode (XmlPullParser parser, String node) throws XmlPullParserException, IOException{
|
||||||
parser.require(XmlPullParser.START_TAG, ns, node);
|
parser.require(XmlPullParser.START_TAG, ns, node);
|
||||||
String value = readText(parser);
|
String value = readText(parser);
|
||||||
//Log.d(TAG, "node= " + node + ", value= " + value);
|
//Log_OC.d(TAG, "node= " + node + ", value= " + value);
|
||||||
parser.require(XmlPullParser.END_TAG, ns, node);
|
parser.require(XmlPullParser.END_TAG, ns, node);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -31,15 +31,15 @@ import org.apache.commons.httpclient.methods.GetMethod;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the server is valid and if the server supports the Share API
|
* Checks if the server is valid and if the server supports the Share API
|
||||||
@ -51,7 +51,10 @@ import android.util.Log;
|
|||||||
|
|
||||||
public class GetRemoteStatusOperation extends RemoteOperation {
|
public class GetRemoteStatusOperation extends RemoteOperation {
|
||||||
|
|
||||||
/** Maximum time to wait for a response from the server when the connection is being tested, in MILLISECONDs. */
|
/**
|
||||||
|
* Maximum time to wait for a response from the server when the connection is being tested,
|
||||||
|
* in MILLISECONDs.
|
||||||
|
*/
|
||||||
public static final int TRY_CONNECTION_TIMEOUT = 5000;
|
public static final int TRY_CONNECTION_TIMEOUT = 5000;
|
||||||
|
|
||||||
private static final String TAG = GetRemoteStatusOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteStatusOperation.class.getSimpleName();
|
||||||
@ -72,7 +75,37 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
String baseUrlSt = client.getBaseUri().toString();
|
String baseUrlSt = client.getBaseUri().toString();
|
||||||
try {
|
try {
|
||||||
get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
|
get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
|
||||||
|
|
||||||
|
client.setFollowRedirects(false);
|
||||||
|
boolean isRedirectToNonSecureConnection = false;
|
||||||
int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
|
int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
|
||||||
|
mLatestResult = new RemoteOperationResult(
|
||||||
|
(status == HttpStatus.SC_OK),
|
||||||
|
status,
|
||||||
|
get.getResponseHeaders()
|
||||||
|
);
|
||||||
|
|
||||||
|
String redirectedLocation = mLatestResult.getRedirectedLocation();
|
||||||
|
while (redirectedLocation != null && redirectedLocation.length() > 0
|
||||||
|
&& !mLatestResult.isSuccess()) {
|
||||||
|
|
||||||
|
isRedirectToNonSecureConnection |= (
|
||||||
|
baseUrlSt.startsWith("https://") &&
|
||||||
|
redirectedLocation.startsWith("http://")
|
||||||
|
);
|
||||||
|
get.releaseConnection();
|
||||||
|
get = new GetMethod(redirectedLocation);
|
||||||
|
status = client.executeMethod(
|
||||||
|
get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT
|
||||||
|
);
|
||||||
|
mLatestResult = new RemoteOperationResult(
|
||||||
|
(status == HttpStatus.SC_OK),
|
||||||
|
status,
|
||||||
|
get.getResponseHeaders()
|
||||||
|
);
|
||||||
|
redirectedLocation = mLatestResult.getRedirectedLocation();
|
||||||
|
}
|
||||||
|
|
||||||
String response = get.getResponseBodyAsString();
|
String response = get.getResponseBodyAsString();
|
||||||
if (status == HttpStatus.SC_OK) {
|
if (status == HttpStatus.SC_OK) {
|
||||||
JSONObject json = new JSONObject(response);
|
JSONObject json = new JSONObject(response);
|
||||||
@ -87,16 +120,24 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
RemoteOperationResult.ResultCode.BAD_OC_VERSION);
|
RemoteOperationResult.ResultCode.BAD_OC_VERSION);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mLatestResult = new RemoteOperationResult(
|
// success
|
||||||
baseUrlSt.startsWith("https://") ?
|
if (isRedirectToNonSecureConnection) {
|
||||||
RemoteOperationResult.ResultCode.OK_SSL :
|
mLatestResult = new RemoteOperationResult(
|
||||||
RemoteOperationResult.ResultCode.OK_NO_SSL
|
RemoteOperationResult.ResultCode.
|
||||||
);
|
OK_REDIRECT_TO_NON_SECURE_CONNECTION
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
mLatestResult = new RemoteOperationResult(
|
||||||
|
baseUrlSt.startsWith("https://") ?
|
||||||
|
RemoteOperationResult.ResultCode.OK_SSL :
|
||||||
|
RemoteOperationResult.ResultCode.OK_NO_SSL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<Object> data = new ArrayList<Object>();
|
ArrayList<Object> data = new ArrayList<Object>();
|
||||||
data.add(ocVersion);
|
data.add(ocVersion);
|
||||||
mLatestResult.setData(data);
|
mLatestResult.setData(data);
|
||||||
retval = true;
|
retval = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,13 +158,14 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mLatestResult.isSuccess()) {
|
if (mLatestResult.isSuccess()) {
|
||||||
Log.i(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage());
|
Log_OC.i(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage());
|
||||||
|
|
||||||
} else if (mLatestResult.getException() != null) {
|
} else if (mLatestResult.getException() != null) {
|
||||||
Log.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(), mLatestResult.getException());
|
Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(),
|
||||||
|
mLatestResult.getException());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage());
|
Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
@ -148,8 +190,8 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
} else {
|
} else {
|
||||||
client.setBaseUri(Uri.parse("https://" + baseUriStr));
|
client.setBaseUri(Uri.parse("https://" + baseUriStr));
|
||||||
boolean httpsSuccess = tryConnection(client);
|
boolean httpsSuccess = tryConnection(client);
|
||||||
if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) {
|
if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) {
|
||||||
Log.d(TAG, "establishing secure connection failed, trying non secure connection");
|
Log_OC.d(TAG, "establishing secure connection failed, trying non secure connection");
|
||||||
client.setBaseUri(Uri.parse("http://" + baseUriStr));
|
client.setBaseUri(Uri.parse("http://" + baseUriStr));
|
||||||
tryConnection(client);
|
tryConnection(client);
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,10 @@ import org.apache.commons.httpclient.methods.GetMethod;
|
|||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +82,7 @@ public class GetRemoteUserNameOperation extends RemoteOperation {
|
|||||||
status = client.executeMethod(get);
|
status = client.executeMethod(get);
|
||||||
if(isSuccess(status)) {
|
if(isSuccess(status)) {
|
||||||
String response = get.getResponseBodyAsString();
|
String response = get.getResponseBodyAsString();
|
||||||
Log.d(TAG, "Successful response: " + response);
|
Log_OC.d(TAG, "Successful response: " + response);
|
||||||
|
|
||||||
// Parse the response
|
// Parse the response
|
||||||
JSONObject respJSON = new JSONObject(response);
|
JSONObject respJSON = new JSONObject(response);
|
||||||
@ -101,21 +100,21 @@ public class GetRemoteUserNameOperation extends RemoteOperation {
|
|||||||
result.setData(data);
|
result.setData(data);
|
||||||
mUserName = displayName;
|
mUserName = displayName;
|
||||||
|
|
||||||
Log.d(TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email);
|
Log_OC.d(TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
|
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
|
||||||
String response = get.getResponseBodyAsString();
|
String response = get.getResponseBodyAsString();
|
||||||
Log.e(TAG, "Failed response while getting user information ");
|
Log_OC.e(TAG, "Failed response while getting user information ");
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
Log.e(TAG, "*** status code: " + status + " ; response message: " + response);
|
Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "*** status code: " + status);
|
Log_OC.e(TAG, "*** status code: " + status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log.e(TAG, "Exception while getting OC user information", e);
|
Log_OC.e(TAG, "Exception while getting OC user information", e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
get.releaseConnection();
|
get.releaseConnection();
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<string name="server_base_url"></string> <!-- the server url, without webdav path -->
|
<string name="server_base_url"></string>
|
||||||
<string name="webdav_path">/remote.php/webdav</string> <!-- default value for webdav path (owncloud version > = 4)-->
|
|
||||||
<string name="username"></string>
|
<string name="username"></string>
|
||||||
<string name="password"></string>
|
<string name="password"></string>
|
||||||
<bool name="chunked">true</bool>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -33,16 +33,24 @@ import java.security.GeneralSecurityException;
|
|||||||
import org.apache.commons.httpclient.protocol.Protocol;
|
import org.apache.commons.httpclient.protocol.Protocol;
|
||||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
||||||
import com.owncloud.android.lib.resources.files.RemoteFile;
|
|
||||||
import com.owncloud.android.lib.common.network.NetworkUtils;
|
import com.owncloud.android.lib.common.network.NetworkUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.resources.files.ChunkedUploadRemoteFileOperation;
|
import com.owncloud.android.lib.resources.files.ChunkedUploadRemoteFileOperation;
|
||||||
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
|
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
|
||||||
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
|
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
|
||||||
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
|
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
|
||||||
|
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||||
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
|
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
|
||||||
import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
|
import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
|
||||||
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
|
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
|
||||||
@ -50,14 +58,6 @@ import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
|
|||||||
import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
|
import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
|
||||||
import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation;
|
import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation;
|
||||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||||
import com.owncloud.android.lib.test_project.R;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity to test OC framework
|
* Activity to test OC framework
|
||||||
@ -72,7 +72,6 @@ public class TestActivity extends Activity {
|
|||||||
private String mServerUri;
|
private String mServerUri;
|
||||||
private String mUser;
|
private String mUser;
|
||||||
private String mPass;
|
private String mPass;
|
||||||
private boolean mChunked;
|
|
||||||
|
|
||||||
private static final int BUFFER_SIZE = 1024;
|
private static final int BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
@ -91,7 +90,6 @@ public class TestActivity extends Activity {
|
|||||||
mServerUri = getString(R.string.server_base_url);
|
mServerUri = getString(R.string.server_base_url);
|
||||||
mUser = getString(R.string.username);
|
mUser = getString(R.string.username);
|
||||||
mPass = getString(R.string.password);
|
mPass = getString(R.string.password);
|
||||||
mChunked = getResources().getBoolean(R.bool.chunked);
|
|
||||||
|
|
||||||
Protocol pr = Protocol.getProtocol("https");
|
Protocol pr = Protocol.getProtocol("https");
|
||||||
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
|
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
|
||||||
@ -133,14 +131,32 @@ public class TestActivity extends Activity {
|
|||||||
/**
|
/**
|
||||||
* Access to the library method to Create a Folder
|
* Access to the library method to Create a Folder
|
||||||
* @param remotePath Full path to the new directory to create in the remote server.
|
* @param remotePath Full path to the new directory to create in the remote server.
|
||||||
* @param createFullPath 'True' means that all the ancestor folders should be created if don't exist yet.
|
* @param createFullPath 'True' means that all the ancestor folders should be created if
|
||||||
|
* don't exist yet.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
|
public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
|
||||||
|
|
||||||
CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
|
return TestActivity.createFolder(remotePath, createFullPath, mClient);
|
||||||
RemoteOperationResult result = createOperation.execute(mClient);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access to the library method to Create a Folder
|
||||||
|
* @param remotePath Full path to the new directory to create in the remote server.
|
||||||
|
* @param createFullPath 'True' means that all the ancestor folders should be created if
|
||||||
|
* don't exist yet.
|
||||||
|
* @param client Client instance configured to access the target OC server.
|
||||||
|
*
|
||||||
|
* @return Result of the operation
|
||||||
|
*/
|
||||||
|
public static RemoteOperationResult createFolder(
|
||||||
|
String remotePath, boolean createFullPath, OwnCloudClient client
|
||||||
|
) {
|
||||||
|
|
||||||
|
CreateRemoteFolderOperation createOperation =
|
||||||
|
new CreateRemoteFolderOperation(remotePath, createFullPath);
|
||||||
|
RemoteOperationResult result = createOperation.execute(client);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -170,13 +186,24 @@ public class TestActivity extends Activity {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RemoteOperationResult removeFile(String remotePath) {
|
public RemoteOperationResult removeFile(String remotePath) {
|
||||||
|
|
||||||
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||||
RemoteOperationResult result = removeOperation.execute(mClient);
|
RemoteOperationResult result = removeOperation.execute(mClient);
|
||||||
|
return TestActivity.removeFile(remotePath, mClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access to the library method to Remove a File or Folder
|
||||||
|
*
|
||||||
|
* @param remotePath Remote path of the file or folder in the server.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) {
|
||||||
|
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||||
|
RemoteOperationResult result = removeOperation.execute(client);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access to the library method to Read a Folder (PROPFIND DEPTH 1)
|
* Access to the library method to Read a Folder (PROPFIND DEPTH 1)
|
||||||
* @param remotePath
|
* @param remotePath
|
||||||
@ -217,21 +244,39 @@ public class TestActivity extends Activity {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RemoteOperationResult uploadFile(String storagePath, String remotePath, String mimeType) {
|
public RemoteOperationResult uploadFile(
|
||||||
|
String storagePath, String remotePath, String mimeType
|
||||||
UploadRemoteFileOperation uploadOperation;
|
) {
|
||||||
if ( mChunked && (new File(storagePath)).length() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE ) {
|
return TestActivity.uploadFile(storagePath, remotePath, mimeType, mClient);
|
||||||
uploadOperation = new ChunkedUploadRemoteFileOperation(storagePath, remotePath, mimeType);
|
|
||||||
} else {
|
|
||||||
uploadOperation = new UploadRemoteFileOperation(storagePath, remotePath, mimeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoteOperationResult result = uploadOperation.execute(mClient);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Access to the library method to Upload a File
|
||||||
|
* @param storagePath
|
||||||
|
* @param remotePath
|
||||||
|
* @param mimeType
|
||||||
|
* @param client Client instance configured to access the target OC server.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static RemoteOperationResult uploadFile(
|
||||||
|
String storagePath, String remotePath, String mimeType, OwnCloudClient client
|
||||||
|
) {
|
||||||
|
UploadRemoteFileOperation uploadOperation;
|
||||||
|
if ((new File(storagePath)).length() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE ) {
|
||||||
|
uploadOperation = new ChunkedUploadRemoteFileOperation(
|
||||||
|
storagePath, remotePath, mimeType
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
uploadOperation = new UploadRemoteFileOperation(
|
||||||
|
storagePath, remotePath, mimeType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteOperationResult result = uploadOperation.execute(client);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/** Access to the library method to Get Shares
|
/** Access to the library method to Get Shares
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
@ -295,11 +340,22 @@ public class TestActivity extends Activity {
|
|||||||
* @return File instance of the extracted file.
|
* @return File instance of the extracted file.
|
||||||
*/
|
*/
|
||||||
public File extractAsset(String fileName) throws IOException {
|
public File extractAsset(String fileName) throws IOException {
|
||||||
File extractedFile = new File(getCacheDir() + File.separator + fileName);
|
return TestActivity.extractAsset(fileName, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts file from AssetManager to cache folder.
|
||||||
|
*
|
||||||
|
* @param fileName Name of the asset file to extract.
|
||||||
|
* @param context Android context to access assets and file system.
|
||||||
|
* @return File instance of the extracted file.
|
||||||
|
*/
|
||||||
|
public static File extractAsset(String fileName, Context context) throws IOException {
|
||||||
|
File extractedFile = new File(context.getCacheDir() + File.separator + fileName);
|
||||||
if (!extractedFile.exists()) {
|
if (!extractedFile.exists()) {
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
FileOutputStream out = null;
|
FileOutputStream out = null;
|
||||||
in = getAssets().open(fileName);
|
in = context.getAssets().open(fileName);
|
||||||
out = new FileOutputStream(extractedFile);
|
out = new FileOutputStream(extractedFile);
|
||||||
byte[] buffer = new byte[BUFFER_SIZE];
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
int readCount;
|
int readCount;
|
||||||
@ -312,7 +368,6 @@ public class TestActivity extends Activity {
|
|||||||
}
|
}
|
||||||
return extractedFile;
|
return extractedFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,459 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2014 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.test_project.test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
import junit.framework.AssertionFailedError;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.httpclient.protocol.Protocol;
|
||||||
|
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
||||||
|
import com.owncloud.android.lib.common.network.NetworkUtils;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation;
|
||||||
|
import com.owncloud.android.lib.test_project.R;
|
||||||
|
import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory;
|
||||||
|
import com.owncloud.android.lib.test_project.TestActivity;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
//import android.test.AndroidTestCase;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to test MoveRemoteFileOperation
|
||||||
|
*
|
||||||
|
* With this TestCase we are experimenting a bit to improve the test suite design, in two aspects:
|
||||||
|
*
|
||||||
|
* - Reduce the dependency from the set of test cases on the "test project" needed to
|
||||||
|
* have an instrumented APK to install in the device, as required by the testing framework
|
||||||
|
* provided by Android. To get there, this class avoids calling TestActivity methods in the test
|
||||||
|
* method.
|
||||||
|
*
|
||||||
|
* - Reduce the impact of creating a remote fixture over the Internet, while the structure of the
|
||||||
|
* TestCase is kept easy to maintain. To get this, all the tests are done in a single test method,
|
||||||
|
* granting this way that setUp and tearDown are run only once.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author David A. Velasco
|
||||||
|
*/
|
||||||
|
|
||||||
|
//public class MoveFileTest extends AndroidTestCase {
|
||||||
|
public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||||
|
|
||||||
|
private static final String LOG_TAG = MoveFileTest.class.getCanonicalName();
|
||||||
|
|
||||||
|
|
||||||
|
/// Paths to files and folders in fixture
|
||||||
|
|
||||||
|
private static final String SRC_BASE_FOLDER = "/src/";
|
||||||
|
private static final String TARGET_BASE_FOLDER = "/target/";
|
||||||
|
private static final String NO_FILE = "nofile.txt";
|
||||||
|
private static final String FILE1 = "file1.txt";
|
||||||
|
private static final String FILE2 = "file2.txt";
|
||||||
|
private static final String FILE3 = "file3.txt";
|
||||||
|
private static final String FILE4 = "file4.txt";
|
||||||
|
private static final String FILE5 = "file5.txt";
|
||||||
|
private static final String FILE6 = "file6.txt";
|
||||||
|
private static final String FILE7 = "file7.txt";
|
||||||
|
private static final String EMPTY = "empty/";
|
||||||
|
private static final String NO_FOLDER = "nofolder/";
|
||||||
|
private static final String FOLDER1 = "folder1/";
|
||||||
|
private static final String FOLDER2 = "folder2/";
|
||||||
|
private static final String FOLDER3 = "folder3/";
|
||||||
|
private static final String FOLDER4 = "folder4/";
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FILE_1 = SRC_BASE_FOLDER + FILE1;
|
||||||
|
private static final String TARGET_PATH_TO_FILE_1 = TARGET_BASE_FOLDER + FILE1;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FILE_2 = SRC_BASE_FOLDER + FILE2;
|
||||||
|
private static final String TARGET_PATH_TO_FILE_2_RENAMED =
|
||||||
|
TARGET_BASE_FOLDER + "renamed_" + FILE2;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FILE_3 = SRC_BASE_FOLDER + FILE3;
|
||||||
|
private static final String SRC_PATH_TO_FILE_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FILE3;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FILE_4 = SRC_BASE_FOLDER + FILE4;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FILE_5 = SRC_BASE_FOLDER + FILE5;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FILE_6 = SRC_BASE_FOLDER + FILE6;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FILE_7 = SRC_BASE_FOLDER + FILE7;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_NON_EXISTENT_FILE = SRC_BASE_FOLDER + NO_FILE;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_EMPTY_FOLDER = SRC_BASE_FOLDER + EMPTY;
|
||||||
|
private static final String TARGET_PATH_TO_EMPTY_FOLDER = TARGET_BASE_FOLDER + EMPTY;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FULL_FOLDER_1 = SRC_BASE_FOLDER + FOLDER1;
|
||||||
|
private static final String TARGET_PATH_TO_FULL_FOLDER_1 = TARGET_BASE_FOLDER + FOLDER1;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FULL_FOLDER_2 = SRC_BASE_FOLDER + FOLDER2;
|
||||||
|
|
||||||
|
private static final String TARGET_PATH_TO_FULL_FOLDER_2_RENAMED =
|
||||||
|
TARGET_BASE_FOLDER + "renamed_" + FOLDER2;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FULL_FOLDER_3 = SRC_BASE_FOLDER + FOLDER3;
|
||||||
|
private static final String SRC_PATH_TO_FULL_FOLDER_4 = SRC_BASE_FOLDER + FOLDER4;
|
||||||
|
|
||||||
|
private static final String SRC_PATH_TO_FULL_FOLDER_3_RENAMED =
|
||||||
|
SRC_BASE_FOLDER + "renamed_" + FOLDER3;
|
||||||
|
|
||||||
|
private static final String TARGET_PATH_RENAMED_WITH_INVALID_CHARS =
|
||||||
|
SRC_BASE_FOLDER + "renamed:??_" + FILE6;
|
||||||
|
|
||||||
|
private static final String TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 = TARGET_BASE_FOLDER
|
||||||
|
+ FOLDER4;
|
||||||
|
|
||||||
|
private static final String TARGET_PATH_TO_NON_EXISTENT_FILE = TARGET_BASE_FOLDER + NO_FILE;
|
||||||
|
|
||||||
|
private static final String TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER =
|
||||||
|
TARGET_BASE_FOLDER + NO_FOLDER + FILE5;
|
||||||
|
|
||||||
|
private static final String TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 = TARGET_BASE_FOLDER + FILE7;
|
||||||
|
|
||||||
|
private static final String[] FOLDERS_IN_FIXTURE = {
|
||||||
|
SRC_PATH_TO_EMPTY_FOLDER,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2,
|
||||||
|
|
||||||
|
TARGET_BASE_FOLDER,
|
||||||
|
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final String[] FILES_IN_FIXTURE = {
|
||||||
|
SRC_PATH_TO_FILE_1,
|
||||||
|
SRC_PATH_TO_FILE_2,
|
||||||
|
SRC_PATH_TO_FILE_3,
|
||||||
|
SRC_PATH_TO_FILE_4,
|
||||||
|
SRC_PATH_TO_FILE_5,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2 + FILE2,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2 + FILE2,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2 + FILE2,
|
||||||
|
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE1,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE2,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2 + FILE2,
|
||||||
|
|
||||||
|
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
String mServerUri, mUser, mPass;
|
||||||
|
OwnCloudClient mClient = null;
|
||||||
|
|
||||||
|
public MoveFileTest() {
|
||||||
|
super(TestActivity.class);
|
||||||
|
|
||||||
|
Protocol pr = Protocol.getProtocol("https");
|
||||||
|
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
|
||||||
|
try {
|
||||||
|
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
|
||||||
|
Protocol.registerProtocol(
|
||||||
|
"https",
|
||||||
|
new Protocol("https", psf, 443));
|
||||||
|
|
||||||
|
} catch (GeneralSecurityException e) {
|
||||||
|
throw new AssertionFailedError(
|
||||||
|
"Self-signed confident SSL context could not be loaded");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Context getContext() {
|
||||||
|
return getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
// Next initialization cannot be done in the constructor because getContext() is not
|
||||||
|
// ready yet, returns NULL.
|
||||||
|
initAccessToServer(getContext());
|
||||||
|
|
||||||
|
Log.v(LOG_TAG, "Setting up the remote fixture...");
|
||||||
|
|
||||||
|
RemoteOperationResult result = null;
|
||||||
|
for (String folderPath : FOLDERS_IN_FIXTURE) {
|
||||||
|
result = TestActivity.createFolder(folderPath, true, mClient);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
Utils.logAndThrow(LOG_TAG, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File txtFile = TestActivity.extractAsset(
|
||||||
|
TestActivity.ASSETS__TEXT_FILE_NAME, getContext()
|
||||||
|
);
|
||||||
|
for (String filePath : FILES_IN_FIXTURE) {
|
||||||
|
result = TestActivity.uploadFile(
|
||||||
|
txtFile.getAbsolutePath(), filePath, "txt/plain", mClient
|
||||||
|
);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
Utils.logAndThrow(LOG_TAG, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.v(LOG_TAG, "Remote fixture created.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test move folder
|
||||||
|
*/
|
||||||
|
public void testMoveRemoteFileOperation() {
|
||||||
|
Log.v(LOG_TAG, "testMoveFolder in");
|
||||||
|
|
||||||
|
/// successful cases
|
||||||
|
|
||||||
|
// move file
|
||||||
|
MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FILE_1,
|
||||||
|
TARGET_PATH_TO_FILE_1,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
RemoteOperationResult result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move & rename file, different location
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FILE_2,
|
||||||
|
TARGET_PATH_TO_FILE_2_RENAMED,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move & rename file, same location (rename file)
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FILE_3,
|
||||||
|
SRC_PATH_TO_FILE_3_RENAMED,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move empty folder
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_EMPTY_FOLDER,
|
||||||
|
TARGET_PATH_TO_EMPTY_FOLDER,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move non-empty folder
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_1,
|
||||||
|
TARGET_PATH_TO_FULL_FOLDER_1,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move & rename folder, different location
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_2,
|
||||||
|
TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move & rename folder, same location (rename folder)
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3,
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move for nothing (success, but no interaction with network)
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FILE_4,
|
||||||
|
SRC_PATH_TO_FILE_4,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
// move overwriting
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FULL_FOLDER_4,
|
||||||
|
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
|
||||||
|
/// Failed cases
|
||||||
|
|
||||||
|
// file to move does not exist
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_NON_EXISTENT_FILE,
|
||||||
|
TARGET_PATH_TO_NON_EXISTENT_FILE,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
|
||||||
|
|
||||||
|
// folder to move into does no exist
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FILE_5,
|
||||||
|
TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT);
|
||||||
|
|
||||||
|
// target location (renaming) has invalid characters
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FILE_6,
|
||||||
|
TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||||
|
|
||||||
|
// name collision
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_PATH_TO_FILE_7,
|
||||||
|
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
|
||||||
|
|
||||||
|
// move a folder into a descendant
|
||||||
|
moveOperation = new MoveRemoteFileOperation(
|
||||||
|
SRC_BASE_FOLDER,
|
||||||
|
SRC_PATH_TO_EMPTY_FOLDER,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
result = moveOperation.execute(mClient);
|
||||||
|
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
Log.v(LOG_TAG, "Deleting remote fixture...");
|
||||||
|
|
||||||
|
String[] mPathsToCleanUp = {
|
||||||
|
SRC_BASE_FOLDER,
|
||||||
|
TARGET_BASE_FOLDER
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String path : mPathsToCleanUp) {
|
||||||
|
RemoteOperationResult removeResult =
|
||||||
|
TestActivity.removeFile(path, mClient);
|
||||||
|
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT ) {
|
||||||
|
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.tearDown();
|
||||||
|
|
||||||
|
Log.v(LOG_TAG, "Remote fixture delete.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initAccessToServer(Context context) {
|
||||||
|
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
|
||||||
|
|
||||||
|
mServerUri = context.getString(R.string.server_base_url);
|
||||||
|
mUser = context.getString(R.string.username);
|
||||||
|
mPass = context.getString(R.string.password);
|
||||||
|
|
||||||
|
mClient = new OwnCloudClient(
|
||||||
|
Uri.parse(mServerUri),
|
||||||
|
NetworkUtils.getMultiThreadedConnManager()
|
||||||
|
);
|
||||||
|
mClient.setDefaultTimeouts(
|
||||||
|
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
||||||
|
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
|
||||||
|
mClient.setFollowRedirects(true);
|
||||||
|
mClient.setCredentials(
|
||||||
|
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||||
|
mUser,
|
||||||
|
mPass
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Log.v(LOG_TAG, "Client instance set up.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user