Handle a possible weird case for empty directories table
Usually ContactsProvider must have at least one directory
in its directories table. If it does not, Contacts app works
wrongly with search UI, which is not appropriate for production.
We still need to figure out when and why it "may" happen, so
this change will dump really nasty error log when it happened.
Also modifies its comment. It looks this method does not
maintain the cursor, and should not (as this method is called
from other methods which want to maintain it)
Bug: 4970089
Change-Id: Ieaca11bfabf8413bb3f8c9867d304a5c00b5735b
diff --git a/src/com/android/contacts/list/ContactEntryListAdapter.java b/src/com/android/contacts/list/ContactEntryListAdapter.java
index 95a8c2b..62b678c 100644
--- a/src/com/android/contacts/list/ContactEntryListAdapter.java
+++ b/src/com/android/contacts/list/ContactEntryListAdapter.java
@@ -31,6 +31,7 @@
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Directory;
import android.text.TextUtils;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -320,9 +321,16 @@
/**
* Updates partitions according to the directory meta-data contained in the supplied
- * cursor. Takes ownership of the cursor and will close it.
+ * cursor.
*/
public void changeDirectories(Cursor cursor) {
+ if (cursor.getCount() == 0) {
+ // Directory table must have at least local directory, without which this adapter will
+ // enter very weird state.
+ Log.e(TAG, "Directory search loader returned an empty cursor, which implies we have " +
+ "no directory entries.", new RuntimeException());
+ return;
+ }
HashSet<Long> directoryIds = new HashSet<Long>();
int idColumnIndex = cursor.getColumnIndex(Directory._ID);