0

Android: Stop checking native library version number

Now that we never extract the native library, there's no point in
asserting that it's the right one (version skew is impossible).

Bug: 1041930
Change-Id: Id69fbfb5587402aba608a057b18df80898aaf255
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2756732
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Clark DuVall <cduvall@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Egor Pasko <pasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#876714}
This commit is contained in:
Andrew Grieve
2021-04-27 19:42:48 +00:00
committed by Chromium LUCI CQ
parent 324f88c41d
commit 5ba1789980
15 changed files with 29 additions and 109 deletions

@ -5,8 +5,6 @@
#include "android_webview/lib/webview_jni_onload.h"
#include "android_webview/lib/aw_main_delegate.h"
#include "base/android/library_loader/library_loader_hooks.h"
#include "components/version_info/version_info_values.h"
#include "content/public/app/content_jni_onload.h"
#include "content/public/app/content_main.h"
@ -16,7 +14,6 @@ bool OnJNIOnLoadInit() {
if (!content::android::OnJNIOnLoadInit())
return false;
base::android::SetVersionNumber(PRODUCT_VERSION);
content::SetContentMainDelegate(new android_webview::AwMainDelegate());
return true;
}

@ -179,15 +179,6 @@ template("system_webview_apk_or_module_tmpl") {
}
}
if (!_use_trichrome_library || android_64bit_target_cpu) {
# 32-bit TrichromeWebView doesn't have a native library, so only do this
# for other configs.
native_lib_version_rule = "//build/util:chrome_version_json"
_native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
}
aapt_locale_allowlist = locales
resource_exclusion_regex = common_resource_exclusion_regex

@ -91,11 +91,6 @@ android_apk("webview_instrumentation_apk") {
shared_libraries = [ ":libstandalonelibwebviewchromium" ]
native_lib_version_rule = "//build/util:chrome_version_json"
_native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_build_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
command_line_flags_file = "android-webview-command-line"
}

@ -814,19 +814,7 @@ public class LibraryLoader {
throw new ProcessInitException(LoaderErrors.FAILED_TO_REGISTER_JNI);
}
// Check that the version of the library we have loaded matches the version we expect
if (!NativeLibraries.sVersionNumber.equals(LibraryLoaderJni.get().getVersionNumber())) {
Log.e(TAG,
"Expected native library version number \"%s\", "
+ "actual native library version number \"%s\"",
NativeLibraries.sVersionNumber, LibraryLoaderJni.get().getVersionNumber());
throw new ProcessInitException(LoaderErrors.NATIVE_LIBRARY_WRONG_VERSION);
} else {
// Log the version anyway as this is often helpful, but word it differently so it's
// clear that it isn't an error.
Log.i(TAG, "Loaded native library version number \"%s\"",
NativeLibraries.sVersionNumber);
}
Log.i(TAG, "Successfully loaded native library");
UmaRecorderHolder.onLibraryLoaded();
// From now on, keep tracing in sync with native.
@ -915,9 +903,5 @@ public class LibraryLoader {
// Records the number of milliseconds it took to load the libraries in the renderer.
void recordRendererLibraryLoadTime(long libraryLoadTime);
// Get the version of the native library. This is needed so that we can check we
// have the right version before initializing the (rest of the) JNI.
String getVersionNumber();
}
}

@ -131,10 +131,6 @@ void SetVersionNumber(const char* version_number) {
g_library_version_number = strdup(version_number);
}
ScopedJavaLocalRef<jstring> JNI_LibraryLoader_GetVersionNumber(JNIEnv* env) {
return ConvertUTF8ToJavaString(env, g_library_version_number);
}
void InitAtExitManager() {
g_at_exit_manager = new base::AtExitManager();
}

