Open CaptainIanOnDuty opened 1 month ago
Thanks for the report. I can reproduce this issue using a complete sample code here: repro_147960.
When applying flutterSurfaceView.setSecure(true)
to FlutterFragment, it will display a back screen only. Without enabling secure, flutter fragment displays normally.
Maybe related: https://github.com/flutter/flutter/issues/32082
You can try adding a transparent view to the upper layer.
public void setSecure(boolean isSecure) {
if (activity == null) {
Log.d("FlutterForbidshotPlugin", "activity ==null");
return;
}
if (isSecure) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();
View flag_secure = viewGroup.findViewWithTag("FLAG_SECURE");
try {
if (isSecure) {
if (flag_secure == null) {
flag_secure = new View(activity);
flag_secure.setTag("FLAG_SECURE");
viewGroup.addView(flag_secure, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
}
} else {
viewGroup.removeView(flag_secure);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Steps to reproduce
Expected results
Flutter screen not shared and displayed black screen
Actual results
Can see the Flutter screen which is not guarded by FLAG_SECURE or setSecure(). Native Android screen is guarded as expected. If I use TextureView instead of SurfaceView, this issue will not appear. The guess is that setSecure should be set before attach, but at the point onFlutterSurfaceViewCreated is executed, the view is already attached.
Code sample
Code sample
Create following class ```dart public class OurFlutterFragment extends FlutterFragment { @Override public void onFlutterSurfaceViewCreated(@NonNull FlutterSurfaceView flutterSurfaceView) { flutterSurfaceView.setSecure(true); } } ``` Following this to add Flutter screen into Android app https://docs.flutter.dev/add-to-app/android/add-flutter-fragment?tab=add-fragment-java#add-a-flutterfragment-to-an-activity-with-a-new-flutterengine But replace ```dart flutterFragment = FlutterFragment.createDefault(); ``` with ```dart flutterFragment = OurFlutterFragment.createDefault(); ```Screenshots or Video
Screenshots / Video demonstration
[Upload media here]Logs
Logs
```console [Paste your logs here] ```Flutter Doctor output
Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [!] Xcode - develop for iOS and macOS (Xcode 15.3) ! CocoaPods 1.11.3 out of date (1.13.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods for instructions. [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] IntelliJ IDEA Ultimate Edition (version 2022.3) [✓] VS Code (version 1.72.2) [✓] Connected device (2 available) [✓] Network resources
! Doctor found issues in 1 category.