Fixed crash in RemoteContactCusror.

Test: manual
PiperOrigin-RevId: 168427349
Change-Id: Ie58920b76266ebb298210b5faac8fcbda4dbcd15
diff --git a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
index e6f3c26..5d80a45 100644
--- a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
+++ b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
@@ -118,12 +118,19 @@
     int position = getPosition();
     // proceed backwards until we reach the header row, which contains the directory ID.
     while (moveToPrevious()) {
-      int id = getInt(getColumnIndex(COLUMN_DIRECTORY_ID));
-      if (id != -1) {
-        // return the cursor to it's original position/state
-        moveToPosition(position);
-        return id;
+      int columnIndex = getColumnIndex(COLUMN_DIRECTORY_ID);
+      if (columnIndex == -1) {
+        continue;
       }
+
+      int id = getInt(columnIndex);
+      if (id == -1) {
+        continue;
+      }
+
+      // return the cursor to it's original position/state
+      moveToPosition(position);
+      return id;
     }
     throw Assert.createIllegalStateFailException("No directory id for contact at: " + position);
   }