From: masensio Date: Tue, 1 Apr 2014 12:51:53 +0000 (+0200) Subject: Run ExistenceCheckRemoteOperation on OperationsService X-Git-Tag: oc-android-1.7.0_signed~345^2~14^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/c2c10bcff893790e7af07c51afeb43315ff2ed84?ds=inline;hp=-c Run ExistenceCheckRemoteOperation on OperationsService --- c2c10bcff893790e7af07c51afeb43315ff2ed84 diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 69eea77b..3c144046 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -156,8 +156,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private final Handler mHandler = new Handler(); private Thread mOperationThread; private GetRemoteStatusOperation mOcServerChkOperation; - private ExistenceCheckRemoteOperation mAuthCheckOperation; - + //private ExistenceCheckRemoteOperation mAuthCheckOperation; + private int mExistenceCheckOpId = -1; + private Uri mNewCapturedUriFromOAuth2Redirection; private AccountManager mAccountMgr; @@ -794,12 +795,32 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { showDialog(DIALOG_LOGIN_PROGRESS); /// test credentials accessing the root folder - mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false); - OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true); - client.setBasicCredentials(username, password); - mOperationThread = mAuthCheckOperation.execute(client, this, mHandler); + String remotePath =""; + boolean successIfAbsent = false; + boolean followRedirects = true; + startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, username, password, followRedirects); + } + private void startExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent, String webdav_path, + String username, String password, boolean followRedirects) { + + Intent existenceCheckIntent = new Intent(); + existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK); + existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl); + existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath); + existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent); + existenceCheckIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path); + existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username); + existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password); + existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken); + existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects); + + if (mOperationsServiceBinder != null) { + Log.wtf(TAG, "starting existenceCheckRemoteOperation..." ); + mExistenceCheckOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent); + } + } /** * Starts the OAuth 'grant type' flow to get an access token, with @@ -843,9 +864,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType); /// test credentials accessing the root folder - mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false); - OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, false); - mOperationThread = mAuthCheckOperation.execute(client, this, mHandler); + String remotePath =""; + boolean successIfAbsent = false; + boolean followRedirections = false; + startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirections); } @@ -864,11 +886,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { onGetOAuthAccessTokenFinish((OAuth2GetAccessToken)operation, result); } else if (operation instanceof ExistenceCheckRemoteOperation) { + Log.wtf(TAG, "received detection response through callback" ); if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) { - onSamlBasedFederatedSingleSignOnAuthorizationStart(operation, result); + onSamlBasedFederatedSingleSignOnAuthorizationStart(result); } else { - onAuthorizationCheckFinish((ExistenceCheckRemoteOperation)operation, result); + onAuthorizationCheckFinish(result); } } else if (operation instanceof GetRemoteUserNameOperation) { onGetUserNameFinish((GetRemoteUserNameOperation) operation, result); @@ -944,7 +967,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } - private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperation operation, RemoteOperationResult result) { + private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) { try { dismissDialog(DIALOG_LOGIN_PROGRESS); } catch (IllegalArgumentException e) { @@ -1055,8 +1078,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { url = "http://" + url; } } - - // OC-208: Add suffix remote.php/webdav to normalize (OC-34) + url = trimUrlWebdav(url); if (url.endsWith("/")) { @@ -1272,10 +1294,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /// time to test the retrieved access token on the ownCloud server mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN); Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken); - mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false); - OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true); - client.setBearerCredentials(mAuthToken); - mAuthCheckOperation.execute(client, this, mHandler); + + String remotePath =""; + boolean successIfAbsent = false; + boolean followRedirects = true; + startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirects); } else { updateAuthStatusIconAndText(result); @@ -1293,7 +1316,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * @param operation Access check performed. * @param result Result of the operation. */ - private void onAuthorizationCheckFinish(ExistenceCheckRemoteOperation operation, RemoteOperationResult result) { + private void onAuthorizationCheckFinish(RemoteOperationResult result) { try { dismissDialog(DIALOG_LOGIN_PROGRESS); } catch (IllegalArgumentException e) { @@ -1878,6 +1901,20 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { onDetectAuthenticationFinish(result); } } + + if (mExistenceCheckOpId != -1) { + RemoteOperationResult result = + mOperationsServiceBinder.getOperationResultIfFinished(mExistenceCheckOpId); + if (result != null) { + Log.wtf(TAG, "found result of operation finished while rotating"); + if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) { + onSamlBasedFederatedSingleSignOnAuthorizationStart(result); + + } else { + onAuthorizationCheckFinish(result); + } + } + } } /** diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 0ccd9094..d44a3af4 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -29,6 +29,7 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.operations.CreateShareOperation; @@ -60,10 +61,16 @@ public class OperationsService extends Service { public static final String EXTRA_SEND_INTENT = "SEND_INTENT"; public static final String EXTRA_RESULT = "RESULT"; public static final String EXTRA_WEBDAV_PATH = "WEBDAV_PATH"; + public static final String EXTRA_SUCCESS_IF_ABSENT = "SUCCESS_IF_ABSENT"; + public static final String EXTRA_USERNAME = "USERNAME"; + public static final String EXTRA_PASSWORD = "PASSWORD"; + public static final String EXTRA_AUTH_TOKEN = "AUTH_TOKEN"; + public static final String EXTRA_FOLLOW_REDIRECTS = "FOLLOW_REDIRECTS"; public static final String ACTION_CREATE_SHARE = "CREATE_SHARE"; public static final String ACTION_UNSHARE = "UNSHARE"; public static final String ACTION_DETECT_AUTHENTICATION_METHOD = "DETECT_AUTHENTICATION_METHOD"; + public static final String ACTION_EXISTENCE_CHECK = "EXISTENCE_CHECK"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED"; @@ -77,9 +84,21 @@ public class OperationsService extends Service { private static class Target { public Uri mServerUrl = null; public Account mAccount = null; - public Target(Account account, Uri serverUrl) { + public String mWebDavUrl = ""; + public String mUsername = ""; + public String mPassword = ""; + public String mAuthToken = ""; + public boolean mFollowRedirects = true; + + public Target(Account account, Uri serverUrl, String webdavUrl, String username, String password, String authToken, + boolean followRedirects) { mAccount = account; mServerUrl = serverUrl; + mWebDavUrl = webdavUrl; + mUsername = username; + mPassword = password; + mAuthToken = authToken; + mFollowRedirects = followRedirects; } } @@ -228,9 +247,20 @@ public class OperationsService extends Service { } else { Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT); String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL); + String webDavPath = operationIntent.getStringExtra(EXTRA_WEBDAV_PATH); + String webDavUrl = serverUrl + webDavPath; + String username = operationIntent.getStringExtra(EXTRA_USERNAME); + String password = operationIntent.getStringExtra(EXTRA_PASSWORD); + String authToken = operationIntent.getStringExtra(EXTRA_AUTH_TOKEN); + boolean followRedirects = operationIntent.getBooleanExtra(EXTRA_FOLLOW_REDIRECTS, true); target = new Target( account, - (serverUrl == null) ? null : Uri.parse(serverUrl) + (serverUrl == null) ? null : Uri.parse(serverUrl), + ((webDavPath == null) || (serverUrl == null)) ? "" : webDavUrl, + (username == null) ? "" : username, + (password == null) ? "" : password, + (authToken == null) ? "" : authToken, + followRedirects ); String action = operationIntent.getAction(); @@ -255,6 +285,12 @@ public class OperationsService extends Service { operation = new DetectAuthenticationMethodOperation( OperationsService.this, webdav_url); + } else if (action.equals(ACTION_EXISTENCE_CHECK)) { + // Existence Check + String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); + boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, true); + operation = new ExistenceCheckRemoteOperation(remotePath, OperationsService.this, successIfAbsent); + } } @@ -316,7 +352,7 @@ public class OperationsService extends Service { synchronized(mPendingOperations) { next = mPendingOperations.peek(); } - + if (next != null) { mCurrentOperation = next.second; @@ -329,7 +365,16 @@ public class OperationsService extends Service { mOwnCloudClient = OwnCloudClientFactory.createOwnCloudClient(mLastTarget.mAccount, getApplicationContext()); mStorageManager = new FileDataStorageManager(mLastTarget.mAccount, getContentResolver()); } else { - mOwnCloudClient = OwnCloudClientFactory.createOwnCloudClient(mLastTarget.mServerUrl, getApplicationContext(), true); // this is not good enough + mOwnCloudClient = OwnCloudClientFactory.createOwnCloudClient(mLastTarget.mServerUrl, getApplicationContext(), + mLastTarget.mFollowRedirects); // this is not good enough + if (mLastTarget.mWebDavUrl != "") { + mOwnCloudClient.setWebdavUri(Uri.parse(mLastTarget.mWebDavUrl)); + } + if (mLastTarget.mUsername != "" && mLastTarget.mPassword != "") { + mOwnCloudClient.setBasicCredentials(mLastTarget.mUsername, mLastTarget.mPassword); + } else if (mLastTarget.mAuthToken != "") { + mOwnCloudClient.setBearerCredentials(mLastTarget.mAuthToken); + } mStorageManager = null; } }