Commit 65f0e20a authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Commit Bot

Revert "Reland "[Android] Remove most resource names in resources.arsc""

This reverts commit d3fd7a3e.

Reason for revert: breaks ui tests

Original change's description:
> Reland "[Android] Remove most resource names in resources.arsc"
> 
> This is a reland of 86259392
> 
> TBR=This is the same cl no changes
> 
> Original change's description:
> > [Android] Remove most resource names in resources.arsc
> >
> > resource names are stored in the resources.arsc file to allow for
> > getIdentifier with the string name of the resource to work. This cl
> > obfuscates all of those resources to one name (and thus stored only
> > once) for all resources that are not accessed via getIdentifier.
> >
> > This improves binary size by about 200KB.
> >
> > Bug: 894208
> >
> > Change-Id: I28c440c22b90cd045f53017073fdb88c7410d530
> > Reviewed-on: https://chromium-review.googlesource.com/c/1265897
> > Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
> > Reviewed-by: Richard Coles <torne@chromium.org>
> > Reviewed-by: agrieve <agrieve@chromium.org>
> > Reviewed-by: Ted Choc <tedchoc@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#603229}
> 
> Bug: 894208
> Change-Id: Id023518c91c0c98cf68f15efad286c4874b4976d
> Reviewed-on: https://chromium-review.googlesource.com/c/1308991
> Reviewed-by: Mohamed Heikal <mheikal@chromium.org>
> Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#604426}

TBR=torne@chromium.org,tedchoc@chromium.org,agrieve@chromium.org,mheikal@chromium.org

