OSDN Git Service

Apollo: Lock when re-opening cursor
authorEthan Chen <intervigil@gmail.com>
Thu, 21 Nov 2013 06:50:41 +0000 (22:50 -0800)
committerGerrit Code Review <gerrit@cyanogenmod.org>
Wed, 27 Nov 2013 00:55:14 +0000 (00:55 +0000)
* In certain situations it may be possible to query the cursor
  in a state where it has been closed and not yet re-opened.

Change-Id: I60b19624887bc8ef27b928105a07072e3e11f80b

src/com/andrew/apollo/MusicPlaybackService.java

index a607fa6..0ea00b7 100644 (file)
@@ -984,10 +984,12 @@ public class MusicPlaybackService extends Service {
     }
 
     private void updateCursor(final String selection, final String[] selectionArgs) {
-        closeCursor();
+        synchronized (this) {
+            closeCursor();
 
-        mCursor = openCursorAndGoToFirst(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
-                PROJECTION, selection, selectionArgs);
+            mCursor = openCursorAndGoToFirst(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
+                    PROJECTION, selection, selectionArgs);
+        }
 
         long albumId = getAlbumId();
         if (albumId >= 0) {
@@ -1490,9 +1492,11 @@ public class MusicPlaybackService extends Service {
                 SystemClock.sleep(3000);
                 updateCursor(mPlayList[mPlayPos]);
             }
-            closeCursor();
-            mOpenFailedCounter = 20;
-            openCurrentAndNext();
+            synchronized (this) {
+                closeCursor();
+                mOpenFailedCounter = 20;
+                openCurrentAndNext();
+            }
             if (!mPlayer.isInitialized()) {
                 mPlayListLen = 0;
                 return;