summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Hamilton <jham@android.com>2011-10-28 07:30:43 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-28 07:30:43 -0700
commit79faaaec4f99360b1f9a3503b85433b6e77c7898 (patch)
tree9ffc4920f930a14dad36b732def2ce8c8fad561c
parentfb21ff7547c2a8af66645bdc6be7daf7450e15af (diff)
parenta907d6f8c670ca07c0b09f3537fa6eecdc6d36b9 (diff)
downloadpackages_apps_nfc-79faaaec4f99360b1f9a3503b85433b6e77c7898.zip
packages_apps_nfc-79faaaec4f99360b1f9a3503b85433b6e77c7898.tar.gz
packages_apps_nfc-79faaaec4f99360b1f9a3503b85433b6e77c7898.tar.bz2
Merge "Add event logs for NFC events. DO NOT MERGE" into ics-mr0
-rw-r--r--Android.mk20
-rw-r--r--src/com/android/nfc/EventLogTags.logtags12
-rwxr-xr-xsrc/com/android/nfc/NfcService.java12
-rwxr-xr-xsrc/com/android/nfc/P2pLinkManager.java90
4 files changed, 124 insertions, 10 deletions
diff --git a/Android.mk b/Android.mk
index b5ae045..a041854 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,15 +3,33 @@ include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_SRC_FILES := \
+ $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := Nfc
LOCAL_CERTIFICATE := platform
+LOCAL_STATIC_JAVA_LIBRARIES := NfcLogTags
+
LOCAL_JNI_SHARED_LIBRARIES := libnfc_jni
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)
+
+#####
+# static lib for the log tags
+#####
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := src/com/android/nfc/EventLogTags.logtags
+
+LOCAL_MODULE:= NfcLogTags
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+
include $(call all-makefiles-under,$(LOCAL_PATH))
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()");