Commit d63380b8 authored by Christopher Grant's avatar Christopher Grant Committed by Commit Bot

Android: Clean up feature module JNI registration

DFMs use explicit JNI registration for both Chrome and Monochrome, but
the feature shouldn't care which it's in. Traditionally, JNI registration has
been done based on APK targets, but we can also point generation at an Android
library.

Do that here, and also, tweak the JNI generation template to allow
exclusion of transitive deps. For a DFM, this means we can generate JNI
only for a module's entrypoints, without pulling in methods from the
base module or other unneeded deps. This seems cleaner, and also allows
this change to work in component builds.

Bug: None
Change-Id: I3f3f457815a7e2f06f575f72476cc4c877741c7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1992694
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729869}
parent 1c66f4c1
...@@ -313,6 +313,9 @@ if (enable_java_templates) { ...@@ -313,6 +313,9 @@ if (enable_java_templates) {
# enable_native_mocks: Allow native calls using # enable_native_mocks: Allow native calls using
# org.chromium.base.annotations.NativeMethods to be mocked in tests # org.chromium.base.annotations.NativeMethods to be mocked in tests
# (optional). # (optional).
# no_transitive_deps: Generate registration for only the Java source in the
# specified target(s). This is useful for generating registration for
# feature modules, without including base module dependencies.
# #
# Example # Example
# generate_jni_registration("chrome_jni_registration") { # generate_jni_registration("chrome_jni_registration") {
...@@ -349,10 +352,15 @@ if (enable_java_templates) { ...@@ -349,10 +352,15 @@ if (enable_java_templates) {
".build_config" ".build_config"
_rebased_build_config = rebase_path(_build_config, root_build_dir) _rebased_build_config = rebase_path(_build_config, root_build_dir)
inputs += [ _build_config ] inputs += [ _build_config ]
args += [
# This is a list of .sources files. if (defined(invoker.no_transitive_deps) && invoker.no_transitive_deps) {
"--sources-files=@FileArg($_rebased_build_config:deps_info:jni:all_source)", args += [ "--sources-files=@FileArg($_rebased_build_config:deps_info:java_sources_file)" ]
] } else {
args += [
# This is a list of .sources files.
"--sources-files=@FileArg($_rebased_build_config:deps_info:jni:all_source)",
]
}
} }
if (use_hashed_jni_names) { if (use_hashed_jni_names) {
......
...@@ -43,17 +43,9 @@ component("stack_unwinder") { ...@@ -43,17 +43,9 @@ component("stack_unwinder") {
} }
} }
# TODO(https://crbug.com/1008109): Adapt JNI registration to point at a Java
# target, instead of an APK/module target. This JNI registration target
# points at ChromeModern's module, but it's used by Monochrome as well, since
# both variants do explicit JNI registration in DFMs (for consistency).
#
# Alternatively, move to lazy JNI init for DFMs in Monochrome, by conditionally
# including a registration stub, as Chrome's base library does. That requires
# two sets of registration targets, so that the feature module template can
# selectively pull in the real version or a stub.
generate_jni_registration("jni_registration") { generate_jni_registration("jni_registration") {
targets = [ "//chrome/android:chrome_modern_public_bundle__stack_unwinder_bundle_module" ] targets = [ "//chrome/android/features/stack_unwinder/internal:java" ]
header_output = "$target_gen_dir/jni_registration.h" header_output = "$target_gen_dir/jni_registration.h"
namespace = "stack_unwinder" namespace = "stack_unwinder"
no_transitive_deps = true
} }
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/android/jni_generator/jni_generator_helper.h"
#include "base/android/jni_utils.h" #include "base/android/jni_utils.h"
#include "chrome/android/modules/stack_unwinder/internal/jni_registration.h" #include "chrome/android/modules/stack_unwinder/internal/jni_registration.h"
extern "C" { extern "C" {
// This JNI registration method is found and called by module framework code. // This JNI registration method is found and called by module framework code.
__attribute__((visibility("default"))) bool JNI_OnLoad_stack_unwinder( JNI_GENERATOR_EXPORT bool JNI_OnLoad_stack_unwinder(JNIEnv* env) {
JNIEnv* env) {
if (!base::android::IsSelectiveJniRegistrationEnabled(env) && if (!base::android::IsSelectiveJniRegistrationEnabled(env) &&
!stack_unwinder::RegisterNonMainDexNatives(env)) { !stack_unwinder::RegisterNonMainDexNatives(env)) {
return false; return false;
......
...@@ -43,19 +43,9 @@ component("test_dummy") { ...@@ -43,19 +43,9 @@ component("test_dummy") {
} }
} }
# TODO(https://crbug.com/1008109): Adapt JNI registration to point at a Java
# target, instead of an APK/module target. This JNI registration target
# points at ChromeModern's module, but it's used by Monochrome as well, since
# both variants do explicit JNI registration in DFMs (for consistency).
#
# Alternatively, move to lazy JNI init for DFMs in Monochrome, by conditionally
# including a registration stub, as Chrome's base library does. That requires
# two sets of registration targets, so that the feature module template can
# selectively pull in the real version or a stub.
generate_jni_registration("jni_registration") { generate_jni_registration("jni_registration") {
targets = [ no_transitive_deps = true
"//chrome/android:chrome_modern_public_bundle__test_dummy_bundle_module", targets = [ "//chrome/android/features/test_dummy/internal:java" ]
]
header_output = "$target_gen_dir/jni_registration.h" header_output = "$target_gen_dir/jni_registration.h"
namespace = "test_dummy" namespace = "test_dummy"
} }
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/android/jni_generator/jni_generator_helper.h"
#include "base/android/jni_utils.h" #include "base/android/jni_utils.h"
#include "chrome/android/modules/test_dummy/internal/jni_registration.h" #include "chrome/android/modules/test_dummy/internal/jni_registration.h"
extern "C" { extern "C" {
// This JNI registration method is found and called by module framework code. // This JNI registration method is found and called by module framework code.
// Ideally, this code would be generated by the build. JNI_GENERATOR_EXPORT bool JNI_OnLoad_test_dummy(JNIEnv* env) {
__attribute__((visibility("default"))) bool JNI_OnLoad_test_dummy(JNIEnv* env) {
if (!base::android::IsSelectiveJniRegistrationEnabled(env) && if (!base::android::IsSelectiveJniRegistrationEnabled(env) &&
!test_dummy::RegisterNonMainDexNatives(env)) { !test_dummy::RegisterNonMainDexNatives(env)) {
return false; return false;
......
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