neckaros / secure_application

Secure your application from prying eyes
MIT License
103 stars 61 forks source link

Why application not locked after opening? #30

Closed minhdanh closed 2 years ago

minhdanh commented 2 years ago

Hi, is there a reason this package doesn’t lock an app after launch? I’ve tried it and it just works when I switch to another app and come back. Can we make it work even when after we launch an app?

minhdanh commented 2 years ago

I understand that the package uses the resume lifecycle event to execute the code. This event is fired when we switch to another app and switch back, or open the task switcher. But what is the point of locking an app, when you can bypass that by closing and opening the app again? 🤔

neckaros commented 2 years ago

I understand that the package uses the resume lifecycle event to execute the code. This event is fired when we switch to another app and switch back, or open the task switcher. But what is the point of locking an app, when you can bypass that by closing and opening the app again? 🤔

You are free to have a state locked by default on your app. You can for example call lock on the SecureApplicationController

minhdanh commented 2 years ago

Thank you for the hint. I can make app locked on first launch now:

        final secureApplicationController = SecureApplicationController(
          SecureApplicationState(
            locked: true,
            secured: true,
          ),
        );
        return MaterialApp(
          home: SecureApplication(
            secureApplicationController: secureApplicationController,
            nativeRemoveDelay: 500,
 ...
minhdanh commented 2 years ago

One small question though, with the default state is locked, what else I should do for the callback onNeedUnlock to be called on app launch/opening (so that the app can ask for fingerprint automatically)?

minhdanh commented 2 years ago

what else I should do for the callback onNeedUnlock to be called on app launch/opening (so that the app can ask for fingerprint automatically)?

I could do that by using WidgetsBinding.instance?.addPostFrameCallback:

class _UnlockScreenState extends State<UnlockScreen> {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance?.addPostFrameCallback((_) => localAuthenticate());
  }
...
neckaros commented 2 years ago

Nice find. I will see if I can not make a easier solution without adding too much complexity to the plug-in