Commit Graph
100 Commits
Author SHA1 Message Date
Thomas Kuehne a810fa8a36 log: improve logging of Bluetooth adapter changes 2025-07-06 15:05:00 +02:00
Thomas Kuehne 46d3f461e9 Timers: use fixed delay instead of fixed rate
from lint:
Use of scheduleAtFixedRate is strongly discouraged because it can lead to unexpected behaviour when Android processes become cached (tasks may unexpectedly execute hundreds or thousands of times in quick succession when a process changes from cached to uncached).
2025-07-06 09:43:30 +02:00
Thomas KuehneandJosé Rebelo 32e1b8a538 setBusyTask - ensure that busy task names are translated (#5043) 2025-07-05 20:21:45 +02:00
Thomas KuehneandJosé Rebelo 5d140e167d replace three dots (...) with ellipses (…) 2025-07-05 19:12:22 +02:00
Thomas Kuehne 42d19dbaed dispose DeviceSupports if connect() throws an exception (#5045) 2025-07-05 18:04:45 +02:00
Thomas KuehneandJosé Rebelo 443594db8c add CompanionDeviceService initiated re-connection (#5023) 2025-07-04 22:17:19 +02:00
Thomas KuehneandJosé Rebelo b30ede77c7 ble: improve exception handling and streamline logged information 2025-07-04 22:03:15 +02:00
Thomas KuehneandJosé Rebelo 2709446597 casio: introduce BLE legacy writes to fake not-yet-written characteristic values (#5008) 2025-07-04 19:55:10 +02:00
Thomas KuehneandJosé Rebelo 83db1c98ff logging: use Runtime.addShutdownHook to flush the log
This should have a better chance to write the last log lines than doing it in UncaughtExceptionHandler.
2025-07-04 10:49:40 +02:00
Thomas KuehneandJosé Rebelo 8820f64d69 concurrency: AtomicBoolean and volatile boolean
when multiple threads may be involved
AtomicBoolean: at least once code location tests and then sets the value
volatile boolean: test and set are in different code path
2025-07-03 10:17:33 +02:00
Thomas KuehneandJosé Rebelo 9976d396ec ble: BtLEQueue optimizations for CompanionDevice auto connect (#5019) 2025-07-01 23:30:29 +02:00
Thomas KuehneandJosé Rebelo d98e51190d ble: always use the TransactionBuilder provided to createTransactionBuilder
The use of initializeDevice's TransactionBuilder was inconsistent:
onServicesDiscovered used the input argument
performInitialized used the return
2025-07-01 23:04:03 +02:00
Thomas Kuehne 0d4e64ca85 fix: AbstractMethodError CompanionDeviceService.onDeviceDisappeared (#5028)
In older Android versions this is method is abstract.
2025-07-01 19:27:28 +02:00
Thomas KuehneandJosé Rebelo 071c7529ba use Build.VERSION_CODES instead of magic numbers
The available codes only depend on compileSdk.
minSdk and targetSdk are not relevant.
2025-06-29 16:32:27 +02:00
Thomas KuehneandJosé Rebelo 6728e87393 DeviceCommunicationService - stress test connect/dispose (#5020)
only effective in debug builds:
Test if a DeviceSupport is ready for multiple connect triggers (manual, AutoConnectIntervalReceiver, BluetoothConnectReceiver, GBCompanionDeviceService)

Device specific debugging preferences:
1) optionally call DeviceSupport.dispose() twice
2) optionally call DeviceSupport.connect() multiple times in series or in parallel
2025-06-29 16:31:53 +02:00
Thomas KuehneandJosé Rebelo 4723115356 enable StrictMode with penalty log for debug builds (#5022) 2025-06-29 14:26:32 +02:00
Thomas KuehneandJosé Rebelo f732ff582a ble: add ReadPhyAction, SetPreferredPhyAction, onServiceChanged and onReliableWriteCompleted 2025-06-28 19:34:22 +02:00
Thomas KuehneandJosé Rebelo e40608dcf6 ble: enable BtLEQueue to log to-be-written values 2025-06-28 19:28:22 +02:00
Thomas KuehneandJosé Rebelo 95d163e8c3 casio gbx100: distinct transaction names for better debugging (#5008) 2025-06-28 16:40:02 +02:00
Thomas KuehneandJosé Rebelo 868bc0bd7e BtBR+BtLE: adjust DeviceSupport's isConnected to check the queue's status
DeviceSupport asks BtBRQueue/BtLEQueue for the connectivity status as the queue knows best.
This enables the queue implementation to sidestep multi-threading issues.
2025-06-26 20:42:49 +02:00
Thomas KuehneandJosé Rebelo 3d2ac05390 ble: fix BtLEQueue reconnection logic
Ensure that handleDisconnected uses a robust reconnection logic.
2025-06-24 14:12:28 +02:00
Thomas KuehneandJosé Rebelo ac56df52ac ble: fix DeviceCommunicationService disposes DeviceSupport
When a device goes out of range and then comes back into range DeviceCommunicationService disposes DeviceSupport while trying to re-establish a connection.
This causes race conditions as there are multiple for path for reconnections that can be executed in parallel.
The DeviceService.ACTION_CONNECT path kills everything abruptly potential leaving the gadget with a broken connection.

partial backport from PR #4916
2025-06-24 09:53:50 +02:00
Thomas KuehneandJosé Rebelo 7fcc879280 ble: fix BondingAction.getCurrentTarget 2025-06-24 00:09:30 +02:00
Thomas KuehneandJosé Rebelo 4c94bc5568 G1DeviceSupport: fix setUpdateState 2025-06-22 19:19:14 +02:00
Thomas KuehneandJosé Rebelo 8bf39e62d5 Huawei: fix setUpdateState 2025-06-22 19:19:00 +02:00
Thomas Kuehne 168fec3253 log: set distinct thread names to enhance logging of race conditions 2025-06-22 17:21:32 +02:00
Thomas KuehneandJosé Rebelo 2e8c38d255 miband: fix setUpdateState 2025-06-22 14:54:48 +02:00
Thomas KuehneandJosé Rebelo 161c89cfcf makibeshr3: fix setUpdateState 2025-06-22 14:50:32 +02:00
Thomas KuehneandJosé Rebelo bd48d299f7 qhybrid: fix setUpdateState 2025-06-22 14:50:10 +02:00
Thomas KuehneandJosé Rebelo cc41bcac2a jyou: fix setUpdateState 2025-06-22 14:49:27 +02:00
Thomas KuehneandJosé Rebelo d48bea3003 test: fix setUpdateState 2025-06-22 14:48:50 +02:00
Thomas KuehneandJosé Rebelo 906764ae2a no1f1: fix setUpdateState 2025-06-22 14:48:30 +02:00
Thomas KuehneandJosé Rebelo c700a4c71c waspos: fix setUpdateState 2025-06-22 14:47:51 +02:00
Thomas KuehneandJosé Rebelo 280f4fc61d BangleJSDeviceSupport: fix setUpdateState 2025-06-22 14:46:50 +02:00
Thomas KuehneandJosé Rebelo c9a9ae8ad0 ble: introduce getServiceDiscoveryDelay and apply BtLEQueue settings (2/2)
1/2:
- rename AbstractBTLEDeviceSupport to AbstractBTLESingleDeviceSupport
- apply all BtLEQueue settings before processing starts
- introduce getServiceDiscoveryDelay to support device specific delay between STATE_CONNECTED and getServices/discoverServices
2/2:
- add a new AbstractBTLEDeviceSupport as a common super class of AbstractBTLEMultiDeviceSupport and AbstractBTLESingleDeviceSupport
2025-06-22 13:47:33 +02:00
Thomas KuehneandJosé Rebelo 94ec64095a ble: introduce getServiceDiscoveryDelay and apply BtLEQueue settings (1/2)
1/2:
- rename AbstractBTLEDeviceSupport to AbstractBTLESingleDeviceSupport
- apply all BtLEQueue settings before processing starts
- introduce getServiceDiscoveryDelay to support device specific delay between STATE_CONNECTED and getServices/discoverServices
2/2:
- add a new AbstractBTLEDeviceSupport as a common super class of AbstractBTLEMultiDeviceSupport and AbstractBTLESingleDeviceSupport
2025-06-22 13:47:33 +02:00
Thomas KuehneandJosé Rebelo fcd4ac30be ble: introduce CompanionDeviceService to elevate process priority 2025-06-22 12:48:01 +02:00
Thomas Kuehne 485df6a021 ble+bt: replace setState with setUpdateState
code de-duplication: GBDevice.setState + sendDeviceUpdateIntent + DEVICE_STATE
1) add nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder.setUpdateState
2) add nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder.setUpdateState
3) add nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.setUpdateState
4) use the new setUpdateState

The status logic in following classes require a deeper analysis. They were thus not updated:
- AbstractBTBRDeviceSupport
- BFH16DeviceSupport
- BangleJSDeviceSupport
- DeviceCommunicationService
- FossilWatchAdapter
- G1DeviceSupport
- GenericHeadphonesSupport
- HuaweiSupportProvider
- JYouSupport
- MakibesHR3DeviceSupport
- MiBandSupport
- MisfitWatchAdapter
- No1F1Support
- TestDeviceSupport
- WaspOSDeviceSupport
2025-06-22 11:12:19 +02:00
Thomas Kuehne 79a6ee2c92 use StandardCharsets.UTF_8 instead of name based charset lookups
eliminates the need to handle UnsupportedEncodingException and improves performance
2025-06-21 20:51:22 +02:00
Thomas KuehneandJosé Rebelo 5c439be493 add @Override annotations to device specific code
@Override is helpful to ensure that factoring can't cause "orphaned" methods
2025-06-21 18:35:48 +02:00
Thomas KuehneandJosé Rebelo e00261cac6 fix and annotate null handling in some core classes 2025-06-21 09:36:05 +02:00
Thomas KuehneandJosé Rebelo 52d3b20430 ble: log detailed companion bonding error 2025-06-19 21:54:17 +02:00
Thomas Kuehne ba48c39426 ble: fix BondingInterface.getMacAddress null pointer issues 2025-06-19 20:53:58 +02:00
Thomas KuehneandJosé Rebelo 91ae4bffd2 ble: use correct type of DeviceFilter for CompanionDeviceManager.associate
Use BluetoothDeviceFilter or BluetoothLeDeviceFilter instead of always BluetoothDeviceFilter.
While this doesn't seem to impact the associate call itself it influences how/when CompanionDeviceService picks up the gadget on some devices.
2025-06-16 21:33:59 +02:00
Thomas KuehneandJosé Rebelo 871f4f3167 ble: fix incomplete bond removal
this is a partial backport from PR #4916
2025-06-15 15:03:39 +02:00
Thomas Kuehne 0e98ee4fca fix: AutoConnectIntervalReceiver delays processing by rescheduling
When a GATT device disconnects and supports automatic reconnection then:
1) two DeviceManager.ACTION_DEVICES_CHANGED intents are posted
2) for the first intent AutoConnectIntervalReceiver schedules a 8 sec alarm
3) for the second intent AutoConnectIntervalReceiver schedules a 16 sec alarm

