Understanding command through adb shell and throug

2019-01-03 07:13发布

I am trying to give BATTERSTATS permission to an app. When I run the command from a PC - it works just fine:

adb shell pm grant com.example.sample.myapplication android.permission.BATTERY_STATS

But the same pm grant command does not work when run from Android app:

java.lang.Process process = Runtime.getRuntime().exec("pm grant com.example.sample.myapplication android.permission.BATTERY_STATS");

Does it require root permission to give this permission? If it is so, why it does not require the device to be rooted to run it via adb shell?

I am new to Android, please explain a bit more clearly what is happening inside and how to proceed.

1条回答
Anthone
2楼-- · 2019-01-03 07:52

The command you run with adb shell gets executed with shell(UID=2000) user privileges. The command you run from your java code gets executed with your app's UID privileges. Thus the difference.

查看更多
登录 后发表回答