Excluding local invisible contacts from search results

Change-Id: I691d26d23bb6efe89582c4db7fcac86c06590671
diff --git a/src/com/android/contacts/list/ContactEntryListAdapter.java b/src/com/android/contacts/list/ContactEntryListAdapter.java
index ddd90d3..7f00ff3 100644
--- a/src/com/android/contacts/list/ContactEntryListAdapter.java
+++ b/src/com/android/contacts/list/ContactEntryListAdapter.java
@@ -44,6 +44,12 @@
     private static final String TAG = "ContactEntryListAdapter";
 
     /**
+     * Indicates whether the {@link Directory#LOCAL_INVISIBLE} directory should
+     * be included in the search.
+     */
+    private static final boolean LOCAL_INVISIBLE_DIRECTORY_ENABLED = false;
+
+    /**
      * The animation is used here to allocate animated name text views.
      */
     private TextWithHighlightingFactory mTextWithHighlightingFactory;
@@ -217,6 +223,7 @@
 
     public void configureDirectoryLoader(DirectoryListLoader loader) {
         loader.setDirectorySearchEnabled(mDirectorySearchEnabled);
+        loader.setLocalInvisibleDirectoryEnabled(LOCAL_INVISIBLE_DIRECTORY_ENABLED);
     }
 
     /**
diff --git a/src/com/android/contacts/list/DirectoryListLoader.java b/src/com/android/contacts/list/DirectoryListLoader.java
index 558d3ae..c2505e1 100644
--- a/src/com/android/contacts/list/DirectoryListLoader.java
+++ b/src/com/android/contacts/list/DirectoryListLoader.java
@@ -72,6 +72,7 @@
     };
 
     private boolean mDirectorySearchEnabled;
+    private boolean mLocalInvisibleDirectoryEnabled;
 
     private MatrixCursor mDefaultDirectoryList;
 
@@ -83,6 +84,14 @@
         mDirectorySearchEnabled = flag;
     }
 
+    /**
+     * A flag that indicates whether the {@link Directory#LOCAL_INVISIBLE} directory should
+     * be included in the results.
+     */
+    public void setLocalInvisibleDirectoryEnabled(boolean flag) {
+        this.mLocalInvisibleDirectoryEnabled = flag;
+    }
+
     @Override
     public void startLoading() {
         getContext().getContentResolver().
@@ -108,8 +117,11 @@
         MatrixCursor result = new MatrixCursor(RESULT_PROJECTION);
         Context context = getContext();
         PackageManager pm = context.getPackageManager();
+        String selection = mLocalInvisibleDirectoryEnabled
+                ? null
+                : Directory._ID + "!=" + Directory.LOCAL_INVISIBLE;
         Cursor cursor = context.getContentResolver().query(DirectoryQuery.URI,
-                DirectoryQuery.PROJECTION, null, null, DirectoryQuery.ORDER_BY);
+                DirectoryQuery.PROJECTION, selection, null, DirectoryQuery.ORDER_BY);
         try {
             while(cursor.moveToNext()) {
                 Object[] row = new Object[RESULT_PROJECTION.length];