OSDN Git Service

Use cancellationSignal only on API Level 16 and above.
authorGeorge Mount <mount@google.com>
Fri, 15 Mar 2013 14:52:15 +0000 (07:52 -0700)
committerGeorge Mount <mount@google.com>
Fri, 15 Mar 2013 15:38:28 +0000 (08:38 -0700)
 Bug 8390238

Change-Id: If2dacb1eb74e531d004b6f281d32a81f7cd59139

gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
src/com/android/photos/data/PhotoProvider.java

index 13d48fd..b0b1fe0 100644 (file)
@@ -185,6 +185,9 @@ public class ApiHelper {
     public static final boolean HAS_ROTATION_ANIMATION =
             hasField(WindowManager.LayoutParams.class, "rotationAnimation");
 
+    public static final boolean HAS_CANCELLATION_SIGNAL =
+            Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN;
+
     public static int getIntFieldIfExists(Class<?> klass, String fieldName,
             Class<?> obj, int defaultVal) {
         try {
index 8413206..2455580 100644 (file)
@@ -30,6 +30,8 @@ import android.net.Uri;
 import android.os.CancellationSignal;
 import android.provider.BaseColumns;
 
+import com.android.gallery3d.common.ApiHelper;
+
 import java.util.List;
 
 /**
@@ -357,9 +359,7 @@ public class PhotoProvider extends SQLiteContentProvider {
         selection = addIdToSelection(match, selection);
         selectionArgs = addIdToSelectionArgs(match, uri, selectionArgs);
         String table = getTableFromMatch(match, uri);
-        SQLiteDatabase db = getDatabaseHelper().getReadableDatabase();
-        return db.query(false, table, projection, selection, selectionArgs, null, null, sortOrder,
-                null, cancellationSignal);
+        return query(table, projection, selection, selectionArgs, sortOrder, cancellationSignal);
     }
 
     @Override
@@ -563,4 +563,15 @@ public class PhotoProvider extends SQLiteContentProvider {
                 throw new IllegalArgumentException("Operation not allowed on an existing row.");
         }
     }
+
+    protected Cursor query(String table, String[] columns, String selection,
+            String[] selectionArgs, String orderBy, CancellationSignal cancellationSignal) {
+        SQLiteDatabase db = getDatabaseHelper().getReadableDatabase();
+        if (ApiHelper.HAS_CANCELLATION_SIGNAL) {
+            return db.query(false, table, columns, selection, selectionArgs, null, null,
+                    orderBy, null, cancellationSignal);
+        } else {
+            return db.query(table, columns, selection, selectionArgs, null, null, orderBy);
+        }
+    }
 }