@@ -57,28 +57,13 @@ public override Task<PermissionStatus> CheckStatusAsync()
57
57
if ( RequiredPermissions == null || RequiredPermissions . Length <= 0 )
58
58
return Task . FromResult ( PermissionStatus . Granted ) ;
59
59
60
- var context = Platform . AppContext ;
61
- var targetsMOrHigher = context . ApplicationInfo . TargetSdkVersion >= BuildVersionCodes . M ;
62
-
63
60
foreach ( var ( androidPermission , isRuntime ) in RequiredPermissions )
64
61
{
65
62
var ap = androidPermission ;
66
63
if ( ! IsDeclaredInManifest ( ap ) )
67
64
throw new PermissionException ( $ "You need to declare using the permission: `{ androidPermission } ` in your AndroidManifest.xml") ;
68
65
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 ) ;
82
67
if ( status != PermissionStatus . Granted )
83
68
return Task . FromResult ( PermissionStatus . Denied ) ;
84
69
}
@@ -107,6 +92,38 @@ public override async Task<PermissionStatus> RequestAsync()
107
92
return PermissionStatus . Granted ;
108
93
}
109
94
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
+
110
127
protected virtual async Task < PermissionResult > DoRequest ( string [ ] permissions )
111
128
{
112
129
TaskCompletionSource < PermissionResult > tcs ;
@@ -233,6 +250,17 @@ public override (string androidPermission, bool isRuntime)[] RequiredPermissions
233
250
( Manifest . Permission . AccessFineLocation , true )
234
251
} ;
235
252
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
+
236
264
public override async Task < PermissionStatus > RequestAsync ( )
237
265
{
238
266
// Check status before requesting first
0 commit comments