use of android.os.storage.IMountService in project android_frameworks_base by ParanoidAndroid.
the class UsbStorageActivity method checkStorageUsersAsync.
private void checkStorageUsersAsync() {
IMountService ims = getMountService();
if (ims == null) {
// Display error dialog
scheduleShowDialog(DLG_ERROR_SHARING);
}
String extStoragePath = Environment.getExternalStorageDirectory().toString();
boolean showDialog = false;
try {
int[] stUsers = ims.getStorageUsers(extStoragePath);
if (stUsers != null && stUsers.length > 0) {
showDialog = true;
} else {
// List of applications on sdcard.
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ApplicationInfo> infoList = am.getRunningExternalApplications();
if (infoList != null && infoList.size() > 0) {
showDialog = true;
}
}
} catch (RemoteException e) {
// Display error dialog
scheduleShowDialog(DLG_ERROR_SHARING);
}
if (showDialog) {
// Display dialog to user
scheduleShowDialog(DLG_CONFIRM_KILL_STORAGE_USERS);
} else {
if (localLOGV)
Log.i(TAG, "Enabling UMS");
switchUsbMassStorage(true);
}
}
use of android.os.storage.IMountService in project android_frameworks_base by ParanoidAndroid.
the class ShutdownThread method run.
/**
* Makes sure we handle the shutdown gracefully.
* Shuts off power regardless of radio and bluetooth state if the alloted time has passed.
*/
public void run() {
BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// We don't allow apps to cancel this, so ignore the result.
actionDone();
}
};
/*
* Write a system property in case the system_server reboots before we
* get to the actual hardware restart. If that happens, we'll retry at
* the beginning of the SystemServer startup.
*/
{
String reason = (mReboot ? "1" : "0") + (mRebootReason != null ? mRebootReason : "");
SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason);
}
/*
* If we are rebooting into safe mode, write a system property
* indicating so.
*/
if (mRebootSafeMode) {
SystemProperties.set(REBOOT_SAFEMODE_PROPERTY, "1");
}
Log.i(TAG, "Sending shutdown broadcast...");
// First send the high-level shut down broadcast.
mActionDone = false;
Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, null, br, mHandler, 0, null, null);
final long endTime = SystemClock.elapsedRealtime() + MAX_BROADCAST_TIME;
synchronized (mActionDoneSync) {
while (!mActionDone) {
long delay = endTime - SystemClock.elapsedRealtime();
if (delay <= 0) {
Log.w(TAG, "Shutdown broadcast timed out");
break;
}
try {
mActionDoneSync.wait(delay);
} catch (InterruptedException e) {
}
}
}
Log.i(TAG, "Shutting down activity manager...");
final IActivityManager am = ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
if (am != null) {
try {
am.shutdown(MAX_BROADCAST_TIME);
} catch (RemoteException e) {
}
}
// Shutdown radios.
shutdownRadios(MAX_RADIO_WAIT_TIME);
// Shutdown MountService to ensure media is in a safe state
IMountShutdownObserver observer = new IMountShutdownObserver.Stub() {
public void onShutDownComplete(int statusCode) throws RemoteException {
Log.w(TAG, "Result code " + statusCode + " from MountService.shutdown");
actionDone();
}
};
Log.i(TAG, "Shutting down MountService");
// Set initial variables and time out time.
mActionDone = false;
final long endShutTime = SystemClock.elapsedRealtime() + MAX_SHUTDOWN_WAIT_TIME;
synchronized (mActionDoneSync) {
try {
final IMountService mount = IMountService.Stub.asInterface(ServiceManager.checkService("mount"));
if (mount != null) {
mount.shutdown(observer);
} else {
Log.w(TAG, "MountService unavailable for shutdown");
}
} catch (Exception e) {
Log.e(TAG, "Exception during MountService shutdown", e);
}
while (!mActionDone) {
long delay = endShutTime - SystemClock.elapsedRealtime();
if (delay <= 0) {
Log.w(TAG, "Shutdown wait timed out");
break;
}
try {
mActionDoneSync.wait(delay);
} catch (InterruptedException e) {
}
}
}
rebootOrShutdown(mReboot, mRebootReason);
}
use of android.os.storage.IMountService in project android_frameworks_base by ParanoidAndroid.
the class Environment method getPrimaryVolume.
private static StorageVolume getPrimaryVolume() {
if (sPrimaryVolume == null) {
synchronized (sLock) {
if (sPrimaryVolume == null) {
try {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
final StorageVolume[] volumes = mountService.getVolumeList();
sPrimaryVolume = StorageManager.getPrimaryVolume(volumes);
} catch (Exception e) {
Log.e(TAG, "couldn't talk to MountService", e);
}
}
}
}
return sPrimaryVolume;
}
use of android.os.storage.IMountService in project android_frameworks_base by ParanoidAndroid.
the class Environment method getExternalStorageState.
/**
* Gets the current state of the primary "external" storage device.
*
* @see #getExternalStorageDirectory()
*/
public static String getExternalStorageState() {
try {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
final StorageVolume primary = getPrimaryVolume();
return mountService.getVolumeState(primary.getPath());
} catch (RemoteException rex) {
Log.w(TAG, "Failed to read external storage state; assuming REMOVED: " + rex);
return Environment.MEDIA_REMOVED;
}
}
use of android.os.storage.IMountService in project XobotOS by xamarin.
the class ExternalStorageFormatter method updateProgressState.
void updateProgressState() {
String status = mStorageVolume == null ? Environment.getExternalStorageState() : mStorageManager.getVolumeState(mStorageVolume.getPath());
if (Environment.MEDIA_MOUNTED.equals(status) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(status)) {
updateProgressDialog(R.string.progress_unmounting);
IMountService mountService = getMountService();
final String extStoragePath = mStorageVolume == null ? Environment.getExternalStorageDirectory().toString() : mStorageVolume.getPath();
try {
// Remove encryption mapping if this is an unmount for a factory reset.
mountService.unmountVolume(extStoragePath, true, mFactoryReset);
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with mount service", e);
}
} else if (Environment.MEDIA_NOFS.equals(status) || Environment.MEDIA_UNMOUNTED.equals(status) || Environment.MEDIA_UNMOUNTABLE.equals(status)) {
updateProgressDialog(R.string.progress_erasing);
final IMountService mountService = getMountService();
final String extStoragePath = mStorageVolume == null ? Environment.getExternalStorageDirectory().toString() : mStorageVolume.getPath();
if (mountService != null) {
new Thread() {
@Override
public void run() {
boolean success = false;
try {
mountService.formatVolume(extStoragePath);
success = true;
} catch (Exception e) {
Toast.makeText(ExternalStorageFormatter.this, R.string.format_error, Toast.LENGTH_LONG).show();
}
if (success) {
if (mFactoryReset) {
sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
// Intent handling is asynchronous -- assume it will happen soon.
stopSelf();
return;
}
}
// reset, then it is time to remount the storage.
if (!success && mAlwaysReset) {
sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
} else {
try {
mountService.mountVolume(extStoragePath);
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with mount service", e);
}
}
stopSelf();
return;
}
}.start();
} else {
Log.w(TAG, "Unable to locate IMountService");
}
} else if (Environment.MEDIA_BAD_REMOVAL.equals(status)) {
fail(R.string.media_bad_removal);
} else if (Environment.MEDIA_CHECKING.equals(status)) {
fail(R.string.media_checking);
} else if (Environment.MEDIA_REMOVED.equals(status)) {
fail(R.string.media_removed);
} else if (Environment.MEDIA_SHARED.equals(status)) {
fail(R.string.media_shared);
} else {
fail(R.string.media_unknown_state);
Log.w(TAG, "Unknown storage state: " + status);
stopSelf();
}
}
Aggregations