android P广播权限问题Background execution not allowed: receiving Intent和系统受保护广播问题调查

1、隐式广播权限

android O系统后,隐式广播收到的限制,一定要指定包名才能发送出来。
否则会报错:
Background execution not allowed: receiving Intent { act=android.bluetooth.anw.action.PAIR_REQUEST flg=0x10 (has extras) } to com.anwsdk.sample/.BTMsgReceiver

但是在实际开发测试时,有些旧的app应用还是发送的隐式广播,导致接收不到,临时修改系统源码解决:
源码:\frameworks\base\services\core\java\com\android\server\am\BroadcastQueue.java
processNextBroadcastLocked()对广播进行了判断和处理:

       if (!skip) {
            final int allowed = mService.getAppStartModeLocked(
                    info.activityInfo.applicationInfo.uid, info.activityInfo.packageName,
                    info.activityInfo.applicationInfo.targetSdkVersion, -1, true, false, false);
            if (allowed != ActivityManager.APP_START_MODE_NORMAL) {
                // We won't allow this receiver to be launched if the app has been
                // completely disabled from launches, or it was not explicitly sent
                // to it and the app is in a state that should not receive it
                // (depending on how getAppStartModeLocked has determined that).
                if (allowed == ActivityManager.APP_START_MODE_DISABLED) {
                    Slog.w(TAG, "Background execution disabled: receiving "
                            + r.intent + " to "
                            + component.flattenToShortString());
                    skip = true;
                } else if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0)
                        || (r.intent.getComponent() == null
                            && r.intent.getPackage() == null
                            && ((r.intent.getFlags()
                                    & Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND) == 0)
                            && !isSignaturePerm(r.requiredPermissions))) {
                    mService.addBackgroundCheckViolationLocked(r.intent.getAction(),
                            component.getPackageName());
                    Slog.w(TAG, "Background execution not allowed: receiving "
                            + r.intent + " to "
                            + component.flattenToShortString());
			
					//取消skip=true,让广播依旧可以发送出去
                    //skip = true;
                }
            }
        }

2、受保护的广播

报错:
ActivityManager: Sending non-protected broadcast …Throwable at

系统中发送的广播必须是受保护的广播,否则发送失败。

源码:\frameworks\base\core\res\AndroidManifest.xml

增加:

    <protected-broadcast android:name="android.intent.action.DOCK_IDLE" />
    <protected-broadcast android:name="android.intent.action.DOCK_ACTIVE" />
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunxiaolin2016

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值