[go: up one dir, main page]

Fix module install

Previously, we created a SplitInstallManager _before_ calling
SplitCompat.install(-), which breaks the module install flow on Android
pre-Q.

(cherry picked from commit 801cc00b4ec48cfcfbbd48a441d59d48892f7c48)

Bug: b/133669491
Change-Id: I0b317732ed364a592047eeb7387c74dd1ea1b258
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1646903
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: Christopher Grant <cjgrant@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#668416}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1658958
Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#295}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java b/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java
index c87f1d36..d01bc2c 100644
--- a/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java
+++ b/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java
@@ -40,6 +40,7 @@
 
     /** Needs to be called before trying to access a module. */
     public static void init() {
+        if (sSplitCompatted) return;
         // SplitCompat.install may copy modules into Chrome's internal folder or clean them up.
         try (StrictModeContext unused = StrictModeContext.allowDiskWrites()) {
             SplitCompat.install(ContextUtils.getApplicationContext());
diff --git a/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java b/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java
index 447be85..8b7a346 100644
--- a/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java
+++ b/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java
@@ -91,6 +91,8 @@
 
     /** Records via UMA all modules that have been requested and are currently installed. */
     public static void recordModuleAvailability() {
+        // MUST call init before creating a SplitInstallManager.
+        ModuleInstaller.init();
         SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
         Set<String> requestedModules = new HashSet<>();
         requestedModules.addAll(
@@ -124,6 +126,8 @@
 
     public PlayCoreModuleInstallerBackend(OnFinishedListener listener) {
         super(listener);
+        // MUST call init before creating a SplitInstallManager.
+        ModuleInstaller.init();
         mManager = SplitInstallManagerFactory.create(ContextUtils.getApplicationContext());
         mManager.registerListener(this);
     }