Skip to content

Commit

Permalink
Bluetooth fix (#71)
Browse files Browse the repository at this point in the history
* Fixing isEnabled check when bluetooth disabled

* Fixing isEnabled call after bluetooth status event

* Adding param

* Version bump

* Adding variable
  • Loading branch information
colmharte authored Feb 16, 2021
1 parent 8440988 commit e6671c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void getConfigData(Promise promise) {
@ReactMethod
public void status(Promise promise) {
if(nearbyNotSupported()) {
Tracing.setExposureStatus("unavailable", "apiError: " + apiError);
Tracing.setExposureStatus("unavailable", "apiError: " + apiError, false);
}
Tracing.getExposureStatus(promise);
}
Expand Down
25 changes: 19 additions & 6 deletions android/src/main/java/ie/gov/tracing/Tracing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import ie.gov.tracing.storage.SharedPrefs
import ie.gov.tracing.storage.SharedPrefs.Companion.getLong
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.util.*
import kotlin.concurrent.schedule

object Tracing {
class Listener: ActivityEventListener {
Expand Down Expand Up @@ -126,7 +128,7 @@ object Tracing {
}
Events.raiseEvent(Events.INFO, "bleStatusUpdate - $intent.action, $doesSupportENS")
if (doesSupportENS) {
Tracing.setExposureStatus(newStatus, newExposureDisabledReason)
Tracing.setExposureStatus(newStatus, newExposureDisabledReason, true)
}
}
}
Expand Down Expand Up @@ -174,7 +176,7 @@ object Tracing {
var startPromise: Promise? = null

@JvmStatic
fun setExposureStatus(status: String, reason: String = "") {
fun setExposureStatus(status: String, reason: String = "", scheduleCheck: Boolean = false) {
var changed = false
if (exposureStatus != status) {
exposureStatus = status
Expand All @@ -185,8 +187,14 @@ object Tracing {
changed = true
}
if (changed) {
Events.raiseEvent(Events.ON_STATUS_CHANGED, getExposureStatus(null))
}
if (scheduleCheck) {
Timer("DelayedENSCheck", false).schedule(300) {
Events.raiseEvent(Events.ON_STATUS_CHANGED, getExposureStatus(null))
}
} else {
Events.raiseEvent(Events.ON_STATUS_CHANGED, getExposureStatus(null))
}
}
}

@JvmStatic
Expand Down Expand Up @@ -768,8 +776,13 @@ object Tracing {
fun getExposureStatus(promise: Promise? = null): ReadableMap = runBlocking {
val result: WritableMap = Arguments.createMap()
val typeData: WritableArray = Arguments.createArray()

val enabled = ExposureNotificationHelper.isEnabled().await()
var enabled = false

try {
enabled = ExposureNotificationHelper.isEnabled().await()
} catch(ex: Exception) {
Events.raiseError("Error reading ENS status", ex)
}
val isPaused = SharedPrefs.getBoolean("servicePaused", context)
if (doesSupportENS && isPaused && !enabled) {
exposureStatus = EXPOSURE_STATUS_DISABLED
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-exposure-notification-service",
"title": "React Native Exposure Notification Service",
"version": "1.3.0",
"version": "1.3.1",
"description": "React native module providing a common interface to Apple/Google's Exposure Notification APIs",
"main": "dist/index.js",
"files": [
Expand Down

0 comments on commit e6671c7

Please sign in to comment.