parameters: (options, temp_dir, extra_manifest=None)
return_statement: return debug_manifest_path, orig_package, fixed_package
docstring: Fix the APK's AndroidManifest.xml.
  
    This adds any missing namespaces for 'android' and 'tools', and
    sets certains elements like 'platformBuildVersionCode' or
    'android:debuggable' depending on the content of |options|.
  
    Args:
      options: The command-line arguments tuple.
      temp_dir: A temporary directory where the fixed manifest will be written to.
      extra_manifest: Path to an AndroidManifest.xml file which will get merged
          into the application node of the base manifest.
    Returns:
      Tuple of:
       * Manifest path within |temp_dir|.
       * Original package_name.
       * Manifest package name.
docstring_summary: Fix the APK's AndroidManifest.xml.
docstring_tokens: Fix the APK s AndroidManifest . xml .
function: def _FixManifest(options, temp_dir, extra_manifest=None):
    """Fix the APK's AndroidManifest.xml.
  
    This adds any missing namespaces for 'android' and 'tools', and
    sets certains elements like 'platformBuildVersionCode' or
    'android:debuggable' depending on the content of |options|.
  
    Args:
      options: The command-line arguments tuple.
      temp_dir: A temporary directory where the fixed manifest will be written to.
      extra_manifest: Path to an AndroidManifest.xml file which will get merged
          into the application node of the base manifest.
    Returns:
      Tuple of:
       * Manifest path within |temp_dir|.
       * Original package_name.
       * Manifest package name.
    """
    def maybe_extract_version(j):
      try:
        return resource_utils.ExtractBinaryManifestValues(options.aapt2_path, j)
      except build_utils.CalledProcessError:
        return None
  
    android_sdk_jars = [j for j in options.include_resources
                        if os.path.basename(j) in ('android.jar',
                                                   'android_system.jar')]
    extract_all = [maybe_extract_version(j) for j in android_sdk_jars]
    successful_extractions = [x for x in extract_all if x]
    if len(successful_extractions) == 0:
      raise Exception(
          'Unable to find android SDK jar among candidates: %s'
              % ', '.join(android_sdk_jars))
    if len(successful_extractions) > 1:
      raise Exception(
          'Found multiple android SDK jars among candidates: %s'
              % ', '.join(android_sdk_jars))
    version_code, version_name = successful_extractions.pop()[:2]
  
    debug_manifest_path = os.path.join(temp_dir, 'AndroidManifest.xml')
    doc, manifest_node, app_node = manifest_utils.ParseManifest(
        options.android_manifest)
  
    if extra_manifest:
      _, extra_manifest_node, extra_app_node = manifest_utils.ParseManifest(
          extra_manifest)
      for node in extra_app_node:
        app_node.append(node)
      for node in extra_manifest_node:
        # DFM manifests have a bunch of tags we don't care about inside
        # <manifest>, so only take <queries>.
        if node.tag == 'queries':
          manifest_node.append(node)
  
    manifest_utils.AssertUsesSdk(manifest_node, options.min_sdk_version,
                                 options.target_sdk_version)
    # We explicitly check that maxSdkVersion is set in the manifest since we don't
    # add it later like minSdkVersion and targetSdkVersion.
    manifest_utils.AssertUsesSdk(
        manifest_node,
        max_sdk_version=options.max_sdk_version,
        fail_if_not_exist=True)
    manifest_utils.AssertPackage(manifest_node, options.manifest_package)
  
    manifest_node.set('platformBuildVersionCode', version_code)
    manifest_node.set('platformBuildVersionName', version_name)
  
    orig_package = manifest_node.get('package')
    fixed_package = orig_package
    if options.arsc_package_name:
      manifest_node.set('package', options.arsc_package_name)
      fixed_package = options.arsc_package_name
  
    if options.debuggable:
      app_node.set('{%s}%s' % (manifest_utils.ANDROID_NAMESPACE, 'debuggable'),
                   'true')
  
    if options.uses_split:
      uses_split = ElementTree.SubElement(manifest_node, 'uses-split')
      uses_split.set('{%s}name' % manifest_utils.ANDROID_NAMESPACE,
                     options.uses_split)
  
    # Make sure the min-sdk condition is not less than the min-sdk of the bundle.
    for min_sdk_node in manifest_node.iter('{%s}min-sdk' %
                                           manifest_utils.DIST_NAMESPACE):
      dist_value = '{%s}value' % manifest_utils.DIST_NAMESPACE
      if int(min_sdk_node.get(dist_value)) < int(options.min_sdk_version):
        min_sdk_node.set(dist_value, options.min_sdk_version)
  
    manifest_utils.SaveManifest(doc, debug_manifest_path)
    return debug_manifest_path, orig_package, fixed_package
