OSDN Git Service

Fix ANRs due to waiting for IO on UI thread
authorBobby Georgescu <georgescu@google.com>
Tue, 29 Jan 2013 00:16:44 +0000 (16:16 -0800)
committerBobby Georgescu <georgescu@google.com>
Tue, 29 Jan 2013 00:16:44 +0000 (16:16 -0800)
Bug: 7998915
Change-Id: I938145a7072170f713099a04578f98951b35cbab

src/com/android/gallery3d/app/AbstractGalleryActivity.java
src/com/android/gallery3d/app/PhotoPage.java
src/com/android/gallery3d/ui/MenuExecutor.java

index acfc033..c9cce81 100644 (file)
@@ -343,9 +343,7 @@ public class AbstractGalleryActivity extends Activity implements GalleryContext
         if (mBatchServiceIsBound && mBatchService != null) {
             return mBatchService.getThreadPool();
         } else {
-            // Fall back on the old behavior if for some reason the
-            // service is not available.
-            return getThreadPool();
+            throw new RuntimeException("Batch service unavailable");
         }
     }
 }
index c110a8c..b3a6040 100644 (file)
@@ -1217,9 +1217,7 @@ public abstract class PhotoPage extends ActivityState implements
     @Override
     public void onCommitDeleteImage() {
         if (mDeletePath == null) return;
-        mSelectionManager.deSelectAll();
-        mSelectionManager.toggle(mDeletePath);
-        mMenuExecutor.onMenuClicked(R.id.action_delete, null, true, false);
+        mMenuExecutor.startSingleItemAction(R.id.action_delete, mDeletePath);
         mDeletePath = null;
     }
 
index 28fd71e..497632f 100644 (file)
@@ -132,7 +132,6 @@ public class MenuExecutor {
     private void stopTaskAndDismissDialog() {
         if (mTask != null) {
             if (!mWaitOnStop) mTask.cancel();
-            mTask.waitDone();
             if (mDialog != null && mDialog.isShowing()) mDialog.dismiss();
             mDialog = null;
             mTask = null;
@@ -334,15 +333,26 @@ public class MenuExecutor {
         stopTaskAndDismissDialog();
 
         Activity activity = mActivity;
-        mDialog = createProgressDialog(activity, title, ids.size());
         if (showDialog) {
+            mDialog = createProgressDialog(activity, title, ids.size());
             mDialog.show();
+        } else {
+            mDialog = null;
         }
         MediaOperation operation = new MediaOperation(action, ids, listener);
         mTask = mActivity.getBatchServiceThreadPoolIfAvailable().submit(operation, null);
         mWaitOnStop = waitOnStop;
     }
 
+    public void startSingleItemAction(int action, Path targetPath) {
+        ArrayList<Path> ids = new ArrayList<Path>(1);
+        ids.add(targetPath);
+        mDialog = null;
+        MediaOperation operation = new MediaOperation(action, ids, null);
+        mTask = mActivity.getBatchServiceThreadPoolIfAvailable().submit(operation, null);
+        mWaitOnStop = false;
+    }
+
     public static String getMimeType(int type) {
         switch (type) {
             case MediaObject.MEDIA_TYPE_IMAGE :