Loading java/aar.go +3 −1 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ type aapt struct { usesNonSdkApis bool sdkLibraries []string hasNoCode bool LoggingParent string splitNames []string splits []split Loading Loading @@ -234,7 +235,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) 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. additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests) Loading java/android_manifest.go +4 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ var optionalUsesLibs = []string{ // Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml 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 if isLibrary { Loading Loading @@ -91,6 +91,9 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext args = append(args, "--has-no-code") } if loggingParent != "" { args = append(args, "--logging-parent", loggingParent) } var deps android.Paths targetSdkVersion, err := sdkContext.targetSdkVersion().effectiveVersionString(ctx) if err != nil { Loading java/app.go +4 −1 Original line number Diff line number Diff line Loading @@ -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. Package_name *string // the logging parent of this app. Logging_parent *string } type AndroidApp struct { Loading Loading @@ -303,7 +306,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { a.aapt.splitNames = a.appProperties.Package_splits a.aapt.sdkLibraries = a.exportedSdkLibs a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent) a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...) // apps manifests are handled by aapt, don't let Module see them Loading java/app_test.go +37 −25 Original line number Diff line number Diff line Loading @@ -1181,6 +1181,7 @@ func TestOverrideAndroidApp(t *testing.T) { name: "bar", base: "foo", certificate: ":new_certificate", logging_parent: "bah", } android_app_certificate { Loading @@ -1203,6 +1204,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag string overrides []string aaptFlag string logging_parent string }{ { moduleName: "foo", Loading @@ -1211,6 +1213,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", overrides: []string{"qux"}, aaptFlag: "", logging_parent: "", }, { moduleName: "bar", Loading @@ -1219,6 +1222,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag: "cert/new_cert.x509.pem cert/new_cert.pk8", overrides: []string{"qux", "foo"}, aaptFlag: "", logging_parent: "bah", }, { moduleName: "baz", Loading @@ -1227,6 +1231,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", overrides: []string{"qux", "foo"}, aaptFlag: "--rename-manifest-package org.dandroid.bp", logging_parent: "", }, } for _, expected := range expectedVariants { Loading Loading @@ -1260,6 +1265,13 @@ func TestOverrideAndroidApp(t *testing.T) { 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. res := variant.Output("package-res.apk") aapt2Flags := res.Args["flags"] Loading scripts/manifest_fixer.py +52 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,9 @@ def parse_args(): 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', 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', help=('specify if the app wants to use embedded dex and avoid extracted,' 'locally compiled code. Must not conflict if already declared ' Loading Loading @@ -124,6 +127,52 @@ def raise_min_sdk_version(doc, min_sdk_version, target_sdk_version, library): 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): """Add additional <uses-library> tags Loading Loading @@ -291,6 +340,9 @@ def main(): if args.uses_non_sdk_api: add_uses_non_sdk_api(doc) if args.logging_parent: add_logging_parent(doc, args.logging_parent) if args.use_embedded_dex: add_use_embedded_dex(doc) Loading Loading
java/aar.go +3 −1 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ type aapt struct { usesNonSdkApis bool sdkLibraries []string hasNoCode bool LoggingParent string splitNames []string splits []split Loading Loading @@ -234,7 +235,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) 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. additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests) Loading
java/android_manifest.go +4 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ var optionalUsesLibs = []string{ // Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml 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 if isLibrary { Loading Loading @@ -91,6 +91,9 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext args = append(args, "--has-no-code") } if loggingParent != "" { args = append(args, "--logging-parent", loggingParent) } var deps android.Paths targetSdkVersion, err := sdkContext.targetSdkVersion().effectiveVersionString(ctx) if err != nil { Loading
java/app.go +4 −1 Original line number Diff line number Diff line Loading @@ -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. Package_name *string // the logging parent of this app. Logging_parent *string } type AndroidApp struct { Loading Loading @@ -303,7 +306,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { a.aapt.splitNames = a.appProperties.Package_splits a.aapt.sdkLibraries = a.exportedSdkLibs a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent) a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...) // apps manifests are handled by aapt, don't let Module see them Loading
java/app_test.go +37 −25 Original line number Diff line number Diff line Loading @@ -1181,6 +1181,7 @@ func TestOverrideAndroidApp(t *testing.T) { name: "bar", base: "foo", certificate: ":new_certificate", logging_parent: "bah", } android_app_certificate { Loading @@ -1203,6 +1204,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag string overrides []string aaptFlag string logging_parent string }{ { moduleName: "foo", Loading @@ -1211,6 +1213,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", overrides: []string{"qux"}, aaptFlag: "", logging_parent: "", }, { moduleName: "bar", Loading @@ -1219,6 +1222,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag: "cert/new_cert.x509.pem cert/new_cert.pk8", overrides: []string{"qux", "foo"}, aaptFlag: "", logging_parent: "bah", }, { moduleName: "baz", Loading @@ -1227,6 +1231,7 @@ func TestOverrideAndroidApp(t *testing.T) { signFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", overrides: []string{"qux", "foo"}, aaptFlag: "--rename-manifest-package org.dandroid.bp", logging_parent: "", }, } for _, expected := range expectedVariants { Loading Loading @@ -1260,6 +1265,13 @@ func TestOverrideAndroidApp(t *testing.T) { 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. res := variant.Output("package-res.apk") aapt2Flags := res.Args["flags"] Loading
scripts/manifest_fixer.py +52 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,9 @@ def parse_args(): 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', 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', help=('specify if the app wants to use embedded dex and avoid extracted,' 'locally compiled code. Must not conflict if already declared ' Loading Loading @@ -124,6 +127,52 @@ def raise_min_sdk_version(doc, min_sdk_version, target_sdk_version, library): 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): """Add additional <uses-library> tags Loading Loading @@ -291,6 +340,9 @@ def main(): if args.uses_non_sdk_api: add_uses_non_sdk_api(doc) if args.logging_parent: add_logging_parent(doc, args.logging_parent) if args.use_embedded_dex: add_use_embedded_dex(doc) Loading