• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.nfc;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 /**
23  * Class used to pipe transceive result from the NFC service.
24  *
25  * @hide
26  */
27 public final class TransceiveResult implements Parcelable {
28     private final boolean mTagLost;
29     private final boolean mSuccess;
30     private final byte[] mResponseData;
31 
TransceiveResult(final boolean success, final boolean tagIsLost, final byte[] data)32     public TransceiveResult(final boolean success, final boolean tagIsLost,
33             final byte[] data) {
34         mSuccess = success;
35         mTagLost = tagIsLost;
36         mResponseData = data;
37     }
38 
isSuccessful()39     public boolean isSuccessful() {
40         return mSuccess;
41     }
42 
isTagLost()43     public boolean isTagLost() {
44         return mTagLost;
45     }
46 
getResponseData()47     public byte[] getResponseData() {
48         return mResponseData;
49     }
50 
51     @Override
describeContents()52     public int describeContents() {
53         return 0;
54     }
55 
56     @Override
writeToParcel(Parcel dest, int flags)57     public void writeToParcel(Parcel dest, int flags) {
58         dest.writeInt(mSuccess ? 1 : 0);
59         dest.writeInt(mTagLost ? 1 : 0);
60         if (mSuccess) {
61             dest.writeInt(mResponseData.length);
62             dest.writeByteArray(mResponseData);
63         }
64     }
65 
66     public static final Parcelable.Creator<TransceiveResult> CREATOR =
67             new Parcelable.Creator<TransceiveResult>() {
68         @Override
69         public TransceiveResult createFromParcel(Parcel in) {
70             boolean success = (in.readInt() == 1) ? true : false;
71             boolean tagLost = (in.readInt() == 1) ? true : false;
72             byte[] responseData;
73 
74             if (success) {
75                 int responseLength = in.readInt();
76                 responseData = new byte[responseLength];
77                 in.readByteArray(responseData);
78             } else {
79                 responseData = null;
80             }
81             return new TransceiveResult(success, tagLost, responseData);
82         }
83 
84         @Override
85         public TransceiveResult[] newArray(int size) {
86             return new TransceiveResult[size];
87         }
88     };
89 
90 }
91