Understanding command through adb shell and through code - Android

℡╲_俬逩灬. 提交于 2019-11-26 03:45:29

问题


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:


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.



来源:https://stackoverflow.com/questions/38824114/understanding-command-through-adb-shell-and-through-code-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!