The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os; |
| 18 | |
| 19 | import java.io.File; |
| 20 | |
| 21 | /** |
| 22 | * Provides access to environment variables. |
| 23 | */ |
| 24 | public class Environment { |
| 25 | |
| 26 | private static final File ROOT_DIRECTORY |
| 27 | = getDirectory("ANDROID_ROOT", "/system"); |
| 28 | |
| 29 | /** |
| 30 | * Gets the Android root directory. |
| 31 | */ |
| 32 | public static File getRootDirectory() { |
| 33 | return ROOT_DIRECTORY; |
| 34 | } |
| 35 | |
| 36 | private static final File DATA_DIRECTORY |
| 37 | = getDirectory("ANDROID_DATA", "/data"); |
| 38 | |
| 39 | private static final File EXTERNAL_STORAGE_DIRECTORY |
| 40 | = getDirectory("EXTERNAL_STORAGE", "/sdcard"); |
| 41 | |
| 42 | private static final File DOWNLOAD_CACHE_DIRECTORY |
| 43 | = getDirectory("DOWNLOAD_CACHE", "/cache"); |
| 44 | |
| 45 | /** |
| 46 | * Gets the Android data directory. |
| 47 | */ |
| 48 | public static File getDataDirectory() { |
| 49 | return DATA_DIRECTORY; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Gets the Android external storage directory. |
| 54 | */ |
| 55 | public static File getExternalStorageDirectory() { |
| 56 | return EXTERNAL_STORAGE_DIRECTORY; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Gets the Android Download/Cache content directory. |
| 61 | */ |
| 62 | public static File getDownloadCacheDirectory() { |
| 63 | return DOWNLOAD_CACHE_DIRECTORY; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * getExternalStorageState() returns MEDIA_REMOVED if the media is not present. |
| 68 | */ |
| 69 | public static final String MEDIA_REMOVED = "removed"; |
| 70 | |
| 71 | /** |
| 72 | * getExternalStorageState() returns MEDIA_UNMOUNTED if the media is present |
| 73 | * but not mounted. |
| 74 | */ |
| 75 | public static final String MEDIA_UNMOUNTED = "unmounted"; |
| 76 | |
| 77 | /** |
| 78 | * getExternalStorageState() returns MEDIA_CHECKING if the media is present |
| 79 | * and being disk-checked |
| 80 | */ |
| 81 | public static final String MEDIA_CHECKING = "checking"; |
| 82 | |
| 83 | /** |
| 84 | * getExternalStorageState() returns MEDIA_NOFS if the media is present |
| 85 | * but is blank or is using an unsupported filesystem |
| 86 | */ |
| 87 | public static final String MEDIA_NOFS = "nofs"; |
| 88 | |
| 89 | /** |
| 90 | * getExternalStorageState() returns MEDIA_MOUNTED if the media is present |
| 91 | * and mounted at its mount point with read/write access. |
| 92 | */ |
| 93 | public static final String MEDIA_MOUNTED = "mounted"; |
| 94 | |
| 95 | /** |
| 96 | * getExternalStorageState() returns MEDIA_MOUNTED_READ_ONLY if the media is present |
| 97 | * and mounted at its mount point with read only access. |
| 98 | */ |
| 99 | public static final String MEDIA_MOUNTED_READ_ONLY = "mounted_ro"; |
| 100 | |
| 101 | /** |
| 102 | * getExternalStorageState() returns MEDIA_SHARED if the media is present |
| 103 | * not mounted, and shared via USB mass storage. |
| 104 | */ |
| 105 | public static final String MEDIA_SHARED = "shared"; |
| 106 | |
| 107 | /** |
| 108 | * getExternalStorageState() returns MEDIA_BAD_REMOVAL if the media was |
| 109 | * removed before it was unmounted. |
| 110 | */ |
| 111 | public static final String MEDIA_BAD_REMOVAL = "bad_removal"; |
| 112 | |
| 113 | /** |
| 114 | * getExternalStorageState() returns MEDIA_UNMOUNTABLE if the media is present |
| 115 | * but cannot be mounted. Typically this happens if the file system on the |
| 116 | * media is corrupted. |
| 117 | */ |
| 118 | public static final String MEDIA_UNMOUNTABLE = "unmountable"; |
| 119 | |
| 120 | /** |
| 121 | * Gets the current state of the external storage device. |
| 122 | */ |
| 123 | public static String getExternalStorageState() { |
| 124 | return SystemProperties.get("EXTERNAL_STORAGE_STATE", MEDIA_REMOVED); |
| 125 | } |
| 126 | |
| 127 | static File getDirectory(String variableName, String defaultPath) { |
| 128 | String path = System.getenv(variableName); |
| 129 | return path == null ? new File(defaultPath) : new File(path); |
| 130 | } |
| 131 | } |