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

Problem on setBluetoothState on android version 9 #352

Closed
1 of 3 tasks
akimakitalo opened this issue Apr 23, 2019 · 5 comments
Closed
1 of 3 tasks

Problem on setBluetoothState on android version 9 #352

akimakitalo opened this issue Apr 23, 2019 · 5 comments
Labels
android Relates to Android platform bug Something isn't working properly more info needed Further information is requested. If not provided, issue will be closed runtime issue An issue related to app runtime

Comments

@akimakitalo
Copy link

akimakitalo commented Apr 23, 2019

I'm submitting a ... (check one with "x"):

  • bug report
  • feature request
  • documentation issue

Bug report

Current behavior:
On android version 9 (Honor 9), setBluetoothState() does not work correctly anymore, and successCallback returns an incorrect value. I cannot confirm if this is a general change on android 9.0, or if this is a Huawei change that applies to Honor phones.

Prior to update to android 9, setBluetoothState correctly turned bluetooth on, while success callback was called properly.

After updating to android 9, setBluetoothState now causes a popup from OS asking the user to allow/deny change to bluetooth state. Presumably this is a security update intended to limit the ability of apps to change bluetooth state without user permission.

However the success callback is still called immediately and always returns OK, even if user has not yet granted permission to let the application change the bluetooth state or even if user ultimately denies permission.

Example of how it works right now on android 9:

  1. setBluetoothState() called with intent to set state to true.
  2. setBluetoothState() success callback called with "OK". At this point, bluetooth state has not changed.
  3. OS shows popup asking the user to confirm if bluetooth state should be changed.
  4. User eventually presses yes or no.
  5. If user pressed yes, bluetooth state changes to true. If user presses no, bluetooth state does not change.

Expected behavior:
setBluetoothState() should probably wait for user confirmation before calling the success callback, and call errorCallback if user denies permission to change bluetooth state.

Example on how it should work:

  1. setBluetoothState() called with intent to set state to true.
  2. OS shows popup asking the user to confirm if bluetooth state should be changed.
  3. User eventually presses yes or no.
  4. If user pressed yes, successCallback called. If user pressed no, errorCallback called with somekind of user_denied_permission error.

Steps to reproduce:

On android 9, simply do the following:

cordova.plugins.diagnostic.setBluetoothState((result) => {
    console.log(`successCallback result is ${result}, but bluetooth state has not yet changed, and will not change until user grants permission on OS popup.`);
}, (err) => {
    console.log(err);
}, true);

Environment information

  • Cordova CLI version
    • 8.0.0
  • Cordova platform version
    • android 7.1.4
  • Plugins & versions installed in project (including this plugin)
    • cordova.plugins.diagnostic 4.0.12 "Diagnostic"
  • Dev machine OS and version, e.g.
    - Win 7 professional

Runtime issue

  • Device details
    -Huawei Honor 9 (STF-L09)
  • OS details
    -Android version 9, EMUI: 9.0.1.162 (C432E2R1P5)


@dpa99c
Copy link
Owner

dpa99c commented Apr 25, 2019

Looks like there's not an easy fix here.

According to this SO post, modifying Bluetooth state programmatically (without prompting user permission) on Android 9+ requires WRITE_SETTINGS permission which itself requires a special permission request process (see here).

So the best course of action (as you've suggested) would be to try to hook in to the outcome of the permission request dialog.
However so far I've not found any example of how the plugin can get async notification of the user decision in that dialog on Android 9.

@dpa99c dpa99c added the bug Something isn't working properly label Apr 25, 2019
@dpa99c
Copy link
Owner

dpa99c commented May 11, 2019

I've tested this on a Pixel 2 running Android 9.0 and I'm not seeing the permissions dialog appear: setBluetoothState() works as expected.
So I wonder if this is specific to the Huawei Honor 9 variant of Android 9?

@dpa99c
Copy link
Owner

dpa99c commented Jun 16, 2019

Also tested on Android 10/Q Beta 4 running on Pixel 2 and also no permissions dialog when using setBluetoothState() to enable/disable the Bluetooth device setting

@dpa99c dpa99c added the more info needed Further information is requested. If not provided, issue will be closed label Jun 16, 2019
@dpa99c dpa99c added android Relates to Android platform runtime issue An issue related to app runtime labels Sep 30, 2019
@dpa99c
Copy link
Owner

dpa99c commented Jul 12, 2020

Closed as unable to repro

@dpa99c dpa99c closed this as completed Jul 12, 2020
@egeozer
Copy link

egeozer commented Mar 25, 2022

I know this is closed, but in order to reproduce, you need a Huawei phone with Android 9+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Relates to Android platform bug Something isn't working properly more info needed Further information is requested. If not provided, issue will be closed runtime issue An issue related to app runtime
Projects
None yet
Development

No branches or pull requests

3 participants