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

am: 4e4d3631fc

Change-Id: I5207a13fa2997cad393ec60d5f0cfb93eecbde16
This commit is contained in:
Soroosh Mariooryad
2017-08-24 04:32:47 +00:00
committed by android-build-merger
3 changed files with 11 additions and 4 deletions

View File

@@ -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.
*/

View File

@@ -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;

View File

@@ -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);
}