From 03559753ce0c6105b9357d6050aa4cddb9112ac2 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Mon, 19 Jul 2010 18:25:03 -0400 Subject: [PATCH] Add support for emulating external storage on devices with no SD card Change-Id: I4feb03a4b8f4eae33e940477b355d3a4cac7fa86 Signed-off-by: Mike Lockwood --- core/res/res/values/config.xml | 7 ++++++ .../java/com/android/server/MountService.java | 25 ++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index ec0d83c031892..98b0a287b80df 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -72,6 +72,13 @@ when there's no network connection. If the scan doesn't timeout, use zero --> 0 + + false + diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index d7b92ec0ae71c..ef5e9cc1f614c 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -127,6 +127,8 @@ class MountService extends IMountService.Stub private boolean mBooted = false; private boolean mReady = false; private boolean mSendUmsConnectedOnBoot = false; + // true if we should fake MEDIA_MOUNTED state for external storage + private boolean mEmulateExternalStorage = false; /** * Private hash of currently mounted secure containers. @@ -319,7 +321,9 @@ class MountService extends IMountService.Stub String path = Environment.getExternalStorageDirectory().getPath(); String state = getVolumeState(path); - if (state.equals(Environment.MEDIA_UNMOUNTED)) { + if (mEmulateExternalStorage) { + notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Mounted); + } else if (state.equals(Environment.MEDIA_UNMOUNTED)) { int rc = doMountVolume(path); if (rc != StorageResultCode.OperationSucceeded) { Slog.e(TAG, String.format("Boot-time mount failed (%d)", rc)); @@ -390,11 +394,13 @@ class MountService extends IMountService.Stub Slog.w(TAG, String.format("Duplicate state transition (%s -> %s)", mLegacyState, state)); return; } - // Update state on PackageManager - if (Environment.MEDIA_UNMOUNTED.equals(state)) { - mPms.updateExternalMediaStatus(false, false); - } else if (Environment.MEDIA_MOUNTED.equals(state)) { - mPms.updateExternalMediaStatus(true, false); + // Update state on PackageManager, but only of real events + if (!mEmulateExternalStorage) { + if (Environment.MEDIA_UNMOUNTED.equals(state)) { + mPms.updateExternalMediaStatus(false, false); + } else if (Environment.MEDIA_MOUNTED.equals(state)) { + mPms.updateExternalMediaStatus(true, false); + } } String oldState = mLegacyState; mLegacyState = state; @@ -894,6 +900,13 @@ class MountService extends IMountService.Stub public MountService(Context context) { mContext = context; + mEmulateExternalStorage = context.getResources().getBoolean( + com.android.internal.R.bool.config_emulateExternalStorage); + if (mEmulateExternalStorage) { + Slog.d(TAG, "using emulated external storage"); + mLegacyState = Environment.MEDIA_MOUNTED; + } + // XXX: This will go away soon in favor of IMountServiceObserver mPms = (PackageManagerService) ServiceManager.getService("package");