@@ -57,28 +57,13 @@ public override Task<PermissionStatus> CheckStatusAsync()
5757 if ( RequiredPermissions == null || RequiredPermissions . Length <= 0 )
5858 return Task . FromResult ( PermissionStatus . Granted ) ;
5959
60- var context = Platform . AppContext ;
61- var targetsMOrHigher = context . ApplicationInfo . TargetSdkVersion >= BuildVersionCodes . M ;
62-
6360 foreach ( var ( androidPermission , isRuntime ) in RequiredPermissions )
6461 {
6562 var ap = androidPermission ;
6663 if ( ! IsDeclaredInManifest ( ap ) )
6764 throw new PermissionException ( $ "You need to declare using the permission: `{ androidPermission } ` in your AndroidManifest.xml") ;
6865
69- var status = PermissionStatus . Granted ;
70-
71- if ( targetsMOrHigher )
72- {
73- if ( ContextCompat . CheckSelfPermission ( context , androidPermission ) != Permission . Granted )
74- status = PermissionStatus . Denied ;
75- }
76- else
77- {
78- if ( PermissionChecker . CheckSelfPermission ( context , androidPermission ) != PermissionChecker . PermissionGranted )
79- status = PermissionStatus . Denied ;
80- }
81-
66+ var status = DoCheck ( ap ) ;
8267 if ( status != PermissionStatus . Granted )
8368 return Task . FromResult ( PermissionStatus . Denied ) ;
8469 }
@@ -107,6 +92,38 @@ public override async Task<PermissionStatus> RequestAsync()
10792 return PermissionStatus . Granted ;
10893 }
10994
95+ protected virtual PermissionStatus DoCheck ( string androidPermission )
96+ {
97+ var context = Platform . AppContext ;
98+ var targetsMOrHigher = context . ApplicationInfo . TargetSdkVersion >= BuildVersionCodes . M ;
99+
100+ if ( ! IsDeclaredInManifest ( androidPermission ) )
101+ throw new PermissionException ( $ "You need to declare using the permission: `{ androidPermission } ` in your AndroidManifest.xml") ;
102+
103+ var status = PermissionStatus . Granted ;
104+
105+ if ( targetsMOrHigher )
106+ {
107+ status = ContextCompat . CheckSelfPermission ( context , androidPermission ) switch
108+ {
109+ Permission . Granted => PermissionStatus . Granted ,
110+ Permission . Denied => PermissionStatus . Denied ,
111+ _ => PermissionStatus . Unknown
112+ } ;
113+ }
114+ else
115+ {
116+ status = PermissionChecker . CheckSelfPermission ( context , androidPermission ) switch
117+ {
118+ PermissionChecker . PermissionGranted => PermissionStatus . Granted ,
119+ PermissionChecker . PermissionDenied => PermissionStatus . Denied ,
120+ PermissionChecker . PermissionDeniedAppOp => PermissionStatus . Denied ,
121+ _ => PermissionStatus . Unknown
122+ } ;
123+ }
124+ return status ;
125+ }
126+
110127 protected virtual async Task < PermissionResult > DoRequest ( string [ ] permissions )
111128 {
112129 TaskCompletionSource < PermissionResult > tcs ;
@@ -233,6 +250,17 @@ public override (string androidPermission, bool isRuntime)[] RequiredPermissions
233250 ( Manifest . Permission . AccessFineLocation , true )
234251 } ;
235252
253+ public override Task < PermissionStatus > CheckStatusAsync ( )
254+ {
255+ if ( DoCheck ( Manifest . Permission . AccessFineLocation ) == PermissionStatus . Granted )
256+ return Task . FromResult ( PermissionStatus . Granted ) ;
257+
258+ if ( DoCheck ( Manifest . Permission . AccessCoarseLocation ) == PermissionStatus . Granted )
259+ return Task . FromResult ( PermissionStatus . Restricted ) ;
260+
261+ return Task . FromResult ( PermissionStatus . Denied ) ;
262+ }
263+
236264 public override async Task < PermissionStatus > RequestAsync ( )
237265 {
238266 // Check status before requesting first
0 commit comments