SecurityException: Permission Denial: opening provider (fatal exception: asynctask #3) - android

I am building an Android Library. I kept the code as normal android project while I was developing it and now I converted it into library project (even made a new library project and copied all the code in there just to be sure). The library basically allows user to enter data into database using contentprovider and the library returns that data queried from the database. So whatever app uses the library does not need to use the contentprovider to access data since the library does it all.
I made a very basic app that uses the library, the moment that I make a call to the library the app crashes giving the error code:
FATAL EXCEPTION: AsyncTask #3
Process: com.example.testing, PID: 18991
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Permission Denial: opening provider thesis.thesis.contentprovider.UsersDataContentProvider from ProcessRecord{42a51b18 18991:com.example.testing/u0a272} (pid=18991, uid=10272) that is not exported from uid 10266
at android.os.Parcel.readException(Parcel.java:1465)
at android.os.Parcel.readException(Parcel.java:1419)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2917)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4489)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2330)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1441)
at android.content.ContentResolver.query(ContentResolver.java:448)
at android.content.CursorLoader.loadInBackground(CursorLoader.java:65)
at android.content.CursorLoader.loadInBackground(CursorLoader.java:43)
at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 3 more
I added permissions to testapp, but didnt change the error
<uses-permission android:name="thesis.thesis.contentprovider.READ_DATABASE" />
<uses-permission android:name="thesis.thesis.contentprovider.WRITE_DATABASE" />
The provider declared in library manifest:
<provider
android:name="thesis.thesis.contentprovider.UsersDataContentProvider"
android:authorities="thesis.thesis.contentprovider"
android:exported="true"
android:readPermission="thesis.thesis.contentprovider.READ_DATABASE"
android:writePermission="thesis.thesis.contentprovider.WRITE_DATABASE" />
At the moment I have exported="true" to see if that was the problem but no. Later I want it to be set false, since the data is sensitive.
Can anyone please direct me to where the problem might be. Also ask if additional information is needed.

Related

Can't access content provider from espresso test

I have an application with more modules. In module A I have a ContentProvider. In module B I am accessing to that ContentProvider. The application works fine I can access the data. My issue is when I am trying to write an android instrumented test for a certain activity. In that activity in the onCreate method I am calling an AsyncTask that needs to access the database via the ContentProvider and populate the activity with that data. In this moment I am getting an error:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.mycompany.dashboardlight.test, PID: 19196
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Caused by: java.lang.SecurityException: Permission Denial: opening provider com.mycompany.data.provider.HibpAccountProvider from ProcessRecord{7e4d57b 19196:com.mycompany.dashboardlight.test/u0a265} (pid=19196, uid=10265) that is not exported from uid 10264
at android.os.Parcel.readException(Parcel.java:1693)
at android.os.Parcel.readException(Parcel.java:1646)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4912)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:6043)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2474)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1521)
at android.content.ContentResolver.query(ContentResolver.java:520)
at android.content.ContentResolver.query(ContentResolver.java:478)
I have tried for both modules to have same shareUserId, seppration of permissions to read and write but nothing works.
This is in the manifest where the content provider is:
<provider
android:name="com.mycompany.data.provider.MyProvider"
android:authorities="${applicationId}.data.MyProvider"
android:enabled="true"
android:exported="false" />
This is the manifest in the module that is accessing the data:
<uses-permission android:name="${applicationId}.data.MyProvider" />
Creating other tests for activities that aren't accessing ContentProvider are working fine.
And this is the test:
#RunWith(AndroidJUnit4.class)
public class MyActivityTest {
#Rule
public final ActivityTestRule<MyActivity> breachMain =
new ActivityTestRule<>(MyActivity.class);
#Test
public void isLaunchScreenDetected() {
onView(withText("No Data Breach Found"))
.check(ViewAssertions.matches(isDisplayed()));
}
}
Finally a solution. The issue was in how it was defined the authority. The applicationId is different for when you are installing the application and when you are trying to test the application. When testing the application you may notice that on your package name is appended .test, and in my case since I used hardcoded value com.mypackage lower in the code this caused the permission denial. So I ended with different authorities, because the applicationId is different when installing the application and running the test.
My proposal if you are defining the AUTHORITY also in your java classes, avoid the ${applicationId} not to have a mix like this.

