Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 14 (compile SDK 34) and BroadcastReceiver changes #582

Merged
merged 8 commits into from
Nov 15, 2023
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
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ kotlin {
// Workaround for AtomicFU plugin not automatically adding JVM dependency for Android.
// https://github.com/Kotlin/kotlinx-atomicfu/issues/145
implementation(libs.atomicfu)

implementation(libs.tuulbox.coroutines)
}
}

Expand Down
1 change: 1 addition & 0 deletions core/src/androidMain/kotlin/Bluetooth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.juul.kable.Reason.LocationServicesDisabled
import com.juul.kable.Reason.Off
import com.juul.kable.Reason.TurningOff
import com.juul.kable.Reason.TurningOn
import com.juul.tuulbox.coroutines.flow.broadcastReceiverFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
Expand Down
16 changes: 2 additions & 14 deletions core/src/androidMain/kotlin/broadcastReceiverFlow.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package com.juul.kable

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED
import kotlinx.coroutines.channels.awaitClose
import com.juul.tuulbox.coroutines.flow.broadcastReceiverFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow

@Deprecated("Was not intended to be public. Will not be available (will be `internal`) in a future release.")
public fun broadcastReceiverFlow(
intentFilter: IntentFilter,
): Flow<Intent> = callbackFlow {
val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent != null) trySend(intent)
}
}
ContextCompat.registerReceiver(applicationContext, broadcastReceiver, intentFilter, RECEIVER_NOT_EXPORTED)
awaitClose { applicationContext.unregisterReceiver(broadcastReceiver) }
}
): Flow<Intent> = broadcastReceiverFlow(intentFilter, RECEIVER_NOT_EXPORTED)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import platform.CoreBluetooth.CBPeripheral
import platform.CoreBluetooth.CBUUID
import platform.Foundation.NSData
import platform.Foundation.NSNumber
import kotlin.experimental.ExperimentalNativeApi

internal class CBPeripheralCoreBluetoothAdvertisement(
override val rssi: Int,
Expand Down Expand Up @@ -81,6 +82,7 @@ internal class CBPeripheralCoreBluetoothAdvertisement(

internal fun NSData.toManufacturerData(): ManufacturerData? = toByteArray().toManufacturerData()

@OptIn(ExperimentalNativeApi::class)
private fun ByteArray.toManufacturerData(): ManufacturerData? =
takeIf { size >= 2 }?.getShortAt(0)?.let { code ->
ManufacturerData(
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
android-compile = "33"
android-compile = "34"
QuantumRand marked this conversation as resolved.
Show resolved Hide resolved
android-min = "21"
atomicfu = "0.22.0"
coroutines = "1.7.3"
jvm-toolchain = "11"
kotlin = "1.9.10"
tuulbox = "6.5.0"
tuulbox = "7.0.0"

[libraries]
androidx-core = { module = "androidx.core:core-ktx", version = "1.12.0" }
Expand All @@ -15,6 +15,7 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
tuulbox-collections = { module = "com.juul.tuulbox:collections", version.ref = "tuulbox" }
tuulbox-coroutines = { module = "com.juul.tuulbox:coroutines", version.ref = "tuulbox" }
QuantumRand marked this conversation as resolved.
Show resolved Hide resolved
tuulbox-logging = { module = "com.juul.tuulbox:logging", version.ref = "tuulbox" }
uuid = { module = "com.benasher44:uuid", version = "0.8.1" }

Expand Down