android - permission denial for content provider when called from within the same app -


i have 1 app. has content provider not exported (i don't want other apps have access content) have been using content provider until now.

i have created content observer update textview. onchange method gets called when content changes , tries re-query content. that's when gets security exception looks this:

java.lang.securityexception: permission denial: reading org.sil.lcroffline.data.dataprovider uri content://org.sil.lcroffline/users/by_account_name/5555544444 pid=0, uid=1000 requires provider exported, or granturipermission()

here's code generates it:

@override public void onchange(boolean selfchange, uri uri) {     cursor c = null;     try {         c = mcontentresolver.query(userentry.builduserphoneuri(maccount.name), null, null, null, null);         // stuff data in cursor     } {         if (c != null) c.close();     } } 

the uri looks it's formed properly, , don't think there's problem matching in content provider.

the code above works fine when called programatically within app, it's when it's triggered change in observed data exception occurs.

how permission denial within same app, , how fix this?

behold manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="org.sil.lcroffline">      <!-- communicate lcr -->     <uses-permission android:name="android.permission.get_accounts" />     <uses-permission android:name="android.permission.internet" />     <uses-permission android:name="android.permission.access_network_state" />     <!-- required because we're manually creating new account. -->     <uses-permission android:name="android.permission.authenticate_accounts"/>      <uses-permission android:name="android.permission.manage_accounts" />      <uses-permission android:name="android.permission.use_credentials" />      <uses-permission android:name="android.permission.write_sync_settings" />      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme">         <activity             android:name=".authentication.loginactivity"             android:label="@string/app_name"             android:exported="true">         </activity>         <activity             android:name=".mainactivity"             android:label="@string/title_activity_main"             android:theme="@style/apptheme.noactionbar"             android:exported="true">             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity android:name=".reportactivity"             android:parentactivityname=".mainactivity"></activity>         <service android:name=".authentication.authenticatorservice">             <intent-filter>                 <action android:name="android.accounts.accountauthenticator" />             </intent-filter>             <meta-data android:name="android.accounts.accountauthenticator"                 android:resource="@xml/authenticator" />         </service>         <provider             android:authorities="@string/data_authority"             android:name=".data.dataprovider"             android:exported="false" />         <service             android:name=".data.syncservice"             android:exported="true"             android:process=":sync">             <intent-filter>                 <action android:name="android.content.syncadapter"/>             </intent-filter>             <meta-data android:name="android.content.syncadapter"                 android:resource="@xml/syncadapter" />         </service>     </application>  </manifest> 

it turns out caused me not using handler in contentobserver

when don't pass handler content observer onchange method gets called directly instead of message call being posted through handler. , good, except process calls onchange method in situation system os, doesn't have necessary permissions query content provider.

to fixed changed code content observer created this:

muserobserver = new contentobserver(null) {     // override onchange methods here } 

to this:

muserobserver = new contentobserver(new handler()) {     // override onchange methods here } 

i clued in this question


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -