vendredi 10 mars 2017

Intrumented Test related to PendingIntent.getBroadcast()

I am trying to instrumented test my alarm module.

In the instrumented test, I try to use and set an alarm with the system Alarm service.

AlarmManager alarmMgr = (AlarmManager)  
getInstrumentation().getContext().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent("ACTION_TIMEOUT_REACHED", null,   
getInstrumentation().getContext(),ALARM_RECEIVER.class);
intent.putExtra("PARAM_ID", "123");
PendingIntent alarmIntent=PendingIntent.getBroadcast(getInstrumentation().getContext(), 0, intent, 0);
alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + millisecondUntilExpire, alarmIntent);

Upon running the test, I encounter the following error

java.lang.SecurityException: Permission Denial: getIntentSender() from pid=27923, uid=10332, (need uid=10333) is not allowed to send as package org.abc.full.test
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
at android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:4346)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:511)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:495)
at org.abc.TimeoutAlarmTest.java:68)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at        org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57 )
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1889)

My question is how to workaround this issue? It is because my package domain is different from the Manifest package declaration? My Manifest file declaration is the following

<manifest xmlns:android="http://ift.tt/nIICcg"
      xmlns:tools="http://ift.tt/LrGmb4"
      package="org.abc.def"> 

instead of

<manifest xmlns:android="http://ift.tt/nIICcg"
      xmlns:tools="http://ift.tt/LrGmb4"
      package="org.abc.full.test"> 

Aucun commentaire:

Enregistrer un commentaire