Skip to content

Commit 6d1409e

Browse files
committed
Fix AndroidOS.IBinder NDK compatibility
1 parent 65da959 commit 6d1409e

File tree

1 file changed

+3
-58
lines changed

1 file changed

+3
-58
lines changed

Sources/AndroidOS/IBinderNDK.swift

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Android
1111
#endif
1212
import SwiftJava
13-
import CSwiftJavaJNI
13+
import SwiftJavaJNICore
1414
import AndroidBinder
1515

1616
// MARK: - NDK Parcel
@@ -32,64 +32,9 @@ public extension AndroidOS.IBinder {
3232
public extension AndroidBinder {
3333

3434
/// Converts an `android.os.IBinder` object into an `AIBinder*` object.
35-
convenience init(_ javaObject: AndroidOS.IBinder) {
36-
self.init(javaObject.javaThis, environment: javaObject.javaEnvironment)
35+
static func fromJava(_ javaObject: AndroidOS.IBinder) -> AndroidBinder? {
36+
AndroidBinder.fromJava(javaObject.javaThis, environment: javaObject.javaEnvironment)
3737
}
3838
}
3939

40-
internal extension AndroidBinder {
41-
42-
/**
43-
* Converts an `android.os.IBinder` object into an `AIBinder* object`.
44-
*
45-
* If the binder is null, null is returned. If this binder object was originally an
46-
* AIBinder object, the original object is returned. The returned object has one refcount
47-
* associated with it, and so this should be accompanied with an `AIBinder_decStrong` call.
48-
*
49-
* Available since API level 29.
50-
*
51-
* \param env Java environment. Must not be null.
52-
* \param binder android.os.IBinder java object.
53-
*
54-
* \return an AIBinder object representing the Java binder object. If either parameter is null, or
55-
* the Java object is of the wrong type, this will return null.
56-
*/
57-
convenience init(_ javaObject: jobject, environment: JNIEnvironment) {
58-
guard let pointer = AIBinder_fromJavaBinder(environment, javaObject) else {
59-
fatalError("Unable to initialize from Java object")
60-
}
61-
self.init(pointer)
62-
}
63-
64-
/**
65-
* Converts an `AIBinder*` object into an `android.os.IBinder` object.
66-
*
67-
* If the binder is null, null is returned. If this binder object was originally an IBinder object,
68-
* the original java object will be returned.
69-
*
70-
* WARNING: this function returns global and local references. This can be
71-
* figured out using GetObjectRefType. Though, when this function is called
72-
* from within a Java context, the local ref will automatically be cleaned
73-
* up. If this is called outside of a Java frame,
74-
* PushObjectFrame/PopObjectFrame can simulate this automatic cleanup.
75-
*
76-
* Available since API level 29.
77-
*
78-
* \param env Java environment. Must not be null.
79-
* \param binder the object to convert.
80-
*
81-
* \return an android.os.IBinder object or null if the parameters were null.
82-
*/
83-
func toJavaObject(environment: JNIEnvironment) -> jobject {
84-
withUnsafePointer {
85-
AIBinder_toJavaBinder(environment, $0)
86-
}
87-
}
88-
}
89-
90-
#if !os(Android)
91-
func AIBinder_fromJavaBinder(_ environment: JNIEnvironment?, _ javaObject: jobject) -> OpaquePointer? { fatalError("stub") }
92-
93-
func AIBinder_toJavaBinder(_ environment: JNIEnvironment?, _ ndkObject: OpaquePointer?) -> jobject { fatalError("stub") }
94-
#endif
9540
#endif

0 commit comments

Comments
 (0)