Repository navigation
Conversation
|
I created new branch from unoplatform/master, reapply all changes from previous PR, push it.... and got (on web) conflict in |
There was a problem hiding this comment.
Thanks. I've tested your PR, and this is what the sample gives:
Creating an activity to validate the permissions is not the right way to do this, as it pops up a new full screen activity to ask for permissions.
Also, I noticed that the existing PermissionsHelper already provides the infrastructure to validate permissions, so I wonder why you needed another one to do so. What's missing in here ?
Finally, you need to apply the code formatting rules of the Uno project. The best way to do so is to use the "cleanup" tool from VS, at the bottom of the code editor:
|
Seems like test environment is different than normal app environment (as this code is working when I call it from my uno-app). Android.App.Application.Context is null? Yes, there is some permission helper implementation, but it doesn't work. I tried to use it when I tried to use geolocation. As effects of my work on geolocation, I created PR for geolocation (#1998, Oct 31, 2019) - simple bug correction in Geolocator.RequestAccessAsync, than #2024 (Nov 5, 2019) - much more complete Geolocator implementation, and full code I'm using in my app (KrakTram, public transport in Kraków) - "// this code would not compile here - but it compile in your own app.". Than you add 'help needed' tag for it, to split this into levels (I don't know what you exactly mean by this levels), than using your suggestion I open another PR with all code that not require splitting into levels to #2536 (Jan 25). Many comments/code changes from peer review was done in this process :) Searching how to implement OpenFilePicker, I encounter example with defining Activity (not in manifest, but as [Activity flag). I use this general idea to make permission subroutines to my build of Uno, reworked geolocator, SMS messages, call log, known folders, etc. to use this subroutines instead of implementing it in all of them (as you commented in #2773, on 23rd March). |
|
What does not
No the environment is not null, but the activity is not created with the proper flags. In any case, this is not a good solution to this problem.
Can you remind me what does not work ? The wiring up should be enough for the permissions request to be raised. |
|
Ok, environment is not null, but maybe standard Uno-Android-App is wrapped in Activity, and test is not wrapped? I only guessing, because when I call AndroidPermissionAsync or MissingPermissions from my app, it works. But in test, it throws exception (screenshot you included shows it) about StartActivity outside Activity, so in test it is outside Activity, and in app - it is inside Activity. Previous implementation doesn't work, i.e. it doesn't display any dialog. |
|
The point of the existing implementation is to forward the calls from the Uno layer to the Uno.UI layer. If calls are missing, let's add them to make the missing permissions work. |
|
The point of existing implementation is - it doesn't work. And never did. If you don't want to accept this PR, you can change current permission helper methods, and mark it as 'breaking change'. And I will simply wait till this would be done, and then create PR for accessing SMS log (read/write). CalendarDatePicker PR was ready in November, now support for it 'is planned' (six months later), so also callog, contacts, SMS, knownfolders can wait months till someone else (re)implement it. |
|
Thank you for the explanation. The current implementation you're proposing is not adequate as it starts a new activity, and should not. The current implementation of the permission helper does have access to the current activity through this method: And are currently used by existing parts of Uno (camera capture being one). Are those not working for you as well ? As for the other PRs you're mentioning, many of those PRs are missing the samples we requested. |
|
I didn't try camera, I tried to use current implementation for GPS. As far as I remember (it was in november), current implementation doesn't show system dialog, so I was forced to make working implementation by myself. At first, code works only in app, not in Uno, as it has not access to activity (or something like that, my memory is not so good to remember such details after half a year). Why making Activity is wrong? |
|
I created empty Uno app. Shared mainpage.xaml has only TextBlock and Button, button click handler exactly as in test file in this PR. As Uno.UI, I used my build (with this PR, #3025, included). Build/deploy to real device, with Android 8.1 Go. When I click button without adding permission to Manifest, it correctly shows "MissingPermissions returned NULL, check if app manifest includes AccessFineLocation". And when I click it with declaring permission in Manifest, I got system dialog asking grant/deny permission. So, there is some difference between running code as UserControl/inside test and as App. And this is very serious problem! Maybe some other tests also fail, both false positive and false negative... |
|
As I mentioned above, making a activity pops up an opaque activity above the application. This is not an acceptable behavior for an application. As for the existing permissions helper, it works properly. I've adjusted the GeoLocator in #3064 so that it requests the permissions properly. Please take a look at the change to use it in your PR. If you need more features in the permissions helper, add it to the existing structure. |
|
Geolocator for Android should be rewritten - see my PRs for this. Not only asking for permission. |
|
For the GeoLocation, try again, this is what the PR I mentioned does. |
|
Correction of false implementation of geolocator RequestAccessAsync was in PR#1998, Oct 31, 2019. At this time, no one comments that current implementation of permissionhelper works... Before I change any of my PRs, I have to check again if current implementation of permissionhelper works. Maybe extend it to methods as in this PR (with list of permission, and not single permission on input). I don't expect that your PR #3064 would have any tests... Besides, it probably should be in permissionhelper.android.cs, not permissionhelper.cs file, as it is only for Android. |
|
The PR #3064 already has a test, and it was failing on android: https://github.com/unoplatform/uno/blob/master/src/SamplesApp/UITests.Shared/Windows_Devices/GeolocatorTests.xaml
|
|
Ok, I tested your version. And yes, it shows system permission dialog (when called from app, I didn't try if dialog is also shown when called from Uno). This dialog is same as in my version (same look of whole screen, same ability to interact - either answer in this dialog, or open task manager and kill app). |
|
That what I mean by modifying the PermissionsHelper to add the missing parts. If there is a need for multi-permissions check, they you can add support for it. The CancellationToken is generally provided (or should be if not) by the AsyncAction builder, but in #3064 it cannot be provided because the API signatures are not the right ones (and will need to be adjusted). |
|
Can testing permission be in Uno.UWP, without call to Uno.UI? This call is unncesessary. |
|
No it cannot, it has to be delegated to Uno.UI, but that's not an issue. It's also possible to change the output to be an enum instead of a boolean. We can add a |
|
I mean permission check, not system dialog asking for permission. Why "it has to be delegated to Uno.UI"? |
|
It has to be delegated to Uno.UI because that's where the |
|
BaseActivity is not used in permission checking at all. |
|
BaseActivity is used in the permissions checking, please take a look at this line: |
|
And the permission request: |
|
Yes, you use BaseActivity. But my version uses Android.Support.V4.Content.ContextCompat.CheckSelfPermission(Android.App.Application.Context, permission). See code in this PR. |
|
My question "Can testing permission be in Uno.UWP, without call to Uno.UI?" is not about technical possibility (I know that it can be done), but "Would you accept such code?". |
|
The relevant code should be at the same place, whether it's checking or requesting, even if Application.Context is available in the Uno assembly. If you need to makes changes, change the delegates so that it fits your extended scenario. |
|
Ok. So, if required methods has to be hard to create (and not as simple as possible), I would not have enough time for this in near future... Pity. |
|
It's not hard to create, it's about moving code from one layer to another. Otherwise, use the methods as is in your existing PRs even if it's asking one permissions at a time. |
|
Would it be ok? With body of main methods in Uno.UI, and called from several methods in Uno.UWP? |
jeromelaban
left a comment
There was a problem hiding this comment.
Thanks for the update, this is much better! This will allow you to update your other PRs.
| #region "submethods for MissingPermissions" | ||
| private static IList<string> GetManifestPermissions() | ||
| { | ||
| // get all permission declared in Manifest (can be null) |
There was a problem hiding this comment.
This goes into the xml comment
|
Why there are conflicting files? I used rebase unoplatform/master? |
| /// </summary> | ||
| /// <param name="requiredPermissions">Permissions that are required. Can be null.</param> | ||
| /// <param name="optionalPermissions">Permissions that are required only if declared in Manifest. Can be null.</param> | ||
| /// <returns>Array of all permission that is not granted at this moment (can be empty!), or null if some error occured</returns> |
There was a problem hiding this comment.
| /// <returns>Array of all permission that is not granted at this moment (can be empty!), or null if some error occured</returns> | |
| /// <returns>Array of all permission that is not granted at this moment (can be empty!), or null if some error occurred </returns> | |
| return null; | ||
| } | ||
|
|
||
| // prepare list of all permissions (all required, and all optional defined in Manifest |
There was a problem hiding this comment.
| // prepare list of all permissions (all required, and all optional defined in Manifest | |
| // prepare a list of all permissions (all required, and all optional defined in Manifest) | |
| /// </summary> | ||
| /// <param name="requiredPermissions">Permissions that are required. Can be null.</param> | ||
| /// <param name="optionalPermissions">Permissions that are required only if declared in Manifest. Can be null.</param> | ||
| /// <param name="ignoreErrors">if 'true', then do not throw exception on error, and simply retur false</param> |
There was a problem hiding this comment.
| /// <param name="ignoreErrors">if 'true', then do not throw exception on error, and simply retur false</param> | |
| /// <param name="ignoreErrors">if 'true', then do not throw exception on error, and simply return false</param> | |
| bool allGranted = result.GrantResults.All(r => r == Android.Content.PM.Permission.Granted); | ||
| return allGranted; | ||
| } | ||
| return false; // it shouldn't happen (if it happens, then there is some error (in Android?). Maybe we even should throw exception... |
There was a problem hiding this comment.
| return false; // it shouldn't happen (if it happens, then there is some error (in Android?). Maybe we even should throw exception... | |
| return false; // it shouldn't happen (if it happens, then there is some error (in Android?). Maybe we even should throw an exception... | |
| /// </summary> | ||
| /// <param name="requiredPermissions">Permissions that are required. Can be null.</param> | ||
| /// <param name="optionalPermissions">Permissions that are required only if declared in Manifest. Can be null.</param> | ||
| /// <returns>Array of all permission that is not granted at this moment (can be empty!), or null if some error occured</returns> |
There was a problem hiding this comment.
| /// <returns>Array of all permission that is not granted at this moment (can be empty!), or null if some error occured</returns> | |
| /// <returns>Array of all permission that is not granted at this moment (can be empty!), or null if some error occurred </returns> |
| /// Return null on error, or array of permission to be asked for (not granted at this time). | ||
| /// </summary> | ||
| /// <param name="requiredPermission">Permission that is </param> | ||
| /// <returns>Array with permission if it is not granted at this moment (can be empty!), or null if some error occured</returns> |
There was a problem hiding this comment.
| /// <returns>Array with permission if it is not granted at this moment (can be empty!), or null if some error occured</returns> | |
| /// <returns>Array with permission if it is not granted at this moment (can be empty!), or null if some error occurred </returns> |
| /// </summary> | ||
| /// <param name="requiredPermissions">Permissions that are required. Can be null.</param> | ||
| /// <param name="optionalPermissions">Permissions that are required only if declared in Manifest. Can be null.</param> | ||
| /// <param name="ignoreErrors">if 'true', then do not throw exception on error, and simply retur false</param> |
There was a problem hiding this comment.
| /// <param name="ignoreErrors">if 'true', then do not throw exception on error, and simply retur false</param> | |
| /// <param name="ignoreErrors">if 'true', then do not throw exception on error, and simply return false</param> |
|
@pkar70 some conflicts need to be resolved for this PR ;) |
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days. |


GitHub Issue (If applicable): #
PR Type
What kind of change does this PR introduce?
All of above, and - at same time - none of above :)
What is the current behavior?
Current implementation of Android permission helper functions doesn't work.
Currently there is no possibility to invoke system dialog asking for permission from Uno code (e.g. from RequestAccessAsync methods).
So, PR #2024 (geolocator) is labelled as 'help needed' (to split code into levels - as was said in Lobby or in some comments), also PR #2544 (contacts), PR #2757 (calllog), and soon-to-be PR (SMS access) cannot be fully implemented (some code have to be included in app code, not inside Uno).
What is the new behavior?
New helper methods works inside Uno, and can invoke system dialog asking for permission.
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information
I made it as separate PR, to be used in all four PRs mentioned above, as code is common (and I don't want contacts-PR be dependend on e.g. geolocator PR). Also, it can be used from other Uno PRs and from user code.
I don't edit/modify current Android methods in permissionhelper.cs, as they can be somewhere used (structure of these methods are cumbersome, too complicated for me).
Reopened #2898/#2964
Internal Issue (If applicable):