@ -77,12 +77,6 @@ typedef bool LibraryLoadedHook(JNIEnv* env,
BASE_EXPORT void SetLibraryLoadedHook(LibraryLoadedHook* func);
// Pass the version name to the loader. This used to check that the library
// version matches the version expected by Java before completing JNI
// registration.
// Note: argument must remain valid at least until library loading is complete.
BASE_EXPORT void SetVersionNumber(const char* version_number);
// Call on exit to delete the AtExitManager which OnLibraryLoadedOnUIThread
// created.
BASE_EXPORT void LibraryLoaderExitHook();

@ -11,10 +11,36 @@ import os
import sys
import zipfile
from native_libraries_template import NATIVE_LIBRARIES_TEMPLATE
from util import build_utils
_NATIVE_LIBRARIES_TEMPLATE = """\
// This file is autogenerated by
// build/android/gyp/write_native_libraries_java.py
// Please do not change its content.
package org.chromium.build;
public class NativeLibraries {{
public static final int CPU_FAMILY_UNKNOWN = 0;
public static final int CPU_FAMILY_ARM = 1;
public static final int CPU_FAMILY_MIPS = 2;
public static final int CPU_FAMILY_X86 = 3;
// Set to true to enable the use of the Chromium Linker.
public static {MAYBE_FINAL}boolean sUseLinker{USE_LINKER};
public static {MAYBE_FINAL}boolean sUseLibraryInZipFile{USE_LIBRARY_IN_ZIP_FILE};
public static {MAYBE_FINAL}boolean sUseModernLinker{USE_MODERN_LINKER};
// This is the list of native libraries to be loaded (in the correct order)
// by LibraryLoader.java.
public static {MAYBE_FINAL}String[] LIBRARIES = {{{LIBRARIES}}};
public static {MAYBE_FINAL}int sCpuFamily = {CPU_FAMILY};
}}
"""
def _FormatLibraryName(library_name):
filename = os.path.split(library_name)[1]
assert filename.startswith('lib')
@ -40,10 +66,6 @@ def main():
'--use-modern-linker', action='store_true', help='To use ModernLinker.')
parser.add_argument(
'--native-libraries-list', help='File with list of native libraries.')
parser.add_argument(
'--version-number',
default='""',
help='Expected version of main library.')
parser.add_argument(
'--cpu-family',
choices={
@ -88,7 +110,6 @@ def main():
'USE_LIBRARY_IN_ZIP_FILE': bool_str(options.load_library_from_apk),
'USE_MODERN_LINKER': bool_str(options.use_modern_linker),
'LIBRARIES': ','.join(native_libraries_list),
'VERSION_NUMBER': options.version_number,
'CPU_FAMILY': options.cpu_family,
}
with build_utils.AtomicOutput(options.output) as f:
@ -96,7 +117,7 @@ def main():
build_utils.AddToZipHermetic(
zip_file=srcjar_file,
zip_path='org/chromium/build/NativeLibraries.java',
data=NATIVE_LIBRARIES_TEMPLATE.format(**format_dict))
data=_NATIVE_LIBRARIES_TEMPLATE.format(**format_dict))
if options.depfile:
assert options.native_libraries_list

@ -1,7 +1,6 @@
# Generated by running:
# build/print_python_deps.py --root build/android/gyp --output build/android/gyp/write_native_libraries_java.pydeps build/android/gyp/write_native_libraries_java.py
../../gn_helpers.py
native_libraries_template.py
util/__init__.py
util/build_utils.py
write_native_libraries_java.py

