Restricting DocumentsProvider#getType by implementing getTypeAnonymous

- getTypeAnonymous can be accessed by anyone. It does not reveal any sensitive information.

Bug: b/271262541
Test: build and manual test
Change-Id: I300a3be0904c44214f3ab206c30314855feaa57b
This commit is contained in:
Ashish Kumar
2023-03-01 14:34:42 +00:00
parent 8128beb12a
commit f81e11d51c
2 changed files with 14 additions and 0 deletions

View File

@@ -36849,6 +36849,7 @@ package android.provider {
method public String[] getDocumentStreamTypes(String, String);
method public String getDocumentType(String) throws java.io.FileNotFoundException;
method public final String getType(android.net.Uri);
method @Nullable public final String getTypeAnonymous(@NonNull android.net.Uri);
method public final android.net.Uri insert(android.net.Uri, android.content.ContentValues);
method public boolean isChildDocument(String, String);
method public String moveDocument(String, String, String) throws java.io.FileNotFoundException;

View File

@@ -978,6 +978,19 @@ public abstract class DocumentsProvider extends ContentProvider {
}
}
/**
* An unrestricted version of getType, which does not reveal sensitive information
*/
@Override
public final @Nullable String getTypeAnonymous(@NonNull Uri uri) {
switch (mMatcher.match(uri)) {
case MATCH_ROOT:
return DocumentsContract.Root.MIME_TYPE_ITEM;
default:
return null;
}
}
/**
* Implementation is provided by the parent class. Can be overridden to
* provide additional functionality, but subclasses <em>must</em> always