1 /* 2 * Copyright (C) 2024 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.annotation.FlaggedApi; 20 import android.annotation.IntDef; 21 import android.annotation.IntRange; 22 import android.annotation.NonNull; 23 import android.annotation.SystemApi; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 /** 31 * This class is used to represence T4T (Type-4 Tag) NDEF (NFC Data Exchange Format) 32 * NFCEE (NFC Execution Environment) CC (Capability Container) File data. 33 * The CC file stores metadata about the T4T tag being emulated. 34 * 35 * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.4" for more details. 36 * @hide 37 */ 38 @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION) 39 @SystemApi 40 public final class T4tNdefNfceeCcFileInfo implements Parcelable { 41 /** 42 * Indicates the size of this capability container (called “CC File”)<p> 43 */ 44 private int mCcLength; 45 /** 46 * Indicates the mapping specification version<p> 47 */ 48 private int mVersion; 49 /** 50 * Indicates the NDEF File Identifier<p> 51 */ 52 private int mFileId; 53 /** 54 * Indicates the maximum Max NDEF file size<p> 55 */ 56 private int mMaxSize; 57 /** 58 * Indicates the read access condition<p> 59 */ 60 private boolean mIsReadAllowed; 61 /** 62 * Indicates the write access condition<p> 63 */ 64 private boolean mIsWriteAllowed; 65 66 /** 67 * Constructor to be used by NFC service and internal classes. 68 * @hide 69 */ T4tNdefNfceeCcFileInfo(int cclen, int version, int ndefFileId, int ndefMaxSize, boolean isReadAllowed, boolean isWriteAllowed)70 public T4tNdefNfceeCcFileInfo(int cclen, int version, 71 int ndefFileId, int ndefMaxSize, 72 boolean isReadAllowed, boolean isWriteAllowed) { 73 mCcLength = cclen; 74 mVersion = version; 75 mFileId = ndefFileId; 76 mMaxSize = ndefMaxSize; 77 mIsReadAllowed = isReadAllowed; 78 mIsWriteAllowed = isWriteAllowed; 79 } 80 81 @Override writeToParcel(@onNull Parcel dest, int flags)82 public void writeToParcel(@NonNull Parcel dest, int flags) { 83 dest.writeInt(mCcLength); 84 dest.writeInt(mVersion); 85 dest.writeInt(mFileId); 86 dest.writeInt(mMaxSize); 87 dest.writeBoolean(mIsReadAllowed); 88 dest.writeBoolean(mIsWriteAllowed); 89 } 90 91 /** 92 * Indicates the size of this capability container (called “CC File”). 93 * 94 * @return length of the CC file. 95 */ 96 @IntRange(from = 0xf, to = 0x7fff) getCcFileLength()97 public int getCcFileLength() { 98 return mCcLength; 99 } 100 101 /** 102 * T4T tag mapping version 2.0. 103 * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.4" for more details. 104 */ 105 public static final int VERSION_2_0 = 0x20; 106 /** 107 * T4T tag mapping version 2.0. 108 * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.4" for more details. 109 */ 110 public static final int VERSION_3_0 = 0x30; 111 112 /** 113 * Possible return values for {@link #getVersion()}. 114 * @hide 115 */ 116 @IntDef(prefix = { "VERSION_" }, value = { 117 VERSION_2_0, 118 VERSION_3_0, 119 }) 120 @Retention(RetentionPolicy.SOURCE) 121 public @interface Version{} 122 123 /** 124 * Indicates the mapping version of the T4T tag supported. 125 * 126 * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.5" for more details. 127 * 128 * @return version of the specification 129 */ 130 @Version getVersion()131 public int getVersion() { 132 return mVersion; 133 } 134 135 /** 136 * Indicates the NDEF File Identifier. This is the identifier used in the last invocation of 137 * {@link T4tNdefNfcee#writeData(int, byte[])} 138 * 139 * @return FileId of the data stored or -1 if no data is present. 140 */ 141 @IntRange(from = -1, to = 65535) getFileId()142 public int getFileId() { 143 return mFileId; 144 } 145 146 /** 147 * Indicates the maximum size of T4T NDEF data that can be written to the NFCEE. 148 * 149 * @return max size of the contents. 150 */ 151 @IntRange(from = 0x5, to = 0x7fff) getMaxSize()152 public int getMaxSize() { 153 return mMaxSize; 154 } 155 156 /** 157 * Indicates the read access condition. 158 * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details. 159 * @return boolean true if read access is allowed, otherwise false. 160 */ isReadAllowed()161 public boolean isReadAllowed() { 162 return mIsReadAllowed; 163 } 164 165 /** 166 * Indicates the write access condition. 167 * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details. 168 * @return boolean if write access is allowed, otherwise false. 169 */ isWriteAllowed()170 public boolean isWriteAllowed() { 171 return mIsWriteAllowed; 172 } 173 174 @Override describeContents()175 public int describeContents() { 176 return 0; 177 } 178 179 public static final @NonNull Parcelable.Creator<T4tNdefNfceeCcFileInfo> CREATOR = 180 new Parcelable.Creator<>() { 181 @Override 182 public T4tNdefNfceeCcFileInfo createFromParcel(Parcel in) { 183 184 // NdefNfceeCcFileInfo fields 185 int cclen = in.readInt(); 186 int version = in.readInt(); 187 int ndefFileId = in.readInt(); 188 int ndefMaxSize = in.readInt(); 189 boolean isReadAllowed = in.readBoolean(); 190 boolean isWriteAllowed = in.readBoolean(); 191 192 return new T4tNdefNfceeCcFileInfo(cclen, version, 193 ndefFileId, ndefMaxSize, 194 isReadAllowed, isWriteAllowed); 195 } 196 197 @Override 198 public T4tNdefNfceeCcFileInfo[] newArray(int size) { 199 return new T4tNdefNfceeCcFileInfo[size]; 200 } 201 }; 202 } 203