diff --git a/dev/devicelab/bin/tasks/module_test.dart b/dev/devicelab/bin/tasks/module_test.dart index 87a7cd2681..1a637b7595 100644 --- a/dev/devicelab/bin/tasks/module_test.dart +++ b/dev/devicelab/bin/tasks/module_test.dart @@ -12,6 +12,7 @@ import 'package:path/path.dart' as path; final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew'; final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradlew'; +final String fileReadWriteMode = Platform.isWindows ? 'rw-rw-rw-' : 'rw-r--r--'; final bool useAndroidEmbeddingV2 = Platform.environment['ENABLE_ANDROID_EMBEDDING_V2'] == 'true'; @@ -39,10 +40,36 @@ Future main() async { ); }); - section('Add plugins'); + section('Add read-only asset'); + + final File readonlyTxtAssetFile = await File(path.join( + projectDir.path, + 'assets/read-only.txt' + )) + .create(recursive: true); + + if (!exists(readonlyTxtAssetFile)) { + return TaskResult.failure('Failed to create read-only asset'); + } + + if (!Platform.isWindows) { + await exec('chmod', [ + '444', + readonlyTxtAssetFile.path + ]); + } final File pubspec = File(path.join(projectDir.path, 'pubspec.yaml')); String content = await pubspec.readAsString(); + content = content.replaceFirst( + '\n # assets:\n', + '\n assets:\n - assets/read-only.txt\n', + ); + await pubspec.writeAsString(content, flush: true); + + section('Add plugins'); + + content = await pubspec.readAsString(); content = content.replaceFirst( '\ndependencies:\n', '\ndependencies:\n device_info: 0.4.1\n package_info: 0.4.0+9\n', @@ -226,6 +253,29 @@ Future main() async { ); } + section('Check file access modes for read-only asset from Flutter module'); + + final String readonlyDebugAssetFilePath = path.join( + hostApp.path, + 'app', + 'build', + 'intermediates', + 'merged_assets', + 'debug', + 'out', + 'flutter_assets/assets/read-only.txt', + ); + final File readonlyDebugAssetFile = File(readonlyDebugAssetFilePath); + if (!exists(readonlyDebugAssetFile)) { + return TaskResult.failure('Failed to copy read-only asset file'); + } + + String modes = readonlyDebugAssetFile.statSync().modeString(); + print('\nread-only.txt file access modes = $modes'); + if (modes != null && modes.compareTo(fileReadWriteMode) != 0) { + return TaskResult.failure('Failed to make assets user-readable and writable'); + } + section('Build release host APK'); await inDirectory(hostApp, () async { @@ -272,6 +322,30 @@ Future main() async { ) { return TaskResult.failure("Release host APK doesn't contain metadata: flutterProjectType = module "); } + + section('Check file access modes for read-only asset from Flutter module'); + + final String readonlyReleaseAssetFilePath = path.join( + hostApp.path, + 'app', + 'build', + 'intermediates', + 'merged_assets', + 'release', + 'out', + 'flutter_assets/assets/read-only.txt', + ); + final File readonlyReleaseAssetFile = File(readonlyReleaseAssetFilePath); + if (!exists(readonlyReleaseAssetFile)) { + return TaskResult.failure('Failed to copy read-only asset file'); + } + + modes = readonlyReleaseAssetFile.statSync().modeString(); + print('\nread-only.txt file access modes = $modes'); + if (modes != null && modes.compareTo(fileReadWriteMode) != 0) { + return TaskResult.failure('Failed to make assets user-readable and writable'); + } + return TaskResult.success(null); } on TaskResult catch (taskResult) { return taskResult; diff --git a/packages/flutter_tools/gradle/flutter.gradle b/packages/flutter_tools/gradle/flutter.gradle index ee764b913a..adff0440b7 100644 --- a/packages/flutter_tools/gradle/flutter.gradle +++ b/packages/flutter_tools/gradle/flutter.gradle @@ -647,6 +647,15 @@ class FlutterPlugin implements Plugin { extraGenSnapshotOptions extraGenSnapshotOptionsValue splitDebugInfo splitDebugInfoValue treeShakeIcons treeShakeIconsOptionsValue + doLast { + project.exec { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine('cmd', '/c', 'attrib -r ${assetsDirectory}/* /s') + } else { + commandLine('chmod', '-R', 'u+w', assetsDirectory) + } + } + } } File libJar = project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}/libs.jar") Task packFlutterAppAotTask = project.tasks.create(name: "packLibs${FLUTTER_BUILD_PREFIX}${variant.name.capitalize()}", type: Jar) { @@ -859,6 +868,10 @@ class FlutterTask extends BaseFlutterTask { return intermediateDir } + String getAssetsDirectory() { + return "${outputDirectory}/flutter_assets" + } + CopySpec getAssets() { return project.copySpec { from "${intermediateDir}"