From 92d570529c72c00ab456521a5b0237f62a6abdf5 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Thu, 23 Aug 2012 10:07:52 -0700 Subject: [PATCH] Handle null cache directory data/android directory doesn't exist sometimes, and hence cache directory creation fails. Don't crash the process due to that. Change-Id: I22d7ed5df9c70f021a87029e89a13a11b4b0303b --- core/java/android/app/ActivityThread.java | 12 ++++++++---- core/java/android/app/ContextImpl.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 28c5abd475270..b8e16c5a7cc93 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4070,10 +4070,14 @@ public final class ActivityThread { if (!Process.isIsolated()) { final File cacheDir = appContext.getCacheDir(); - // Provide a usable directory for temporary files - System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); - - setupGraphicsSupport(data.info, cacheDir); + if (cacheDir != null) { + // Provide a usable directory for temporary files + System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); + + setupGraphicsSupport(data.info, cacheDir); + } else { + Log.e(TAG, "Unable to setupGraphicsSupport due to missing cache directory"); + } } /** * For system applications on userdebug/eng builds, log stack diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 0543f0570cbd0..112ce987e23eb 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -769,7 +769,7 @@ class ContextImpl extends Context { } if (!mCacheDir.exists()) { if(!mCacheDir.mkdirs()) { - Log.w(TAG, "Unable to create cache directory"); + Log.w(TAG, "Unable to create cache directory " + mCacheDir.getAbsolutePath()); return null; } FileUtils.setPermissions(