title: SecurityException in Android when calling reflected method
body: <p>I´m developing a Cache-Cleaner application, and when I invoke a hidden method in PackageManager I get a SecurityException, though I have given my app the uses-permission "DELETE_CACHE_FILES"</p>
  
  <p>The Uses-Permissions:</p>
  
  <pre><code>uses-permission android:name="android.permission.DELETE_CACHE_FILES"
  uses-permission android:name="android.permission.CLEAR_APP_CACHE"
  uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  uses-permission android:name="android.permission.CLEAR_APP_USER_DATA"
  uses-permission android:name="android.permission.GET_PACKAGE_SIZE"
  </code></pre>
  
  <p>The reflected method:</p>
  
  <pre><code>Method method = getPackageManager().getClass().getMethod("deleteApplicationCacheFiles", String.class, IPackageDataObserver.class);
  </code></pre>
  
  <p>The Error:</p>
  
  <pre><code>java.lang.reflect.InvocationTargetException
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at &lt;MY_PACKAGE_NAME&gt;.MainActivity$1.onClick(MainActivity.java:70)
  at android.view.View.performClick(View.java:2485)
  at android.view.View$PerformClick.run(View.java:9080)
  at android.os.Handler.handleCallback(Handler.java:587)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:3683)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.SecurityException: Neither user 10037 nor current process has   android.permission.DELETE_CACHE_FILES.
  at android.os.Parcel.readException(Parcel.java:1322)
  at android.os.Parcel.readException(Parcel.java:1276)
  at android.content.pm.IPackageManager$Stub$Proxy.deleteApplicationCacheFiles(IPackageManager.java:2346)
  at android.app.ContextImpl$ApplicationPackageManager.deleteApplicationCacheFiles(ContextImpl.java:2562)
  ... 14 more
  </code></pre>
  
  <p>Line 70:</p>
  
  <pre><code> method.invoke(getPackageManager(), app.packageName, dataObserver);
  </code></pre>
  
  <p>It says that I don´t have the permission, but I have decleared it in my manifest...</p>
  
  <p>EDIT:
  I found out this;</p>
  
  <pre><code>W/PackageManager(62): Not granting permission android.permission.DELETE_CACHE_FILES to package &lt;MY_PACKAGE_NAME&gt;.cachecleaner (protectionLevel=3 flags=0x8be46)
  </code></pre>
  
  <p>EDIT2:
  Declaration of deleteApplicationCacheFiles(got it via method.toGenericString()):</p>
  
  <pre><code>public void android.app.ContextImpl$ApplicationPackageManager.deleteApplicationCacheFiles(java.lang.String, android.content.pm.IPackageDataObserver)
  </code></pre>