From c5a7a55aa983ab78d1daf89629a5fefb169e40f6 Mon Sep 17 00:00:00 2001 From: Lethe <37437842+0xlethe@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:24:40 +0900 Subject: [PATCH 1/2] fix: reactContext.getCurrentActivity is sometime return null --- .../CaptureProtectionModule.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/captureprotection/CaptureProtectionModule.java b/android/src/main/java/com/captureprotection/CaptureProtectionModule.java index 76cb505..4089492 100644 --- a/android/src/main/java/com/captureprotection/CaptureProtectionModule.java +++ b/android/src/main/java/com/captureprotection/CaptureProtectionModule.java @@ -53,7 +53,7 @@ private Method getScreenCaptureCallback() { if (Build.VERSION.SDK_INT < 34) { return null; } - return Utils.getMethod(reactContext.getCurrentActivity().getClass(), "registerScreenCaptureCallback"); + return Utils.getMethod(getCurrentActivity().getClass(), "registerScreenCaptureCallback"); } public void createCaptureCallback() { @@ -169,7 +169,7 @@ public void onHostResume() { createCaptureCallback(); } registerScreenCaptureCallback.invoke( - reactContext.getCurrentActivity(), + getCurrentActivity(), Utils.MainExecutor.INSTANCE, (Object) screenCaptureCallback); } @@ -187,10 +187,10 @@ public void onHostDestroy() { try { if (Build.VERSION.SDK_INT >= 34) { Method method = Utils.getMethod( - reactContext.getCurrentActivity().getClass(), + getCurrentActivity().getClass(), "unregisterScreenCaptureCallback"); if (method != null && screenCaptureCallback != null) { - method.invoke(reactContext.getCurrentActivity(), (Object) screenCaptureCallback); + method.invoke(getCurrentActivity(), (Object) screenCaptureCallback); } } } catch (Exception e) { @@ -212,13 +212,13 @@ private boolean requestStoragePermission() { ? "android.permission.READ_MEDIA_IMAGES" // Manifest.permission.READ_MEDIA_IMAGES : Manifest.permission.READ_EXTERNAL_STORAGE; - if (ContextCompat.checkSelfPermission(reactContext.getCurrentActivity(), + if (ContextCompat.checkSelfPermission(getCurrentActivity(), requestPermission) == PackageManager.PERMISSION_GRANTED) { Log.d(NAME, "Permission is granted"); return true; } else { Log.d(NAME, "Permission is revoked"); - ActivityCompat.requestPermissions(reactContext.getCurrentActivity(), new String[] { requestPermission }, 1); + ActivityCompat.requestPermissions(getCurrentActivity(), new String[] { requestPermission }, 1); return false; } } @@ -275,7 +275,7 @@ private void removeListener() { } private boolean isSecureFlag() { - return (reactContext.getCurrentActivity().getWindow().getAttributes().flags + return (getCurrentActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_SECURE) != 0; } @@ -348,7 +348,7 @@ public void isScreenRecording(Promise promise) { public void preventScreenshot(Promise promise) { runOnUiThread(() -> { try { - reactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); sendEvent(CaptureProtectionConstant.LISTENER_EVENT_NAME, true, true, CaptureProtectionConstant.CaptureProtectionModuleStatus.UNKNOWN.ordinal()); @@ -364,7 +364,7 @@ public void preventScreenshot(Promise promise) { public void allowScreenshot(Boolean removeListener, Promise promise) { runOnUiThread(() -> { try { - reactContext.getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); sendEvent(CaptureProtectionConstant.LISTENER_EVENT_NAME, false, false, CaptureProtectionConstant.CaptureProtectionModuleStatus.UNKNOWN.ordinal()); From 299588fbdf9c99af32f53451104c3b881e2f307c Mon Sep 17 00:00:00 2001 From: Lethe <37437842+0xlethe@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:25:34 +0900 Subject: [PATCH 2/2] release: 1.9.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a819a2b..02de675 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-capture-protection", - "version": "1.9.5", + "version": "1.9.6", "description": "It’s a library for React Native to control simple capture events(i.e. Screenshot or Screen record)", "main": "lib/commonjs/index", "module": "lib/module/index",