Change-Id: I1e4d1de0ea707d6dddfc82b13a44854fc30be753
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 894208
Reviewed-on: https://chromium-review.googlesource.com/c/1313279Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604700}
parent d833bb6b
string/license_activity_title#no_obfuscate
......@@ -29,9 +29,6 @@ public class LicenseActivity extends Activity {
String.format("content://%s.%s", packageName, LICENSES_URI_SUFFIX);
intent.setDataAndType(Uri.parse(licenseUri), LICENSES_CONTENT_TYPE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
// Resources are accessed via getIdentifier because resource ids in the standalone system
// webview apk have incorrect package_ids. Accessing resources via getIdentifier needs to be
// whitelisted in //android_webview/aapt2.config. see https://crbug.com/894208
final int titleId =
getResources().getIdentifier("license_activity_title", "string", packageName);
if (titleId != 0) {
......
......@@ -327,9 +327,8 @@ def main(args):
resource_infos = resource_apk.infolist()
# 1. AndroidManifest.xml
copy_resource(
resource_apk.getinfo('AndroidManifest.xml'),
out_dir=apk_manifest_dir)
assert resource_infos[0].filename == 'AndroidManifest.xml'
copy_resource(resource_infos[0], out_dir=apk_manifest_dir)
# 2. Assets
if options.write_asset_list:
......@@ -377,9 +376,8 @@ def main(args):
build_utils.AddToZipHermetic(out_apk, apk_path, data='')
# 5. Resources
for info in resource_infos:
if info.filename != 'AndroidManifest.xml':
copy_resource(info)
for info in resource_infos[1:]:
copy_resource(info)
# 6. Java resources that should be accessible via
# Class.getResourceAsStream(), in particular parts of Emma jar.
......
......@@ -141,17 +141,6 @@ def _ParseArgs(args):
action='store_true',
help='Whether to strip xml namespaces from processed '
'xml resources')
input_opts.add_argument(
'--resources-config-path', help='Path to aapt2 resources config file.')
input_opts.add_argument(
'--optimize-resources',
default=False,
action='store_true',
help='Whether to run the `aapt2 optimize` step on the resources.')
input_opts.add_argument(
'--unoptimized-resources-path',
help='Path to output the intermediate apk before running '
'`aapt2 optimize`.')
input_opts.add_argument(
'--check-resources-pkg-id', type=_PackageIdArgument,
......@@ -317,6 +306,7 @@ def _CreateLinkApkArgs(options):
'--version-name', options.version_name,
'--auto-add-overlay',
'--no-version-vectors',
'-o', options.apk_path,
]
for j in options.include_resources:
......@@ -491,11 +481,7 @@ def _CompileDeps(aapt2_path, dep_subdirs, temp_dir):
partial_path = os.path.join(partials_dir, dirname + '.zip')
compile_command = (partial_compile_command +
['--dir', directory, '-o', partial_path])
build_utils.CheckOutput(
compile_command,
stderr_filter=lambda output:
build_utils.FilterLines(
output, r'ignoring configuration .* for styleable'))
build_utils.CheckOutput(compile_command)
# Sorting the files in the partial ensures deterministic output from the
# aapt2 link step which uses order of files in the partial.
......@@ -555,15 +541,7 @@ def _PackageApk(options, dep_subdirs, temp_dir, gen_dir, r_txt_path):
for directory in dep_subdirs:
renamed_paths.update(_MoveImagesToNonMdpiFolders(directory))
if options.optimize_resources:
if options.unoptimized_resources_path:
unoptimized_apk_path = options.unoptimized_resources_path
else:
unoptimized_apk_path = os.path.join(gen_dir, 'intermediate.ap_')
else:
unoptimized_apk_path = options.apk_path
link_command = _CreateLinkApkArgs(options)
link_command += ['-o', unoptimized_apk_path]
link_command += ['--output-text-symbols', r_txt_path]
# TODO(digit): Is this below actually required for R.txt generation?
link_command += ['--java', gen_dir]
......@@ -579,26 +557,6 @@ def _PackageApk(options, dep_subdirs, temp_dir, gen_dir, r_txt_path):
# Also creates R.txt
build_utils.CheckOutput(
link_command, print_stdout=False, print_stderr=False)
if options.optimize_resources:
# Optimize the resources.arsc file by obfuscating resource names and only
# allow usage via R.java constant.
optimize_command = [
options.aapt2_path,
'optimize',
'--enable-resource-obfuscation',
'-o',
options.apk_path,
unoptimized_apk_path,
]
if options.resources_config_path:
optimize_command += [
'--resources-config-path',
options.resources_config_path,
]
build_utils.CheckOutput(
optimize_command, print_stdout=False, print_stderr=False)
_CreateResourceInfoFile(
renamed_paths, options.apk_info_path, options.dependencies_res_zips)
......@@ -681,27 +639,25 @@ def main(args):
# Order of these must match order specified in GN so that the correct one
# appears first in the depfile.
possible_output_paths = [
options.apk_path,
options.apk_path + '.info',
options.r_text_out,
options.srcjar_out,
options.proguard_file,
options.proguard_file_main_dex,
options.unoptimized_resources_path,
options.apk_path,
options.apk_path + '.info',
options.r_text_out,
options.srcjar_out,
options.proguard_file,
options.proguard_file_main_dex,
]
output_paths = [x for x in possible_output_paths if x]
# List python deps in input_strings rather than input_paths since the contents
# of them does not change what gets written to the depsfile.
input_strings = options.extra_res_packages + [
options.shared_resources,
options.resource_blacklist_regex,
options.resource_blacklist_exceptions,
str(options.debuggable),
str(options.png_to_webp),
str(options.support_zh_hk),
str(options.no_xml_namespaces),
str(options.optimize_resources),
options.shared_resources,
options.resource_blacklist_regex,
options.resource_blacklist_exceptions,
str(options.debuggable),
str(options.png_to_webp),
str(options.support_zh_hk),
str(options.no_xml_namespaces),
]
input_strings.extend(_CreateLinkApkArgs(options))
......@@ -713,12 +669,11 @@ def main(args):
possible_input_paths = [
options.aapt_path,
options.aapt2_path,
options.android_manifest,
debug_temp_resources_dir,
options.shared_resources_whitelist,
options.resources_config_path,
options.aapt_path,
options.aapt2_path,
options.android_manifest,
debug_temp_resources_dir,
options.shared_resources_whitelist,
]
possible_input_paths += options.include_resources
input_paths = [x for x in possible_input_paths if x]
......
......@@ -1981,15 +1981,14 @@ if (enable_java_templates) {
outputs = []
_android_aapt_path = android_default_aapt_path
_android_aapt2_path = android_sdk_tools_bundle_aapt2
if (_proto_format) {
_android_aapt2_path = android_sdk_tools_bundle_aapt2
depfile = "$target_gen_dir/${invoker.target_name}_3.d"
}
inputs = [
invoker.build_config,
_android_aapt_path,
_android_aapt2_path,
]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
......@@ -2000,13 +1999,19 @@ if (enable_java_templates) {
"--include-resources=@FileArg($_rebased_build_config:android:sdk_jars)",
"--aapt-path",
rebase_path(_android_aapt_path, root_build_dir),
"--aapt2-path",
rebase_path(_android_aapt2_path, root_build_dir),
"--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)",
"--extra-res-packages=@FileArg($_rebased_build_config:resources:extra_package_names)",
"--extra-r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)",
]
if (_proto_format) {
inputs += [ _android_aapt2_path ]
args += [
"--aapt2-path",
rebase_path(_android_aapt2_path, root_build_dir),
]
}
inputs += [ invoker.android_manifest ]
args += [
"--android-manifest",
......@@ -2043,25 +2048,6 @@ if (enable_java_templates) {
]
}
if (defined(invoker.optimize_resources) && invoker.optimize_resources) {
args += [ "--optimize-resources" ]
if (defined(invoker.resources_config_path)) {
inputs += [ invoker.resources_config_path ]
args += [
"--resources-config-path",
rebase_path(invoker.resources_config_path, root_build_dir),
]
}
if (defined(invoker.unoptimized_resources_path)) {
args += [
"--unoptimized-resources-path",
rebase_path(invoker.unoptimized_resources_path, root_build_dir),
]
outputs += [ invoker.unoptimized_resources_path ]
}
}
# Useful to have android:debuggable in the manifest even for Release
# builds. Just omit it for officai
if (debuggable_apks) {
......@@ -2511,13 +2497,6 @@ if (enable_java_templates) {
get_label_info(_incremental_compile_resources_target_name,
"target_gen_dir") + "/AndroidManifest.xml"
if (defined(invoker.unoptimized_resources_path)) {
_incremental_packaged_resources_path =
invoker.unoptimized_resources_path
} else {
_incremental_packaged_resources_path = invoker.packaged_resources_path
}
_rebased_build_config =
rebase_path(invoker.assets_build_config, root_build_dir)
......@@ -2528,7 +2507,7 @@ if (enable_java_templates) {
inputs = [
_android_manifest,
invoker.assets_build_config,
_incremental_packaged_resources_path,
invoker.packaged_resources_path,
]
outputs = [
# Output the non-compiled manifest for easy debugging (as opposed to
......@@ -2543,7 +2522,7 @@ if (enable_java_templates) {
"--out-manifest",
rebase_path(_incremental_android_manifest, root_build_dir),
"--in-apk",
rebase_path(_incremental_packaged_resources_path, root_build_dir),
rebase_path(invoker.packaged_resources_path, root_build_dir),
"--out-apk",
rebase_path(_incremental_compiled_resources_path, root_build_dir),
"--aapt-path",
......
......@@ -1884,10 +1884,6 @@ if (enable_java_templates) {
# uncompress_shared_libraries: True if shared libraries should be stored
# uncompressed in the APK. Must be unset or true if load_library_from_apk
# is set to true.
# optimize_resources: True if resource names should be stripped from the
# resources.arsc file in the apk or module.
# resources_config_path: Path to the aapt2 optimize config file that tags
# resources with acceptable/non-acceptable optimizations.
template("android_apk_or_module") {
forward_variables_from(invoker, [ "testonly" ])
......@@ -2128,13 +2124,6 @@ if (enable_java_templates) {
_android_sdk_dep = "//third_party/android_tools:android_sdk_java"
}
_optimize_resources =
defined(invoker.optimize_resources) && invoker.optimize_resources
if (_optimize_resources) {
_unoptimized_resources_path =
"$target_out_dir/$_template_name.unoptimized.ap_"
}
_compile_resources_target = "${_template_name}__compile_resources"
_compile_resources_rtxt_out =
"${target_gen_dir}/${_compile_resources_target}_R.txt"
......@@ -2147,7 +2136,6 @@ if (enable_java_templates) {
"aapt_locale_whitelist",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"resources_config_path",
"png_to_webp",
"no_xml_namespaces",
])
......@@ -2165,10 +2153,6 @@ if (enable_java_templates) {
proguard_file_main_dex = _generated_proguard_main_dex_config
}
output = _packaged_resources_path
if (_optimize_resources) {
optimize_resources = true
unoptimized_resources_path = _unoptimized_resources_path
}
build_config = _build_config
deps = _deps + [
......@@ -2604,9 +2588,6 @@ if (enable_java_templates) {
if (_incremental_allowed) {
android_manifest = _android_manifest
base_path = _base_path
if (_optimize_resources) {
unoptimized_resources_path = _unoptimized_resources_path
}
}
# Incremental apk does not use native libs nor final dex.
......@@ -2880,7 +2861,6 @@ if (enable_java_templates) {
"never_incremental",
"no_build_hooks",
"no_xml_namespaces",
"optimize_resources",
"png_to_webp",
"post_process_package_resources_script",
"product_version_resources_dep",
......@@ -2889,7 +2869,6 @@ if (enable_java_templates) {
"proguard_jar_path",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"resources_config_path",
"secondary_abi_loadable_modules",
"secondary_abi_shared_libraries",
"secondary_native_lib_placeholders",
......@@ -2979,7 +2958,6 @@ if (enable_java_templates) {
"native_lib_version_rule",
"negative_main_dex_globs",
"no_xml_namespaces",
"optimize_resources",
"png_to_webp",
"product_version_resources_dep",
"proguard_configs",
......@@ -2987,7 +2965,6 @@ if (enable_java_templates) {
"proguard_jar_path",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"resources_config_path",
"secondary_abi_loadable_modules",
"secondary_abi_shared_libraries",
"secondary_native_lib_placeholders",
......
......@@ -107,8 +107,6 @@ template("chrome_public_common_apk_or_module_tmpl") {
# Use zh-TW strings for zh-HK (https://crbug.com/780847).
support_zh_hk = true
optimize_resources = true
if (defined(shared_libraries) && shared_libraries != []) {
_native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
......@@ -229,9 +227,6 @@ template("monochrome_public_common_apk_or_module_tmpl") {
# Webview supports all locales (has no omitted ones).
aapt_locale_whitelist = locales
# Resources config for blocklisting resource names from obfuscation
resources_config_path = "//android_webview/aapt2.config"
if (!defined(invoker.target_type) || invoker.target_type == "android_apk") {
# Incremental install doesn't work for monochrome. See crbug.com/663492.
never_incremental = true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment