diff options
| author | 2016-11-29 11:56:24 +0000 | |
|---|---|---|
| committer | 2016-11-29 11:56:29 +0000 | |
| commit | 6aef541c52890e655d2633212e13ffb9488f7d3c (patch) | |
| tree | a00c5021e861ccb272f3ee202fd99287f485db28 | |
| parent | 69d9aec7c848e3d00d0efae3a6c7cfcde231490b (diff) | |
| parent | bdcdeb4cc470130db9ddb7abe7763c2170755e22 (diff) | |
Merge "PackageManager: Avoid unnecessary calls to derivePackageAbi during boot scans"
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageManagerService.java | 74 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageSettingBase.java | 6 |
2 files changed, 55 insertions, 25 deletions
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index c1bc6182a86b..f5b4b9b400f3 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -402,8 +402,8 @@ public class PackageManagerService extends IPackageManager.Stub { static final int SCAN_CHECK_ONLY = 1<<13; static final int SCAN_DONT_KILL_APP = 1<<14; static final int SCAN_IGNORE_FROZEN = 1<<15; - static final int REMOVE_CHATTY = 1<<16; + static final int SCAN_FIRST_BOOT_OR_UPGRADE = 1<<17; private static final int[] EMPTY_INT_ARRAY = new int[0]; @@ -2215,10 +2215,6 @@ public class PackageManagerService extends IPackageManager.Stub { EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SYSTEM_SCAN_START, startTime); - // Set flag to monitor and not change apk file paths when - // scanning install directories. - final int scanFlags = SCAN_BOOTING | SCAN_INITIAL; - final String bootClassPath = System.getenv("BOOTCLASSPATH"); final String systemServerClassPath = System.getenv("SYSTEMSERVERCLASSPATH"); @@ -2303,6 +2299,14 @@ public class PackageManagerService extends IPackageManager.Stub { } } + // Set flag to monitor and not change apk file paths when + // scanning install directories. + int scanFlags = SCAN_BOOTING | SCAN_INITIAL; + + if (mIsUpgrade || mFirstBoot) { + scanFlags = scanFlags | SCAN_FIRST_BOOT_OR_UPGRADE; + } + // Collect vendor overlay packages. (Do this before scanning any apps.) // For security and version matching reason, only consider // overlay packages if they reside in the right directory. @@ -8082,6 +8086,11 @@ public class PackageManagerService extends IPackageManager.Stub { // old setting to restore at the end. PackageSetting nonMutatedPs = null; + // We keep references to the derived CPU Abis from settings in oder to reuse + // them in the case where we're not upgrading or booting for the first time. + String primaryCpuAbiFromSettings = null; + String secondaryCpuAbiFromSettings = null; + // writer synchronized (mPackages) { if (pkg.mSharedUserId != null) { @@ -8158,6 +8167,14 @@ public class PackageManagerService extends IPackageManager.Stub { } } + if ((scanFlags & SCAN_FIRST_BOOT_OR_UPGRADE) == 0) { + PackageSetting foundPs = mSettings.getPackageLPr(pkg.packageName); + if (foundPs != null) { + primaryCpuAbiFromSettings = foundPs.primaryCpuAbiString; + secondaryCpuAbiFromSettings = foundPs.secondaryCpuAbiString; + } + } + pkgSetting = mSettings.getPackageLPr(pkg.packageName); if (pkgSetting != null && pkgSetting.sharedUser != suid) { PackageManagerService.reportSettingsProblem(Log.WARN, @@ -8190,7 +8207,11 @@ public class PackageManagerService extends IPackageManager.Stub { } mSettings.addUserToSettingLPw(pkgSetting); } else { - // REMOVE SharedUserSetting from method; update in a separate call + // REMOVE SharedUserSetting from method; update in a separate call. + // + // TODO(narayan): This update is bogus. nativeLibraryDir & primaryCpuAbi, + // secondaryCpuAbi are not known at this point so we always update them + // to null here, only to reset them at a later point. Settings.updatePackageSetting(pkgSetting, disabledPkgSetting, suid, destCodeFile, pkg.applicationInfo.nativeLibraryDir, pkg.applicationInfo.primaryCpuAbi, pkg.applicationInfo.secondaryCpuAbi, pkg.applicationInfo.flags, @@ -8329,18 +8350,34 @@ public class PackageManagerService extends IPackageManager.Stub { final String cpuAbiOverride = deriveAbiOverride(pkg.cpuAbiOverride, pkgSetting); if ((scanFlags & SCAN_NEW_INSTALL) == 0) { - Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "derivePackageAbi"); - derivePackageAbi( - pkg, scanFile, cpuAbiOverride, true /*extractLibs*/, mAppLib32InstallDir); - Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); + if ((scanFlags & SCAN_FIRST_BOOT_OR_UPGRADE) != 0) { + Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "derivePackageAbi"); + derivePackageAbi( + pkg, scanFile, cpuAbiOverride, true /*extractLibs*/, mAppLib32InstallDir); + Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); + + // Some system apps still use directory structure for native libraries + // in which case we might end up not detecting abi solely based on apk + // structure. Try to detect abi based on directory structure. + if (isSystemApp(pkg) && !pkg.isUpdatedSystemApp() && + pkg.applicationInfo.primaryCpuAbi == null) { + setBundledAppAbisAndRoots(pkg, pkgSetting); + setNativeLibraryPaths(pkg, mAppLib32InstallDir); + } + } else { + // This is not a first boot or an upgrade, don't bother deriving the + // ABI during the scan. Instead, trust the value that was stored in the + // package setting. + pkg.applicationInfo.primaryCpuAbi = primaryCpuAbiFromSettings; + pkg.applicationInfo.secondaryCpuAbi = secondaryCpuAbiFromSettings; - // Some system apps still use directory structure for native libraries - // in which case we might end up not detecting abi solely based on apk - // structure. Try to detect abi based on directory structure. - if (isSystemApp(pkg) && !pkg.isUpdatedSystemApp() && - pkg.applicationInfo.primaryCpuAbi == null) { - setBundledAppAbisAndRoots(pkg, pkgSetting); setNativeLibraryPaths(pkg, mAppLib32InstallDir); + + if (DEBUG_ABI_SELECTION) { + Slog.i(TAG, "Using ABIS and native lib paths from settings : " + + pkg.packageName + " " + pkg.applicationInfo.primaryCpuAbi + ", " + + pkg.applicationInfo.secondaryCpuAbi); + } } } else { if ((scanFlags & SCAN_MOVE) != 0) { @@ -9195,11 +9232,6 @@ public class PackageManagerService extends IPackageManager.Stub { String cpuAbiOverride, boolean extractLibs, File appLib32InstallDir) throws PackageManagerException { - // TODO: We can probably be smarter about this stuff. For installed apps, - // we can calculate this information at install time once and for all. For - // system apps, we can probably assume that this information doesn't change - // after the first boot scan. As things stand, we do lots of unnecessary work. - // Give ourselves some initial paths; we'll come back for another // pass once we've determined ABI below. setNativeLibraryPaths(pkg, appLib32InstallDir); diff --git a/services/core/java/com/android/server/pm/PackageSettingBase.java b/services/core/java/com/android/server/pm/PackageSettingBase.java index 3ad2ae1a97ea..6089d2eba960 100644 --- a/services/core/java/com/android/server/pm/PackageSettingBase.java +++ b/services/core/java/com/android/server/pm/PackageSettingBase.java @@ -76,14 +76,12 @@ abstract class PackageSettingBase extends SettingBase { String legacyNativeLibraryPathString; /** - * The primary CPU abi for this package. This value is regenerated at every - * boot scan. + * The primary CPU abi for this package. */ String primaryCpuAbiString; /** - * The secondary CPU abi for this package. This value is regenerated at every - * boot scan. + * The secondary CPU abi for this package. */ String secondaryCpuAbiString; |