@ -724,12 +724,6 @@ if (enable_java_templates) {
"--native-libraries-list",
rebase_path(invoker.native_libraries_list_file, root_build_dir),
]
if (defined(invoker.version_number)) {
args += [
"--version-number",
invoker.version_number,
]
}
if (defined(invoker.main_component_library)) {
args += [
"--main-component-library",
@ -2643,13 +2637,6 @@ if (enable_java_templates) {
if (_generate_native_libraries_java) {
write_native_libraries_java("${_template_name}__native_libraries") {
forward_variables_from(invoker, [ "main_component_library" ])
deps = []
if (defined(invoker.native_lib_version_rule)) {
deps += [ invoker.native_lib_version_rule ]
}
if (defined(invoker.native_lib_version_arg)) {
version_number = invoker.native_lib_version_arg
}
# Do not add a dep on the generated_file target in order to avoid having
# to build the native libraries before this target. The dependency is
@ -2665,13 +2652,6 @@ if (enable_java_templates) {
use_final_fields = true
}
_srcjar_deps += [ ":${_template_name}__native_libraries" ]
} else {
if (defined(invoker.native_lib_version_arg)) {
not_needed(invoker, [ "native_lib_version_arg" ])
}
if (defined(invoker.native_lib_version_rule)) {
not_needed(invoker, [ "native_lib_version_rule" ])
}
}
_loadable_modules = []
@ -3490,8 +3470,6 @@ if (enable_java_templates) {
"main_component_library",
"min_sdk_version",
"native_lib_placeholders",
"native_lib_version_arg",
"native_lib_version_rule",
"never_incremental",
"no_xml_namespaces",
"png_to_webp",
@ -3623,8 +3601,6 @@ if (enable_java_templates) {
"max_sdk_version",
"min_sdk_version",
"native_lib_placeholders",
"native_lib_version_arg",
"native_lib_version_rule",
"no_xml_namespaces",
"package_id",
"package_name",

@ -189,14 +189,6 @@ template("chrome_public_common_apk_or_module_tmpl") {
short_resource_paths = true
if ((defined(shared_libraries) && shared_libraries != []) ||
(defined(secondary_abi_shared_libraries) &&
secondary_abi_shared_libraries != [])) {
_native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
native_lib_version_rule = "//build/util:chrome_version_json"
}
if (!defined(aapt_locale_allowlist)) {
if (target_type == "android_apk") {
# For APKs, do not include the resource strings files from our

@ -123,11 +123,6 @@ template("trichrome_library_apk_tmpl") {
"//third_party/icu:icu_assets",
]
_native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
native_lib_version_rule = "//build/util:chrome_version_json"
# Flag whether additional deps and libs should be included for each ABI.
_include_primary_support = false
_include_secondary_support = false

@ -4,9 +4,7 @@
#include "chrome/app/android/chrome_jni_onload.h"
#include "base/android/library_loader/library_loader_hooks.h"
#include "chrome/app/android/chrome_main_delegate_android.h"
#include "components/version_info/version_info.h"
#include "content/public/app/content_jni_onload.h"
#include "content/public/app/content_main.h"
@ -16,9 +14,6 @@ bool OnJNIOnLoadInit() {
if (!content::android::OnJNIOnLoadInit())
return false;
// Pass the library version number to content so that we can check it from the
// Java side before continuing initialization.
base::android::SetVersionNumber(version_info::GetVersionNumber().c_str());
content::SetContentMainDelegate(new ChromeMainDelegateAndroid());
return true;
}

@ -5,7 +5,6 @@
#include <memory>
#include "base/android/jni_android.h"
#include "base/android/library_loader/library_loader_hooks.h"
#include "chrome/app/android/chrome_jni_onload.h"
#include "chrome/test/base/chrome_test_launcher.h"
#include "content/public/app/content_jni_onload.h"
@ -22,10 +21,6 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
if (!content::android::OnJNIOnLoadInit())
return -1;
// Tests do not have a version so they expect the version number to be "" in
// java.
base::android::SetVersionNumber("");
// This needs to be done before base::TestSuite::Initialize() is called,
// as it also tries to set MessagePumpForUIFactory.
base::MessagePump::OverrideMessagePumpForUIFactory(

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/library_loader/library_loader_hooks.h"
#include "components/version_info/version_info.h"
#include "components/version_info/version_info_values.h"
#include "content/public/app/content_jni_onload.h"
#include "content/public/app/content_main.h"
#include "weblayer/app/content_main_delegate_impl.h"
@ -23,8 +20,6 @@ bool OnJNIOnLoadInit() {
if (!content::android::OnJNIOnLoadInit())
return false;
base::android::SetVersionNumber(version_info::GetVersionNumber().c_str());
weblayer::MainParams params;
params.delegate = new weblayer::MainDelegateImpl;

@ -263,11 +263,6 @@ android_apk("weblayer_support_apk") {
product_config_java_packages = [ weblayer_product_config_java_package ]
native_lib_version_rule = "//build/util:chrome_version_json"
_native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_build_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
shared_libraries = [ "//weblayer:libweblayer_test" ]
}