Commit a5b12ef2ee65dc0a379d671468d8adda4b2fdf4b

Authored by cuong
1 parent 66dde2f33f

reset

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

android/src/main/java/com/reactnativecommunity/rnpermissions/RNPermissionsModule.java
... ... @@ -37,40 +37,40 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
37 37 private static final String SETTING_NAME = "@RNPermissions:NonRequestables";
38 38 private static final int OVERLAY_PERMISSION_CODE = 1009;
39 39  
40   - private Promise mPickerPromise;
  40 + private Promise mPickerPromise;
41 41  
42   - private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {
43   - @Override
44   - public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
45   - if (requestCode == OVERLAY_PERMISSION_CODE) {
  42 + private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {
  43 + @Override
  44 + public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
  45 + if (requestCode == OVERLAY_PERMISSION_CODE) {
46 46 // Log.e("TEAGGGG", "OVERLAY_PERMISSION_CODE: "+ requestCode);
47   - if (mPickerPromise != null) {
48   - final WritableMap output = Arguments.createMap();
49   - final WritableMap settings = Arguments.createMap();
50   - output.putMap("settings", settings);
51   - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
52   - final ReactApplicationContext reactContext = getReactApplicationContext();
53   - if (!Settings.canDrawOverlays(reactContext)) {
54   - output.putString("status", "blocked");
  47 + if (mPickerPromise != null) {
  48 + final WritableMap output = Arguments.createMap();
  49 + final WritableMap settings = Arguments.createMap();
  50 + output.putMap("settings", settings);
  51 + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
  52 + final ReactApplicationContext reactContext = getReactApplicationContext();
  53 + if (!Settings.canDrawOverlays(reactContext)) {
  54 + output.putString("status", "blocked");
  55 + } else {
  56 + output.putString("status", "granted");
  57 + }
55 58 } else {
56   - output.putString("status", "granted");
  59 + if (resultCode == Activity.RESULT_CANCELED) {
  60 + output.putString("status", "blocked");
  61 + } else if (resultCode == Activity.RESULT_OK) {
  62 + output.putString("status", "granted");
  63 + }
57 64 }
58   - } else {
59   - if (resultCode == Activity.RESULT_CANCELED) {
60   - output.putString("status", "blocked");
61   - } else if (resultCode == Activity.RESULT_OK) {
62   - output.putString("status", "granted");
63   - }
64   - }
65 65  
66 66 // Log.e("TEAGGGG", "output: "+ output.toString());
67   - mPickerPromise.resolve(output);
  67 + mPickerPromise.resolve(output);
  68 + }
68 69 }
69 70 }
70   - }
71   - };
  71 + };
72 72  
73   - private static final String[][] PERMISSIONS = new String[][] {
  73 + private static final String[][] PERMISSIONS = new String[][] {
74 74 { "ACCEPT_HANDOVER", "android.permission.ACCEPT_HANDOVER" },
75 75 { "ACCESS_BACKGROUND_LOCATION", "android.permission.ACCESS_BACKGROUND_LOCATION" },
76 76 { "ACCESS_COARSE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION" },
... ... @@ -242,7 +242,7 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
242 242 }
243 243  
244 244 @ReactMethod
245   - public void checkOverlayPermission(final Promise promise) {
  245 + public void checkOverlayAndroid(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,7 @@ export interface Contract {
11 11  
12 12 check(permission: Permission): Promise<PermissionStatus>;
13 13  
14   - checkOverlayPermission(): Promise<boolean>;
  14 + checkOverlayAndroid(): Promise<boolean>;
15 15  
16 16 request(
17 17 permission: Permission,
... ... @@ -14,7 +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 checkOverlayPermission = module.checkOverlayPermission;
  17 +export const checkOverlayAndroid = module.checkOverlayAndroid;
18 18 export const request = module.request;
19 19 export const checkNotifications = module.checkNotifications;
20 20 export const requestNotifications = module.requestNotifications;
... ... @@ -26,7 +26,7 @@ export default {
26 26 RESULTS,
27 27 openSettings,
28 28 check,
29   - checkOverlayPermission,
  29 + checkOverlayAndroid,
30 30 request,
31 31 checkNotifications,
32 32 requestNotifications,
src/module.android.ts
... ... @@ -16,7 +16,7 @@ const RNP: {
16 16 checkNotifications: () => Promise<NotificationsResponse>;
17 17 openSettings: () => Promise<true>;
18 18 checkOrRequestOverlayPermission: () => Promise<true>;
19   - checkOverlayPermission: () => Promise<boolean>;
  19 + checkOverlayAndroid: () => Promise<boolean>;
20 20 getNonRequestables: () => Promise<Permission[]>;
21 21 isNonRequestable: (permission: Permission) => Promise<boolean>;
22 22 setNonRequestable: (permission: Permission) => Promise<true>;
... ... @@ -69,8 +69,8 @@ async function check(permission: Permission): Promise&lt;PermissionStatus&gt; {
69 69 }
70 70 }
71 71  
72   -async function checkOverlayPermission(): Promise<boolean> {
73   - return await RNP.checkOverlayPermission();
  72 +async function checkOverlayAndroid(): Promise<boolean> {
  73 + return await RNP.checkOverlayAndroid();
74 74 }
75 75  
76 76 async function request(
... ... @@ -168,7 +168,7 @@ async function requestMultiple&lt;P extends Permission[]&gt;(
168 168 export const module: Contract = {
169 169 openSettings,
170 170 check,
171   - checkOverlayPermission,
  171 + checkOverlayAndroid,
172 172 request,
173 173 checkNotifications,
174 174 requestNotifications: checkNotifications,
... ... @@ -42,7 +42,7 @@ export function checkNotifications(): Promise&lt;NotificationsResponse&gt; {
42 42 return RNP.checkNotifications();
43 43 }
44 44  
45   -async function checkOverlayPermission(): Promise<boolean> {
  45 +async function checkOverlayAndroid(): Promise<boolean> {
46 46 return true;
47 47 }
48 48  
... ... @@ -88,7 +88,7 @@ async function requestMultiple&lt;P extends Permission[]&gt;(
88 88 export const module: Contract = {
89 89 openSettings,
90 90 check,
91   - checkOverlayPermission,
  91 + checkOverlayAndroid,
92 92 request,
93 93 checkNotifications,
94 94 requestNotifications,
... ... @@ -6,11 +6,10 @@ async function check(): Promise&lt;PermissionStatus&gt; {
6 6 return RESULTS.UNAVAILABLE;
7 7 }
8 8  
9   -async function checkOverlayPermission(): Promise<PermissionStatus> {
  9 +async function checkOverlayAndroid(): Promise<PermissionStatus> {
10 10 return RESULTS.UNAVAILABLE;
11 11 }
12 12  
13   -
14 13 async function checkNotifications(): Promise<NotificationsResponse> {
15 14 return {status: RESULTS.UNAVAILABLE, settings: {}};
16 15 }
... ... @@ -27,7 +26,7 @@ async function checkMultiple&lt;P extends Permission[]&gt;(
27 26 export const module: Contract = {
28 27 openSettings: Promise.reject,
29 28 check,
30   - checkOverlayPermission,
  29 + checkOverlayAndroid,
31 30 request: check,
32 31 checkNotifications,
33 32 requestNotifications: checkNotifications,