通过ADB Shell和代码了解命令-Android [英] Understanding command through adb shell and through code - Android
问题描述
我正在尝试为应用授予BATTERSTATS
权限.当我从PC上运行命令时-可以正常工作:
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
但是从Android应用程序运行时,相同的pm grant
命令不起作用:
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");
是否需要root权限才能授予此权限?
如果是这样,为什么不要求将设备植根以通过adb shell
运行它?
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
?
我是Android的新手,请更清楚地解释一下内部正在发生什么以及如何进行.
I am new to Android, please explain a bit more clearly what is happening inside and how to proceed.
推荐答案
使用adb shell
运行的命令将以shell(UID=2000)
用户权限执行.从java
代码运行的命令将使用应用程序的UID
特权执行.因此有所不同.
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.
这篇关于通过ADB Shell和代码了解命令-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!