Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Permissions API's #18

Closed
Redth opened this issue Feb 24, 2018 · 2 comments
Closed

Permissions API's #18

Redth opened this issue Feb 24, 2018 · 2 comments
Assignees
Milestone

Comments

@Redth
Copy link
Member

Redth commented Feb 24, 2018

Check and Request permissions.

Internally we need to ensure we have API’s for a couple of things:

  • internal bool EnsurePermissionDeclared (string permission) checks if Info.plist on iOS, or AndroidManifest.xml, or x on UWP has the permission declared/defined and throws an exception with a meaningful error message including a link to documentation of how to ensure permissions are defined in the appropriate file for the given platform at runtime.

Permissions

public static class Permissions 
{
    public static Task<PermissionStatus> CheckPermissionAsync (string permission);
    public static Task<IDictionary<string, PermissionStatus>> CheckPermissionsAsync (params string[] permissions);

    public static Task<PermissionStatus> RequestPermissionAsync (string permission);
    public static Task<IDictionary<string, PermissionStatus>> RequestPermissionsAsync (params string[] permissions);
}

PermissionStatus (enum)

public enum PermissionStatus {
    Unknown,
    Denied,
    Disabled,
    Restricted,
    Granted,
}
@Redth Redth added this to the Preview-1 milestone Feb 24, 2018
@Redth Redth self-assigned this Feb 24, 2018
@Redth
Copy link
Member Author

Redth commented Feb 24, 2018

I think we also need some helper properties/static readonly fields that return the correct string permission for a given platform:

This is not how I'd want the actual implementation to be, but to illustrate the idea:

public static class PermissionType
{
#if __ANDROID__
    public static readonly Camera = "android.permission.CAMERA";
#elif __IOS__
    public static readonly Camera = "Camera";
#elif __UWP__
    public static readonly Camera = "Camera";
#endif
}

So that the user can call the api's more sanely splat:

await Permissions.RequestPermissionAsync(PermissionType.Camera);

@Redth
Copy link
Member Author

Redth commented Feb 24, 2018

I may be changing my mind on this a bit now. Looking at iOS and UWP, they both have different code paths depending on which permission has been requested, unlike Android which is just a string to identify the permission.

I'm starting to think an enum was already the best choice here.

@mattleibow mattleibow removed their assignment Mar 1, 2018
@Redth Redth added this to New in Triage Mar 7, 2018
@Redth Redth added this to Ready in v0.5.0-preview Mar 7, 2018
@Redth Redth moved this from Ready for Implementation to In Progress in v0.5.0-preview Mar 12, 2018
@Redth Redth removed this from New in Triage Mar 27, 2018
Redth added a commit that referenced this issue Mar 28, 2018
* Initial pass at permissions

* Don’t need async on EnsureDeclared

* Fix BOM that StyleCop was not happy about

* Use correct support lib package

* Added device tests for permissions

* Track android permission requests

This keeps a dictionary of permission requests so as to not duplicate existing requests for permissions, as well as to track their status when the results come in.

* Pass permission results call to Caboodle

* Check platform target, not runtime version

* New tuples!

* Add missing using

* iOS: return granted for irrelevant permissions

* Fix tests around LocationWhenInUse

* Permissions Device Tests check throws on some

* Get battery permission for android device tests

* Android permission requests should be runtime only

* Fix requestCode scope on android permissions

* Use inner method instead of delegate

* Refactor permission declaration check on iOS

* Only check Info.plist permissions on iOS 8.0+

* Always be making stylecop happy

* Permissions are internal only for v1
@jamesmontemagno jamesmontemagno moved this from In Progress to Backlog in v0.5.0-preview Mar 28, 2018
@Redth Redth closed this as completed Mar 29, 2018
@Redth Redth moved this from Backlog/Needs Specifications to In Review in v0.5.0-preview Apr 6, 2018
@Redth Redth moved this from In Review to Done in v0.5.0-preview Apr 6, 2018
@mattleibow mattleibow moved this from Done to Closed in v0.5.0-preview Apr 26, 2018
Redth pushed a commit that referenced this issue Jul 12, 2021
merge xamarin:main into dimonovdd:main
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
v0.5.0-preview
  
Closed
Development

No branches or pull requests

3 participants