"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/dev/devicelab/bin/tasks/android_obfuscate_test.dart" (13 Nov 2020, 4026 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'dart:async';
    6 
    7 import 'package:flutter_devicelab/framework/apk_utils.dart';
    8 import 'package:flutter_devicelab/framework/framework.dart';
    9 import 'package:flutter_devicelab/framework/utils.dart';
   10 import 'package:path/path.dart' as path;
   11 
   12 Future<void> main() async {
   13   await task(() async {
   14     try {
   15       bool foundApkProjectName = false;
   16       await runProjectTest((FlutterProject flutterProject) async {
   17         section('APK content for task assembleRelease with --obfuscate');
   18         await inDirectory(flutterProject.rootPath, () async {
   19           await flutter('build', options: <String>[
   20             'apk',
   21             '--target-platform=android-arm',
   22             '--obfuscate',
   23             '--split-debug-info=foo/',
   24             '--verbose',
   25           ]);
   26         });
   27         final String outputApkDirectory = path.join(
   28           flutterProject.rootPath,
   29           'build/app/outputs/apk/release/app-release.apk',
   30         );
   31         final Iterable<String> apkFiles = await getFilesInApk(outputApkDirectory);
   32 
   33         checkCollectionContains<String>(<String>[
   34           ...flutterAssets,
   35           ...baseApkFiles,
   36           'lib/armeabi-v7a/libapp.so',
   37         ], apkFiles);
   38 
   39         // Verify that an identifier from the Dart project code is not present
   40         // in the compiled binary.
   41         await inDirectory(flutterProject.rootPath, () async {
   42           await exec('unzip', <String>[outputApkDirectory]);
   43           checkFileExists(path.join(flutterProject.rootPath, 'lib/armeabi-v7a/libapp.so'));
   44           final String response = await eval(
   45             'grep',
   46             <String>[flutterProject.name, 'lib/armeabi-v7a/libapp.so'],
   47             canFail: true,
   48           );
   49           if (response.trim().contains('matches')) {
   50             foundApkProjectName = true;
   51           }
   52         });
   53       });
   54 
   55       bool foundAarProjectName = false;
   56       await runModuleProjectTest((FlutterModuleProject flutterProject) async {
   57         section('AAR content with --obfuscate');
   58 
   59         await inDirectory(flutterProject.rootPath, () async {
   60           await flutter('build', options: <String>[
   61             'aar',
   62             '--target-platform=android-arm',
   63             '--obfuscate',
   64             '--split-debug-info=foo/',
   65             '--no-debug',
   66             '--no-profile',
   67             '--verbose',
   68           ]);
   69         });
   70 
   71         final String outputAarDirectory = path.join(
   72           flutterProject.rootPath,
   73           'build/host/outputs/repo/com/example/${flutterProject.name}/flutter_release/1.0/flutter_release-1.0.aar',
   74         );
   75         final Iterable<String> aarFiles = await getFilesInAar(outputAarDirectory);
   76 
   77         checkCollectionContains<String>(<String>[
   78           ...flutterAssets,
   79           'jni/armeabi-v7a/libapp.so',
   80         ], aarFiles);
   81 
   82         // Verify that an identifier from the Dart project code is not present
   83         // in the compiled binary.
   84         await inDirectory(flutterProject.rootPath, () async {
   85           await exec('unzip', <String>[outputAarDirectory]);
   86           checkFileExists(path.join(flutterProject.rootPath, 'jni/armeabi-v7a/libapp.so'));
   87           final String response = await eval(
   88             'grep',
   89             <String>[flutterProject.name, 'jni/armeabi-v7a/libapp.so'],
   90             canFail: true,
   91           );
   92           if (response.trim().contains('matches')) {
   93             foundAarProjectName = true;
   94           }
   95         });
   96       });
   97 
   98       if (foundApkProjectName) {
   99         return TaskResult.failure('Found project name in obfuscated APK dart library');
  100       }
  101       if (foundAarProjectName) {
  102         return TaskResult.failure('Found project name in obfuscated AAR dart library');
  103       }
  104 
  105       return TaskResult.success(null);
  106     } on TaskResult catch (taskResult) {
  107       return taskResult;
  108     } catch (e) {
  109       return TaskResult.failure(e.toString());
  110     }
  111   });
  112 }