Skip to content

Commit

Permalink
Merge pull request #32 from kshoji/feature/fix-companion-device-manag…
Browse files Browse the repository at this point in the history
…er-20240412

Adjusted behavior when using CompanionDeviceManager
  • Loading branch information
kshoji authored Apr 12, 2024
2 parents 3ef3690 + a44d103 commit 6e6ab71
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public void onServicesDiscovered(final BluetoothGatt gatt, int status) {
public void run() {
// this calls onCharacteristicRead after completed
gatt.readCharacteristic(manufacturerCharacteristic);
if (gattRequestQueue.size() > 0) {
gattRequestQueue.remove(0).run();
}
}
});
}
Expand All @@ -152,6 +155,9 @@ public void run() {
public void run() {
// this calls onCharacteristicRead after completed
gatt.readCharacteristic(modelCharacteristic);
if (gattRequestQueue.size() > 0) {
gattRequestQueue.remove(0).run();
}
}
});
}
Expand All @@ -161,7 +167,9 @@ public void run() {
gattRequestQueue.add(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// if the app is running on Meta/Oculus, don't set the mtu
boolean isOculusDevices = "miramar".equals(Build.DEVICE) || "hollywood".equals(Build.DEVICE) || "eureka".equals(Build.DEVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE || isOculusDevices) {
// Android 14: the default MTU size set to 517
// https://developer.android.com/about/versions/14/behavior-changes-all#mtu-set-to-517
final int mtu = 517;
Expand All @@ -180,6 +188,7 @@ public void run() {
} else {
// request maximum MTU size
// this calls onMtuChanged after completed
// NOTE: Some devices already have MTU set to 517, so the `onMtuChanged` method is not called.
boolean result = gatt.requestMtu(517); // GATT_MAX_MTU_SIZE defined at `stack/include/gatt_api.h`
Log.d(Constants.TAG, "Central requestMtu address: " + gatt.getDevice().getAddress() + ", succeed: " + result);
}
Expand Down

0 comments on commit 6e6ab71

Please sign in to comment.