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

Commit f83b94aa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Extending SearchFeatureProvider API to provide timeout" into oc-mr1-dev

parents a78eeb2d 98fc9b13
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -137,6 +137,13 @@ public interface SearchFeatureProvider {
        return false;
    }

    /**
     * @return smart ranking timeout in milliseconds.
     */
    default long smartSearchRankingTimeoutMs(Context context) {
        return 300L;
    }

    /**
     * Prepare for search ranking predictions to avoid latency on the first prediction call.
     */
+2 −4
Original line number Diff line number Diff line
@@ -64,9 +64,6 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
    @VisibleForTesting
    static final int MSG_RANKING_TIMED_OUT = 1;

    // TODO(b/38197948): Tune this timeout based on latency of static and async rankings. Also, we
    // should add a gservices flag to control this.
    private static final long RANKING_TIMEOUT_MS = 300;
    private final SearchFragment mFragment;
    private final Context mContext;
    private final List<SearchResult> mSearchResults;
@@ -245,8 +242,9 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
            mAsyncRankingState = PENDING_RESULTS;
            mSearchFeatureProvider.cancelPendingSearchQuery(mContext);
            final Handler handler = getHandler();
            final long timeoutMs = mSearchFeatureProvider.smartSearchRankingTimeoutMs(mContext);
            handler.sendMessageDelayed(
                    handler.obtainMessage(MSG_RANKING_TIMED_OUT), RANKING_TIMEOUT_MS);
                    handler.obtainMessage(MSG_RANKING_TIMED_OUT), timeoutMs);
            mSearchFeatureProvider.querySearchResults(mContext, query, this);
        } else {
            mAsyncRankingState = DISABLED;
+2 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ public class SearchResultsAdapterTest {
        mLoaderClassName = DatabaseResultLoader.class.getName();
        when(mFragment.getContext()).thenReturn(mMockContext);
        when(mMockContext.getApplicationContext()).thenReturn(mContext);
        when(mSearchFeatureProvider.smartSearchRankingTimeoutMs(any(Context.class)))
                .thenReturn(300L);
        mAdapter = new SearchResultsAdapter(mFragment, mSearchFeatureProvider);
    }