Fix logging successful search events

Test: manually test that success and abandon
  search events are logged to clearcut
Bug: 34080070

Change-Id: Ic699f707f9faa53351713ffbaaaeeff30a82b20f
diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
index e905ac7..e16b2ca 100644
--- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
@@ -95,6 +95,7 @@
     private static final String TAG = "DefaultListFragment";
     private static final String ENABLE_DEBUG_OPTIONS_HIDDEN_CODE = "debug debug!";
     private static final String KEY_DELETION_IN_PROGRESS = "deletionInProgress";
+    private static final String KEY_SEARCH_RESULT_CLICKED = "search_result_clicked";
 
     private static final int ACTIVITY_REQUEST_CODE_SHARE = 0;
 
@@ -150,6 +151,8 @@
      */
     private boolean mDisableOptionItemSelected;
 
+    private boolean mSearchResultClicked;
+
     private ActionBarAdapter mActionBarAdapter;
     private ContactsDrawerActivity mActivity;
     private ContactsRequest mContactsRequest;
@@ -251,6 +254,22 @@
         setHasOptionsMenu(true);
     }
 
+    /**
+     * Whether a search result was clicked by the user. Tracked so that we can distinguish
+     * between exiting the search mode after a result was clicked from exiting w/o clicking
+     * any search result.
+     */
+    public boolean wasSearchResultClicked() {
+        return mSearchResultClicked;
+    }
+
+    /**
+     * Resets whether a search result was clicked by the user to false.
+     */
+    public void resetSearchResultClicked() {
+        mSearchResultClicked = false;
+    }
+
     @Override
     public CursorLoader createCursorLoader(Context context) {
         return new FavoritesAndContactsLoader(context);
@@ -372,6 +391,11 @@
         if (getAdapter().isDisplayingCheckBoxes()) {
             super.onItemClick(position, id);
             return;
+        } else {
+            if (isSearchMode()) {
+                mSearchResultClicked = true;
+                Logger.logSearchEvent(createSearchStateForSearchResultClick(position));
+            }
         }
         viewContact(position, uri, getAdapter().isEnterpriseContact(position));
     }
@@ -649,8 +673,11 @@
 
         setCheckBoxListListener(new CheckBoxListListener());
         setOnContactListActionListener(new ContactBrowserActionListener());
-        if (savedInstanceState != null && savedInstanceState.getBoolean(KEY_DELETION_IN_PROGRESS)) {
-            deleteSelectedContacts();
+        if (savedInstanceState != null) {
+            if (savedInstanceState.getBoolean(KEY_DELETION_IN_PROGRESS)) {
+                deleteSelectedContacts();
+            }
+            mSearchResultClicked = savedInstanceState.getBoolean(KEY_SEARCH_RESULT_CLICKED);
         }
 
         setDirectorySearchMode();
@@ -1184,6 +1211,7 @@
         }
         mDisableOptionItemSelected = true;
         outState.putBoolean(KEY_DELETION_IN_PROGRESS, mIsDeletionInProgress);
+        outState.putBoolean(KEY_SEARCH_RESULT_CLICKED, mSearchResultClicked);
     }
 
     @Override
diff --git a/src/com/android/contacts/list/MultiSelectContactsListFragment.java b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
index 67c937c..61e92b8 100644
--- a/src/com/android/contacts/list/MultiSelectContactsListFragment.java
+++ b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
@@ -68,31 +68,12 @@
 
     private static final String EXTRA_KEY_SELECTED_CONTACTS = "selected_contacts";
 
-    private static final String KEY_SEARCH_RESULT_CLICKED = "search_result_clicked";
-
     private OnCheckBoxListActionListener mCheckBoxListListener;
-    private boolean mSearchResultClicked;
 
     public void setCheckBoxListListener(OnCheckBoxListActionListener checkBoxListListener) {
         mCheckBoxListListener = checkBoxListListener;
     }
 
-    /**
-     * Whether a search result was clicked by the user. Tracked so that we can distinguish
-     * between exiting the search mode after a result was clicked from exiting w/o clicking
-     * any search result.
-     */
-    public boolean wasSearchResultClicked() {
-        return mSearchResultClicked;
-    }
-
-    /**
-     * Resets whether a search result was clicked by the user to false.
-     */
-    public void resetSearchResultClicked() {
-        mSearchResultClicked = false;
-    }
-
     public void setAnimateOnLoad(boolean shouldAnimate) {
         mAnimateOnLoad = shouldAnimate;
     }
@@ -119,7 +100,6 @@
             final TreeSet<Long> selectedContactIds = (TreeSet<Long>)
                     savedInstanceState.getSerializable(EXTRA_KEY_SELECTED_CONTACTS);
             getAdapter().setSelectedContactIds(selectedContactIds);
-            mSearchResultClicked = savedInstanceState.getBoolean(KEY_SEARCH_RESULT_CLICKED);
         }
     }
 
@@ -149,7 +129,6 @@
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putSerializable(EXTRA_KEY_SELECTED_CONTACTS, getSelectedContactIds());
-        outState.putBoolean(KEY_SEARCH_RESULT_CLICKED, mSearchResultClicked);
     }
 
     public void displayCheckBoxes(boolean displayCheckBoxes) {
@@ -204,11 +183,6 @@
         }
         if (getAdapter().isDisplayingCheckBoxes()) {
             getAdapter().toggleSelectionOfContactId(contactId);
-        } else {
-            if (isSearchMode()) {
-                mSearchResultClicked = true;
-                Logger.logSearchEvent(createSearchStateForSearchResultClick(position));
-            }
         }
         if (mCheckBoxListListener != null && getAdapter().getSelectedContactIds().size() == 0) {
             mCheckBoxListListener.onStopDisplayingCheckBoxes();