summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothlocaldevice_android.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Merge remote-tracking branch 'origin/tqtc/lts-5.15.10' into ↵Tarja Sundqvist2023-04-241-31/+93
|\ | | | | | | | | | | tqtc/lts-5.15-opensource Change-Id: I19a002f2b52eb02d4bfdf32c336811a71d42e9f2
| * Replace deprecated bluetooth disable/enable methods on AndroidJuha Vuolle2022-05-101-28/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting from Android 13 (API level 33) the BluetoothAdapter enable() and disable() methods have been deprecated. In addition both methods are strongly discouraged as they do not necessarily trigger a permission dialogue to turn the bluetooth ON/OFF. The methods are replaced with preferred 'action requests' which are available since API level 5 and have the benefit of triggering a user dialogue when powering Bluetooth ON/OFF. The calls to these replacing APIs are surrounded by sdkVersion checks with one exception: it appears that the old enable() call does not work well when performing a multi-state transition from Discoverable => PoweredOff => Connectable. The replacing API fairs better there and hence it is replaced unconditionally. Elsewhere the sdkVersion check is for >= 31 in order to be able to test with devices available at the moment (API level 31 corresponds with Android 12). As a drive-by few related code changes: - handle hostmode enum in a switch-case instead of if-elseif - rename the opaque tokens and setConnectable() method in the broadcast receiver to better reflect their role Fixes: QTBUG-102442 Change-Id: I5d9395ce9e5ecd28b1f8e2f37d13e8aea7cfcdd3 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit b865d41be6181b309808f432ee825dc84a670e62)
| * Improve Android-12 bluetooth permission error reportingJuha Vuolle2022-04-141-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original commit to add support for new Android-12 (API Level 31) Bluetooth permissions covered the possible codepaths the QtBluetooth module user might use. This commit seeks to improve the error reporting insofar as they are due to missing permissions. Since there are many possible codepaths to take, the following elaborates function-by-function the details for easier understanding. QBluetoothDeviceDiscoveryAgent::start() This is the main entry point for using device discovery and checks the needed permissions. QBluetoothServiceDiscoveryAgent::start() This is the main entry point for using service discovery. In most use cases it uses device discovery first which ensures adequate permissions / failure if not granted. There is one codepath bypassing this when setRemoteAddress() has been called, for which reason there is a permission check. QBluetoothSocket::localName() localAddress() connectToServiceHelper() These functions require permissions and can be called in any order so all of them check for permissions. Notably this commit moves the permission check from the constructor to these functions. QBluetoothServiceInfo::registerService() This function creates a local device and initiates active listening. The local device creation in this function will fail if it is not granted permissions, but this commit adds an earlier permission check for slightly improved error reporting. QBluetoothServer::listen() This is the main entry point for using the server and it checks for permission. The local device iteration in the function would also fail without permissions, but the permission check is added for slightly improved error reporting. Notably the initiateActiveListening() does not have permission check as there is no code path to it without already having the permission. QBluetoothLocalDevice::allDevices() constructor() setHostMode The local device needs permissions already at construction time. This commit documents this on the local device documentation. In addition the local device has a widely used allDevices() static function for iterating devices which needs its own permission checks. Also the setHostMode() function requires Advertise permission as it ultimately uses ACTION_REQUEST_DISCOVERABLE Intent. QLowEnergyController::connectToDevice() startAdvertising() addService() This commit moves the permission check from the construction time to these individual entry functions, as the creation itself does not seem to require permissions (tested this with a somewhat contrived setup which dodges earlier permission checks *). The aim here is to slightly improve the error reporting if an error is suspected to be due to missing permissions. User may decline the first permission requests and call subsequent functions which may or may not trigger a new permission query. For this reason this commit also adds another permission to startAdvertising(). *) In most if not all practical scenarios a local device and a device discovery has been made which both perform the permission checks. In addition the header include order was reorganized to preferred order where this commit touches them This commit amends a0542cff15d58db83a835f1a378a55a0ec117c9c Task-number: QTBUG-99590 Change-Id: Ic34a0184a79f6ea7c4a6643b9603e8ddaa18e28e Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit cc121cdef160a4ef528d1483ac365ac8319a1e42) Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
| * Introduce Android 12 / SDK 31+ bluetooth permissionsJuha Vuolle2022-03-241-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Android 12 introduces three new bluetooth runtime permissions which are required to use bluetooth. This commit introduces these permissions. The permission requirements are sprinkled throughout the Android bluetooth APIs, and we need to make sure all user codepaths are covered. As next step we can also reduce the < 31 permissions when building for 31+ target, but this possibly requires some buildsystem related support as well. Task-number: QTBUG-99590 Change-Id: Iab4b7d6d9935509e669265ed6851990d49a3a7e1 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit a0542cff15d58db83a835f1a378a55a0ec117c9c) Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* | Revert "Update commercial license headers"v5.15.3-lts-lgplTarja Sundqvist2021-03-241-20/+20
|/ | | | | | | | | | | This reverts commit 0db3b38521e11147cb802798a2cb7811a96029a9. Revert of commercial license headers is required for Qt 5.15.3 opensource release. Task-number: QTBUG-91108 Change-Id: Ie82dac4e6a4e2e0e1207d17a10c09701871d6875 Reviewed-by: Jukka Jokiniva <jukka.jokiniva@qt.io>
* Update commercial license headersTarja Sundqvist2021-02-021-20/+20
| | | | | | | | | | | | | | | Updated header.COMM to the files in tqtc-qtconnectivity. Examples, tests or documentation files are not updated. The commercial license header may contain some additional lines so that its line count equals with the earlier license header. Reason for this is that some autotests use hard coded line numbers and a change in the line count causes failures in test. Task-number: QTQAINFRA-4159 Change-Id: Icf450df25282ffadf5bcd0950753d17ba6ab57e3 Reviewed-by: Antti Kokko <antti.kokko@qt.io>
* Do not handle PAIRING_VARIANT_PINAlex Blasche2019-07-171-11/+0
| | | | | | | | | | | | | | | The user has to enter a pin in such cases. Since QBluetoothLocalDevice does not have an API to return a pin it makes no sense for QtBluetooth to handle this type of request. Android will provide its own fall back form. This patch is mostly a revert of f8c0572ddcd. Fixes: QTBUG-76565 Task-number: QTBUG-70295 Change-Id: I61062ac84ce508f3b82c7359a60d5c9c5bba86a4 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Use QAndroidJniExceptionCleaner instead of QAndroidJniEnvironmentBogDan Vatra2019-04-051-11/+4
| | | | | Change-Id: I357091799f04a3ef1c8df78960eb63a46e2b3d6c Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Minor code cleanup for QBluetoothLocalDevice implementation on AndroidAlex Blasche2018-09-261-14/+10
| | | | | Change-Id: I22da03879c23f6b6842cb832cea0cfee6e016445 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Properly handle pin code pairing on AndroidAlex Blasche2018-09-261-0/+11
| | | | | | | | | | | Most likely this paring variant was forgotten when Android support for QBluetoothLocalDevice was implemented. This variant is rather uncommon and Android's default pairing handler are likely to automatically handle such requests too. Fixes: QTBUG-70295 Change-Id: I618242da415574245e5a213a6e34f190c685c8e9 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Android: Workaround buggy BT implementationv5.8.0-rc1v5.8.0BogDan Vatra2016-12-081-38/+22
| | | | | | | | | On some devices (e.g. HTC 10) calling BluetoothAdapter.getDefaultAdapter() always fails first time. Task-number: QTBUG-57489 Change-Id: I3a22a831f9a13d880756b598c408ab21a0f52126 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Android: Fixed crashBogDan Vatra2016-12-081-0/+4
| | | | | | | | | | getDefaultAdapter might fail and it will throw an exception if the bt is not turned on, we must clear all pending exceptions otherwise next java call will crash the application. Task-number: QTBUG-57489 Change-Id: I191247528065acb3cdc4f6c0d36371ebf9f2e2c8 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Updated license headersAntti Kokko2016-01-201-15/+21
| | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I856c13e2a6d4d12c46e1286b0ca1c092ee4608f8 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Don't register meta types during static init time5.5Alex Blasche2015-11-301-0/+2
| | | | | | | | | | The QMetaType register my not be up and running by the time we attempt these meta type registration. Change-Id: I1a857a936a24b4b00a49574fac311c08c09b3d5a Task-number: QTBUG-49455 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Merge branch '5.4' into 5.5Alex Blasche2015-04-011-28/+10
|\ | | | | | | Change-Id: I177affc6c60fd3cc55e914a7ea2a9aeba260906f
| * Android: Fix crash in QBluetoothLocalDevice ctor due to Java exceptionAlex Blasche2015-03-181-28/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In general BluetoothAdapter.getDefaultAdapter should not throw an exception. If the device does not support Bluetooth the function should return a null reference only. However some devices throw a RuntimeException as well. We need to catch it to prevent unwinding of the stack. At the same time the patch simplifies the code by using QAndroidJniObject where possible. [ChangeLog][QtBluetooth][Android] Fixed crash in QBluetoothLocalDevice ctor on some devices due to a platform exception in QBluetoothAdapter.getDefaultAdapter(). Task-number: QTBUG-45066 Change-Id: I933783cda891127e5e37722f96f477c13b433ca7 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
* | Update copyright headersJani Heikkinen2015-02-161-7/+7
|/ | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Change-Id: I3822a6484e8f7a420330de1cb1aeb0c3d1cf41b7 Reviewed-by: Sergio Ahumada <sahumada@texla.cl>
* Android: Enable pairing for Android v15+Alex Blasche2015-02-021-3/+3
| | | | | | | | | | | | | | The required API became public in Android v19 which is what was used as check so far. However the same API was already privately provided since Android v15. THis patch ensures that older Android versions can create pairing requests too. This patch was provided by George Najarian. Task-number: QTBUG-43757 Change-Id: I0f38e538a972341a6acf719098f1010e52b639b7 Reviewed-by: BogDan Vatra <bogdan@kde.org> Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
* Update license headers and add new licensesJani Heikkinen2014-08-241-18/+10
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 & LICENSE.GPLv2 - Removed LICENSE.GPL Change-Id: I7a8b8b787fcae9a178794364efdefe1021d10b1b Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
* Fix coding style in QBluetoothOleg Shparber2014-04-231-94/+107
| | | | | | | | Affected: QBluetooth, QBluetoothAddress, QBluetoothDeviceDiscoveryAgent, QBluetoothDeviceInfo, QBluetoothHostInfo, QBluetoothLocalDevice Change-Id: Ia5af61f87eafecfba56b75fa61b81014cdd38960 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
* Android: Improve QBluetoothLocalDevice::connectedDevices()Alex Blasche2014-03-241-2/+36
| | | | | | | | | | | | | | | There is no API to get the list of connected Bluetooth devices on Android. However there are service API's which return a list of their current clients. In this particular case we find the GATT related service connections. We use that info to complement the internal list of connected devices. Note that although this is using Bluetooth Low Energy related API's the Qt API does not support this feature at this point in time. Task-number: QTBUG-36764 Change-Id: Ia8266f3a9d24fd16afdd636ca2d3d0a0c6b2b499 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
* Android: Fix crashes due to concurrency issuesAlex Blasche2014-03-111-0/+1
| | | | | | | | | | | | | | | BroadcastReceiver.onReceive() is executed in the main thread whereas the Qt classes are in a different thread. This created issues whereby Java's qtObject pointer was reset by the Qt classes/thread but onReceive still trying to access the same object later on. In most cases the Qt classes using BroadcastReceiver were half way through their object tear down. This patch fixes the problem by guarding qtObject against concurrent thread access and ensures that the qtObject pointer is reset before the object tear down starts. Change-Id: Iab97b0af8e10686d97419ac8504f2fe69e9536f3 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
* Port QtBluetooth to AndroidAlex Blasche2014-02-131-0/+443
This is a feature merge to dev targeting Qt 5.3. Known issues: -QTBUG-36754: QBluetoothServer::close() crashes -QTBUG-36763: QBluetothTransferManager port to Android not possible -QTBUG-36764: Improve QBluetoothLocalDevice::connectedDevices() -QTBUG-36810: Remove direct use of Android action strings The above issues and some other minor TODO's will be addressed until final release time. Task-number: QTBUG-33792 [ChangeLog][QtBluetooth][Android] QtBluetooth has been ported to Android. Change-Id: I31ba83e3b7d6aa68e7258b7e43235de7d1a6e68a Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>