blob: 54e2c0b681cb490d61ed28b732378fd945f36667 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.os;
18
Jeff Sharkey4ca728c2014-01-10 16:27:19 -080019import android.app.admin.DevicePolicyManager;
Jeff Sharkey1abdb712013-08-11 16:28:14 -070020import android.content.Context;
San Mehatb1043402010-02-05 08:26:50 -080021import android.os.storage.IMountService;
Mike Lockwood2f6a3882011-05-09 19:08:06 -070022import android.os.storage.StorageVolume;
Jeff Sharkeyb049e212012-09-07 23:16:01 -070023import android.text.TextUtils;
Kenny Rootb2278dc2011-01-18 13:03:28 -080024import android.util.Log;
San Mehat7fd0fee2009-12-17 07:12:23 -080025
Jeff Sharkey44cbdec2013-10-07 16:49:47 -070026import com.google.android.collect.Lists;
Jeff Sharkey8b2c3a142012-11-12 11:45:05 -080027
Gilles Debunneee1d6302011-05-13 10:09:32 -070028import java.io.File;
Jeff Sharkey63d0a062013-03-01 16:12:55 -080029import java.io.IOException;
Jeff Sharkey44cbdec2013-10-07 16:49:47 -070030import java.util.ArrayList;
Gilles Debunneee1d6302011-05-13 10:09:32 -070031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032/**
33 * Provides access to environment variables.
34 */
35public class Environment {
Kenny Rootb2278dc2011-01-18 13:03:28 -080036 private static final String TAG = "Environment";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Jeff Sharkeyb049e212012-09-07 23:16:01 -070038 private static final String ENV_EXTERNAL_STORAGE = "EXTERNAL_STORAGE";
Jeff Sharkey4fbbda42012-09-24 18:34:07 -070039 private static final String ENV_EMULATED_STORAGE_SOURCE = "EMULATED_STORAGE_SOURCE";
Jeff Sharkeyb049e212012-09-07 23:16:01 -070040 private static final String ENV_EMULATED_STORAGE_TARGET = "EMULATED_STORAGE_TARGET";
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -070041 private static final String ENV_MEDIA_STORAGE = "MEDIA_STORAGE";
Jeff Sharkey44cbdec2013-10-07 16:49:47 -070042 private static final String ENV_SECONDARY_STORAGE = "SECONDARY_STORAGE";
Jeff Sharkey63d0a062013-03-01 16:12:55 -080043 private static final String ENV_ANDROID_ROOT = "ANDROID_ROOT";
Jeff Sharkeyb049e212012-09-07 23:16:01 -070044
Jeff Sharkeydfa45302012-09-12 16:25:22 -070045 /** {@hide} */
Jeff Sharkey1abdb712013-08-11 16:28:14 -070046 public static final String DIR_ANDROID = "Android";
47 private static final String DIR_DATA = "data";
48 private static final String DIR_MEDIA = "media";
49 private static final String DIR_OBB = "obb";
50 private static final String DIR_FILES = "files";
51 private static final String DIR_CACHE = "cache";
52
53 /** {@hide} */
54 @Deprecated
55 public static final String DIRECTORY_ANDROID = DIR_ANDROID;
Jeff Sharkeydfa45302012-09-12 16:25:22 -070056
Jeff Sharkey63d0a062013-03-01 16:12:55 -080057 private static final File DIR_ANDROID_ROOT = getDirectory(ENV_ANDROID_ROOT, "/system");
58 private static final File DIR_MEDIA_STORAGE = getDirectory(ENV_MEDIA_STORAGE, "/data/media");
59
60 private static final String CANONCIAL_EMULATED_STORAGE_TARGET = getCanonicalPathOrNull(
61 ENV_EMULATED_STORAGE_TARGET);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Oscar Montemayora8529f62009-11-18 10:14:20 -080063 private static final String SYSTEM_PROPERTY_EFS_ENABLED = "persist.security.efs.enabled";
64
Jeff Sharkeyb049e212012-09-07 23:16:01 -070065 private static UserEnvironment sCurrentUser;
Jeff Sharkey48749fc2013-04-19 13:25:04 -070066 private static boolean sUserRequired;
Kenny Roote1ff2142010-10-12 11:20:01 -070067
Jeff Sharkeyb049e212012-09-07 23:16:01 -070068 static {
69 initForCurrentUser();
70 }
71
72 /** {@hide} */
73 public static void initForCurrentUser() {
74 final int userId = UserHandle.myUserId();
75 sCurrentUser = new UserEnvironment(userId);
Jeff Sharkeyb049e212012-09-07 23:16:01 -070076 }
77
78 /** {@hide} */
79 public static class UserEnvironment {
80 // TODO: generalize further to create package-specific environment
81
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -070082 /** External storage dirs, as visible to vold */
83 private final File[] mExternalDirsForVold;
84 /** External storage dirs, as visible to apps */
85 private final File[] mExternalDirsForApp;
86 /** Primary emulated storage dir for direct access */
87 private final File mEmulatedDirForDirect;
Jeff Sharkeyb049e212012-09-07 23:16:01 -070088
89 public UserEnvironment(int userId) {
90 // See storage config details at http://source.android.com/tech/storage/
91 String rawExternalStorage = System.getenv(ENV_EXTERNAL_STORAGE);
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -070092 String rawEmulatedSource = System.getenv(ENV_EMULATED_STORAGE_SOURCE);
93 String rawEmulatedTarget = System.getenv(ENV_EMULATED_STORAGE_TARGET);
Jeff Sharkey44cbdec2013-10-07 16:49:47 -070094
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -070095 String rawMediaStorage = System.getenv(ENV_MEDIA_STORAGE);
96 if (TextUtils.isEmpty(rawMediaStorage)) {
97 rawMediaStorage = "/data/media";
98 }
Jeff Sharkeyb049e212012-09-07 23:16:01 -070099
Jeff Sharkey44cbdec2013-10-07 16:49:47 -0700100 ArrayList<File> externalForVold = Lists.newArrayList();
101 ArrayList<File> externalForApp = Lists.newArrayList();
102
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700103 if (!TextUtils.isEmpty(rawEmulatedTarget)) {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700104 // Device has emulated storage; external storage paths should have
105 // userId burned into them.
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -0700106 final String rawUserId = Integer.toString(userId);
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700107 final File emulatedSourceBase = new File(rawEmulatedSource);
108 final File emulatedTargetBase = new File(rawEmulatedTarget);
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -0700109 final File mediaBase = new File(rawMediaStorage);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700110
111 // /storage/emulated/0
Jeff Sharkey44cbdec2013-10-07 16:49:47 -0700112 externalForVold.add(buildPath(emulatedSourceBase, rawUserId));
113 externalForApp.add(buildPath(emulatedTargetBase, rawUserId));
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -0700114 // /data/media/0
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700115 mEmulatedDirForDirect = buildPath(mediaBase, rawUserId);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700116
117 } else {
118 // Device has physical external storage; use plain paths.
119 if (TextUtils.isEmpty(rawExternalStorage)) {
120 Log.w(TAG, "EXTERNAL_STORAGE undefined; falling back to default");
121 rawExternalStorage = "/storage/sdcard0";
122 }
123
124 // /storage/sdcard0
Jeff Sharkey44cbdec2013-10-07 16:49:47 -0700125 externalForVold.add(new File(rawExternalStorage));
126 externalForApp.add(new File(rawExternalStorage));
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -0700127 // /data/media
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700128 mEmulatedDirForDirect = new File(rawMediaStorage);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700129 }
Jeff Sharkey44cbdec2013-10-07 16:49:47 -0700130
131 // Splice in any secondary storage paths, but only for owner
132 final String rawSecondaryStorage = System.getenv(ENV_SECONDARY_STORAGE);
133 if (!TextUtils.isEmpty(rawSecondaryStorage) && userId == UserHandle.USER_OWNER) {
134 for (String secondaryPath : rawSecondaryStorage.split(":")) {
135 externalForVold.add(new File(secondaryPath));
136 externalForApp.add(new File(secondaryPath));
137 }
138 }
139
140 mExternalDirsForVold = externalForVold.toArray(new File[externalForVold.size()]);
141 mExternalDirsForApp = externalForApp.toArray(new File[externalForApp.size()]);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700142 }
143
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700144 @Deprecated
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700145 public File getExternalStorageDirectory() {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700146 return mExternalDirsForApp[0];
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700147 }
148
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700149 @Deprecated
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700150 public File getExternalStoragePublicDirectory(String type) {
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700151 return buildExternalStoragePublicDirs(type)[0];
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700152 }
153
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700154 public File[] getExternalDirsForVold() {
155 return mExternalDirsForVold;
156 }
157
158 public File[] getExternalDirsForApp() {
159 return mExternalDirsForApp;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700160 }
161
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700162 public File getMediaDir() {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700163 return mEmulatedDirForDirect;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700164 }
165
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700166 public File[] buildExternalStoragePublicDirs(String type) {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700167 return buildPaths(mExternalDirsForApp, type);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700168 }
169
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700170 public File[] buildExternalStorageAndroidDataDirs() {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700171 return buildPaths(mExternalDirsForApp, DIR_ANDROID, DIR_DATA);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700172 }
173
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700174 public File[] buildExternalStorageAndroidObbDirs() {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700175 return buildPaths(mExternalDirsForApp, DIR_ANDROID, DIR_OBB);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700176 }
177
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700178 public File[] buildExternalStorageAppDataDirs(String packageName) {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700179 return buildPaths(mExternalDirsForApp, DIR_ANDROID, DIR_DATA, packageName);
180 }
181
182 public File[] buildExternalStorageAppDataDirsForVold(String packageName) {
183 return buildPaths(mExternalDirsForVold, DIR_ANDROID, DIR_DATA, packageName);
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700184 }
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -0700185
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700186 public File[] buildExternalStorageAppMediaDirs(String packageName) {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700187 return buildPaths(mExternalDirsForApp, DIR_ANDROID, DIR_MEDIA, packageName);
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700188 }
189
190 public File[] buildExternalStorageAppObbDirs(String packageName) {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700191 return buildPaths(mExternalDirsForApp, DIR_ANDROID, DIR_OBB, packageName);
192 }
193
194 public File[] buildExternalStorageAppObbDirsForVold(String packageName) {
195 return buildPaths(mExternalDirsForVold, DIR_ANDROID, DIR_OBB, packageName);
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700196 }
197
198 public File[] buildExternalStorageAppFilesDirs(String packageName) {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700199 return buildPaths(mExternalDirsForApp, DIR_ANDROID, DIR_DATA, packageName, DIR_FILES);
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700200 }
201
202 public File[] buildExternalStorageAppCacheDirs(String packageName) {
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700203 return buildPaths(mExternalDirsForApp, DIR_ANDROID, DIR_DATA, packageName, DIR_CACHE);
Jeff Sharkey3fe5bf62012-09-18 15:54:52 -0700204 }
Mike Lockwood2f6a3882011-05-09 19:08:06 -0700205 }
San Mehat7fd0fee2009-12-17 07:12:23 -0800206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 /**
208 * Gets the Android root directory.
209 */
210 public static File getRootDirectory() {
Jeff Sharkey63d0a062013-03-01 16:12:55 -0800211 return DIR_ANDROID_ROOT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 }
213
Jason parksa3cdaa52011-01-13 14:15:43 -0600214 /**
215 * Gets the system directory available for secure storage.
216 * If Encrypted File system is enabled, it returns an encrypted directory (/data/secure/system).
217 * Otherwise, it returns the unencrypted /data/system directory.
218 * @return File object representing the secure storage system directory.
219 * @hide
220 */
221 public static File getSystemSecureDirectory() {
222 if (isEncryptedFilesystemEnabled()) {
223 return new File(SECURE_DATA_DIRECTORY, "system");
224 } else {
225 return new File(DATA_DIRECTORY, "system");
226 }
227 }
228
229 /**
230 * Gets the data directory for secure storage.
231 * If Encrypted File system is enabled, it returns an encrypted directory (/data/secure).
232 * Otherwise, it returns the unencrypted /data directory.
233 * @return File object representing the data directory for secure storage.
234 * @hide
235 */
236 public static File getSecureDataDirectory() {
237 if (isEncryptedFilesystemEnabled()) {
238 return SECURE_DATA_DIRECTORY;
239 } else {
240 return DATA_DIRECTORY;
241 }
242 }
243
244 /**
Jeff Sharkeyd525baa2012-05-22 18:25:32 -0700245 * Return directory used for internal media storage, which is protected by
246 * {@link android.Manifest.permission#WRITE_MEDIA_STORAGE}.
247 *
248 * @hide
249 */
250 public static File getMediaStorageDirectory() {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700251 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700252 return sCurrentUser.getMediaDir();
Jeff Sharkeyd525baa2012-05-22 18:25:32 -0700253 }
254
255 /**
Amith Yamasani61f57372012-08-31 12:12:28 -0700256 * Return the system directory for a user. This is for use by system services to store
257 * files relating to the user. This directory will be automatically deleted when the user
258 * is removed.
259 *
260 * @hide
261 */
262 public static File getUserSystemDirectory(int userId) {
263 return new File(new File(getSystemSecureDirectory(), "users"), Integer.toString(userId));
264 }
265
266 /**
Jason parksa3cdaa52011-01-13 14:15:43 -0600267 * Returns whether the Encrypted File System feature is enabled on the device or not.
268 * @return <code>true</code> if Encrypted File System feature is enabled, <code>false</code>
269 * if disabled.
270 * @hide
271 */
272 public static boolean isEncryptedFilesystemEnabled() {
273 return SystemProperties.getBoolean(SYSTEM_PROPERTY_EFS_ENABLED, false);
274 }
275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 private static final File DATA_DIRECTORY
277 = getDirectory("ANDROID_DATA", "/data");
278
Oscar Montemayora8529f62009-11-18 10:14:20 -0800279 /**
280 * @hide
281 */
282 private static final File SECURE_DATA_DIRECTORY
283 = getDirectory("ANDROID_SECURE_DATA", "/data/secure");
284
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700285 private static final File DOWNLOAD_CACHE_DIRECTORY = getDirectory("DOWNLOAD_CACHE", "/cache");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286
287 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700288 * Return the user data directory.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 */
290 public static File getDataDirectory() {
291 return DATA_DIRECTORY;
292 }
293
294 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700295 * Return the primary external storage directory. This directory may not
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800296 * currently be accessible if it has been mounted by the user on their
297 * computer, has been removed from the device, or some other problem has
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700298 * happened. You can determine its current state with
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800299 * {@link #getExternalStorageState()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700300 * <p>
301 * <em>Note: don't be confused by the word "external" here. This directory
302 * can better be thought as media/shared storage. It is a filesystem that
303 * can hold a relatively large amount of data and that is shared across all
304 * applications (does not enforce permissions). Traditionally this is an SD
305 * card, but it may also be implemented as built-in storage in a device that
306 * is distinct from the protected internal storage and can be mounted as a
307 * filesystem on a computer.</em>
308 * <p>
309 * On devices with multiple users (as described by {@link UserManager}),
310 * each user has their own isolated external storage. Applications only have
311 * access to the external storage for the user they're running as.
312 * <p>
313 * In devices with multiple "external" storage directories, this directory
Dianne Hackborn407f6252010-10-04 11:31:17 -0700314 * represents the "primary" external storage that the user will interact
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700315 * with. Access to secondary storage is available through
316 * <p>
317 * Applications should not directly use this top-level directory, in order
318 * to avoid polluting the user's root namespace. Any files that are private
319 * to the application should be placed in a directory returned by
320 * {@link android.content.Context#getExternalFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700321 * Context.getExternalFilesDir}, which the system will take care of deleting
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700322 * if the application is uninstalled. Other shared files should be placed in
323 * one of the directories returned by
324 * {@link #getExternalStoragePublicDirectory}.
325 * <p>
326 * Writing to this path requires the
327 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission,
328 * and starting in read access requires the
Jeff Sharkey8c165792012-10-22 14:08:29 -0700329 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission,
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700330 * which is automatically granted if you hold the write permission.
331 * <p>
Chet Haasee8222dd2013-09-05 07:44:18 -0700332 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, if your
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700333 * application only needs to store internal data, consider using
334 * {@link Context#getExternalFilesDir(String)} or
335 * {@link Context#getExternalCacheDir()}, which require no permissions to
336 * read or write.
337 * <p>
338 * This path may change between platform versions, so applications should
339 * only persist relative paths.
340 * <p>
341 * Here is an example of typical code to monitor the state of external
342 * storage:
343 * <p>
344 * {@sample
345 * development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800346 * monitor_storage}
Dianne Hackborn407f6252010-10-04 11:31:17 -0700347 *
348 * @see #getExternalStorageState()
349 * @see #isExternalStorageRemovable()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 */
351 public static File getExternalStorageDirectory() {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700352 throwIfUserRequired();
Jeff Sharkey2d8b4e82013-09-17 17:30:33 -0700353 return sCurrentUser.getExternalDirsForApp()[0];
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700354 }
355
356 /** {@hide} */
357 public static File getLegacyExternalStorageDirectory() {
358 return new File(System.getenv(ENV_EXTERNAL_STORAGE));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
360
Jeff Sharkey4fbbda42012-09-24 18:34:07 -0700361 /** {@hide} */
362 public static File getLegacyExternalStorageObbDirectory() {
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700363 return buildPath(getLegacyExternalStorageDirectory(), DIR_ANDROID, DIR_OBB);
Jeff Sharkey4fbbda42012-09-24 18:34:07 -0700364 }
365
366 /** {@hide} */
367 public static File getEmulatedStorageSource(int userId) {
368 // /mnt/shell/emulated/0
369 return new File(System.getenv(ENV_EMULATED_STORAGE_SOURCE), String.valueOf(userId));
370 }
371
372 /** {@hide} */
373 public static File getEmulatedStorageObbSource() {
374 // /mnt/shell/emulated/obb
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700375 return new File(System.getenv(ENV_EMULATED_STORAGE_SOURCE), DIR_OBB);
Jeff Sharkey4fbbda42012-09-24 18:34:07 -0700376 }
377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 /**
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800379 * Standard directory in which to place any audio files that should be
380 * in the regular list of music for the user.
381 * This may be combined with
382 * {@link #DIRECTORY_PODCASTS}, {@link #DIRECTORY_NOTIFICATIONS},
383 * {@link #DIRECTORY_ALARMS}, and {@link #DIRECTORY_RINGTONES} as a series
384 * of directories to categories a particular audio file as more than one
385 * type.
386 */
387 public static String DIRECTORY_MUSIC = "Music";
388
389 /**
390 * Standard directory in which to place any audio files that should be
391 * in the list of podcasts that the user can select (not as regular
392 * music).
393 * This may be combined with {@link #DIRECTORY_MUSIC},
394 * {@link #DIRECTORY_NOTIFICATIONS},
395 * {@link #DIRECTORY_ALARMS}, and {@link #DIRECTORY_RINGTONES} as a series
396 * of directories to categories a particular audio file as more than one
397 * type.
398 */
399 public static String DIRECTORY_PODCASTS = "Podcasts";
400
401 /**
402 * Standard directory in which to place any audio files that should be
403 * in the list of ringtones that the user can select (not as regular
404 * music).
405 * This may be combined with {@link #DIRECTORY_MUSIC},
406 * {@link #DIRECTORY_PODCASTS}, {@link #DIRECTORY_NOTIFICATIONS}, and
407 * {@link #DIRECTORY_ALARMS} as a series
408 * of directories to categories a particular audio file as more than one
409 * type.
410 */
411 public static String DIRECTORY_RINGTONES = "Ringtones";
412
413 /**
414 * Standard directory in which to place any audio files that should be
415 * in the list of alarms that the user can select (not as regular
416 * music).
417 * This may be combined with {@link #DIRECTORY_MUSIC},
418 * {@link #DIRECTORY_PODCASTS}, {@link #DIRECTORY_NOTIFICATIONS},
419 * and {@link #DIRECTORY_RINGTONES} as a series
420 * of directories to categories a particular audio file as more than one
421 * type.
422 */
423 public static String DIRECTORY_ALARMS = "Alarms";
424
425 /**
426 * Standard directory in which to place any audio files that should be
427 * in the list of notifications that the user can select (not as regular
428 * music).
429 * This may be combined with {@link #DIRECTORY_MUSIC},
430 * {@link #DIRECTORY_PODCASTS},
431 * {@link #DIRECTORY_ALARMS}, and {@link #DIRECTORY_RINGTONES} as a series
432 * of directories to categories a particular audio file as more than one
433 * type.
434 */
435 public static String DIRECTORY_NOTIFICATIONS = "Notifications";
436
437 /**
438 * Standard directory in which to place pictures that are available to
439 * the user. Note that this is primarily a convention for the top-level
440 * public directory, as the media scanner will find and collect pictures
441 * in any directory.
442 */
443 public static String DIRECTORY_PICTURES = "Pictures";
444
445 /**
446 * Standard directory in which to place movies that are available to
447 * the user. Note that this is primarily a convention for the top-level
448 * public directory, as the media scanner will find and collect movies
449 * in any directory.
450 */
451 public static String DIRECTORY_MOVIES = "Movies";
452
453 /**
454 * Standard directory in which to place files that have been downloaded by
455 * the user. Note that this is primarily a convention for the top-level
456 * public directory, you are free to download files anywhere in your own
Dianne Hackbornce59fb82010-04-07 17:19:04 -0700457 * private directories. Also note that though the constant here is
458 * named DIRECTORY_DOWNLOADS (plural), the actual file name is non-plural for
459 * backwards compatibility reasons.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800460 */
Dianne Hackbornce59fb82010-04-07 17:19:04 -0700461 public static String DIRECTORY_DOWNLOADS = "Download";
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800462
463 /**
464 * The traditional location for pictures and videos when mounting the
465 * device as a camera. Note that this is primarily a convention for the
466 * top-level public directory, as this convention makes no sense elsewhere.
467 */
468 public static String DIRECTORY_DCIM = "DCIM";
Jeff Sharkey3e1189b2013-09-12 21:59:06 -0700469
470 /**
471 * Standard directory in which to place documents that have been created by
472 * the user.
473 */
474 public static String DIRECTORY_DOCUMENTS = "Documents";
475
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800476 /**
477 * Get a top-level public external storage directory for placing files of
478 * a particular type. This is where the user will typically place and
479 * manage their own files, so you should be careful about what you put here
480 * to ensure you don't erase their files or get in the way of their own
481 * organization.
482 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700483 * <p>On devices with multiple users (as described by {@link UserManager}),
484 * each user has their own isolated external storage. Applications only
485 * have access to the external storage for the user they're running as.</p>
486 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800487 * <p>Here is an example of typical code to manipulate a picture on
488 * the public external storage:</p>
489 *
490 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
491 * public_picture}
492 *
493 * @param type The type of storage directory to return. Should be one of
494 * {@link #DIRECTORY_MUSIC}, {@link #DIRECTORY_PODCASTS},
495 * {@link #DIRECTORY_RINGTONES}, {@link #DIRECTORY_ALARMS},
496 * {@link #DIRECTORY_NOTIFICATIONS}, {@link #DIRECTORY_PICTURES},
497 * {@link #DIRECTORY_MOVIES}, {@link #DIRECTORY_DOWNLOADS}, or
498 * {@link #DIRECTORY_DCIM}. May not be null.
499 *
500 * @return Returns the File path for the directory. Note that this
501 * directory may not yet exist, so you must make sure it exists before
502 * using it such as with {@link File#mkdirs File.mkdirs()}.
503 */
504 public static File getExternalStoragePublicDirectory(String type) {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700505 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700506 return sCurrentUser.buildExternalStoragePublicDirs(type)[0];
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800507 }
508
509 /**
510 * Returns the path for android-specific data on the SD card.
511 * @hide
512 */
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700513 public static File[] buildExternalStorageAndroidDataDirs() {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700514 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700515 return sCurrentUser.buildExternalStorageAndroidDataDirs();
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800516 }
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700517
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800518 /**
519 * Generates the raw path to an application's data
520 * @hide
521 */
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700522 public static File[] buildExternalStorageAppDataDirs(String packageName) {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700523 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700524 return sCurrentUser.buildExternalStorageAppDataDirs(packageName);
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800525 }
526
527 /**
528 * Generates the raw path to an application's media
529 * @hide
530 */
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700531 public static File[] buildExternalStorageAppMediaDirs(String packageName) {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700532 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700533 return sCurrentUser.buildExternalStorageAppMediaDirs(packageName);
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800534 }
535
536 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800537 * Generates the raw path to an application's OBB files
538 * @hide
539 */
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700540 public static File[] buildExternalStorageAppObbDirs(String packageName) {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700541 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700542 return sCurrentUser.buildExternalStorageAppObbDirs(packageName);
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800543 }
544
545 /**
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800546 * Generates the path to an application's files.
547 * @hide
548 */
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700549 public static File[] buildExternalStorageAppFilesDirs(String packageName) {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700550 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700551 return sCurrentUser.buildExternalStorageAppFilesDirs(packageName);
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800552 }
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700553
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800554 /**
555 * Generates the path to an application's cache.
556 * @hide
557 */
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700558 public static File[] buildExternalStorageAppCacheDirs(String packageName) {
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700559 throwIfUserRequired();
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700560 return sCurrentUser.buildExternalStorageAppCacheDirs(packageName);
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800561 }
562
563 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700564 * Return the download/cache content directory.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 */
566 public static File getDownloadCacheDirectory() {
567 return DOWNLOAD_CACHE_DIRECTORY;
568 }
569
570 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700571 * Unknown storage state, such as when a path isn't backed by known storage
572 * media.
573 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800574 * @see #getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700575 */
576 public static final String MEDIA_UNKNOWN = "unknown";
577
578 /**
579 * Storage state if the media is not present.
580 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800581 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 */
583 public static final String MEDIA_REMOVED = "removed";
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700586 * Storage state if the media is present but not mounted.
587 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800588 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 */
590 public static final String MEDIA_UNMOUNTED = "unmounted";
591
592 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700593 * Storage state if the media is present and being disk-checked.
594 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800595 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 */
597 public static final String MEDIA_CHECKING = "checking";
598
599 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700600 * Storage state if the media is present but is blank or is using an
601 * unsupported filesystem.
602 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800603 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 */
605 public static final String MEDIA_NOFS = "nofs";
606
607 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700608 * Storage state if the media is present and mounted at its mount point with
609 * read/write access.
610 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800611 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 */
613 public static final String MEDIA_MOUNTED = "mounted";
614
615 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700616 * Storage state if the media is present and mounted at its mount point with
617 * read-only access.
618 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800619 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 */
621 public static final String MEDIA_MOUNTED_READ_ONLY = "mounted_ro";
622
623 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700624 * Storage state if the media is present not mounted, and shared via USB
625 * mass storage.
626 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800627 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 */
629 public static final String MEDIA_SHARED = "shared";
630
631 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700632 * Storage state if the media was removed before it was unmounted.
633 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800634 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 */
636 public static final String MEDIA_BAD_REMOVAL = "bad_removal";
637
638 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700639 * Storage state if the media is present but cannot be mounted. Typically
640 * this happens if the file system on the media is corrupted.
641 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800642 * @see #getExternalStorageState(File)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 */
644 public static final String MEDIA_UNMOUNTABLE = "unmountable";
645
646 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700647 * Returns the current state of the primary "external" storage device.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800648 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700649 * @see #getExternalStorageDirectory()
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700650 * @return one of {@link #MEDIA_UNKNOWN}, {@link #MEDIA_REMOVED},
651 * {@link #MEDIA_UNMOUNTED}, {@link #MEDIA_CHECKING},
652 * {@link #MEDIA_NOFS}, {@link #MEDIA_MOUNTED},
653 * {@link #MEDIA_MOUNTED_READ_ONLY}, {@link #MEDIA_SHARED},
654 * {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 */
656 public static String getExternalStorageState() {
Jeff Sharkeya6d19992013-10-14 16:43:42 -0700657 final File externalDir = sCurrentUser.getExternalDirsForApp()[0];
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800658 return getExternalStorageState(externalDir);
659 }
660
661 /**
662 * @deprecated use {@link #getExternalStorageState(File)}
663 */
664 @Deprecated
665 public static String getStorageState(File path) {
666 return getExternalStorageState(path);
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700667 }
668
669 /**
670 * Returns the current state of the storage device that provides the given
671 * path.
672 *
673 * @return one of {@link #MEDIA_UNKNOWN}, {@link #MEDIA_REMOVED},
674 * {@link #MEDIA_UNMOUNTED}, {@link #MEDIA_CHECKING},
675 * {@link #MEDIA_NOFS}, {@link #MEDIA_MOUNTED},
676 * {@link #MEDIA_MOUNTED_READ_ONLY}, {@link #MEDIA_SHARED},
677 * {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}.
678 */
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800679 public static String getExternalStorageState(File path) {
680 final StorageVolume volume = getStorageVolume(path);
681 if (volume != null) {
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700682 final IMountService mountService = IMountService.Stub.asInterface(
683 ServiceManager.getService("mount"));
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800684 try {
685 return mountService.getVolumeState(volume.getPath());
686 } catch (RemoteException e) {
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700687 }
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700688 }
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800689
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700690 return Environment.MEDIA_UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 }
692
Dianne Hackborn407f6252010-10-04 11:31:17 -0700693 /**
694 * Returns whether the primary "external" storage device is removable.
Dianne Hackborn407f6252010-10-04 11:31:17 -0700695 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800696 * @return true if the storage device can be removed (such as an SD card),
697 * or false if the storage device is built in and cannot be
698 * physically removed.
Dianne Hackborn407f6252010-10-04 11:31:17 -0700699 */
700 public static boolean isExternalStorageRemovable() {
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800701 if (isStorageDisabled()) return false;
702 final File externalDir = sCurrentUser.getExternalDirsForApp()[0];
703 return isExternalStorageRemovable(externalDir);
Dianne Hackborn407f6252010-10-04 11:31:17 -0700704 }
705
Kenny Roote1ff2142010-10-12 11:20:01 -0700706 /**
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800707 * Returns whether the storage device that provides the given path is
708 * removable.
Andy Stadler50c294f2011-03-07 19:13:42 -0800709 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800710 * @return true if the storage device can be removed (such as an SD card),
711 * or false if the storage device is built in and cannot be
712 * physically removed.
713 * @throws IllegalArgumentException if the path is not a valid storage
714 * device.
715 */
716 public static boolean isExternalStorageRemovable(File path) {
717 final StorageVolume volume = getStorageVolume(path);
718 if (volume != null) {
719 return volume.isRemovable();
720 } else {
721 throw new IllegalArgumentException("Failed to find storage device at " + path);
722 }
723 }
724
725 /**
726 * Returns whether the primary "external" storage device is emulated. If
727 * true, data stored on this device will be stored on a portion of the
728 * internal storage system.
Andy Stadler50c294f2011-03-07 19:13:42 -0800729 *
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800730 * @see DevicePolicyManager#setStorageEncryption(android.content.ComponentName,
731 * boolean)
Kenny Roote1ff2142010-10-12 11:20:01 -0700732 */
733 public static boolean isExternalStorageEmulated() {
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800734 if (isStorageDisabled()) return false;
735 final File externalDir = sCurrentUser.getExternalDirsForApp()[0];
736 return isExternalStorageEmulated(externalDir);
737 }
738
739 /**
740 * Returns whether the storage device that provides the given path is
741 * emulated. If true, data stored on this device will be stored on a portion
742 * of the internal storage system.
743 *
744 * @throws IllegalArgumentException if the path is not a valid storage
745 * device.
746 */
747 public static boolean isExternalStorageEmulated(File path) {
748 final StorageVolume volume = getStorageVolume(path);
749 if (volume != null) {
750 return volume.isEmulated();
751 } else {
752 throw new IllegalArgumentException("Failed to find storage device at " + path);
753 }
Kenny Roote1ff2142010-10-12 11:20:01 -0700754 }
755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 static File getDirectory(String variableName, String defaultPath) {
757 String path = System.getenv(variableName);
758 return path == null ? new File(defaultPath) : new File(path);
759 }
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700760
Jeff Sharkey63d0a062013-03-01 16:12:55 -0800761 private static String getCanonicalPathOrNull(String variableName) {
762 String path = System.getenv(variableName);
763 if (path == null) {
764 return null;
765 }
766 try {
767 return new File(path).getCanonicalPath();
768 } catch (IOException e) {
769 Log.w(TAG, "Unable to resolve canonical path for " + path);
770 return null;
771 }
772 }
773
Jeff Sharkey48749fc2013-04-19 13:25:04 -0700774 /** {@hide} */
775 public static void setUserRequired(boolean userRequired) {
776 sUserRequired = userRequired;
777 }
778
779 private static void throwIfUserRequired() {
780 if (sUserRequired) {
781 Log.wtf(TAG, "Path requests must specify a user by using UserEnvironment",
782 new Throwable());
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700783 }
784 }
785
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700786 /**
787 * Append path segments to each given base path, returning result.
788 *
789 * @hide
790 */
791 public static File[] buildPaths(File[] base, String... segments) {
792 File[] result = new File[base.length];
793 for (int i = 0; i < base.length; i++) {
794 result[i] = buildPath(base[i], segments);
795 }
796 return result;
797 }
798
799 /**
800 * Append path segments to given base path, returning result.
801 *
802 * @hide
803 */
804 public static File buildPath(File base, String... segments) {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700805 File cur = base;
806 for (String segment : segments) {
807 if (cur == null) {
808 cur = new File(segment);
809 } else {
810 cur = new File(cur, segment);
811 }
812 }
813 return cur;
814 }
Jeff Sharkey63d0a062013-03-01 16:12:55 -0800815
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800816 private static boolean isStorageDisabled() {
817 return SystemProperties.getBoolean("config.disable_storage", false);
818 }
819
820 private static StorageVolume getStorageVolume(File path) {
821 try {
822 path = path.getCanonicalFile();
823 } catch (IOException e) {
824 return null;
825 }
826
827 try {
828 final IMountService mountService = IMountService.Stub.asInterface(
829 ServiceManager.getService("mount"));
830 final StorageVolume[] volumes = mountService.getVolumeList();
831 for (StorageVolume volume : volumes) {
832 if (FileUtils.contains(volume.getPathFile(), path)) {
833 return volume;
834 }
835 }
836 } catch (RemoteException e) {
837 }
838
839 return null;
840 }
841
Jeff Sharkey63d0a062013-03-01 16:12:55 -0800842 /**
843 * If the given path exists on emulated external storage, return the
844 * translated backing path hosted on internal storage. This bypasses any
845 * emulation later, improving performance. This is <em>only</em> suitable
846 * for read-only access.
847 * <p>
848 * Returns original path if given path doesn't meet these criteria. Callers
849 * must hold {@link android.Manifest.permission#WRITE_MEDIA_STORAGE}
850 * permission.
851 *
852 * @hide
853 */
854 public static File maybeTranslateEmulatedPathToInternal(File path) {
855 // Fast return if not emulated, or missing variables
856 if (!Environment.isExternalStorageEmulated()
857 || CANONCIAL_EMULATED_STORAGE_TARGET == null) {
858 return path;
859 }
860
861 try {
862 final String rawPath = path.getCanonicalPath();
863 if (rawPath.startsWith(CANONCIAL_EMULATED_STORAGE_TARGET)) {
864 final File internalPath = new File(DIR_MEDIA_STORAGE,
865 rawPath.substring(CANONCIAL_EMULATED_STORAGE_TARGET.length()));
866 if (internalPath.exists()) {
867 return internalPath;
868 }
869 }
870 } catch (IOException e) {
871 Log.w(TAG, "Failed to resolve canonical path for " + path);
872 }
873
874 // Unable to translate to internal path; use original
875 return path;
876 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877}