def _GetApkPackageName(apk_path): """Return the package name of a given apk.""" package_name = _package_name_cache.get(apk_path, None) if package_name: return package_name aapt_path = host_paths.GetAaptPath() aapt_output = subprocess.check_output( [aapt_path, 'dump', 'badging', apk_path]).split('\n') for line in aapt_output: match = _PACKAGE_NAME_RE.match(line) if match: package_name = match.group(1) _package_name_cache[apk_path] = package_name logging.debug('Package name %s for %s', package_name, apk_path) return package_name return None
def test_GetAaptPath(self): _EXPECTED_AAPT_PATH = os.path.join(constants.ANDROID_SDK_TOOLS, 'aapt') self.assertEqual(host_paths.GetAaptPath(), _EXPECTED_AAPT_PATH) self.assertEqual(host_paths.GetAaptPath(), _EXPECTED_AAPT_PATH)