However the AlarmManager replaces the 8 sec alarm with the 16 sec one.
So AutoConnectIntervalReceiver attempts to reconnect after 16 sec delay.
2025-06-15 10:05:43 +02:00
Thomas Kuehne b990746e8e fix: #4952 - Call requires API level 35: java.lang.CharSequence#isEmpty 2025-06-15 08:58:06 +02:00
Thomas KuehneandJosé Rebelo 2a38a9e9b7 weaken core parameter types to the actually required type
When possible use CharSequence, Collection and Iterable for method parameters and function parameters instead of more specific types.
2025-06-14 23:02:34 +02:00
Thomas Kuehne c3aa18d7f5 cleanup: use .size() instead of .toArray().length
this avoids unnecessary array allocation and filling
2025-06-14 12:30:14 +02:00
Thomas Kuehne 7063ef56c6 logging: enable logcat to retain more content
Remove "0x" prefix from Logging.formatBytes output in order to reduce the output size by 2/5.
2025-06-14 09:21:31 +02:00
Thomas KuehneandJosé Rebelo afdf6e6888 ble: remove macAddress parameter from BondingUtil.companionDeviceManagerBond
Redundant source of truth. The information is already available via the device parameter.
Leaving it in would complicate future improvements to the CompanionDevice handling.
2025-06-13 22:55:36 +02:00
Thomas KuehneandJosé Rebelo 0acba61522 BLE: fix concurrency handling of ACTION_BOND_STATE_CHANGED and improve logs 2025-06-09 12:57:04 +02:00
Thomas KuehneandJosé Rebelo dff57d6e37 BluetoothGattCharacteristic: prefer WRITE_TYPE_DEFAULT over WRITE_TYPE_NO_RESPONSE if both are supported
If both PROPERTY_WRITE and PROPERTY_WRITE_NO_RESPONSE are supported by a BluetoothGattCharacteristic Android defaults to WRITE_TYPE_NO_RESPONSE.
This then may cause early BluetoothGattCallback.onCharacteristicWrite calls when the write has been queued on the mobile but potentially not yet actually completely reached the gadget.
Depending on the queued BtLEAction(s) and timing details this is often harmless but may sporadically cause inconsistencies.

