Merge "Extending SearchFeatureProvider API to provide timeout" into oc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f83b94aa0c
@@ -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.
|
||||
*/
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user