Merge "Allow for setting a logging_parent for an Android App."
This commit is contained in:
@@ -101,6 +101,7 @@ type aapt struct {
|
|||||||
usesNonSdkApis bool
|
usesNonSdkApis bool
|
||||||
sdkLibraries []string
|
sdkLibraries []string
|
||||||
hasNoCode bool
|
hasNoCode bool
|
||||||
|
LoggingParent string
|
||||||
|
|
||||||
splitNames []string
|
splitNames []string
|
||||||
splits []split
|
splits []split
|
||||||
@@ -234,7 +235,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||||||
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
||||||
|
|
||||||
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries,
|
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries,
|
||||||
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode)
|
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode,
|
||||||
|
a.LoggingParent)
|
||||||
|
|
||||||
// Add additional manifest files to transitive manifests.
|
// Add additional manifest files to transitive manifests.
|
||||||
additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
|
additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
|
||||||
|
@@ -53,7 +53,7 @@ var optionalUsesLibs = []string{
|
|||||||
|
|
||||||
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
|
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
|
||||||
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, sdkLibraries []string,
|
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, sdkLibraries []string,
|
||||||
isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, useEmbeddedDex, hasNoCode bool) android.Path {
|
isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, useEmbeddedDex, hasNoCode bool, loggingParent string) android.Path {
|
||||||
|
|
||||||
var args []string
|
var args []string
|
||||||
if isLibrary {
|
if isLibrary {
|
||||||
@@ -91,6 +91,9 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
|
|||||||
args = append(args, "--has-no-code")
|
args = append(args, "--has-no-code")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if loggingParent != "" {
|
||||||
|
args = append(args, "--logging-parent", loggingParent)
|
||||||
|
}
|
||||||
var deps android.Paths
|
var deps android.Paths
|
||||||
targetSdkVersion, err := sdkContext.targetSdkVersion().effectiveVersionString(ctx)
|
targetSdkVersion, err := sdkContext.targetSdkVersion().effectiveVersionString(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -111,6 +111,9 @@ type overridableAppProperties struct {
|
|||||||
|
|
||||||
// the package name of this app. The package name in the manifest file is used if one was not given.
|
// the package name of this app. The package name in the manifest file is used if one was not given.
|
||||||
Package_name *string
|
Package_name *string
|
||||||
|
|
||||||
|
// the logging parent of this app.
|
||||||
|
Logging_parent *string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidApp struct {
|
type AndroidApp struct {
|
||||||
@@ -303,7 +306,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
|||||||
|
|
||||||
a.aapt.splitNames = a.appProperties.Package_splits
|
a.aapt.splitNames = a.appProperties.Package_splits
|
||||||
a.aapt.sdkLibraries = a.exportedSdkLibs
|
a.aapt.sdkLibraries = a.exportedSdkLibs
|
||||||
|
a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent)
|
||||||
a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...)
|
a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...)
|
||||||
|
|
||||||
// apps manifests are handled by aapt, don't let Module see them
|
// apps manifests are handled by aapt, don't let Module see them
|
||||||
|
@@ -1181,6 +1181,7 @@ func TestOverrideAndroidApp(t *testing.T) {
|
|||||||
name: "bar",
|
name: "bar",
|
||||||
base: "foo",
|
base: "foo",
|
||||||
certificate: ":new_certificate",
|
certificate: ":new_certificate",
|
||||||
|
logging_parent: "bah",
|
||||||
}
|
}
|
||||||
|
|
||||||
android_app_certificate {
|
android_app_certificate {
|
||||||
@@ -1196,37 +1197,41 @@ func TestOverrideAndroidApp(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
expectedVariants := []struct {
|
expectedVariants := []struct {
|
||||||
moduleName string
|
moduleName string
|
||||||
variantName string
|
variantName string
|
||||||
apkName string
|
apkName string
|
||||||
apkPath string
|
apkPath string
|
||||||
signFlag string
|
signFlag string
|
||||||
overrides []string
|
overrides []string
|
||||||
aaptFlag string
|
aaptFlag string
|
||||||
|
logging_parent string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
moduleName: "foo",
|
moduleName: "foo",
|
||||||
variantName: "android_common",
|
variantName: "android_common",
|
||||||
apkPath: "/target/product/test_device/system/app/foo/foo.apk",
|
apkPath: "/target/product/test_device/system/app/foo/foo.apk",
|
||||||
signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
||||||
overrides: []string{"qux"},
|
overrides: []string{"qux"},
|
||||||
aaptFlag: "",
|
aaptFlag: "",
|
||||||
|
logging_parent: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
moduleName: "bar",
|
moduleName: "bar",
|
||||||
variantName: "android_common_bar",
|
variantName: "android_common_bar",
|
||||||
apkPath: "/target/product/test_device/system/app/bar/bar.apk",
|
apkPath: "/target/product/test_device/system/app/bar/bar.apk",
|
||||||
signFlag: "cert/new_cert.x509.pem cert/new_cert.pk8",
|
signFlag: "cert/new_cert.x509.pem cert/new_cert.pk8",
|
||||||
overrides: []string{"qux", "foo"},
|
overrides: []string{"qux", "foo"},
|
||||||
aaptFlag: "",
|
aaptFlag: "",
|
||||||
|
logging_parent: "bah",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
moduleName: "baz",
|
moduleName: "baz",
|
||||||
variantName: "android_common_baz",
|
variantName: "android_common_baz",
|
||||||
apkPath: "/target/product/test_device/system/app/baz/baz.apk",
|
apkPath: "/target/product/test_device/system/app/baz/baz.apk",
|
||||||
signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
||||||
overrides: []string{"qux", "foo"},
|
overrides: []string{"qux", "foo"},
|
||||||
aaptFlag: "--rename-manifest-package org.dandroid.bp",
|
aaptFlag: "--rename-manifest-package org.dandroid.bp",
|
||||||
|
logging_parent: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, expected := range expectedVariants {
|
for _, expected := range expectedVariants {
|
||||||
@@ -1260,6 +1265,13 @@ func TestOverrideAndroidApp(t *testing.T) {
|
|||||||
expected.overrides, mod.appProperties.Overrides)
|
expected.overrides, mod.appProperties.Overrides)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test Overridable property: Logging_parent
|
||||||
|
logging_parent := mod.aapt.LoggingParent
|
||||||
|
if expected.logging_parent != logging_parent {
|
||||||
|
t.Errorf("Incorrect overrides property value for logging parent, expected: %q, got: %q",
|
||||||
|
expected.logging_parent, logging_parent)
|
||||||
|
}
|
||||||
|
|
||||||
// Check the package renaming flag, if exists.
|
// Check the package renaming flag, if exists.
|
||||||
res := variant.Output("package-res.apk")
|
res := variant.Output("package-res.apk")
|
||||||
aapt2Flags := res.Args["flags"]
|
aapt2Flags := res.Args["flags"]
|
||||||
|
@@ -51,6 +51,9 @@ def parse_args():
|
|||||||
help='specify additional <uses-library> tag to add. android:requred is set to false')
|
help='specify additional <uses-library> tag to add. android:requred is set to false')
|
||||||
parser.add_argument('--uses-non-sdk-api', dest='uses_non_sdk_api', action='store_true',
|
parser.add_argument('--uses-non-sdk-api', dest='uses_non_sdk_api', action='store_true',
|
||||||
help='manifest is for a package built against the platform')
|
help='manifest is for a package built against the platform')
|
||||||
|
parser.add_argument('--logging-parent', dest='logging_parent', default='',
|
||||||
|
help=('specify logging parent as an additional <meta-data> tag. '
|
||||||
|
'This value is ignored if the logging_parent meta-data tag is present.'))
|
||||||
parser.add_argument('--use-embedded-dex', dest='use_embedded_dex', action='store_true',
|
parser.add_argument('--use-embedded-dex', dest='use_embedded_dex', action='store_true',
|
||||||
help=('specify if the app wants to use embedded dex and avoid extracted,'
|
help=('specify if the app wants to use embedded dex and avoid extracted,'
|
||||||
'locally compiled code. Must not conflict if already declared '
|
'locally compiled code. Must not conflict if already declared '
|
||||||
@@ -124,6 +127,52 @@ def raise_min_sdk_version(doc, min_sdk_version, target_sdk_version, library):
|
|||||||
element.setAttributeNode(target_attr)
|
element.setAttributeNode(target_attr)
|
||||||
|
|
||||||
|
|
||||||
|
def add_logging_parent(doc, logging_parent_value):
|
||||||
|
"""Add logging parent as an additional <meta-data> tag.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
doc: The XML document. May be modified by this function.
|
||||||
|
logging_parent_value: A string representing the logging
|
||||||
|
parent value.
|
||||||
|
Raises:
|
||||||
|
RuntimeError: Invalid manifest
|
||||||
|
"""
|
||||||
|
manifest = parse_manifest(doc)
|
||||||
|
|
||||||
|
logging_parent_key = 'android.content.pm.LOGGING_PARENT'
|
||||||
|
elems = get_children_with_tag(manifest, 'application')
|
||||||
|
application = elems[0] if len(elems) == 1 else None
|
||||||
|
if len(elems) > 1:
|
||||||
|
raise RuntimeError('found multiple <application> tags')
|
||||||
|
elif not elems:
|
||||||
|
application = doc.createElement('application')
|
||||||
|
indent = get_indent(manifest.firstChild, 1)
|
||||||
|
first = manifest.firstChild
|
||||||
|
manifest.insertBefore(doc.createTextNode(indent), first)
|
||||||
|
manifest.insertBefore(application, first)
|
||||||
|
|
||||||
|
indent = get_indent(application.firstChild, 2)
|
||||||
|
|
||||||
|
last = application.lastChild
|
||||||
|
if last is not None and last.nodeType != minidom.Node.TEXT_NODE:
|
||||||
|
last = None
|
||||||
|
|
||||||
|
if not find_child_with_attribute(application, 'meta-data', android_ns,
|
||||||
|
'name', logging_parent_key):
|
||||||
|
ul = doc.createElement('meta-data')
|
||||||
|
ul.setAttributeNS(android_ns, 'android:name', logging_parent_key)
|
||||||
|
ul.setAttributeNS(android_ns, 'android:value', logging_parent_value)
|
||||||
|
application.insertBefore(doc.createTextNode(indent), last)
|
||||||
|
application.insertBefore(ul, last)
|
||||||
|
last = application.lastChild
|
||||||
|
|
||||||
|
# align the closing tag with the opening tag if it's not
|
||||||
|
# indented
|
||||||
|
if last and last.nodeType != minidom.Node.TEXT_NODE:
|
||||||
|
indent = get_indent(application.previousSibling, 1)
|
||||||
|
application.appendChild(doc.createTextNode(indent))
|
||||||
|
|
||||||
|
|
||||||
def add_uses_libraries(doc, new_uses_libraries, required):
|
def add_uses_libraries(doc, new_uses_libraries, required):
|
||||||
"""Add additional <uses-library> tags
|
"""Add additional <uses-library> tags
|
||||||
|
|
||||||
@@ -291,6 +340,9 @@ def main():
|
|||||||
if args.uses_non_sdk_api:
|
if args.uses_non_sdk_api:
|
||||||
add_uses_non_sdk_api(doc)
|
add_uses_non_sdk_api(doc)
|
||||||
|
|
||||||
|
if args.logging_parent:
|
||||||
|
add_logging_parent(doc, args.logging_parent)
|
||||||
|
|
||||||
if args.use_embedded_dex:
|
if args.use_embedded_dex:
|
||||||
add_use_embedded_dex(doc)
|
add_use_embedded_dex(doc)
|
||||||
|
|
||||||
|
@@ -226,6 +226,47 @@ class RaiseMinSdkVersionTest(unittest.TestCase):
|
|||||||
self.assertEqual(output, expected)
|
self.assertEqual(output, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class AddLoggingParentTest(unittest.TestCase):
|
||||||
|
"""Unit tests for add_logging_parent function."""
|
||||||
|
|
||||||
|
def add_logging_parent_test(self, input_manifest, logging_parent=None):
|
||||||
|
doc = minidom.parseString(input_manifest)
|
||||||
|
if logging_parent:
|
||||||
|
manifest_fixer.add_logging_parent(doc, logging_parent)
|
||||||
|
output = StringIO.StringIO()
|
||||||
|
manifest_fixer.write_xml(output, doc)
|
||||||
|
return output.getvalue()
|
||||||
|
|
||||||
|
manifest_tmpl = (
|
||||||
|
'<?xml version="1.0" encoding="utf-8"?>\n'
|
||||||
|
'<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'
|
||||||
|
'%s'
|
||||||
|
'</manifest>\n')
|
||||||
|
|
||||||
|
def uses_logging_parent(self, logging_parent=None):
|
||||||
|
attrs = ''
|
||||||
|
if logging_parent:
|
||||||
|
meta_text = ('<meta-data android:name="android.content.pm.LOGGING_PARENT" '
|
||||||
|
'android:value="%s"/>\n') % (logging_parent)
|
||||||
|
attrs += ' <application>\n %s </application>\n' % (meta_text)
|
||||||
|
|
||||||
|
return attrs
|
||||||
|
|
||||||
|
def test_no_logging_parent(self):
|
||||||
|
"""Tests manifest_fixer with no logging_parent."""
|
||||||
|
manifest_input = self.manifest_tmpl % ''
|
||||||
|
expected = self.manifest_tmpl % self.uses_logging_parent()
|
||||||
|
output = self.add_logging_parent_test(manifest_input)
|
||||||
|
self.assertEqual(output, expected)
|
||||||
|
|
||||||
|
def test_logging_parent(self):
|
||||||
|
"""Tests manifest_fixer with no logging_parent."""
|
||||||
|
manifest_input = self.manifest_tmpl % ''
|
||||||
|
expected = self.manifest_tmpl % self.uses_logging_parent('FOO')
|
||||||
|
output = self.add_logging_parent_test(manifest_input, 'FOO')
|
||||||
|
self.assertEqual(output, expected)
|
||||||
|
|
||||||
|
|
||||||
class AddUsesLibrariesTest(unittest.TestCase):
|
class AddUsesLibrariesTest(unittest.TestCase):
|
||||||
"""Unit tests for add_uses_libraries function."""
|
"""Unit tests for add_uses_libraries function."""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user