Must be explicitly enabled in the device specific developer settings.
2025-06-09 11:58:07 +02:00
Thomas KuehneandJosé Rebelo 5e038a831f ble: add more Gatt status codes to BleNamesResolver 2025-06-08 21:16:04 +02:00
Thomas Kuehne 70f26114e4 ble: fix check-and-use concurrency issues in BtLEQueue
this is a partial backport from PR #4915
2025-06-08 07:43:32 +02:00
Thomas Kuehne ad08df3f96 log: replace Throwable.printStackTrace by LOG.warn to reliably pinpoint where this exception handling is happening 2025-06-05 00:48:20 +02:00
Thomas KuehneandJosé Rebelo 3320203c23 gradle: upgrade Android SDK to API 36 / Baklava
Keep targetSdk and minSdk unchanged. Ensure SDK is up-to-date as Google once again changed relevant CompanionDevice APIs.
2025-06-03 20:59:49 +02:00
Thomas Kuehne d6fb02619a Debug: assist user to input properly formatted MAC addresses
Android's Bluetooth rejects MACs with:
- lower letter (abcdef) instead of upper letters (ABCDEF)
- hyphens (-) instead of colons (:)

banglejs builds also support pebble emulator addresses
2025-06-03 01:04:01 +02:00
Thomas KuehneandJosé Rebelo b60b560d9d UI: use dynamic tint for icons to support light, dark and dynamic colour themes 2025-05-24 22:07:07 +02:00
Thomas KuehneandJosé Rebelo 6470931e2c ble: eliminate possibility of InternalGattCallback.getCallbackToUse race conditions 2025-05-24 18:14:24 +02:00
Thomas Kuehne 9848654b58 ble: fix GattCallback.onConnectionStateChange is never called 2025-05-24 16:52:46 +02:00
Thomas KuehneandJosé Rebelo c159a13a66 ble: support gadget initiated connections
The BluetoothDevice.ACTION_ACL_CONNECTED intent indicating gadget or Android imitated connections is not specific to Bluetooth Classic.
So make the GBPrefs.DEVICE_CONNECT_BACK setting available to both Bluetooth Classic and BLE.
2025-05-24 14:58:19 +02:00
Thomas KuehneandJosé Rebelo bb2ba155cc ble: explicitly deal with GATT status 8, 129 and 133 in BtLEQueue.handleDisconnected 2025-05-24 14:40:23 +02:00
Thomas KuehneandJosé Rebelo 9bb3279e67 UI: add icon for SpO2 measurement 2025-05-24 14:20:46 +02:00
Thomas KuehneandJosé Rebelo e87779d7ea UI: additional activity icons 2025-05-24 14:10:29 +02:00
Thomas KuehneandJosé Rebelo de4b59cdfc UI: add icon to the "About you" preferences 2025-05-23 21:40:38 +02:00
Thomas Kuehne b99e63104d UI: add icons for the "General settings" preferences 2025-05-23 20:21:27 +02:00
Thomas KuehneandJosé Rebelo e9415f3350 ble: add per-device setting to request BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER 2025-05-21 20:51:14 +02:00
Thomas KuehneandJosé Rebelo a83026b180 ble: BluetoothDevice.getAlias replaced getAliasName in Android 11 2025-05-17 14:52:14 +00:00
Thomas KuehneandJosé Rebelo d646197107 ble: log names instead of numeric status and decode more BluetoothGattCallback status codes 2025-05-16 20:04:17 +00:00
Thomas Kuehne 1033299122 ble: fix wrong Logger in performInitialized 2025-05-15 22:12:20 +02:00
Thomas KuehneandArjan Schrijver f22fa75770 BleGattClientSupport: add GATT_SUCCESS check 2025-05-14 20:38:44 +00:00
Thomas KuehneandArjan Schrijver 53c2fdce54 logging: wrong number of placeholders 2025-05-14 20:34:08 +00:00
Thomas Kuehne 8259592c49 logging: wrong class argument used for LoggerFactory.getLogger 2025-05-14 22:06:32 +02:00
Thomas KuehneandJosé Rebelo 67eff1e361 huami+pebble: replace deprecated writeCharacteristic and writeDescriptor 2025-05-13 19:38:53 +00:00
Thomas KuehneandJosé Rebelo 7733f7ed28 GattCallback: memory safe onDescriptorRead
Change the method signature of GattCallback.onDescriptorRead to be memory safe. See Android 13 (Tiramisu, API 33) documentation for background.

