I'm reading the docs https://developer.android.com/reference/android/content/ContentProvider.html#setReadPermission(java.lang.String) and it says Change the permission required to read data from the content provider. This is normally set for you from its manifest information when the provider is first created.
But I'm unable to change permission on a new one. I tried to call this in constructor and in onCreate()
, but nothing was changed. When I run command from adb to update the data, I receive error Permission Denial: opening provider com.test.MyContentProvider from (null) (pid=5641, uid=2000) requires OLD.PERMISSION
How to solve that? Thanks
UPD with my code:
<permission android:name="test.test.TEST" android:protectionLevel="signature" />
<uses-permission android:name="test.test.TEST" />
<provider
android:name="com.test.MyContentProvider"
android:authorities="com.test"
android:enabled="true"
android:exported="true">
</provider>
MyContentProvider.java:
public class MyContentProvider extends ContentProvider {
public MyContentProvider() {
setReadPermission("test.test.TEST");
setWritePermission("test.test.TEST");
}
@Override
public boolean onCreate() {
setReadPermission("test.test.TEST");
setWritePermission("test.test.TEST");
return true;
}
// ...
}
So when I try to call from ADB the following command it successfully finishes (but shouldn't because it was updated to the permission with signature protection level)
content insert --uri content://com.test/x --bind column_name:s:new_value
And vise versa if I setup read&write permissions in manifest to the signature permission and after reset it to a normal permission, I get error that says that I miss required permission (the old one)