#navi_header|技術| AndroidManifest.xmlでの""と"android:permission"属性の使用例+メモ。 #more|| #outline|| ---- * 実験 - "PermissionTest1" : Activity, BroadcastReceiver, Serviceを用意しているアプリ。全てのコンポーネントでIntentFilterを設定せず、パッケージ名とクラス名で直接呼び出すものとする。それぞれ次の5パターンを用意。 -- android:exported=false : 外部非公開。IntentFilterが無いので、特に指定しない場合のデフォルト設定。 -- android:exported=true : 外部公開。 -- Intent有り + android:exported 指定なし : IntentFilterが有るため、exported省略時は外部公開。 -- Intent有り + android:exported=false : IntentFilterが有るが、exported=falseなので外部非公開。 -- Intent有り + android:exported=true : IntentFilterが有り、外部公開。 -- android:permission="test.perms1.TESTPERM_NORMAL" : "normal"レベルのpermissionを要求(+外部公開)。 -- android:permission="test.perms1.TESTPERM_DANGEROUS" : "dangerous"レベルのpermissionを要求(+外部公開)。 -- android:permission="test.perms1.TESTPERM_SIGNATURE" : "signature"レベルのpermissionを要求(+外部公開)。 - "PermissionTest2" : PermissionTest1の各コンポーネントを呼び出すアプリ。AndroidManifest.xmlで必要な""を定義済み。PermissionTest1と同じ証明書で署名する。 - "PermissionTest3" : PermissionTest2と内容は同じだが、PermissionTest1,2と異なる証明書で署名する。 Activityは表示されたか否か、BroadcastReceiver/ServiceはLogを出力するようにしてそれで判定する。PermissionTest2,3でもstartActivity()/sendBroadcast()/startService()それぞれtry-catchで囲み、ThrowableをLogに出力するようにしている。 予想としては、外部非公開は全て呼べない、それ以外はPermissionTest3だけ、"signature"レベルのpermissionが署名違いで呼べない結果になると思われる。 ** サンプルコード bitbucketにてMercurialで公開: - https://bitbucket.org/msakamoto_sf/androidpermissionsamples //[[yb://medias/android/PermissionTestEx01.zip]] - PermissionTest1のAndroidManifest.xml -- https://bitbucket.org/msakamoto_sf/androidpermissionsamples/src/4985d5cddd5b/PermissionTest1/AndroidManifest.xml - test.perms2.Main.java: PermissionTest2で使っている呼び出しコード(PermissionTest3も同様) -- https://bitbucket.org/msakamoto_sf/androidpermissionsamples/src/4985d5cddd5b/PermissionTest2/src/test/perms2/Main.java --- Spinnerで呼び出したいActivity/Receiver/Serviceを選択するようになってる。 - res/values/strings.xml: -- https://bitbucket.org/msakamoto_sf/androidpermissionsamples/src/4985d5cddd5b/PermissionTest1/res/values/strings.xml ** 結果 予想通り + android:exported="false"の非公開は呼べない。 + PermissionTest3でのみ、"signature"レベルのpermissionが署名違いで呼べない。 という結果になった。 ただしReceiverについてはIntentFilter有りのexported無しが非公開扱いになっており、これだけ予想と異なっていた。 Activity: | | PermissionTest2 | PermissionTest3 | | android:exported=false | SecurityException: Permission Denial | 同左 | | android:exported=true | o | o | | IntentFilter有り + exported無し | o | o | | IntentFilter有り + exported=false | SecurityException: Permission Denial | 同左 | | IntentFilter有り + exported=true | o | o | | "normal" level | o | o | | "dangerous" level | o | o | | "signature" level | o | SecurityException: Permission Denial | BroadcastReceiver: | | PermissionTest2 | PermissionTest3 | | android:exported=false | (Log-WARN): Permission Denial | 同左 | | android:exported=true | o | o | | IntentFilter有り + exported無し | (Log-WARN): Permission Denial | 同左 | | IntentFilter有り + exported=false | (Log-WARN): Permission Denial | 同左 | | IntentFilter有り + exported=true | o | o | | "normal" level | o | o | | "dangerous" level | o | o | | "signature" level | o | (Log-WARN): Permission Denial | Service: | | PermissionTest2 | PermissionTest3 | | android:exported=false | SecurityException: Not allowed to start service Intent | 同左 | | android:exported=true | o | o | | IntentFilter有り + exported無し | o | o | | IntentFilter有り + exported=false | SecurityException: Not allowed to start service Intent | 同左 | | IntentFilter有り + exported=true | o | o | | "normal" level | o | o | | "dangerous" level | o | o | | "signature" level | o | SecurityException: Not allowed to start service Intent | ** 参考資料 - Security and Permissions | Android Developers -- http://developer.android.com/guide/topics/security/security.html - コンテントプロバイダを公開しない方法 - haruserのめもちょ -- http://d.hatena.ne.jp/haruser/20090823/1251042430 - ContentProvider で特定のアプリにのみ利用を許可する - おともだち革命 -- http://d.hatena.ne.jp/s5r/20110225/1298613278 #navi_footer|技術|