Bug 1000849 - Make a dummy MatrixCursor to listen for dataset changed notifications. r=lucasr
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 25 Apr 2014 08:29:27 -0700
changeset 198741 528ed2029bc27fb1111f1de9697b4011b80a951a
parent 198740 548827cce8d7209cb5604ced64d3c4b77ef49b95
child 198742 6fa6a3e42d65981df45b24326826f7be387fb5e5
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs1000849
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1000849 - Make a dummy MatrixCursor to listen for dataset changed notifications. r=lucasr
mobile/android/base/db/BrowserContract.java
mobile/android/base/db/HomeProvider.java
--- a/mobile/android/base/db/BrowserContract.java
+++ b/mobile/android/base/db/BrowserContract.java
@@ -342,16 +342,19 @@ public class BrowserContract {
 
         public static final String DATASET_ID = "dataset_id";
         public static final String URL = "url";
         public static final String TITLE = "title";
         public static final String DESCRIPTION = "description";
         public static final String IMAGE_URL = "image_url";
         public static final String CREATED = "created";
         public static final String FILTER = "filter";
+
+        public static final String[] DEFAULT_PROJECTION =
+            new String[] { _ID, DATASET_ID, URL, TITLE, DESCRIPTION, IMAGE_URL, FILTER };
     }
 
     /*
      * Contains names and schema definitions for tables and views
      * no longer being used by current ContentProviders. These values are used
      * to make incremental updates to the schema during a database upgrade. Will be
      * removed with bug 947018.
      */
--- a/mobile/android/base/db/HomeProvider.java
+++ b/mobile/android/base/db/HomeProvider.java
@@ -80,22 +80,27 @@ public class HomeProvider extends SQLite
             throw new IllegalArgumentException("All queries should contain a dataset ID parameter");
         }
 
         selection = DBUtils.concatenateWhere(selection, HomeItems.DATASET_ID + " = ?");
         selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
                                                     new String[] { datasetId });
 
         // Otherwise, let the SQLiteContentProvider implementation take care of this query for us!
-        final Cursor c = super.query(uri, projection, selection, selectionArgs, sortOrder);
-        if (c != null) {
-            final ContentResolver cr = getContext().getContentResolver();
-            c.setNotificationUri(cr, getDatasetNotificationUri(datasetId));
+        Cursor c = super.query(uri, projection, selection, selectionArgs, sortOrder);
+
+        // SQLiteBridgeContentProvider may return a null Cursor if the database hasn't been created yet.
+        // However, we need a non-null cursor in order to listen for notifications.
+        if (c == null) {
+            c = new MatrixCursor(projection != null ? projection : HomeItems.DEFAULT_PROJECTION);
         }
 
+        final ContentResolver cr = getContext().getContentResolver();
+        c.setNotificationUri(cr, getDatasetNotificationUri(datasetId));
+
         return c;
     }
 
     /**
      * Returns a cursor populated with static fake data.
      */
     private Cursor queryFakeItems(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
         JSONArray items = null;
@@ -105,27 +110,17 @@ public class HomeProvider extends SQLite
         } catch (IOException e) {
             Log.e(LOGTAG, "Error getting fake home items", e);
             return null;
         } catch (JSONException e) {
             Log.e(LOGTAG, "Error parsing fake_home_items.json", e);
             return null;
         }
 
-        final String[] itemsColumns = new String[] {
-            HomeItems._ID,
-            HomeItems.DATASET_ID,
-            HomeItems.URL,
-            HomeItems.TITLE,
-            HomeItems.DESCRIPTION,
-            HomeItems.IMAGE_URL,
-            HomeItems.FILTER
-        };
-
-        final MatrixCursor c = new MatrixCursor(itemsColumns);
+        final MatrixCursor c = new MatrixCursor(HomeItems.DEFAULT_PROJECTION);
         for (int i = 0; i < items.length(); i++) {
             try {
                 final JSONObject item = items.getJSONObject(i);
                 c.addRow(new Object[] {
                     item.getInt("id"),
                     item.getString("dataset_id"),
                     item.getString("url"),
                     item.getString("title"),