Commit 948ea53f60d711a768a2de63db4b02ce40280691

Authored by cuong
1 parent 6da63a55a2

test android overlay

Showing 6 changed files with 34 additions and 0 deletions Side-by-side Diff

android/src/main/java/com/reactnativecommunity/rnpermissions/RNPermissionsModule.java
... ... @@ -240,4 +240,17 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
240 240 promise.resolve(output);
241 241 }
242 242 }
  243 +
  244 + @ReactMethod
  245 + public void checkOverlayAndroid(final Promise promise) {
  246 +// Check if Android M or higher
  247 + final ReactApplicationContext reactContext = getReactApplicationContext();
  248 + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && !Settings.canDrawOverlays(reactContext)) {
  249 + promise.resolve(false);
  250 + } else {
  251 + //default is granted :D
  252 + promise.resolve(true);
  253 + }
  254 + }
  255 +
243 256 }
... ... @@ -11,6 +11,8 @@ export interface Contract {
11 11  
12 12 check(permission: Permission): Promise<PermissionStatus>;
13 13  
  14 + checkOverlayAndroid(): Promise<boolean>;
  15 +
14 16 request(
15 17 permission: Permission,
16 18 rationale?: Rationale,
... ... @@ -14,6 +14,7 @@ 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 18 export const request = module.request;
18 19 export const checkNotifications = module.checkNotifications;
19 20 export const requestNotifications = module.requestNotifications;
... ... @@ -25,6 +26,7 @@ export default {
25 26 RESULTS,
26 27 openSettings,
27 28 check,
  29 + checkOverlayAndroid,
28 30 request,
29 31 checkNotifications,
30 32 requestNotifications,
src/module.android.ts
... ... @@ -16,6 +16,7 @@ const RNP: {
16 16 checkNotifications: () => Promise<NotificationsResponse>;
17 17 openSettings: () => Promise<true>;
18 18 checkOrRequestOverlayPermission: () => Promise<true>;
  19 + checkOverlayAndroid: () => Promise<boolean>;
19 20 getNonRequestables: () => Promise<Permission[]>;
20 21 isNonRequestable: (permission: Permission) => Promise<boolean>;
21 22 setNonRequestable: (permission: Permission) => Promise<true>;
... ... @@ -68,6 +69,10 @@ async function check(permission: Permission): Promise&lt;PermissionStatus&gt; {
68 69 }
69 70 }
70 71  
  72 +async function checkOverlayAndroid(): Promise<boolean> {
  73 + return await RNP.checkOverlayAndroid();
  74 +}
  75 +
71 76 async function request(
72 77 permission: Permission,
73 78 rationale?: Rationale,
... ... @@ -163,6 +168,7 @@ async function requestMultiple&lt;P extends Permission[]&gt;(
163 168 export const module: Contract = {
164 169 openSettings,
165 170 check,
  171 + checkOverlayAndroid,
166 172 request,
167 173 checkNotifications,
168 174 requestNotifications: checkNotifications,
... ... @@ -17,6 +17,7 @@ const RNP: {
17 17 options: NotificationOption[],
18 18 ) => Promise<NotificationsResponse>;
19 19 openSettings: () => Promise<true>;
  20 +
20 21 check: (permission: Permission) => Promise<PermissionStatus>;
21 22 request: (permission: Permission) => Promise<PermissionStatus>;
22 23 } = NativeModules.RNPermissions;
... ... @@ -41,6 +42,10 @@ export function checkNotifications(): Promise&lt;NotificationsResponse&gt; {
41 42 return RNP.checkNotifications();
42 43 }
43 44  
  45 +async function checkOverlayAndroid(): Promise<boolean> {
  46 + return true;
  47 +}
  48 +
44 49 export function requestNotifications(
45 50 options: NotificationOption[],
46 51 ): Promise<NotificationsResponse> {
... ... @@ -83,6 +88,7 @@ async function requestMultiple&lt;P extends Permission[]&gt;(
83 88 export const module: Contract = {
84 89 openSettings,
85 90 check,
  91 + checkOverlayAndroid,
86 92 request,
87 93 checkNotifications,
88 94 requestNotifications,
... ... @@ -6,6 +6,10 @@ async function check(): Promise&lt;PermissionStatus&gt; {
6 6 return RESULTS.UNAVAILABLE;
7 7 }
8 8  
  9 +async function checkOverlayAndroid(): Promise<PermissionStatus> {
  10 + return RESULTS.UNAVAILABLE;
  11 +}
  12 +
9 13 async function checkNotifications(): Promise<NotificationsResponse> {
10 14 return {status: RESULTS.UNAVAILABLE, settings: {}};
11 15 }
... ... @@ -22,6 +26,7 @@ async function checkMultiple&lt;P extends Permission[]&gt;(
22 26 export const module: Contract = {
23 27 openSettings: Promise.reject,
24 28 check,
  29 + checkOverlayAndroid,
25 30 request: check,
26 31 checkNotifications,
27 32 requestNotifications: checkNotifications,