Merge "Add hidden menu option to invoke contacts dump activity"
diff --git a/res/menu/people_options.xml b/res/menu/people_options.xml
index 8c91e88..2b3c918 100644
--- a/res/menu/people_options.xml
+++ b/res/menu/people_options.xml
@@ -55,4 +55,10 @@
     <item
         android:id="@+id/menu_help"
         android:title="@string/menu_help" />
+
+    <item
+        android:id="@+id/export_database"
+        android:title="@string/menu_export_database"
+        android:visible="false"
+        android:showAsAction="never" />
 </menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8292a56..e2db03c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1818,6 +1818,9 @@
          voicemail service in Airplane mode. [CHAR LIMI=NONE] -->
     <string name="dialog_voicemail_airplane_mode_message">To call voicemail, first turn off Airplane mode.</string>
 
+    <!-- Menu item shown only when the special debug mode is enabled, which is used to send all contacts database files via email.  [CHAR LIMI=NONE] -->
+    <string name="menu_export_database">Export database files</string>
+
     <!-- Content description for the fake action menu overflow button.
          This should be same as the description for the real action menu
          overflow button available in ActionBar.
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index a99ac45..b811dd9 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -110,6 +110,8 @@
     /** Shows a toogle button for hiding/showing updates. Don't submit with true */
     private static final boolean DEBUG_TRANSITIONS = false;
 
+    private static final String ENABLE_DEBUG_OPTIONS_HIDDEN_CODE = "debug debug!";
+
     // These values needs to start at 2. See {@link ContactEntryListFragment}.
     private static final int SUBACTIVITY_NEW_CONTACT = 2;
     private static final int SUBACTIVITY_EDIT_CONTACT = 3;
@@ -165,6 +167,8 @@
 
     private ContactDetailLayoutController mContactDetailLayoutController;
 
+    private boolean mEnableDebugMenuOptions;
+
     private final Handler mHandler = new Handler();
 
     /**
@@ -631,7 +635,10 @@
                 invalidateOptionsMenu();
                 break;
             case ActionBarAdapter.Listener.Action.CHANGE_SEARCH_QUERY:
-                setQueryTextToFragment(mActionBarAdapter.getQueryString());
+                final String queryString = mActionBarAdapter.getQueryString();
+                setQueryTextToFragment(queryString);
+                updateDebugOptionsVisibility(
+                        ENABLE_DEBUG_OPTIONS_HIDDEN_CODE.equals(queryString));
                 break;
             default:
                 throw new IllegalStateException("Unkonwn ActionBarAdapter action: " + action);
@@ -643,6 +650,13 @@
         updateFragmentsVisibility();
     }
 
+    private void updateDebugOptionsVisibility(boolean visible) {
+        if (mEnableDebugMenuOptions != visible) {
+            mEnableDebugMenuOptions = visible;
+            invalidateOptionsMenu();
+        }
+    }
+
     /**
      * Updates the fragment/view visibility according to the current mode, such as
      * {@link ActionBarAdapter#isSearchMode()} and {@link ActionBarAdapter#getCurrentTab()}.
@@ -1449,6 +1463,9 @@
         makeMenuItemVisible(menu, R.id.menu_settings,
                 showMiscOptions && !ContactsPreferenceActivity.isEmpty(this));
 
+        // Debug options need to be visible even in search mode.
+        makeMenuItemVisible(menu, R.id.export_database, mEnableDebugMenuOptions);
+
         return true;
     }
 
@@ -1545,6 +1562,12 @@
                 startActivity(intent);
                 return true;
             }
+            case R.id.export_database: {
+                final Intent intent = new Intent("com.android.providers.contacts.DUMP_DATABASE");
+                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+                startActivity(intent);
+                return true;
+            }
         }
         return false;
     }