Search in sources :

Example 61 with IMountService

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();
    }
}
Also used : IMountService(android.os.storage.IMountService) Intent(android.content.Intent) RemoteException(android.os.RemoteException) RemoteException(android.os.RemoteException)

Example 62 with IMountService

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);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) IBinder(android.os.IBinder) IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException)

Example 63 with IMountService

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;
}
Also used : IMountService(android.os.storage.IMountService) File(java.io.File) ErrnoException(android.system.ErrnoException) AndroidRuntimeException(android.util.AndroidRuntimeException) ReceiverCallNotAllowedException(android.content.ReceiverCallNotAllowedException) FileNotFoundException(java.io.FileNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 64 with IMountService

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
    }
}
Also used : IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException)

Example 65 with IMountService

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;
}
Also used : IMountService(android.os.storage.IMountService) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) KeyStoreException(java.security.KeyStoreException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) RemoteException(android.os.RemoteException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) BadPaddingException(javax.crypto.BadPaddingException)

Aggregations

IMountService (android.os.storage.IMountService)89 RemoteException (android.os.RemoteException)70 IBinder (android.os.IBinder)23 IOException (java.io.IOException)15 Context (android.content.Context)10 UserInfo (android.content.pm.UserInfo)10 FileNotFoundException (java.io.FileNotFoundException)10 Intent (android.content.Intent)9 ErrnoException (android.system.ErrnoException)9 IActivityManager (android.app.IActivityManager)6 BroadcastReceiver (android.content.BroadcastReceiver)6 IMountShutdownObserver (android.os.storage.IMountShutdownObserver)6 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)5 ArraySet (android.util.ArraySet)5 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)5 InvalidKeyException (java.security.InvalidKeyException)5 KeyStoreException (java.security.KeyStoreException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 UnrecoverableKeyException (java.security.UnrecoverableKeyException)5 CertificateException (java.security.cert.CertificateException)5