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
.lib
.common
.OwnCloudAccount
;
30 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
31 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
32 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentials
;
33 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentialsFactory
;
34 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
.AccountNotFoundException
;
35 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
36 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
37 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
38 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
39 import com
.owncloud
.android
.lib
.resources
.files
.ExistenceCheckRemoteOperation
;
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";
86 // TODO review if ALL OF THEM are necessary
87 public static final String EXTRA_SUCCESS_IF_ABSENT
= "SUCCESS_IF_ABSENT";
88 public static final String EXTRA_USERNAME
= "USERNAME";
89 public static final String EXTRA_PASSWORD
= "PASSWORD";
90 public static final String EXTRA_AUTH_TOKEN
= "AUTH_TOKEN";
91 public static final String EXTRA_COOKIE
= "COOKIE";
93 public static final String ACTION_CREATE_SHARE
= "CREATE_SHARE";
94 public static final String ACTION_UNSHARE
= "UNSHARE";
95 public static final String ACTION_GET_SERVER_INFO
= "GET_SERVER_INFO";
96 public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN
= "OAUTH2_GET_ACCESS_TOKEN";
97 public static final String ACTION_EXISTENCE_CHECK
= "EXISTENCE_CHECK";
98 public static final String ACTION_GET_USER_NAME
= "GET_USER_NAME";
99 public static final String ACTION_RENAME
= "RENAME";
100 public static final String ACTION_REMOVE
= "REMOVE";
101 public static final String ACTION_CREATE_FOLDER
= "CREATE_FOLDER";
102 public static final String ACTION_SYNC_FILE
= "SYNC_FILE";
103 public static final String ACTION_SYNC_FOLDER
= "SYNC_FOLDER"; // for the moment, just to download
104 public static final String ACTION_MOVE_FILE
= "MOVE_FILE";
106 public static final String ACTION_OPERATION_ADDED
= OperationsService
.class.getName() + ".OPERATION_ADDED";
107 public static final String ACTION_OPERATION_FINISHED
= OperationsService
.class.getName() + ".OPERATION_FINISHED";
110 private ConcurrentMap
<Integer
, Pair
<RemoteOperation
, RemoteOperationResult
>>
111 mUndispatchedFinishedOperations
=
112 new ConcurrentHashMap
<Integer
, Pair
<RemoteOperation
, RemoteOperationResult
>>();
114 private static class Target
{
115 public Uri mServerUrl
= null
;
116 public Account mAccount
= null
;
117 public String mUsername
= null
;
118 public String mPassword
= null
;
119 public String mAuthToken
= null
;
120 public String mCookie
= null
;
122 public Target(Account account
, Uri serverUrl
, String username
, String password
, String authToken
,
125 mServerUrl
= serverUrl
;
126 mUsername
= username
;
127 mPassword
= password
;
128 mAuthToken
= authToken
;
133 private ServiceHandler mOperationsHandler
;
134 private OperationsServiceBinder mOperationsBinder
;
136 private ServiceHandler mSyncFolderHandler
;
139 * Service initialization
142 public void onCreate() {
144 /// First worker thread for most of operations
145 HandlerThread thread
= new HandlerThread("Operations thread", Process
.THREAD_PRIORITY_BACKGROUND
);
147 mOperationsHandler
= new ServiceHandler(thread
.getLooper(), this);
148 mOperationsBinder
= new OperationsServiceBinder(mOperationsHandler
);
150 /// Separated worker thread for download of folders (WIP)
151 thread
= new HandlerThread("Syncfolder thread", Process
.THREAD_PRIORITY_BACKGROUND
);
153 mSyncFolderHandler
= new ServiceHandler(thread
.getLooper(), this);
158 * Entry point to add a new operation to the queue of operations.
160 * New operations are added calling to startService(), resulting in a call to this method.
161 * This ensures the service will keep on working although the caller activity goes away.
164 public int onStartCommand(Intent intent
, int flags
, int startId
) {
165 if (ACTION_SYNC_FOLDER
.equals(intent
.getAction())) {
166 // WIP: for the moment, only SYNC_FOLDER is expected here; the rest of the operations are requested through
168 Pair
<Target
, RemoteOperation
> itemToQueue
= newOperation(intent
);
169 if (itemToQueue
!= null
) {
170 mSyncFolderHandler
.mPendingOperations
.add(itemToQueue
);
171 Message msg
= mSyncFolderHandler
.obtainMessage();
173 mSyncFolderHandler
.sendMessage(msg
);
177 Message msg
= mOperationsHandler
.obtainMessage();
179 mOperationsHandler
.sendMessage(msg
);
182 return START_NOT_STICKY
;
186 public void onDestroy() {
187 //Log_OC.wtf(TAG, "onDestroy init" );
190 OwnCloudClientManagerFactory
.getDefaultSingleton().
191 saveAllClients(this, MainApp
.getAccountType());
193 // TODO - get rid of these exceptions
194 } catch (AccountNotFoundException e
) {
196 } catch (AuthenticatorException e
) {
198 } catch (OperationCanceledException e
) {
200 } catch (IOException e
) {
204 //Log_OC.wtf(TAG, "Clear mUndispatchedFinisiedOperations" );
205 mUndispatchedFinishedOperations
.clear();
207 //Log_OC.wtf(TAG, "onDestroy end" );
213 * Provides a binder object that clients can use to perform actions on the queue of operations,
214 * except the addition of new operations.
217 public IBinder
onBind(Intent intent
) {
218 //Log_OC.wtf(TAG, "onBind" );
219 return mOperationsBinder
;
224 * Called when ALL the bound clients were unbound.
227 public boolean onUnbind(Intent intent
) {
228 ((OperationsServiceBinder
)mOperationsBinder
).clearListeners();
229 return false
; // not accepting rebinding (default behaviour)
234 * Binder to let client components to perform actions on the queue of operations.
236 * It provides by itself the available operations.
238 public class OperationsServiceBinder
extends Binder
/* implements OnRemoteOperationListener */ {
241 * Map of listeners that will be reported about the end of operations from a {@link OperationsServiceBinder} instance
243 private ConcurrentMap
<OnRemoteOperationListener
, Handler
> mBoundListeners
=
244 new ConcurrentHashMap
<OnRemoteOperationListener
, Handler
>();
246 private ServiceHandler mServiceHandler
= null
;
249 public OperationsServiceBinder(ServiceHandler serviceHandler
) {
250 mServiceHandler
= serviceHandler
;
255 * Cancels an operation
259 public void cancel() {
264 public void clearListeners() {
266 mBoundListeners
.clear();
271 * Adds a listener interested in being reported about the end of operations.
273 * @param listener Object to notify about the end of operations.
274 * @param callbackHandler {@link Handler} to access the listener without breaking Android threading protection.
276 public void addOperationListener (OnRemoteOperationListener listener
, Handler callbackHandler
) {
277 synchronized (mBoundListeners
) {
278 mBoundListeners
.put(listener
, callbackHandler
);
284 * Removes a listener from the list of objects interested in the being reported about the end of operations.
286 * @param listener Object to notify about progress of transfer.
288 public void removeOperationListener (OnRemoteOperationListener listener
) {
289 synchronized (mBoundListeners
) {
290 mBoundListeners
.remove(listener
);
296 * TODO - IMPORTANT: update implementation when more operations are moved into the service
298 * @return 'True' when an operation that enforces the user to wait for completion is in process.
300 public boolean isPerformingBlockingOperation() {
301 return (!mServiceHandler
.mPendingOperations
.isEmpty());
306 * Creates and adds to the queue a new operation, as described by operationIntent.
308 * Calls startService to make the operation is processed by the ServiceHandler.
310 * @param operationIntent Intent describing a new operation to queue and execute.
311 * @return Identifier of the operation created, or null if failed.
313 public long queueNewOperation(Intent operationIntent
) {
314 Pair
<Target
, RemoteOperation
> itemToQueue
= newOperation(operationIntent
);
315 if (itemToQueue
!= null
) {
316 mServiceHandler
.mPendingOperations
.add(itemToQueue
);
317 startService(new Intent(OperationsService
.this, OperationsService
.class));
318 return itemToQueue
.second
.hashCode();
321 return Long
.MAX_VALUE
;
326 public boolean dispatchResultIfFinished(int operationId
, OnRemoteOperationListener listener
) {
327 Pair
<RemoteOperation
, RemoteOperationResult
> undispatched
=
328 mUndispatchedFinishedOperations
.remove(operationId
);
329 if (undispatched
!= null
) {
330 listener
.onRemoteOperationFinish(undispatched
.first
, undispatched
.second
);
332 //Log_OC.wtf(TAG, "Sending callback later");
334 if (!mServiceHandler
.mPendingOperations
.isEmpty()) {
339 //Log_OC.wtf(TAG, "Not finished yet");
347 * Operations worker. Performs the pending operations in the order they were requested.
349 * Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}.
351 private static class ServiceHandler
extends Handler
{
352 // don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak
355 OperationsService mService
;
358 private ConcurrentLinkedQueue
<Pair
<Target
, RemoteOperation
>> mPendingOperations
=
359 new ConcurrentLinkedQueue
<Pair
<Target
, RemoteOperation
>>();
360 private RemoteOperation mCurrentOperation
= null
;
361 private Target mLastTarget
= null
;
362 private OwnCloudClient mOwnCloudClient
= null
;
363 private FileDataStorageManager mStorageManager
;
366 public ServiceHandler(Looper looper
, OperationsService service
) {
368 if (service
== null
) {
369 throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
375 public void handleMessage(Message msg
) {
377 mService
.stopSelf(msg
.arg1
);
382 * Performs the next operation in the queue
384 private void nextOperation() {
386 //Log_OC.wtf(TAG, "nextOperation init" );
388 Pair
<Target
, RemoteOperation
> next
= null
;
389 synchronized(mPendingOperations
) {
390 next
= mPendingOperations
.peek();
395 mCurrentOperation
= next
.second
;
396 RemoteOperationResult result
= null
;
398 /// prepare client object to send the request to the ownCloud server
399 if (mLastTarget
== null
|| !mLastTarget
.equals(next
.first
)) {
400 mLastTarget
= next
.first
;
401 if (mLastTarget
.mAccount
!= null
) {
402 OwnCloudAccount ocAccount
= new OwnCloudAccount(mLastTarget
.mAccount
, mService
);
403 mOwnCloudClient
= OwnCloudClientManagerFactory
.getDefaultSingleton().
404 getClientFor(ocAccount
, mService
);
405 mStorageManager
= new FileDataStorageManager(
406 mLastTarget
.mAccount
,
407 mService
.getContentResolver()
410 OwnCloudCredentials credentials
= null
;
411 if (mLastTarget
.mUsername
!= null
&&
412 mLastTarget
.mUsername
.length() > 0) {
413 credentials
= OwnCloudCredentialsFactory
.newBasicCredentials(
414 mLastTarget
.mUsername
,
415 mLastTarget
.mPassword
); // basic
417 } else if (mLastTarget
.mAuthToken
!= null
&&
418 mLastTarget
.mAuthToken
.length() > 0) {
419 credentials
= OwnCloudCredentialsFactory
.newBearerCredentials(
420 mLastTarget
.mAuthToken
); // bearer token
422 } else if (mLastTarget
.mCookie
!= null
&&
423 mLastTarget
.mCookie
.length() > 0) {
424 credentials
= OwnCloudCredentialsFactory
.newSamlSsoCredentials(
425 mLastTarget
.mCookie
); // SAML SSO
427 OwnCloudAccount ocAccount
= new OwnCloudAccount(
428 mLastTarget
.mServerUrl
, credentials
);
429 mOwnCloudClient
= OwnCloudClientManagerFactory
.getDefaultSingleton().
430 getClientFor(ocAccount
, mService
);
431 mStorageManager
= null
;
435 /// perform the operation
436 if (mCurrentOperation
instanceof SyncOperation
) {
437 result
= ((SyncOperation
)mCurrentOperation
).execute(mOwnCloudClient
, mStorageManager
);
439 result
= mCurrentOperation
.execute(mOwnCloudClient
);
442 } catch (AccountsException e
) {
443 if (mLastTarget
.mAccount
== null
) {
444 Log_OC
.e(TAG
, "Error while trying to get authorization for a NULL account", e
);
446 Log_OC
.e(TAG
, "Error while trying to get authorization for " + mLastTarget
.mAccount
.name
, e
);
448 result
= new RemoteOperationResult(e
);
450 } catch (IOException e
) {
451 if (mLastTarget
.mAccount
== null
) {
452 Log_OC
.e(TAG
, "Error while trying to get authorization for a NULL account", e
);
454 Log_OC
.e(TAG
, "Error while trying to get authorization for " + mLastTarget
.mAccount
.name
, e
);
456 result
= new RemoteOperationResult(e
);
457 } catch (Exception e
) {
458 if (mLastTarget
.mAccount
== null
) {
459 Log_OC
.e(TAG
, "Unexpected error for a NULL account", e
);
461 Log_OC
.e(TAG
, "Unexpected error for " + mLastTarget
.mAccount
.name
, e
);
463 result
= new RemoteOperationResult(e
);
466 synchronized(mPendingOperations
) {
467 mPendingOperations
.poll();
471 //sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result);
472 mService
.dispatchResultToOperationListeners(mLastTarget
, mCurrentOperation
, result
);
482 * Creates a new operation, as described by operationIntent.
484 * TODO - move to ServiceHandler (probably)
486 * @param operationIntent Intent describing a new operation to queue and execute.
487 * @return Pair with the new operation object and the information about its target server.
489 private Pair
<Target
, RemoteOperation
> newOperation(Intent operationIntent
) {
490 RemoteOperation operation
= null
;
491 Target target
= null
;
493 if (!operationIntent
.hasExtra(EXTRA_ACCOUNT
) &&
494 !operationIntent
.hasExtra(EXTRA_SERVER_URL
)) {
495 Log_OC
.e(TAG
, "Not enough information provided in intent");
498 Account account
= operationIntent
.getParcelableExtra(EXTRA_ACCOUNT
);
499 String serverUrl
= operationIntent
.getStringExtra(EXTRA_SERVER_URL
);
500 String username
= operationIntent
.getStringExtra(EXTRA_USERNAME
);
501 String password
= operationIntent
.getStringExtra(EXTRA_PASSWORD
);
502 String authToken
= operationIntent
.getStringExtra(EXTRA_AUTH_TOKEN
);
503 String cookie
= operationIntent
.getStringExtra(EXTRA_COOKIE
);
506 (serverUrl
== null
) ? null
: Uri
.parse(serverUrl
),
513 String action
= operationIntent
.getAction();
514 if (action
.equals(ACTION_CREATE_SHARE
)) { // Create Share
515 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
516 Intent sendIntent
= operationIntent
.getParcelableExtra(EXTRA_SEND_INTENT
);
517 if (remotePath
.length() > 0) {
518 operation
= new CreateShareOperation(remotePath
, ShareType
.PUBLIC_LINK
,
519 "", false
, "", 1, sendIntent
);
522 } else if (action
.equals(ACTION_UNSHARE
)) { // Unshare file
523 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
524 if (remotePath
.length() > 0) {
525 operation
= new UnshareLinkOperation(
527 OperationsService
.this);
530 } else if (action
.equals(ACTION_GET_SERVER_INFO
)) {
531 // check OC server and get basic information from it
532 operation
= new GetServerInfoOperation(serverUrl
, OperationsService
.this);
534 } else if (action
.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN
)) {
535 /// GET ACCESS TOKEN to the OAuth server
536 String oauth2QueryParameters
=
537 operationIntent
.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS
);
538 operation
= new OAuth2GetAccessToken(
539 getString(R
.string
.oauth2_client_id
),
540 getString(R
.string
.oauth2_redirect_uri
),
541 getString(R
.string
.oauth2_grant_type
),
542 oauth2QueryParameters
);
544 } else if (action
.equals(ACTION_EXISTENCE_CHECK
)) {
546 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
547 boolean successIfAbsent
= operationIntent
.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT
, false
);
548 operation
= new ExistenceCheckRemoteOperation(remotePath
, OperationsService
.this, successIfAbsent
);
550 } else if (action
.equals(ACTION_GET_USER_NAME
)) {
552 operation
= new GetRemoteUserNameOperation();
554 } else if (action
.equals(ACTION_RENAME
)) {
555 // Rename file or folder
556 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
557 String newName
= operationIntent
.getStringExtra(EXTRA_NEWNAME
);
558 operation
= new RenameFileOperation(remotePath
, newName
);
560 } else if (action
.equals(ACTION_REMOVE
)) {
561 // Remove file or folder
562 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
563 boolean onlyLocalCopy
= operationIntent
.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL
, false
);
564 operation
= new RemoveFileOperation(remotePath
, onlyLocalCopy
);
566 } else if (action
.equals(ACTION_CREATE_FOLDER
)) {
568 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
569 boolean createFullPath
= operationIntent
.getBooleanExtra(EXTRA_CREATE_FULL_PATH
, true
);
570 operation
= new CreateFolderOperation(remotePath
, createFullPath
);
572 } else if (action
.equals(ACTION_SYNC_FILE
)) {
574 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
575 boolean syncFileContents
= operationIntent
.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS
, true
);
576 operation
= new SynchronizeFileOperation(
577 remotePath
, account
, syncFileContents
, getApplicationContext()
580 } else if (action
.equals(ACTION_SYNC_FOLDER
)) {
582 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
583 operation
= new SynchronizeFolderOperation(
584 this, // TODO remove this dependency from construction time
587 System
.currentTimeMillis() // TODO remove this dependency from construction time
590 } else if (action
.equals(ACTION_MOVE_FILE
)) {
592 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
593 String newParentPath
= operationIntent
.getStringExtra(EXTRA_NEW_PARENT_PATH
);
594 operation
= new MoveFileOperation(remotePath
,newParentPath
,account
);
599 } catch (IllegalArgumentException e
) {
600 Log_OC
.e(TAG
, "Bad information provided in intent: " + e
.getMessage());
604 if (operation
!= null
) {
605 return new Pair
<Target
, RemoteOperation
>(target
, operation
);
613 * Sends a broadcast when a new operation is added to the queue.
615 * Local broadcasts are only delivered to activities in the same process, but can't be done sticky :\
617 * @param target Account or URL pointing to an OC server.
618 * @param operation Added operation.
620 private void sendBroadcastNewOperation(Target target
, RemoteOperation operation
) {
621 Intent intent
= new Intent(ACTION_OPERATION_ADDED
);
622 if (target
.mAccount
!= null
) {
623 intent
.putExtra(EXTRA_ACCOUNT
, target
.mAccount
);
625 intent
.putExtra(EXTRA_SERVER_URL
, target
.mServerUrl
);
627 //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
628 //lbm.sendBroadcast(intent);
629 sendStickyBroadcast(intent
);
633 // TODO - maybe add a notification for real start of operations
636 * Sends a LOCAL broadcast when an operations finishes in order to the interested activities can update their view
638 * Local broadcasts are only delivered to activities in the same process.
640 * @param target Account or URL pointing to an OC server.
641 * @param operation Finished operation.
642 * @param result Result of the operation.
644 private void sendBroadcastOperationFinished(Target target
, RemoteOperation operation
, RemoteOperationResult result
) {
645 Intent intent
= new Intent(ACTION_OPERATION_FINISHED
);
646 intent
.putExtra(EXTRA_RESULT
, result
);
647 if (target
.mAccount
!= null
) {
648 intent
.putExtra(EXTRA_ACCOUNT
, target
.mAccount
);
650 intent
.putExtra(EXTRA_SERVER_URL
, target
.mServerUrl
);
652 //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
653 //lbm.sendBroadcast(intent);
654 sendStickyBroadcast(intent
);
659 * Notifies the currently subscribed listeners about the end of an operation.
661 * @param target Account or URL pointing to an OC server.
662 * @param operation Finished operation.
663 * @param result Result of the operation.
665 private void dispatchResultToOperationListeners(
666 Target target
, final RemoteOperation operation
, final RemoteOperationResult result
) {
668 Iterator
<OnRemoteOperationListener
> listeners
= mOperationsBinder
.mBoundListeners
.keySet().iterator();
669 while (listeners
.hasNext()) {
670 final OnRemoteOperationListener listener
= listeners
.next();
671 final Handler handler
= mOperationsBinder
.mBoundListeners
.get(listener
);
672 if (handler
!= null
) {
673 handler
.post(new Runnable() {
676 listener
.onRemoteOperationFinish(operation
, result
);
683 //mOperationResults.put(operation.hashCode(), result);
684 Pair
<RemoteOperation
, RemoteOperationResult
> undispatched
=
685 new Pair
<RemoteOperation
, RemoteOperationResult
>(operation
, result
);
686 mUndispatchedFinishedOperations
.put(operation
.hashCode(), undispatched
);
688 Log_OC
.d(TAG
, "Called " + count
+ " listeners");