[flutter_releases] Flutter Stable 2.0.4 Framework Cherrypicks (#79486)

* Skip linking on Flutter for CocoaPods transitive dependencies (#78592)
* Apply Engine cherrypicks for release 2.0.4

Co-authored-by: Jenn Magder <magder@google.com>
diff --git a/bin/internal/engine.version b/bin/internal/engine.version
index 7406cc8..f85c5b5 100644
--- a/bin/internal/engine.version
+++ b/bin/internal/engine.version
@@ -1 +1 @@
-3459eb24361807fb186953a864cf890fa8e9d26a
+2dce47073a378673f6ca095e91b8065544c3a881
diff --git a/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart b/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart
index 539f71f..efbf90e 100644
--- a/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart
+++ b/dev/devicelab/bin/tasks/build_ios_framework_module_test.dart
@@ -66,7 +66,7 @@
   String content = pubspec.readAsStringSync();
   content = content.replaceFirst(
     '\ndependencies:\n',
-    '\ndependencies:\n  device_info: 0.4.1\n  package_info: 0.4.0+9\n',
+    '\ndependencies:\n  device_info: 0.4.1\n  package_info: 0.4.0+9\n  connectivity: 3.0.3\n',
   );
   pubspec.writeAsStringSync(content, flush: true);
   await inDirectory(projectDir, () async {
@@ -284,6 +284,21 @@
       'device_info',
     );
     await _checkBitcode(pluginFrameworkPath, mode);
+    if (!await _linksOnFlutter(pluginFrameworkPath)) {
+      throw TaskResult.failure('$pluginFrameworkPath does not link on Flutter');
+    }
+
+    final String transitiveDependencyFrameworkPath = path.join(
+      outputPath,
+      mode,
+      'Reachability.xcframework',
+      localXcodeArmDirectoryName,
+      'Reachability.framework',
+      'Reachability',
+    );
+    if (await _linksOnFlutter(transitiveDependencyFrameworkPath)) {
+      throw TaskResult.failure('Transitive dependency $transitiveDependencyFrameworkPath unexpectedly links on Flutter');
+    }
 
     checkFileExists(path.join(
       outputPath,
@@ -407,6 +422,18 @@
       mode,
       'package_info.xcframework',
     ));
+
+    checkDirectoryExists(path.join(
+      cocoapodsOutputPath,
+      mode,
+      'connectivity.xcframework',
+    ));
+
+    checkDirectoryExists(path.join(
+      cocoapodsOutputPath,
+      mode,
+      'Reachability.xcframework',
+    ));
   }
 
   if (File(path.join(
@@ -443,3 +470,13 @@
     'arm64',
   ]);
 }
+
+Future<bool> _linksOnFlutter(String pathToBinary) async {
+  final String loadCommands = await eval('otool', <String>[
+    '-l',
+    '-arch',
+    'arm64',
+    pathToBinary,
+  ]);
+  return loadCommands.contains('Flutter.framework');
+}
diff --git a/packages/flutter_tools/bin/podhelper.rb b/packages/flutter_tools/bin/podhelper.rb
index b47e2c4..4a44d67 100644
--- a/packages/flutter_tools/bin/podhelper.rb
+++ b/packages/flutter_tools/bin/podhelper.rb
@@ -33,6 +33,9 @@
 def flutter_additional_ios_build_settings(target)
   return unless target.platform_name == :ios
 
+  # Return if it's not a Flutter plugin (transitive dependency).
+  return unless target.dependencies.any? { |dependency| dependency.name == 'Flutter' }
+
   # [target.deployment_target] is a [String] formatted as "8.0".
   inherit_deployment_target = target.deployment_target[/\d+/].to_i < 9
 
@@ -75,6 +78,9 @@
 def flutter_additional_macos_build_settings(target)
   return unless target.platform_name == :osx
 
+  # Return if it's not a Flutter plugin (transitive dependency).
+  return unless target.dependencies.any? { |dependency| dependency.name == 'FlutterMacOS' }
+
   # [target.deployment_target] is a [String] formatted as "10.8".
   deployment_target_major, deployment_target_minor = target.deployment_target.match(/(\d+).?(\d*)/).captures