Search code examples
androidandroid-permissions

Is it possible to grant INJECT_EVENTS permission to an app for dev/testing purposes


I'm working on an app that gets installed into system/app (the apk gets delivered to phone manufacturers who include into the system image).

I want to perform some proof of concept experiments that requires adding the INJECT_EVENTS permission to the app. AFAIK, in order for an app to be granted this permission a) it needs to be a system app and b) it needs to be signed with the system certificate.

a) is no problem as that is where the app will go eventually, and I'm also working with a rooted device.

However I don't have the system certificate for b).

In order to develop and test the app before it gets delivered to the phone manufacturers, is there a way I can grant this permission to the app?

adb shell pm grant "app package" android.permission.INJECT_EVENTS results in this:

Operation not allowed: java.lang.SecurityException: Permission android.permission.INJECT_EVENTS is not a changeable permission type

Solution

  • The adb shell is not a SU user. use the RunTime to inject shell commands as SU. Use any tool to grant you SU privileges, then execute your command

    Process suProcess = Runtime.getRuntime().exec("su pm grant 'app package' android.permission.INJECT_EVENTS");
    suProcess.waitFor();