Merge "Add API to check for emulated external storage"

This commit is contained in:
Kenny Root
2010-10-12 12:45:46 -07:00
committed by Android (Google) Code Review
5 changed files with 75 additions and 7 deletions

View File

@@ -31,7 +31,14 @@ public class Environment {
private static final String SYSTEM_PROPERTY_EFS_ENABLED = "persist.security.efs.enabled";
private static IMountService mMntSvc = null;
private static class MountServiceHolder {
static IMountService mSingleton = IMountService.Stub.asInterface(ServiceManager
.getService("mount"));
}
private static final Object mLock = new Object();
private volatile static Boolean mIsExternalStorageEmulated = null;
/**
* Gets the Android root directory.
@@ -382,11 +389,8 @@ public class Environment {
*/
public static String getExternalStorageState() {
try {
if (mMntSvc == null) {
mMntSvc = IMountService.Stub.asInterface(ServiceManager
.getService("mount"));
}
return mMntSvc.getVolumeState(getExternalStorageDirectory().toString());
return MountServiceHolder.mSingleton.getVolumeState(getExternalStorageDirectory()
.toString());
} catch (Exception rex) {
return Environment.MEDIA_REMOVED;
}
@@ -405,6 +409,32 @@ public class Environment {
com.android.internal.R.bool.config_externalStorageRemovable);
}
/**
* Returns whether the device has an external storage device which is
* emulated. If true, the device does not have real external storage
* and certain system services such as the package manager use this
* to determine where to install an application.
*
* @hide
*/
public static boolean isExternalStorageEmulated() {
if (mIsExternalStorageEmulated == null) {
synchronized (mLock) {
if (mIsExternalStorageEmulated == null) {
boolean externalStorageEmulated;
try {
externalStorageEmulated =
MountServiceHolder.mSingleton.isExternalStorageEmulated();
} catch (Exception e) {
externalStorageEmulated = false;
}
mIsExternalStorageEmulated = Boolean.valueOf(externalStorageEmulated);
}
}
}
return mIsExternalStorageEmulated;
}
static File getDirectory(String variableName, String defaultPath) {
String path = System.getenv(variableName);
return path == null ? new File(defaultPath) : new File(path);

View File

@@ -565,6 +565,25 @@ public interface IMountService extends IInterface {
}
return _result;
}
/**
* Returns whether the external storage is emulated.
*/
public boolean isExternalStorageEmulated() throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
boolean _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
mRemote.transact(Stub.TRANSACTION_isExternalStorageEmulated, _data, _reply, 0);
_reply.readException();
_result = 0 != _reply.readInt();
} finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
}
private static final String DESCRIPTOR = "IMountService";
@@ -619,6 +638,8 @@ public interface IMountService extends IInterface {
static final int TRANSACTION_getMountedObbPath = IBinder.FIRST_CALL_TRANSACTION + 24;
static final int TRANSACTION_isExternalStorageEmulated = IBinder.FIRST_CALL_TRANSACTION + 25;
/**
* Cast an IBinder object into an IMountService interface, generating a
* proxy if needed.
@@ -889,6 +910,13 @@ public interface IMountService extends IInterface {
reply.writeString(mountedPath);
return true;
}
case TRANSACTION_isExternalStorageEmulated: {
data.enforceInterface(DESCRIPTOR);
boolean emulated = isExternalStorageEmulated();
reply.writeNoException();
reply.writeInt(emulated ? 1 : 0);
return true;
}
}
return super.onTransact(code, data, reply, flags);
}
@@ -1043,4 +1071,9 @@ public interface IMountService extends IInterface {
* Unregisters an IMountServiceListener
*/
public void unregisterListener(IMountServiceListener listener) throws RemoteException;
/**
* Returns whether or not the external storage is emulated.
*/
public boolean isExternalStorageEmulated() throws RemoteException;
}