1616
1717package android .nfc ;
1818
19- import android .nfc .technology .IsoDep ;
20- import android .nfc .technology .MifareClassic ;
21- import android .nfc .technology .MifareUltralight ;
22- import android .nfc .technology .NfcV ;
23- import android .nfc .technology .Ndef ;
24- import android .nfc .technology .NdefFormatable ;
25- import android .nfc .technology .NfcA ;
26- import android .nfc .technology .NfcB ;
27- import android .nfc .technology .NfcF ;
28- import android .nfc .technology .TagTechnology ;
19+ import android .nfc .tech .TagTechnology ;
2920import android .os .Bundle ;
3021import android .os .Parcel ;
3122import android .os .Parcelable ;
32- import android .os .RemoteException ;
3323
3424import java .util .Arrays ;
3525
4434 * {@link Tag} objects are passed to applications via the {@link NfcAdapter#EXTRA_TAG} extra
4535 * in {@link NfcAdapter#ACTION_TAG_DISCOVERED} intents. A {@link Tag} object is immutable
4636 * and represents the state of the tag at the time of discovery. It can be
47- * directly queried for its UID and Type, or used to create a {@link TagTechnology}
48- * (with {@link NfcAdapter#getTechnology}) .
37+ * directly queried for its UID and Type, or used to create a {@link TagTechnology} using the
38+ * static <code>get()</code> methods on the varios tech classes .
4939 * <p>
5040 * A {@link Tag} can be used to create a {@link TagTechnology} only while the tag is in
5141 * range. If it is removed and then returned to range, then the most recent
@@ -61,14 +51,16 @@ public class Tag implements Parcelable {
6151 /*package*/ final int [] mTechList ;
6252 /*package*/ final Bundle [] mTechExtras ;
6353 /*package*/ final int mServiceHandle ; // for use by NFC service, 0 indicates a mock
54+ /*package*/ final INfcTag mTagService ;
6455
6556 /*package*/ int mConnectedTechnology ;
6657
6758 /**
6859 * Hidden constructor to be used by NFC service and internal classes.
6960 * @hide
7061 */
71- public Tag (byte [] id , int [] techList , Bundle [] techListExtras , int serviceHandle ) {
62+ public Tag (byte [] id , int [] techList , Bundle [] techListExtras , int serviceHandle ,
63+ INfcTag tagService ) {
7264 if (techList == null ) {
7365 throw new IllegalArgumentException ("rawTargets cannot be null" );
7466 }
@@ -77,23 +69,23 @@ public Tag(byte[] id, int[] techList, Bundle[] techListExtras, int serviceHandle
7769 // Ensure mTechExtras is as long as mTechList
7870 mTechExtras = Arrays .copyOf (techListExtras , techList .length );
7971 mServiceHandle = serviceHandle ;
72+ mTagService = tagService ;
8073
8174 mConnectedTechnology = -1 ;
8275 }
8376
8477 /**
8578 * Construct a mock Tag.
86- * <p>This is an application constructed tag, so NfcAdapter methods on this
87- * Tag such as {@link NfcAdapter#getTechnology} may fail with
88- * {@link IllegalArgumentException} since it does not represent a physical Tag.
79+ * <p>This is an application constructed tag, so NfcAdapter methods on this Tag may fail
80+ * with {@link IllegalArgumentException} since it does not represent a physical Tag.
8981 * <p>This constructor might be useful for mock testing.
9082 * @param id The tag identifier, can be null
9183 * @param techList must not be null
9284 * @return freshly constructed tag
9385 */
9486 public static Tag createMockTag (byte [] id , int [] techList , Bundle [] techListExtras ) {
9587 // set serviceHandle to 0 to indicate mock tag
96- return new Tag (id , techList , techListExtras , 0 );
88+ return new Tag (id , techList , techListExtras , 0 , null );
9789 }
9890
9991 /**
@@ -127,7 +119,16 @@ public int[] getTechnologyList() {
127119 return Arrays .copyOf (mTechList , mTechList .length );
128120 }
129121
130- /*package*/ TagTechnology getTechnology (NfcAdapter adapter , int tech ) {
122+ /** @hide */
123+ public boolean hasTech (int techType ) {
124+ for (int tech : mTechList ) {
125+ if (tech == techType ) return true ;
126+ }
127+ return false ;
128+ }
129+
130+ /** @hide */
131+ public Bundle getTechExtras (int tech ) {
131132 int pos = -1 ;
132133 for (int idx = 0 ; idx < mTechList .length ; idx ++) {
133134 if (mTechList [idx ] == tech ) {
@@ -139,44 +140,12 @@ public int[] getTechnologyList() {
139140 return null ;
140141 }
141142
142- Bundle extras = mTechExtras [pos ];
143- try {
144- switch (tech ) {
145- case TagTechnology .NFC_A : {
146- return new NfcA (adapter , this , extras );
147- }
148- case TagTechnology .NFC_B : {
149- return new NfcB (adapter , this , extras );
150- }
151- case TagTechnology .ISO_DEP : {
152- return new IsoDep (adapter , this , extras );
153- }
154- case TagTechnology .NFC_V : {
155- return new NfcV (adapter , this , extras );
156- }
157- case TagTechnology .NDEF : {
158- return new Ndef (adapter , this , tech , extras );
159- }
160- case TagTechnology .NDEF_FORMATABLE : {
161- return new NdefFormatable (adapter , this , tech , extras );
162- }
163- case TagTechnology .NFC_F : {
164- return new NfcF (adapter , this , extras );
165- }
166- case TagTechnology .MIFARE_CLASSIC : {
167- return new MifareClassic (adapter , this , extras );
168- }
169- case TagTechnology .MIFARE_ULTRALIGHT : {
170- return new MifareUltralight (adapter , this , extras );
171- }
143+ return mTechExtras [pos ];
144+ }
172145
173- default : {
174- throw new UnsupportedOperationException ("Tech " + tech + " not supported" );
175- }
176- }
177- } catch (RemoteException e ) {
178- return null ;
179- }
146+ /** @hide */
147+ public INfcTag getTagService () {
148+ return mTagService ;
180149 }
181150
182151 @ Override
@@ -223,6 +192,7 @@ public void writeToParcel(Parcel dest, int flags) {
223192 dest .writeIntArray (mTechList );
224193 dest .writeTypedArray (mTechExtras , 0 );
225194 dest .writeInt (mServiceHandle );
195+ dest .writeStrongBinder (mTagService .asBinder ());
226196 }
227197
228198 public static final Parcelable .Creator <Tag > CREATOR =
@@ -235,8 +205,9 @@ public Tag createFromParcel(Parcel in) {
235205 in .readIntArray (techList );
236206 Bundle [] techExtras = in .createTypedArray (Bundle .CREATOR );
237207 int serviceHandle = in .readInt ();
208+ INfcTag tagService = INfcTag .Stub .asInterface (in .readStrongBinder ());
238209
239- return new Tag (id , techList , techExtras , serviceHandle );
210+ return new Tag (id , techList , techExtras , serviceHandle , tagService );
240211 }
241212
242213 @ Override
0 commit comments