权限检查类Android [英] Classes for Permission Checks Android

查看:103
本文介绍了权限检查类Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解本机Android代码库.我想知道代码中检查权限的部分.例如,如果我要发送短信,则需要使用以下功能: public void sendDataMessage(字符串destinationAddress,字符串scAddress,short destinationPort,byte []数据,PendingIntent sentIntent,PendingIntent deliveryIntent)需要在Android清单中声明权限 SEND_SMS .如果我不声明该权限,则会收到一个安全异常.但是我没有在SmsManager.java的代码中找到这部分.这是函数:

I am trying to understand the native Android Code Base. I would like to know the part of the code where permissions are checked. For eg if I want to send an SMS, I need the function : public void sendDataMessage (String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) Together with this I need to declare the permission SEND_SMS in the Android Manifest. If I dont declare the permission, I get a security Exception. But I didn't find this part in the code in the SmsManager.java. This is the function:

public void sendDataMessage(
        String destinationAddress, String scAddress, short destinationPort,
        byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) {
    if (TextUtils.isEmpty(destinationAddress)) {
        throw new IllegalArgumentException("Invalid destinationAddress");
    }

    if (data == null || data.length == 0) {
        throw new IllegalArgumentException("Invalid message data");
    }

    try {
        ISms iccISms = getISmsServiceOrThrow();
        iccISms.sendDataForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(),
                destinationAddress, scAddress, destinationPort & 0xFFFF,
                data, sentIntent, deliveryIntent);
    } catch (RemoteException ex) {
        // ignore it
    }
}

因此要在哪里检查权限.我正在寻找代码的一部分,在发送SMS之前,Android会检查SEND_SMS权限.我期待在PackageManager中调用各种权限检查功能,但事实并非如此.我在此处找到了一些类似的问题有关如何将软件包链接到linux用户的信息.但是我想浏览一下经过精确检查的代码.

So where exactly are the permissions checked. I am looking for the part of the code where before sending the SMS, Android checks for the SEND_SMS permission. I was expecting a call to various permission Check functions in the PackageManager but it is not the case. I found a few similar questions here where they talk about how the packages are linked to linux users. But I would like to go through the code where it is precisely checked.

推荐答案

sendTextMessage()方法实例化一个ISms对象.然后,它将调用在接口中定义的sendText()方法.

The sendTextMessage() method instantiates an ISms object. It then calls the sendText() method defined in the interface.

 ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
         if (iccISms != null) {
             iccISms.sendText(destinationAddress, scAddress, text, sentIntent, deliveryIntent);
         }

这里ISms是一个接口.因此,由getService()方法返回的对象必须实现此接口.幸运的是,只有两个类扩展了此接口.第一个是IccSmsInterfaceManager,另一个是IccSmsInterfaceManagerProxy(我忽略了这个).

here ISms is an interface. so the object returned by getService() method must be implementing this interface. Luckily only two classes extend this interface. The first being IccSmsInterfaceManager and the other being IccSmsInterfaceManagerProxy (I ignored this one).

可以在"/frameworks/base/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java"中找到IccSmsInterfaceManager类.此类的sendText()方法执行权限检查,这是我们的关注点.

The IccSmsInterfaceManager class can be found in '/frameworks/base/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java'. The sendText() method of this class performs the permission check which is our point of interest.

 mPhone.getContext().enforceCallingPermission(
            "android.permission.SEND_SMS",
            "Sending SMS message");

此forceCallCallingPermission调用最终通过以下类进入PackageManager

this enforceCallingPermission call ultimately lands up in the PackageManager through following classes,

上下文-> ActivityManager-> PackageManagerService

context-> ActivityManager -> PackageManagerService

来源:追赶Android系统会压倒兔子Hole ,上次访问时间:2016年7月20日

Source:Chasing Android System Calls Down The Rabbit Hole , last accessed: jul 20, 2016

这篇关于权限检查类Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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