yuliskov/SmartTube · error · IllegalArgumentException

Unknown Uri: ${uri}

Error message

Unknown Uri: ${uri}

What it means

VideoContentProvider is the read-only search-suggestions ContentProvider that feeds Android TV / Leanback global search. Its query() routes the URI through a UriMatcher that only accepts the pattern '<authority>/search/search_suggest_query/*' (authority comes from R.string.search_authority); every other URI throws IllegalArgumentException('Unknown Uri: ' + uri).

Source

Thrown at leanbackassistant/src/main/java/com/liskovsoft/leanbackassistant/search/VideoContentProvider.java:118

    @Override
    public Cursor query(
            @NonNull Uri uri,
            @Nullable String[] projection,
            @Nullable String selection,
            @Nullable String[] selectionArgs,
            @Nullable String sortOrder) {

        Log.d(TAG, uri.toString());

        if (mUriMatcher.match(uri) == SEARCH_SUGGEST) {
            Log.d(TAG, "Search suggestions requested.");

            //String limitStr = uri.getQueryParameter("limit");
            //int limit = limitStr != null ? Integer.parseInt(limitStr) : SEARCH_LIMIT;
            return search(uri.getLastPathSegment(), SEARCH_LIMIT);
        } else {
            Log.d(TAG, "Unknown uri to query: " + uri);
            throw new IllegalArgumentException("Unknown Uri: " + uri);
        }
    }

    public static MediaItem findVideoWithId(int id) {
        if (sCachedMediaItems == null) {
            return null;
        }

        for (MediaItem video : sCachedMediaItems) {
            if (video != null && video.getId() == id) {
                return video;
            }
        }

        return null;
    }

    private Cursor search(String query, int limit) {

View on GitHub (pinned to 3de8d90593)

Solutions

  1. Diff the incoming URI (the provider already logs it: Log.d(TAG, uri.toString())) against the expected '<authority>/search/search_suggest_query/*' pattern.
  2. Build the query URI from the framework constant: authority + '/search/' + SearchManager.SUGGEST_URI_PATH_QUERY + '/' + query — never hand-concatenate paths.
  3. Make sure the authority in the manifest <provider android:authorities>, the searchable.xml android:searchSuggestAuthority value, and the client code all use the identical string.
  4. If you fork the provider and need more endpoints, add them to buildUriMatcher() instead of assuming only search exists.

Example fix

// before — hand-built URI, wrong path
Uri uri = Uri.parse("content://" + AUTHORITY + "/videos");
getContentResolver().query(uri, null, null, null, null); // throws Unknown Uri

// after — framework search-suggest path
Uri uri = Uri.parse("content://" + AUTHORITY
        + "/search/" + SearchManager.SUGGEST_URI_PATH_QUERY
        + "/" + Uri.encode(query));
Cursor c = getContentResolver().query(uri, null, null, null, null);
Defensive patterns

Strategy: validation

Validate before calling

String SUGGEST_PATH = "/search/" + SearchManager.SUGGEST_URI_PATH_QUERY; // "/search/search_suggest_query"

boolean isSearchSuggestUri(Uri uri) {
    return uri != null
            && AUTHORITY.equals(uri.getAuthority())
            && uri.getPath() != null
            && uri.getPath().startsWith(SUGGEST_PATH);
}

// use
Uri uri = Uri.parse("content://" + AUTHORITY + SUGGEST_PATH + "/" + Uri.encode(q));
if (isSearchSuggestUri(uri)) {
    Cursor c = getContentResolver().query(uri, null, null, null, null);
}

Try / catch

try {
    Cursor c = getContentResolver().query(uri, null, null, null, null);
} catch (IllegalArgumentException e) { // Unknown Uri
    Log.w(TAG, "Bad provider URI: " + uri, e);
    // skip gracefully — never retry the same URI unchanged
}

Prevention

When it happens

Trigger: Calling ContentResolver.query() with a URI whose authority differs from the manifest provider authority, or whose path is not /search/search_suggest_query[/<query>] — e.g. content://<authority>/videos or content://wrong.authority/search/search_suggest_query/test.

Common situations: The manifest authorities string or R.string.search_authority was renamed but the querying side (searchables.xml meta-data or client code) was not updated; hand-built exploratory URIs via adb shell content query; a different app targeting the provider with a stale or misspelled authority.

Related errors


AI-assisted analysis of yuliskov/SmartTube@3de8d90593 (2026-08-22). Data as JSON: /api/errors/d17da045cc0e33bb. Report an issue: GitHub.