Getting "FATAL EXCEPTION AsyncTask #1"

I'm getting the following error while running my application in Android. I don't have any background task going on.
FATAL EXCEPTION: AsyncTask #1
Process: com.inclov.inclovapp, PID: 32532
java.lang.RuntimeException: An error occured while executing
doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:304) at
java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.SecurityException: Permission Denial: opening
provider com.android.providers.contacts.ContactsProvider2 from
ProcessRecord{2363bbc5 32532:com.inclov.inclovapp/u0a161} (pid=32532,
uid=10161) requires android.permission.READ_CONTACTS or
android.permission.WRITE_CONTACTS at
android.os.Parcel.readException(Parcel.java:1546) at
android.os.Parcel.readException(Parcel.java:1499) at
android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3503)
at
android.app.ActivityThread.acquireProvider(ActivityThread.java:5062)
at
android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2737)
at
android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1446)
at android.content.ContentResolver.query(ContentResolver.java:466) at
android.content.CursorLoader.loadInBackground(CursorLoader.java:64) at
android.content.CursorLoader.loadInBackground(CursorLoader.java:42) at
android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
at
android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
at
android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)
at android.os.AsyncTask$2.call(AsyncTask.java:292) at
java.util.concurrent.FutureTask.run(FutureTask.java:237) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
add these to you manifest:
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Read this for more info - https://developer.android.com/training/contacts-provider/retrieve-names.html#Permissions
As stated in the error , you need these permissions :
android.permission.READ_CONTACTS
or
android.permission.WRITE_CONTACTS
For lollipop and prior, you need to add this to your manifest :
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
If you are targeting Marshmallow, you need to add a request Permissions logic inside the activity using this. Follow this official Link on how to do it.

Collections.sort causing java.lang.SecurityException: Requires READ_PHONE_STATE

I am getting the crash below at this code line:
pkgMrg_global = getActivity().getPackageManager();
apps = pkgMrg_global.getInstalledApplications(0);
//GETTING CRASH AT LINE BELOW
Collections.sort(apps,
new ApplicationInfo.DisplayNameComparator(
pkgMrg_global));
What I dont understand is how Collections.sort leads to this Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10157 nor current process has android.permission.READ_PHONE_STATE?
Stacktrace:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10157 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1465)
at android.os.Parcel.readException(Parcel.java:1419)
at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getSubscriberId(IPhoneSubInfo.java:231)
at android.telephony.TelephonyManager.getSubscriberId(TelephonyManager.java:1352)
at android.app.ApplicationPackageManager.getSimOperatorNameForStk(ApplicationPackageManager.java:1548)
at android.app.ApplicationPackageManager.getText(ApplicationPackageManager.java:1109)
at android.content.pm.PackageItemInfo.loadLabel(PackageItemInfo.java:115)
at android.app.ApplicationPackageManager.getApplicationLabel(ApplicationPackageManager.java:1186)
at android.content.pm.ApplicationInfo$DisplayNameComparator.compare(ApplicationInfo.java:561)
at android.content.pm.ApplicationInfo$DisplayNameComparator.compare(ApplicationInfo.java:554)
at java.util.TimSort.binarySort(TimSort.java:261)
at java.util.TimSort.sort(TimSort.java:204)
at java.util.TimSort.sort(TimSort.java:169)
at java.util.Arrays.sort(Arrays.java:2010)
at java.util.Collections.sort(Collections.java:1883)
at com.mavdev.focusoutfacebook.fragments.addablock.apps.Fragment_appsselect_addblock$loadAppsListfromSystem.doInBackground(Fragment_appsselect_addblock.java:1830)
at com.mavdev.focusoutfacebook.fragments.addablock.apps.Fragment_appsselect_addblock$loadAppsListfromSystem.doInBackground(Fragment_appsselect_addblock.java:1802)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 4 more
As per google docs here
The note says
Note: If both your minSdkVersion and targetSdkVersion values are set to 3 or lower, the system implicitly grants your app this permission. If you don't need this permission, be sure your targetSdkVersion is 4 or higher.
Protection level: dangerous
if so you need to add the permission
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Constant Value: "android.permission.READ_PHONE_STATE"
add this permission to your android manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Olingo OData 2.0 for Android - Dependency to javax.xml.stream.XMLInputFactory

