Repository: flutter
Issue: Add to App fragment with SurfaceView does not apply in Android even after setSecure to true
Labels: c: new feature,platform-android,engine,a: existing-apps,has reproducible steps,P3,team-android,triaged-android,found in release: 3.19,found in release: 3.22

### Steps to reproduce

1. Create a sample Android app and add the FLAG_SECURE in onCreate() method under MainActivity
2. Extends the FlutterFragment and override onFlutterSurfaceViewCreated which setSecure to true
4. Following https://docs.flutter.dev/add-to-app/android/add-flutter-fragment?tab=add-fragment-java to add Flutter screen using the FlutterFragment created in step 2
5. Start the screen sharing
6. Launch the app
7. Launch the Flutter screen

### 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

<details open><summary>Code sample</summary>

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();
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### 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.