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

Refactor parameter user_agent out of RemoteOperation and children

This commit is contained in:
masensio 2015-03-24 14:31:40 +01:00
parent 94ac3a93d3
commit 9990eeb7ff
29 changed files with 96 additions and 166 deletions

View File

@ -79,8 +79,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
mHandler = new Handler();
Uri serverUri = Uri.parse(getString(R.string.server_base_url));
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true,
getString(R.string.user_agent));
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
getString(R.string.username),
@ -150,7 +149,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private void startRefresh() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
refreshOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
refreshOperation.execute(mClient, this, mHandler);
}
private void startUpload() {
@ -160,7 +159,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
String mimeType = getString(R.string.sample_file_mimetype);
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType);
uploadOperation.addDatatransferProgressListener(this);
uploadOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
uploadOperation.execute(mClient, this, mHandler);
}
private void startRemoteDeletion() {
@ -168,7 +167,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
removeOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
removeOperation.execute(mClient, this, mHandler);
}
private void startDownload() {
@ -179,7 +178,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath());
downloadOperation.addDatatransferProgressListener(this);
downloadOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
downloadOperation.execute(mClient, this, mHandler);
}
@SuppressWarnings("deprecation")

View File

@ -67,12 +67,11 @@ public class OwnCloudClient extends HttpClient {
private int mInstanceNumber = 0;
private Uri mBaseUri;
private String mUserAgent;
/**
* Constructor
*/
public OwnCloudClient(Uri baseUri, HttpConnectionManager connectionMgr, String userAgent) {
public OwnCloudClient(Uri baseUri, HttpConnectionManager connectionMgr) {
super(connectionMgr);
if (baseUri == null) {
@ -83,8 +82,8 @@ public class OwnCloudClient extends HttpClient {
mInstanceNumber = sIntanceCounter++;
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
mUserAgent = userAgent;
getParams().setParameter(HttpMethodParams.USER_AGENT, mUserAgent);
String userAgent = OwnCloudClientManagerFactory.getUserAgent();
getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
getParams().setParameter(
CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
@ -212,7 +211,8 @@ public class OwnCloudClient extends HttpClient {
// Update User Agent
HttpParams params = method.getParams();
params.setParameter(HttpMethodParams.USER_AGENT, mUserAgent);
String userAgent = OwnCloudClientManagerFactory.getUserAgent();
params.setParameter(HttpMethodParams.USER_AGENT, userAgent);
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
method.getName() + " " + method.getPath());

View File

@ -61,7 +61,6 @@ public class OwnCloudClientFactory {
*
* @param account The ownCloud account
* @param appContext Android application context
* @param userAgent OwnCloud userAgent string
* @return A OwnCloudClient object ready to be used
* @throws AuthenticatorException If the authenticator failed to get the authorization
* token for the account.
@ -71,8 +70,7 @@ public class OwnCloudClientFactory {
* authorization token for the account.
* @throws AccountNotFoundException If 'account' is unknown for the AccountManager
*/
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext,
String userAgent)
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext)
throws OperationCanceledException, AuthenticatorException, IOException,
AccountNotFoundException {
//Log_OC.d(TAG, "Creating OwnCloudClient associated to " + account.name);
@ -83,7 +81,7 @@ public class OwnCloudClientFactory {
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;
boolean isSamlSso =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso, userAgent);
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
if (isOauth2) {
String accessToken = am.blockingGetAuthToken(
@ -127,7 +125,7 @@ public class OwnCloudClientFactory {
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext,
Activity currentActivity, String userAgent)
Activity currentActivity)
throws OperationCanceledException, AuthenticatorException, IOException,
AccountNotFoundException {
Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
@ -137,7 +135,7 @@ public class OwnCloudClientFactory {
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;
boolean isSamlSso =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso, userAgent);
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
if (isOauth2) { // TODO avoid a call to getUserData here
AccountManagerFuture<Bundle> future = am.getAuthToken(
@ -204,11 +202,10 @@ public class OwnCloudClientFactory {
*
* @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH
* @param context Android context where the OwnCloudClient is being created.
* @param userAgent OwnCloud userAgent string
* @return A OwnCloudClient object ready to be used
*/
public static OwnCloudClient createOwnCloudClient(Uri uri, Context context,
boolean followRedirects, String userAgent) {
boolean followRedirects) {
try {
NetworkUtils.registerAdvancedSslContext(true, context);
} catch (GeneralSecurityException e) {
@ -220,8 +217,7 @@ public class OwnCloudClientFactory {
" in the system will be used for HTTPS connections", e);
}
OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager(),
userAgent);
OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager());
client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
client.setFollowRedirects(followRedirects);

View File

@ -42,7 +42,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
public interface OwnCloudClientManager {
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context, String userAgent)
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
IOException;

View File

@ -34,6 +34,8 @@ public class OwnCloudClientManagerFactory {
private static OwnCloudClientManager sDefaultSingleton;
private static String sUserAgent;
public static OwnCloudClientManager newDefaultOwnCloudClientManager() {
return newOwnCloudClientManager(sDefaultPolicy);
}
@ -71,7 +73,15 @@ public class OwnCloudClientManagerFactory {
}
sDefaultPolicy = policy;
}
public static void setUserAgent(String userAgent){
sUserAgent = userAgent;
}
public static String getUserAgent() {
return sUserAgent;
}
private static boolean defaultSingletonMustBeUpdated(Policy policy) {
if (sDefaultSingleton == null) {
return false;

View File

@ -40,7 +40,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
private static final String TAG = SimpleFactoryManager.class.getSimpleName();
@Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context, String userAgent)
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
IOException {
@ -49,8 +49,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
account.getBaseUri(),
context.getApplicationContext(),
true,
userAgent);
true);
Log_OC.v(TAG, " new client {" +
(account.getName() != null ?

View File

@ -62,8 +62,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
@Override
public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context,
String userAgent)
public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
IOException {
@ -109,8 +108,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
client = OwnCloudClientFactory.createOwnCloudClient(
account.getBaseUri(),
context.getApplicationContext(),
true,
userAgent); // TODO remove dependency on OwnCloudClientFactory
true); // TODO remove dependency on OwnCloudClientFactory
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
// enable cookie tracking

View File

@ -81,9 +81,6 @@ public abstract class RemoteOperation implements Runnable {
/** Activity */
private Activity mCallerActivity;
/** User agent */
private String mUserAgent;
/**
* Abstract method to implement the operation in derived classes.
@ -97,15 +94,14 @@ public abstract class RemoteOperation implements Runnable {
* Do not call this method from the main thread.
*
* This method should be used whenever an ownCloud account is available, instead of
* {@link #execute(OwnCloudClient, java.lang.String)}.
* {@link #execute(OwnCloudClient)}.
*
* @param account ownCloud account in remote ownCloud server to reach during the
* execution of the operation.
* @param context Android context for the component calling the method.
* @param userAgent userAgent string
* @return Result of the operation.
*/
public RemoteOperationResult execute(Account account, Context context, String userAgent) {
public RemoteOperationResult execute(Account account, Context context) {
if (account == null)
throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " +
"Account");
@ -114,11 +110,10 @@ public abstract class RemoteOperation implements Runnable {
"Context");
mAccount = account;
mContext = context.getApplicationContext();
mUserAgent = userAgent;
try {
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mContext, mUserAgent);
getClientFor(ocAccount, mContext);
} catch (Exception e) {
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
return new RemoteOperationResult(e);
@ -134,15 +129,13 @@ public abstract class RemoteOperation implements Runnable {
*
* @param client Client object to reach an ownCloud server during the execution of
* the operation.
* @param userAgent userAgent string
* @return Result of the operation.
*/
public RemoteOperationResult execute(OwnCloudClient client, String userAgent) {
public RemoteOperationResult execute(OwnCloudClient client) {
if (client == null)
throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " +
"OwnCloudClient");
mClient = client;
mUserAgent = userAgent;
return run(client);
}
@ -151,10 +144,10 @@ public abstract class RemoteOperation implements Runnable {
* Asynchronously executes the remote operation
*
* This method should be used whenever an ownCloud account is available, instead of
* {@link #execute(OwnCloudClient, java.lang.String)}.
* {@link #execute(OwnCloudClient)}.
*
* @deprecated This method will be removed in version 1.0.
* Use {@link #execute(Account, Context, String, OnRemoteOperationListener,
* Use {@link #execute(Account, Context, OnRemoteOperationListener,
* Handler)} instead.
*
* @param account ownCloud account in remote ownCloud server to reach during
@ -193,18 +186,17 @@ public abstract class RemoteOperation implements Runnable {
* Asynchronously executes the remote operation
*
* This method should be used whenever an ownCloud account is available,
* instead of {@link #execute(OwnCloudClient, String, OnRemoteOperationListener, Handler))}.
* instead of {@link #execute(OwnCloudClient, OnRemoteOperationListener, Handler))}.
*
* @param account ownCloud account in remote ownCloud server to reach during the
* execution of the operation.
* @param context Android context for the component calling the method.
* @param userAgent userAgent string
* @param listener Listener to be notified about the execution of the operation.
* @param listenerHandler Handler associated to the thread where the methods of the listener
* objects must be called.
* @return Thread were the remote operation is executed.
*/
public Thread execute(Account account, Context context, String userAgent,
public Thread execute(Account account, Context context,
OnRemoteOperationListener listener, Handler listenerHandler) {
if (account == null)
@ -234,20 +226,18 @@ public abstract class RemoteOperation implements Runnable {
*
* @param client Client object to reach an ownCloud server
* during the execution of the operation.
* @param userAgent userAgent string
* @param listener Listener to be notified about the execution of the operation.
* @param listenerHandler Handler associated to the thread where the methods of
* the listener objects must be called.
* @return Thread were the remote operation is executed.
*/
public Thread execute(OwnCloudClient client, String userAgent,
public Thread execute(OwnCloudClient client,
OnRemoteOperationListener listener, Handler listenerHandler) {
if (client == null) {
throw new IllegalArgumentException
("Trying to execute a remote operation with a NULL OwnCloudClient");
}
mClient = client;
mUserAgent = userAgent;
if (listener == null) {
throw new IllegalArgumentException
@ -270,7 +260,7 @@ public abstract class RemoteOperation implements Runnable {
/**
* Asynchronous execution of the operation
* started by {@link RemoteOperation#execute(OwnCloudClient, String,
* started by {@link RemoteOperation#execute(OwnCloudClient,
* OnRemoteOperationListener, Handler)},
* and result posting.
*
@ -287,12 +277,12 @@ public abstract class RemoteOperation implements Runnable {
/** DEPRECATED BLOCK - will be removed at version 1.0 */
if (mCallerActivity != null) {
mClient = OwnCloudClientFactory.createOwnCloudClient(
mAccount, mContext, mCallerActivity, mUserAgent);
mAccount, mContext, mCallerActivity);
} else {
/** EOF DEPRECATED */
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mContext, mUserAgent);
getClientFor(ocAccount, mContext);
}
} else {
@ -371,13 +361,4 @@ public abstract class RemoteOperation implements Runnable {
return mClient;
}
/**
* Returns the user agent string
* @return
*/
public final String getUserAgent() {
return mUserAgent;
}
}

View File

@ -75,7 +75,6 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
}
mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
mPutMethod.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
((ChunkFromFileChannelRequestEntity)mEntity).setOffset(offset);
mPutMethod.setRequestEntity(mEntity);
status = client.executeMethod(mPutMethod);

View File

@ -78,8 +78,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
result = createFolder(client);
if (!result.isSuccess() && mCreateFullPath &&
RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) {
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client,
getUserAgent());
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
if (result.isSuccess()) {
result = createFolder(client); // second (and last) try
}
@ -98,7 +97,6 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
MkColMethod mkcol = null;
try {
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
mkcol.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
@ -115,11 +113,10 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
return result;
}
private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client,
String userAgent) {
private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) {
RemoteOperation operation = new CreateRemoteFolderOperation(parentPath,
mCreateFullPath);
return operation.execute(client, userAgent);
return operation.execute(client);
}

View File

@ -102,7 +102,6 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
int status = -1;
boolean savedFile = false;
mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
mGet.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
Iterator<OnDatatransferProgressListener> it = null;
FileOutputStream fos = null;

View File

@ -77,7 +77,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
HeadMethod head = null;
try {
head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath));
head.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
client.exhaustResponse(head.getResponseBodyAsStream());
boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) ||

View File

@ -113,7 +113,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath),
mOverwrite
);
move.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT);
/// process response

View File

@ -79,7 +79,6 @@ public class ReadRemoteFileOperation extends RemoteOperation {
propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
WebdavUtils.getFilePropSet(), // PropFind Properties
DavConstants.DEPTH_0);
propfind.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status;
status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

View File

@ -76,7 +76,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
WebdavUtils.getAllPropSet(), // PropFind Properties
DavConstants.DEPTH_1);
query.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(query);
// check and process response

View File

@ -68,7 +68,6 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
try {
delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
delete.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
delete.getResponseBodyAsString(); // exhaust the response, although not interesting

View File

@ -107,7 +107,6 @@ public class RenameRemoteFileOperation extends RemoteOperation {
move = new LocalMoveMethod( client.getWebdavUri() +
WebdavUtils.encodePath(mOldRemotePath),
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath));
move.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
move.getResponseBodyAsString(); // exhaust response, although not interesting

View File

@ -82,7 +82,6 @@ public class UploadRemoteFileOperation extends RemoteOperation {
} else {
mPutMethod = new PutMethod(client.getWebdavUri() +
WebdavUtils.encodePath(mRemotePath));
mPutMethod.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
}
}

View File

@ -106,7 +106,6 @@ public class CreateRemoteShareOperation extends RemoteOperation {
post.setRequestHeader( "Content-Type",
"application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
post.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
post.addParameter(PARAM_PATH, mRemoteFilePath);
post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue()));

View File

@ -86,7 +86,6 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
try {
// Get Method
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
// Add Parameters to Get Method
get.setQueryString(new NameValuePair[] {

View File

@ -67,7 +67,6 @@ public class GetRemoteSharesOperation extends RemoteOperation {
try{
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
status = client.executeMethod(get);
if(isSuccess(status)) {
String response = get.getResponseBodyAsString();

View File

@ -72,7 +72,6 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id);
delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
delete.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
status = client.executeMethod(delete);

View File

@ -38,6 +38,7 @@ import android.net.ConnectivityManager;
import android.net.Uri;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -77,10 +78,10 @@ public class GetRemoteStatusOperation extends RemoteOperation {
String baseUrlSt = client.getBaseUri().toString();
try {
get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
HttpParams params = get.getParams().getDefaultParams();
params.setParameter(HttpMethodParams.USER_AGENT, getUserAgent());
params.setParameter(HttpMethodParams.USER_AGENT,
OwnCloudClientManagerFactory.getUserAgent());
get.getParams().setDefaults(params);
client.setFollowRedirects(false);

View File

@ -79,7 +79,6 @@ public class GetRemoteUserNameOperation extends RemoteOperation {
try {
get = new GetMethod(client.getBaseUri() + OCS_ROUTE);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
status = client.executeMethod(get);
if(isSuccess(status)) {
String response = get.getResponseBodyAsString();

View File

@ -72,7 +72,6 @@ public class TestActivity extends Activity {
private String mServerUri;
private String mUser;
private String mPass;
private static String mUserAgent;
private static final int BUFFER_SIZE = 1024;
@ -91,7 +90,6 @@ public class TestActivity extends Activity {
mServerUri = getString(R.string.server_base_url);
mUser = getString(R.string.username);
mPass = getString(R.string.password);
mUserAgent = getString(R.string.user_agent);
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
@ -106,8 +104,7 @@ public class TestActivity extends Activity {
}
}
mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager());
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
@ -159,7 +156,7 @@ public class TestActivity extends Activity {
CreateRemoteFolderOperation createOperation =
new CreateRemoteFolderOperation(remotePath, createFullPath);
RemoteOperationResult result = createOperation.execute(client, mUserAgent);
RemoteOperationResult result = createOperation.execute(client);
return result;
}
@ -177,7 +174,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
RemoteOperationResult result = renameOperation.execute(mClient, mUserAgent);
RemoteOperationResult result = renameOperation.execute(mClient);
return result;
}
@ -190,7 +187,7 @@ public class TestActivity extends Activity {
*/
public RemoteOperationResult removeFile(String remotePath) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent);
RemoteOperationResult result = removeOperation.execute(mClient);
return result;
}
@ -202,7 +199,7 @@ public class TestActivity extends Activity {
*/
public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(client, mUserAgent);
RemoteOperationResult result = removeOperation.execute(client);
return result;
}
@ -216,7 +213,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult readFile(String remotePath) {
ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath);
RemoteOperationResult result = readOperation.execute(mClient, mUserAgent);
RemoteOperationResult result = readOperation.execute(mClient);
return result;
}
@ -235,7 +232,7 @@ public class TestActivity extends Activity {
folder.mkdirs();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath());
RemoteOperationResult result = downloadOperation.execute(mClient, mUserAgent);
RemoteOperationResult result = downloadOperation.execute(mClient);
return result;
}
@ -276,7 +273,7 @@ public class TestActivity extends Activity {
);
}
RemoteOperationResult result = uploadOperation.execute(client, mUserAgent);
RemoteOperationResult result = uploadOperation.execute(client);
return result;
}
@ -287,7 +284,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult getShares(){
GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation();
RemoteOperationResult result = getOperation.execute(mClient, mUserAgent);
RemoteOperationResult result = getOperation.execute(mClient);
return result;
}
@ -315,7 +312,7 @@ public class TestActivity extends Activity {
String password, int permissions){
CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions);
RemoteOperationResult result = createOperation.execute(mClient, mUserAgent);
RemoteOperationResult result = createOperation.execute(mClient);
return result;
}
@ -329,7 +326,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult removeShare(int idShare) {
RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare);
RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent);
RemoteOperationResult result = removeOperation.execute(mClient);
return result;

View File

@ -279,8 +279,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_1,
false
);
RemoteOperationResult result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
RemoteOperationResult result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename file, different location
@ -289,8 +288,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename file, same location (rename file)
@ -299,8 +297,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move empty folder
@ -309,8 +306,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move non-empty folder
@ -319,8 +315,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename folder, different location
@ -329,8 +324,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename folder, same location (rename folder)
@ -339,8 +333,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move for nothing (success, but no interaction with network)
@ -349,8 +342,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FILE_4,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move overwriting
@ -359,8 +351,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
true
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
@ -372,8 +363,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
// folder to move into does no exist
@ -382,8 +372,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT);
// target location (renaming) has invalid characters
@ -392,8 +381,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
// name collision
@ -402,8 +390,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
// move a folder into a descendant
@ -412,8 +399,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
false
);
result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
}
@ -450,8 +436,7 @@ public class MoveFileTest extends RemoteTest {
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager(),
getContext().getString(R.string.user_agent)
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,

View File

@ -97,8 +97,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testConstructor() {
try {
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager());
throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) {
@ -107,7 +106,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
}
try {
new OwnCloudClient(mServerUri, null, mUserAgent);
new OwnCloudClient(mServerUri, null);
throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) {
@ -116,8 +115,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
}
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
assertNotNull("OwnCloudClient instance not built", client);
assertEquals("Wrong user agent",
client.getParams().getParameter(HttpMethodParams.USER_AGENT),
@ -127,8 +125,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetCredentials() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
assertNotNull("Returned NULL credentials", client.getCredentials());
assertEquals("Not instanced without credentials",
@ -151,8 +148,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
int connectionTimeout = client.getConnectionTimeout();
int readTimeout = client.getDataTimeout();
@ -200,8 +196,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExecuteMethod() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
int status = -1;
try {
@ -222,8 +217,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExhaustResponse() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
PropFindMethod propfind = null;
try {
@ -265,8 +259,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetDefaultTimeouts() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
int oldDataTimeout = client.getDataTimeout();
int oldConnectionTimeout = client.getConnectionTimeout();
@ -306,8 +299,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetWebdavUri() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken"));
Uri webdavUri = client.getWebdavUri();
assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " +
@ -345,8 +337,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetBaseUri() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
assertEquals("Returned base URI different that URI passed to constructor",
mServerUri, client.getBaseUri());

View File

@ -95,16 +95,13 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
public void testGetClientFor() {
try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent));
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
assertNotSame("Got same client instances for same account",
client, mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
client, mSFMgr.getClientFor(mValidAccount, getContext()));
assertNotSame("Got same client instances for different accounts",
client, mSFMgr.getClientFor(mAnonymousAccount, getContext(),
getContext().getString(R.string.user_agent)));
client, mSFMgr.getClientFor(mAnonymousAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
@ -114,12 +111,10 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
public void testRemoveClientFor() {
try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent));
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
mSFMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager",
client, mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
client, mSFMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());

View File

@ -94,16 +94,13 @@ public class SingleSessionManagerTest extends AndroidTestCase {
public void testGetClientFor() {
try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent));
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext(),
getContext().getString(R.string.user_agent));
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext());
assertNotSame("Got same client instances for different accounts",
client1, client2);
assertSame("Got different client instances for same account",
client1, mSSMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
client1, mSSMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
@ -114,12 +111,10 @@ public class SingleSessionManagerTest extends AndroidTestCase {
public void testRemoveClientFor() {
try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent));
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
mSSMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager",
client1, mSSMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
client1, mSSMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}