diff options
author | Xavier Ducrohet <xav@android.com> | 2009-08-13 17:26:37 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2009-08-13 21:10:01 -0700 |
commit | 94fdabe399ee3b69d2dd0d622149b698c4a1171f (patch) | |
tree | 3cc96438b46c211f0325cbe4d48947a5b410854c /androidprefs | |
parent | e2783fe1e42f9cff6a2cff909ba6ea5f541e2e29 (diff) | |
download | sdk-94fdabe399ee3b69d2dd0d622149b698c4a1171f.zip sdk-94fdabe399ee3b69d2dd0d622149b698c4a1171f.tar.gz sdk-94fdabe399ee3b69d2dd0d622149b698c4a1171f.tar.bz2 |
Make sure that the android pref folder is always present when queried.
BUG: 2053511
Diffstat (limited to 'androidprefs')
-rw-r--r-- | androidprefs/src/com/android/prefs/AndroidLocation.java | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/androidprefs/src/com/android/prefs/AndroidLocation.java b/androidprefs/src/com/android/prefs/AndroidLocation.java index cfd9f53..446c426 100644 --- a/androidprefs/src/com/android/prefs/AndroidLocation.java +++ b/androidprefs/src/com/android/prefs/AndroidLocation.java @@ -37,34 +37,44 @@ public final class AndroidLocation { super(string); } } - + private static String sPrefsLocation = null; - + /** * Returns the folder used to store android related files. * @return an OS specific path, terminated by a separator. - * @throws AndroidLocationException + * @throws AndroidLocationException */ public final static String getFolder() throws AndroidLocationException { if (sPrefsLocation == null) { String home = findValidPath("ANDROID_SDK_HOME", "user.home", "HOME"); - + // if the above failed, we throw an exception. if (home == null) { throw new AndroidLocationException( "Unable to get the home directory. Make sure the user.home property is set up"); } else { sPrefsLocation = home + File.separator + ".android" + File.separator; + } + } - // make sure the folder exists! - File f = new File(sPrefsLocation); - if (f.exists() == false) { - f.mkdir(); - } else if (f.isFile()) { - throw new AndroidLocationException(sPrefsLocation + - " is not a directory! This is required to run Android tools."); - } + // make sure the folder exists! + File f = new File(sPrefsLocation); + if (f.exists() == false) { + try { + f.mkdir(); + } catch (SecurityException e) { + AndroidLocationException e2 = new AndroidLocationException(String.format( + "Unable to create folder '%1$s'. " + + "This is the path of preference folder expected by the Android tools.", + sPrefsLocation)); + e2.initCause(e); + throw e2; } + } else if (f.isFile()) { + throw new AndroidLocationException(sPrefsLocation + + " is not a directory! " + + "This is the path of preference folder expected by the Android tools."); } return sPrefsLocation; @@ -92,7 +102,7 @@ public final class AndroidLocation { } } } - + return null; } } |