From ec882e3f4829206f0c2718128d43899e2708a626 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 7 Jun 2023 08:51:19 +0200 Subject: [PATCH 1/2] Remove isBound() method Indeed, is bound state is redundant with the synchronization service beging set or not. This commit also fixes possible NPE. --- .../drive/FileObservers/FileEventListener.java | 11 +++++++---- .../e/drive/services/ObserverService.java | 18 +++++++++++------- .../SynchronizationServiceConnection.java | 15 +++++---------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java index 4e2bbd2b..c00b5a1b 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -105,10 +105,13 @@ public class FileEventListener { */ private void sendSyncRequestToSynchronizationService(@NonNull SyncRequest request) { Timber.d("Sending a SyncRequest for %s", request.getSyncedFileState().getName()); - if (serviceConnection.isBound()) { - serviceConnection.getSynchronizationService().queueSyncRequest(request); - serviceConnection.getSynchronizationService().startSynchronization(); - }else{ + + SynchronizationService service = serviceConnection.getSynchronizationService(); + + if (service != null) { + service.queueSyncRequest(request); + service.startSynchronization(); + } else { Timber.d("Impossible to send SyncRequest. FileEventListener is not bound to SynchronizationService"); } } diff --git a/app/src/main/java/foundation/e/drive/services/ObserverService.java b/app/src/main/java/foundation/e/drive/services/ObserverService.java index c1f08443..e90718cc 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -179,8 +179,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene return false; } - final boolean isSyncServicePaused = synchronizationServiceConnection.isBound() - && synchronizationServiceConnection.getSynchronizationService().pauseSync(); + final SynchronizationService service = + synchronizationServiceConnection.getSynchronizationService(); + + final boolean isSyncServicePaused = service != null && service.pauseSync(); Timber.d("isSyncServicePaused ? %s", isSyncServicePaused); return isSyncServicePaused; } @@ -329,8 +331,9 @@ public class ObserverService extends Service implements OnRemoteOperationListene startScan(false); - if (synchronizationServiceConnection.isBound()) { - synchronizationServiceConnection.getSynchronizationService().unPauseSync(); + SynchronizationService service = synchronizationServiceConnection.getSynchronizationService(); + if (service != null) { + service.unPauseSync(); } if (!syncRequests.isEmpty()) { @@ -352,9 +355,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene * Send all gathered SyncRequest to SynchronizationService */ private void passSyncRequestsToSynchronizationService() { - if (synchronizationServiceConnection.isBound()) { - synchronizationServiceConnection.getSynchronizationService().queueSyncRequests(syncRequests.values()); - synchronizationServiceConnection.getSynchronizationService().startSynchronization(); + SynchronizationService service = synchronizationServiceConnection.getSynchronizationService(); + if (service != null) { + service.queueSyncRequests(syncRequests.values()); + service.startSynchronization(); } else { Timber.e("ERROR: binding to SynchronizationService lost"); } diff --git a/app/src/main/java/foundation/e/drive/utils/SynchronizationServiceConnection.java b/app/src/main/java/foundation/e/drive/utils/SynchronizationServiceConnection.java index 7640135a..1227e96c 100644 --- a/app/src/main/java/foundation/e/drive/utils/SynchronizationServiceConnection.java +++ b/app/src/main/java/foundation/e/drive/utils/SynchronizationServiceConnection.java @@ -25,8 +25,8 @@ import timber.log.Timber; */ public class SynchronizationServiceConnection implements ServiceConnection { - private SynchronizationService synchronizationService; - private boolean isBound = false; + @Nullable + private SynchronizationService synchronizationService = null; private boolean attemptingToBind = false; @Override @@ -34,7 +34,6 @@ public class SynchronizationServiceConnection implements ServiceConnection { Timber.tag(SynchronizationServiceConnection.class.getSimpleName()) .v("binding to SynchronizationService"); attemptingToBind = false; - isBound = true; final SynchronizationService.SynchronizationBinder binder = (SynchronizationService.SynchronizationBinder) iBinder; synchronizationService = binder.getService(); } @@ -43,11 +42,7 @@ public class SynchronizationServiceConnection implements ServiceConnection { public void onServiceDisconnected(@Nullable ComponentName componentName) { Timber.tag(SynchronizationServiceConnection.class.getSimpleName()) .v("onServiceDisconnected()"); - isBound = false; - } - - public boolean isBound() { - return isBound; + synchronizationService = null; } /** @@ -65,9 +60,9 @@ public class SynchronizationServiceConnection implements ServiceConnection { */ public void unBind(@NonNull Context context) { attemptingToBind = false; - if (isBound) { + if (synchronizationService != null) { context.unbindService(this); - isBound = false; + synchronizationService = null; } } -- GitLab From f9f2a8624dd57a6146f5aa157409e61708c11538 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 7 Jun 2023 11:05:38 +0200 Subject: [PATCH 2/2] Ignore some DuplicateStrings We might need to rework this for all languages --- app/src/main/res/values-is/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-is/strings.xml b/app/src/main/res/values-is/strings.xml index ad7ddac8..9834689e 100644 --- a/app/src/main/res/values-is/strings.xml +++ b/app/src/main/res/values-is/strings.xml @@ -1,5 +1,5 @@ - + /e/ Drif Leyfa samstillingu skráa á gjaldskyldu neti Myndir og myndskeið @@ -19,8 +19,8 @@ •   afrit Fela samheiti + Samheiti samheiti - Samheiti Engin internettenging fannst, viðmótshlutinn mun uppfærast sjálfkrafa þegar virk internettenging kemst á Tilkynningarás eDrive Netskýið þitt er fullt. -- GitLab