SecurityException: 不允许执行 OP_READ_PHONE_STATE [英] SecurityException: not allowed to perform OP_READ_PHONE_STATE

查看:149
本文介绍了SecurityException: 不允许执行 OP_READ_PHONE_STATE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户报告我的应用程序崩溃并显示此错误跟踪

User is reporting my app crashes with this error trace

java.lang.SecurityException: com.android.phone from uid 10134 not allowed to perform OP_READ_PHONE_STATE
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getVoiceMailNumberForSubscriber(IPhoneSubInfo.java:858)
at android.telephony.TelephonyManager.getVoiceMailNumber(TelephonyManager.java:2383)
at android.telephony.TelephonyManager.getVoiceMailNumber(TelephonyManager.java:2366)

到目前为止,只有一位用户报告了此问题.其他数千名用户正在运行此版本的应用,没有出现明显问题.

So far only one user has reported this problem. Several thousand other users are running this version of the app with no apparent problems.

当我们调用TelephonyManager.getVoiceMailNumber() 时抛出异常.此操作记录为需要 READ_PHONE_STATE 权限,该权限已被绝对、肯定地授予.

The exception is thrown when we call TelephonyManager.getVoiceMailNumber(). This operation is documented as required the READ_PHONE_STATE permission, which has absolutely, positively been granted.

我找到了 android.apps.AppOpsManager 类的 OP_READ_PHONE_STATE 权限,但无法弄清楚它到底有什么不满意之处.

I tracked down the OP_READ_PHONE_STATE permission to the android.apps.AppOpsManager class but can not figure out exactly what it is unhappy about.

谁能解释一下正在发生的事情以及需要做些什么来解决问题.

Can anyone explain just what is happening and what needs to be done to fix things.

谢谢,-肯

推荐答案

在 AOSP 中寻找该方法最终导致 cheakReadPhoneState() 方法.

Looking for that method in AOSP eventually leads to the cheakReadPhoneState() method.

在 Android 6 中,该方法是 此处.

In Android 6, that method was here.

在这两种情况下,它看起来都非常相似.这是 Android 6 代码:

In both cases, it looks pretty similar. Here's the Android 6 code:

private boolean checkReadPhoneState(String callingPackage, String message) {
    try {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);

        // SKIP checking run-time OP_READ_PHONE_STATE since self or using PRIVILEGED
        return true;
    } catch (SecurityException e) {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
                message);
    }

    return mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
        callingPackage) == AppOpsManager.MODE_ALLOWED;
}

首先检查READ_PRIVILEGED_PHONE_STATE 是否被授予.如果是,则其余代码将短路并返回 true.否则,它确保 READ_PHONE_STATE 被授予,否则抛出 SecurityException.

First it checks to see if READ_PRIVILEGED_PHONE_STATE is granted. If it is, then the rest of the code is short-circuited and it returns true. Otherwise, it makes sure that READ_PHONE_STATE is granted, throwing a SecurityException otherwise.

最后,如果READ_PHONE_STATE 被授予,它确保OP_READ_PHONE_STATE 也被授予.我不完全确定它为什么这样做,但这就是问题的来源.无论在哪个设备上发生此错误,运行时权限的工作方式都会发生一些变化.当授予 READ_PHONE_STATE 权限时,还应授予 OP_READ_PHONE_STATE 操作,但系统会出于任何原因撤销该操作.

Finally, if READ_PHONE_STATE is granted, it makes sure that OP_READ_PHONE_STATE is also granted. I'm not entirely sure why it's doing that, but that's where the problem is coming from. Whichever devices this error is occurring on have changed something with the way runtime permissions work. When the READ_PHONE_STATE permission is granted, the OP_READ_PHONE_STATE op should also be granted, but the system is revoking that op for whatever reason.

(也有可能是用户正在使用某个应用来管理应用操作并手动撤销了它.)

(It's also possible that the user is using an app to manage app-ops and has revoked it manually.)

为了修复它,我真的不认为你可以.您能做的最好的事情就是捕获错误并要求用户运行 ADB 命令以手动授予操作权限:

For fixing it, I don't really think you can. The best you can do is catch the error and ask that users run an ADB command to manually grant the op:

adb shell appops set com.your.packagename READ_PHONE_STATE allow.

这篇关于SecurityException: 不允许执行 OP_READ_PHONE_STATE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