diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-16 09:59:13 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-20 10:28:53 +0000 |
commit | 6c11fb357ec39bf087b8b632e2b1e375aef1b38b (patch) | |
tree | c8315530db18a8ee566521c39ab8a6af4f72bc03 /chromium/components/module_installer | |
parent | 3ffaed019d0772e59d6cdb2d0d32fe4834c31f72 (diff) | |
download | qtwebengine-chromium-6c11fb357ec39bf087b8b632e2b1e375aef1b38b.tar.gz |
BASELINE: Update Chromium to 74.0.3729.159
Change-Id: I8d2497da544c275415aedd94dd25328d555de811
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/module_installer')
5 files changed, 77 insertions, 17 deletions
diff --git a/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/FakeModuleInstallerBackend.java b/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/FakeModuleInstallerBackend.java index 84785b31354..dae242dc9b5 100644 --- a/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/FakeModuleInstallerBackend.java +++ b/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/FakeModuleInstallerBackend.java @@ -71,25 +71,65 @@ class FakeModuleInstallerBackend extends ModuleInstallerBackend { private boolean installInternal(String moduleName) { Context context = ContextUtils.getApplicationContext(); int versionCode = BuildInfo.getInstance().versionCode; - // Path where SplitCompat looks for downloaded modules. May change in future releases of - // the Play Core SDK. - File dstModuleFile = joinPaths(context.getFilesDir().getPath(), "splitcompat", - Integer.toString(versionCode), "unverified-splits", moduleName + ".apk"); - File srcModuleFile = joinPaths(MODULES_SRC_DIRECTORY_PATH, moduleName + ".apk"); - // NOTE: Need to give Chrome storage permission for this to work. - try { - dstModuleFile.getParentFile().mkdirs(); - } catch (SecurityException e) { - Log.e(TAG, "Failed to create module dir", e); + // Get list of all files at path where SplitCompat looks for downloaded modules. + // May change in future releases of the Play Core SDK. + File srcModuleDir = new File(MODULES_SRC_DIRECTORY_PATH); + if (!srcModuleDir.exists()) { + Log.e(TAG, "Modules source directory does not exist"); + return false; + } + if (!srcModuleDir.canRead()) { + Log.e(TAG, "Cannot read modules source directory"); + return false; + } + if (!srcModuleDir.isDirectory()) { + Log.e(TAG, "Modules source directory is not a directory"); return false; } + File[] srcModuleFiles = srcModuleDir.listFiles(); + if (srcModuleFiles == null) { + Log.e(TAG, "Cannot get list of files in modules source directory"); + return false; + } + + // Check if any apks for the module are actually installed. + boolean no_module_apks_installed = true; + + for (File srcModuleFile : srcModuleFiles) { + // Take only source APK files of the specified module. + String srcModuleFileName = srcModuleFile.getName(); + if (srcModuleFileName.endsWith(".apk") && srcModuleFileName.startsWith(moduleName)) { + // Construct destination file corresponding to each source file. + File dstModuleFile = joinPaths(context.getFilesDir().getPath(), "splitcompat", + Integer.toString(versionCode), "unverified-splits", srcModuleFileName); + + // NOTE: Need to give Chrome storage permission for this to work. + try { + dstModuleFile.getParentFile().mkdirs(); + } catch (SecurityException e) { + Log.e(TAG, "Failed to create module dir %s", dstModuleFile.getName(), e); + return false; + } + + try (FileInputStream istream = new FileInputStream(srcModuleFile); + FileOutputStream ostream = new FileOutputStream(dstModuleFile)) { + ostream.getChannel().transferFrom( + istream.getChannel(), 0, istream.getChannel().size()); + if (srcModuleFileName.equals(moduleName + ".apk")) { + // Base apk of the module must be installed for install + // to be successful. + no_module_apks_installed = false; + } + } catch (RuntimeException | IOException e) { + Log.e(TAG, "Failed to install module apk %s", dstModuleFile.getName(), e); + return false; + } + } + } - try (FileInputStream istream = new FileInputStream(srcModuleFile); - FileOutputStream ostream = new FileOutputStream(dstModuleFile)) { - ostream.getChannel().transferFrom(istream.getChannel(), 0, istream.getChannel().size()); - } catch (RuntimeException | IOException e) { - Log.e(TAG, "Failed to install module", e); + if (no_module_apks_installed) { + Log.e(TAG, "Did not find any module APKs"); return false; } diff --git a/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java b/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java index 85d1b67997f..879472a2a94 100644 --- a/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java +++ b/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/ModuleInstaller.java @@ -49,6 +49,17 @@ public class ModuleInstaller { updateCrashKeys(); } + /** + * Needs to be called in attachBaseContext of the activities that want to have access to + * splits prior to application restart. + * + * For details, see: + * https://developer.android.com/reference/com/google/android/play/core/splitcompat/SplitCompat.html#install(android.content.Context) + */ + public static void initActivity(Context context) { + SplitCompat.install(context); + } + /** Writes fully installed and emulated modules to crash keys. */ public static void updateCrashKeys() { Context context = ContextUtils.getApplicationContext(); diff --git a/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java b/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java index 4061ba538bd..d28467b5149 100644 --- a/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java +++ b/chromium/components/module_installer/android/java/src-impl/org/chromium/components/module_installer/PlayCoreModuleInstallerBackend.java @@ -25,7 +25,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.TimeUnit; /** * Backend that uses the Play Core SDK to download a module from Play and install it subsequently. @@ -132,7 +131,7 @@ import java.util.concurrent.TimeUnit; moduleInfo.second ? "CachedInstallDuration" : "UncachedInstallDuration"; RecordHistogram.recordLongTimesHistogram( "Android.FeatureModules." + histogramSubname + "." + name, - installDurationMs, TimeUnit.MILLISECONDS); + installDurationMs); } } onFinished(success, moduleNames); diff --git a/chromium/components/module_installer/android/java/src-stub/org/chromium/components/module_installer/ModuleInstaller.java b/chromium/components/module_installer/android/java/src-stub/org/chromium/components/module_installer/ModuleInstaller.java index 65ee45b16b6..5dd14d3090d 100644 --- a/chromium/components/module_installer/android/java/src-stub/org/chromium/components/module_installer/ModuleInstaller.java +++ b/chromium/components/module_installer/android/java/src-stub/org/chromium/components/module_installer/ModuleInstaller.java @@ -4,11 +4,16 @@ package org.chromium.components.module_installer; +import android.content.Context; + import org.chromium.base.VisibleForTesting; /** Dummy fallback of ModuleInstaller for APK builds. */ public class ModuleInstaller { public static void init() {} + + public static void initActivity(Context context) {} + public static void updateCrashKeys(){}; public static void install( diff --git a/chromium/components/module_installer/android/java/src-test/org/chromium/components/module_installer/ModuleInstaller.java b/chromium/components/module_installer/android/java/src-test/org/chromium/components/module_installer/ModuleInstaller.java index 9df2a242004..720b8e8d235 100644 --- a/chromium/components/module_installer/android/java/src-test/org/chromium/components/module_installer/ModuleInstaller.java +++ b/chromium/components/module_installer/android/java/src-test/org/chromium/components/module_installer/ModuleInstaller.java @@ -4,6 +4,8 @@ package org.chromium.components.module_installer; +import android.content.Context; + import org.chromium.base.VisibleForTesting; import java.util.HashSet; @@ -14,6 +16,9 @@ public class ModuleInstaller { private static Set<String> sModulesRequestedDeffered = new HashSet<>(); public static void init() {} + + public static void initActivity(Context context) {} + public static void updateCrashKeys(){}; public static void install( |