Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74112be4 authored by Tony Huang's avatar Tony Huang
Browse files

Add search history metrics

Update metrics log for search history.

Fix: 128880499
Test: manual
Test: atest DocumentsUITests
Change-Id: I7e2efd2412a985caa73354920ae3e9d2073a8778
parent 62d47764
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -169,11 +169,6 @@ public abstract class BaseActivity
             */
            @Override
            public void onSearchChanged(@Nullable String query) {
                if (query != null) {
                    Metrics.logUserAction(MetricConsts.USER_ACTION_SEARCH);
                }


                if (mSearchManager.isSearching()) {
                    Metrics.logSearchMode(query != null, mSearchManager.hasCheckedChip());
                    if (mInjector.pickResult != null) {
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ public class SearchFragment extends DialogFragment

    private void onHistoryItemClicked(AdapterView<?> parent, View view, int position, long id) {
        final String item = mHistoryList.get(position);
        mSearchViewManager.setHistorySearch();
        mSearchView.setQuery(item, true);
    }

+22 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import androidx.annotation.VisibleForTesting;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.SearchView.OnQueryTextListener;

import com.android.documentsui.MetricConsts;
import com.android.documentsui.Metrics;
import com.android.documentsui.R;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
@@ -81,6 +83,7 @@ public class SearchViewManager implements
    private boolean mSearchExpanded;
    private boolean mIgnoreNextClose;
    private boolean mFullBar;
    private boolean mIsHistorySearch;

    private Menu mMenu;
    private MenuItem mMenuItem;
@@ -322,6 +325,7 @@ public class SearchViewManager implements
            mQueuedSearchTask = null;
            mUiHandler.removeCallbacks(mQueuedSearchRunnable);
            mQueuedSearchRunnable = null;
            mIsHistorySearch = false;
        }
    }

@@ -453,6 +457,7 @@ public class SearchViewManager implements
                        if (mCurrentSearch != null && mCurrentSearch.isEmpty()) {
                            mCurrentSearch = null;
                        }
                        logTextSearchMetric();
                        mListener.onSearchChanged(mCurrentSearch);
                    };
                    mUiHandler.post(mQueuedSearchRunnable);
@@ -527,6 +532,16 @@ public class SearchViewManager implements
                mSearchView.getContext().getApplicationContext()).deleteHistory(history);
    }

    private void logTextSearchMetric() {
        if (isTextSearching()) {
            Metrics.logUserAction(mIsHistorySearch
                    ? MetricConsts.USER_ACTION_SEARCH_HISTORY : MetricConsts.USER_ACTION_SEARCH);
            Metrics.logSearchType(mIsHistorySearch
                    ? MetricConsts.TYPE_SEARCH_HISTORY : MetricConsts.TYPE_SEARCH_STRING);
            mIsHistorySearch = false;
        }
    }

    /**
     * Get the query content from intent.
     * @return If has query content, return the query content. Otherwise, return null
@@ -540,6 +555,13 @@ public class SearchViewManager implements
        mCurrentSearch = queryString;
    }

    /**
     * Set next search type is history search.
     */
    public void setHistorySearch() {
        mIsHistorySearch = true;
    }

    public boolean isSearching() {
        return mCurrentSearch != null || mChipViewManager.hasCheckedItems();
    }