*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.operations.CreateFolderOperation;
import android.accounts.AccountsException;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.accounts.AccountsException;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
public static final String EXTRA_RESULT = "RESULT";
public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH";
public static final String EXTRA_FILE = "FILE";
public static final String EXTRA_RESULT = "RESULT";
public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH";
public static final String EXTRA_FILE = "FILE";
public static final String ACTION_REMOVE = "REMOVE";
public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER";
public static final String ACTION_SYNC_FILE = "SYNC_FILE";
public static final String ACTION_REMOVE = "REMOVE";
public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER";
public static final String ACTION_SYNC_FILE = "SYNC_FILE";
- public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
- public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
+ public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() +
+ ".OPERATION_ADDED";
+ public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() +
+ ".OPERATION_FINISHED";
Log_OC.d(TAG, "Creating service");
/// First worker thread for most of operations
Log_OC.d(TAG, "Creating service");
/// First worker thread for most of operations
- HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND);
+ HandlerThread thread = new HandlerThread("Operations thread",
+ Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);
thread.start();
mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);
Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
if (itemToQueue != null) {
Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
if (itemToQueue != null) {
- mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation)itemToQueue.second);
+ mSyncFolderHandler.add(account, remotePath,
+ (SynchronizeFolderOperation)itemToQueue.second);
*/
private ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners =
new ConcurrentHashMap<OnRemoteOperationListener, Handler>();
*/
private ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners =
new ConcurrentHashMap<OnRemoteOperationListener, Handler>();
* Adds a listener interested in being reported about the end of operations.
*
* @param listener Object to notify about the end of operations.
* Adds a listener interested in being reported about the end of operations.
*
* @param listener Object to notify about the end of operations.
synchronized (mBoundListeners) {
mBoundListeners.put(listener, callbackHandler);
}
synchronized (mBoundListeners) {
mBoundListeners.put(listener, callbackHandler);
}
*/
public boolean isPerformingBlockingOperation() {
return (!mServiceHandler.mPendingOperations.isEmpty());
*/
public boolean isPerformingBlockingOperation() {
return (!mServiceHandler.mPendingOperations.isEmpty());
Pair<RemoteOperation, RemoteOperationResult> undispatched =
mUndispatchedFinishedOperations.remove(operationId);
if (undispatched != null) {
Pair<RemoteOperation, RemoteOperationResult> undispatched =
mUndispatchedFinishedOperations.remove(operationId);
if (undispatched != null) {
- * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting
- * to download.
+ * If 'file' is a directory, returns 'true' if some of its descendant files is downloading
+ * or waiting to download.
*/
public boolean isSynchronizing(Account account, String remotePath) {
return mSyncFolderHandler.isSynchronizing(account, remotePath);
*/
public boolean isSynchronizing(Account account, String remotePath) {
return mSyncFolderHandler.isSynchronizing(account, remotePath);
* Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}.
*/
private static class ServiceHandler extends Handler {
* Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}.
*/
private static class ServiceHandler extends Handler {
if (mLastTarget == null || !mLastTarget.equals(next.first)) {
mLastTarget = next.first;
if (mLastTarget.mAccount != null) {
if (mLastTarget == null || !mLastTarget.equals(next.first)) {
mLastTarget = next.first;
if (mLastTarget.mAccount != null) {
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mService);
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mService);
if (mLastTarget.mCookie != null &&
mLastTarget.mCookie.length() > 0) {
// just used for GetUserName
if (mLastTarget.mCookie != null &&
mLastTarget.mCookie.length() > 0) {
// just used for GetUserName
} else {
result = mCurrentOperation.execute(mOwnCloudClient);
}
} catch (AccountsException e) {
if (mLastTarget.mAccount == null) {
} else {
result = mCurrentOperation.execute(mOwnCloudClient);
}
} catch (AccountsException e) {
if (mLastTarget.mAccount == null) {
- Log_OC.e(TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e);
+ 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) {
}
result = new RemoteOperationResult(e);
} catch (IOException e) {
if (mLastTarget.mAccount == null) {
- Log_OC.e(TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e);
+ Log_OC.e(TAG, "Error while trying to get authorization for " +
+ mLastTarget.mAccount.name, e);
* TODO - move to ServiceHandler (probably)
*
* @param operationIntent Intent describing a new operation to queue and execute.
* TODO - move to ServiceHandler (probably)
*
* @param operationIntent Intent describing a new operation to queue and execute.
*/
private Pair<Target , RemoteOperation> newOperation(Intent operationIntent) {
RemoteOperation operation = null;
*/
private Pair<Target , RemoteOperation> newOperation(Intent operationIntent) {
RemoteOperation operation = null;
String action = operationIntent.getAction();
if (action.equals(ACTION_CREATE_SHARE)) { // Create Share
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String action = operationIntent.getAction();
if (action.equals(ACTION_CREATE_SHARE)) { // Create Share
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT);
if (remotePath.length() > 0) {
operation = new CreateShareOperation(OperationsService.this, remotePath,
ShareType.PUBLIC_LINK,
Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT);
if (remotePath.length() > 0) {
operation = new CreateShareOperation(OperationsService.this, remotePath,
ShareType.PUBLIC_LINK,
- "", false, "", 1, sendIntent);
+ "", false, password, 1, sendIntent);
} else if (action.equals(ACTION_REMOVE)) {
// Remove file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
} else if (action.equals(ACTION_REMOVE)) {
// Remove file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new RemoveFileOperation(remotePath, onlyLocalCopy);
} else if (action.equals(ACTION_CREATE_FOLDER)) {
// Create Folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new RemoveFileOperation(remotePath, onlyLocalCopy);
} else if (action.equals(ACTION_CREATE_FOLDER)) {
// Create Folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new CreateFolderOperation(remotePath, createFullPath);
} else if (action.equals(ACTION_SYNC_FILE)) {
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new CreateFolderOperation(remotePath, createFullPath);
} else if (action.equals(ACTION_SYNC_FILE)) {
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFileOperation(
remotePath, account, syncFileContents, getApplicationContext()
);
operation = new SynchronizeFileOperation(
remotePath, account, syncFileContents, getApplicationContext()
);
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFolderOperation(
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFolderOperation(
- private void sendBroadcastOperationFinished(Target target, RemoteOperation operation, RemoteOperationResult result) {
+ private void sendBroadcastOperationFinished(Target target, RemoteOperation operation,
+ RemoteOperationResult result) {
Intent intent = new Intent(ACTION_OPERATION_FINISHED);
intent.putExtra(EXTRA_RESULT, result);
if (target.mAccount != null) {
Intent intent = new Intent(ACTION_OPERATION_FINISHED);
intent.putExtra(EXTRA_RESULT, result);
if (target.mAccount != null) {
while (listeners.hasNext()) {
final OnRemoteOperationListener listener = listeners.next();
final Handler handler = mOperationsBinder.mBoundListeners.get(listener);
while (listeners.hasNext()) {
final OnRemoteOperationListener listener = listeners.next();
final Handler handler = mOperationsBinder.mBoundListeners.get(listener);