Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/AndroidBinder/AndroidBinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ public extension AndroidBinder {
/**
* Determine whether the current thread is currently executing an incoming transaction.
*
* Available since API level 33.
*
* \return true if the current thread is currently executing an incoming transaction, and false
* otherwise.
*/
@available(Android 33, *)
static var isHandlingTransaction: Bool {
AIBinder_isHandlingTransaction()
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/AndroidBinder/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public struct AndroidBinderError: Error {
public extension AndroidBinderError {

var message: String {
let status = Status(errorCode: errorCode)
return status.description
if #available(Android 30, *) {
let status = Status(errorCode: errorCode)
return status.description
} else {
return "Binder error (code: \(errorCode))"
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions Sources/AndroidBinder/Parcel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public extension Parcel {
*
* \return A parcel which is not related to any IBinder objects.
*/
@available(Android 31, *)
init() {
self.handle = .create()
}
Expand All @@ -73,6 +74,7 @@ public extension Parcel {
*
* Available since API level 31.
*/
@available(Android 31, *)
var dataSize: Int {
Int(handle.dataSize)
}
Expand Down Expand Up @@ -106,6 +108,7 @@ public extension Parcel {
*
* Available since API level 31.
*/
@available(Android 31, *)
func reset() throws(AndroidBinderError) {
try handle.reset().get()
}
Expand All @@ -119,6 +122,7 @@ public extension Parcel {
* \param start starting position in \p other (must be a value from getDataPosition).
* \param size number of bytes to copy from \p other.
*/
@available(Android 31, *)
func appendContents(of other: borrowing Parcel, start: Int = 0, size: Int) throws(AndroidBinderError) {
try handle.appendFrom(other.handle, start: Int32(start), size: Int32(size)).get()
}
Expand Down Expand Up @@ -602,6 +606,7 @@ internal extension Parcel.Handle {
*
* Available since API level 31.
*/
@available(Android 31, *)
static func create() -> Parcel.Handle {
guard let pointer = AParcel_create() else {
fatalError("Unable to initialize \(Self.self) \(#function)")
Expand Down Expand Up @@ -637,6 +642,7 @@ internal extension Parcel.Handle {
*
* Available since API level 31.
*/
@available(Android 31, *)
var dataSize: Int32 {
AParcel_getDataSize(pointer)
}
Expand All @@ -655,6 +661,7 @@ internal extension Parcel.Handle {
*
* Available since API level 31.
*/
@available(Android 31, *)
func reset() -> Result<Void, AndroidBinderError> {
AParcel_reset(pointer).mapError()
}
Expand All @@ -664,6 +671,7 @@ internal extension Parcel.Handle {
*
* Available since API level 31.
*/
@available(Android 31, *)
func appendFrom(_ from: Parcel.Handle, start: Int32, size: Int32) -> Result<Void, AndroidBinderError> {
AParcel_appendFrom(from.pointer, pointer, start, size).mapError()
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/AndroidBinder/Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public extension Status {
extension Status { //: CustomStringConvertible, CustomDebugStringConvertible {

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

internal extension Status {

@available(Android 30, *)
struct Description: ~Copyable {

let cString: UnsafePointer<CChar>
Expand Down Expand Up @@ -172,8 +174,9 @@ internal extension Status {
}
}

@available(Android 30, *)
extension Status.Description {

public var description: String {
String(cString: cString)
}
Expand Down Expand Up @@ -290,6 +293,7 @@ internal extension Status.Handle {
*
* \return a description, must be deleted with AStatus_deleteDescription.
*/
@available(Android 30, *)
func withDescription<T>(_ block: (borrowing Status.Description) -> T) -> T {
let description = Status.Description(status: self)
return block(description)
Expand Down
2 changes: 1 addition & 1 deletion Sources/AndroidOS/IBinderNDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal extension AndroidBinder {
* the Java object is of the wrong type, this will return null.
*/
convenience init(_ javaObject: jobject, environment: JNIEnvironment) {
guard let pointer = AParcel_fromJavaParcel(environment, javaObject) else {
guard let pointer = AIBinder_fromJavaBinder(environment, javaObject) else {
fatalError("Unable to initialize from Java object")
}
self.init(pointer)
Expand Down
2 changes: 2 additions & 0 deletions Sources/AndroidOS/ParcelNDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public extension AndroidOS.Parcel {
public extension AndroidOS.Parcel {

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