Commit 58264047072709da5e46d38721577972c84af4bb

Authored by cuong
1 parent 948ea53f60

add checkOverlayPermission

requestOverlayPermission

Showing 6 changed files with 50 additions and 38 deletions Side-by-side Diff

android/src/main/java/com/reactnativecommunity/rnpermissions/RNPermissionsModule.java
... ... @@ -209,7 +209,7 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
209 209 //
210 210 //https://developer.android.com/preview/behavior-changes-all#manage_overlay
211 211 @ReactMethod
212   - public void checkOrRequestOverlayPermission(final Promise promise) {
  212 + public void requestOverlayPermission(final Promise promise) {
213 213 // Check if Android M or higher
214 214 final ReactApplicationContext reactContext = getReactApplicationContext();
215 215 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && !Settings.canDrawOverlays(reactContext)) {
... ... @@ -242,7 +242,7 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
242 242 }
243 243  
244 244 @ReactMethod
245   - public void checkOverlayAndroid(final Promise promise) {
  245 + public void checkOverlayPermission(final Promise promise) {
246 246 // Check if Android M or higher
247 247 final ReactApplicationContext reactContext = getReactApplicationContext();
248 248 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && !Settings.canDrawOverlays(reactContext)) {
... ... @@ -11,7 +11,9 @@ export interface Contract {
11 11  
12 12 check(permission: Permission): Promise<PermissionStatus>;
13 13  
14   - checkOverlayAndroid(): Promise<boolean>;
  14 + checkOverlayPermission(): Promise<boolean>;
  15 +
  16 + requestOverlayPermission(): Promise<PermissionStatus>;
15 17  
16 18 request(
17 19 permission: Permission,
... ... @@ -14,7 +14,8 @@ export * from &#39;./types&#39;;
14 14  
15 15 export const openSettings = module.openSettings;
16 16 export const check = module.check;
17   -export const checkOverlayAndroid = module.checkOverlayAndroid;
  17 +export const checkOverlayPermission = module.checkOverlayPermission;
  18 +export const requestOverlayPermission = module.requestOverlayPermission;
18 19 export const request = module.request;
19 20 export const checkNotifications = module.checkNotifications;
20 21 export const requestNotifications = module.requestNotifications;
... ... @@ -26,7 +27,8 @@ export default {
26 27 RESULTS,
27 28 openSettings,
28 29 check,
29   - checkOverlayAndroid,
  30 + checkOverlayPermission,
  31 + requestOverlayPermission,
30 32 request,
31 33 checkNotifications,
32 34 requestNotifications,
src/module.android.ts
... ... @@ -15,8 +15,8 @@ const RNP: {
15 15  
16 16 checkNotifications: () => Promise<NotificationsResponse>;
17 17 openSettings: () => Promise<true>;
18   - checkOrRequestOverlayPermission: () => Promise<true>;
19   - checkOverlayAndroid: () => Promise<boolean>;
  18 + checkOverlayPermission: () => Promise<boolean>;
  19 + requestOverlayPermission(): Promise<PermissionStatus>;
20 20 getNonRequestables: () => Promise<Permission[]>;
21 21 isNonRequestable: (permission: Permission) => Promise<boolean>;
22 22 setNonRequestable: (permission: Permission) => Promise<true>;
... ... @@ -41,9 +41,26 @@ async function openSettings(): Promise&lt;void&gt; {
41 41 }
42 42  
43 43 async function check(permission: Permission): Promise<PermissionStatus> {
44   - if (permission == PERMISSIONS.ANDROID.MANAGE_OVERLAY_PERMISSION) {
45   - console.warn("check MANAGE_OVERLAY_PERMISSION ts")
46   - const output = await RNP.checkOrRequestOverlayPermission()
  44 + if (!RNP.available.includes(permission)) {
  45 + return RESULTS.UNAVAILABLE;
  46 + }
  47 +
  48 + if (await Core.check(permission as CorePermission)) {
  49 + return RESULTS.GRANTED;
  50 + }
  51 +
  52 + return (await RNP.isNonRequestable(permission))
  53 + ? RESULTS.BLOCKED
  54 + : RESULTS.DENIED;
  55 +}
  56 +
  57 +async function checkOverlayPermission(): Promise<boolean> {
  58 + return await RNP.checkOverlayPermission();
  59 +}
  60 +
  61 +async function requestOverlayPermission(): Promise<PermissionStatus> {
  62 + console.warn("requestOverlayPermission")
  63 + const output = await RNP.requestOverlayPermission()
47 64 if (output.status == RESULTS.GRANTED) {
48 65 return RESULTS.GRANTED
49 66 } else if (output.status == RESULTS.BLOCKED) {
... ... @@ -51,26 +68,6 @@ async function check(permission: Permission): Promise&lt;PermissionStatus&gt; {
51 68 } else {
52 69 return RESULTS.UNAVAILABLE
53 70 }
54   - // return (await RNP.checkOrRequestOverlayPermission())
55   - // ? RESULTS.BLOCKED
56   - // : RESULTS.DENIED;
57   - } else {
58   - if (!RNP.available.includes(permission)) {
59   - return RESULTS.UNAVAILABLE;
60   - }
61   -
62   - if (await Core.check(permission as CorePermission)) {
63   - return RESULTS.GRANTED;
64   - }
65   -
66   - return (await RNP.isNonRequestable(permission))
67   - ? RESULTS.BLOCKED
68   - : RESULTS.DENIED;
69   - }
70   -}
71   -
72   -async function checkOverlayAndroid(): Promise<boolean> {
73   - return await RNP.checkOverlayAndroid();
74 71 }
75 72  
76 73 async function request(
... ... @@ -168,7 +165,8 @@ async function requestMultiple&lt;P extends Permission[]&gt;(
168 165 export const module: Contract = {
169 166 openSettings,
170 167 check,
171   - checkOverlayAndroid,
  168 + checkOverlayPermission,
  169 + requestOverlayPermission,
172 170 request,
173 171 checkNotifications,
174 172 requestNotifications: checkNotifications,
... ... @@ -32,6 +32,14 @@ async function check(permission: Permission): Promise&lt;PermissionStatus&gt; {
32 32 : RESULTS.UNAVAILABLE;
33 33 }
34 34  
  35 +async function checkOverlayPermission(): Promise<boolean> {
  36 + return true;
  37 +}
  38 +
  39 +async function requestOverlayPermission(): Promise<PermissionStatus> {
  40 + return RESULTS.UNAVAILABLE;
  41 +}
  42 +
35 43 async function request(permission: Permission): Promise<PermissionStatus> {
36 44 return RNP.available.includes(permission)
37 45 ? RNP.request(permission)
... ... @@ -42,10 +50,6 @@ export function checkNotifications(): Promise&lt;NotificationsResponse&gt; {
42 50 return RNP.checkNotifications();
43 51 }
44 52  
45   -async function checkOverlayAndroid(): Promise<boolean> {
46   - return true;
47   -}
48   -
49 53 export function requestNotifications(
50 54 options: NotificationOption[],
51 55 ): Promise<NotificationsResponse> {
... ... @@ -88,7 +92,8 @@ async function requestMultiple&lt;P extends Permission[]&gt;(
88 92 export const module: Contract = {
89 93 openSettings,
90 94 check,
91   - checkOverlayAndroid,
  95 + checkOverlayPermission,
  96 + requestOverlayPermission,
92 97 request,
93 98 checkNotifications,
94 99 requestNotifications,
... ... @@ -6,7 +6,11 @@ async function check(): Promise&lt;PermissionStatus&gt; {
6 6 return RESULTS.UNAVAILABLE;
7 7 }
8 8  
9   -async function checkOverlayAndroid(): Promise<PermissionStatus> {
  9 +async function checkOverlayPermission(): Promise<boolean> {
  10 + return true;
  11 +}
  12 +
  13 +async function requestOverlayPermission(): Promise<PermissionStatus> {
10 14 return RESULTS.UNAVAILABLE;
11 15 }
12 16  
... ... @@ -26,7 +30,8 @@ async function checkMultiple&lt;P extends Permission[]&gt;(
26 30 export const module: Contract = {
27 31 openSettings: Promise.reject,
28 32 check,
29   - checkOverlayAndroid,
  33 + checkOverlayPermission,
  34 + requestOverlayPermission,
30 35 request: check,
31 36 checkNotifications,
32 37 requestNotifications: checkNotifications,