Androidはワンツーパンチ 三歩進んで二歩下がる

プログラミングやどうでもいい話

メール送信でIntent.ACTION_SENDTOを使う際にメールアドレスがlogcatに表示されないようにする『Android アプリのセキュア設計・セキュアコーディングガイド』メモ

JSSECさまの『Android アプリのセキュア設計・セキュアコーディングガイド』を読ませていただいているので忘れないようにメモです。
内容はリンク先を是非ともご覧くださいませ。

メール送信でIntent.ACTION_SENDTOを使う際にメールアドレスがlogcatに表示されないようにするには

以下の様なUriにメールアドレスを含めるとような書き方だと
logcatにメールアドレスが表示されてしまう。

String mail = "hoge@hage.com";
Uri uri = Uri.parse("mailto:" + mail);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(intent);

こんな感じ

03-31 23:24:10.811: I/ActivityManager(1442): Starting: Intent { act=android.intent.action.SENDTO dat=hoge@hage.com cmp=com.google.android.gm/.ComposeActivityGmail } from pid 14074
03-31 23:24:10.831: I/ActivityManager(1442): Starting: Intent { act=android.intent.action.SENDTO dat=hoge@hage.com flg=0x2000000 cmp=com.google.android.gm/.ComposeActivity } from pid 13750

以下の様にUriにメールアドレスを含めず、Extrasを使うような書き方だと
logcatにメールアドレスが表示されなくなる。

String mail = "hoge@hage.com";
Uri uri = Uri.parse("mailto:");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { mail });
startActivity(intent);

こんな感じ

03-31 23:24:59.891: I/ActivityManager(1442): Starting: Intent { act=android.intent.action.SENDTO dat=mailto: cmp=com.google.android.gm/.ComposeActivityGmail (has extras) } from pid 14074
03-31 23:24:59.951: I/ActivityManager(1442): Starting: Intent { act=android.intent.action.SENDTO dat=mailto: flg=0x2000000 cmp=com.google.android.gm/.ComposeActivity (has extras) } from pid 13750