Skip to content

Commit a489a09

Browse files
authored
Merge pull request #33 from PureSwift/feature/6.3-fixes
Fix AndroidBinder for Swift 6.3
2 parents da6e345 + f2e9535 commit a489a09

6 files changed

Lines changed: 25 additions & 4 deletions

File tree

Sources/AndroidBinder/AndroidBinder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ public extension AndroidBinder {
111111
/**
112112
* Determine whether the current thread is currently executing an incoming transaction.
113113
*
114+
* Available since API level 33.
115+
*
114116
* \return true if the current thread is currently executing an incoming transaction, and false
115117
* otherwise.
116118
*/
119+
@available(Android 33, *)
117120
static var isHandlingTransaction: Bool {
118121
AIBinder_isHandlingTransaction()
119122
}

Sources/AndroidBinder/Error.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ public struct AndroidBinderError: Error {
3636
public extension AndroidBinderError {
3737

3838
var message: String {
39-
let status = Status(errorCode: errorCode)
40-
return status.description
39+
if #available(Android 30, *) {
40+
let status = Status(errorCode: errorCode)
41+
return status.description
42+
} else {
43+
return "Binder error (code: \(errorCode))"
44+
}
4145
}
4246
}
4347

Sources/AndroidBinder/Parcel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public extension Parcel {
5050
*
5151
* \return A parcel which is not related to any IBinder objects.
5252
*/
53+
@available(Android 31, *)
5354
init() {
5455
self.handle = .create()
5556
}
@@ -73,6 +74,7 @@ public extension Parcel {
7374
*
7475
* Available since API level 31.
7576
*/
77+
@available(Android 31, *)
7678
var dataSize: Int {
7779
Int(handle.dataSize)
7880
}
@@ -106,6 +108,7 @@ public extension Parcel {
106108
*
107109
* Available since API level 31.
108110
*/
111+
@available(Android 31, *)
109112
func reset() throws(AndroidBinderError) {
110113
try handle.reset().get()
111114
}
@@ -119,6 +122,7 @@ public extension Parcel {
119122
* \param start starting position in \p other (must be a value from getDataPosition).
120123
* \param size number of bytes to copy from \p other.
121124
*/
125+
@available(Android 31, *)
122126
func appendContents(of other: borrowing Parcel, start: Int = 0, size: Int) throws(AndroidBinderError) {
123127
try handle.appendFrom(other.handle, start: Int32(start), size: Int32(size)).get()
124128
}
@@ -602,6 +606,7 @@ internal extension Parcel.Handle {
602606
*
603607
* Available since API level 31.
604608
*/
609+
@available(Android 31, *)
605610
static func create() -> Parcel.Handle {
606611
guard let pointer = AParcel_create() else {
607612
fatalError("Unable to initialize \(Self.self) \(#function)")
@@ -637,6 +642,7 @@ internal extension Parcel.Handle {
637642
*
638643
* Available since API level 31.
639644
*/
645+
@available(Android 31, *)
640646
var dataSize: Int32 {
641647
AParcel_getDataSize(pointer)
642648
}
@@ -655,6 +661,7 @@ internal extension Parcel.Handle {
655661
*
656662
* Available since API level 31.
657663
*/
664+
@available(Android 31, *)
658665
func reset() -> Result<Void, AndroidBinderError> {
659666
AParcel_reset(pointer).mapError()
660667
}
@@ -664,6 +671,7 @@ internal extension Parcel.Handle {
664671
*
665672
* Available since API level 31.
666673
*/
674+
@available(Android 31, *)
667675
func appendFrom(_ from: Parcel.Handle, start: Int32, size: Int32) -> Result<Void, AndroidBinderError> {
668676
AParcel_appendFrom(from.pointer, pointer, start, size).mapError()
669677
}

Sources/AndroidBinder/Status.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public extension Status {
121121
extension Status { //: CustomStringConvertible, CustomDebugStringConvertible {
122122

123123
/// Get human-readable description for debugging.
124+
@available(Android 30, *)
124125
public var description: String {
125126
handle.withDescription { $0.description }
126127
}
@@ -142,6 +143,7 @@ internal extension Status {
142143

143144
internal extension Status {
144145

146+
@available(Android 30, *)
145147
struct Description: ~Copyable {
146148

147149
let cString: UnsafePointer<CChar>
@@ -172,8 +174,9 @@ internal extension Status {
172174
}
173175
}
174176

177+
@available(Android 30, *)
175178
extension Status.Description {
176-
179+
177180
public var description: String {
178181
String(cString: cString)
179182
}
@@ -290,6 +293,7 @@ internal extension Status.Handle {
290293
*
291294
* \return a description, must be deleted with AStatus_deleteDescription.
292295
*/
296+
@available(Android 30, *)
293297
func withDescription<T>(_ block: (borrowing Status.Description) -> T) -> T {
294298
let description = Status.Description(status: self)
295299
return block(description)

Sources/AndroidOS/IBinderNDK.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal extension AndroidBinder {
5656
* the Java object is of the wrong type, this will return null.
5757
*/
5858
convenience init(_ javaObject: jobject, environment: JNIEnvironment) {
59-
guard let pointer = AParcel_fromJavaParcel(environment, javaObject) else {
59+
guard let pointer = AIBinder_fromJavaBinder(environment, javaObject) else {
6060
fatalError("Unable to initialize from Java object")
6161
}
6262
self.init(pointer)

Sources/AndroidOS/ParcelNDK.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public extension AndroidOS.Parcel {
2424
public extension AndroidOS.Parcel {
2525

2626
/// Create a temporary NDK object and perform operatios on it.
27+
@available(Android 30, *)
2728
func withNDK<E, Result>(_ body: (borrowing NDK) throws(E) -> Result) throws(E) -> Result where E: Error {
2829
let ndk = NDK.fromJava(javaThis, environment: javaEnvironment)
2930
return try body(ndk)
@@ -46,6 +47,7 @@ internal extension AndroidBinder.Parcel {
4647
* will return null. This must be deleted with AParcel_delete. This does not take ownership of the
4748
* jobject and is only good for as long as the jobject is alive.
4849
*/
50+
@available(Android 30, *)
4951
static func fromJava(_ javaObject: jobject, environment: JNIEnvironment) -> AndroidBinder.Parcel {
5052
guard let pointer = AParcel_fromJavaParcel(environment, javaObject) else {
5153
fatalError("Unable to initialize from Java object")

0 commit comments

Comments
 (0)