gbumps / react-native-screenguard

A Native screenshot blocking library for React-Native developer, with background customizable after captured. Screenshot detector are also supported.
https://gbumps.github.io/react-native-screenguard/
MIT License
231 stars 28 forks source link

Application crashing in production in particular devices #24

Closed surajQuitsure closed 1 year ago

surajQuitsure commented 1 year ago

As per the google crashlytics, while registering the ScreenGuard module application is crashing in some devices.

Devices: Motorola edge 40 - Android 13, Nothing Phone(1) - Android 13, etc.

My implementation of ScreenGuard in react native:

  import { useColorScheme } from 'react-native';

  const isDarkMode = useColorScheme();

  useEffect(() => {
    const screenCaptureColor = isDarkMode === "dark" ? Colors.darker : Colors.lighter
    ScreenGuardModule.register(screenCaptureColor, (_) => {
      console.log("ScreenGuradModule registered")
    });

    //handling android backpress
    const onbackPress = async () => {
      navigation.pop();
    };

    const backHandler = BackHandler.addEventListener(
      'hardwareBackPress',
      onbackPress,
    );

    return async () => {
      backHandler.remove();
      ScreenGuardModule.unregister()
    };
  }, []);

As per the crashlytics reports are:

  ScreenGuardModule.lambda$deactivateShield$2
  java.lang.NullPointerException
  java.util.Objects.requireNonNull (Objects.java:220)
 com.screenguard.ScreenGuardModule.lambda$deactivateShield$2 (ScreenGuardModule.java:6)
gbumps commented 1 year ago

Can you give me more info on which react native version you are using and version dependency of react-native-screenguard ? If you have the frequency of the crash, please provide it for me for better understanding, thanks in advance!

surajQuitsure commented 1 year ago

Yes, here is more information:

"react-native": "0.70.6"
"react-native-screenguard": "^0.2.4"

Frequency of crash: 6-7 crashes / day Also I noticed in crashlytics, for all crashes application was in background, let's say user received notification and he pulled down the notification drawer and dismissed the notification, the reopened the application from background then application crashed

gbumps commented 1 year ago

Hmm, I understand now. Will have a fix later on.

surajQuitsure commented 1 year ago

Can you give me the quick fix so that I can apply that code in node modules, because the application I'm working on has large userbase, if the crashes persists then this application will have major hit on the ranking in playstore

gbumps commented 1 year ago

ok, here's work around on the native Android side:

Check ScreenGuardModule.java and fix the method deactivateShield like this:

@ReactMethod
    public void deactivateShield() {
        try {
            if (mHandlerBlockScreenShot != null) {
                   mHandlerBlockScreenShot.post(() -> Objects.requireNonNull(
                          getReactApplicationContext().getCurrentActivity()
                     ).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE));
                    mHandlerBlockScreenShot = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Remember to double check both background and foreground as well before resubmitting.

Thanks in advance!

surajQuitsure commented 1 year ago

I'll add this solution and watch the crashlytics for a while and then will let you know

gbumps commented 1 year ago

Mark as done, closing. Feel free to reopen if issue occurred again.

a fix for this will be on next release soon for both stable and beta release channels.

gbumps commented 1 year ago

This issue has been resolved at ver 0.3.2, please install and rebuild, thanks!

surajQuitsure commented 1 year ago

Thanks!