4

i need to use android.permission.CHANGE_COMPONENT_ENABLED_STATE permission in my code because i need to update the component of another apk of my project, but it don't seems really work for me

here is my code :

<permission
    android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"
    android:protectionLevel="signatureOrSystem"/>

final int permission = ctx.checkCallingPermission(android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE);

final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED);
L.d(TAG, "allowedByPermission :" + allowedByPermission + " permission:" + permission);
if(allowedByPermission) {}

allowedByPermission always log a false.. not sure if i could miss something?

AJit
  • 1,283
  • 1
  • 13
  • 34

1 Answers1

4

First, your app would need <uses-permission>, not <permission>.

Second, your app cannot hold that permission, unless it is installed on the system partition (e.g., by a rooted device user) or is signed by the same signing key that signed the system firmware.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • can you plz provide any example of ? also both apk's are generated with same signature so it should work right? – AJit Oct 10 '13 at 18:43
  • @AJit: "also both apk's are generated with same signature so it should work right?" -- no, it should not. The permission would grant you the right to disable *any* component of *any* application, and that is a very privileged operation. – CommonsWare Oct 10 '13 at 18:46
  • also can you give any clue about this CHANGE_COMPONENT_ENABLED_STATE permission? do we use only in rooted devices? – AJit Oct 10 '13 at 18:46
  • @AJit: "do we use only in rooted devices?" -- please re-read the second paragraph of my answer. – CommonsWare Oct 10 '13 at 18:47
  • really thanks for the quick replay.. still i am not sure how i can update component to another apk.. – AJit Oct 10 '13 at 18:50
  • @AJit: You cannot directly update the enabled status of a component of another APK. You are welcome to use IPC (e.g., `startService()`) to send a message from one app to the other, telling the second app to enable or disable its own component. – CommonsWare Oct 10 '13 at 18:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/39010/discussion-between-ajit-and-commonsware) – AJit Oct 10 '13 at 18:52