Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
packages_apps_Nfc
Commits
f5c40bdb
Commit
f5c40bdb
authored
13 years ago
by
Jeff Hamilton
Committed by
Nick Pelly
13 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Add event logs for NFC events. DO NOT MERGE
Bug: 5128799 Change-Id: I5607abe5d28ef9682afa084651c50aa651655b60
parent
0e16fed3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
10 deletions
+124
-10
Android.mk
Android.mk
+19
-1
src/com/android/nfc/EventLogTags.logtags
src/com/android/nfc/EventLogTags.logtags
+12
-0
src/com/android/nfc/NfcService.java
src/com/android/nfc/NfcService.java
+6
-6
src/com/android/nfc/P2pLinkManager.java
src/com/android/nfc/P2pLinkManager.java
+87
-3
No files found.
Android.mk
View file @
f5c40bdb
...
...
@@ -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))
This diff is collapsed.
Click to expand it.
src/com/android/nfc/EventLogTags.logtags
0 → 100644
View file @
f5c40bdb
# 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)
This diff is collapsed.
Click to expand it.
src/com/android/nfc/NfcService.java
View file @
f5c40bdb
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
src/com/android/nfc/P2pLinkManager.java
View file @
f5c40bdb
...
...
@@ -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()"
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment