FileProvder Security Exception in library

325 Views Asked by At

I have a library which needs to have a fileprovider and in order to prevent conflict with the implementing app's FileProvider, I used the approach mentioned here. Although the library has no issues building and the library tested in the sample application, It throws the below exception.

Note: Despite the exception, I'm able to share the content out to other apps using share intent. I'm going clueless why the exception occurs while still the files are shared without any crash.

Exception:

E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.library.package.reporter.FilesProvider uri content://com.library.package.sample.com.library.package.provider.fileprovider/./reports/2020-03-28%2022%3A42%3A50_report.txt from pid=3158, uid=1000 requires the provider be exported, or grantUriPermission()
    at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729)
    at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602)
    at android.content.ContentProvider$Transport.query(ContentProvider.java:231)
    at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104)
    at android.os.Binder.execTransactInternal(Binder.java:1021)
    at android.os.Binder.execTransact(Binder.java:994)

Manifest:

<provider
        android:name=".reporter.FilesProvider"
        android:authorities="${applicationId}.com.library.package.provider.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths" />
    </provider>

FileProvider Usage:

Uri uri = FilesProvider.getUriForFile(getApplicationContext(), getPackageName() + ".com.library.package.provider.fileprovider", new File(filePath));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TEXT, content);
intent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.intent_share_title)));

Should I just ignore the crash and move on or is there something I'm doing wrong?

0

There are 0 best solutions below