Skip to content

Commit 8c9d6b4

Browse files
authored
Merge pull request #37 from PureSwift/feature/nfc
Add `android.nfc.*` generated sources
2 parents d1ccdee + e49c2c0 commit 8c9d6b4

34 files changed

Lines changed: 2263 additions & 1 deletion

Package.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ var package = Package(
9393
),
9494
.library(
9595
name: "AndroidMedia", targets: ["AndroidMedia"]
96+
),
97+
.library(
98+
name: "AndroidNFC", targets: ["AndroidNFC"]
9699
)
97100
],
98101
dependencies: [
@@ -169,7 +172,8 @@ var package = Package(
169172
"AndroidNativeActivity",
170173
"AndroidInput",
171174
"AndroidLocation",
172-
"AndroidMedia"
175+
"AndroidMedia",
176+
"AndroidNFC"
173177
],
174178
swiftSettings: [
175179
.swiftLanguageMode(.v5),
@@ -573,6 +577,23 @@ var package = Package(
573577
ndkVersionDefine,
574578
sdkVersionDefine
575579
]
580+
),
581+
.target(
582+
name: "AndroidNFC",
583+
dependencies: [
584+
"AndroidJava",
585+
"AndroidOS",
586+
"AndroidUtil",
587+
"AndroidContent",
588+
"AndroidApp",
589+
.product(name: "JavaLangIO", package: "JavaLang"),
590+
],
591+
exclude: ["swift-java.config"],
592+
swiftSettings: [
593+
.swiftLanguageMode(.v5),
594+
ndkVersionDefine,
595+
sdkVersionDefine
596+
]
576597
)
577598
],
578599
swiftLanguageModes: [.v5, .v6]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Auto-generated by Java-to-Swift wrapper generator.
2+
import AndroidOS
3+
import SwiftJava
4+
import SwiftJavaJNICore
5+
6+
/// Represents a single NFC antenna location on the device.
7+
///
8+
/// Coordinates are expressed in millimeters relative to the top-left corner of the device
9+
/// as reported by `NfcAntennaInfo`. Used to help users align their device with an NFC tag.
10+
///
11+
/// See also: [android.nfc.AvailableNfcAntenna](https://developer.android.com/reference/android/nfc/AvailableNfcAntenna)
12+
@available(Android 31, *)
13+
@JavaClass("android.nfc.AvailableNfcAntenna", implements: Parcelable.self)
14+
open class AvailableNfcAntenna: JavaObject {
15+
/// Creates an antenna location at the given coordinates.
16+
///
17+
/// - Parameter arg0: X coordinate in millimeters from the top-left of the device.
18+
/// - Parameter arg1: Y coordinate in millimeters from the top-left of the device.
19+
@JavaMethod
20+
@_nonoverride public convenience init(_ arg0: Int32, _ arg1: Int32, environment: JNIEnvironment? = nil)
21+
22+
/// Returns the X coordinate of this antenna in millimeters from the top-left of the device.
23+
@JavaMethod
24+
open func getLocationX() -> Int32
25+
26+
/// Returns the Y coordinate of this antenna in millimeters from the top-left of the device.
27+
@JavaMethod
28+
open func getLocationY() -> Int32
29+
30+
/// Describes the kinds of special objects contained in this `Parcelable` instance.
31+
@JavaMethod
32+
open func describeContents() -> Int32
33+
34+
/// Flattens this object into a `Parcel`.
35+
@JavaMethod
36+
open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32)
37+
38+
/// Returns `true` if this antenna location equals the given object.
39+
@JavaMethod
40+
open override func equals(_ arg0: JavaObject?) -> Bool
41+
42+
/// Returns a string representation of this antenna location.
43+
@JavaMethod
44+
open override func toString() -> String
45+
46+
/// Returns a hash code for this antenna location.
47+
@JavaMethod
48+
open override func hashCode() -> Int32
49+
}
50+
@available(Android 31, *)
51+
extension JavaClass<AvailableNfcAntenna> {
52+
@JavaStaticField(isFinal: true)
53+
public var CREATOR: Parcelable.Creator<AvailableNfcAntenna>!
54+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// Auto-generated by Java-to-Swift wrapper generator.
2+
import AndroidApp
3+
import AndroidContent
4+
import SwiftJava
5+
import SwiftJavaJNICore
6+
7+
/// Manages NFC card emulation services, AID routing, and payment preferences.
8+
///
9+
/// Card emulation allows Android devices to act as NFC cards. Obtain an instance via
10+
/// `CardEmulation.getInstance(_:)`. Requires the `FEATURE_NFC_HOST_CARD_EMULATION` feature.
11+
///
12+
/// See also: [android.nfc.cardemulation.CardEmulation](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation)
13+
@available(Android 19, *)
14+
@JavaClass("android.nfc.cardemulation.CardEmulation")
15+
open class CardEmulation: JavaObject {
16+
/// Sets whether the given service should default to observe mode.
17+
///
18+
/// - Parameter arg0: The component name of the card emulation service.
19+
/// - Parameter arg1: `true` to default to observe mode.
20+
/// - Returns: `true` if the setting was applied.
21+
@available(Android 35, *)
22+
@JavaMethod
23+
open func setShouldDefaultToObserveModeForService(_ arg0: ComponentName?, _ arg1: Bool) -> Bool
24+
25+
/// Registers a polling loop filter for the given service.
26+
///
27+
/// - Parameter arg0: The component name of the card emulation service.
28+
/// - Parameter arg1: A hex string filter for matching polling loop data.
29+
/// - Parameter arg2: `true` to auto-transact when the filter matches.
30+
/// - Returns: `true` if the filter was registered.
31+
@available(Android 35, *)
32+
@JavaMethod
33+
open func registerPollingLoopFilterForService(_ arg0: ComponentName?, _ arg1: String, _ arg2: Bool) -> Bool
34+
35+
/// Registers a regex pattern filter for the given service's polling loop data.
36+
///
37+
/// - Parameter arg0: The component name of the card emulation service.
38+
/// - Parameter arg1: A regex pattern to match against polling loop data.
39+
/// - Parameter arg2: `true` to auto-transact when the pattern matches.
40+
/// - Returns: `true` if the filter was registered.
41+
@available(Android 35, *)
42+
@JavaMethod
43+
open func registerPollingLoopPatternFilterForService(_ arg0: ComponentName?, _ arg1: String, _ arg2: Bool) -> Bool
44+
45+
/// Removes a previously registered polling loop pattern filter.
46+
///
47+
/// - Parameter arg0: The component name of the card emulation service.
48+
/// - Parameter arg1: The pattern string to remove.
49+
/// - Returns: `true` if the filter was removed.
50+
@available(Android 35, *)
51+
@JavaMethod
52+
open func removePollingLoopPatternFilterForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
53+
54+
/// Returns the route destination (e.g., `"HCE"`, `"OffHost"`) for the preferred payment service.
55+
@available(Android 35, *)
56+
@JavaMethod
57+
open func getRouteDestinationForPreferredPaymentService() -> String
58+
59+
/// Returns `true` if the given service is the default for the specified category.
60+
///
61+
/// - Parameter arg0: The component name of the card emulation service.
62+
/// - Parameter arg1: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
63+
@JavaMethod
64+
open func isDefaultServiceForCategory(_ arg0: ComponentName?, _ arg1: String) -> Bool
65+
66+
/// Returns `true` if the given service is the default handler for the specified AID.
67+
///
68+
/// - Parameter arg0: The component name of the card emulation service.
69+
/// - Parameter arg1: The AID as a hex string.
70+
@JavaMethod
71+
open func isDefaultServiceForAid(_ arg0: ComponentName?, _ arg1: String) -> Bool
72+
73+
/// Returns `true` if the given category allows foreground preference selection.
74+
///
75+
/// - Parameter arg0: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
76+
@JavaMethod
77+
open func categoryAllowsForegroundPreference(_ arg0: String) -> Bool
78+
79+
/// Returns the selection mode for the given category (e.g., `SELECTION_MODE_PREFER_DEFAULT`).
80+
///
81+
/// - Parameter arg0: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
82+
@JavaMethod
83+
open func getSelectionModeForCategory(_ arg0: String) -> Int32
84+
85+
/// Removes a previously registered polling loop filter for the given service.
86+
///
87+
/// - Parameter arg0: The component name of the card emulation service.
88+
/// - Parameter arg1: The hex string filter to remove.
89+
/// - Returns: `true` if the filter was removed.
90+
@available(Android 35, *)
91+
@JavaMethod
92+
open func removePollingLoopFilterForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
93+
94+
/// Clears the off-host secure element association for the given service.
95+
///
96+
/// - Parameter arg0: The component name of the card emulation service.
97+
/// - Returns: `true` if the association was cleared.
98+
@available(Android 26, *)
99+
@JavaMethod
100+
open func unsetOffHostForService(_ arg0: ComponentName?) -> Bool
101+
102+
/// Binds the given service to a specific off-host secure element.
103+
///
104+
/// - Parameter arg0: The component name of the card emulation service.
105+
/// - Parameter arg1: The off-host secure element name (e.g., `"eSE"`, `"SIM"`).
106+
/// - Returns: `true` if the binding was applied.
107+
@available(Android 26, *)
108+
@JavaMethod
109+
open func setOffHostForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
110+
111+
/// Removes AIDs registered by the given service for the specified category.
112+
///
113+
/// - Parameter arg0: The component name of the card emulation service.
114+
/// - Parameter arg1: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
115+
/// - Returns: `true` if the AIDs were removed.
116+
@JavaMethod
117+
open func removeAidsForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
118+
119+
/// Sets the given service as the preferred card emulation service while the activity is foreground.
120+
///
121+
/// - Parameter arg0: The foreground activity.
122+
/// - Parameter arg1: The component name of the service to prefer.
123+
/// - Returns: `true` if the preference was set.
124+
@available(Android 21, *)
125+
@JavaMethod
126+
open func setPreferredService(_ arg0: Activity?, _ arg1: ComponentName?) -> Bool
127+
128+
/// Clears the preferred card emulation service set by `setPreferredService(_:_:)`.
129+
///
130+
/// - Parameter arg0: The foreground activity.
131+
/// - Returns: `true` if the preference was cleared.
132+
@available(Android 21, *)
133+
@JavaMethod
134+
open func unsetPreferredService(_ arg0: Activity?) -> Bool
135+
136+
/// Returns `true` if the device supports AID prefix and subset registration.
137+
@available(Android 23, *)
138+
@JavaMethod
139+
open func supportsAidPrefixRegistration() -> Bool
140+
}
141+
@available(Android 19, *)
142+
extension JavaClass<CardEmulation> {
143+
@available(*, deprecated)
144+
@JavaStaticField(isFinal: true)
145+
public var ACTION_CHANGE_DEFAULT: String
146+
147+
@JavaStaticField(isFinal: true)
148+
public var CATEGORY_OTHER: String
149+
150+
@JavaStaticField(isFinal: true)
151+
public var CATEGORY_PAYMENT: String
152+
153+
@JavaStaticField(isFinal: true)
154+
public var EXTRA_CATEGORY: String
155+
156+
@JavaStaticField(isFinal: true)
157+
public var EXTRA_SERVICE_COMPONENT: String
158+
159+
@JavaStaticField(isFinal: true)
160+
public var SELECTION_MODE_ALWAYS_ASK: Int32
161+
162+
@JavaStaticField(isFinal: true)
163+
public var SELECTION_MODE_ASK_IF_CONFLICT: Int32
164+
165+
@JavaStaticField(isFinal: true)
166+
public var SELECTION_MODE_PREFER_DEFAULT: Int32
167+
168+
/// Returns a `CardEmulation` instance for the given NFC adapter.
169+
///
170+
/// - Parameter arg0: The `NfcAdapter` for this device.
171+
/// - Returns: A `CardEmulation` instance.
172+
@JavaStaticMethod
173+
public func getInstance(_ arg0: NfcAdapter?) -> CardEmulation!
174+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Auto-generated by Java-to-Swift wrapper generator.
2+
import SwiftJava
3+
import SwiftJavaJNICore
4+
5+
/// Thrown when an NDEF message cannot be parsed or is not a valid NDEF format.
6+
///
7+
/// See also: [android.nfc.FormatException](https://developer.android.com/reference/android/nfc/FormatException)
8+
@JavaClass("android.nfc.FormatException")
9+
open class FormatException: JavaObject {
10+
@JavaMethod
11+
@_nonoverride public convenience init(environment: JNIEnvironment? = nil)
12+
13+
@JavaMethod
14+
@_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil)
15+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Auto-generated by Java-to-Swift wrapper generator.
2+
import AndroidApp
3+
import AndroidContent
4+
import AndroidOS
5+
import SwiftJava
6+
import SwiftJavaJNICore
7+
8+
/// Abstract service for host-based NFC card emulation (HCE) using ISO 7816-4 APDUs.
9+
///
10+
/// Subclass this to handle APDU commands from an NFC reader. Register in the manifest
11+
/// with the `SERVICE_INTERFACE` action and provide an AID list in `SERVICE_META_DATA`.
12+
///
13+
/// Override `processCommandApdu(_:_:)` to handle commands, and call
14+
/// `sendResponseApdu(_:)` from any thread to send a response.
15+
///
16+
/// See also: [android.nfc.cardemulation.HostApduService](https://developer.android.com/reference/android/nfc/cardemulation/HostApduService)
17+
@available(Android 19, *)
18+
@JavaClass("android.nfc.cardemulation.HostApduService")
19+
open class HostApduService: Service {
20+
@JavaMethod
21+
@_nonoverride public convenience init(environment: JNIEnvironment? = nil)
22+
23+
/// Returns the `IBinder` used by the NFC service to communicate with this service.
24+
@JavaMethod
25+
open func onBind(_ arg0: Intent?) -> IBinder!
26+
27+
/// Sends a response APDU back to the NFC reader.
28+
///
29+
/// May be called from any thread. If `processCommandApdu(_:_:)` returns `nil`,
30+
/// this must be called later to provide the response.
31+
///
32+
/// - Parameter arg0: The response APDU bytes to send.
33+
@JavaMethod
34+
open func sendResponseApdu(_ arg0: [Int8])
35+
36+
/// Signals to the NFC service that this service could not handle the last APDU.
37+
///
38+
/// The NFC service may then route the command to another registered service.
39+
@JavaMethod
40+
open func notifyUnhandled()
41+
42+
/// Called when the NFC reader sends a command APDU.
43+
///
44+
/// Return the response APDU synchronously, or return `nil` and call
45+
/// `sendResponseApdu(_:)` from a background thread later.
46+
///
47+
/// - Parameter arg0: The command APDU bytes received from the reader.
48+
/// - Parameter arg1: Optional extras (currently unused, may be `nil`).
49+
/// - Returns: The response APDU bytes, or `nil` if the response will be sent asynchronously.
50+
@JavaMethod
51+
open func processCommandApdu(_ arg0: [Int8], _ arg1: Bundle?) -> [Int8]
52+
53+
/// Called when the NFC link is deactivated or another AID is selected.
54+
///
55+
/// - Parameter arg0: One of `DEACTIVATION_LINK_LOSS` or `DEACTIVATION_DESELECTED`.
56+
@JavaMethod
57+
open func onDeactivated(_ arg0: Int32)
58+
}
59+
@available(Android 19, *)
60+
extension JavaClass<HostApduService> {
61+
@JavaStaticField(isFinal: true)
62+
public var DEACTIVATION_DESELECTED: Int32
63+
64+
@JavaStaticField(isFinal: true)
65+
public var DEACTIVATION_LINK_LOSS: Int32
66+
67+
@JavaStaticField(isFinal: true)
68+
public var SERVICE_INTERFACE: String
69+
70+
@JavaStaticField(isFinal: true)
71+
public var SERVICE_META_DATA: String
72+
}

0 commit comments

Comments
 (0)