mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-18 20:03:00 +00:00
Refactor parameter user_agent out of RemoteOperation and children
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ?
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user