问题描述
考虑使用广播接收器
来实现一个简单的目标的简单工具。因为这不应该被其他应用程序使用,它定义与签名
或 signatureOrSystem
A的ProtectionLevel权限:
Consider a simple tool using a BroadcastReceiver
to achieve a simple goal. Because this should not be used by other applications, it defines a permission with a protectionLevel of signature
or signatureOrSystem
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="any.test">
<permission
android:name="any.test.PERMISSION"
android:protectionLevel="signatureOrSystem" />
<application android:label="AnyTest">
<receiver
android:name=".Receiver"
android:exported="true"
android:permission="any.test.PERMISSION" />
</application>
</manifest>
现在我想用通过
adb shell am broadcast -n any.test/.Receiver
从我的计算机。虽然这个工程在模拟器上完全没有问题,它不会在所有的真实设备上时,这个权限设置工作。如果没有设置权限,一切都按预期。
from my computer. While this works perfectly fine on an emulator, it doesn't work at all on a real device when this permission is set. If the permission is not set, everything works as intended.
所以,我怎么可以定义或授予这样我就可以用 ADB测试这一切在真实设备上的权限
?
So how can I define or grant the permission so that I can test all this on a real device with ADB
?
我想使这个出口接收器一点在调试模式下更安全,因此,如果有一个为亚行特别批准
使用或运行时测试只允许通话从亚行
我可以在 Receiver.onReceive执行(上下文,意图)
,这将有助于太。接收器不必为亚行
,并在同一时间其他应用工作。
I want to make this exported receiver a little more secure in debug mode, so if there's a special permission for ADB
usage or a run-time test to only allow calls from ADB
I can implement in Receiver.onReceive(Context, Intent)
, it would help too. The receiver doesn't have to work for ADB
and other apps at the same time.
推荐答案
一个root的shell可以发送任何权限保护的任何广播。结果
一个正常的外壳也已获得很多的权限,检查AOSP源集code这个文件:框架\\基地\\包\\壳牌\\ AndroidManifest.xml中。
A root shell can send any broadcast protected by any permissions.
A normal shell also has been granted lots of permissions, check this file in the AOSP souce code: frameworks\base\packages\Shell\AndroidManifest.xml.
替换您的 any.test.PERMISSION
在此文件中的ProtectionLevel是 signatureOrSystem
,像 android.permission.REAL_GET_TASKS 。在此之后,您可以发送广播接收这个壳,但其他3应用程序不能。
Replace your any.test.PERMISSION
with one permission in this file that the protectionLevel is signatureOrSystem
, like android.permission.REAL_GET_TASKS
. After that, you can send broadcast to this receiver in shell, but other 3rd app can not.
这篇关于BroadcastReceiver的权限亚行外壳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!