Flutter Engine
The Flutter Engine
Functions | Variables
android_illegal_imports Namespace Reference

Functions

def CheckBadFiles (bad_files, bad_class, good_class)
 
def main ()
 

Variables

string ANDROID_LOG_CLASS = 'android.util.Log'
 
string FLUTTER_LOG_CLASS = 'io.flutter.Log'
 
string ANDROIDX_TRACE_CLASS = 'androidx.tracing.Trace'
 
string ANDROID_TRACE_CLASS = 'android.tracing.Trace'
 
string FLUTTER_TRACE_CLASS = 'io.flutter.util.TraceSection'
 
string ANDROID_BUILD_VERSION_CODE_CLASS = 'VERSION_CODES'
 

Function Documentation

◆ CheckBadFiles()

def android_illegal_imports.CheckBadFiles (   bad_files,
  bad_class,
  good_class 
)

Definition at line 22 of file android_illegal_imports.py.

22def CheckBadFiles(bad_files, bad_class, good_class):
23 if bad_files:
24 print('')
25 print('Illegal import %s detected in the following files:' % bad_class)
26 for bad_file in bad_files:
27 print(' - ' + bad_file)
28 print('Use %s instead.' % good_class)
29 print('')
30 return True
31
32 return False
33
34
def CheckBadFiles(bad_files, bad_class, good_class)
def print(*args, **kwargs)
Definition: run_tests.py:49

◆ main()

def android_illegal_imports.main ( )

Definition at line 35 of file android_illegal_imports.py.

35def main():
36 parser = argparse.ArgumentParser(
37 description='Checks Flutter Android library for forbidden imports'
38 )
39 parser.add_argument('--stamp', type=str, required=True)
40 parser.add_argument('--files', type=str, required=True, nargs='+')
41 args = parser.parse_args()
42
43 open(args.stamp, 'a').close()
44
45 bad_log_files = []
46 bad_trace_files = []
47 bad_version_codes_files = []
48
49 for file in args.files:
50 if (file.endswith(os.path.join('io', 'flutter', 'Log.java')) or
51 file.endswith(os.path.join('io', 'flutter', 'util', 'TraceSection.java')) or
52 file.endswith(os.path.join('io', 'flutter', 'Build.java'))):
53 continue
54 with open(file) as f:
55 contents = f.read()
56 if ANDROID_LOG_CLASS in contents:
57 bad_log_files.append(file)
58 if ANDROIDX_TRACE_CLASS in contents or ANDROID_TRACE_CLASS in contents:
59 bad_trace_files.append(file)
60 if ANDROID_BUILD_VERSION_CODE_CLASS in contents:
61 bad_version_codes_files.append(file)
62
63 # Flutter's Log class allows additional configuration around verbosity.
64
65 # Flutter's tracing class makes sure we do not violate string lengths that
66 # cause crashes at runtime.
67
68 # Flutter's Build.API_LEVELS class is clearer to read about which API version
69 # is used.
70 has_bad_files = CheckBadFiles(bad_log_files, ANDROID_LOG_CLASS,
71 FLUTTER_LOG_CLASS) or CheckBadFiles(
72 bad_trace_files, 'android[x].tracing.Trace', FLUTTER_TRACE_CLASS
73 ) or CheckBadFiles(
74 bad_version_codes_files, 'android.os.Build.VERSION_CODES',
75 'io.flutter.Build.API_LEVELS'
76 )
77
78 if has_bad_files:
79 return 1
80
81 return 0
82
83

Variable Documentation

◆ ANDROID_BUILD_VERSION_CODE_CLASS

string android_illegal_imports.ANDROID_BUILD_VERSION_CODE_CLASS = 'VERSION_CODES'

Definition at line 19 of file android_illegal_imports.py.

◆ ANDROID_LOG_CLASS

string android_illegal_imports.ANDROID_LOG_CLASS = 'android.util.Log'

Definition at line 12 of file android_illegal_imports.py.

◆ ANDROID_TRACE_CLASS

string android_illegal_imports.ANDROID_TRACE_CLASS = 'android.tracing.Trace'

Definition at line 16 of file android_illegal_imports.py.

◆ ANDROIDX_TRACE_CLASS

string android_illegal_imports.ANDROIDX_TRACE_CLASS = 'androidx.tracing.Trace'

Definition at line 15 of file android_illegal_imports.py.

◆ FLUTTER_LOG_CLASS

string android_illegal_imports.FLUTTER_LOG_CLASS = 'io.flutter.Log'

Definition at line 13 of file android_illegal_imports.py.

◆ FLUTTER_TRACE_CLASS

string android_illegal_imports.FLUTTER_TRACE_CLASS = 'io.flutter.util.TraceSection'

Definition at line 17 of file android_illegal_imports.py.