diff options
author | Martijn Coenen <maco@google.com> | 2013-09-11 17:52:18 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-11 17:52:18 +0000 |
commit | b7e5692b62cf0f3f1b02d8dc1008f3faf12df584 (patch) | |
tree | 7ab79d3939be5836fb5b8ad7715abac32bb93782 /core | |
parent | e9aad4ae31caeb00f95d83119c2020f4cb5f345c (diff) | |
parent | 58d2065984646a61145df285d1c77b68b1f700fb (diff) | |
download | frameworks_base-b7e5692b62cf0f3f1b02d8dc1008f3faf12df584.zip frameworks_base-b7e5692b62cf0f3f1b02d8dc1008f3faf12df584.tar.gz frameworks_base-b7e5692b62cf0f3f1b02d8dc1008f3faf12df584.tar.bz2 |
Merge "Add support for loading banners from HCE services." into klp-dev
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/nfc/cardemulation/ApduServiceInfo.java | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/core/java/android/nfc/cardemulation/ApduServiceInfo.java b/core/java/android/nfc/cardemulation/ApduServiceInfo.java index d3e5752..40a3612 100644 --- a/core/java/android/nfc/cardemulation/ApduServiceInfo.java +++ b/core/java/android/nfc/cardemulation/ApduServiceInfo.java @@ -22,6 +22,7 @@ import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; +import android.content.res.Resources.NotFoundException; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.drawable.Drawable; @@ -80,10 +81,15 @@ public final class ApduServiceInfo implements Parcelable { final boolean mRequiresDeviceUnlock; /** + * The id of the service banner specified in XML. + */ + final int mBannerResourceId; + + /** * @hide */ public ApduServiceInfo(ResolveInfo info, boolean onHost, String description, - ArrayList<AidGroup> aidGroups, boolean requiresUnlock) { + ArrayList<AidGroup> aidGroups, boolean requiresUnlock, int bannerResource) { this.mService = info; this.mDescription = description; this.mAidGroups = aidGroups; @@ -95,6 +101,7 @@ public final class ApduServiceInfo implements Parcelable { this.mCategoryToGroup.put(aidGroup.category, aidGroup); this.mAids.addAll(aidGroup.aids); } + this.mBannerResourceId = bannerResource; } public ApduServiceInfo(PackageManager pm, ResolveInfo info, boolean onHost) @@ -141,6 +148,9 @@ public final class ApduServiceInfo implements Parcelable { mRequiresDeviceUnlock = sa.getBoolean( com.android.internal.R.styleable.HostApduService_requireDeviceUnlock, false); + mBannerResourceId = sa.getResourceId( + com.android.internal.R.styleable.HostApduService_apduServiceBanner, -1); + sa.recycle(); } else { TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.OffHostApduService); @@ -148,6 +158,9 @@ public final class ApduServiceInfo implements Parcelable { mDescription = sa.getString( com.android.internal.R.styleable.OffHostApduService_description); mRequiresDeviceUnlock = false; + mBannerResourceId = sa.getResourceId( + com.android.internal.R.styleable.HostApduService_apduServiceBanner, -1); + sa.recycle(); } mAidGroups = new ArrayList<AidGroup>(); @@ -183,6 +196,7 @@ public final class ApduServiceInfo implements Parcelable { } else { currentGroup = new AidGroup(groupCategory, groupDescription); } + groupAttrs.recycle(); } else if (eventType == XmlPullParser.END_TAG && "aid-group".equals(tagName) && currentGroup != null) { if (currentGroup.aids.size() > 0) { @@ -206,6 +220,7 @@ public final class ApduServiceInfo implements Parcelable { } else { Log.e(TAG, "Ignoring invalid or duplicate aid: " + aid); } + a.recycle(); } } } catch (NameNotFoundException e) { @@ -248,6 +263,21 @@ public final class ApduServiceInfo implements Parcelable { return mService.loadIcon(pm); } + public Drawable loadBanner(PackageManager pm) { + Resources res; + try { + res = pm.getResourcesForApplication(mService.serviceInfo.packageName); + Drawable banner = res.getDrawable(mBannerResourceId); + return banner; + } catch (NotFoundException e) { + Log.e(TAG, "Could not load banner."); + return null; + } catch (NameNotFoundException e) { + Log.e(TAG, "Could not load banner."); + return null; + } + } + static boolean isValidAid(String aid) { if (aid == null) return false; @@ -302,6 +332,7 @@ public final class ApduServiceInfo implements Parcelable { dest.writeTypedList(mAidGroups); } dest.writeInt(mRequiresDeviceUnlock ? 1 : 0); + dest.writeInt(mBannerResourceId); }; public static final Parcelable.Creator<ApduServiceInfo> CREATOR = @@ -317,7 +348,8 @@ public final class ApduServiceInfo implements Parcelable { source.readTypedList(aidGroups, AidGroup.CREATOR); } boolean requiresUnlock = (source.readInt() != 0) ? true : false; - return new ApduServiceInfo(info, onHost, description, aidGroups, requiresUnlock); + int bannerResource = source.readInt(); + return new ApduServiceInfo(info, onHost, description, aidGroups, requiresUnlock, bannerResource); } @Override |