@Override protected RemoteOperationResult run(OwnCloudClient client) { OCShare share = getStorageManager().getShareById(mShareId); // ShareType.USER | ShareType.GROUP if (share == null) { // TODO try to get remote share before failing? return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); } mPath = share.getPath(); // Update remote share with password UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(share.getRemoteId()); updateOp.setPermissions(mPermissions); RemoteOperationResult result = updateOp.execute(client); if (result.isSuccess()) { RemoteOperation getShareOp = new GetRemoteShareOperation(share.getRemoteId()); result = getShareOp.execute(client); if (result.isSuccess()) { share = (OCShare) result.getData().get(0); // TODO check permissions are being saved updateData(share); } } return result; }
/** Performs the next operation in the queue */ private void nextOperation() { // Log_OC.e(TAG, "nextOperation init" ); Pair<Target, RemoteOperation> next = null; synchronized (mPendingOperations) { next = mPendingOperations.peek(); } if (next != null) { mCurrentOperation = next.second; RemoteOperationResult result = null; try { /// prepare client object to send the request to the ownCloud server if (mLastTarget == null || !mLastTarget.equals(next.first)) { mLastTarget = next.first; if (mLastTarget.mAccount != null) { OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService); mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton() .getClientFor(ocAccount, mService); OwnCloudVersion version = com.owncloud.android.authentication.AccountUtils.getServerVersion( mLastTarget.mAccount); mOwnCloudClient.setOwnCloudVersion(version); mStorageManager = new FileDataStorageManager(mLastTarget.mAccount, mService.getContentResolver()); } else { OwnCloudCredentials credentials = null; if (mLastTarget.mCookie != null && mLastTarget.mCookie.length() > 0) { // just used for GetUserName // TODO refactor to run GetUserName as AsyncTask in the context of // AuthenticatorActivity credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials( null, // unknown mLastTarget.mCookie); // SAML SSO } OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mServerUrl, credentials); mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton() .getClientFor(ocAccount, mService); mStorageManager = null; } } /// perform the operation if (mCurrentOperation instanceof SyncOperation) { result = ((SyncOperation) mCurrentOperation).execute(mOwnCloudClient, mStorageManager); } else { result = mCurrentOperation.execute(mOwnCloudClient); } } catch (AccountsException e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e); } else { Log_OC.e( TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e); } result = new RemoteOperationResult(e); } catch (IOException e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e); } else { Log_OC.e( TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e); } result = new RemoteOperationResult(e); } catch (Exception e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Unexpected error for a NULL account", e); } else { Log_OC.e(TAG, "Unexpected error for " + mLastTarget.mAccount.name, e); } result = new RemoteOperationResult(e); } finally { synchronized (mPendingOperations) { mPendingOperations.poll(); } } // sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result); mService.dispatchResultToOperationListeners(mCurrentOperation, result); } }