I tried to implement an OData V2 Client using Apache Olingo OData 2.0 in Android.
Executing the client class as java class works fine, but I cannot run the Android App using the same code in an AsyncTask:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.my.app.appname, PID: 2521
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.conurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
java.util.conurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLInputFactory;
at org.apache.olingo.odata2.core.commons.XmlHelper.createStreamReader(XmlHelper.java:41)
org.apache.olingo.odata2.core.edm.provider.EdmxProvider.parse(EdmxProvider.java:50)
org.apache.olingo.odata2.core.ep.ProviderFacadeImpl.readMetadata(ProviderFacadeImpl.java:224)
org.apache.olingo.odata2.api.ep.EntityProvider.readMetadata(EntityProvider.java:844)
at connectivity.MyClass.doInBackground(MyClass.java:153)
at connectivity.MyClass.doInBackground(MyClass.java:38)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237) <4 more...>
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.xml.stream.XMLInputFactory" on path: DexPathList[[zip file "/data/app/com.my.app.appname-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469) <12 more...>
Suppressed: java.lang.ClassNotFoundException: javax.xml.stream.XmlInputFactory
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.findClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
My questions are:
(How) Can I fix this issue?
(I read somewhere that the missing class might not be supported by Android?)
Would it help to switch to Apache Olingo OData 4.0?
(I need to consume an OData V2 service and if Olingo V4 would suport this on Android, I might try to migrate my client...)
Thanks in advance!
You have to repackage the javax.xml.stream classes yourself since Android does not support XML. Olingo V4 has a special android packaged client for that on the V4 dowload page: http://olingo.apache.org/doc/odata4/download.html
Olingo V2 does not have this feature because when the V2 library was created the main focus was on server side implementations. This is why a lot of convenience on client side is missing.

1895-1904/com.android.mms E/StrictMode﹕ is this my Bug?

Any help given at this stage will be appreciated, i have tried reading but now i am actually confused, The first time it was Calender i went and introduced an exception and that has gone away now i see it is mms How can i deal with this? any advice?
1895-1904/com.android.mms E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'release' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at android.drm.DrmManagerClient.<init>(DrmManagerClient.java:258)
at com.google.android.mms.pdu.PduPersister.<init>(PduPersister.java:288)
at com.google.android.mms.pdu.PduPersister.getPduPersister(PduPersister.java:299)
at com.android.mms.transaction.TransactionService.onNewIntent(TransactionService.java:231)
at com.android.mms.transaction.TransactionService$ServiceHandler.handleMessage(TransactionService.java:633)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
1989-2046/com.android.email E/EmailServiceProxy﹕ RuntimeException when trying to unbind from service
java.lang.IllegalArgumentException: Service not registered: com.android.emailcommon.service.ServiceProxy$ProxyConnection#1d27587c
at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1029)
at android.app.ContextImpl.unbindService(ContextImpl.java:1808)
at android.content.ContextWrapper.unbindService(ContextWrapper.java:551)
at com.android.emailcommon.service.ServiceProxy$ProxyConnection$1.doInBackground(ServiceProxy.java:124)
at com.android.emailcommon.service.ServiceProxy$ProxyConnection$1.doInBackground(ServiceProxy.java:111)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
If you are building a custom ROM and are modifying the com.android.mms and com.android.email apps, then perhaps these are your issues.
Otherwise, they are issues for the developers of the com.android.mms and com.android.email apps.

Categories

Resources