[Android API 23+] Request for permissions on runtime - #6614
Conversation
4b9bda3 to
5264d86
Compare
|
@livecodepanos I think it would make things easier to have an api and callback handler in mblandroiddc.cpp and call it before calling anything that needs the permission. That way it's easier to setup the a static sentinel variable and a wait loop while waiting for the callback. Also it would hopefully be easier to reuse the same code in all the places required. |
|
|
|
still WIP until adding a |
| MCAndroidEngineRemoteCall("askPermission", "bx", &t_result, p_permission); | ||
|
|
||
| while (s_in_permission_dialog) | ||
| MCscreen -> wait(60.0, True, True); |
There was a problem hiding this comment.
@livecodepanos I think it might be simpler to make this a blocking wait MCscreen -> wait(60.0, False, True); as if we are using a dispatching wait it's feasible that there could be another request during it and the implementation would need to be much more complicated to handle that.
There was a problem hiding this comment.
If we do need dispatching wait then I think we would need to generate a request code from a sequence static uint and have s_in_permission_dialog and s_permission_granted be maps of request code -> bool and include the request code as a param in Java_com_runrev_android_Engine_doAskPermissionDone the correct wait loop can be broken.
| } | ||
| } | ||
|
|
||
| public static final int CAMERA_PERMISSION_REQUEST_CODE = 1; |
There was a problem hiding this comment.
If we aren't actually using the request code then we could just call all requests with 1. If we do need dispatching waits (see the other comment) then we probably need a unique code to come from the engine and map to the actual request.
|
|
||
| Introduced: 9.0.1 | ||
|
|
||
| OS: mobile |
There was a problem hiding this comment.
@livecodepanos OS and Platform entries here need to be swapped
| local tCameraPermissionGranted | ||
| put androidRequestPermission("android.permission.CAMERA") into tCameraPermissionGranted | ||
| if not tCameraPermissionGranted then | ||
| answer "This app is not permitted to access the device camera. You can change this \ |
There was a problem hiding this comment.
@livecodepanos this does not compile. Should be:
answer "This app is not permitted to access the device camera. You can change this" & \
"in the Settings app."
Interestingly enough I chatted to @runrevmark once about \ escaping newlines in string literals and it's both feasible and backwards compatible to do at some point.
There was a problem hiding this comment.
Good catch @montegoulding :)
I guess I need to use && instead of & (or add a space at the end of the first string)
| Boolean MCAndroidSystem::GetStandardFolder(MCNameRef p_folder, MCStringRef &r_folder) | ||
| { | ||
| // accessing "external documents", "external cache" etc requires Write External Storage permission | ||
| if (MCStringBeginsWith(MCNameGetString(p_folder), MCSTR("external"), kMCStringOptionCompareCaseless) && !MCAndroidCheckRuntimePermission(MCSTR("android.permission.WRITE_EXTERNAL_STORAGE"))) |
There was a problem hiding this comment.
@livecodepanos can you put everything after && onto a new line here
| { | ||
| if (p_sensor == kMCSensorTypeLocation) | ||
| { | ||
| bool t_success = MCAndroidCheckRuntimePermission(MCSTR("android.permission.ACCESS_COARSE_LOCATION")) && MCAndroidCheckRuntimePermission(MCSTR("android.permission.ACCESS_FINE_LOCATION")); |
|
@panos.merakos there’s a couple of minor patches to make but I’m also wondering if the LCS api should use a case insensitive enum |
|
Hehe I was thinking the same (i.e. to request just |
|
OK, I think we had better check with @runrevmark on the API to see what he thinks before reviewing OK. I'm not sure we expose many things in a low level way like this in the engine although I agree it does reduce longer term maintenance. |
|
I suggest: Note: RequestPermission does not return anything. Grant of permission is done with HasPermission subsequently. I suggest pTag is either a full permissions name (which is done case-sensitively) or if there is no '.' then it builds it as .toUpper(pTag). |
| put androidRequestPermission("android.permission.CAMERA") into tCameraPermissionGranted | ||
| put androidHasPermission("android.permission.CAMERA") into tCameraPermissionGranted | ||
| if not tCameraPermissionGranted then | ||
| androidRequestPermission("android.permission.CAMERA") |
There was a problem hiding this comment.
@livecodepanos you should drop the parentheses here and from the syntax element
| local tLocationPermissionGranted | ||
| put androidHasPermission("android.permission.ACCESS_FINE_LOCATION") into tLocationPermissionGranted | ||
| if not tLocationPermissionGranted then | ||
| androidRequestPermission("android.permission.ACCESS_FINE_LOCATION") |
|
|
||
| bool MCSystemRequestPermission(MCStringRef p_permission, bool& r_granted) | ||
| { | ||
| r_granted = MCAndroidCheckRuntimePermission(p_permission); |
There was a problem hiding this comment.
@livecodepanos you need to add do-nothing stubs for these to mbliphonemisc.mm I think
| permissionName (enum): | ||
| The name of the permission to request. | ||
|
|
||
| - "android.permission.CAMERA": permission to access the device camera. |
There was a problem hiding this comment.
@livecodepanos should this list all the dangerous permissions: https://developer.android.com/guide/topics/permissions/overview#permission-groups
|
@livecode-vulcan review ok 39b59ee |
|
💙 review by @montegoulding ok 39b59ee |
[Android API 23+] Request for permissions on runtime
|
😎 test success 39b59ee
|
No description provided.