Skip to content

Commit

Permalink
Require Android API Level 34 for SystemCleaner (#2036)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyDjemai authored Mar 18, 2024
1 parent 8527f08 commit 789a902
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
{{- self.add_import("androidx.annotation.RequiresApi") }}

private fun UniffiCleaner.Companion.create(): UniffiCleaner =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
AndroidSystemCleaner()
} else {
UniffiJnaCleaner()
}

// The SystemCleaner, available from API Level 33.
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
// Some API Level 33 OSes do not support using it, so we require API Level 34.
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
private class AndroidSystemCleaner : UniffiCleaner {
val cleaner = android.system.SystemCleaner.cleaner()

override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
AndroidSystemCleanable(cleaner.register(value, cleanUpTask))
}

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
private class AndroidSystemCleanable(
private val cleanable: java.lang.ref.Cleaner.Cleanable,
) : UniffiCleaner.Cleanable {
Expand Down

0 comments on commit 789a902

Please sign in to comment.