PackageManager: Avoid null access

In case cache creation fails, mCacheDir may be null. Avoid an
access.

Bug: 74087079
Test: m
Test: boot under low-space condition
Change-Id: I55836c820ef2c3431e8f06224d6f9edf0e9881ef
This commit is contained in:
Andreas Gampe
2018-03-05 17:46:25 -08:00
parent 8cdc0da9ad
commit 9f292ce7f2

View File

@@ -3375,6 +3375,13 @@ public class PackageManagerService extends IPackageManager.Stub
// "/data/system/package_cache/1"
File cacheDir = FileUtils.createDir(cacheBaseDir, PACKAGE_PARSER_CACHE_VERSION);
if (cacheDir == null) {
// Something went wrong. Attempt to delete everything and return.
Slog.wtf(TAG, "Cache directory cannot be created - wiping base dir " + cacheBaseDir);
FileUtils.deleteContentsAndDir(cacheBaseDir);
return null;
}
// The following is a workaround to aid development on non-numbered userdebug
// builds or cases where "adb sync" is used on userdebug builds. If we detect that
// the system partition is newer.