• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 The Chromium 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"""Module containing utilities for apk packages."""
6
7import os.path
8import re
9
10from pylib import cmd_helper
11from pylib import constants
12
13
14def GetPackageName(apk_path):
15  """Returns the package name of the apk."""
16  aapt = os.path.join(constants.ANDROID_SDK_TOOLS, 'aapt')
17  aapt_output = cmd_helper.GetCmdOutput(
18      [aapt, 'dump', 'badging', apk_path]).split('\n')
19  package_name_re = re.compile(r'package: .*name=\'(\S*)\'')
20  for line in aapt_output:
21    m = package_name_re.match(line)
22    if m:
23      return m.group(1)
24  raise Exception('Failed to determine package name of %s' % apk_path)
25