AppProvider extends FDroidProvider { @Override public Cursor query(@NonNull Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) { AppQuerySelection selection = new AppQuerySelection(customSelection, selectionArgs); boolean includeSwap = true; boolean repoIsKnown = false; int limit = 0; List<String> pathSegments = uri.getPathSegments(); switch (MATCHER.match(uri)) { case CALC_PREFERRED_METADATA: updatePreferredMetadata(); return null; case CODE_LIST: includeSwap = false; break; case CODE_SINGLE: long repoId = Long.parseLong(pathSegments.get(1)); String packageName = pathSegments.get(2); selection = selection.add(querySingle(packageName, repoId)); repoIsKnown = true; break; case CAN_UPDATE: selection = selection.add(queryCanUpdate()); includeSwap = false; break; case REPO: selection = selection.add(queryRepo(Long.parseLong(uri.getLastPathSegment()))); repoIsKnown = true; break; case INSTALLED: selection = selection.add(queryInstalled()); sortOrder = Cols.NAME; includeSwap = false; break; case SEARCH_TEXT: selection = selection.add(querySearch(pathSegments.get(1))); includeSwap = false; break; case SEARCH_TEXT_AND_CATEGORIES: selection = selection .add(querySearch(pathSegments.get(1))) .add(queryCategory(pathSegments.get(2))); includeSwap = false; break; case SEARCH_REPO: selection = selection .add(querySearch(pathSegments.get(2))) .add(queryRepo(Long.parseLong(pathSegments.get(1)))); repoIsKnown = true; break; case CATEGORY: selection = selection.add(queryCategory(uri.getLastPathSegment())); includeSwap = false; break; case TOP_FROM_CATEGORY: selection = selection.add(queryCategory(pathSegments.get(2))); limit = Integer.parseInt(pathSegments.get(1)); sortOrder = getTableName() + "." + Cols.LAST_UPDATED + " DESC"; includeSwap = false; break; case INSTALLED_WITH_KNOWN_VULNS: selection = selection.add(queryInstalledWithKnownVulns()); includeSwap = false; break; case RECENTLY_UPDATED: String table = getTableName(); String isNew = table + "." + Cols.LAST_UPDATED + " <= " + table + "." + Cols.ADDED + " DESC"; String hasFeatureGraphic = table + "." + Cols.FEATURE_GRAPHIC + " IS NULL ASC "; String lastUpdated = table + "." + Cols.LAST_UPDATED + " DESC"; sortOrder = lastUpdated + ", " + isNew + ", " + hasFeatureGraphic; limit = 200; includeSwap = false; break; case HIGHEST_PRIORITY: selection = selection.add(queryPackageName(uri.getLastPathSegment())); includeSwap = false; break; default: Log.e(TAG, "Invalid URI for app content provider: " + uri); throw new UnsupportedOperationException("Invalid URI for app content provider: " + uri); } if (!repoIsKnown) { selection = selection.add(queryHighestPriority()); } return runQuery(uri, selection, projection, includeSwap, sortOrder, limit); }  static Uri getContentUri(); static Uri getRecentlyUpdatedUri(); static Uri getCategoryUri(String category); static Uri getInstalledWithKnownVulnsUri(); static Uri getTopFromCategoryUri(String category, int limit); static Uri getInstalledUri(); static Uri getCanUpdateUri(); static Uri getRepoUri(Repo repo); static Uri getSpecificAppUri(String packageName, long repoId); static Uri getHighestPriorityMetadataUri(String packageName); static Uri getSearchUri(String query, @Nullable String category); static Uri getSearchUri(Repo repo, String query); static String getAuthority(); @Override Cursor query(@NonNull Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder); @Override int delete(@NonNull Uri uri, String where, String[] whereArgs); @Override Uri insert(@NonNull Uri uri, ContentValues values); @Override int update(@NonNull Uri uri, ContentValues values, String where, String[] whereArgs);  }
@Test public void testQuery() { Cursor cursor = queryAllApps(); assertNotNull(cursor); cursor.close(); }