Skip to content

Commit

Permalink
Set GATT MTU before discovering services
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Dec 31, 2023
1 parent 740bc0a commit 73618ce
Show file tree
Hide file tree
Showing 5 changed files with 10,130 additions and 8,424 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
compileSdk 34
minSdk 19
targetSdk 34
versionName "4.1.3"
versionName "4.1.4"
versionCode = versionName.replace(".","").toInteger() * 10

vectorDrawables {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</queries>

<application
android:process=":TagMo"
android:name=".TagMo"
android:enableOnBackInvokedCallback="true"
android:allowBackup="true"
Expand Down Expand Up @@ -129,7 +130,8 @@
android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize"
android:launchMode="singleTop" />
<service
android:name=".bluetooth.GattService" />
android:name=".bluetooth.GattService"
android:process=":TagMo" />
<receiver
android:name=".update.UpdateReceiver"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ class GattService : Service() {
private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() {
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
if (Version.isLollipop) {
gatt.requestMtu(247) // Nordic
return
}
mBluetoothGatt?.discoverServices()
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
listener?.onConnectionLost()
Expand All @@ -452,10 +456,6 @@ class GattService : Service() {
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
Debug.verbose(Companion::class.java, "${serviceType.logTag} onServicesDiscovered $status")
if (status == BluetoothGatt.GATT_SUCCESS) {
if (Version.isLollipop) {
gatt.requestMtu(247) // Nordic
return
}
when (serviceType) {
Nordic.DEVICE.BLUUP, Nordic.DEVICE.FLASK, Nordic.DEVICE.SLIDE -> {
listener?.onBluupServicesDiscovered()
Expand All @@ -475,18 +475,7 @@ class GattService : Service() {
Debug.verbose(Companion::class.java, "${serviceType.logTag} onMtuChange $mtu $status")
if (status == BluetoothGatt.GATT_SUCCESS)
maxTransmissionUnit = mtu - 3
when (serviceType) {
Nordic.DEVICE.BLUUP, Nordic.DEVICE.FLASK, Nordic.DEVICE.SLIDE -> {
listener?.onBluupServicesDiscovered()
}
Nordic.DEVICE.PIXL, Nordic.DEVICE.LOOP, Nordic.DEVICE.LINK -> {
listener?.onPixlServicesDiscovered()
}
Nordic.DEVICE.PUCK -> {
listener?.onPuckServicesDiscovered()
}
else -> { }
}
mBluetoothGatt?.discoverServices()
}

override fun onCharacteristicRead(
Expand Down
Loading

0 comments on commit 73618ce

Please sign in to comment.