[Android] Do not kill parsing service while setup is ongoing

Geoffrey Métais git at videolan.org
Wed Apr 19 15:30:11 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr 19 15:28:26 2017 +0200| [46e7242d702a8ba837d3ad604181a89325ea194e] | committer: Geoffrey Métais

Do not kill parsing service while setup is ongoing

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

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

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 71b39aa..f0ef24b 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -51,6 +51,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
     public static final long NOTIFICATION_DELAY = 1000L;
     private PowerManager.WakeLock mWakeLock;
 
+    private volatile boolean initOngoing = false;
     private final IBinder mBinder = new LocalBinder();
     private Medialibrary mMedialibrary;
     private int mParsing = 0, mReload = 0;
@@ -180,9 +181,10 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
             mThreadPool.execute(new Runnable() {
                 @Override
                 public void run() {
+                    initOngoing = true;
+                    boolean shouldInit = !(new File(MediaParsingService.this.getCacheDir()+Medialibrary.VLC_MEDIA_DB_NAME).exists());
                     mMedialibrary.setup();
                     if (mMedialibrary.init(MediaParsingService.this)) {
-                        boolean shouldInit = !(new File(MediaParsingService.this.getCacheDir()+Medialibrary.VLC_MEDIA_DB_NAME).exists());
                         List<String> devices = new ArrayList<>();
                         devices.add(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
                         devices.addAll(AndroidDevices.getExternalStorageDirectories());
@@ -206,11 +208,14 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                         for (String storage : AndroidDevices.getMediaDirectories())
                             mMedialibrary.discover(storage);
                         LocalBroadcastManager.getInstance(MediaParsingService.this).sendBroadcast(new Intent(VLCApplication.ACTION_MEDIALIBRARY_READY));
-                        if (upgrade) {
-                            mMedialibrary.forceParserRetry();
-                        } else if (!shouldInit)
-                            reload(null);
+                        if (!shouldInit) {
+                            if (upgrade)
+                                mMedialibrary.forceParserRetry();
+                            else
+                                reload(null);
+                        }
                     }
+                    initOngoing = false;
                 }
             });
     }
@@ -289,7 +294,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
     @Override
     public void onDiscoveryCompleted(String entryPoint) {
         if (BuildConfig.DEBUG) Log.d(TAG, "onDiscoveryCompleted: "+entryPoint);
-        if (!mMedialibrary.isWorking())
+        if (!initOngoing && !mMedialibrary.isWorking())
             stopSelf();
     }
 
@@ -315,7 +320,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
         if (BuildConfig.DEBUG) Log.d(TAG, "onReloadCompleted "+entryPoint);
         if (TextUtils.isEmpty(entryPoint))
             --mReload;
-        if (!mMedialibrary.isWorking())
+        if (!initOngoing && !mMedialibrary.isWorking())
             stopSelf();
     }
 



More information about the Android mailing list