2 * ownCloud Android client application
4 * Copyright (C) 2015 ownCloud Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.services
;
22 import java
.io
.IOException
;
23 import java
.util
.Iterator
;
24 import java
.util
.concurrent
.ConcurrentHashMap
;
25 import java
.util
.concurrent
.ConcurrentLinkedQueue
;
26 import java
.util
.concurrent
.ConcurrentMap
;
28 import com
.owncloud
.android
.MainApp
;
29 import com
.owncloud
.android
.R
;
30 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
31 import com
.owncloud
.android
.datamodel
.OCFile
;
32 import com
.owncloud
.android
.lib
.common
.OwnCloudAccount
;
33 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
34 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
35 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentials
;
36 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentialsFactory
;
37 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
;
38 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
.AccountNotFoundException
;
39 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
40 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
41 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
42 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
43 import com
.owncloud
.android
.lib
.resources
.shares
.ShareType
;
44 import com
.owncloud
.android
.lib
.resources
.users
.GetRemoteUserNameOperation
;
45 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
46 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
47 import com
.owncloud
.android
.operations
.CreateShareOperation
;
48 import com
.owncloud
.android
.operations
.GetServerInfoOperation
;
49 import com
.owncloud
.android
.operations
.MoveFileOperation
;
50 import com
.owncloud
.android
.operations
.OAuth2GetAccessToken
;
51 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
52 import com
.owncloud
.android
.operations
.RenameFileOperation
;
53 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
54 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
55 import com
.owncloud
.android
.operations
.UnshareLinkOperation
;
57 import android
.accounts
.Account
;
58 import android
.accounts
.AccountManager
;
59 import android
.accounts
.AccountsException
;
60 import android
.accounts
.AuthenticatorException
;
61 import android
.accounts
.OperationCanceledException
;
62 import android
.app
.Service
;
63 import android
.content
.Intent
;
64 import android
.net
.Uri
;
65 import android
.os
.Binder
;
66 import android
.os
.Handler
;
67 import android
.os
.HandlerThread
;
68 import android
.os
.IBinder
;
69 import android
.os
.Looper
;
70 import android
.os
.Message
;
71 import android
.os
.Process
;
72 import android
.util
.Pair
;
74 public class OperationsService
extends Service
{
76 private static final String TAG
= OperationsService
.class.getSimpleName();
78 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
79 public static final String EXTRA_SERVER_URL
= "SERVER_URL";
80 public static final String EXTRA_OAUTH2_QUERY_PARAMETERS
= "OAUTH2_QUERY_PARAMETERS";
81 public static final String EXTRA_REMOTE_PATH
= "REMOTE_PATH";
82 public static final String EXTRA_SEND_INTENT
= "SEND_INTENT";
83 public static final String EXTRA_NEWNAME
= "NEWNAME";
84 public static final String EXTRA_REMOVE_ONLY_LOCAL
= "REMOVE_LOCAL_COPY";
85 public static final String EXTRA_CREATE_FULL_PATH
= "CREATE_FULL_PATH";
86 public static final String EXTRA_SYNC_FILE_CONTENTS
= "SYNC_FILE_CONTENTS";
87 public static final String EXTRA_RESULT
= "RESULT";
88 public static final String EXTRA_NEW_PARENT_PATH
= "NEW_PARENT_PATH";
89 public static final String EXTRA_FILE
= "FILE";
90 public static final String EXTRA_PASSWORD_SHARE
= "PASSWORD_SHARE";
92 public static final String EXTRA_COOKIE
= "COOKIE";
94 public static final String ACTION_CREATE_SHARE
= "CREATE_SHARE";
95 public static final String ACTION_UNSHARE
= "UNSHARE";
96 public static final String ACTION_GET_SERVER_INFO
= "GET_SERVER_INFO";
97 public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN
= "OAUTH2_GET_ACCESS_TOKEN";
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() +
108 public static final String ACTION_OPERATION_FINISHED
= OperationsService
.class.getName() +
109 ".OPERATION_FINISHED";
112 private ConcurrentMap
<Integer
, Pair
<RemoteOperation
, RemoteOperationResult
>>
113 mUndispatchedFinishedOperations
=
114 new ConcurrentHashMap
<Integer
, Pair
<RemoteOperation
, RemoteOperationResult
>>();
116 private static class Target
{
117 public Uri mServerUrl
= null
;
118 public Account mAccount
= null
;
119 public String mCookie
= null
;
121 public Target(Account account
, Uri serverUrl
, String cookie
) {
123 mServerUrl
= serverUrl
;
128 private ServiceHandler mOperationsHandler
;
129 private OperationsServiceBinder mOperationsBinder
;
131 private SyncFolderHandler mSyncFolderHandler
;
134 * Service initialization
137 public void onCreate() {
139 Log_OC
.d(TAG
, "Creating service");
141 /// First worker thread for most of operations
142 HandlerThread thread
= new HandlerThread("Operations thread",
143 Process
.THREAD_PRIORITY_BACKGROUND
);
145 mOperationsHandler
= new ServiceHandler(thread
.getLooper(), this);
146 mOperationsBinder
= new OperationsServiceBinder(mOperationsHandler
);
148 /// Separated worker thread for download of folders (WIP)
149 thread
= new HandlerThread("Syncfolder thread", Process
.THREAD_PRIORITY_BACKGROUND
);
151 mSyncFolderHandler
= new SyncFolderHandler(thread
.getLooper(), this);
156 * Entry point to add a new operation to the queue of operations.
158 * New operations are added calling to startService(), resulting in a call to this method.
159 * This ensures the service will keep on working although the caller activity goes away.
162 public int onStartCommand(Intent intent
, int flags
, int startId
) {
163 Log_OC
.d(TAG
, "Starting command with id " + startId
);
165 // WIP: for the moment, only SYNC_FOLDER is expected here;
166 // the rest of the operations are requested through the Binder
167 if (ACTION_SYNC_FOLDER
.equals(intent
.getAction())) {
169 if (!intent
.hasExtra(EXTRA_ACCOUNT
) || !intent
.hasExtra(EXTRA_REMOTE_PATH
)) {
170 Log_OC
.e(TAG
, "Not enough information provided in intent");
171 return START_NOT_STICKY
;
173 Account account
= intent
.getParcelableExtra(EXTRA_ACCOUNT
);
174 String remotePath
= intent
.getStringExtra(EXTRA_REMOTE_PATH
);
176 Pair
<Account
, String
> itemSyncKey
= new Pair
<Account
, String
>(account
, remotePath
);
178 Pair
<Target
, RemoteOperation
> itemToQueue
= newOperation(intent
);
179 if (itemToQueue
!= null
) {
180 mSyncFolderHandler
.add(account
, remotePath
,
181 (SynchronizeFolderOperation
)itemToQueue
.second
);
182 Message msg
= mSyncFolderHandler
.obtainMessage();
184 msg
.obj
= itemSyncKey
;
185 mSyncFolderHandler
.sendMessage(msg
);
189 Message msg
= mOperationsHandler
.obtainMessage();
191 mOperationsHandler
.sendMessage(msg
);
194 return START_NOT_STICKY
;
198 public void onDestroy() {
199 Log_OC
.v(TAG
, "Destroying service" );
202 OwnCloudClientManagerFactory
.getDefaultSingleton().
203 saveAllClients(this, MainApp
.getAccountType());
205 // TODO - get rid of these exceptions
206 } catch (AccountNotFoundException e
) {
208 } catch (AuthenticatorException e
) {
210 } catch (OperationCanceledException e
) {
212 } catch (IOException e
) {
216 mUndispatchedFinishedOperations
.clear();
218 mOperationsBinder
= null
;
220 mOperationsHandler
.getLooper().quit();
221 mOperationsHandler
= null
;
223 mSyncFolderHandler
.getLooper().quit();
224 mSyncFolderHandler
= null
;
230 * Provides a binder object that clients can use to perform actions on the queue of operations,
231 * except the addition of new operations.
234 public IBinder
onBind(Intent intent
) {
235 //Log_OC.wtf(TAG, "onBind" );
236 return mOperationsBinder
;
241 * Called when ALL the bound clients were unbound.
244 public boolean onUnbind(Intent intent
) {
245 mOperationsBinder
.clearListeners();
246 return false
; // not accepting rebinding (default behaviour)
251 * Binder to let client components to perform actions on the queue of operations.
253 * It provides by itself the available operations.
255 public class OperationsServiceBinder
extends Binder
/* implements OnRemoteOperationListener */ {
258 * Map of listeners that will be reported about the end of operations from a
259 * {@link OperationsServiceBinder} instance
261 private ConcurrentMap
<OnRemoteOperationListener
, Handler
> mBoundListeners
=
262 new ConcurrentHashMap
<OnRemoteOperationListener
, Handler
>();
264 private ServiceHandler mServiceHandler
= null
;
266 public OperationsServiceBinder(ServiceHandler serviceHandler
) {
267 mServiceHandler
= serviceHandler
;
272 * Cancels a pending or current synchronization.
274 * @param account ownCloud account where the remote folder is stored.
275 * @param file A folder in the queue of pending synchronizations
277 public void cancel(Account account
, OCFile file
) {
278 mSyncFolderHandler
.cancel(account
, file
);
282 public void clearListeners() {
284 mBoundListeners
.clear();
289 * Adds a listener interested in being reported about the end of operations.
291 * @param listener Object to notify about the end of operations.
292 * @param callbackHandler {@link Handler} to access the listener without
293 * breaking Android threading protection.
295 public void addOperationListener (OnRemoteOperationListener listener
,
296 Handler callbackHandler
) {
297 synchronized (mBoundListeners
) {
298 mBoundListeners
.put(listener
, callbackHandler
);
304 * Removes a listener from the list of objects interested in the being reported about
305 * the end of operations.
307 * @param listener Object to notify about progress of transfer.
309 public void removeOperationListener (OnRemoteOperationListener listener
) {
310 synchronized (mBoundListeners
) {
311 mBoundListeners
.remove(listener
);
317 * TODO - IMPORTANT: update implementation when more operations are moved into the service
319 * @return 'True' when an operation that enforces the user to wait for completion is
322 public boolean isPerformingBlockingOperation() {
323 return (!mServiceHandler
.mPendingOperations
.isEmpty());
328 * Creates and adds to the queue a new operation, as described by operationIntent.
330 * Calls startService to make the operation is processed by the ServiceHandler.
332 * @param operationIntent Intent describing a new operation to queue and execute.
333 * @return Identifier of the operation created, or null if failed.
335 public long queueNewOperation(Intent operationIntent
) {
336 Pair
<Target
, RemoteOperation
> itemToQueue
= newOperation(operationIntent
);
337 if (itemToQueue
!= null
) {
338 mServiceHandler
.mPendingOperations
.add(itemToQueue
);
339 startService(new Intent(OperationsService
.this, OperationsService
.class));
340 return itemToQueue
.second
.hashCode();
343 return Long
.MAX_VALUE
;
348 public boolean dispatchResultIfFinished(int operationId
,
349 OnRemoteOperationListener listener
) {
350 Pair
<RemoteOperation
, RemoteOperationResult
> undispatched
=
351 mUndispatchedFinishedOperations
.remove(operationId
);
352 if (undispatched
!= null
) {
353 listener
.onRemoteOperationFinish(undispatched
.first
, undispatched
.second
);
355 //Log_OC.wtf(TAG, "Sending callback later");
357 if (!mServiceHandler
.mPendingOperations
.isEmpty()) {
362 //Log_OC.wtf(TAG, "Not finished yet");
368 * Returns True when the file described by 'file' in the ownCloud account 'account' is
369 * downloading or waiting to download.
371 * If 'file' is a directory, returns 'true' if some of its descendant files is downloading
372 * or waiting to download.
374 * @param account ownCloud account where the remote file is stored.
375 * @param remotePath Path of the folder to check if something is synchronizing
376 * / downloading / uploading inside.
378 public boolean isSynchronizing(Account account
, String remotePath
) {
379 return mSyncFolderHandler
.isSynchronizing(account
, remotePath
);
386 * Operations worker. Performs the pending operations in the order they were requested.
388 * Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}.
390 private static class ServiceHandler
extends Handler
{
391 // don't make it a final class, and don't remove the static ; lint will warn about a p
392 // ossible memory leak
395 OperationsService mService
;
398 private ConcurrentLinkedQueue
<Pair
<Target
, RemoteOperation
>> mPendingOperations
=
399 new ConcurrentLinkedQueue
<Pair
<Target
, RemoteOperation
>>();
400 private RemoteOperation mCurrentOperation
= null
;
401 private Target mLastTarget
= null
;
402 private OwnCloudClient mOwnCloudClient
= null
;
403 private FileDataStorageManager mStorageManager
;
406 public ServiceHandler(Looper looper
, OperationsService service
) {
408 if (service
== null
) {
409 throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
415 public void handleMessage(Message msg
) {
417 Log_OC
.d(TAG
, "Stopping after command with id " + msg
.arg1
);
418 mService
.stopSelf(msg
.arg1
);
423 * Performs the next operation in the queue
425 private void nextOperation() {
427 //Log_OC.wtf(TAG, "nextOperation init" );
429 Pair
<Target
, RemoteOperation
> next
= null
;
430 synchronized(mPendingOperations
) {
431 next
= mPendingOperations
.peek();
436 mCurrentOperation
= next
.second
;
437 RemoteOperationResult result
= null
;
439 /// prepare client object to send the request to the ownCloud server
440 if (mLastTarget
== null
|| !mLastTarget
.equals(next
.first
)) {
441 mLastTarget
= next
.first
;
442 if (mLastTarget
.mAccount
!= null
) {
443 OwnCloudAccount ocAccount
= new OwnCloudAccount(mLastTarget
.mAccount
,
445 mOwnCloudClient
= OwnCloudClientManagerFactory
.getDefaultSingleton().
446 getClientFor(ocAccount
, mService
);
448 AccountManager am
= AccountManager
.get(mService
.getApplicationContext());
449 String version
= am
.getUserData(mLastTarget
.mAccount
,
450 AccountUtils
.Constants
.KEY_OC_VERSION
);
451 mOwnCloudClient
.setOwnCloudVersion(version
);
453 mStorageManager
= new FileDataStorageManager(
454 mLastTarget
.mAccount
,
455 mService
.getContentResolver()
458 OwnCloudCredentials credentials
= null
;
459 if (mLastTarget
.mCookie
!= null
&&
460 mLastTarget
.mCookie
.length() > 0) {
461 // just used for GetUserName
462 // TODO refactor to run GetUserName as AsyncTask in the context of
463 // AuthenticatorActivity
464 credentials
= OwnCloudCredentialsFactory
.newSamlSsoCredentials(
465 mLastTarget
.mCookie
); // SAML SSO
467 OwnCloudAccount ocAccount
= new OwnCloudAccount(
468 mLastTarget
.mServerUrl
, credentials
);
469 mOwnCloudClient
= OwnCloudClientManagerFactory
.getDefaultSingleton().
470 getClientFor(ocAccount
, mService
);
471 mStorageManager
= null
;
475 /// perform the operation
476 if (mCurrentOperation
instanceof SyncOperation
) {
477 result
= ((SyncOperation
)mCurrentOperation
).execute(mOwnCloudClient
,
480 result
= mCurrentOperation
.execute(mOwnCloudClient
);
483 } catch (AccountsException e
) {
484 if (mLastTarget
.mAccount
== null
) {
485 Log_OC
.e(TAG
, "Error while trying to get authorization for a NULL account",
488 Log_OC
.e(TAG
, "Error while trying to get authorization for " +
489 mLastTarget
.mAccount
.name
, e
);
491 result
= new RemoteOperationResult(e
);
493 } catch (IOException e
) {
494 if (mLastTarget
.mAccount
== null
) {
495 Log_OC
.e(TAG
, "Error while trying to get authorization for a NULL account",
498 Log_OC
.e(TAG
, "Error while trying to get authorization for " +
499 mLastTarget
.mAccount
.name
, e
);
501 result
= new RemoteOperationResult(e
);
502 } catch (Exception e
) {
503 if (mLastTarget
.mAccount
== null
) {
504 Log_OC
.e(TAG
, "Unexpected error for a NULL account", e
);
506 Log_OC
.e(TAG
, "Unexpected error for " + mLastTarget
.mAccount
.name
, e
);
508 result
= new RemoteOperationResult(e
);
511 synchronized(mPendingOperations
) {
512 mPendingOperations
.poll();
516 //sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result);
517 mService
.dispatchResultToOperationListeners(mCurrentOperation
, result
);
527 * Creates a new operation, as described by operationIntent.
529 * TODO - move to ServiceHandler (probably)
531 * @param operationIntent Intent describing a new operation to queue and execute.
532 * @return Pair with the new operation object and the information about its
535 private Pair
<Target
, RemoteOperation
> newOperation(Intent operationIntent
) {
536 RemoteOperation operation
= null
;
537 Target target
= null
;
539 if (!operationIntent
.hasExtra(EXTRA_ACCOUNT
) &&
540 !operationIntent
.hasExtra(EXTRA_SERVER_URL
)) {
541 Log_OC
.e(TAG
, "Not enough information provided in intent");
544 Account account
= operationIntent
.getParcelableExtra(EXTRA_ACCOUNT
);
545 String serverUrl
= operationIntent
.getStringExtra(EXTRA_SERVER_URL
);
546 String cookie
= operationIntent
.getStringExtra(EXTRA_COOKIE
);
549 (serverUrl
== null
) ? null
: Uri
.parse(serverUrl
),
553 String action
= operationIntent
.getAction();
554 if (action
.equals(ACTION_CREATE_SHARE
)) { // Create Share
555 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
556 String password
= operationIntent
.getStringExtra(EXTRA_PASSWORD_SHARE
);
557 Intent sendIntent
= operationIntent
.getParcelableExtra(EXTRA_SEND_INTENT
);
558 if (remotePath
.length() > 0) {
559 operation
= new CreateShareOperation(OperationsService
.this, remotePath
,
560 ShareType
.PUBLIC_LINK
,
561 "", false
, password
, 1, sendIntent
);
564 } else if (action
.equals(ACTION_UNSHARE
)) { // Unshare file
565 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
566 if (remotePath
.length() > 0) {
567 operation
= new UnshareLinkOperation(
569 OperationsService
.this);
572 } else if (action
.equals(ACTION_GET_SERVER_INFO
)) {
573 // check OC server and get basic information from it
574 operation
= new GetServerInfoOperation(serverUrl
, OperationsService
.this);
576 } else if (action
.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN
)) {
577 /// GET ACCESS TOKEN to the OAuth server
578 String oauth2QueryParameters
=
579 operationIntent
.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS
);
580 operation
= new OAuth2GetAccessToken(
581 getString(R
.string
.oauth2_client_id
),
582 getString(R
.string
.oauth2_redirect_uri
),
583 getString(R
.string
.oauth2_grant_type
),
584 oauth2QueryParameters
);
586 } else if (action
.equals(ACTION_GET_USER_NAME
)) {
588 operation
= new GetRemoteUserNameOperation();
590 } else if (action
.equals(ACTION_RENAME
)) {
591 // Rename file or folder
592 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
593 String newName
= operationIntent
.getStringExtra(EXTRA_NEWNAME
);
594 operation
= new RenameFileOperation(remotePath
, newName
);
596 } else if (action
.equals(ACTION_REMOVE
)) {
597 // Remove file or folder
598 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
599 boolean onlyLocalCopy
= operationIntent
.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL
,
601 operation
= new RemoveFileOperation(remotePath
, onlyLocalCopy
);
603 } else if (action
.equals(ACTION_CREATE_FOLDER
)) {
605 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
606 boolean createFullPath
= operationIntent
.getBooleanExtra(EXTRA_CREATE_FULL_PATH
,
608 operation
= new CreateFolderOperation(remotePath
, createFullPath
);
610 } else if (action
.equals(ACTION_SYNC_FILE
)) {
612 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
613 boolean syncFileContents
=
614 operationIntent
.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS
, true
);
615 operation
= new SynchronizeFileOperation(
616 remotePath
, account
, syncFileContents
, getApplicationContext()
619 } else if (action
.equals(ACTION_SYNC_FOLDER
)) {
621 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
622 operation
= new SynchronizeFolderOperation(
623 this, // TODO remove this dependency from construction time
626 System
.currentTimeMillis() // TODO remove this dependency from construction time
629 } else if (action
.equals(ACTION_MOVE_FILE
)) {
631 String remotePath
= operationIntent
.getStringExtra(EXTRA_REMOTE_PATH
);
632 String newParentPath
= operationIntent
.getStringExtra(EXTRA_NEW_PARENT_PATH
);
633 operation
= new MoveFileOperation(remotePath
,newParentPath
,account
);
638 } catch (IllegalArgumentException e
) {
639 Log_OC
.e(TAG
, "Bad information provided in intent: " + e
.getMessage());
643 if (operation
!= null
) {
644 return new Pair
<Target
, RemoteOperation
>(target
, operation
);
652 * Sends a broadcast when a new operation is added to the queue.
654 * Local broadcasts are only delivered to activities in the same process, but can't be
657 * @param target Account or URL pointing to an OC server.
658 * @param operation Added operation.
660 private void sendBroadcastNewOperation(Target target
, RemoteOperation operation
) {
661 Intent intent
= new Intent(ACTION_OPERATION_ADDED
);
662 if (target
.mAccount
!= null
) {
663 intent
.putExtra(EXTRA_ACCOUNT
, target
.mAccount
);
665 intent
.putExtra(EXTRA_SERVER_URL
, target
.mServerUrl
);
667 //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
668 //lbm.sendBroadcast(intent);
669 sendStickyBroadcast(intent
);
673 // TODO - maybe add a notification for real start of operations
676 * Sends a LOCAL broadcast when an operations finishes in order to the interested activities c
677 * an update their view
679 * Local broadcasts are only delivered to activities in the same process.
681 * @param target Account or URL pointing to an OC server.
682 * @param operation Finished operation.
683 * @param result Result of the operation.
685 private void sendBroadcastOperationFinished(Target target
, RemoteOperation operation
,
686 RemoteOperationResult result
) {
687 Intent intent
= new Intent(ACTION_OPERATION_FINISHED
);
688 intent
.putExtra(EXTRA_RESULT
, result
);
689 if (target
.mAccount
!= null
) {
690 intent
.putExtra(EXTRA_ACCOUNT
, target
.mAccount
);
692 intent
.putExtra(EXTRA_SERVER_URL
, target
.mServerUrl
);
694 //LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
695 //lbm.sendBroadcast(intent);
696 sendStickyBroadcast(intent
);
701 * Notifies the currently subscribed listeners about the end of an operation.
703 * @param operation Finished operation.
704 * @param result Result of the operation.
706 protected void dispatchResultToOperationListeners(
707 final RemoteOperation operation
, final RemoteOperationResult result
710 Iterator
<OnRemoteOperationListener
> listeners
=
711 mOperationsBinder
.mBoundListeners
.keySet().iterator();
712 while (listeners
.hasNext()) {
713 final OnRemoteOperationListener listener
= listeners
.next();
714 final Handler handler
= mOperationsBinder
.mBoundListeners
.get(listener
);
715 if (handler
!= null
) {
716 handler
.post(new Runnable() {
719 listener
.onRemoteOperationFinish(operation
, result
);
726 //mOperationResults.put(operation.hashCode(), result);
727 Pair
<RemoteOperation
, RemoteOperationResult
> undispatched
=
728 new Pair
<RemoteOperation
, RemoteOperationResult
>(operation
, result
);
729 mUndispatchedFinishedOperations
.put(operation
.hashCode(), undispatched
);
731 Log_OC
.d(TAG
, "Called " + count
+ " listeners");