• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.nfc;
17 
18 import android.annotation.FlaggedApi;
19 import android.annotation.IntDef;
20 import android.annotation.SystemApi;
21 import android.nfc.cardemulation.CardEmulation;
22 
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 
26 /**
27  * Represents a protocol entry in current routing table.
28  * @hide
29  */
30 @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
31 @SystemApi
32 public class RoutingTableProtocolEntry extends NfcRoutingTableEntry {
33     /**
34      * Protocol undetermined.
35      */
36     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
37     public static final int PROTOCOL_UNDETERMINED = 0;
38     /**
39      * T1T Protocol
40      */
41     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
42     public static final int PROTOCOL_T1T = 1;
43     /**
44      * T2T Protocol
45      */
46     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
47     public static final int PROTOCOL_T2T = 2;
48     /**
49      * T3T Protocol
50      */
51     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
52     public static final int PROTOCOL_T3T = 3;
53     /**
54      * ISO-DEP Protocol
55      */
56     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
57     public static final int PROTOCOL_ISO_DEP = 4;
58     /**
59      * DEP Protocol
60      */
61     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
62     public static final int PROTOCOL_NFC_DEP = 5;
63     /**
64      * T5T Protocol
65      */
66     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
67     public static final int PROTOCOL_T5T = 6;
68     /**
69      * NDEF Protocol
70      */
71     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
72     public static final int PROTOCOL_NDEF = 7;
73     /**
74      * Unsupported Protocol
75      */
76     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
77     public static final int PROTOCOL_UNSUPPORTED = -1;
78 
79     /**
80      *
81      * @hide
82      */
83     @IntDef(prefix = { "PROTOCOL_" }, value = {
84             PROTOCOL_UNDETERMINED,
85             PROTOCOL_T1T,
86             PROTOCOL_T2T,
87             PROTOCOL_T3T,
88             PROTOCOL_ISO_DEP,
89             PROTOCOL_NFC_DEP,
90             PROTOCOL_T5T,
91             PROTOCOL_NDEF,
92             PROTOCOL_UNSUPPORTED
93     })
94     @Retention(RetentionPolicy.SOURCE)
95     public @interface ProtocolValue {}
96 
97     private final @ProtocolValue int mValue;
98 
99     /** @hide */
RoutingTableProtocolEntry(int nfceeId, @ProtocolValue int value, @CardEmulation.ProtocolAndTechnologyRoute int routeType)100     public RoutingTableProtocolEntry(int nfceeId, @ProtocolValue int value,
101             @CardEmulation.ProtocolAndTechnologyRoute int routeType) {
102         super(nfceeId, TYPE_PROTOCOL, routeType);
103         this.mValue = value;
104     }
105 
106     /**
107      * Gets Protocol value.
108      * @return Protocol defined in {@link ProtocolValue}
109      */
110     @ProtocolValue
111     @FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
getProtocol()112     public int getProtocol() {
113         return mValue;
114     }
115 
116     /** @hide */
117     @ProtocolValue
protocolStringToInt(String protocolString)118     public static int protocolStringToInt(String protocolString) {
119         return switch (protocolString) {
120             case "PROTOCOL_T1T" -> PROTOCOL_T1T;
121             case "PROTOCOL_T2T" -> PROTOCOL_T2T;
122             case "PROTOCOL_T3T" -> PROTOCOL_T3T;
123             case "PROTOCOL_ISO_DEP" -> PROTOCOL_ISO_DEP;
124             case "PROTOCOL_NFC_DEP" -> PROTOCOL_NFC_DEP;
125             case "PROTOCOL_T5T" -> PROTOCOL_T5T;
126             case "PROTOCOL_NDEF" -> PROTOCOL_NDEF;
127             case "PROTOCOL_UNDETERMINED" -> PROTOCOL_UNDETERMINED;
128             default -> PROTOCOL_UNSUPPORTED;
129         };
130     }
131 }
132