Skip to content

Commit

Permalink
Automatically adding @IdentifierNameString for DFMs
Browse files Browse the repository at this point in the history
Bug: 1170343
Change-Id: I2a5c082d2069ba40318b9a53553d465c1e632702
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3607495
Auto-Submit: Sam Maier <smaier@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Owners-Override: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/main@{#997760}
  • Loading branch information
Sam Maier authored and Chromium LUCI CQ committed Apr 29, 2022
1 parent 6c7eb9d commit bd22e61
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 26 deletions.
7 changes: 7 additions & 0 deletions base/android/proguard/chromium_code.flags
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,10 @@
-identifiernamestring class * {
@org.chromium.base.annotations.IdentifierNameString *;
}

# -identifiernamestring doesn't keep the module impl around, we have to
# explicitly keep it.
-if @org.chromium.components.module_installer.builder.ModuleInterface interface *
-keep,allowobfuscation,allowaccessmodification class * extends <1> {
<init>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@
@org.chromium.base.annotations.IdentifierNameString *;
}

# -identifiernamestring doesn't keep the module impl around, we have to
# explicitly keep it.
-if @org.chromium.components.module_installer.builder.ModuleInterface interface *
-keep,allowobfuscation,allowaccessmodification class * extends <1> {
<init>();
}

# File: ../../build/android/dcheck_is_off.flags
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@

package org.chromium.chrome.features.dev_ui;

import org.chromium.base.annotations.UsedByReflection;

/** Implementation for the DevUI DFM. */
@UsedByReflection("DevUiModule")
public class DevUiImpl implements DevUi {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import androidx.annotation.NonNull;

import org.chromium.base.SysUtils;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.base.jank_tracker.JankTracker;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.OneshotSupplier;
Expand Down Expand Up @@ -55,7 +54,6 @@
/**
* Impl class that will resolve components for tab management.
*/
@UsedByReflection("TabManagementModule")
public class TabManagementDelegateImpl implements TabManagementDelegate {
@Override
public TabSwitcher createGridTabSwitcher(@NonNull Activity activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

package org.chromium.chrome.browser.vr;

import org.chromium.base.annotations.UsedByReflection;

/** {@link VrDelegateProvider} implementation if the VR module is available. */
@UsedByReflection("VrModuleProvider.java")
public class VrDelegateProviderImpl implements VrDelegateProvider {
private final VrDelegateImpl mDelegate = new VrDelegateImpl();
private final VrIntentDelegateImpl mIntentDelegate = new VrIntentDelegateImpl();

@UsedByReflection("VrModuleProvider.java")
public VrDelegateProviderImpl() {}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

import androidx.fragment.app.Fragment;

import org.chromium.base.annotations.UsedByReflection;
import org.chromium.chrome.browser.webauth.authenticator.CableAuthenticatorUI;

/**
* This is the implementation of the interface to the caBLE v2 Authenticator module. It should
* never be accessed directly, only by the module infrastructure machinery. (It's required to be
* public for that machinery to function.)
*/
@UsedByReflection("Cablev2AuthenticatorModule")
public class ModuleImpl implements Module {
@Override
public Fragment getFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.annotations.UsedByReflection;

/**
* Provides access to the stack unwinder native code functions within the dynamic feature module.
*/
@UsedByReflection("StackUnwinderModule")
@MainDex
public class StackUnwinderModuleContentsImpl implements StackUnwinderModuleContents {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

package org.chromium.chrome.modules.test_dummy;

import org.chromium.base.annotations.UsedByReflection;
import org.chromium.chrome.browser.test_dummy.TestDummy;
import org.chromium.chrome.browser.test_dummy.TestDummyImpl;

/** Provides the test dummy implementation inside the test dummy module. */
@UsedByReflection("TestDummyModule")
public class TestDummyProviderImpl implements TestDummyProvider {
private final TestDummyImpl mTestDummy = new TestDummyImpl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@

package org.chromium.chromecast.shell;

import org.chromium.base.annotations.UsedByReflection;

/** Interface implementation inside the module. */
@UsedByReflection("CastBrowserModule")
public class CastBrowserImpl implements CastBrowser {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.Context;
import android.view.View;

import org.chromium.base.annotations.UsedByReflection;
import org.chromium.base.supplier.Supplier;
import org.chromium.components.autofill_assistant.onboarding.OnboardingCoordinatorFactory;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
Expand All @@ -17,7 +16,6 @@
* Implementation of {@link AutofillAssistantModuleEntry}. This is the entry point into the
* assistant DFM.
*/
@UsedByReflection("AutofillAssistantModuleEntryProvider.java")
public class AutofillAssistantModuleEntryImpl implements AutofillAssistantModuleEntry {
@Override
public AssistantOnboardingHelper createOnboardingHelper(
Expand Down
3 changes: 3 additions & 0 deletions components/module_installer/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ android_library("module_installer_java") {
"//third_party/androidx:androidx_annotation_annotation_java",
]

public_deps = [ "//build/android:build_java" ]

annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
}

Expand Down Expand Up @@ -76,6 +78,7 @@ java_annotation_processor("module_interface_processor") {
[ "//third_party/android_deps:auto_service_processor" ]
deps = [
":module_interface_java",
"//build/android:build_java",
"//third_party/android_deps:com_google_auto_service_auto_service_annotations_java",
"//third_party/android_deps:com_google_guava_guava_java",
"//third_party/android_deps:com_squareup_javapoet_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.auto.service.AutoService;
import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
Expand All @@ -15,8 +16,11 @@
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;

import org.chromium.base.annotations.IdentifierNameString;

import java.util.Set;

import javax.annotation.Generated;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
Expand Down Expand Up @@ -82,10 +86,17 @@ private TypeSpec createModuleClassSpec(
TypeName installEngineInterface =
ClassName.get("org.chromium.components.module_installer.engine", "InstallEngine");

FieldSpec classNameString =
FieldSpec.builder(ClassName.get(String.class), "sModuleClassString")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
.addAnnotation(IdentifierNameString.class)
.initializer("$S", implClassName)
.build();

FieldSpec module = FieldSpec.builder(moduleClassName, "sModule")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("new $T($S, $T.class, $S)", moduleClassName,
moduleName, moduleInterface, implClassName)
.initializer("new $T($S, $T.class, sModuleClassString)",
moduleClassName, moduleName, moduleInterface)
.build();

MethodSpec isInstalled = MethodSpec.methodBuilder("isInstalled")
Expand Down Expand Up @@ -134,9 +145,17 @@ private TypeSpec createModuleClassSpec(

MethodSpec constructor =
MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE).build();
AnnotationSpec generatedAnnotation =
AnnotationSpec.builder(Generated.class)
.addMember("value",
String.format("\"%s\"",
ModuleInterfaceProcessor.class.getCanonicalName()))
.build();

return TypeSpec.classBuilder(fooModuleClassName)
.addAnnotation(generatedAnnotation)
.addModifiers(Modifier.PUBLIC)
.addField(classNameString)
.addField(module)
.addMethod(constructor)
.addMethod(isInstalled)
Expand Down
4 changes: 0 additions & 4 deletions docs/android_dynamic_feature_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ Next, define an implementation that goes into the module in the new file
package org.chromium.chrome.browser.foo;

import org.chromium.base.Log;
import org.chromium.base.annotations.UsedByReflection;

@UsedByReflection("FooModule")
public class FooImpl implements Foo {
@Override
public void bar() {
Expand Down Expand Up @@ -713,10 +711,8 @@ package org.chromium.chrome.browser.foo;

import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.chrome.browser.foo.R;

@UsedByReflection("FooModule")
public class FooImpl implements Foo {
@Override
public void bar() {
Expand Down

0 comments on commit bd22e61

Please sign in to comment.