Rename preferCodeIntegrity to useEmbeddedDex
Test: build and run testing app Bug: 112037137 Change-Id: Ia82c2c3ba7eb32117a4be078ac31ee2ba510f9eb
This commit is contained in:
@@ -87,14 +87,14 @@ type Tools struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ModuleConfig struct {
|
type ModuleConfig struct {
|
||||||
Name string
|
Name string
|
||||||
DexLocation string // dex location on device
|
DexLocation string // dex location on device
|
||||||
BuildPath string
|
BuildPath string
|
||||||
DexPath string
|
DexPath string
|
||||||
PreferCodeIntegrity bool
|
UseEmbeddedDex bool
|
||||||
UncompressedDex bool
|
UncompressedDex bool
|
||||||
HasApkLibraries bool
|
HasApkLibraries bool
|
||||||
PreoptFlags []string
|
PreoptFlags []string
|
||||||
|
|
||||||
ProfileClassListing string
|
ProfileClassListing string
|
||||||
ProfileIsTextListing bool
|
ProfileIsTextListing bool
|
||||||
|
@@ -66,7 +66,7 @@ var testModuleConfig = ModuleConfig{
|
|||||||
DexLocation: "",
|
DexLocation: "",
|
||||||
BuildPath: "",
|
BuildPath: "",
|
||||||
DexPath: "",
|
DexPath: "",
|
||||||
PreferCodeIntegrity: false,
|
UseEmbeddedDex: false,
|
||||||
UncompressedDex: false,
|
UncompressedDex: false,
|
||||||
HasApkLibraries: false,
|
HasApkLibraries: false,
|
||||||
PreoptFlags: nil,
|
PreoptFlags: nil,
|
||||||
|
@@ -149,14 +149,14 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
dexpreoptConfig := dexpreopt.ModuleConfig{
|
dexpreoptConfig := dexpreopt.ModuleConfig{
|
||||||
Name: ctx.ModuleName(),
|
Name: ctx.ModuleName(),
|
||||||
DexLocation: dexLocation,
|
DexLocation: dexLocation,
|
||||||
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").String(),
|
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").String(),
|
||||||
DexPath: dexJarFile.String(),
|
DexPath: dexJarFile.String(),
|
||||||
PreferCodeIntegrity: false,
|
UseEmbeddedDex: false,
|
||||||
UncompressedDex: d.uncompressedDex,
|
UncompressedDex: d.uncompressedDex,
|
||||||
HasApkLibraries: false,
|
HasApkLibraries: false,
|
||||||
PreoptFlags: nil,
|
PreoptFlags: nil,
|
||||||
|
|
||||||
ProfileClassListing: profileClassListing.String(),
|
ProfileClassListing: profileClassListing.String(),
|
||||||
ProfileIsTextListing: profileIsTextListing,
|
ProfileIsTextListing: profileIsTextListing,
|
||||||
|
@@ -61,9 +61,10 @@ 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('--prefer-code-integrity', dest='prefer_code_integrity', action='store_true',
|
parser.add_argument('--use-embedded-dex', dest='use_embedded_dex', action='store_true',
|
||||||
help=('specify if the app prefers strict code integrity. Should not be conflict '
|
help=('specify if the app wants to use embedded dex and avoid extracted,'
|
||||||
'if already declared in the manifest.'))
|
'locally compiled code. Should not be conflict if already declared '
|
||||||
|
'in the manifest.'))
|
||||||
parser.add_argument('input', help='input AndroidManifest.xml file')
|
parser.add_argument('input', help='input AndroidManifest.xml file')
|
||||||
parser.add_argument('output', help='output AndroidManifest.xml file')
|
parser.add_argument('output', help='output AndroidManifest.xml file')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
@@ -272,7 +273,7 @@ def add_uses_non_sdk_api(doc):
|
|||||||
application.setAttributeNode(attr)
|
application.setAttributeNode(attr)
|
||||||
|
|
||||||
|
|
||||||
def add_prefer_code_integrity(doc):
|
def add_use_embedded_dex(doc):
|
||||||
manifest = parse_manifest(doc)
|
manifest = parse_manifest(doc)
|
||||||
elems = get_children_with_tag(manifest, 'application')
|
elems = get_children_with_tag(manifest, 'application')
|
||||||
application = elems[0] if len(elems) == 1 else None
|
application = elems[0] if len(elems) == 1 else None
|
||||||
@@ -285,13 +286,13 @@ def add_prefer_code_integrity(doc):
|
|||||||
manifest.insertBefore(doc.createTextNode(indent), first)
|
manifest.insertBefore(doc.createTextNode(indent), first)
|
||||||
manifest.insertBefore(application, first)
|
manifest.insertBefore(application, first)
|
||||||
|
|
||||||
attr = application.getAttributeNodeNS(android_ns, 'preferCodeIntegrity')
|
attr = application.getAttributeNodeNS(android_ns, 'useEmbeddedDex')
|
||||||
if attr is None:
|
if attr is None:
|
||||||
attr = doc.createAttributeNS(android_ns, 'android:preferCodeIntegrity')
|
attr = doc.createAttributeNS(android_ns, 'android:useEmbeddedDex')
|
||||||
attr.value = 'true'
|
attr.value = 'true'
|
||||||
application.setAttributeNode(attr)
|
application.setAttributeNode(attr)
|
||||||
elif attr.value != 'true':
|
elif attr.value != 'true':
|
||||||
raise RuntimeError('existing attribute mismatches the option of --prefer-code-integrity')
|
raise RuntimeError('existing attribute mismatches the option of --use-embedded-dex')
|
||||||
|
|
||||||
|
|
||||||
def write_xml(f, doc):
|
def write_xml(f, doc):
|
||||||
@@ -321,8 +322,8 @@ 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.prefer_code_integrity:
|
if args.use_embedded_dex:
|
||||||
add_prefer_code_integrity(doc)
|
add_use_embedded_dex(doc)
|
||||||
|
|
||||||
with open(args.output, 'wb') as f:
|
with open(args.output, 'wb') as f:
|
||||||
write_xml(f, doc)
|
write_xml(f, doc)
|
||||||
|
@@ -346,12 +346,12 @@ class AddUsesNonSdkApiTest(unittest.TestCase):
|
|||||||
self.assertEqual(output, expected)
|
self.assertEqual(output, expected)
|
||||||
|
|
||||||
|
|
||||||
class PreferCodeIntegrityTest(unittest.TestCase):
|
class UseEmbeddedDexTest(unittest.TestCase):
|
||||||
"""Unit tests for add_prefer_code_integrity function."""
|
"""Unit tests for add_use_embedded_dex function."""
|
||||||
|
|
||||||
def run_test(self, input_manifest):
|
def run_test(self, input_manifest):
|
||||||
doc = minidom.parseString(input_manifest)
|
doc = minidom.parseString(input_manifest)
|
||||||
manifest_fixer.add_prefer_code_integrity(doc)
|
manifest_fixer.add_use_embedded_dex(doc)
|
||||||
output = StringIO.StringIO()
|
output = StringIO.StringIO()
|
||||||
manifest_fixer.write_xml(output, doc)
|
manifest_fixer.write_xml(output, doc)
|
||||||
return output.getvalue()
|
return output.getvalue()
|
||||||
@@ -362,23 +362,23 @@ class PreferCodeIntegrityTest(unittest.TestCase):
|
|||||||
' <application%s/>\n'
|
' <application%s/>\n'
|
||||||
'</manifest>\n')
|
'</manifest>\n')
|
||||||
|
|
||||||
def prefer_code_integrity(self, value):
|
def use_embedded_dex(self, value):
|
||||||
return ' android:preferCodeIntegrity="%s"' % value
|
return ' android:useEmbeddedDex="%s"' % value
|
||||||
|
|
||||||
def test_manifest_with_undeclared_preference(self):
|
def test_manifest_with_undeclared_preference(self):
|
||||||
manifest_input = self.manifest_tmpl % ''
|
manifest_input = self.manifest_tmpl % ''
|
||||||
expected = self.manifest_tmpl % self.prefer_code_integrity('true')
|
expected = self.manifest_tmpl % self.use_embedded_dex('true')
|
||||||
output = self.run_test(manifest_input)
|
output = self.run_test(manifest_input)
|
||||||
self.assertEqual(output, expected)
|
self.assertEqual(output, expected)
|
||||||
|
|
||||||
def test_manifest_with_prefer_code_integrity(self):
|
def test_manifest_with_use_embedded_dex(self):
|
||||||
manifest_input = self.manifest_tmpl % self.prefer_code_integrity('true')
|
manifest_input = self.manifest_tmpl % self.use_embedded_dex('true')
|
||||||
expected = manifest_input
|
expected = manifest_input
|
||||||
output = self.run_test(manifest_input)
|
output = self.run_test(manifest_input)
|
||||||
self.assertEqual(output, expected)
|
self.assertEqual(output, expected)
|
||||||
|
|
||||||
def test_manifest_with_not_prefer_code_integrity(self):
|
def test_manifest_with_not_use_embedded_dex(self):
|
||||||
manifest_input = self.manifest_tmpl % self.prefer_code_integrity('false')
|
manifest_input = self.manifest_tmpl % self.use_embedded_dex('false')
|
||||||
self.assertRaises(RuntimeError, self.run_test, manifest_input)
|
self.assertRaises(RuntimeError, self.run_test, manifest_input)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user