Skip to content

Commit

Permalink
release: 1.9.11
Browse files Browse the repository at this point in the history
  • Loading branch information
wn-na committed Jul 28, 2024
1 parent 3446a6f commit 67b66bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class CaptureProtectionModule extends ReactContextBaseJavaModule implemen
// Activity.ScreenCaptureCallback is Add API level 34
public static Object screenCaptureCallback = null;

private Activity getReactCurrentActivity() {
return reactContext.getCurrentActivity();
}

private Method getScreenCaptureCallback() {
if (Build.VERSION.SDK_INT < 34) {
return null;
Expand Down Expand Up @@ -213,13 +217,17 @@ private boolean requestStoragePermission() {
? "android.permission.READ_MEDIA_IMAGES" // Manifest.permission.READ_MEDIA_IMAGES
: Manifest.permission.READ_EXTERNAL_STORAGE;

if (ContextCompat.checkSelfPermission(getCurrentActivity(),
if (getReactCurrentActivity() == null) {
return false;
}

if (ContextCompat.checkSelfPermission(getReactCurrentActivity(),
requestPermission) == PackageManager.PERMISSION_GRANTED) {
Log.d(NAME, "Permission is granted");
return true;
} else {
Log.d(NAME, "Permission is revoked");
ActivityCompat.requestPermissions(getCurrentActivity(), new String[] { requestPermission }, 1);
ActivityCompat.requestPermissions(getReactCurrentActivity(), new String[] { requestPermission }, 1);
return false;
}
} catch (Exception e) {
Expand Down Expand Up @@ -280,7 +288,11 @@ private void removeListener() {
}

private boolean isSecureFlag() {
return (getCurrentActivity().getWindow().getAttributes().flags
Activity currentActivity = getReactCurrentActivity();
if (currentActivity == null) {
return false;
}
return (currentActivity.getWindow().getAttributes().flags
& WindowManager.LayoutParams.FLAG_SECURE) != 0;
}

Expand Down Expand Up @@ -353,7 +365,12 @@ public void isScreenRecording(Promise promise) {
public void preventScreenshot(Promise promise) {
runOnUiThread(() -> {
try {
getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
Activity currentActivity = getReactCurrentActivity();
if (currentActivity == null) {
Log.w(NAME, "preventScreenshot: Current Activity is null");
return;
}
currentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

sendEvent(CaptureProtectionConstant.LISTENER_EVENT_NAME, true, true,
CaptureProtectionConstant.CaptureProtectionModuleStatus.UNKNOWN.ordinal());
Expand All @@ -369,7 +386,12 @@ public void preventScreenshot(Promise promise) {
public void allowScreenshot(Boolean removeListener, Promise promise) {
runOnUiThread(() -> {
try {
getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
Activity currentActivity = getReactCurrentActivity();
if (currentActivity == null) {
Log.w(NAME, "allowScreenshot: Current Activity is null");
return;
}
currentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);

sendEvent(CaptureProtectionConstant.LISTENER_EVENT_NAME, false, false,
CaptureProtectionConstant.CaptureProtectionModuleStatus.UNKNOWN.ordinal());
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-capture-protection",
"version": "1.9.10",
"version": "1.9.11",
"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",
Expand Down

0 comments on commit 67b66bf

Please sign in to comment.