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

Commit b1cda553 authored by Tony Huang's avatar Tony Huang Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE when record histoy"

parents 9420cb44 126e53dd
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -540,7 +540,7 @@ public class SearchViewManager implements
     * Record current search for history.
     */
    public void recordHistory() {
        if (!mRecordSearchSupplier.getAsBoolean()) {
        if (TextUtils.isEmpty(mCurrentSearch) || !mRecordSearchSupplier.getAsBoolean()) {
            return;
        }

@@ -548,6 +548,11 @@ public class SearchViewManager implements
    }

    protected void recordHistoryInternal() {
        if (mSearchView == null) {
            Log.w(TAG, "Search view is null, skip record history this time");
            return;
        }

        SearchHistoryManager.getInstance(
                mSearchView.getContext().getApplicationContext()).addHistory(mCurrentSearch);
    }
@@ -558,6 +563,11 @@ public class SearchViewManager implements
     * @param history target string for removed.
     */
    public void removeHistory(String history) {
        if (mSearchView == null) {
            Log.w(TAG, "Search view is null, skip remove history this time");
            return;
        }

        SearchHistoryManager.getInstance(
                mSearchView.getContext().getApplicationContext()).deleteHistory(history);
    }
+13 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ public final class SearchViewManagerTest {
    private static class TestableSearchViewManager extends SearchViewManager {

        private String mHistoryRecorded;
        private boolean mIsHistoryRecorded;

        public TestableSearchViewManager(
                SearchManagerListener listener,
@@ -160,11 +161,16 @@ public final class SearchViewManagerTest {
        @Override
        protected void recordHistoryInternal() {
            mHistoryRecorded = getCurrentSearch();
            mIsHistoryRecorded = true;
        }

        public String getRecordedHistory() {
            return mHistoryRecorded;
        }

        public boolean isHistoryRecorded() {
            return mIsHistoryRecorded;
        }
    }

    private void fastForwardTo(long timeMs) {
@@ -334,6 +340,13 @@ public final class SearchViewManagerTest {
        assertNull(mSearchViewManager.getRecordedHistory());
    }

    @Test
    public void testHistoryRecorded_skipWhenNoSearchString() {
        mSearchViewManager.recordHistory();

        assertFalse(mSearchViewManager.isHistoryRecorded());
    }

    @Test
    public void testCheckedChipItems_IsEmptyIfSearchCanceled() throws Exception {
        mSearchViewManager.onClick(null);