Move a11y indexing from DynamicContentMonitor to loader

This is necessary to kill DynamicContentMonitor later

- Removed all logic related to indexing accesiblitysetting from the
  monitor class and AccessibilitySetting page itself
- Created a loader to search against A11yServices at runtime

I noticed adding a loader in SearchResultsAdapter is rather manual. It's
something we should consider refactor in the future.

Bug: 64310452
Test: robotests
Change-Id: Iff31aff65ce000991229433f294e2ec69af99da2
This commit is contained in:
Fan Zhang
2017-08-02 17:32:43 -07:00
parent 56538f1775
commit 5035f8c559
13 changed files with 375 additions and 213 deletions

View File

@@ -56,6 +56,8 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
@VisibleForTesting
static final String APP_RESULTS_LOADER_KEY = InstalledAppResultLoader.class.getName();
@VisibleForTesting
static final String ACCESSIBLITY_LOADER_KEY = AccessibilityServiceResultLoader.class.getName();
@VisibleForTesting
static final int MSG_RANKING_TIMED_OUT = 1;
@@ -262,11 +264,16 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
getSortedLoadedResults(DB_RESULTS_LOADER_KEY);
List<? extends SearchResult> installedAppResults =
getSortedLoadedResults(APP_RESULTS_LOADER_KEY);
List<? extends SearchResult> accessibilityResults =
getSortedLoadedResults(ACCESSIBLITY_LOADER_KEY);
int dbSize = databaseResults.size();
int appSize = installedAppResults.size();
int a11ySize = accessibilityResults.size();
int dbIndex = 0;
int appIndex = 0;
int a11yIndex = 0;
int rank = SearchResult.TOP_RANK;
mStaticallyRankedSearchResults.clear();
@@ -277,6 +284,9 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
while ((appIndex < appSize) && (installedAppResults.get(appIndex).rank == rank)) {
mStaticallyRankedSearchResults.add(installedAppResults.get(appIndex++));
}
while ((a11yIndex < a11ySize) && (accessibilityResults.get(a11yIndex).rank == rank)) {
mStaticallyRankedSearchResults.add(accessibilityResults.get(a11yIndex++));
}
rank++;
}
@@ -286,6 +296,9 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
while (appIndex < appSize) {
mStaticallyRankedSearchResults.add(installedAppResults.get(appIndex++));
}
while(a11yIndex < a11ySize) {
mStaticallyRankedSearchResults.add(accessibilityResults.get(a11yIndex++));
}
}
private void updateSearchResults() {
@@ -318,10 +331,13 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
getUnsortedLoadedResults(DB_RESULTS_LOADER_KEY);
List<? extends SearchResult> installedAppResults =
getSortedLoadedResults(APP_RESULTS_LOADER_KEY);
List<? extends SearchResult> accessibilityResults =
getSortedLoadedResults(ACCESSIBLITY_LOADER_KEY);
int dbSize = databaseResults.size();
int appSize = installedAppResults.size();
int a11ySize = accessibilityResults.size();
final List<SearchResult> asyncRankingResults = new ArrayList<>(dbSize + appSize);
final List<SearchResult> asyncRankingResults = new ArrayList<>(dbSize + appSize + a11ySize);
TreeSet<SearchResult> dbResultsSortedByScores = new TreeSet<>(
new Comparator<SearchResult>() {
@Override
@@ -339,8 +355,9 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
});
dbResultsSortedByScores.addAll(databaseResults);
asyncRankingResults.addAll(dbResultsSortedByScores);
// App results are not ranked by async ranking and appended at the end of the list.
// Other results are not ranked by async ranking and appended at the end of the list.
asyncRankingResults.addAll(installedAppResults);
asyncRankingResults.addAll(accessibilityResults);
return asyncRankingResults;
}