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

Testing a proof-of-concept fix for the duplicate GATT service issue. #36

Open
wants to merge 1 commit into
base: herald
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,20 @@ class ConcreteBLETransmitter(
override fun bleTimer(now: Long) {
if (!isSupported || bluetoothStateManager.state() == BluetoothState.poweredOff) {
if (advertLoopState != AdvertLoopState.stopped) {
// [AT] Clear services and close GATT server, if it exists
try {
if (bluetoothGattServer != null) {
logger.debug("[AT] bleTimer, non-null gatt server, stopping GATT server")
bluetoothGattServer!!.clearServices()
bluetoothGattServer!!.close()
}
} catch (e: Throwable) {
logger.fault("[AT] bleTimer, failed to stop GATT server", e)
}
advertiseCallback = null
bluetoothGattServer = null
state(now, AdvertLoopState.stopped)
logger.debug("advertLoopTask, stop advert (advert={}ms)", timeSincelastStateChange(now))
logger.debug("[AT] advertLoopTask, BluetoothState.powerdOff, stop advert (advert={}ms)", timeSincelastStateChange(now))
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.IntentFilter
import android.location.LocationManager
import android.os.Build
import android.os.PowerManager
import android.util.Log
import androidx.annotation.Keep
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LifecycleService
Expand Down Expand Up @@ -93,12 +94,16 @@ class BluetoothMonitoringService : LifecycleService(), CoroutineScope, SensorDel
}

fun teardown() {
commandHandler.removeCallbacksAndMessages(null)
//commandHandler.removeCallbacksAndMessages(null)

Utils.cancelBMUpdateCheck(this.applicationContext)
Utils.cancelNextScan(this.applicationContext)
Utils.cancelNextAdvertise(this.applicationContext)
sensor?.stop()
//Utils.cancelBMUpdateCheck(this.applicationContext)
//Utils.cancelNextScan(this.applicationContext)
//Utils.cancelNextAdvertise(this.applicationContext)

//[AT]
Log.i(TAG, "[AT] teardown, do nothing")

//sensor?.stop()
}

private fun setupNotifications() {
Expand Down Expand Up @@ -263,8 +268,15 @@ class BluetoothMonitoringService : LifecycleService(), CoroutineScope, SensorDel
}

fun sensorStart() {
if (broadcastMessage != null) {
// [AT] Don't create a new sensor, to avoid creating multiple advertisements/duplicate GATT services
Log.i(TAG, "[AT] sensorStart")

if (broadcastMessage != null && sensor == null) {

streetPassRecordStorage = StreetPassRecordStorage(applicationContext)

Log.i(TAG, "[AT] creating a new SensorArray")

sensor = SensorArray(applicationContext, this)
getAppDelegate().sensor()?.add(this)
// Sensor will start and stop with Bluetooth power on / off events
Expand Down