Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help in implementation as I am unable to stop screen capture #3

Closed
RuhaanSharma opened this issue Jun 18, 2020 · 5 comments
Closed

Comments

@RuhaanSharma
Copy link

RuhaanSharma commented Jun 18, 2020

I have tried to implement your library as per documentation instructions.
But When I use your demo app , I am unable to capture screen and also any screen recorder app don't capture app screen , just black screen AS it should be.
But In my app it never works.
Please guide me what step I am missing.

My code :

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: [
          ChangeNotifierProvider.value(
            value: ProviderCall(),
          ),
        ],
        child: Consumer<ProviderCall>(
            builder: (ctx, auth, _) => MaterialApp(
                  title: AllStrings.appName,
                  theme: new ThemeData(
                    primaryColor: Colors.deepPurple,
                    primarySwatch: Colors.deepPurple,
                    primaryColorDark: Colors.deepPurple,
                    hintColor: Colors.blue,
                  ),
                  debugShowCheckedModeBanner: false,
                  home: SecureApplication(
                      nativeRemoveDelay: 800,
                      onNeedUnlock: (secureApplicationController) async {},
                      child: MyHomePage(title: 'My  App')),
                )));
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var valueNotifier ;
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    valueNotifier = SecureApplicationProvider.of(context);
    return PickupLayout(
        scaffold: Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SecureGate(
          blurr: 0,
          opacity: 0,
          child: new Center(
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    new RaisedButton(
                      padding: const EdgeInsets.all(8.0),
                      textColor: Colors.white,
                      color: Colors.blue,
                      onPressed: () => secure(context),
                      child: new Text("Secure"),
                    ),
                    new RaisedButton(
                      onPressed: () => open(context),
                      textColor: Colors.white,
                      color: Colors.red,
                      padding: const EdgeInsets.all(8.0),
                      child: new Text(
                        "Open",
                      ),
                    ),
                  ],
                ),
              ],
            ),
          )),
    ));
  }

  void secure(BuildContext context) {
      valueNotifier.secure();
  }

  void open(BuildContext context) {
    valueNotifier.open();
  }
}

As per my understanding of your library , I want to secure the screen and don't want to lock the screen.
I guess I am missing some step.
Plese guide me to solution.

@neckaros
Copy link
Owner

What is the behavior you are expecting when back in app?

@RuhaanSharma
Copy link
Author

I am just expecting when user is in MyHomePage, user should not be able to capture screen shot or any screen recorder app should not be able to create video of that screen.
As per documentation, I have used SecureApplication and SecureGate in my app but I am able to capture screen shot as well as video of MyHomePage screen.
I think I am missing some step.
Please guide me to solution.

@RuhaanSharma
Copy link
Author

RuhaanSharma commented Jun 19, 2020

Reason FLAG_SECURE was not working in my application was missing following in AndroidManifest application tag:

 <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

With your library it started "could not capture screen shot"
but still any screen recorder app is recording the app video and
was getting error like "getter secureData called on null" in some dynamic scenario.
I have reverted back to native implementation for now for android.

To stop any screen recorder from capturing video of my app , I had use code to secure surface view.


import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSecureSurfaceView();
    }

    private Boolean setSecureSurfaceView() {
        try {
            ViewGroup content = (findViewById(android.R.id.content));
            if (!isNonEmptyContainer(content)) {
                return false;
            }
            View splashView = content.getChildAt(0);
            if (!isNonEmptyContainer(splashView)) {
                return false;
            }
            View flutterView = ((ViewGroup) splashView).getChildAt(0);
            if (!isNonEmptyContainer(flutterView)) {
                return false;
            }
            View surfaceView = ((ViewGroup) flutterView).getChildAt(0);
            if (surfaceView instanceof SurfaceView) {
                ((SurfaceView)surfaceView).setSecure(true);
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
            } else {
                return false;
            }
        } catch (Exception e) {
            String msg = e.toString();
        }
        return true;
    }

    private Boolean isNonEmptyContainer(View view) {
        if (view instanceof ViewGroup
                && ((ViewGroup)view).getChildCount() > 0) {
            return true;
        }
        return false;
    }
}

@neckaros
Copy link
Owner

Sorry I missed the part where you said that it was in the demo app that it was working.

Tbh I never tried without v2 embedder but it shroud work as I also have the v1 register method:

companion object {
    @JvmStatic
    fun registerWith(registrar: Registrar) {
      val channel = MethodChannel(registrar.messenger(), "secure_application")
      channel.setMethodCallHandler(SecureApplicationPlugin())
    }
  }

I will try to test with old embedding to try to reproduce your issue.

FYI on Android I also use native for app switcher / screenshot protection:

@RuhaanSharma
Copy link
Author

RuhaanSharma commented Jun 20, 2020

I understand that you have also use native method.
But somehow , I could not shed light on this , something I am doing in creating scaffold or widgets , as this is my first flutter project but I had to set following line to make it work in my app where any screen recorder could not record my screen.

((SurfaceView)surfaceView).setSecure(true);

I really liked your library and simplicity of it to use.
I am sure it will save hours of work for many developers especially starters like me.
Thanks for your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants