From b1bc3239cee22ce040da51070b11fa0340536ca9 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 31 Jul 2024 11:52:34 +0200 Subject: [PATCH 1/2] Check mOperationsBinder nullability Signed-off-by: alperozturk --- .../android/services/OperationsService.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/services/OperationsService.java b/app/src/main/java/com/owncloud/android/services/OperationsService.java index 4cf151b3f77e..3456578a8d79 100644 --- a/app/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/app/src/main/java/com/owncloud/android/services/OperationsService.java @@ -775,23 +775,27 @@ private User toUser(@Nullable Account account) { * @param operation Finished operation. * @param result Result of the operation. */ - protected void dispatchResultToOperationListeners( - final RemoteOperation operation, final RemoteOperationResult result - ) { + protected void dispatchResultToOperationListeners(final RemoteOperation operation, final RemoteOperationResult result) { + if (mOperationsBinder == null) { + Log_OC.d(TAG, "mOperationsBinder is null dispatchResultToOperationListeners cancelled"); + return; + } + int count = 0; - Iterator listeners = mOperationsBinder.mBoundListeners.keySet().iterator(); - while (listeners.hasNext()) { - final OnRemoteOperationListener listener = listeners.next(); + + for (OnRemoteOperationListener listener : mOperationsBinder.mBoundListeners.keySet()) { final Handler handler = mOperationsBinder.mBoundListeners.get(listener); if (handler != null) { handler.post(() -> listener.onRemoteOperationFinish(operation, result)); count += 1; } } + if (count == 0) { Pair undispatched = new Pair<>(operation, result); mUndispatchedFinishedOperations.put(operation.hashCode(), undispatched); } + Log_OC.d(TAG, "Called " + count + " listeners"); } } From d68f0a9a9f9c0a9cc77612f6745aedcb1570c500 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 31 Jul 2024 12:03:04 +0200 Subject: [PATCH 2/2] Dont ignore count logic Signed-off-by: alperozturk --- .../android/services/OperationsService.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/services/OperationsService.java b/app/src/main/java/com/owncloud/android/services/OperationsService.java index 3456578a8d79..372a3c88e089 100644 --- a/app/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/app/src/main/java/com/owncloud/android/services/OperationsService.java @@ -776,18 +776,15 @@ private User toUser(@Nullable Account account) { * @param result Result of the operation. */ protected void dispatchResultToOperationListeners(final RemoteOperation operation, final RemoteOperationResult result) { - if (mOperationsBinder == null) { - Log_OC.d(TAG, "mOperationsBinder is null dispatchResultToOperationListeners cancelled"); - return; - } - int count = 0; - for (OnRemoteOperationListener listener : mOperationsBinder.mBoundListeners.keySet()) { - final Handler handler = mOperationsBinder.mBoundListeners.get(listener); - if (handler != null) { - handler.post(() -> listener.onRemoteOperationFinish(operation, result)); - count += 1; + if (mOperationsBinder != null) { + for (OnRemoteOperationListener listener : mOperationsBinder.mBoundListeners.keySet()) { + final Handler handler = mOperationsBinder.mBoundListeners.get(listener); + if (handler != null) { + handler.post(() -> listener.onRemoteOperationFinish(operation, result)); + count += 1; + } } }