1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.services
;
20 import java
.io
.IOException
;
21 import java
.util
.Iterator
;
22 import java
.util
.concurrent
.ConcurrentHashMap
;
23 import java
.util
.concurrent
.ConcurrentLinkedQueue
;
24 import java
.util
.concurrent
.ConcurrentMap
;
26 import com
.owncloud
.android
.MainApp
;
27 import com
.owncloud
.android
.R
;
28 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
29 import com
.owncloud
.android
.datamodel
.OCFile
;
30 import com
.owncloud
.android
.lib
.common
.OwnCloudAccount
;
31 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
32 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
33 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentials
;
34 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentialsFactory
;
35 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
.AccountNotFoundException
;
36 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
37 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
38 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
39 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
40 import com
.owncloud
.android
.lib
.resources
.shares
.ShareType
;
41 import com
.owncloud
.android
.lib
.resources
.users
.GetRemoteUserNameOperation
;
42 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
43 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
44 import com
.owncloud
.android
.operations
.CreateShareOperation
;
45 import com
.owncloud
.android
.operations
.GetServerInfoOperation
;
46 import com
.owncloud
.android
.operations
.MoveFileOperation
;
47 import com
.owncloud
.android
.operations
.OAuth2GetAccessToken
;
48 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
49 import com
.owncloud
.android
.operations
.RenameFileOperation
;
50 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
51 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
52 import com
.owncloud
.android
.operations
.UnshareLinkOperation
;
54 import android
.accounts
.Account
;
55 import android
.accounts
.AccountsException
;
56 import android
.accounts
.AuthenticatorException
;
57 import android
.accounts
.OperationCanceledException
;
58 import android
.app
.Service
;
59 import android
.content
.Intent
;
60 import android
.net
.Uri
;
61 import android
.os
.Binder
;
62 import android
.os
.Handler
;
63 import android
.os
.HandlerThread
;
64 import android
.os
.IBinder
;
65 import android
.os
.Looper
;
66 import android
.os
.Message
;
67 import android
.os
.Process
;
68 import android
.util
.Pair
;
70 public class OperationsService
extends Service
{
72 private static final String TAG
= OperationsService
.class.getSimpleName();
74 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
75 public static final String EXTRA_SERVER_URL
= "SERVER_URL";
76 public static final String EXTRA_OAUTH2_QUERY_PARAMETERS
= "OAUTH2_QUERY_PARAMETERS";
77 public static final String EXTRA_REMOTE_PATH
= "REMOTE_PATH";
78 public static final String EXTRA_SEND_INTENT
= "SEND_INTENT";
79 public static final String EXTRA_NEWNAME
= "NEWNAME";
80 public static final String EXTRA_REMOVE_ONLY_LOCAL
= "REMOVE_LOCAL_COPY";
81 public static final String EXTRA_CREATE_FULL_PATH
= "CREATE_FULL_PATH";
82 public static final String EXTRA_SYNC_FILE_CONTENTS
= "SYNC_FILE_CONTENTS";
83 public static final String EXTRA_RESULT
= "RESULT";
84 public static final String EXTRA_NEW_PARENT_PATH
= "NEW_PARENT_PATH";
85 public static final String EXTRA_FILE
= "FILE";
87 public static final String EXTRA_COOKIE
= "COOKIE";
89 public static final String ACTION_CREATE_SHARE
= "CREATE_SHARE";
90 public static final String ACTION_UNSHARE
= "UNSHARE";
91 public static final String ACTION_GET_SERVER_INFO
= "GET_SERVER_INFO";
92 public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN
= "OAUTH2_GET_ACCESS_TOKEN";
93 public static final String ACTION_GET_USER_NAME
= "GET_USER_NAME";
94 public static final String ACTION_RENAME
= "RENAME";
95 public static final String ACTION_REMOVE
= "REMOVE";
96 public static final String ACTION_CREATE_FOLDER
= "CREATE_FOLDER";
97 public static final String ACTION_SYNC_FILE
= "SYNC_FILE";
98 public static final String ACTION_SYNC_FOLDER
= "SYNC_FOLDER"; // for the moment, just to download
99 public static final String ACTION_MOVE_FILE
= "MOVE_FILE";
101 public static final String ACTION_OPERATION_ADDED
= OperationsService
.class.getName() + ".OPERATION_ADDED";
102 public static final String ACTION_OPERATION_FINISHED
= OperationsService
.class.getName() + ".OPERATION_FINISHED";
105 private ConcurrentMap
<Integer
, Pair
<RemoteOperation
, RemoteOperationResult
>>
106 mUndispatchedFinishedOperations
=
107 new ConcurrentHashMap
<Integer
, Pair
<RemoteOperation
, RemoteOperationResult
>>();
109 private static class Target
{
110 public Uri mServerUrl
= null
;
111 public Account mAccount
= null
;
112 public String mCookie
= null
;
114 public Target(Account account
, Uri serverUrl
, String cookie
) {
116 mServerUrl
= serverUrl
;
121 private ServiceHandler mOperationsHandler
;
122 private OperationsServiceBinder mOperationsBinder
;
124 private SyncFolderHandler mSyncFolderHandler
;
127 * Service initialization
130 public void onCreate() {
132 Log_OC
.d(TAG
, "Creating service");
134 /// First worker thread for most of operations
135 HandlerThread thread
= new HandlerThread("Operations thread", Process
.THREAD_PRIORITY_BACKGROUND
);
137 mOperationsHandler
= new ServiceHandler(thread
.getLooper(), this);
138 mOperationsBinder
= new OperationsServiceBinder(mOperationsHandler
);
140 /// Separated worker thread for download of folders (WIP)
141 thread
= new HandlerThread("Syncfolder thread", Process
.THREAD_PRIORITY_BACKGROUND
);
143 mSyncFolderHandler
= new SyncFolderHandler(thread
.getLooper(), this);
148 * Entry point to add a new operation to the queue of operations.
150 * New operations are added calling to startService(), resulting in a call to this method.
151 * This ensures the service will keep on working although the caller activity goes away.
154 public int onStartCommand(Intent intent
, int flags
, int startId
) {
155 Log_OC
.d(TAG
, "Starting command with id " + startId
);
157 // WIP: for the moment, only SYNC_FOLDER is expected here;
158 // the rest of the operations are requested through the Binder
159 if (ACTION_SYNC_FOLDER
.equals(intent
.getAction())) {
161 if (!intent
.hasExtra(EXTRA_ACCOUNT
) || !intent
.hasExtra(EXTRA_REMOTE_PATH
)) {
162 Log_OC
.e(TAG
, "Not enough information provided in intent");
163 return START_NOT_STICKY
;
165 Account account
= intent
.getParcelableExtra(EXTRA_ACCOUNT
);
166 String remotePath
= intent
.getStringExtra(EXTRA_REMOTE_PATH
);
168 Pair
<Account
, String
> itemSyncKey
= new Pair
<Account
, String
>(account
, remotePath
);
170 Pair
<Target
, RemoteOperation
> itemToQueue
= newOperation(intent
);
171 if (itemToQueue
!= null
) {
172 mSyncFolderHandler
.add(account
, remotePath
, (SynchronizeFolderOperation
)itemToQueue
.second
);
173 Message msg
= mSyncFolderHandler
.obtainMessage();
175 msg
.obj
= itemSyncKey
;
176 mSyncFolderHandler
.sendMessage(msg
);
180 Message msg
= mOperationsHandler
.obtainMessage();
182 mOperationsHandler
.sendMessage(msg
);
185 return START_NOT_STICKY
;
189 public void onDestroy() {
190 Log_OC
.v(TAG
, "Destroying service" );
193 OwnCloudClientManagerFactory
.getDefaultSingleton().
194 saveAllClients(this, MainApp
.getAccountType());
196 // TODO - get rid of these exceptions
197 } catch (AccountNotFoundException e
) {
199 } catch (AuthenticatorException e
) {
201 } catch (OperationCanceledException e
) {
203 } catch (IOException e
) {
207 mUndispatchedFinishedOperations
.clear();
209 mOperationsBinder
= null
;
211 mOperationsHandler
.getLooper().quit();
212 mOperationsHandler
= null
;
214 mSyncFolderHandler
.getLooper().quit();
215 mSyncFolderHandler
= null
;
221 * Provides a binder object that clients can use to perform actions on the queue of operations,
222 * except the addition of new operations.
225 public IBinder
onBind(Intent intent
) {
226 //Log_OC.wtf(TAG, "onBind" );
227 return mOperationsBinder
;
232 * Called when ALL the bound clients were unbound.
235 public boolean onUnbind(Intent intent
) {
236 mOperationsBinder
.clearListeners();
237 return false
; // not accepting rebinding (default behaviour)
242 * Binder to let client components to perform actions on the queue of operations.
244 * It provides by itself the available operations.
246 public class OperationsServiceBinder
extends Binder
/* implements OnRemoteOperationListener */ {
249 * Map of listeners that will be reported about the end of operations from a {@link OperationsServiceBinder} instance
251 private ConcurrentMap
<OnRemoteOperationListener
, Handler
> mBoundListeners
=
252 new ConcurrentHashMap
<OnRemoteOperationListener
, Handler
>();
254 private ServiceHandler mServiceHandler
= null
;
256 public OperationsServiceBinder(ServiceHandler serviceHandler
) {
257 mServiceHandler
= serviceHandler
;
262 * Cancels a pending or current synchronization.
264 * @param account ownCloud account where the remote folder is stored.
265 * @param file A folder in the queue of pending synchronizations
267 public void cancel(Account account
, OCFile file
) {
268 mSyncFolderHandler
.cancel(account
, file
);
272 public void clearListeners() {
274 mBoundListeners
.clear();
279 * Adds a listener interested in being reported about the end of operations.
281 * @param listener Object to notify about the end of operations.
282 * @param callbackHandler {@link Handler} to access the listener without breaking Android threading protection.
284 public void addOperationListener (OnRemoteOperationListener listener
, Handler callbackHandler
) {
285 synchronized (mBoundListeners
) {
286 mBoundListeners
.put(listener
, callbackHandler
);
292 * Removes a listener from the list of objects interested in the being reported about the end of operations.
294 * @param listener Object to notify about progress of transfer.
296 public void removeOperationListener (OnRemoteOperationListener listener
) {
297 synchronized (mBoundListeners
) {
298 mBoundListeners
.remove(listener
);
304 * TODO - IMPORTANT: update implementation when more operations are moved into the service
306 * @return 'True' when an operation that enforces the user to wait for completion is in process.
308 public boolean isPerformingBlockingOperation() {
309 return (!mServiceHandler
.mPendingOperations
.isEmpty());
314 * Creates and adds to the queue a new operation, as described by operationIntent.
316 * Calls startService to make the operation is processed by the ServiceHandler.
318 * @param operationIntent Intent describing a new operation to queue and execute.
319 * @return Identifier of the operation created, or null if failed.
321 public long queueNewOperation(Intent operationIntent
) {
322 Pair
<Target
, RemoteOperation
> itemToQueue
= newOperation(operationIntent
);
323 if (itemToQueue
!= null
) {
324 mServiceHandler
.mPendingOperations
.add(itemToQueue
);
325 startService(new Intent(OperationsService
.this, OperationsService
.class));
326 return itemToQueue
.second
.hashCode();
329 return Long
.MAX_VALUE
;
334 public boolean dispatchResultIfFinished(int operationId
, OnRemoteOperationListener listener
) {
335 Pair
<RemoteOperation
, RemoteOperationResult
> undispatched
=
336 mUndispatchedFinishedOperations
.remove(operationId
);
337 if (undispatched
!= null
) {
338 listener
.onRemoteOperationFinish(undispatched
.first
, undispatched
.second
);
340 //Log_OC.wtf(TAG, "Sending callback later");
342 if (!mServiceHandler
.mPendingOperations
.isEmpty()) {
347 //Log_OC.wtf(TAG, "Not finished yet");
353 * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting
356 * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting
359 * @param account ownCloud account where the remote file is stored.
360 * @param remotePath Path of the folder to check if something is synchronizing / downloading / uploading
363 public boolean isSynchronizing(Account account
, String remotePath
) {
364 return mSyncFolderHandler
.isSynchronizing(account
, remotePath
);
371 * Operations worker. Performs the pending operations in the order they were requested.
373 * Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}.
375 private static class ServiceHandler
extends Handler
{
376 // don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak
379 OperationsService mService
;
382 private ConcurrentLinkedQueue
<Pair
<Target
, RemoteOperation
>> mPendingOperations
=
383 new ConcurrentLinkedQueue
<Pair
<Target
, RemoteOperation
>>();
384 private RemoteOperation mCurrentOperation
= null
;
385 private Target mLastTarget
= null
;
386 private OwnCloudClient mOwnCloudClient
= null
;
387 private FileDataStorageManager mStorageManager
;
390 public ServiceHandler(Looper looper
, OperationsService service
) {
392 if (service
== null
) {
393 throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
399 public void handleMessage(Message msg
) {
401 Log_OC
.d(TAG
, "Stopping after command with id " + msg
.arg1
);
402 mService
.stopSelf(msg
.arg1
);
407 * Performs the next operation in the queue
409 private void nextOperation() {
411 //Log_OC.wtf(TAG, "nextOperation init" );
413 Pair
<Target
, RemoteOperation
> next
= null
;
414 synchronized(mPendingOperations
) {
415 next
= mPendingOperations
.peek();
420 mCurrentOperation
= next
.second
;
421 RemoteOperationResult result
= null
;
423 /// prepare client object to send the request to the ownCloud server
424 if (mLastTarget
== null
|| !mLastTarget
.equals(next
.first
)) {
425 mLastTarget
= next
.first
;
426 if (mLastTarget
.mAccount
!= null
) {
427 OwnCloudAccount ocAccount
= new OwnCloudAccount(mLastTarget
.mAccount
, mService
);
428 mOwnCloudClient
= OwnCloudClientManagerFactory
.getDefaultSingleton().
429 getClientFor(ocAccount
, mService
);
430 mStorageManager
= new FileDataStorageManager(
431 mLastTarget
.mAccount
,
432 mService
.getContentResolver()
435 OwnCloudCredentials credentials
= null
;
436 if (mLastTarget
.mCookie
!= null
&&
437 mLastTarget
.mCookie
.length() > 0) {
438 // just used for GetUserName
439 // TODO refactor to run GetUserName as AsyncTask in the context of AuthenticatorActivity
440 credentials
= OwnCloudCredentialsFactory
.newSamlSsoCredentials(
441 mLastTarget
.mCookie
); // SAML SSO
443 OwnCloudAccount ocAccount
= new OwnCloudAccount(
444 mLastTarget
.mServerUrl
, credentials
);
445 mOwnCloudClient
= OwnCloudClientManagerFactory
.getDefaultSingleton().
446 getClientFor(ocAccount
, mService
);
447 mStorageManager
= null
;
451 /// perform the operation
452 if (mCurrentOperation
instanceof SyncOperation
) {
453 result
= ((SyncOperation
)mCurrentOperation
).execute(mOwnCloudClient
, mStorageManager
);
455 result
= mCurrentOperation
.execute(mOwnCloudClient
);
458 } catch (AccountsException e
) {
459 if (mLastTarget
.mAccount
== null
) {
460 Log_OC
.e(TAG
, "Error while trying to get authorization for a NULL account", e
);
462 Log_OC
.e(TAG
, "Error while trying to get authorization for " + mLastTarget
.mAccount
.name
, e
);
464 result
= new RemoteOperationResult(e
);
466 } catch (IOException e
) {
467 if (mLastTarget
.mAccount
== null
) {
468 Log_OC
.e(TAG
, "Error while trying to get authorization for a NULL account", e
);
470 Log_OC
.e(TAG
, "Error while trying to get authorization for " + mLastTarget
.mAccount
.name
, e
);
472 result
= new RemoteOperationResult(e
);
473 } catch (Exception e
) {
474 if (mLastTarget
.mAccount
== null
) {
475 Log_OC
.e(TAG
, "Unexpected error for a NULL account", e
);
477 Log_OC
.e(TAG
, "Unexpected error for " + mLastTarget
.mAccount
.name
, e
);
479 result
= new RemoteOperationResult(e
);
482 synchronized(mPendingOperations
) {
483 mPendingOperations
.poll();
487 //sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result);
488 mService
.dispatchResultToOperationListeners(mCurrentOperation
, result
);
498 * Creates a new operation, as described by operationIntent.
500 * TODO - move to ServiceHandler (probably)
502 * @param operationIntent Intent describing a new operation to queue and execute.
503 * @return Pair with the new operation object and the information about its target server.
505 private Pair
<Target
, RemoteOperation
> newOperation(Intent operationIntent
) {
506 RemoteOperation operation
= null
;
507 Target target
= null
;
509 if (!operationIntent
.hasExtra(EXTRA_ACCOUNT
) &&
510 !operationIntent
.hasExtra(EXTRA_SERVER_URL
)) {
511 Log_OC
.e(TAG
, "Not enough information provided in intent");
514 Account account
= operationIntent
.getParcelableExtra(EXTRA_ACCOUNT
);
515 String serverUrl
= operationIntent
.getStringExtra(EXTRA_SERVER_URL
);
516 String cookie
= operationIntent
.getStringExtra(EXTRA_COOKIE
);
519 (serverUrl
== null
) ? null
: Uri
.parse(serverUrl
),
523 String action
= operationIntent
.getAction();
524 if (action
.equals(ACTION_CREATE_SHARE
)) { // Create Share
525 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
526 Intent sendIntent
= operationIntent
.getParcelableExtra(EXTRA_SEND_INTENT
);
527 if (remotePath
.length() > 0) {
528 operation
= new CreateShareOperation(OperationsService
.this, remotePath
, ShareType
.PUBLIC_LINK
,
529 "", false
, "", 1, sendIntent
);
532 } else if (action
.equals(ACTION_UNSHARE
)) { // Unshare file
533 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
534 if (remotePath
.length() > 0) {
535 operation
= new UnshareLinkOperation(
537 OperationsService
.this);
540 } else if (action
.equals(ACTION_GET_SERVER_INFO
)) {
541 // check OC server and get basic information from it
542 operation
= new GetServerInfoOperation(serverUrl
, OperationsService
.this);
544 } else if (action
.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN
)) {
545 /// GET ACCESS TOKEN to the OAuth server
546 String oauth2QueryParameters
=
547 operationIntent
.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS
);
548 operation
= new OAuth2GetAccessToken(
549 getString(R
.string
.oauth2_client_id
),
550 getString(R
.string
.oauth2_redirect_uri
),
551 getString(R
.string
.oauth2_grant_type
),
552 oauth2QueryParameters
);
554 } else if (action
.equals(ACTION_GET_USER_NAME
)) {
556 operation
= new GetRemoteUserNameOperation();
558 } else if (action
.equals(ACTION_RENAME
)) {
559 // Rename file or folder
560 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
561 String newName
= operationIntent
.getStringExtra(EXTRA_NEWNAME
);
562 operation
= new RenameFileOperation(remotePath
, newName
);
564 } else if (action
.equals(ACTION_REMOVE
)) {
565 // Remove file or folder
566 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
567 boolean onlyLocalCopy
= operationIntent
.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL
, false
);
568 operation
= new RemoveFileOperation(remotePath
, onlyLocalCopy
);
570 } else if (action
.equals(ACTION_CREATE_FOLDER
)) {
572 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
573 boolean createFullPath
= operationIntent
.getBooleanExtra(EXTRA_CREATE_FULL_PATH
, true
);
574 operation
= new CreateFolderOperation(remotePath
, createFullPath
);
576 } else if (action
.equals(ACTION_SYNC_FILE
)) {
578 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
579 boolean syncFileContents
= operationIntent
.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS
, true
);
580 operation
= new SynchronizeFileOperation(
581 remotePath
, account
, syncFileContents
, getApplicationContext()
584 } else if (action
.equals(ACTION_SYNC_FOLDER
)) {
586 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
587 operation
= new SynchronizeFolderOperation(
588 this, // TODO remove this dependency from construction time
591 System
.currentTimeMillis() // TODO remove this dependency from construction time
594 } else if (action
.equals(ACTION_MOVE_FILE
)) {
596 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
597 String newParentPath
= operationIntent
.getStringExtra(EXTRA_NEW_PARENT_PATH
);
598 operation
= new MoveFileOperation(remotePath
,newParentPath
,account
);
603 } catch (IllegalArgumentException e
) {
604 Log_OC
.e(TAG
, "Bad information provided in intent: " + e
.getMessage());
608 if (operation
!= null
) {
609 return new Pair
<Target
, RemoteOperation
>(target
, operation
);
617 * Sends a broadcast when a new operation is added to the queue.
619 * Local broadcasts are only delivered to activities in the same process, but can't be done sticky :\
621 * @param target Account or URL pointing to an OC server.
622 * @param operation Added operation.
624 private void sendBroadcastNewOperation(Target target
, RemoteOperation operation
) {
625 Intent intent
= new Intent(ACTION_OPERATION_ADDED
);
626 if (target
.mAccount
!= null
) {
627 intent
.putExtra(EXTRA_ACCOUNT
, target
.mAccount
);
629 intent
.putExtra(EXTRA_SERVER_URL
, target
.mServerUrl
);
631 //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
632 //lbm.sendBroadcast(intent);
633 sendStickyBroadcast(intent
);
637 // TODO - maybe add a notification for real start of operations
640 * Sends a LOCAL broadcast when an operations finishes in order to the interested activities can update their view
642 * Local broadcasts are only delivered to activities in the same process.
644 * @param target Account or URL pointing to an OC server.
645 * @param operation Finished operation.
646 * @param result Result of the operation.
648 private void sendBroadcastOperationFinished(Target target
, RemoteOperation operation
, RemoteOperationResult result
) {
649 Intent intent
= new Intent(ACTION_OPERATION_FINISHED
);
650 intent
.putExtra(EXTRA_RESULT
, result
);
651 if (target
.mAccount
!= null
) {
652 intent
.putExtra(EXTRA_ACCOUNT
, target
.mAccount
);
654 intent
.putExtra(EXTRA_SERVER_URL
, target
.mServerUrl
);
656 //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
657 //lbm.sendBroadcast(intent);
658 sendStickyBroadcast(intent
);
663 * Notifies the currently subscribed listeners about the end of an operation.
665 * @param operation Finished operation.
666 * @param result Result of the operation.
668 protected void dispatchResultToOperationListeners(
669 final RemoteOperation operation
, final RemoteOperationResult result
672 Iterator
<OnRemoteOperationListener
> listeners
= mOperationsBinder
.mBoundListeners
.keySet().iterator();
673 while (listeners
.hasNext()) {
674 final OnRemoteOperationListener listener
= listeners
.next();
675 final Handler handler
= mOperationsBinder
.mBoundListeners
.get(listener
);
676 if (handler
!= null
) {
677 handler
.post(new Runnable() {
680 listener
.onRemoteOperationFinish(operation
, result
);
687 //mOperationResults.put(operation.hashCode(), result);
688 Pair
<RemoteOperation
, RemoteOperationResult
> undispatched
=
689 new Pair
<RemoteOperation
, RemoteOperationResult
>(operation
, result
);
690 mUndispatchedFinishedOperations
.put(operation
.hashCode(), undispatched
);
692 Log_OC
.d(TAG
, "Called " + count
+ " listeners");