diff options
author | Jeff Hamilton <jham@android.com> | 2011-08-11 11:49:45 -0500 |
---|---|---|
committer | Jeff Hamilton <jham@android.com> | 2011-10-25 16:38:15 -0500 |
commit | 416e2fc507d696486a127f932105b3b95519d0cb (patch) | |
tree | c23f2e6b8f67dea0d81e592b166fff664369c534 /src/com | |
parent | 96fec5b58860068460d642d7102c4804a2adbd6c (diff) | |
download | packages_apps_nfc-416e2fc507d696486a127f932105b3b95519d0cb.zip packages_apps_nfc-416e2fc507d696486a127f932105b3b95519d0cb.tar.gz packages_apps_nfc-416e2fc507d696486a127f932105b3b95519d0cb.tar.bz2 |
Add event logs for NFC events.
Change-Id: I5607abe5d28ef9682afa084651c50aa651655b60
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/nfc/EventLogTags.logtags | 12 | ||||
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 12 | ||||
-rwxr-xr-x | src/com/android/nfc/P2pLinkManager.java | 90 |
3 files changed, 105 insertions, 9 deletions
diff --git a/src/com/android/nfc/EventLogTags.logtags b/src/com/android/nfc/EventLogTags.logtags new file mode 100644 index 0000000..40a60b3 --- /dev/null +++ b/src/com/android/nfc/EventLogTags.logtags @@ -0,0 +1,12 @@ +# See system/core/logcat/event.logtags for a description of the format of this file. + +option java_package com.android.nfc + +# logged on the first P2P sharing event +90000 nfc_first_share +# logged when a P2P transaction succeeds +90001 nfc_share (size|1|2),(tnf|1),(type|3),(aar_present|1),(duration|1|3) +# logged when a P2P transaction fails +90002 nfc_share_fail (size|1|2),(tnf|1),(type|3),(aar_present|1) +# data is either the URL or MIME type +90003 nfc_ndef_received (size|1|2),(tnf|1),(type|3),(aar_present|1) diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index b955714..337930e 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -90,12 +90,12 @@ public class NfcService extends Application implements DeviceHostListener { public static final String PREF = "NfcServicePrefs"; - private static final String PREF_NFC_ON = "nfc_on"; - private static final boolean NFC_ON_DEFAULT = true; - private static final String PREF_NDEF_PUSH_ON = "ndef_push_on"; - private static final boolean NDEF_PUSH_ON_DEFAULT = true; - - private static final String PREF_FIRST_BOOT = "first_boot"; + static final String PREF_NFC_ON = "nfc_on"; + static final boolean NFC_ON_DEFAULT = true; + static final String PREF_NDEF_PUSH_ON = "ndef_push_on"; + static final boolean NDEF_PUSH_ON_DEFAULT = true; + static final String PREF_FIRST_BEAM = "first_beam"; + static final String PREF_FIRST_BOOT = "first_boot"; static final int MSG_NDEF_TAG = 0; static final int MSG_CARD_EMULATION = 1; diff --git a/src/com/android/nfc/P2pLinkManager.java b/src/com/android/nfc/P2pLinkManager.java index 5c5be9f..466453d 100755 --- a/src/com/android/nfc/P2pLinkManager.java +++ b/src/com/android/nfc/P2pLinkManager.java @@ -25,6 +25,7 @@ import com.android.nfc.snep.SnepServer; import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; import android.content.Context; +import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -36,6 +37,7 @@ import android.os.AsyncTask; import android.os.Handler; import android.os.Message; import android.os.RemoteException; +import android.os.SystemClock; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Profile; import android.util.Log; @@ -43,6 +45,8 @@ import android.util.Log; import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.Charsets; +import java.util.Arrays; import java.util.List; /** @@ -134,6 +138,8 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba NdefMessage mStaticNdef; INdefPushCallback mCallbackNdef; SendTask mSendTask; + SharedPreferences mPrefs; + boolean mFirstBeam; public P2pLinkManager(Context context) { mNdefPushServer = new NdefPushServer(NDEFPUSH_SAP, mNppCallback); @@ -147,6 +153,8 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba mSendState = SEND_STATE_NOTHING_TO_SEND; mIsSendEnabled = false; mIsReceiveEnabled = false; + mPrefs = context.getSharedPreferences(NfcService.PREF, Context.MODE_PRIVATE); + mFirstBeam = mPrefs.getBoolean(NfcService.PREF_FIRST_BEAM, true); } /** @@ -285,7 +293,14 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba } } - void onSendComplete() { + void onSendComplete(NdefMessage msg, long elapsedRealtime) { + if (mFirstBeam) { + EventLogTags.writeNfcFirstShare(); + mPrefs.edit().putBoolean(NfcService.PREF_FIRST_BEAM, false).apply(); + mFirstBeam = false; + } + EventLogTags.writeNfcShare(getMessageSize(msg), getMessageTnf(msg), getMessageType(msg), + getMessageAarPresent(msg), (int) elapsedRealtime); // Make callbacks on UI thread mHandler.sendEmptyMessage(MSG_SEND_COMPLETE); } @@ -319,6 +334,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba m = mMessageToSend; } + long time = SystemClock.elapsedRealtime(); try { if (DBG) Log.d(TAG, "Sending ndef via SNEP"); result = doSnepProtocol(m); @@ -331,9 +347,12 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba result = new NdefPushClient().push(m); } - if (DBG) Log.d(TAG, "SendTask result=" + result); + time = SystemClock.elapsedRealtime() - time; + + if (DBG) Log.d(TAG, "SendTask result=" + result + ", time ms=" + time); + if (result) { - onSendComplete(); + onSendComplete(m, time); } return null; } @@ -382,6 +401,8 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba }; void onReceiveComplete(NdefMessage msg) { + EventLogTags.writeNfcNdefReceived(getMessageSize(msg), getMessageTnf(msg), + getMessageType(msg), getMessageAarPresent(msg)); // Make callbacks on UI thread mHandler.obtainMessage(MSG_RECEIVE_COMPLETE, msg).sendToTarget(); } @@ -394,6 +415,11 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba if (mLinkState != LINK_STATE_DEBOUNCE) { break; } + if (mSendState == SEND_STATE_SENDING) { + EventLogTags.writeNfcShareFail(getMessageSize(mMessageToSend), + getMessageTnf(mMessageToSend), getMessageType(mMessageToSend), + getMessageAarPresent(mMessageToSend)); + } if (DBG) Log.d(TAG, "Debounce timeout"); mLinkState = LINK_STATE_DOWN; mSendState = SEND_STATE_NOTHING_TO_SEND; @@ -439,6 +465,64 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba return true; } + int getMessageSize(NdefMessage msg) { + if (msg != null) { + return msg.toByteArray().length; + } else { + return 0; + } + } + + int getMessageTnf(NdefMessage msg) { + if (msg == null) { + return NdefRecord.TNF_EMPTY; + } + NdefRecord records[] = msg.getRecords(); + if (records == null || records.length == 0) { + return NdefRecord.TNF_EMPTY; + } + return records[0].getTnf(); + } + + String getMessageType(NdefMessage msg) { + if (msg == null) { + return "null"; + } + NdefRecord records[] = msg.getRecords(); + if (records == null || records.length == 0) { + return "null"; + } + NdefRecord record = records[0]; + switch (record.getTnf()) { + case NdefRecord.TNF_ABSOLUTE_URI: + // The actual URI is in the type field, don't log it + return "uri"; + case NdefRecord.TNF_EXTERNAL_TYPE: + case NdefRecord.TNF_MIME_MEDIA: + case NdefRecord.TNF_WELL_KNOWN: + return new String(record.getType(), Charsets.UTF_8); + default: + return "unknown"; + } + } + + int getMessageAarPresent(NdefMessage msg) { + if (msg == null) { + return 0; + } + NdefRecord records[] = msg.getRecords(); + if (records == null) { + return 0; + } + for (NdefRecord record : records) { + if (record.getTnf() == NdefRecord.TNF_EXTERNAL_TYPE && + Arrays.equals(NdefRecord.RTD_ANDROID_APP, record.getType())) { + return 1; + } + } + return 0; + } + @Override public void onP2pSendConfirmed() { if (DBG) Log.d(TAG, "onP2pSendConfirmed()"); |