Unverified Commit 902b0124 authored by Callum Moffat's avatar Callum Moffat Committed by GitHub

Add `UIApplicationSupportsIndirectInputEvents` migration (#106889)

parent 2987d9e1
...@@ -26,7 +26,7 @@ import 'application_package.dart'; ...@@ -26,7 +26,7 @@ import 'application_package.dart';
import 'code_signing.dart'; import 'code_signing.dart';
import 'iproxy.dart'; import 'iproxy.dart';
import 'migrations/deployment_target_migration.dart'; import 'migrations/deployment_target_migration.dart';
import 'migrations/minimum_frame_duration_migration.dart'; import 'migrations/host_app_info_plist_migration.dart';
import 'migrations/project_base_configuration_migration.dart'; import 'migrations/project_base_configuration_migration.dart';
import 'migrations/project_build_location_migration.dart'; import 'migrations/project_build_location_migration.dart';
import 'migrations/project_object_version_migration.dart'; import 'migrations/project_object_version_migration.dart';
...@@ -125,7 +125,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -125,7 +125,7 @@ Future<XcodeBuildResult> buildXcodeProject({
ProjectBuildLocationMigration(app.project, globals.logger), ProjectBuildLocationMigration(app.project, globals.logger),
DeploymentTargetMigration(app.project, globals.logger), DeploymentTargetMigration(app.project, globals.logger),
ProjectObjectVersionMigration(app.project, globals.logger), ProjectObjectVersionMigration(app.project, globals.logger),
MinimumFrameDurationMigration(app.project, globals.logger), HostAppInfoPlistMigration(app.project, globals.logger),
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
......
...@@ -7,10 +7,11 @@ import '../../base/project_migrator.dart'; ...@@ -7,10 +7,11 @@ import '../../base/project_migrator.dart';
import '../../xcode_project.dart'; import '../../xcode_project.dart';
const String _kDisableMinimumFrameDurationKey = 'CADisableMinimumFrameDurationOnPhone'; const String _kDisableMinimumFrameDurationKey = 'CADisableMinimumFrameDurationOnPhone';
const String _kIndirectInputEventsKey = 'UIApplicationSupportsIndirectInputEvents';
/// Add "CADisableMinimumFrameDurationOnPhone: true" to the Info.plist. /// Update Info.plist.
class MinimumFrameDurationMigration extends ProjectMigrator { class HostAppInfoPlistMigration extends ProjectMigrator {
MinimumFrameDurationMigration( HostAppInfoPlistMigration(
IosProject project, IosProject project,
super.logger, super.logger,
) : _infoPlist = project.defaultHostInfoPlist; ) : _infoPlist = project.defaultHostInfoPlist;
...@@ -20,7 +21,7 @@ class MinimumFrameDurationMigration extends ProjectMigrator { ...@@ -20,7 +21,7 @@ class MinimumFrameDurationMigration extends ProjectMigrator {
@override @override
bool migrate() { bool migrate() {
if (!_infoPlist.existsSync()) { if (!_infoPlist.existsSync()) {
logger.printTrace('Info.plist not found, skipping minimum frame duration migration.'); logger.printTrace('Info.plist not found, skipping host app Info.plist migration.');
return true; return true;
} }
...@@ -30,22 +31,37 @@ class MinimumFrameDurationMigration extends ProjectMigrator { ...@@ -30,22 +31,37 @@ class MinimumFrameDurationMigration extends ProjectMigrator {
@override @override
String migrateFileContents(String fileContents) { String migrateFileContents(String fileContents) {
if (fileContents.contains(_kDisableMinimumFrameDurationKey)) { String newContents = fileContents;
// No migration needed if the key already exits. if (!newContents.contains(_kDisableMinimumFrameDurationKey)) {
return fileContents; logger.printTrace('Adding $_kDisableMinimumFrameDurationKey to Info.plist');
} const String plistEnd = '''
logger.printTrace('Adding $_kDisableMinimumFrameDurationKey to Info.plist');
const String plistEnd = '''
</dict> </dict>
</plist> </plist>
'''; ''';
const String plistWithKey = ''' const String plistWithKey = '''
<key>$_kDisableMinimumFrameDurationKey</key> <key>$_kDisableMinimumFrameDurationKey</key>
<true/> <true/>
</dict> </dict>
</plist> </plist>
'''; ''';
newContents = newContents.replaceAll(plistEnd, plistWithKey);
}
if (!newContents.contains(_kIndirectInputEventsKey)) {
logger.printTrace('Adding $_kIndirectInputEventsKey to Info.plist');
const String plistEnd = '''
</dict>
</plist>
''';
const String plistWithKey = '''
<key>$_kIndirectInputEventsKey</key>
<true/>
</dict>
</plist>
''';
newContents = newContents.replaceAll(plistEnd, plistWithKey);
}
return fileContents.replaceAll(plistEnd, plistWithKey); return newContents;
} }
} }
...@@ -7,7 +7,7 @@ import 'package:file/memory.dart'; ...@@ -7,7 +7,7 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/project_migrator.dart'; import 'package:flutter_tools/src/base/project_migrator.dart';
import 'package:flutter_tools/src/ios/migrations/deployment_target_migration.dart'; import 'package:flutter_tools/src/ios/migrations/deployment_target_migration.dart';
import 'package:flutter_tools/src/ios/migrations/minimum_frame_duration_migration.dart'; import 'package:flutter_tools/src/ios/migrations/host_app_info_plist_migration.dart';
import 'package:flutter_tools/src/ios/migrations/project_base_configuration_migration.dart'; import 'package:flutter_tools/src/ios/migrations/project_base_configuration_migration.dart';
import 'package:flutter_tools/src/ios/migrations/project_build_location_migration.dart'; import 'package:flutter_tools/src/ios/migrations/project_build_location_migration.dart';
import 'package:flutter_tools/src/ios/migrations/project_object_version_migration.dart'; import 'package:flutter_tools/src/ios/migrations/project_object_version_migration.dart';
...@@ -738,7 +738,7 @@ platform :ios, '11.0' ...@@ -738,7 +738,7 @@ platform :ios, '11.0'
}); });
}); });
group('add CADisableMinimumFrameDurationOnPhone key to info.plist migration', () { group('update info.plist migration', () {
late MemoryFileSystem memoryFileSystem; late MemoryFileSystem memoryFileSystem;
late BufferLogger testLogger; late BufferLogger testLogger;
late FakeIosProject project; late FakeIosProject project;
...@@ -753,14 +753,14 @@ platform :ios, '11.0' ...@@ -753,14 +753,14 @@ platform :ios, '11.0'
}); });
testWithoutContext('skipped if files are missing', () { testWithoutContext('skipped if files are missing', () {
final MinimumFrameDurationMigration iosProjectMigration = MinimumFrameDurationMigration( final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
project, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
expect(infoPlistFile.existsSync(), isFalse); expect(infoPlistFile.existsSync(), isFalse);
expect(testLogger.traceText, contains('Info.plist not found, skipping minimum frame duration migration.')); expect(testLogger.traceText, contains('Info.plist not found, skipping host app Info.plist migration.'));
expect(testLogger.statusText, isEmpty); expect(testLogger.statusText, isEmpty);
}); });
...@@ -772,12 +772,14 @@ platform :ios, '11.0' ...@@ -772,12 +772,14 @@ platform :ios, '11.0'
<dict> <dict>
<key>CADisableMinimumFrameDurationOnPhone</key> <key>CADisableMinimumFrameDurationOnPhone</key>
<true/> <true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict> </dict>
</plist> </plist>
'''; ''';
infoPlistFile.writeAsStringSync(infoPlistFileContent); infoPlistFile.writeAsStringSync(infoPlistFileContent);
final MinimumFrameDurationMigration iosProjectMigration = MinimumFrameDurationMigration( final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
project, project,
testLogger, testLogger,
); );
...@@ -788,7 +790,7 @@ platform :ios, '11.0' ...@@ -788,7 +790,7 @@ platform :ios, '11.0'
expect(testLogger.statusText, isEmpty); expect(testLogger.statusText, isEmpty);
}); });
testWithoutContext('info.plist is migrated to use CADisableMinimumFrameDurationOnPhone', () { testWithoutContext('info.plist is migrated', () {
const String infoPlistFileContent = ''' const String infoPlistFileContent = '''
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
...@@ -799,7 +801,7 @@ platform :ios, '11.0' ...@@ -799,7 +801,7 @@ platform :ios, '11.0'
'''; ''';
infoPlistFile.writeAsStringSync(infoPlistFileContent); infoPlistFile.writeAsStringSync(infoPlistFileContent);
final MinimumFrameDurationMigration iosProjectMigration = MinimumFrameDurationMigration( final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
project, project,
testLogger, testLogger,
); );
...@@ -811,12 +813,15 @@ platform :ios, '11.0' ...@@ -811,12 +813,15 @@ platform :ios, '11.0'
<dict> <dict>
<key>CADisableMinimumFrameDurationOnPhone</key> <key>CADisableMinimumFrameDurationOnPhone</key>
<true/> <true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict> </dict>
</plist> </plist>
''')); '''));
}); });
}); });
}); });
} }
class FakeIosProject extends Fake implements IosProject { class FakeIosProject extends Fake implements IosProject {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment