Skip to content

Commit

Permalink
Modified installInternal to produce correct return value
Browse files Browse the repository at this point in the history
Fix installInternal logic so that it returns false if no apks of the
specified module were installed

Bug: 939380
Change-Id: I7f3986dd82370afb5d671df299208de52900ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1509796
Commit-Queue: Anthony Cui <cuianthony@google.com>
Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#639179}
  • Loading branch information
Anthony Cui authored and Commit Bot committed Mar 8, 2019
1 parent a86e86d commit ac78d53
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ private boolean installInternal(String moduleName) {
// Get list of all files at path where SplitCompat looks for downloaded modules.
// May change in future releases of the Play Core SDK.
File[] srcModuleFiles = new File(MODULES_SRC_DIRECTORY_PATH).listFiles();
// 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.
if (srcModuleFile.getName().endsWith(".apk")) {
// 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",
srcModuleFile.getName());
Integer.toString(versionCode), "unverified-splits", srcModuleFileName);

// NOTE: Need to give Chrome storage permission for this to work.
try {
Expand All @@ -95,13 +97,22 @@ private boolean installInternal(String moduleName) {
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;
}
}
}

if (no_module_apks_installed) {
return false;
}

// Check that the module's signature matches Chrome's.
try {
Verifier verifier = new Verifier(context);
Expand Down

0 comments on commit ac78d53

Please sign in to comment.