android sdk 23 instrumentation permissions problems (java.lang.SecurityException) -


trying simple app insert record phone book. looks don't have problems permissions, system won't let create record anyway:

07-28 18:11:44.799  2304 10616 updateicingcorporaservi: updating corpora: apps=com.example.aero.myapplication, contacts=maybe 07-28 18:11:45.362  2304 10648 updateicingcorporaservi: updating corpora: apps=com.example.aero.myapplication.test, contacts=maybe 07-28 18:11:45.651 10663 10678 grantpermissioncallable: permission: android.permission.write_contacts granted! 07-28 18:11:46.255 10663 10678 ok      : contact permission record allowed 07-28 18:11:46.255 10663 10678 d info    : creating contact: 123456789 07-28 18:11:46.259  2097  2114 e databaseutils: java.lang.securityexception: proxy package com.android.providers.contacts uid 10001 or calling package com.example.aero.myapplication.test uid 10097 not allowed perform write_contacts 07-28 18:11:46.260 10663 10678 e error   : exception encountered while inserting contact: java.lang.securityexception: proxy package com.android.providers.contacts uid 10001 or calling package com.example.aero.myapplication.test uid 10097 not allowed perform write_contacts 

any ideas? why mystique? once run app install 2 apk:

$ adb push /users/aero/androidstudioprojects/myapplication/app/build/outputs/apk/app-debug.apk /data/local/tmp/com.example.aero.myapplication $ adb shell pm install -r "/data/local/tmp/com.example.aero.myapplication" 

and

$ adb push /users/aero/androidstudioprojects/myapplication/app/build/outputs/apk/app-debug-androidtest.apk /data/local/tmp/com.example.aero.myapplication.test $ adb shell pm install -r "/data/local/tmp/com.example.aero.myapplication.test" 

and com.example.aero.myapplication has permissions in system, com.example.aero.myapplication.test doesn't have permissions. i've lost little bit.

package com.example.aero.myapplication;   import android.manifest; import android.app.instrumentation; import android.content.contentprovideroperation; import android.content.context; import android.content.intent; import android.content.pm.packagemanager; import android.os.bundle; import android.os.environment; import android.provider.contactscontract; import android.support.test.instrumentationregistry; import android.support.test.filters.sdksuppress; import android.support.test.rule.grantpermissionrule; import android.support.test.runner.androidjunit4; import android.support.test.uiautomator.by; import android.support.test.uiautomator.uidevice; import android.support.v4.app.activitycompat; import android.support.v7.app.appcompatactivity; import android.util.log;  import org.junit.before; import org.junit.rule; import org.junit.runner.runwith;  import java.util.arraylist;  import static org.hamcrest.corematchers.notnullvalue; import static org.junit.assert.assertthat;   @runwith(androidjunit4.class) public class mainactivity{      @rule     public grantpermissionrule permissionrule = grantpermissionrule.grant(manifest.permission.write_contacts);      public instrumentation instrumentation;     private uidevice mdevice;     private static final int record_request_code = 101;       @before     public void before() {         // initialize uidevice instance         mdevice = uidevice.getinstance(instrumentationregistry.getinstrumentation());         //instrumentation = instrumentationregistry.getinstrumentation();         assertthat(mdevice, notnullvalue());         // start home screen         mdevice.presshome();     }      @org.junit.test     public void test() throws interruptedexception {         context context = instrumentationregistry.getinstrumentation().getcontext();         string name = "test record";         string nmbr = "123456789";         createphonebookentry(context, name, nmbr);     }      public void createphonebookentry(context context, string name, string nmbr) {         //activitycompat.requestpermissions(context,         //        new string[]{manifest.permission.write_contacts},         //        record_request_code)           int permission = activitycompat.checkselfpermission(context,                 manifest.permission.write_contacts);          if (permission != packagemanager.permission_granted) {             log.i("error", "contact permission record denied");         } else {             log.i("ok", "contact permission record allowed");             };          /*      * gets values ui      */         // creates new array of contentprovideroperation objects.         arraylist<contentprovideroperation> ops =                 new arraylist<contentprovideroperation>();      /*      * creates new raw contact account type (server type) , account name      * (user's account). remember display name not stored in row, in      * structuredname data row. no other data required.      */         contentprovideroperation.builder op =                 contentprovideroperation.newinsert(contactscontract.rawcontacts.content_uri)                         .withvalue(contactscontract.rawcontacts.account_type, null)                         .withvalue(contactscontract.rawcontacts.account_name, null);          // builds operation , adds array of operations         ops.add(op.build());          // creates display name new raw contact, structuredname data row.         op =                 contentprovideroperation.newinsert(contactscontract.data.content_uri)             /*              * withvaluebackreference sets value of first argument value of              * contentproviderresult indexed second argument. in particular              * call, raw contact id column of structuredname data row set              * value of result returned first operation, 1              * adds raw contact row.              */                         .withvaluebackreference(contactscontract.data.raw_contact_id, 0)                          // sets data row's mime type structuredname                         .withvalue(contactscontract.data.mimetype,                                 contactscontract.commondatakinds.structuredname.content_item_type)                          // sets data row's display name name in ui.                         .withvalue(contactscontract.commondatakinds.structuredname.display_name, name);          // builds operation , adds array of operations         ops.add(op.build());          // inserts specified phone number , type phone data row         op =                 contentprovideroperation.newinsert(contactscontract.data.content_uri)             /*              * sets value of raw contact id column new raw contact id returned              * first operation in batch.              */                         .withvaluebackreference(contactscontract.data.raw_contact_id, 0)                          // sets data row's mime type phone                         .withvalue(contactscontract.data.mimetype,                                 contactscontract.commondatakinds.phone.content_item_type)                          // sets phone number , type                         .withvalue(contactscontract.commondatakinds.phone.number, nmbr)                         .withvalue(contactscontract.commondatakinds.phone.type, "mobile");          // builds operation , adds array of operations         ops.add(op.build());         // ask contacts provider create new contact         log.d("info", "creating contact: " + nmbr);      /*      * applies array of contentprovideroperation objects in batch. results      * discarded.      */         try {             context.getcontentresolver().applybatch(contactscontract.authority, ops);         } catch (exception e) {             // log exception             log.e("error", "exception encountered while inserting contact: " + e);         }     } } 


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -