From 38d3bb76967e115b81c9f804e4de9189adfd9680 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 7 Aug 2013 20:03:03 -0700 Subject: [PATCH] NFC: Unify ApduServiceInfo for on/off host. Change-Id: I4f8bb441d7eb564da0486f3e8a1ac08dd18d0dc8 --- .../android/nfc/cardemulation/ApduServiceInfo.java | 61 +++++++++++++++------- .../nfc/cardemulation/CardEmulationManager.java | 3 +- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/core/java/android/nfc/cardemulation/ApduServiceInfo.java b/core/java/android/nfc/cardemulation/ApduServiceInfo.java index 11fd39a21944..ffa7d7ebe30b 100644 --- a/core/java/android/nfc/cardemulation/ApduServiceInfo.java +++ b/core/java/android/nfc/cardemulation/ApduServiceInfo.java @@ -60,7 +60,7 @@ public final class ApduServiceInfo implements Parcelable { final ArrayList mAids; /** - * Whether this is an {@link HostApduService} or {@link OffHostApduService} + * Whether this service represents AIDs running on the host CPU */ final boolean mOnHost; @@ -77,30 +77,37 @@ public final class ApduServiceInfo implements Parcelable { /** * @hide */ - public ApduServiceInfo(ResolveInfo info, String description, + public ApduServiceInfo(ResolveInfo info, boolean onHost, String description, ArrayList aidGroups) { this.mService = info; this.mDescription = description; this.mAidGroups = aidGroups; this.mAids = new ArrayList(); this.mCategoryToGroup = new HashMap(); - this.mOnHost = false; + this.mOnHost = onHost; for (AidGroup aidGroup : aidGroups) { this.mCategoryToGroup.put(aidGroup.category, aidGroup); this.mAids.addAll(aidGroup.aids); } } - public ApduServiceInfo(PackageManager pm, ResolveInfo info) throws XmlPullParserException, - IOException { + public ApduServiceInfo(PackageManager pm, ResolveInfo info, boolean onHost) + throws XmlPullParserException, IOException { ServiceInfo si = info.serviceInfo; - XmlResourceParser parser = null; try { - parser = si.loadXmlMetaData(pm, HostApduService.SERVICE_META_DATA); - if (parser == null) { - throw new XmlPullParserException("No " + HostApduService.SERVICE_META_DATA + - " meta-data"); + if (onHost) { + parser = si.loadXmlMetaData(pm, HostApduService.SERVICE_META_DATA); + if (parser == null) { + throw new XmlPullParserException("No " + HostApduService.SERVICE_META_DATA + + " meta-data"); + } + } else { + parser = si.loadXmlMetaData(pm, OffHostApduService.SERVICE_META_DATA); + if (parser == null) { + throw new XmlPullParserException("No " + OffHostApduService.SERVICE_META_DATA + + " meta-data"); + } } int eventType = parser.getEventType(); @@ -109,22 +116,34 @@ public final class ApduServiceInfo implements Parcelable { } String tagName = parser.getName(); - if (!"host-apdu-service".equals(tagName)) { + if (onHost && !"host-apdu-service".equals(tagName)) { throw new XmlPullParserException( "Meta-data does not start with tag"); + } else if (!onHost && !"offhost-apdu-service".equals(tagName)) { + throw new XmlPullParserException( + "Meta-data does not start with tag"); } Resources res = pm.getResourcesForApplication(si.applicationInfo); AttributeSet attrs = Xml.asAttributeSet(parser); - TypedArray sa = res.obtainAttributes(attrs, - com.android.internal.R.styleable.HostApduService); - mService = info; - mDescription = sa.getString( - com.android.internal.R.styleable.HostApduService_description); + if (onHost) { + TypedArray sa = res.obtainAttributes(attrs, + com.android.internal.R.styleable.HostApduService); + mService = info; + mDescription = sa.getString( + com.android.internal.R.styleable.HostApduService_description); + } else { + TypedArray sa = res.obtainAttributes(attrs, + com.android.internal.R.styleable.OffHostApduService); + mService = info; + mDescription = sa.getString( + com.android.internal.R.styleable.OffHostApduService_description); + } + mAidGroups = new ArrayList(); mCategoryToGroup = new HashMap(); mAids = new ArrayList(); - mOnHost = true; // TODO + mOnHost = onHost; final int depth = parser.getDepth(); AidGroup currentGroup = null; @@ -202,6 +221,10 @@ public final class ApduServiceInfo implements Parcelable { return mCategoryToGroup.containsKey(category); } + public boolean isOnHost() { + return mOnHost; + } + public CharSequence loadLabel(PackageManager pm) { return mService.loadLabel(pm); } @@ -258,6 +281,7 @@ public final class ApduServiceInfo implements Parcelable { public void writeToParcel(Parcel dest, int flags) { mService.writeToParcel(dest, flags); dest.writeString(mDescription); + dest.writeInt(mOnHost ? 1 : 0); dest.writeInt(mAidGroups.size()); if (mAidGroups.size() > 0) { dest.writeTypedList(mAidGroups); @@ -270,12 +294,13 @@ public final class ApduServiceInfo implements Parcelable { public ApduServiceInfo createFromParcel(Parcel source) { ResolveInfo info = ResolveInfo.CREATOR.createFromParcel(source); String description = source.readString(); + boolean onHost = (source.readInt() != 0) ? true : false; ArrayList aidGroups = new ArrayList(); int numGroups = source.readInt(); if (numGroups > 0) { source.readTypedList(aidGroups, AidGroup.CREATOR); } - return new ApduServiceInfo(info, description, aidGroups); + return new ApduServiceInfo(info, onHost, description, aidGroups); } @Override diff --git a/core/java/android/nfc/cardemulation/CardEmulationManager.java b/core/java/android/nfc/cardemulation/CardEmulationManager.java index 673b33a3920c..537fded58f00 100644 --- a/core/java/android/nfc/cardemulation/CardEmulationManager.java +++ b/core/java/android/nfc/cardemulation/CardEmulationManager.java @@ -56,7 +56,8 @@ public final class CardEmulationManager { public static final String EXTRA_CATEGORY = "category"; /** - * The ComponentName of the card emulation service component. + * The ComponentName object passed in as a parcelable + * extra for {@link #ACTION_CHANGE_DEFAULT} * * @see #ACTION_CHANGE_DEFAULT */ -- 2.11.0