To be memory safe onDescriptorRead should always evaluate the `value` parameter, potential in combination with BLETypeConversions, and not use:
- BluetoothGattDescriptor.getValue
- BluetoothGattDescriptor.getIntValue
- BluetoothGattDescriptor.getFloatValue
- BluetoothGattDescriptor.getStringValue
2025-05-13 19:36:17 +00:00
Thomas Kuehne e1de7efa55 BleNamesResolver: add BluetoothProfile#STATE_... lookup 2025-05-13 20:39:40 +02:00
Thomas Kuehne f453e21c0f onMtuChanged: add missing super calls and GATT_SUCCESS checks 2025-05-10 22:39:41 +02:00
Thomas KuehneandJosé Rebelo f3fd988aea fix the new BLETypeConversions.toFloat32 2025-05-10 15:36:14 +00:00
Thomas KuehneandJosé Rebelo 488c789e15 GattCallback: memory safe onCharacteristicChanged and onCharacteristicRead
Change the method signatures of GattCallback.onCharacteristicChanged and GattCallback.onCharacteristicRead to be memory safe. See Android 13 (Tiramisu, API 33) documentation for background.

To be memory safe onCharacteristicChanged and onCharacteristicRead should always evaluate the `value` parameter, potential in combination with BLETypeConversions, and not use:
- BluetoothGattCharacteristic.getValue
- BluetoothGattCharacteristic.getIntValue
- BluetoothGattCharacteristic.getFloatValue
- BluetoothGattCharacteristic.getStringValue
2025-05-10 15:36:14 +00:00
Thomas KuehneandJosé Rebelo 03e14edee4 switch the Java toolchain to version 21
Switch the Java toolchain to version 21 - the version shipped with current AndroidStudio releases.
Disable Java 1.8 warnings - see discussion in PR #4735
2025-05-10 13:09:46 +00:00
Thomas KuehneandJosé Rebelo 303d01530f Gradle: execute the genSources task only when necessary
Rebuilds where only elements in app/ where changed no longer re-generate the entity java files.
2025-05-10 08:46:21 +00:00
Thomas Kuehne 414d266666 Gradle: regenerate changelog_git.xml only when actually required
During one build buildGitChangelog is executed multiple times (one call per defined applicationVariant).
This slows down builds and - because it generates a resource file - blocks Android Studio's Instant Run feature.
2025-05-08 23:42:36 +02:00
Thomas KuehneandJosé Rebelo 8b92a479e1 log: use descriptive BluetoothStatusCodes instead of numeric codes 2025-05-04 19:29:53 +00:00
Thomas KuehneandJosé Rebelo f51237217c fix RequestConnectionPriorityAction waiting for a non-existing async BLE update 2025-05-04 19:28:48 +00:00
Thomas KuehneandJosé Rebelo dec5207c2d fix ServerResponseAction sending hardcoded status 0 instead of parameter value 2025-05-04 19:26:21 +00:00
Thomas Kuehne 9f9e4faa98 log: explain why ReadAction didn't try to actually perform a read 2025-05-04 19:37:51 +02:00
Thomas Kuehne 0f91b5790b fix AbstractBTLEDeviceSupport calling bleApi for unsuccessful onCharacteristicRead 2025-05-02 18:31:11 +02:00
Thomas KuehneandJosé Rebelo b6dadcb84f Ultrahuman: add basic support for breathing exercise 2025-05-02 08:30:04 +00:00
Thomas KuehneandJosé Rebelo 7019094f90 extend max # of DeviceCardActions from 1 to 3 2025-05-02 08:30:04 +00:00
Thomas KuehneandJosé Rebelo 7acca2dd47 enhance existing BtLE log messages
- add bonding information - `Connected to GATT server. (BOND_BONDED)`
- add read/write/etc property decoding - `characteristic: (Propr: Ultrahuman State): 86f61001-f706-58a0-95b2-1fb9261e4dc7 (read,notify)`
- decode common GATT errors encountered by InternalGattCallback and InternalGattServerCallback
2025-05-01 13:35:53 +00:00
Thomas KuehneandJosé Rebelo 742d5d96ab log more failure details in WriteAction when running on Tiramisu or higher 2025-05-01 13:35:39 +00:00
Thomas KuehneandJosé Rebelo b378a51656 BleNamesResolver: update service and characteristic UUIDs 2025-04-25 19:35:39 +00:00
Thomas Kuehne d5c632f243 fix to ensure targetCompatibility is effective for Android
PR #4735 inadvertently turned Android's targetCompatibility into Java's targetCompatibility thereby rendering it ineffective for Android.
As a result Android used the toolchain version (17) instead of targetCompatibility 1.8 to create *.class files.
See also: https://developer.android.com/build/jdks
2025-04-22 18:49:37 +02:00
Thomas Kuehne 0c415334da Ultrahuman: code review 2025-04-20 01:36:50 +02:00
Thomas Kuehne 205010b24b remove no-longer needed GenericHrvSummarySample 2025-04-20 01:26:54 +02:00
Thomas Kuehne ff761cf1e4 Ultrahuman optimizations
- fetch only new records instead of all records while the device is connected
- added PREF_POWER_SAVING support (disables / enables SpO2 sensing)
- added HRV visualization
- unified and secured Intent handling
- added BATTERY_CHARGING_FULL support
- honour PREF_TIME_SYNC in onSetTime
- various clean-ups
2025-04-20 01:12:57 +02:00
Thomas KuehneandJosé Rebelo db0d66d64c backport upstream BouncyCastle fixes
aligned with bcgit/bc-java@8b4326f247 :
- Explicitly set IV to zeros when no ParametersWithIV bcgit/bc-java@7c40b52f13
- Fix CCM input length check bcgit/bc-java@e73dbc53db
- pr-1775 fix incrementCounter bcgit/bc-java@7ad116c692
2025-04-17 21:04:15 +00:00
Thomas KuehneandJosé Rebelo c7f236790a Upgrade Gradle from 8.10.2 to 8.13
includes prerequisites:
- pcom.android.tools.build update from 8.6.1 to 8.9.1
- compileSdk update from 34 to 35 (targetSdk and minSdk are unchanged)
- .gradle and .java housekeeping fixes to reduce build warnings
2025-04-17 18:16:10 +00:00
Thomas KuehneandHosted Weblate 6e0259795e Translated using Weblate (German)
Currently translated at 98.1% (3564 of 3631 strings)

Translation: Freeyourgadget/Gadgetbridge
Translate-URL: https://hosted.weblate.org/projects/freeyourgadget/gadgetbridge/de/
2025-04-08 22:11:13 +00:00