use of android.os.storage.IMountService in project android_frameworks_base by ParanoidAndroid.
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.getLegacyExternalStorageDirectory().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.getLegacyExternalStorageDirectory().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();
}
}
use of android.os.storage.IMountService in project android_frameworks_base by ParanoidAndroid.
the class LockPatternUtils method updateEncryptionPassword.
/** Update the encryption password if it is enabled **/
private void updateEncryptionPassword(String password) {
DevicePolicyManager dpm = getDevicePolicyManager();
if (dpm.getStorageEncryptionStatus(getCurrentOrCallingUserId()) != DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE) {
return;
}
IBinder service = ServiceManager.getService("mount");
if (service == null) {
Log.e(TAG, "Could not find the mount service to update the encryption password");
return;
}
IMountService mountService = IMountService.Stub.asInterface(service);
try {
mountService.changeEncryptionPassword(password);
} catch (RemoteException e) {
Log.e(TAG, "Error changing encryption password", e);
}
}
use of android.os.storage.IMountService in project platform_frameworks_base by android.
the class ContextImpl method ensureExternalDirsExistOrFilter.
/**
* Ensure that given directories exist, trying to create them if missing. If
* unable to create, they are filtered by replacing with {@code null}.
*/
private File[] ensureExternalDirsExistOrFilter(File[] dirs) {
File[] result = new File[dirs.length];
for (int i = 0; i < dirs.length; i++) {
File dir = dirs[i];
if (!dir.exists()) {
if (!dir.mkdirs()) {
// recheck existence in case of cross-process race
if (!dir.exists()) {
// Failing to mkdir() may be okay, since we might not have
// enough permissions; ask vold to create on our behalf.
final IMountService mount = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
try {
final int res = mount.mkdirs(getPackageName(), dir.getAbsolutePath());
if (res != 0) {
Log.w(TAG, "Failed to ensure " + dir + ": " + res);
dir = null;
}
} catch (Exception e) {
Log.w(TAG, "Failed to ensure " + dir + ": " + e);
dir = null;
}
}
}
}
result[i] = dir;
}
return result;
}
use of android.os.storage.IMountService in project platform_frameworks_base by android.
the class PackageManagerService method performFstrimIfNeeded.
@Override
public void performFstrimIfNeeded() {
enforceSystemOrRoot("Only the system can request fstrim");
// Before everything else, see whether we need to fstrim.
try {
IMountService ms = PackageHelper.getMountService();
if (ms != null) {
boolean doTrim = false;
final long interval = android.provider.Settings.Global.getLong(mContext.getContentResolver(), android.provider.Settings.Global.FSTRIM_MANDATORY_INTERVAL, DEFAULT_MANDATORY_FSTRIM_INTERVAL);
if (interval > 0) {
final long timeSinceLast = System.currentTimeMillis() - ms.lastMaintenance();
if (timeSinceLast > interval) {
doTrim = true;
Slog.w(TAG, "No disk maintenance in " + timeSinceLast + "; running immediately");
}
}
if (doTrim) {
final boolean dexOptDialogShown;
synchronized (mPackages) {
dexOptDialogShown = mDexOptDialogShown;
}
if (!isFirstBoot() && dexOptDialogShown) {
try {
ActivityManagerNative.getDefault().showBootMessage(mContext.getResources().getString(R.string.android_upgrading_fstrim), true);
} catch (RemoteException e) {
}
}
ms.runMaintenance();
}
} else {
Slog.e(TAG, "Mount service unavailable!");
}
} catch (RemoteException e) {
// Can't happen; MountService is local
}
}
use of android.os.storage.IMountService in project android_frameworks_base by DirtyUnicorns.
the class LockSettingsService method checkVoldPassword.
@Override
public boolean checkVoldPassword(int userId) throws RemoteException {
if (!mFirstCallToVold) {
return false;
}
mFirstCallToVold = false;
checkPasswordReadPermission(userId);
// There's no guarantee that this will safely connect, but if it fails
// we will simply show the lock screen when we shouldn't, so relatively
// benign. There is an outside chance something nasty would happen if
// this service restarted before vold stales out the password in this
// case. The nastiness is limited to not showing the lock screen when
// we should, within the first minute of decrypting the phone if this
// service can't connect to vold, it restarts, and then the new instance
// does successfully connect.
final IMountService service = getMountService();
String password;
long identity = Binder.clearCallingIdentity();
try {
password = service.getPassword();
service.clearPassword();
} finally {
Binder.restoreCallingIdentity(identity);
}
if (password == null) {
return false;
}
try {
if (mLockPatternUtils.isLockPatternEnabled(userId)) {
if (checkPattern(password, userId, null).getResponseCode() == GateKeeperResponse.RESPONSE_OK) {
return true;
}
}
} catch (Exception e) {
}
try {
if (mLockPatternUtils.isLockPasswordEnabled(userId)) {
if (checkPassword(password, userId, null).getResponseCode() == GateKeeperResponse.RESPONSE_OK) {
return true;
}
}
} catch (Exception e) {
}
return false;
}
Aggregations