Skip to content

Commit 24a0308

Browse files
digit-androidandroid-build SharedAccount
authored andcommitted
PackageManagerService: always install native binaries from .apk
The previous implementation fails to work properly when the .apk and installed versions of the binaries have the same size and date. Change-Id: I063817a935da9ad459858d7eec8bb3d940607850
1 parent 3b70e15 commit 24a0308

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

services/java/com/android/server/PackageManagerService.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,21 +3623,19 @@ private int cachePackageSharedLibsForAbiLI(PackageParser.Package pkg,
36233623

36243624
installedNativeLibraries = true;
36253625

3626+
// Always extract the shared library
36263627
String sharedLibraryFilePath = sharedLibraryDir.getPath() +
36273628
File.separator + libFileName;
36283629
File sharedLibraryFile = new File(sharedLibraryFilePath);
3629-
if (! sharedLibraryFile.exists() ||
3630-
sharedLibraryFile.length() != entry.getSize() ||
3631-
sharedLibraryFile.lastModified() != entry.getTime()) {
3632-
if (Config.LOGD) {
3633-
Log.d(TAG, "Caching shared lib " + entry.getName());
3634-
}
3635-
if (mInstaller == null) {
3636-
sharedLibraryDir.mkdir();
3637-
}
3638-
cacheNativeBinaryLI(pkg, zipFile, entry, sharedLibraryDir,
3639-
sharedLibraryFile);
3630+
3631+
if (Config.LOGD) {
3632+
Log.d(TAG, "Caching shared lib " + entry.getName());
36403633
}
3634+
if (mInstaller == null) {
3635+
sharedLibraryDir.mkdir();
3636+
}
3637+
cacheNativeBinaryLI(pkg, zipFile, entry, sharedLibraryDir,
3638+
sharedLibraryFile);
36413639
}
36423640
if (!hasNativeLibraries)
36433641
return PACKAGE_INSTALL_NATIVE_NO_LIBRARIES;
@@ -3679,18 +3677,16 @@ private int cachePackageGdbServerLI(PackageParser.Package pkg,
36793677
String installGdbServerPath = installGdbServerDir.getPath() +
36803678
"/" + GDBSERVER;
36813679
File installGdbServerFile = new File(installGdbServerPath);
3682-
if (! installGdbServerFile.exists() ||
3683-
installGdbServerFile.length() != entry.getSize() ||
3684-
installGdbServerFile.lastModified() != entry.getTime()) {
3685-
if (Config.LOGD) {
3686-
Log.d(TAG, "Caching gdbserver " + entry.getName());
3687-
}
3688-
if (mInstaller == null) {
3689-
installGdbServerDir.mkdir();
3690-
}
3691-
cacheNativeBinaryLI(pkg, zipFile, entry, installGdbServerDir,
3692-
installGdbServerFile);
3680+
3681+
if (Config.LOGD) {
3682+
Log.d(TAG, "Caching gdbserver " + entry.getName());
3683+
}
3684+
if (mInstaller == null) {
3685+
installGdbServerDir.mkdir();
36933686
}
3687+
cacheNativeBinaryLI(pkg, zipFile, entry, installGdbServerDir,
3688+
installGdbServerFile);
3689+
36943690
return PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES;
36953691
}
36963692
return PACKAGE_INSTALL_NATIVE_NO_LIBRARIES;
@@ -3704,6 +3700,16 @@ private int cachePackageGdbServerLI(PackageParser.Package pkg,
37043700
// one if ro.product.cpu.abi2 is defined.
37053701
//
37063702
private int cachePackageSharedLibsLI(PackageParser.Package pkg, File scanFile) {
3703+
// Remove all native binaries from a directory. This is used when upgrading
3704+
// a package: in case the new .apk doesn't contain a native binary that was
3705+
// in the old one (and thus installed), we need to remove it from
3706+
// /data/data/<appname>/lib
3707+
//
3708+
// The simplest way to do that is to remove all files in this directory,
3709+
// since it is owned by "system", applications are not supposed to write
3710+
// anything there.
3711+
removeNativeBinariesLI(pkg);
3712+
37073713
String cpuAbi = Build.CPU_ABI;
37083714
try {
37093715
int result = cachePackageSharedLibsForAbiLI(pkg, scanFile, cpuAbi);

0 commit comments

Comments
 (0)