Closed RuhaanSharma closed 4 years ago
What is the behavior you are expecting when back in app?
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.
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;
}
}
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: https://github.com/neckaros/secure_application/blob/a2ecc9bd10c6f9587b5afe07b7a1007447fa0b20/android/src/main/kotlin/org/jezequel/secure_application/SecureApplicationPlugin.kt#L83
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.
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 :
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.