protected-broadcast

1.6のgitコミット差分を見ていたら、Broadcastの一部がSystemからしかSendできないようになっていた。確かにこれまではウソのシステム通知が可能で、自作アプリからぼんぼんシステムエラーを起こすことができた。それがAndroidの思想かと思っていたが、やはり対応したのだな。

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=commitdiff;h=a8675f67e33bc7337d148358783b0fd138b501ff

AndroidManifest.xmlというタグが追加されている。ここに記載することで、そのActionは守られるようになる。


../core/res/AndroidManifest.xml<-- ================================================ --><-- Special broadcasts that only the system can send --><-- ================================================ -->



























Broadcastの送信処理は、ActivityManagerServiceに実態がある。ここで、callingUidがシステムからの送信要求であるかを見るように変更が加えられている。


../services/java/com/android/server/am/ActivityManagerService.java

/*
* Prevent non-system code (defined here to be non-persistent
* processes) from sending protected broadcasts.
*/
if (callingUid == Process.SYSTEM_UID || callingUid == Process.PHONE_UID
|| callingUid == Process.SHELL_UID || callingUid == 0) {
// Always okay.
} else if (callerApp == null || !callerApp.persistent) {
try {
if (ActivityThread.getPackageManager().isProtectedBroadcast(
intent.getAction())) {
String msg = "Permission Denial: not allowed to send broadcast "
+ intent.getAction() + " from pid="
+ callingPid + ", uid=" + callingUid;
Log.w(TAG, msg);
throw new SecurityException(msg);
}
} catch (RemoteException e) {
Log.w(TAG, "Remote exception", e);
return BROADCAST_SUCCESS;
}
}