From 126fae80494cacc55a8e5c4e46769c04a977a662 Mon Sep 17 00:00:00 2001 From: Sam Maier Date: Fri, 31 Mar 2023 16:16:02 +0000 Subject: [PATCH] Removing concept of MainDex/non-MainDex native With automatic registration being the default now, there is no need to differentiate MainDex/non-MainDex as automatic registration is lazy anyways. Low-Coverage-Reason: Just a deletion of code Bug: 1371542 Change-Id: I85cc1f72e71eb4b2ed36a06bd8b0a25a484ce3fe Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4385433 Owners-Override: Andrew Grieve Reviewed-by: Andrew Grieve Commit-Queue: Sam Maier Cr-Commit-Position: refs/heads/main@{#1124766} --- .../java/src/org/chromium/base/JNIUtils.java | 21 --- .../base/NativeLibraryLoadedStatus.java | 12 +- .../base/library_loader/LibraryLoader.java | 125 ++++------------- .../base/library_loader/EarlyNativeTest.java | 87 +----------- base/android/jni_generator/README.md | 8 +- ...mpleForAnnotationProcessorManualJni.golden | 9 +- ...tivesBothInnerAndOuterRegistrations.golden | 11 +- .../golden/testNativesRegistrations.golden | 11 +- ...stProxyMultiplexNativesRegistration.golden | 19 +-- .../golden/testProxyNativesMainDex.golden | 84 ----------- ...estProxyNativesMainDexAndNonMainDex.golden | 124 ---------------- .../testProxyNativesRegistrations.golden | 9 +- .../chromium/jni_generator/JniProcessor.java | 17 +-- .../jni_generator/jni_generator_tests.py | 132 +----------------- .../jni_registration_generator.py | 63 ++------- .../jni_generator/sample_entry_point.cc | 8 +- base/android/jni_generator/sample_for_tests.h | 8 +- base/android/jni_utils.cc | 4 - base/android/jni_utils.h | 3 - .../library_loader/library_loader_hooks.cc | 13 -- .../library_loader/library_loader_hooks.h | 5 - .../start_surface/InstantStartTest.java | 4 +- .../start_surface/StartSurfaceTestUtils.java | 3 +- .../chrome/browser/ChromeApplicationImpl.java | 2 +- .../internal/entrypoints.cc | 6 +- .../stack_unwinder/internal/entrypoints.cc | 6 +- .../test_dummy/internal/entrypoints.cc | 6 +- chrome/browser/android/chrome_entry_point.cc | 11 +- .../android/chrome_entry_point_for_test.cc | 11 +- chrome/browser/android/vr/register_gvr_jni.cc | 3 +- .../android/cast_browser_module_entrypoint.cc | 6 +- chromecast/app/android/cast_jni_loader.cc | 2 +- .../cronet/android/cronet_library_loader.cc | 2 +- .../ContentChildProcessServiceDelegate.java | 3 - .../content_public/app/ZygotePreload.java | 2 - .../TestChildProcessService.java | 4 - docs/android_dynamic_feature_modules.md | 6 +- .../display_synchronizer_jni.h | 3 - third_party/gvr-android-sdk/gvr_api_jni.h | 3 - .../gvr-android-sdk/native_callbacks_jni.h | 3 - .../java/src/org/chromium/url/GURL.java | 5 +- weblayer/app/entry_point.cc | 3 +- .../web_view_compatibility_helper_impl.cc | 12 +- 43 files changed, 101 insertions(+), 778 deletions(-) delete mode 100644 base/android/jni_generator/golden/testProxyNativesMainDex.golden delete mode 100644 base/android/jni_generator/golden/testProxyNativesMainDexAndNonMainDex.golden diff --git a/base/android/java/src/org/chromium/base/JNIUtils.java b/base/android/java/src/org/chromium/base/JNIUtils.java index 810c7a6d4f06fb..4497e0dee75525 100644 --- a/base/android/java/src/org/chromium/base/JNIUtils.java +++ b/base/android/java/src/org/chromium/base/JNIUtils.java @@ -15,7 +15,6 @@ @MainDex public class JNIUtils { private static final String TAG = "JNIUtils"; - private static Boolean sSelectiveJniRegistrationEnabled; private static ClassLoader sJniClassLoader; /** @@ -51,26 +50,6 @@ public static void setClassLoader(ClassLoader classLoader) { sJniClassLoader = classLoader; } - /** - * @return whether or not the current process supports selective JNI registration. - */ - @CalledByNative - public static boolean isSelectiveJniRegistrationEnabled() { - if (sSelectiveJniRegistrationEnabled == null) { - sSelectiveJniRegistrationEnabled = false; - } - return sSelectiveJniRegistrationEnabled; - } - - /** - * Allow this process to selectively perform JNI registration. This must be called before - * loading native libraries or it will have no effect. - */ - public static void enableSelectiveJniRegistration() { - assert sSelectiveJniRegistrationEnabled == null; - sSelectiveJniRegistrationEnabled = true; - } - /** * Helper to convert from java maps to two arrays for JNI. */ diff --git a/base/android/java/src/org/chromium/base/NativeLibraryLoadedStatus.java b/base/android/java/src/org/chromium/base/NativeLibraryLoadedStatus.java index 5b31cf45bfb6df..e876c3c1d015c0 100644 --- a/base/android/java/src/org/chromium/base/NativeLibraryLoadedStatus.java +++ b/base/android/java/src/org/chromium/base/NativeLibraryLoadedStatus.java @@ -14,24 +14,20 @@ public class NativeLibraryLoadedStatus { * Interface for querying native method availability. */ public interface NativeLibraryLoadedStatusProvider { - boolean areMainDexNativeMethodsReady(); boolean areNativeMethodsReady(); } private static NativeLibraryLoadedStatusProvider sProvider; - public static void checkLoaded(boolean isMainDex) { + public static void checkLoaded() { // Necessary to make sure all of these calls are stripped in release builds. if (!BuildConfig.ENABLE_ASSERTS) return; if (sProvider == null) return; - boolean nativeMethodsReady = isMainDex ? sProvider.areMainDexNativeMethodsReady() - : sProvider.areNativeMethodsReady(); - if (!nativeMethodsReady) { - throw new JniException(String.format( - "Native method called before the native library was ready (isMainDex=%b).", - isMainDex)); + if (!sProvider.areNativeMethodsReady()) { + throw new JniException( + String.format("Native method called before the native library was ready.")); } } diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java index 0ddd4ff5465374..9e780790097bf9 100644 --- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java +++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java @@ -18,7 +18,6 @@ import org.chromium.base.BaseSwitches; import org.chromium.base.CommandLine; import org.chromium.base.ContextUtils; -import org.chromium.base.JNIUtils; import org.chromium.base.Log; import org.chromium.base.NativeLibraryLoadedStatus; import org.chromium.base.NativeLibraryLoadedStatus.NativeLibraryLoadedStatusProvider; @@ -82,7 +81,7 @@ public class LibraryLoader { private static boolean sBrowserStartupBlockedForTesting; - // Helps mInitializedForTesting and mLoadStateForTesting to be removed by R8. + // Helps mInitializedForTesting and mLoadedForTesting to be removed by R8. private static boolean sEnableStateForTesting; // One-way switch becomes true when the libraries are initialized (by calling @@ -96,20 +95,12 @@ public class LibraryLoader { // synchronization. private boolean mFallbackToSystemLinker; - // State that only transitions one-way from 0->1->2. Volatile for the same reasons as - // mInitialized. - @IntDef({LoadState.NOT_LOADED, LoadState.MAIN_DEX_LOADED, LoadState.LOADED}) - @Retention(RetentionPolicy.SOURCE) - private @interface LoadState { - int NOT_LOADED = 0; - int MAIN_DEX_LOADED = 1; - int LOADED = 2; - } - private volatile @LoadState int mLoadState; + // State that only transitions from false->true. Volatile for the same reasons as mInitialized. + private volatile boolean mLoaded; - // Tracks mLoadState, but can be reset to NOT_LOADED between tests to ensure that each test that + // Tracks mLoaded, but can be reset to NOT_LOADED between tests to ensure that each test that // requires native explicitly loads it. - private @LoadState int mLoadStateForTesting; + private boolean mLoadedForTesting; // Tracks mInitialized, but can be reset to false between tests to ensure that each test that // requires native explicitly loads it. @@ -123,10 +114,6 @@ public class LibraryLoader { // Avoids locking: should be initialized very early. private @LibraryProcessType int mLibraryProcessType; - // Makes sure non-Main Dex initialization happens only once. Does not use any class members - // except the volatile |mLoadState|. - private final Object mNonMainDexLock = new Object(); - // Mediates all communication between Linker instances in different processes. private final MultiProcessMediator mMediator = new MultiProcessMediator(); @@ -145,7 +132,7 @@ public class LibraryLoader { @GuardedBy("mLock") private boolean mLibraryPreloaderCalled; - // Similar to |mLoadState| but is limited case of being loaded in app zygote. + // Similar to |mLoaded| but is limited case of being loaded in app zygote. // This is exposed to clients. @GuardedBy("mLock") private boolean mLoadedByZygote; @@ -421,11 +408,6 @@ protected LibraryLoader() { } if (BuildConfig.ENABLE_ASSERTS) { NativeLibraryLoadedStatus.setProvider(new NativeLibraryLoadedStatusProvider() { - @Override - public boolean areMainDexNativeMethodsReady() { - return isMainDexLoaded(); - } - @Override public boolean areNativeMethodsReady() { return isLoaded(); @@ -463,7 +445,7 @@ public void setLibraryProcessType(@LibraryProcessType int type) { public void setNativeLibraryPreloader(NativeLibraryPreloader loader) { synchronized (mLock) { assert mLibraryPreloader == null; - assert mLoadState == LoadState.NOT_LOADED; + assert !mLoaded; mLibraryPreloader = loader; } } @@ -529,25 +511,9 @@ public boolean isLoadedByZygote() { */ public void ensureInitialized() { if (isInitialized()) return; - ensureMainDexInitialized(); - loadNonMainDex(); - } - - /** - * This method blocks until the native library is initialized, and the Main Dex is loaded - * (MainDex JNI is registered). - * - * You should use this if you would like to use isolated parts of the native library that don't - * depend on content initialization, and only use MainDex classes with JNI. - * - * However, you should be careful not to call this too early in startup on the UI thread, or you - * may significantly increase the time to first draw. - */ - public void ensureMainDexInitialized() { synchronized (mLock) { if (DEBUG) logLinkerUsed(); - loadMainDexAlreadyLocked( - ContextUtils.getApplicationContext().getApplicationInfo(), false); + loadAlreadyLocked(ContextUtils.getApplicationContext().getApplicationInfo(), false); initializeAlreadyLocked(); } } @@ -594,13 +560,7 @@ private void preloadAlreadyLocked(String packageName, boolean inZygote) { @Deprecated @VisibleForTesting public boolean isLoaded() { - return mLoadState == LoadState.LOADED - && (!sEnableStateForTesting || mLoadStateForTesting == LoadState.LOADED); - } - - private boolean isMainDexLoaded() { - return mLoadState >= LoadState.MAIN_DEX_LOADED - && (!sEnableStateForTesting || mLoadStateForTesting >= LoadState.MAIN_DEX_LOADED); + return mLoaded && (!sEnableStateForTesting || mLoadedForTesting); } /** @@ -627,7 +587,7 @@ public void loadNow() { * Causes LibraryLoader to pretend that native libraries have not yet been initialized. */ public void resetForTesting() { - mLoadStateForTesting = LoadState.NOT_LOADED; + mLoadedForTesting = false; mInitializedForTesting = false; sEnableStateForTesting = true; } @@ -641,20 +601,17 @@ public void resetForTesting() { */ public void loadNowOverrideApplicationContext(Context appContext) { synchronized (mLock) { - if (mLoadState != LoadState.NOT_LOADED - && appContext != ContextUtils.getApplicationContext()) { + if (mLoaded && appContext != ContextUtils.getApplicationContext()) { throw new IllegalStateException("Attempt to load again from alternate context."); } - loadMainDexAlreadyLocked(appContext.getApplicationInfo(), /* inZygote= */ false); + loadAlreadyLocked(appContext.getApplicationInfo(), /* inZygote= */ false); } - loadNonMainDex(); } public void loadNowInZygote(ApplicationInfo appInfo) { synchronized (mLock) { - assert mLoadState == LoadState.NOT_LOADED; - loadMainDexAlreadyLocked(appInfo, /* inZygote= */ true); - loadNonMainDex(); + assert !mLoaded; + loadAlreadyLocked(appInfo, /* inZygote= */ true); mLoadedByZygote = true; } } @@ -759,14 +716,14 @@ private void loadWithSystemLinkerAlreadyLocked(ApplicationInfo appInfo, boolean // triggering JNI_OnLoad in native code. @GuardedBy("mLock") @VisibleForTesting - protected void loadMainDexAlreadyLocked(ApplicationInfo appInfo, boolean inZygote) { - if (mLoadState >= LoadState.MAIN_DEX_LOADED) { - if (sEnableStateForTesting && mLoadStateForTesting == LoadState.NOT_LOADED) { - mLoadStateForTesting = LoadState.MAIN_DEX_LOADED; + protected void loadAlreadyLocked(ApplicationInfo appInfo, boolean inZygote) { + if (mLoaded) { + if (sEnableStateForTesting && !mLoadedForTesting) { + mLoadedForTesting = true; } return; } - try (TraceEvent te = TraceEvent.scoped("LibraryLoader.loadMainDexAlreadyLocked")) { + try (TraceEvent te = TraceEvent.scoped("LibraryLoader.loadAlreadyLocked")) { assert !mInitialized; assert mLibraryProcessType != LibraryProcessType.PROCESS_UNINITIALIZED || inZygote; @@ -788,9 +745,9 @@ protected void loadMainDexAlreadyLocked(ApplicationInfo appInfo, boolean inZygot long loadTimeMs = uptimeTimer.getElapsedMillis(); if (DEBUG) Log.i(TAG, "Time to load native libraries: %d ms", loadTimeMs); - mLoadState = LoadState.MAIN_DEX_LOADED; + mLoaded = true; if (sEnableStateForTesting) { - mLoadStateForTesting = LoadState.MAIN_DEX_LOADED; + mLoadedForTesting = true; } getMediator().recordLoadTimeHistogram(loadTimeMs); @@ -800,30 +757,6 @@ protected void loadMainDexAlreadyLocked(ApplicationInfo appInfo, boolean inZygot } } - @VisibleForTesting - protected void loadNonMainDex() { - if (mLoadState == LoadState.LOADED) { - if (sEnableStateForTesting) { - mLoadStateForTesting = LoadState.LOADED; - } - return; - } - synchronized (mNonMainDexLock) { - assert mLoadState != LoadState.NOT_LOADED; - if (mLoadState == LoadState.LOADED) return; - try (TraceEvent te = TraceEvent.scoped("LibraryLoader.loadNonMainDex")) { - if (!JNIUtils.isSelectiveJniRegistrationEnabled()) { - // On M+ the native symbols are exported, and registering natives seems fast. - LibraryLoaderJni.get().registerNonMainDexJni(); - } - mLoadState = LoadState.LOADED; - if (sEnableStateForTesting) { - mLoadStateForTesting = LoadState.LOADED; - } - } - } - } - // The WebView requires the Command Line to be switched over before // initialization is done. This is okay in the WebView's case since the // JNI is already loaded by this point. @@ -838,7 +771,7 @@ public void switchCommandLineForWebView() { // switch the Java CommandLine will delegate all calls the native CommandLine). @GuardedBy("mLock") private void ensureCommandLineSwitchedAlreadyLocked() { - assert isMainDexLoaded(); + assert isLoaded(); if (mCommandLineSwitched) { return; } @@ -901,10 +834,8 @@ private void initializeAlreadyLocked() { // From now on, keep tracing in sync with native. TraceEvent.onNativeTracingReady(); - // From this point on, native code is ready to use, but non-MainDex JNI may not yet have - // been registered. Check isInitialized() to be sure that initialization is fully complete. - // Note that this flag can be accessed asynchronously, so any initialization - // must be performed before. + // From this point on, native code is ready to use. Note that this flag can be accessed + // asynchronously, so any initialization must be performed before. mInitialized = true; if (sEnableStateForTesting) { mInitializedForTesting = true; @@ -957,11 +888,11 @@ public static void setEnvForNative() { */ protected static void setLibrariesLoadedForNativeTests() { LibraryLoader self = getInstance(); - self.mLoadState = LoadState.LOADED; + self.mLoaded = true; self.mInitialized = true; if (sEnableStateForTesting) { self.mInitializedForTesting = true; - self.mLoadStateForTesting = LoadState.LOADED; + self.mLoadedForTesting = true; } } @@ -979,9 +910,5 @@ interface Natives { // Performs auxiliary initialization useful right after the native library load. Returns // true on success and false on failure. boolean libraryLoaded(@LibraryProcessType int processType); - - // Registers JNI for non-main processes. For details see android_native_libraries.md, - // android_dynamic_feature_modules.md and jni_generator/README.md - void registerNonMainDexJni(); } } diff --git a/base/android/javatests/src/org/chromium/base/library_loader/EarlyNativeTest.java b/base/android/javatests/src/org/chromium/base/library_loader/EarlyNativeTest.java index f1175da2fa7c78..2126301779f8aa 100644 --- a/base/android/javatests/src/org/chromium/base/library_loader/EarlyNativeTest.java +++ b/base/android/javatests/src/org/chromium/base/library_loader/EarlyNativeTest.java @@ -4,8 +4,6 @@ package org.chromium.base.library_loader; -import android.content.pm.ApplicationInfo; - import androidx.test.filters.SmallTest; import org.junit.After; @@ -21,12 +19,9 @@ import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.util.Batch; import org.chromium.base.test.util.CallbackHelper; -import org.chromium.base.test.util.RequiresRestart; import org.chromium.build.BuildConfig; import org.chromium.build.annotations.MainDex; -import java.util.concurrent.TimeoutException; - /** * Tests for early JNI initialization. */ @@ -36,15 +31,15 @@ @Batch(Batch.UNIT_TESTS) public class EarlyNativeTest { private boolean mWasInitialized; - private CallbackHelper mLoadMainDexStarted; - private CallbackHelper mEnsureMainDexInitializedFinished; + private CallbackHelper mLoadStarted; + private CallbackHelper mEnsureInitializedFinished; @Before public void setUp() { mWasInitialized = LibraryLoader.getInstance().isInitialized(); LibraryLoader.getInstance().resetForTesting(); - mLoadMainDexStarted = new CallbackHelper(); - mEnsureMainDexInitializedFinished = new CallbackHelper(); + mLoadStarted = new CallbackHelper(); + mEnsureInitializedFinished = new CallbackHelper(); } @After @@ -55,25 +50,6 @@ public void tearDown() { } } - private class TestLibraryLoader extends LibraryLoader { - @Override - @SuppressWarnings("GuardedBy") // ErrorProne: should be guarded by 'mLock' - protected void loadMainDexAlreadyLocked(ApplicationInfo appInfo, boolean inZygote) { - mLoadMainDexStarted.notifyCalled(); - super.loadMainDexAlreadyLocked(appInfo, inZygote); - } - - @Override - protected void loadNonMainDex() { - try { - mEnsureMainDexInitializedFinished.waitForCallback(0); - } catch (TimeoutException e) { - throw new RuntimeException(e); - } - super.loadNonMainDex(); - } - } - @NativeMethods interface Natives { boolean isCommandLineInitialized(); @@ -82,12 +58,7 @@ interface Natives { @Test @SmallTest - public void testEnsureMainDexInitialized() { - LibraryLoader.getInstance().ensureMainDexInitialized(); - // Some checks to ensure initialization has taken place. - Assert.assertTrue(EarlyNativeTestJni.get().isCommandLineInitialized()); - Assert.assertFalse(EarlyNativeTestJni.get().isProcessNameEmpty()); - + public void testEnsureInitialized() { // Make sure the Native library isn't considered ready for general use. Assert.assertFalse(LibraryLoader.getInstance().isInitialized()); @@ -101,64 +72,16 @@ public void testEnsureMainDexInitialized() { Assert.assertTrue(LibraryLoader.getInstance().isInitialized()); } - private void doTestFullInitializationDoesntBlockMainDexInitialization(final boolean initialize) - throws Exception { - final TestLibraryLoader loader = new TestLibraryLoader(); - loader.setLibraryProcessType(LibraryProcessType.PROCESS_BROWSER); - final Thread t1 = new Thread(() -> { - if (initialize) { - loader.ensureInitialized(); - } else { - loader.loadNow(); - } - }); - t1.start(); - mLoadMainDexStarted.waitForCallback(0); - final Thread t2 = new Thread(() -> { - loader.ensureMainDexInitialized(); - Assert.assertFalse(loader.isInitialized()); - mEnsureMainDexInitializedFinished.notifyCalled(); - }); - t2.start(); - t2.join(); - t1.join(); - Assert.assertTrue(loader.isInitialized()); - } - - @Test - @SmallTest - @RequiresRestart("Uses custom LibraryLoader") - public void testFullInitializationDoesntBlockMainDexInitialization() throws Exception { - doTestFullInitializationDoesntBlockMainDexInitialization(true); - } - - @Test - @SmallTest - @RequiresRestart("Uses custom LibraryLoader") - public void testLoadDoesntBlockMainDexInitialization() throws Exception { - doTestFullInitializationDoesntBlockMainDexInitialization(false); - } - @Test @SmallTest public void testNativeMethodsReadyAfterLibraryInitialized() { // Test is a no-op if DCHECK isn't on. if (!BuildConfig.ENABLE_ASSERTS) return; - Assert.assertFalse( - NativeLibraryLoadedStatus.getProviderForTesting().areMainDexNativeMethodsReady()); - Assert.assertFalse( - NativeLibraryLoadedStatus.getProviderForTesting().areNativeMethodsReady()); - - LibraryLoader.getInstance().ensureMainDexInitialized(); - Assert.assertTrue( - NativeLibraryLoadedStatus.getProviderForTesting().areMainDexNativeMethodsReady()); Assert.assertFalse( NativeLibraryLoadedStatus.getProviderForTesting().areNativeMethodsReady()); LibraryLoader.getInstance().ensureInitialized(); - Assert.assertTrue( - NativeLibraryLoadedStatus.getProviderForTesting().areMainDexNativeMethodsReady()); Assert.assertTrue( NativeLibraryLoadedStatus.getProviderForTesting().areNativeMethodsReady()); } diff --git a/base/android/jni_generator/README.md b/base/android/jni_generator/README.md index f202dd1b540855..3d4321b7c4f2aa 100644 --- a/base/android/jni_generator/README.md +++ b/base/android/jni_generator/README.md @@ -28,11 +28,9 @@ resolved by the runtime (via `dlsym()`). There are a number of notable exceptions to this. See usage of `jni_registration_generator.py` in the codebase. -The `jni_registration_generator.py` exposes two registration methods: -* `RegisterNonMainDexNatives` - Registers native functions needed by multiple - process types (e.g. Rendereres, GPU process). -* `RegisterMainDexNatives` - Registers native functions needed only by the - browser process. +The `jni_registration_generator.py` exposes a registration function when using +manual registation: +* `RegisterNatives` - Registers all native functions. ### Exposing Java Methods diff --git a/base/android/jni_generator/golden/SampleForAnnotationProcessorManualJni.golden b/base/android/jni_generator/golden/SampleForAnnotationProcessorManualJni.golden index a92393027967c2..73d6eeb782c101 100644 --- a/base/android/jni_generator/golden/SampleForAnnotationProcessorManualJni.golden +++ b/base/android/jni_generator/golden/SampleForAnnotationProcessorManualJni.golden @@ -226,16 +226,11 @@ JNI_REGISTRATION_EXPORT bool RegisterNative_org_chromium_base_natives_GEN_1JNI(J } // namespace -// Step 4: Main dex and non-main dex registration functions. +// Step 4: Registration function. namespace None { -bool RegisterMainDexNatives(JNIEnv* env) { - - return true; -} - -bool RegisterNonMainDexNatives(JNIEnv* env) { +bool RegisterNatives(JNIEnv* env) { // Register natives in a proxy. if (!RegisterNative_org_chromium_base_natives_GEN_1JNI(env)) { return false; diff --git a/base/android/jni_generator/golden/testInnerClassNativesBothInnerAndOuterRegistrations.golden b/base/android/jni_generator/golden/testInnerClassNativesBothInnerAndOuterRegistrations.golden index 547f209256acc0..e83121222cf7c5 100644 --- a/base/android/jni_generator/golden/testInnerClassNativesBothInnerAndOuterRegistrations.golden +++ b/base/android/jni_generator/golden/testInnerClassNativesBothInnerAndOuterRegistrations.golden @@ -94,18 +94,11 @@ JNI_REGISTRATION_EXPORT bool RegisterNative_org_chromium_TestJni(JNIEnv* env) { } -// Step 4: Main dex and non-main dex registration functions. +// Step 4: Registration function. namespace test { -bool RegisterMainDexNatives(JNIEnv* env) { - if (!RegisterNative_org_chromium_TestJni(env)) - return false; - - return true; -} - -bool RegisterNonMainDexNatives(JNIEnv* env) { +bool RegisterNatives(JNIEnv* env) { return true; } diff --git a/base/android/jni_generator/golden/testNativesRegistrations.golden b/base/android/jni_generator/golden/testNativesRegistrations.golden index 442c47df3ea6c8..de98b51f1151da 100644 --- a/base/android/jni_generator/golden/testNativesRegistrations.golden +++ b/base/android/jni_generator/golden/testNativesRegistrations.golden @@ -160,18 +160,11 @@ JNI_REGISTRATION_EXPORT bool RegisterNative_org_chromium_TestJni(JNIEnv* env) { } -// Step 4: Main dex and non-main dex registration functions. +// Step 4: Registration function. namespace test { -bool RegisterMainDexNatives(JNIEnv* env) { - if (!RegisterNative_org_chromium_TestJni(env)) - return false; - - return true; -} - -bool RegisterNonMainDexNatives(JNIEnv* env) { +bool RegisterNatives(JNIEnv* env) { return true; } diff --git a/base/android/jni_generator/golden/testProxyMultiplexNativesRegistration.golden b/base/android/jni_generator/golden/testProxyMultiplexNativesRegistration.golden index 473c68887e77a6..ac7d5fbc190a6d 100644 --- a/base/android/jni_generator/golden/testProxyMultiplexNativesRegistration.golden +++ b/base/android/jni_generator/golden/testProxyMultiplexNativesRegistration.golden @@ -360,7 +360,7 @@ JNI_GENERATOR_EXPORT void Java_J_N_resolve_1for_1void_1LLATTARRAOOAOOA( // Step 3: Method declarations. -static const JNINativeMethod kMethods_J_NMAIN_DEX[] = { +static const JNINativeMethod kMethods_J_N[] = { { "resolve_for_boolean", "(J)Z", reinterpret_cast(Java_J_N_resolve_1for_1boolean) }, { "resolve_for_class", "(J)Ljava/lang/Class;", reinterpret_cast(Java_J_N_resolve_1for_1class) }, @@ -396,14 +396,14 @@ static const JNINativeMethod kMethods_J_NMAIN_DEX[] = { namespace { -JNI_REGISTRATION_EXPORT bool RegisterNative_J_NMAIN_DEX(JNIEnv* env) { - const int number_of_methods = std::size(kMethods_J_NMAIN_DEX); +JNI_REGISTRATION_EXPORT bool RegisterNative_J_N(JNIEnv* env) { + const int number_of_methods = std::size(kMethods_J_N); base::android::ScopedJavaLocalRef native_clazz = base::android::GetClass(env, "J/N"); if (env->RegisterNatives( native_clazz.obj(), - kMethods_J_NMAIN_DEX, + kMethods_J_N, number_of_methods) < 0) { jni_generator::HandleRegistrationError(env, native_clazz.obj(), __FILE__); @@ -416,13 +416,13 @@ JNI_REGISTRATION_EXPORT bool RegisterNative_J_NMAIN_DEX(JNIEnv* env) { } // namespace -// Step 4: Main dex and non-main dex registration functions. +// Step 4: Registration function. namespace test { -bool RegisterMainDexNatives(JNIEnv* env) { +bool RegisterNatives(JNIEnv* env) { // Register natives in a proxy. - if (!RegisterNative_J_NMAIN_DEX(env)) { + if (!RegisterNative_J_N(env)) { return false; } @@ -430,11 +430,6 @@ bool RegisterMainDexNatives(JNIEnv* env) { return true; } -bool RegisterNonMainDexNatives(JNIEnv* env) { - - return true; -} - } // namespace test #endif // HEADER_GUARD diff --git a/base/android/jni_generator/golden/testProxyNativesMainDex.golden b/base/android/jni_generator/golden/testProxyNativesMainDex.golden deleted file mode 100644 index fefa53b58632e8..00000000000000 --- a/base/android/jni_generator/golden/testProxyNativesMainDex.golden +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2017 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - - -// This file is autogenerated by -// base/android/jni_generator/jni_registration_generator.py -// Please do not change its content. - -#ifndef HEADER_GUARD -#define HEADER_GUARD - -#include - -#include - -#include "base/android/jni_generator/jni_generator_helper.h" -#include "base/android/jni_int_wrapper.h" - - -// Step 1: Forward declarations (classes). - - -// Step 2: Forward declarations (methods). - -JNI_GENERATOR_EXPORT void Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Foo_1thisismaindex( - JNIEnv* env, - jclass jcaller); - - -// Step 3: Method declarations. - - -static const JNINativeMethod kMethods_org_chromium_base_natives_GEN_1JNIMAIN_DEX[] = { - { "test_foo_Foo_thisismaindex", "()V", - reinterpret_cast(Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Foo_1thisismaindex) - }, - -}; - -namespace { - -JNI_REGISTRATION_EXPORT bool RegisterNative_org_chromium_base_natives_GEN_1JNIMAIN_DEX(JNIEnv* env) { - const int number_of_methods = std::size(kMethods_org_chromium_base_natives_GEN_1JNIMAIN_DEX); - - base::android::ScopedJavaLocalRef native_clazz = - base::android::GetClass(env, "org/chromium/base/natives/GEN_JNI"); - if (env->RegisterNatives( - native_clazz.obj(), - kMethods_org_chromium_base_natives_GEN_1JNIMAIN_DEX, - number_of_methods) < 0) { - - jni_generator::HandleRegistrationError(env, native_clazz.obj(), __FILE__); - return false; - } - - return true; -} - -} // namespace - - -// Step 4: Main dex and non-main dex registration functions. - -namespace test { - -bool RegisterMainDexNatives(JNIEnv* env) { - // Register natives in a proxy. - if (!RegisterNative_org_chromium_base_natives_GEN_1JNIMAIN_DEX(env)) { - return false; - } - - - return true; -} - -bool RegisterNonMainDexNatives(JNIEnv* env) { - - return true; -} - -} // namespace test - -#endif // HEADER_GUARD diff --git a/base/android/jni_generator/golden/testProxyNativesMainDexAndNonMainDex.golden b/base/android/jni_generator/golden/testProxyNativesMainDexAndNonMainDex.golden deleted file mode 100644 index e317bd07724352..00000000000000 --- a/base/android/jni_generator/golden/testProxyNativesMainDexAndNonMainDex.golden +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2017 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - - -// This file is autogenerated by -// base/android/jni_generator/jni_registration_generator.py -// Please do not change its content. - -#ifndef HEADER_GUARD -#define HEADER_GUARD - -#include - -#include - -#include "base/android/jni_generator/jni_generator_helper.h" -#include "base/android/jni_int_wrapper.h" - - -// Step 1: Forward declarations (classes). - - -// Step 2: Forward declarations (methods). - -JNI_GENERATOR_EXPORT void Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Bar_1foo( - JNIEnv* env, - jclass jcaller); -JNI_GENERATOR_EXPORT void Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Bar_1bar( - JNIEnv* env, - jclass jcaller); -JNI_GENERATOR_EXPORT void Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Foo_1thisismaindex( - JNIEnv* env, - jclass jcaller); - - -// Step 3: Method declarations. - - -static const JNINativeMethod kMethods_org_chromium_base_natives_GEN_1JNI[] = { - { "test_foo_Bar_foo", "()V", - reinterpret_cast(Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Bar_1foo) }, - { "test_foo_Bar_bar", "()V", - reinterpret_cast(Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Bar_1bar) }, - -}; - -namespace { - -JNI_REGISTRATION_EXPORT bool RegisterNative_org_chromium_base_natives_GEN_1JNI(JNIEnv* env) { - const int number_of_methods = std::size(kMethods_org_chromium_base_natives_GEN_1JNI); - - base::android::ScopedJavaLocalRef native_clazz = - base::android::GetClass(env, "org/chromium/base/natives/GEN_JNI"); - if (env->RegisterNatives( - native_clazz.obj(), - kMethods_org_chromium_base_natives_GEN_1JNI, - number_of_methods) < 0) { - - jni_generator::HandleRegistrationError(env, native_clazz.obj(), __FILE__); - return false; - } - - return true; -} - -} // namespace - -static const JNINativeMethod kMethods_org_chromium_base_natives_GEN_1JNIMAIN_DEX[] = { - { "test_foo_Foo_thisismaindex", "()V", - reinterpret_cast(Java_org_chromium_base_natives_GEN_1JNI_test_1foo_1Foo_1thisismaindex) - }, - -}; - -namespace { - -JNI_REGISTRATION_EXPORT bool RegisterNative_org_chromium_base_natives_GEN_1JNIMAIN_DEX(JNIEnv* env) { - const int number_of_methods = std::size(kMethods_org_chromium_base_natives_GEN_1JNIMAIN_DEX); - - base::android::ScopedJavaLocalRef native_clazz = - base::android::GetClass(env, "org/chromium/base/natives/GEN_JNI"); - if (env->RegisterNatives( - native_clazz.obj(), - kMethods_org_chromium_base_natives_GEN_1JNIMAIN_DEX, - number_of_methods) < 0) { - - jni_generator::HandleRegistrationError(env, native_clazz.obj(), __FILE__); - return false; - } - - return true; -} - -} // namespace - - -// Step 4: Main dex and non-main dex registration functions. - -namespace test { - -bool RegisterMainDexNatives(JNIEnv* env) { - // Register natives in a proxy. - if (!RegisterNative_org_chromium_base_natives_GEN_1JNIMAIN_DEX(env)) { - return false; - } - - - return true; -} - -bool RegisterNonMainDexNatives(JNIEnv* env) { - // Register natives in a proxy. - if (!RegisterNative_org_chromium_base_natives_GEN_1JNI(env)) { - return false; - } - - - return true; -} - -} // namespace test - -#endif // HEADER_GUARD diff --git a/base/android/jni_generator/golden/testProxyNativesRegistrations.golden b/base/android/jni_generator/golden/testProxyNativesRegistrations.golden index 508d02ba8d8228..334d0226bd7262 100644 --- a/base/android/jni_generator/golden/testProxyNativesRegistrations.golden +++ b/base/android/jni_generator/golden/testProxyNativesRegistrations.golden @@ -81,16 +81,11 @@ JNI_REGISTRATION_EXPORT bool RegisterNative_org_chromium_base_natives_GEN_1JNI(J } // namespace -// Step 4: Main dex and non-main dex registration functions. +// Step 4: Registration function. namespace test { -bool RegisterMainDexNatives(JNIEnv* env) { - - return true; -} - -bool RegisterNonMainDexNatives(JNIEnv* env) { +bool RegisterNatives(JNIEnv* env) { // Register natives in a proxy. if (!RegisterNative_org_chromium_base_natives_GEN_1JNI(env)) { return false; diff --git a/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java b/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java index 06af39bc0182a4..b5506690ed1240 100644 --- a/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java +++ b/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java @@ -23,7 +23,6 @@ import org.chromium.base.NativeLibraryLoadedStatus; import org.chromium.base.annotations.NativeMethods; import org.chromium.build.annotations.CheckDiscard; -import org.chromium.build.annotations.MainDex; import java.util.ArrayList; import java.util.List; @@ -58,7 +57,6 @@ @AutoService(Processor.class) public class JniProcessor extends AbstractProcessor { private static final Class JNI_STATIC_NATIVES_CLASS = NativeMethods.class; - private static final Class MAIN_DEX_CLASS = MainDex.class; private static final Class CHECK_DISCARD_CLASS = CheckDiscard.class; private static final String CHECK_DISCARD_CRBUG = "crbug.com/993421"; @@ -167,13 +165,10 @@ public boolean process( // method overridden will be a wrapper that calls its // native counterpart in NativeClass. boolean isNativesInterfacePublic = type.getModifiers().contains(Modifier.PUBLIC); - // If the outerType needs to be in the main dex, then the generated NativeWrapperClass - // should also be added to the main dex. - boolean addMainDexAnnotation = outerElement.getAnnotation(MAIN_DEX_CLASS) != null; TypeSpec nativeWrapperClassSpec = createNativeWrapperClassSpec(getNameOfWrapperClass(outerClassName), - isNativesInterfacePublic, addMainDexAnnotation, type, methodMap); + isNativesInterfacePublic, type, methodMap); // Queue this file for writing. // Can't write right now because the wrapper class depends on NativeClass @@ -294,12 +289,11 @@ void printError(String s, Element e) { * * @param name name of the wrapper class. * @param isPublic if true, a public modifier will be added to this native wrapper. - * @param isMainDex if true, the @MainDex annotation will be added to this native wrapper. * @param nativeInterface the {@link NativeMethods} annotated type that this native wrapper * will implement. * @param methodMap a map from the old method name to the new method spec in NativeClass. * */ - TypeSpec createNativeWrapperClassSpec(String name, boolean isPublic, boolean isMainDex, + TypeSpec createNativeWrapperClassSpec(String name, boolean isPublic, TypeElement nativeInterface, Map methodMap) { // The wrapper class builder. TypeName nativeInterfaceType = TypeName.get(nativeInterface.asType()); @@ -308,9 +302,6 @@ TypeSpec createNativeWrapperClassSpec(String name, boolean isPublic, boolean isM if (isPublic) { builder.addModifiers(Modifier.PUBLIC); } - if (isMainDex) { - builder.addAnnotation(MAIN_DEX_CLASS); - } builder.addAnnotation(createAnnotationWithValue(CHECK_DISCARD_CLASS, CHECK_DISCARD_CRBUG)); // Start by adding all the native method wrappers. @@ -351,7 +342,7 @@ TypeSpec createNativeWrapperClassSpec(String name, boolean isPublic, boolean isM throw new UnsupportedOperationException($noMockExceptionString); } } - NativeLibraryLoadedStatus.checkLoaded($isMainDex) + NativeLibraryLoadedStatus.checkLoaded() return new {classname}Jni(); } */ @@ -375,7 +366,7 @@ TypeSpec createNativeWrapperClassSpec(String name, boolean isPublic, boolean isM noMockExceptionString) .endControlFlow() .endControlFlow() - .addStatement("$T.$N($L)", JNI_STATUS_CLASS_NAME, "checkLoaded", isMainDex) + .addStatement("$T.$N()", JNI_STATUS_CLASS_NAME, "checkLoaded") .addStatement("return new $N()", name) .build(); diff --git a/base/android/jni_generator/jni_generator_tests.py b/base/android/jni_generator/jni_generator_tests.py index 328b8fc3f616db..1e3eeb398cdae2 100755 --- a/base/android/jni_generator/jni_generator_tests.py +++ b/base/android/jni_generator/jni_generator_tests.py @@ -24,7 +24,6 @@ import jni_registration_generator import zipfile from jni_generator import CalledByNative -from jni_generator import IsMainDexJavaClass from jni_generator import NativeMethod from jni_generator import Param from jni_generator import ProxyHelpers @@ -106,9 +105,8 @@ def _MergeRegistrationForTests(results, signature for signature in proxy_signatures_list) proxy_native_array_list = sorted( - set(combined_dict['PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX'].split( - '},\n'))) - combined_dict['PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX'] = '},\n'.join( + set(combined_dict['PROXY_NATIVE_METHOD_ARRAY'].split('},\n'))) + combined_dict['PROXY_NATIVE_METHOD_ARRAY'] = '},\n'.join( p for p in proxy_native_array_list if p != '') + '}' signature_to_cases = collections.defaultdict(list) @@ -432,8 +430,7 @@ def testNatives(self): h2 = jni_registration_generator.DictionaryGenerator(JniGeneratorOptions(), '', '', 'org/chromium/TestJni', - natives, jni_params, - True) + natives, jni_params) content = TestGenerator._MergeRegistrationForTests([h2.Generate()]) reg_options = JniRegistrationGeneratorOptions() @@ -533,8 +530,7 @@ class MyOtherInnerClass { h2 = jni_registration_generator.DictionaryGenerator(JniGeneratorOptions(), '', '', 'org/chromium/TestJni', - natives, jni_params, - True) + natives, jni_params) content = TestGenerator._MergeRegistrationForTests([h2.Generate()]) reg_options = JniRegistrationGeneratorOptions() @@ -1186,50 +1182,6 @@ def testNativesLong(self): test_options) self.AssertGoldenTextEquals(h.GetContent()) - def testMainDexAnnotation(self): - mainDexEntries = [ - '@MainDex public class Test {', - '@MainDex public class Test{', - """@MainDex - public class Test { - """, - """@MainDex public class Test - { - """, - '@MainDex /* This class is a test */ public class Test {', - '@MainDex public class Test implements java.io.Serializable {', - '@MainDex public class Test implements java.io.Serializable, Bidule {', - '@MainDex public class Test extends BaseTest {', - """@MainDex - public class Test extends BaseTest implements Bidule { - """, - """@MainDex - public class Test extends BaseTest implements Bidule, Machin, Chose { - """, - """@MainDex - public class Test implements Testable { - """, - '@MainDex public class Test implements Testable ' - ' {', - '@a.B @MainDex @C public class Test extends Testable {', - """public class Test extends Testable { - @MainDex void func() {} - """, - ] - for entry in mainDexEntries: - self.assertEqual(True, IsMainDexJavaClass(entry), entry) - - def testNoMainDexAnnotation(self): - noMainDexEntries = [ - 'public class Test {', '@NotMainDex public class Test {', - '// @MainDex public class Test {', '/* @MainDex */ public class Test {', - 'public class Test implements java.io.Serializable {', - '@MainDexNot public class Test {', - 'public class Test extends BaseTest {' - ] - for entry in noMainDexEntries: - self.assertEqual(False, IsMainDexJavaClass(entry)) - def testNativeExportsOnlyOption(self): test_data = """ package org.chromium.example.jni_generator; @@ -1522,79 +1474,6 @@ class SampleProxyJni { self.AssertListEquals(_RemoveHashedNames(natives), []) - def testProxyNativesMainDex(self): - test_data = """ - @MainDex - class Foo() { - @NativeMethods - interface Natives { - void thisismaindex(); - } - void dontmatchme(); - public static void metoo(); - public static native void this_is_a_non_proxy_native(); - } - """ - - non_main_dex_test_data = """ - class Bar() { - @NativeMethods - interface Natives { - void foo(); - void bar(); - } - } - """ - qualified_clazz = 'test/foo/Foo' - options = JniRegistrationGeneratorOptions() - options.manual_jni_registration = True - - natives, _ = jni_generator.ProxyHelpers.ExtractStaticProxyNatives( - qualified_clazz, test_data, 'long') - - golden_natives = [ - NativeMethod( - return_type='void', - static=True, - name='thisismaindex', - params=[], - java_class_name=None, - is_proxy=True, - proxy_name='test_foo_Foo_thisismaindex'), - ] - - self.AssertListEquals(_RemoveHashedNames(natives), golden_natives) - - jni_params = jni_generator.JniParams(qualified_clazz) - main_dex_header = jni_registration_generator.DictionaryGenerator( - options, '', '', qualified_clazz, natives, jni_params, - main_dex=True).Generate() - content = TestGenerator._MergeRegistrationForTests([main_dex_header]) - - self.AssertGoldenTextEquals( - jni_registration_generator.CreateFromDict(options, '', content)) - - other_qualified_clazz = 'test/foo/Bar' - other_natives, _ = jni_generator.ProxyHelpers.ExtractStaticProxyNatives( - other_qualified_clazz, non_main_dex_test_data, 'long') - - jni_params = jni_generator.JniParams(other_qualified_clazz) - non_main_dex_header = jni_registration_generator.DictionaryGenerator( - options, - '', - '', - other_qualified_clazz, - other_natives, - jni_params, - main_dex=False).Generate() - - content = TestGenerator._MergeRegistrationForTests([main_dex_header] + - [non_main_dex_header]) - - self.AssertGoldenTextEquals( - jni_registration_generator.CreateFromDict(options, '', content), - 'AndNonMainDex') - def testProxyNatives(self): test_data = """ class SampleProxyJni { @@ -1683,8 +1562,7 @@ class SampleProxyJni{ self.AssertGoldenTextEquals(h1.GetContent()) h2 = jni_registration_generator.DictionaryGenerator(reg_options, '', '', qualified_clazz, - natives, jni_params, - False) + natives, jni_params) content = TestGenerator._MergeRegistrationForTests([h2.Generate()]) diff --git a/base/android/jni_generator/jni_registration_generator.py b/base/android/jni_generator/jni_registration_generator.py index 100d6e0b22bc63..3bc14d11d1d321 100755 --- a/base/android/jni_generator/jni_registration_generator.py +++ b/base/android/jni_generator/jni_registration_generator.py @@ -3,11 +3,9 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -"""Generates GEN_JNI.java (or N.java) and helper for manual JNI registration. - -Creates a header file with two static functions: RegisterMainDexNatives() and -RegisterNonMainDexNatives(). Together, these will use manual JNI registration -to register all native methods that exist within an application.""" +"""Generates GEN_JNI.java (or N.java) and optional header for manual JNI +registration. +""" import argparse import collections @@ -33,9 +31,7 @@ 'PROXY_NATIVE_SIGNATURES', 'FORWARDING_PROXY_METHODS', 'PROXY_NATIVE_METHOD_ARRAY', - 'PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX', - 'REGISTER_MAIN_DEX_NATIVES', - 'REGISTER_NON_MAIN_DEX_NATIVES', + 'REGISTER_NATIVES', ] @@ -45,8 +41,7 @@ def _Generate(options, java_file_paths): Generates a srcjar containing a single class, GEN_JNI, that contains all native method declarations. - Optionally generates a header file that provides functions - (RegisterMainDexNatives and RegisterNonMainDexNatives) to perform + Optionally generates a header file that provides RegisterNatives to perform JNI registration. Args: @@ -70,7 +65,7 @@ def _Generate(options, java_file_paths): for key in MERGEABLE_KEYS: combined_dict[key] = ''.join(d.get(key, '') for d in module_results) - # PROXY_NATIVE_SIGNATURES and PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX will have + # PROXY_NATIVE_SIGNATURES and PROXY_NATIVE_METHOD_ARRAY will have # duplicates for JNI multiplexing since all native methods with similar # signatures map to the same proxy. Similarly, there may be multiple switch # case entries for the same proxy signatures. @@ -81,9 +76,8 @@ def _Generate(options, java_file_paths): signature for signature in proxy_signatures_list) proxy_native_array_list = sorted( - set(combined_dict['PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX'].split( - '},\n'))) - combined_dict['PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX'] = '},\n'.join( + set(combined_dict['PROXY_NATIVE_METHOD_ARRAY'].split('},\n'))) + combined_dict['PROXY_NATIVE_METHOD_ARRAY'] = '},\n'.join( p for p in proxy_native_array_list if p != '') + '}' signature_to_cases = collections.defaultdict(list) @@ -164,10 +158,9 @@ def _DictForPath(options, path): content_namespace = jni_generator.ExtractJNINamespace(contents) jni_params = jni_generator.JniParams(fully_qualified_class) jni_params.ExtractImportsAndInnerClasses(contents) - is_main_dex = jni_generator.IsMainDexJavaClass(contents) dict_generator = DictionaryGenerator(options, found_module_name, content_namespace, fully_qualified_class, - natives, jni_params, is_main_dex) + natives, jni_params) return dict_generator.Generate() @@ -257,19 +250,13 @@ def _SetProxyRegistrationFields(options, module_name, registration_dict): ${PROXY_NATIVE_METHOD_ARRAY}\ ${JNI_NATIVE_METHOD} -// Step 4: Main dex and non-main dex registration functions. +// Step 4: Registration function. namespace ${NAMESPACE} { -bool RegisterMainDexNatives(JNIEnv* env) {\ -${REGISTER_MAIN_DEX_PROXY_NATIVES} -${REGISTER_MAIN_DEX_NATIVES} - return true; -} - -bool RegisterNonMainDexNatives(JNIEnv* env) {\ +bool RegisterNatives(JNIEnv* env) {\ ${REGISTER_PROXY_NATIVES} -${REGISTER_NON_MAIN_DEX_NATIVES} +${REGISTER_NATIVES} return true; } @@ -299,19 +286,8 @@ def _SetProxyRegistrationFields(options, module_name, registration_dict): proxy_native_array = '' proxy_natives_registration = '' - if registration_dict['PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX']: - sub_dict['REGISTRATION_NAME'] += 'MAIN_DEX' - sub_dict['ESCAPED_PROXY_CLASS'] += 'MAIN_DEX' - sub_dict['KMETHODS'] = ( - registration_dict['PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX']) - proxy_native_array += registration_template.substitute(sub_dict) - main_dex_call = registration_call.substitute(sub_dict) - else: - main_dex_call = '' - registration_dict['PROXY_NATIVE_METHOD_ARRAY'] = proxy_native_array registration_dict['REGISTER_PROXY_NATIVES'] = proxy_natives_registration - registration_dict['REGISTER_MAIN_DEX_PROXY_NATIVES'] = main_dex_call if options.manual_jni_registration: registration_dict['MANUAL_REGISTRATION'] = manual_registration.substitute( @@ -437,7 +413,7 @@ class DictionaryGenerator(object): """Generates an inline header file for JNI registration.""" def __init__(self, options, module_name, content_namespace, - fully_qualified_class, natives, jni_params, main_dex): + fully_qualified_class, natives, jni_params): self.options = options self.module_name = module_name self.content_namespace = content_namespace @@ -447,7 +423,6 @@ def __init__(self, options, module_name, content_namespace, self.fully_qualified_class = fully_qualified_class self.jni_params = jni_params self.class_name = self.fully_qualified_class.split('/')[-1] - self.main_dex = main_dex self.helper = jni_generator.HeaderFileGeneratorHelper( self.class_name, self.module_name, @@ -525,10 +500,7 @@ def _AddRegisterNativesCalls(self): jni_generator.GetRegistrationFunctionName(self.fully_qualified_class) } register_body = template.substitute(value) - if self.main_dex: - self._SetDictValue('REGISTER_MAIN_DEX_NATIVES', register_body) - else: - self._SetDictValue('REGISTER_NON_MAIN_DEX_NATIVES', register_body) + self._SetDictValue('REGISTER_NON_NATIVES', register_body) def _AddJNINativeMethodsArrays(self): """Returns the implementation of the array of native methods.""" @@ -599,15 +571,10 @@ def _GetKMethodArrayEntry(self, native): def _AddProxyNativeMethodKStrings(self): """Returns KMethodString for wrapped native methods in all_classes """ - if self.main_dex or self.options.enable_jni_multiplexing: - key = 'PROXY_NATIVE_METHOD_ARRAY_MAIN_DEX' - else: - key = 'PROXY_NATIVE_METHOD_ARRAY' - proxy_k_strings = ('\n'.join( self._GetKMethodArrayEntry(p) for p in self.proxy_natives)) - self._SetDictValue(key, proxy_k_strings) + self._SetDictValue('PROXY_NATIVE_METHOD_ARRAY', proxy_k_strings) def _SubstituteNativeMethods(self, template): """Substitutes NAMESPACE, JAVA_CLASS and KMETHODS in the provided diff --git a/base/android/jni_generator/sample_entry_point.cc b/base/android/jni_generator/sample_entry_point.cc index 5a7eb48b711a97..cc2d50bb0de010 100644 --- a/base/android/jni_generator/sample_entry_point.cc +++ b/base/android/jni_generator/sample_entry_point.cc @@ -14,13 +14,7 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!base::android::IsSelectiveJniRegistrationEnabled(env)) { - if (!RegisterNonMainDexNatives(env)) { - return -1; - } - } - - if (!RegisterMainDexNatives(env)) { + if (!RegisterNatives(env)) { return -1; } return JNI_VERSION_1_4; diff --git a/base/android/jni_generator/sample_for_tests.h b/base/android/jni_generator/sample_for_tests.h index b32bd5ef30c310..20063329f6d8f4 100644 --- a/base/android/jni_generator/sample_for_tests.h +++ b/base/android/jni_generator/sample_for_tests.h @@ -64,12 +64,8 @@ namespace android { // - The Java class must be part of an android_apk target that depends on // a generate_jni_registration target. This generate_jni_registration target // automatically generates all necessary registration functions. The -// generated header file exposes two functions that should be called when a -// library is first loaded: -// 1) RegisterMainDexNatives() -// - Registers all methods that are used outside the browser process -// 2) RegisterNonMainDexNatives() -// - Registers all methods used in the browser process +// generated header file exposes RegisterNatives() which registers all +// methods. // class CPPClass { public: diff --git a/base/android/jni_utils.cc b/base/android/jni_utils.cc index 69849618189994..09f7172c61f34c 100644 --- a/base/android/jni_utils.cc +++ b/base/android/jni_utils.cc @@ -35,10 +35,6 @@ jobject GetSplitClassLoader(JNIEnv* env, const char* split_name) { return class_loader_obj; } -bool IsSelectiveJniRegistrationEnabled(JNIEnv* env) { - return Java_JNIUtils_isSelectiveJniRegistrationEnabled(env); -} - } // namespace android } // namespace base diff --git a/base/android/jni_utils.h b/base/android/jni_utils.h index db25837032b390..f619671e7cb98a 100644 --- a/base/android/jni_utils.h +++ b/base/android/jni_utils.h @@ -24,9 +24,6 @@ inline jobject GetClassLoader(JNIEnv* env) { return GetSplitClassLoader(env, ""); } -// Returns true if the current process permits selective JNI registration. -BASE_EXPORT bool IsSelectiveJniRegistrationEnabled(JNIEnv* env); - } // namespace android } // namespace base diff --git a/base/android/library_loader/library_loader_hooks.cc b/base/android/library_loader/library_loader_hooks.cc index 2a978136dbfdfe..b6453a2fe346ca 100644 --- a/base/android/library_loader/library_loader_hooks.cc +++ b/base/android/library_loader/library_loader_hooks.cc @@ -30,7 +30,6 @@ namespace { base::AtExitManager* g_at_exit_manager = nullptr; LibraryLoadedHook* g_registration_callback = nullptr; NativeInitializationHook* g_native_initialization_hook = nullptr; -NonMainDexJniRegistrationHook* g_jni_registration_hook = nullptr; LibraryProcessType g_library_process_type = PROCESS_UNINITIALIZED; } // namespace @@ -52,12 +51,6 @@ void SetNativeInitializationHook( g_native_initialization_hook = native_initialization_hook; } -void SetNonMainDexJniRegistrationHook( - NonMainDexJniRegistrationHook jni_registration_hook) { - DCHECK(!g_jni_registration_hook); - g_jni_registration_hook = jni_registration_hook; -} - void SetLibraryLoadedHook(LibraryLoadedHook* func) { g_registration_callback = func; } @@ -95,12 +88,6 @@ static jboolean JNI_LibraryLoader_LibraryLoaded( return true; } -static void JNI_LibraryLoader_RegisterNonMainDexJni(JNIEnv* env) { - if (g_jni_registration_hook) { - g_jni_registration_hook(); - } -} - void LibraryLoaderExitHook() { if (g_at_exit_manager) { delete g_at_exit_manager; diff --git a/base/android/library_loader/library_loader_hooks.h b/base/android/library_loader/library_loader_hooks.h index 52734aec581eea..6fe749b083fce4 100644 --- a/base/android/library_loader/library_loader_hooks.h +++ b/base/android/library_loader/library_loader_hooks.h @@ -51,11 +51,6 @@ typedef bool NativeInitializationHook(LibraryProcessType library_process_type); BASE_EXPORT void SetNativeInitializationHook( NativeInitializationHook native_initialization_hook); -typedef void NonMainDexJniRegistrationHook(); - -BASE_EXPORT void SetNonMainDexJniRegistrationHook( - NonMainDexJniRegistrationHook jni_registration_hook); - // Record any pending renderer histogram value as histograms. Pending values // are set by // JNI_LibraryLoader_RegisterChromiumAndroidLinkerRendererHistogram(). diff --git a/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/InstantStartTest.java b/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/InstantStartTest.java index 6db39b6c4c6f93..1409828434c206 100644 --- a/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/InstantStartTest.java +++ b/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/InstantStartTest.java @@ -378,13 +378,13 @@ public void testNoGURLPreNative() { collector.checkThat(StartSurfaceConfiguration.isStartSurfaceFlagEnabled(), is(true)); collector.checkThat(TextUtils.isEmpty(HomepageManager.getHomepageUri()), is(false)); Assert.assertFalse( - NativeLibraryLoadedStatus.getProviderForTesting().areMainDexNativeMethodsReady()); + NativeLibraryLoadedStatus.getProviderForTesting().areNativeMethodsReady()); ReturnToChromeUtil.shouldShowStartSurfaceAsTheHomePage(mActivityTestRule.getActivity()); ReturnToChromeUtil.isStartSurfaceEnabled(mActivityTestRule.getActivity()); PseudoTab.getAllPseudoTabsFromStateFile(mActivityTestRule.getActivity()); Assert.assertFalse("There should be no GURL usages triggering native library loading", - NativeLibraryLoadedStatus.getProviderForTesting().areMainDexNativeMethodsReady()); + NativeLibraryLoadedStatus.getProviderForTesting().areNativeMethodsReady()); } @Test diff --git a/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceTestUtils.java b/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceTestUtils.java index 5cb09a8cf920e9..a39188a5e99230 100644 --- a/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceTestUtils.java +++ b/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceTestUtils.java @@ -170,8 +170,7 @@ public static void startMainActivityFromLauncher(ChromeActivityTestRule activity public static void startAndWaitNativeInitialization( ChromeTabbedActivityTestRule activityTestRule) { Assert.assertTrue(NativeLibraryLoadedStatus.getProviderForTesting() == null - || !NativeLibraryLoadedStatus.getProviderForTesting() - .areMainDexNativeMethodsReady()); + || !NativeLibraryLoadedStatus.getProviderForTesting().areNativeMethodsReady()); CommandLine.getInstance().removeSwitch(ChromeSwitches.DISABLE_NATIVE_INITIALIZATION); TestThreadUtils.runOnUiThreadBlocking( diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java index 30b7debeb87d17..aff0771c7081b7 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java @@ -59,7 +59,7 @@ public void onCreate() { // this point to check. if (ChromeFeatureList.sEarlyLibraryLoad.isEnabled() && ProductConfig.IS_BUNDLE) { // Kick off library loading in a separate thread so it's ready when we need it. - new Thread(() -> LibraryLoader.getInstance().ensureMainDexInitialized()).start(); + new Thread(() -> LibraryLoader.getInstance().ensureInitialized()).start(); } // Initializes the support for dynamic feature modules (browser only). diff --git a/chrome/android/modules/cablev2_authenticator/internal/entrypoints.cc b/chrome/android/modules/cablev2_authenticator/internal/entrypoints.cc index 2d023d14b2fd31..84b38062775120 100644 --- a/chrome/android/modules/cablev2_authenticator/internal/entrypoints.cc +++ b/chrome/android/modules/cablev2_authenticator/internal/entrypoints.cc @@ -9,11 +9,7 @@ extern "C" { // This JNI registration method is found and called by module framework code. JNI_GENERATOR_EXPORT bool JNI_OnLoad_cablev2_authenticator(JNIEnv* env) { - if (!base::android::IsSelectiveJniRegistrationEnabled(env) && - !cablev2_authenticator::RegisterNonMainDexNatives(env)) { - return false; - } - if (!cablev2_authenticator::RegisterMainDexNatives(env)) { + if (!cablev2_authenticator::RegisterNatives(env)) { return false; } return true; diff --git a/chrome/android/modules/stack_unwinder/internal/entrypoints.cc b/chrome/android/modules/stack_unwinder/internal/entrypoints.cc index 389f57e5981691..9072976487e3dc 100644 --- a/chrome/android/modules/stack_unwinder/internal/entrypoints.cc +++ b/chrome/android/modules/stack_unwinder/internal/entrypoints.cc @@ -10,11 +10,7 @@ extern "C" { // This JNI registration method is found and called by module framework // code. JNI_GENERATOR_EXPORT bool JNI_OnLoad_stack_unwinder(JNIEnv* env) { - if (!base::android::IsSelectiveJniRegistrationEnabled(env) && - !stack_unwinder::RegisterNonMainDexNatives(env)) { - return false; - } - if (!stack_unwinder::RegisterMainDexNatives(env)) { + if (!stack_unwinder::RegisterNatives(env)) { return false; } return true; diff --git a/chrome/android/modules/test_dummy/internal/entrypoints.cc b/chrome/android/modules/test_dummy/internal/entrypoints.cc index 5e9d0b09b70001..fe737790454748 100644 --- a/chrome/android/modules/test_dummy/internal/entrypoints.cc +++ b/chrome/android/modules/test_dummy/internal/entrypoints.cc @@ -9,11 +9,7 @@ extern "C" { // This JNI registration method is found and called by module framework code. JNI_GENERATOR_EXPORT bool JNI_OnLoad_test_dummy(JNIEnv* env) { - if (!base::android::IsSelectiveJniRegistrationEnabled(env) && - !test_dummy::RegisterNonMainDexNatives(env)) { - return false; - } - if (!test_dummy::RegisterMainDexNatives(env)) { + if (!test_dummy::RegisterNatives(env)) { return false; } return true; diff --git a/chrome/browser/android/chrome_entry_point.cc b/chrome/browser/android/chrome_entry_point.cc index 563aa1f5179718..48986ed20864b1 100644 --- a/chrome/browser/android/chrome_entry_point.cc +++ b/chrome/browser/android/chrome_entry_point.cc @@ -16,24 +16,15 @@ bool NativeInit(base::android::LibraryProcessType) { return android::OnJNIOnLoadInit(); } -void RegisterNonMainDexNatives() { - RegisterNonMainDexNatives(base::android::AttachCurrentThread()); -} - } // namespace // This is called by the VM when the shared library is first loaded. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { - // All MainDex JNI methods are registered. Since render processes don't need - // very much Java code, we enable selective JNI registration on the - // Java side and only register Non-MainDex JNI when necessary through - // RegisterNonMainDexNatives(). base::android::InitVM(vm); - if (!RegisterMainDexNatives(base::android::AttachCurrentThread())) { + if (!RegisterNatives(base::android::AttachCurrentThread())) { return -1; } - base::android::SetNonMainDexJniRegistrationHook(RegisterNonMainDexNatives); base::android::SetNativeInitializationHook(NativeInit); return JNI_VERSION_1_4; } diff --git a/chrome/browser/android/chrome_entry_point_for_test.cc b/chrome/browser/android/chrome_entry_point_for_test.cc index 16e62482fde1f4..f985c42bd4b326 100644 --- a/chrome/browser/android/chrome_entry_point_for_test.cc +++ b/chrome/browser/android/chrome_entry_point_for_test.cc @@ -24,23 +24,14 @@ bool NativeInit(base::android::LibraryProcessType) { return android::OnJNIOnLoadInit(); } -void RegisterNonMainDexNatives() { - RegisterNonMainDexNatives(base::android::AttachCurrentThread()); -} - } // namespace // This is called by the VM when the shared library is first loaded. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { - // All MainDex JNI methods are registered. Since render processes don't need - // very much Java code, we enable selective JNI registration on the - // Java side and only register Non-MainDex JNI when necessary through - // RegisterNonMainDexNatives(). base::android::InitVM(vm); - if (!RegisterMainDexNatives(base::android::AttachCurrentThread())) { + if (!RegisterNatives(base::android::AttachCurrentThread())) { return -1; } - base::android::SetNonMainDexJniRegistrationHook(RegisterNonMainDexNatives); base::android::SetNativeInitializationHook(NativeInit); return JNI_VERSION_1_4; } diff --git a/chrome/browser/android/vr/register_gvr_jni.cc b/chrome/browser/android/vr/register_gvr_jni.cc index 2585eea9868538..628c475c136e51 100644 --- a/chrome/browser/android/vr/register_gvr_jni.cc +++ b/chrome/browser/android/vr/register_gvr_jni.cc @@ -23,8 +23,7 @@ static const base::android::RegistrationMethod kGvrRegisteredMethods[] = { }; bool RegisterGvrJni(JNIEnv* env) { - if (!base::android::IsSelectiveJniRegistrationEnabled(env) && - !RegisterNativeMethods(env, kGvrRegisteredMethods, + if (!RegisterNativeMethods(env, kGvrRegisteredMethods, std::size(kGvrRegisteredMethods))) { return false; } diff --git a/chromecast/app/android/cast_browser_module_entrypoint.cc b/chromecast/app/android/cast_browser_module_entrypoint.cc index 348800cefaf45a..1b40439be613e3 100644 --- a/chromecast/app/android/cast_browser_module_entrypoint.cc +++ b/chromecast/app/android/cast_browser_module_entrypoint.cc @@ -12,11 +12,7 @@ extern "C" { // This JNI registration method is found and called by module framework code. JNI_GENERATOR_EXPORT bool JNI_OnLoad_cast_browser(JNIEnv* env) { - if (!base::android::IsSelectiveJniRegistrationEnabled(env) && - !RegisterNonMainDexNatives(env)) { - return false; - } - if (!RegisterMainDexNatives(env)) { + if (!RegisterNatives(env)) { return false; } diff --git a/chromecast/app/android/cast_jni_loader.cc b/chromecast/app/android/cast_jni_loader.cc index 94385785d449d2..29f9fd39702e02 100644 --- a/chromecast/app/android/cast_jni_loader.cc +++ b/chromecast/app/android/cast_jni_loader.cc @@ -15,7 +15,7 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!RegisterMainDexNatives(env) || !RegisterNonMainDexNatives(env)) { + if (!RegisterNatives(env)) { return -1; } diff --git a/components/cronet/android/cronet_library_loader.cc b/components/cronet/android/cronet_library_loader.cc index 8838c447712f16..fe3a314d3ab8b2 100644 --- a/components/cronet/android/cronet_library_loader.cc +++ b/components/cronet/android/cronet_library_loader.cc @@ -88,7 +88,7 @@ bool OnInitThread() { jint CronetOnLoad(JavaVM* vm, void* reserved) { base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!RegisterMainDexNatives(env) || !RegisterNonMainDexNatives(env)) { + if (!RegisterNatives(env)) { return -1; } if (!base::android::OnJNIOnLoadInit()) diff --git a/content/public/android/java/src/org/chromium/content/app/ContentChildProcessServiceDelegate.java b/content/public/android/java/src/org/chromium/content/app/ContentChildProcessServiceDelegate.java index 6ec8af5a339e4a..dca1cec5f77847 100644 --- a/content/public/android/java/src/org/chromium/content/app/ContentChildProcessServiceDelegate.java +++ b/content/public/android/java/src/org/chromium/content/app/ContentChildProcessServiceDelegate.java @@ -12,7 +12,6 @@ import android.util.SparseArray; import android.view.Surface; -import org.chromium.base.JNIUtils; import org.chromium.base.Log; import org.chromium.base.ThreadUtils; import org.chromium.base.UnguessableToken; @@ -91,8 +90,6 @@ public void loadNativeLibrary(Context hostContext) { return; } - JNIUtils.enableSelectiveJniRegistration(); - LibraryLoader libraryLoader = LibraryLoader.getInstance(); libraryLoader.getMediator().initInChildProcess(); libraryLoader.loadNowOverrideApplicationContext(hostContext); diff --git a/content/public/android/java/src/org/chromium/content_public/app/ZygotePreload.java b/content/public/android/java/src/org/chromium/content_public/app/ZygotePreload.java index 1b0bf7caf9cdd3..6238ca9e7d55dc 100644 --- a/content/public/android/java/src/org/chromium/content_public/app/ZygotePreload.java +++ b/content/public/android/java/src/org/chromium/content_public/app/ZygotePreload.java @@ -12,7 +12,6 @@ import androidx.annotation.RequiresApi; -import org.chromium.base.JNIUtils; import org.chromium.base.Log; import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.process_launcher.ChildProcessService; @@ -53,7 +52,6 @@ protected final void doPreloadCommon(ApplicationInfo appInfo) { // should give an accurate measurement of zygote process startup time. ChildProcessService.setZygoteInfo( Process.myPid(), SystemClock.currentThreadTimeMillis()); - JNIUtils.enableSelectiveJniRegistration(); LibraryLoader.getInstance().getMediator().initInAppZygote(); LibraryLoader.getInstance().loadNowInZygote(appInfo); } catch (Throwable e) { diff --git a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/TestChildProcessService.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/TestChildProcessService.java index cf782bfef8a71e..f9747a31b0a242 100644 --- a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/TestChildProcessService.java +++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/TestChildProcessService.java @@ -14,7 +14,6 @@ import android.util.SparseArray; import org.chromium.base.CommandLine; -import org.chromium.base.JNIUtils; import org.chromium.base.Log; import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryProcessType; @@ -83,9 +82,6 @@ public void loadNativeLibrary(Context hostContext) { // Store the command line before loading the library to avoid an assert in CommandLine. mCommandLine = CommandLine.getJavaSwitchesOrNull(); - // Non-main processes are launched for testing. Mark them as such so that the JNI - // in the seconary dex won't be registered. See https://crbug.com/810720. - JNIUtils.enableSelectiveJniRegistration(); LibraryLoader.getInstance().loadNow(); LibraryLoader.getInstance().ensureInitialized(); diff --git a/docs/android_dynamic_feature_modules.md b/docs/android_dynamic_feature_modules.md index 8a2d006983fe19..81e7d3b8746885 100644 --- a/docs/android_dynamic_feature_modules.md +++ b/docs/android_dynamic_feature_modules.md @@ -460,11 +460,7 @@ on all Chrome build variants, including Monochrome (unlike base module JNI). extern "C" { // This JNI registration method is found and called by module framework code. JNI_GENERATOR_EXPORT bool JNI_OnLoad_foo(JNIEnv* env) { - if (!base::android::IsSelectiveJniRegistrationEnabled(env) && - !foo::RegisterNonMainDexNatives(env)) { - return false; - } - if (!foo::RegisterMainDexNatives(env)) { + if (!foo::RegisterNatives(env)) { return false; } return true; diff --git a/third_party/gvr-android-sdk/display_synchronizer_jni.h b/third_party/gvr-android-sdk/display_synchronizer_jni.h index a0ad5b0a1cf5de..f28862a7c6e8c4 100644 --- a/third_party/gvr-android-sdk/display_synchronizer_jni.h +++ b/third_party/gvr-android-sdk/display_synchronizer_jni.h @@ -126,9 +126,6 @@ static const JNINativeMethod kMethodsDisplaySynchronizer[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - if (base::android::IsSelectiveJniRegistrationEnabled(env)) - return true; - const int kMethodsDisplaySynchronizerSize = std::extent(); diff --git a/third_party/gvr-android-sdk/gvr_api_jni.h b/third_party/gvr-android-sdk/gvr_api_jni.h index 193dd12a3a1845..5c6c69f4069876 100644 --- a/third_party/gvr-android-sdk/gvr_api_jni.h +++ b/third_party/gvr-android-sdk/gvr_api_jni.h @@ -1725,9 +1725,6 @@ static const JNINativeMethod kMethodsGvrApi[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - if (base::android::IsSelectiveJniRegistrationEnabled(env)) - return true; - const int kMethodsGvrApiSize = std::extent(); if (env->RegisterNatives(GvrApi_clazz(env), kMethodsGvrApi, diff --git a/third_party/gvr-android-sdk/native_callbacks_jni.h b/third_party/gvr-android-sdk/native_callbacks_jni.h index 2cd48b950edd8e..247ef581082f76 100644 --- a/third_party/gvr-android-sdk/native_callbacks_jni.h +++ b/third_party/gvr-android-sdk/native_callbacks_jni.h @@ -324,9 +324,6 @@ static const JNINativeMethod kMethodsNativeCallbacks[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - if (base::android::IsSelectiveJniRegistrationEnabled(env)) - return true; - const int kMethodsNativeCallbacksSize = std::extent(); diff --git a/url/android/java/src/org/chromium/url/GURL.java b/url/android/java/src/org/chromium/url/GURL.java index 28e153cf4700f8..62f9dbbf33edc7 100644 --- a/url/android/java/src/org/chromium/url/GURL.java +++ b/url/android/java/src/org/chromium/url/GURL.java @@ -110,9 +110,12 @@ public static void setReportDebugThrowableCallback(ReportDebugThrowableCallback public static void ensureNativeInitializedForGURL() { if (LibraryLoader.getInstance().isInitialized()) return; long time = SystemClock.elapsedRealtime(); - LibraryLoader.getInstance().ensureMainDexInitialized(); + LibraryLoader.getInstance().ensureInitialized(); // Record metrics only for the UI thread where the delay in loading the library is relevant. if (ThreadUtils.runningOnUiThread()) { + // "MainDex" in name of histogram is a dated reference to when we used to have 2 + // sections of the native library, main dex and non-main dex. Maintaining name for + // consistency in metrics. RecordHistogram.recordTimesHistogram("Startup.Android.GURLEnsureMainDexInitialized", SystemClock.elapsedRealtime() - time); if (sReportCallback != null && new Random().nextInt(100) < DEBUG_REPORT_PERCENTAGE) { diff --git a/weblayer/app/entry_point.cc b/weblayer/app/entry_point.cc index 7329744fcdfc38..5e140ee1a8802b 100644 --- a/weblayer/app/entry_point.cc +++ b/weblayer/app/entry_point.cc @@ -19,8 +19,7 @@ bool NativeInit(base::android::LibraryProcessType) { JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!weblayer_test::RegisterNonMainDexNatives(env) || - !weblayer_test::RegisterMainDexNatives(env) || + if (!weblayer_test::RegisterNatives(env) || !weblayer::MaybeRegisterNatives()) { return -1; } diff --git a/weblayer/browser/web_view_compatibility_helper_impl.cc b/weblayer/browser/web_view_compatibility_helper_impl.cc index 81681b92f95bee..b9d97204c9039b 100644 --- a/weblayer/browser/web_view_compatibility_helper_impl.cc +++ b/weblayer/browser/web_view_compatibility_helper_impl.cc @@ -9,22 +9,14 @@ #endif namespace weblayer { -namespace { -#if defined(WEBLAYER_MANUAL_JNI_REGISTRATION) -void RegisterNonMainDexNativesHook() { - RegisterNonMainDexNatives(base::android::AttachCurrentThread()); -} -#endif -} // namespace bool MaybeRegisterNatives() { #if defined(WEBLAYER_MANUAL_JNI_REGISTRATION) JNIEnv* env = base::android::AttachCurrentThread(); if (Java_WebViewCompatibilityHelperImpl_requiresManualJniRegistration(env)) { - if (!RegisterMainDexNatives(env)) + if (!RegisterNatives(env)) { return false; - base::android::SetNonMainDexJniRegistrationHook( - RegisterNonMainDexNativesHook); + } } #endif return true;