def _GetTestsFromDexdump(test_apk): dex_dumps = dexdump.Dump(test_apk) tests = [] def get_test_methods(methods): return [ { 'method': m, # No annotation info is available from dexdump. # Set MediumTest annotation for default. 'annotations': { 'MediumTest': None }, } for m in methods if m.startswith('test') ] for dump in dex_dumps: for package_name, package_info in six.iteritems(dump): for class_name, class_info in six.iteritems( package_info['classes']): if class_name.endswith('Test'): tests.append({ 'class': '%s.%s' % (package_name, class_name), 'annotations': {}, 'methods': get_test_methods(class_info['methods']), 'superclass': class_info['superclass'], }) return tests
def _MaybeCheckServicesPresentInBase(bundle_path, module_zips): """Checks bundles with isolated splits define all services in the base module. Due to b/169196314, service classes are not found if they are not present in the base module. """ base_manifest = _GetManifestForModule(bundle_path, 'base') isolated_splits = base_manifest.get('{%s}isolatedSplits' % manifest_utils.ANDROID_NAMESPACE) if isolated_splits != 'true': return # Collect service names from all split manifests. base_zip = None service_names = _GetServiceNames(base_manifest) for module_zip in module_zips: name = os.path.basename(module_zip)[:-len('.zip')] if name == 'base': base_zip = module_zip else: service_names.extend( _GetServiceNames(_GetManifestForModule(bundle_path, name))) # Extract classes from the base module's dex. classes = set() base_package_name = manifest_utils.GetPackage(base_manifest) for package in dexdump.Dump(base_zip): for name, package_dict in package.items(): if not name: name = base_package_name classes.update('%s.%s' % (name, c) for c in package_dict['classes'].keys()) # Ensure all services are present in base module. for service_name in service_names: if service_name not in classes: raise Exception( "Service %s should be present in the base module's dex." " See b/169196314 for more details." % service_name)
def _MaybeCheckServicesAndProvidersPresentInBase(bundle_path, module_zips): """Checks bundles with isolated splits define all services in the base module. Due to b/169196314, service classes are not found if they are not present in the base module. Providers are also checked because they are loaded early in startup, and keeping them in the base module gives more time for the chrome split to load. """ base_manifest = _GetManifestForModule(bundle_path, 'base') isolated_splits = base_manifest.get('{%s}isolatedSplits' % manifest_utils.ANDROID_NAMESPACE) if isolated_splits != 'true': return # Collect service names from all split manifests. base_zip = None service_names = _GetComponentNames(base_manifest, 'service') provider_names = _GetComponentNames(base_manifest, 'provider') for module_zip in module_zips: name = os.path.basename(module_zip)[:-len('.zip')] if name == 'base': base_zip = module_zip else: service_names.extend( _GetComponentNames(_GetManifestForModule(bundle_path, name), 'service')) module_providers = _GetComponentNames( _GetManifestForModule(bundle_path, name), 'provider') if module_providers: raise Exception( "Providers should all be declared in the base manifest." " '%s' module declared: %s" % (name, module_providers)) # Extract classes from the base module's dex. classes = set() base_package_name = manifest_utils.GetPackage(base_manifest) for package in dexdump.Dump(base_zip): for name, package_dict in package.items(): if not name: name = base_package_name classes.update('%s.%s' % (name, c) for c in package_dict['classes'].keys()) ignored_service_names = { # Defined in the chime DFM manifest, but unused. # org.chromium.chrome.browser.chime.ScheduledTaskService is used instead. ("com.google.android.libraries.notifications.entrypoints.scheduled." "ScheduledTaskService"), # Defined in the chime DFM manifest, only used pre-O (where isolated # splits are not supported). ("com.google.android.libraries.notifications.executor.impl.basic." "ChimeExecutorApiService"), } # Ensure all services are present in base module. for service_name in service_names: if service_name not in classes: if service_name in ignored_service_names: continue raise Exception( "Service %s should be present in the base module's dex." " See b/169196314 for more details." % service_name) # Ensure all providers are present in base module. for provider_name in provider_names: if provider_name not in classes: raise Exception( "Provider %s should be present in the base module's dex." % provider_name)