function_tokens: def _FixManifest ( options , temp_dir , extra_manifest = None ) : def maybe_extract_version ( j ) : try : return resource_utils . ExtractBinaryManifestValues ( options . aapt2_path , j ) except build_utils . CalledProcessError : return None android_sdk_jars = [ j for j in options . include_resources if os . path . basename ( j ) in ( 'android.jar' , 'android_system.jar' ) ] extract_all = [ maybe_extract_version ( j ) for j in android_sdk_jars ] successful_extractions = [ x for x in extract_all if x ] if len ( successful_extractions ) == 0 : raise Exception ( 'Unable to find android SDK jar among candidates: %s' % ', ' . join ( android_sdk_jars ) ) if len ( successful_extractions ) > 1 : raise Exception ( 'Found multiple android SDK jars among candidates: %s' % ', ' . join ( android_sdk_jars ) ) version_code , version_name = successful_extractions . pop ( ) [ : 2 ] debug_manifest_path = os . path . join ( temp_dir , 'AndroidManifest.xml' ) doc , manifest_node , app_node = manifest_utils . ParseManifest ( options . android_manifest ) if extra_manifest : _ , extra_manifest_node , extra_app_node = manifest_utils . ParseManifest ( extra_manifest ) for node in extra_app_node : app_node . append ( node ) for node in extra_manifest_node : # DFM manifests have a bunch of tags we don't care about inside # <manifest>, so only take <queries>. if node . tag == 'queries' : manifest_node . append ( node ) manifest_utils . AssertUsesSdk ( manifest_node , options . min_sdk_version , options . target_sdk_version ) # We explicitly check that maxSdkVersion is set in the manifest since we don't # add it later like minSdkVersion and targetSdkVersion. manifest_utils . AssertUsesSdk ( manifest_node , max_sdk_version = options . max_sdk_version , fail_if_not_exist = True ) manifest_utils . AssertPackage ( manifest_node , options . manifest_package ) manifest_node . set ( 'platformBuildVersionCode' , version_code ) manifest_node . set ( 'platformBuildVersionName' , version_name ) orig_package = manifest_node . get ( 'package' ) fixed_package = orig_package if options . arsc_package_name : manifest_node . set ( 'package' , options . arsc_package_name ) fixed_package = options . arsc_package_name if options . debuggable : app_node . set ( '{%s}%s' % ( manifest_utils . ANDROID_NAMESPACE , 'debuggable' ) , 'true' ) if options . uses_split : uses_split = ElementTree . SubElement ( manifest_node , 'uses-split' ) uses_split . set ( '{%s}name' % manifest_utils . ANDROID_NAMESPACE , options . uses_split ) # Make sure the min-sdk condition is not less than the min-sdk of the bundle. for min_sdk_node in manifest_node . iter ( '{%s}min-sdk' % manifest_utils . DIST_NAMESPACE ) : dist_value = '{%s}value' % manifest_utils . DIST_NAMESPACE if int ( min_sdk_node . get ( dist_value ) ) < int ( options . min_sdk_version ) : min_sdk_node . set ( dist_value , options . min_sdk_version ) manifest_utils . SaveManifest ( doc , debug_manifest_path ) return debug_manifest_path , orig_package , fixed_package