flutter-permission-handler
flutter-permission-handler copied to clipboard
await Permission.phone.request().isGranted always be true
🐛 Bug Report
var status = await Permission.phone.request();
print(status); // status always be granted
if (await Permission.phone.request().isGranted) {
// always be true
}
Version: 5.0.1+1
Platform:
- [ ] :iphone: iOS
- [x] :robot: Android
it is very very critical bug/..
same :(
Hi @qiaolin-pan, I've tried to reproduce the issue but for me it works as it should.
Steps I took to reproduce:
-
Import dependency permission handler version ^6.1.1
-
Made a Flutter prroject with a single button
-
When clicked on the button it will ask for the permission
-
When clicking on deny (for 2 permissions) the status which is returned is denied.
-
When clicking on allow it wil be status granted.
Tested it on Android 9, 10, 11 (Emulator Pixel 3 and Samsung S9 and S20)
Flutter doctor -v
Flutter (Channel beta, 2.0.0, on Microsoft Windows [Version 10.0.19041.867], locale nl-NL) • Flutter version 2.0.0 at C:\Baseflow\flutter • Framework revision 60bd88df91 (4 weeks ago), 2021-03-03 09:13:17 -0800 • Engine revision 40441def69 • Dart version 2.12.0[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at C:\Users\Jan-Derk\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.3 • Java binary at: C:\Users\Jan-Derk\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.7042882\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted.
[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0) • Android Studio at C:\Users\Jan-Derk\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.7042882 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] IntelliJ IDEA Community Edition (version 2020.2) • IntelliJ at C:\Users\Jan-Derk\AppData\Local\JetBrains\Toolbox\apps\IDEA-C\ch-0\202.7660.26 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart
[√] Connected device (3 available) • AOSP on IA Emulator (mobile) • emulator-5556 • android-x86 • Android 9 (API 28) (emulator) • Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.90 • Edge (web) • edge • web-javascript • Microsoft Edge 89.0.774.57 ! Device RZ8R10RN1NF is not authorized. You might need to check your device for an authorization dialog.
• No issues found!
Is this issue still occuring using the newest version of the permission handler (version 6.1.1)? Please let us know if it does work, thanks in advance!
The status return by Permission.phone.request() is correct but Permission.phone.isGranted always return denied
The requestPermission method from your example :
The result :
I don't know if this is the same problem then this issue. I can create a new one if you prefer.
Hi @MobiliteDev, I tried to reproduce it again with your code snippet and I see what you mean.
when requesting the phone permission by executing Permission.phone.request()
the user get prompted 2 dialogs.
When both are allowed, and you check what the outcome is of Permission.phone.isGranted
you would expect indeed a true
back instead of the false
we both get. I will look into this issue a bit more, but for now I've found an easy to use (and also a good alternative) work around for it.
Instead of requesting the user for the permission, and checking later later for the isGranted
you can also do this:
Permission.phone.request().isGranted
. This will request the phone permission, and when you allow both permission the permission will return a boolean with a true
value, instead of false.
If you still want to know the PermissionStatus
of the phone
permission you can request it again. Another request on a permission that is already granted
will return a PermissionStatus.granted
.
So the code should look like this:
// Will return true when allowing both permission that will be prompted, denying one will result in a false.
final status = await Permission.phone.request().isGranted;
// Optional if you want to know the PermissionStatus
final permissionStatus = await Permission.phone.request();
I hope this will help you out for now, I will look into the code to see if I can fix the issue where it returns a false, even though it shouldn't. I'll give an update here if I know more.
EDIT: You can of course also instead of print("SHOULD BE GRANTED AFTER ACCEPT ==> ${await permission.isGranted}");
use the variable status
you made and call the isGranted
on that variable since it's a PermissionStatus
. So it will look like this: print("SHOULD BE GRANTED AFTER ACCEPT ==> ${status.isGranted}");
this will also result in the right value wether the permission is granted or not (true or false).
The problem is that one of the permissions is not granted. The permission in question is BIND_CALL_REDIRECTION_SERVICE
.
Context: #169 https://developer.android.com/reference/android/Manifest.permission.html#PROCESS_OUTGOING_CALLS
According to the documentation:
Protection level: dangerous. This is a hard restricted permission which cannot be held by an app until the installer on record allowlists the permission
.
@mvanbeusekom what is your opinion on this? We could implement requesting BIND_CALL_REDIRECTION_SERVICE
when the user calls Permission.phone.request()
, but that might not be desirable. In general, right now, multiple permissions are grouped that have different permission levels. To me, it does not make sense to require a dangerous permission such as BIND_CALL_REDIRECTION_SERVICE
when I am only interested in READ_PHONE_STATE
, for example. Would it make sense to have a separate permission for BIND_CALL_REDIRECTION_SERVICE
?
From PermissionUtils.java:153
:
case PermissionConstants.PERMISSION_GROUP_PHONE:
if (hasPermissionInManifest(context, permissionNames, Manifest.permission.READ_PHONE_STATE))
permissionNames.add(Manifest.permission.READ_PHONE_STATE);
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.Q && hasPermissionInManifest(context, permissionNames, Manifest.permission.READ_PHONE_NUMBERS)) {
permissionNames.add(Manifest.permission.READ_PHONE_NUMBERS);
}
if (hasPermissionInManifest(context, permissionNames, Manifest.permission.CALL_PHONE))
permissionNames.add(Manifest.permission.CALL_PHONE);
if (hasPermissionInManifest(context, permissionNames, Manifest.permission.READ_CALL_LOG))
permissionNames.add(Manifest.permission.READ_CALL_LOG);
if (hasPermissionInManifest(context, permissionNames, Manifest.permission.WRITE_CALL_LOG))
permissionNames.add(Manifest.permission.WRITE_CALL_LOG);
if (hasPermissionInManifest(context, permissionNames, Manifest.permission.ADD_VOICEMAIL))
permissionNames.add(Manifest.permission.ADD_VOICEMAIL);
if (hasPermissionInManifest(context, permissionNames, Manifest.permission.USE_SIP))
permissionNames.add(Manifest.permission.USE_SIP);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && hasPermissionInManifest(context, permissionNames, Manifest.permission.BIND_CALL_REDIRECTION_SERVICE))
permissionNames.add(Manifest.permission.BIND_CALL_REDIRECTION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && hasPermissionInManifest(context, permissionNames, Manifest.permission.ANSWER_PHONE_CALLS))
permissionNames.add(Manifest.permission.ANSWER_PHONE_CALLS);
break;