2016-04-18 9 views
1

私は、ネイティブのAndroidコードベースを理解しようとしています。アクセス許可がチェックされるコードの部分を知りたいと思います。たとえば、SMSを送信する場合は、次の関数が必要です。public void sendDataMessage(String destinationAddress、String scAddress、short destinationPort、byte [] data、PendingIntent sentIntent、PendingIntent deliveryIntent)これと一緒に私はパーミッションを宣言する必要がありますAndroidマニフェストのSEND_SMS私が許可を宣言しなければ、私はセキュリティの例外を得る。しかし、私はSmsManager.javaのコードでこの部分を見つけられませんでした。これは関数です。アクセス許可のチェックのためのクラス

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のさまざまな権限チェック機能への呼び出しを期待していましたが、そうではありません。私はいくつかの同様の質問hereを発見したところで、パッケージがLinuxユーザにどのようにリンクされているかを話します。しかし、私はそれが正確にチェックされているコードを通過したいと思います。

答えて

1

sendTextMessage()メソッドは、ISmsオブジェクトをインスタンス化します。次に、インターフェイスで定義されたsendText()メソッドを呼び出します。

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

ここで、ISmsはインターフェイスです。 getService()メソッドから返されたオブジェクトがこのインタフェースを実装している必要があります。幸いなことに、このインタフェースを拡張するのは2つのクラスだけです。最初はIccSmsInterfaceManagerであり、もう1つはIccSmsInterfaceManagerProxy(これは無視しています)です。

IccSmsInterfaceManagerクラスは、 '/frameworks/base/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java'にあります。このクラスのsendText()メソッドは、私たちの関心事であるパー​​ミッションチェックを実行します。

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

このenforceCallingPermissionコールが最終的に以下のクラスを介してPackageManagerにアップ土地、

、コンテキスト> ActivityManager - > PackageManagerService

出典:Chasing Android System Calls Down The Rabbit Hole、最後にアクセス:2016年7月20日

+0

感謝多くのVishal。素晴らしい説明。 :) –

関連する問題