summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2013-10-07 02:41:58 -0700
committerMartijn Coenen <maco@google.com>2013-10-09 09:07:57 +0200
commit341b2c02da8b4d2a681f3fbcc5657921ad421e32 (patch)
tree8c87de05d42b26625eadd7c77cb06f9a256bfbc1
parent43dc7d3d2160c5fbd063e27c2810b87f4626e75f (diff)
downloadandroid_packages_apps_Nfc-341b2c02da8b4d2a681f3fbcc5657921ad421e32.tar.gz
android_packages_apps_Nfc-341b2c02da8b4d2a681f3fbcc5657921ad421e32.tar.bz2
android_packages_apps_Nfc-341b2c02da8b4d2a681f3fbcc5657921ad421e32.zip
Disable HCE debug logging.
But add some code to dump information about the HCE service/AID cache in bugreports. Bug: 11142134 Change-Id: I7387748bcf93e92ab2f25bc307941cdeccaca4ef
-rwxr-xr-xsrc/com/android/nfc/NfcService.java9
-rw-r--r--src/com/android/nfc/cardemulation/AidRoutingManager.java8
-rw-r--r--src/com/android/nfc/cardemulation/RegisteredAidCache.java42
-rw-r--r--src/com/android/nfc/cardemulation/RegisteredServicesCache.java49
4 files changed, 80 insertions, 28 deletions
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index c14f8f87..4d81ae71 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -506,7 +506,7 @@ public class NfcService implements DeviceHostListener {
mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, null);
PackageManager pm = mContext.getPackageManager();
- mIsHceCapable = pm.hasSystemFeature(PackageManager.FEATURE_NFC_HCE);
+ mIsHceCapable = pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION);
if (mIsHceCapable) {
mAidRoutingManager = new AidRoutingManager();
mAidCache = new RegisteredAidCache(mContext, mAidRoutingManager);
@@ -686,7 +686,7 @@ public class NfcService implements DeviceHostListener {
Log.d(TAG,"NFC is off. Checking firmware version");
mDeviceHost.checkFirmware();
// Build initial AID cache even if NFC is off
- if (mAidCache != null) {
+ if (mIsHceCapable) {
mAidCache.invalidateCache(ActivityManager.getCurrentUser());
}
}
@@ -2492,7 +2492,7 @@ public class NfcService implements DeviceHostListener {
}
} else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
mP2pLinkManager.onUserSwitched();
- if (mAidCache != null) {
+ if (mIsHceCapable) {
mAidCache.invalidateCache(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
}
}
@@ -2554,6 +2554,9 @@ public class NfcService implements DeviceHostListener {
pw.println("mIsAirplaneToggleable=" + mIsAirplaneToggleable);
pw.println("mOpenEe=" + mOpenEe);
mP2pLinkManager.dump(fd, pw, args);
+ if (mIsHceCapable) {
+ mAidCache.dump(fd, pw, args);
+ }
mNfceeAccessControl.dump(fd, pw, args);
mNfcDispatcher.dump(fd, pw, args);
pw.println(mDeviceHost.dump());
diff --git a/src/com/android/nfc/cardemulation/AidRoutingManager.java b/src/com/android/nfc/cardemulation/AidRoutingManager.java
index 232f5226..154bcf3e 100644
--- a/src/com/android/nfc/cardemulation/AidRoutingManager.java
+++ b/src/com/android/nfc/cardemulation/AidRoutingManager.java
@@ -28,6 +28,8 @@ import java.util.Set;
public class AidRoutingManager {
static final String TAG = "AidRoutingManager";
+ static final boolean DBG = false;
+
// This is the default IsoDep protocol route; it means
// that for any AID that needs to be routed to this
// destination, we won't need to add a rule to the routing
@@ -78,7 +80,7 @@ public class AidRoutingManager {
int route;
synchronized (mLock) {
int currentRoute = getRouteForAidLocked(aid);
- Log.d(TAG, "Set route for AID: " + aid + ", host: " + onHost + " , current: 0x" +
+ if (DBG) Log.d(TAG, "Set route for AID: " + aid + ", host: " + onHost + " , current: 0x" +
Integer.toHexString(currentRoute));
route = onHost ? 0 : DEFAULT_OFFHOST_ROUTE;
if (route == currentRoute) return true;
@@ -119,7 +121,7 @@ public class AidRoutingManager {
synchronized (mLock) {
Integer route = mRouteForAid.get(aid);
if (route == null) {
- Log.e(TAG, "removeAid(): No existing route for " + aid);
+ if (DBG) Log.d(TAG, "removeAid(): No existing route for " + aid);
return false;
}
Set<String> aids = mAidRoutingTable.get(route);
@@ -140,7 +142,7 @@ public class AidRoutingManager {
NfcService.getInstance().commitRouting();
mDirty = false;
} else {
- Log.d(TAG, "Not committing routing because table not dirty.");
+ if (DBG) Log.d(TAG, "Not committing routing because table not dirty.");
}
}
}
diff --git a/src/com/android/nfc/cardemulation/RegisteredAidCache.java b/src/com/android/nfc/cardemulation/RegisteredAidCache.java
index 7b45291a..ff426846 100644
--- a/src/com/android/nfc/cardemulation/RegisteredAidCache.java
+++ b/src/com/android/nfc/cardemulation/RegisteredAidCache.java
@@ -17,6 +17,8 @@ import android.util.Log;
import com.google.android.collect.Maps;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -29,7 +31,7 @@ import java.util.TreeMap;
public class RegisteredAidCache implements RegisteredServicesCache.Callback {
static final String TAG = "RegisteredAidCache";
- static final boolean DBG = true;
+ static final boolean DBG = false;
// mAidServices is a tree that maps an AID to a list of handling services
// on Android. It is only valid for the current user.
@@ -100,6 +102,9 @@ public class RegisteredAidCache implements RegisteredServicesCache.Callback {
mServiceCache = new RegisteredServicesCache(context, this);
mRoutingManager = routingManager;
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT),
+ true, mSettingsObserver, UserHandle.USER_ALL);
updateFromSettingsLocked(ActivityManager.getCurrentUser());
}
@@ -582,19 +587,46 @@ public class RegisteredAidCache implements RegisteredServicesCache.Callback {
synchronized (mLock) {
mNfcEnabled = false;
}
- mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
mServiceCache.onNfcDisabled();
mRoutingManager.onNfccRoutingTableCleared();
}
public void onNfcEnabled() {
- mContext.getContentResolver().registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT),
- true, mSettingsObserver, UserHandle.USER_ALL);
synchronized (mLock) {
mNfcEnabled = true;
updateFromSettingsLocked(ActivityManager.getCurrentUser());
}
mServiceCache.onNfcEnabled();
}
+
+ String dumpEntry(Map.Entry<String, AidResolveInfo> entry) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" \"" + entry.getKey() + "\"\n");
+ ApduServiceInfo defaultService = entry.getValue().defaultService;
+ ComponentName defaultComponent = defaultService != null ?
+ defaultService.getComponent() : null;
+
+ for (ApduServiceInfo service : entry.getValue().services) {
+ sb.append(" ");
+ if (service.getComponent().equals(defaultComponent)) {
+ sb.append("*DEFAULT* ");
+ }
+ sb.append(service.getComponent() +
+ " (Description: " + service.getDescription() + ")\n");
+ }
+ return sb.toString();
+ }
+
+ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ mServiceCache.dump(fd, pw, args);
+ pw.println("AID cache entries: ");
+ for (Map.Entry<String, AidResolveInfo> entry : mAidCache.entrySet()) {
+ pw.println(dumpEntry(entry));
+ }
+ pw.println("Category defaults: ");
+ for (Map.Entry<String, ComponentName> entry : mCategoryDefaults.entrySet()) {
+ pw.println(" " + entry.getKey() + "->" + entry.getValue());
+ }
+ pw.println("");
+ }
}
diff --git a/src/com/android/nfc/cardemulation/RegisteredServicesCache.java b/src/com/android/nfc/cardemulation/RegisteredServicesCache.java
index 836322f2..2e037d2c 100644
--- a/src/com/android/nfc/cardemulation/RegisteredServicesCache.java
+++ b/src/com/android/nfc/cardemulation/RegisteredServicesCache.java
@@ -17,6 +17,7 @@
package com.android.nfc.cardemulation;
import org.xmlpull.v1.XmlPullParserException;
+
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -36,7 +37,9 @@ import android.util.SparseArray;
import com.google.android.collect.Maps;
+import java.io.FileDescriptor;
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -47,7 +50,7 @@ import java.util.concurrent.atomic.AtomicReference;
public class RegisteredServicesCache {
static final String TAG = "RegisteredServicesCache";
- static final boolean DEBUG = true;
+ static final boolean DEBUG = false;
final Context mContext;
final AtomicReference<BroadcastReceiver> mReceiver;
@@ -89,8 +92,8 @@ public class RegisteredServicesCache {
public void onReceive(Context context, Intent intent) {
final int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
String action = intent.getAction();
+ if (DEBUG) Log.d(TAG, "Intent action: " + action);
if (uid != -1) {
- if (DEBUG) Log.d(TAG, "Intent action: " + action);
boolean replaced = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false) &&
(Intent.ACTION_PACKAGE_ADDED.equals(action) ||
Intent.ACTION_PACKAGE_REMOVED.equals(action));
@@ -108,6 +111,22 @@ public class RegisteredServicesCache {
}
};
mReceiver = new AtomicReference<BroadcastReceiver>(receiver);
+
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
+ intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+ intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+ intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+ intentFilter.addAction(Intent.ACTION_PACKAGE_FIRST_LAUNCH);
+ intentFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
+ intentFilter.addDataScheme("package");
+ mContext.registerReceiverAsUser(mReceiver.get(), UserHandle.ALL, intentFilter, null, null);
+
+ // Register for events related to sdcard operations
+ IntentFilter sdFilter = new IntentFilter();
+ sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
+ sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
+ mContext.registerReceiverAsUser(mReceiver.get(), UserHandle.ALL, sdFilter, null, null);
}
void dump(ArrayList<ApduServiceInfo> services) {
@@ -155,24 +174,10 @@ public class RegisteredServicesCache {
}
public void onNfcDisabled() {
- mContext.unregisterReceiver(mReceiver.get());
+
}
public void onNfcEnabled() {
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
- intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
- intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
- intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
- intentFilter.addDataScheme("package");
- mContext.registerReceiverAsUser(mReceiver.get(), UserHandle.ALL, intentFilter, null, null);
-
- // Register for events related to sdcard operations
- IntentFilter sdFilter = new IntentFilter();
- sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
- sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
- mContext.registerReceiverAsUser(mReceiver.get(), UserHandle.ALL, sdFilter, null, null);
-
invalidateCache(ActivityManager.getCurrentUser());
}
@@ -244,4 +249,14 @@ public class RegisteredServicesCache {
mCallback.onServicesUpdated(userId, Collections.unmodifiableList(validServices));
dump(validServices);
}
+
+ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ pw.println("Registered HCE services for current user: ");
+ UserServices userServices = findOrCreateUserLocked(ActivityManager.getCurrentUser());
+ for (ApduServiceInfo service : userServices.services.values()) {
+ pw.println(" " + service.getComponent() +
+ " (Description: " + service.getDescription() + ")");
+ }
+ pw.println("");
+ }
}