Adding warmup call API for Settings search ranking.
- This allows the ranking implementations to prepare for predictions and avoids latency on the first prediction call. Bug: 38197948 Bug: 37312700 Test: RunSettingsRoboTests Change-Id: I1878b14765ad7cede5648fa1c7f29c419c2e5535
This commit is contained in:
@@ -130,4 +130,10 @@ public interface SearchFeatureProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare for search ranking predictions to avoid latency on the first prediction call.
|
||||
*/
|
||||
default void searchRankingWarmup(Context context) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -209,6 +209,10 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context appContext = getContext().getApplicationContext();
|
||||
if (mSearchFeatureProvider.isSmartSearchRankingEnabled(appContext)) {
|
||||
mSearchFeatureProvider.searchRankingWarmup(appContext);
|
||||
}
|
||||
requery();
|
||||
}
|
||||
|
||||
|
@@ -451,6 +451,36 @@ public class SearchFragmentTest {
|
||||
nullable(String.class), eq(searchResult));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldCallSearchRankingWarmupIfSmartSearchRankingEnabled(){
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider)
|
||||
.searchRankingWarmup(any(Context.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldNotCallSearchRankingWarmupIfSmartSearchRankingDisabled(){
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(any(Context.class)))
|
||||
.thenReturn(false);
|
||||
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider, never())
|
||||
.searchRankingWarmup(any(Context.class));
|
||||
}
|
||||
|
||||
private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag) {
|
||||
return pair -> pair.first == tag;
|
||||
}
|
||||
|
Reference in New Issue
Block a user