Commit 33e550a7 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Reduce visibility of ModuleInstallerImpl

Making ModuleInstallerImpl package-private ensures that callers use the
ModuleInstaller interface instead of depending directly on the
implementation.

Also add stricter parameters and requirements for
ModuleInstaller#initActivity to ensure that SplitCompat#install is
called in the right order (Application first then Activities).

Add /* package */ to classes only used within its package, remove some
redundant public method modifiers in interfaces since all methods in
interfaces are public by default.

Bug: 981084
Change-Id: I4826b2d716fb04fea8b59ed2eff14eb72c843ec7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761048
Commit-Queue: Peter Wen <wnwen@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688265}
parent 24dd8237
......@@ -4,7 +4,7 @@
package org.chromium.components.module_installer;
import android.content.Context;
import android.app.Activity;
import org.chromium.base.VisibleForTesting;
......@@ -32,8 +32,9 @@ public interface ModuleInstaller {
*
* For details, see:
* https://developer.android.com/reference/com/google/android/play/core/splitcompat/SplitCompat.html#install(android.content.Context)
* @param activity The Activity for which SplitCompat will be run.
*/
default void initActivity(Context context) {}
default void initActivity(Activity activity) {}
/**
* Records via UMA all modules that have been requested and are currently installed. The intent
......
......@@ -17,7 +17,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE)
public @interface ModuleInterface {
/** The name of the module. */
public String module();
String module();
/** The fully qualified name of the module's interface implementation. */
public String impl();
String impl();
}
......@@ -11,8 +11,8 @@ import org.chromium.components.module_installer.ModuleInstaller;
import java.util.List;
/** Interface outlining the necessary strategy to load activities and install modules. */
interface ObserverStrategy {
public ModuleInstaller getModuleInstaller();
public List<Activity> getRunningActivities();
public int getStateForActivity(Activity activity);
/* package */ interface ObserverStrategy {
ModuleInstaller getModuleInstaller();
List<Activity> getRunningActivities();
int getStateForActivity(Activity activity);
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ import org.chromium.components.module_installer.ModuleInstaller;
import java.util.List;
/** Strategy utilizing ModuleInstaller and ApplicationStatus. */
class ObserverStrategyImpl implements ObserverStrategy {
/* package */ class ObserverStrategyImpl implements ObserverStrategy {
@Override
public ModuleInstaller getModuleInstaller() {
return ModuleInstaller.getInstance();
......
......@@ -4,6 +4,7 @@
package org.chromium.components.module_installer;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
......@@ -33,7 +34,7 @@ import java.util.TreeSet;
/** Installs dynamic feature modules (DFMs). */
@MainDex
public class ModuleInstallerImpl implements ModuleInstaller {
/* package */ class ModuleInstallerImpl implements ModuleInstaller {
/** Command line switch for activating the fake backend. */
private static final String FAKE_FEATURE_MODULE_INSTALL = "fake-feature-module-install";
private static ModuleInstaller sInstance = new ModuleInstallerImpl();
......@@ -65,8 +66,11 @@ public class ModuleInstallerImpl implements ModuleInstaller {
}
@Override
public void initActivity(Context context) {
SplitCompat.install(context);
public void initActivity(Activity activity) {
// SplitCompat#install should always be run for the application first before it is run for
// any activities.
init();
SplitCompat.install(activity);
}
@Override
......
......@@ -8,7 +8,7 @@ import org.chromium.base.annotations.MainDex;
/** Dummy fallback of ModuleInstaller for APK builds. */
@MainDex
public class ModuleInstallerImpl implements ModuleInstaller {
/* package */ class ModuleInstallerImpl implements ModuleInstaller {
/** A valid singleton instance is necessary for tests to swap it out. */
private static ModuleInstaller sInstance = new ModuleInstallerImpl();
......
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