[Android] Fix race condition for scan feedback display

Geoffrey Métais git at videolan.org
Fri May 19 11:19:41 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May 19 11:17:11 2017 +0200| [a6f62eeb38eb625a945a4ed35a52b572877dcc52] | committer: Geoffrey Métais

Fix race condition for scan feedback display

> https://code.videolan.org/videolan/vlc-android/commit/a6f62eeb38eb625a945a4ed35a52b572877dcc52
---

 .../src/org/videolan/vlc/MediaParsingService.java  | 27 ++++++++++++----------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index ad9f65e..5d10035 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -84,14 +84,17 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                     paused = false;
                     break;
                 case Medialibrary.ACTION_IDLE:
-                    if (intent.getBooleanExtra(Medialibrary.STATE_IDLE, true) && !paused) {
-                        stopSelf();
-                    } else {
-                        synchronized (this) {
-                            mLastNotificationTime = 0L;
+                    if (intent.getBooleanExtra(Medialibrary.STATE_IDLE, true)) {
+                        if (!paused) {
+                            stopSelf();
+                            return;
                         }
-                        showNotification();
                     }
+                    synchronized (MediaParsingService.this) {
+                        if (mLastNotificationTime != -1L)
+                            mLastNotificationTime = 0L;
+                    }
+                    showNotification();
                     break;
             }
         }
@@ -121,7 +124,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
 
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
-        synchronized (this) {
+        synchronized (MediaParsingService.this) {
             if (mLastNotificationTime <= 0L)
                 mLastNotificationTime = System.currentTimeMillis();
         }
@@ -239,7 +242,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
     private final Intent notificationIntent = new Intent();
     private void showNotification() {
         final long currentTime = System.currentTimeMillis();
-        synchronized (this) {
+        synchronized (MediaParsingService.this) {
             if (mLastNotificationTime == -1L || currentTime-mLastNotificationTime < NOTIFICATION_DELAY)
                 return;
             mLastNotificationTime = currentTime;
@@ -265,9 +268,6 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                 }
                 String progressText = sb.toString();
                 builder.setContentText(progressText);
-                mLocalBroadcastManager.sendBroadcast(progessIntent
-                        .putExtra(ACTION_PROGRESS_TEXT, progressText)
-                        .putExtra(ACTION_PROGRESS_VALUE, mParsing));
 
                 boolean isWorking = mMedialibrary.isWorking();
                 if (wasWorking != isWorking) {
@@ -282,6 +282,9 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                 final Notification notification = builder.build();
                 synchronized (MediaParsingService.this) {
                     if (mLastNotificationTime != -1L) {
+                        mLocalBroadcastManager.sendBroadcast(progessIntent
+                                .putExtra(ACTION_PROGRESS_TEXT, progressText)
+                                .putExtra(ACTION_PROGRESS_VALUE, mParsing));
                         try {
                             startForeground(43, notification);
                         } catch (IllegalArgumentException ignored) {}
@@ -292,7 +295,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
     }
 
     private void hideNotification() {
-        synchronized (this) {
+        synchronized (MediaParsingService.this) {
             mLastNotificationTime = -1L;
             NotificationManagerCompat.from(MediaParsingService.this).cancel(43);
         }



More information about the Android mailing list