Skip to content

Commit 2d58a3b

Browse files
committed
Update library
1 parent f60a201 commit 2d58a3b

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

supercel/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
alias(libs.plugins.vanniktech.maven.publish)
99
}
1010

11-
version = "1.0.3"
11+
version = "1.0.4"
1212
android {
1313
namespace = "com.superwall.supercel"
1414
compileSdk = 34

supercel/src/main/java/com/superwall/supercel/CEL.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import java.nio.CharBuffer
3030
import java.nio.charset.CodingErrorAction
3131
import java.util.concurrent.atomic.AtomicLong
3232
import java.util.concurrent.ConcurrentHashMap
33-
import android.os.Build
3433
import java.util.concurrent.atomic.AtomicBoolean
3534

3635
// This is a helper for safely working with byte buffers returned from the Rust code.
@@ -1174,26 +1173,28 @@ private class UniffiJnaCleanable(
11741173
// using Android or not.
11751174
// There are further runtime checks to chose the correct implementation
11761175
// of the cleaner.
1177-
1178-
11791176
private fun UniffiCleaner.Companion.create(): UniffiCleaner =
1180-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
1181-
AndroidSystemCleaner()
1182-
} else {
1177+
try {
1178+
// For safety's sake: if the library hasn't been run in android_cleaner = true
1179+
// mode, but is being run on Android, then we still need to think about
1180+
// Android API versions.
1181+
// So we check if java.lang.ref.Cleaner is there, and use that…
1182+
java.lang.Class.forName("java.lang.ref.Cleaner")
1183+
JavaLangRefCleaner()
1184+
} catch (e: ClassNotFoundException) {
1185+
// … otherwise, fallback to the JNA cleaner.
11831186
UniffiJnaCleaner()
11841187
}
11851188

1186-
// The SystemCleaner, available from API Level 33.
1187-
// Some API Level 33 OSes do not support using it, so we require API Level 34.
1188-
private class AndroidSystemCleaner : UniffiCleaner {
1189-
val cleaner = android.system.SystemCleaner.cleaner()
1189+
private class JavaLangRefCleaner : UniffiCleaner {
1190+
val cleaner = java.lang.ref.Cleaner.create()
11901191

11911192
override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1192-
AndroidSystemCleanable(cleaner.register(value, cleanUpTask))
1193+
JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
11931194
}
11941195

1195-
private class AndroidSystemCleanable(
1196-
private val cleanable: java.lang.ref.Cleaner.Cleanable,
1196+
private class JavaLangRefCleanable(
1197+
val cleanable: java.lang.ref.Cleaner.Cleanable
11971198
) : UniffiCleaner.Cleanable {
11981199
override fun clean() = cleanable.clean()
11991200
}
96 Bytes
Binary file not shown.
64 Bytes
Binary file not shown.
-336 Bytes
Binary file not shown.
160 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)