Search in sources :

Example 71 with IMountService

use of android.os.storage.IMountService in project XobotOS by xamarin.

the class ExternalStorageFormatter method onCancel.

@Override
public void onCancel(DialogInterface dialog) {
    IMountService mountService = getMountService();
    String extStoragePath = mStorageVolume == null ? Environment.getExternalStorageDirectory().toString() : mStorageVolume.getPath();
    try {
        mountService.mountVolume(extStoragePath);
    } catch (RemoteException e) {
        Log.w(TAG, "Failed talking with mount service", e);
    }
    stopSelf();
}
Also used : IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException)

Example 72 with IMountService

use of android.os.storage.IMountService in project android_frameworks_base by DirtyUnicorns.

the class PackageHelper method resizeSdDir.

public static boolean resizeSdDir(long sizeBytes, String cid, String sdEncKey) {
    // Round up to nearest MB, plus another MB for filesystem overhead
    final int sizeMb = (int) ((sizeBytes + MB_IN_BYTES) / MB_IN_BYTES) + 1;
    try {
        IMountService mountService = getMountService();
        int rc = mountService.resizeSecureContainer(cid, sizeMb, sdEncKey);
        if (rc == StorageResultCode.OperationSucceeded) {
            return true;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "MountService running?");
    }
    Log.e(TAG, "Failed to create secure container " + cid);
    return false;
}
Also used : IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException)

Example 73 with IMountService

use of android.os.storage.IMountService in project android_frameworks_base by DirtyUnicorns.

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 74 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)

Example 75 with IMountService

use of android.os.storage.IMountService in project android_frameworks_base by DirtyUnicorns.

the class UserController method unlockUserCleared.

boolean unlockUserCleared(final int userId, byte[] token, byte[] secret, IProgressListener listener) {
    UserState uss;
    synchronized (mService) {
        // TODO Move this block outside of synchronized if it causes lock contention
        if (!StorageManager.isUserKeyUnlocked(userId)) {
            final UserInfo userInfo = getUserInfo(userId);
            final IMountService mountService = getMountService();
            try {
                // We always want to unlock user storage, even user is not started yet
                mountService.unlockUserKey(userId, userInfo.serialNumber, token, secret);
            } catch (RemoteException | RuntimeException e) {
                Slog.w(TAG, "Failed to unlock: " + e.getMessage());
            }
        }
        // Bail if user isn't actually running, otherwise register the given
        // listener to watch for unlock progress
        uss = mStartedUsers.get(userId);
        if (uss == null) {
            notifyFinished(userId, listener);
            return false;
        } else {
            uss.mUnlockProgress.addListener(listener);
            uss.tokenProvided = (token != null);
        }
    }
    finishUserUnlocking(uss);
    final ArraySet<Integer> childProfilesToUnlock = new ArraySet<>();
    synchronized (mService) {
        // managed profiles under that user.
        for (int i = 0; i < mStartedUsers.size(); i++) {
            final int testUserId = mStartedUsers.keyAt(i);
            final UserInfo parent = getUserManager().getProfileParent(testUserId);
            if (parent != null && parent.id == userId && testUserId != userId) {
                Slog.d(TAG, "User " + testUserId + " (parent " + parent.id + "): attempting unlock because parent was just unlocked");
                childProfilesToUnlock.add(testUserId);
            }
        }
    }
    final int size = childProfilesToUnlock.size();
    for (int i = 0; i < size; i++) {
        maybeUnlockUser(childProfilesToUnlock.valueAt(i));
    }
    return true;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArraySet(android.util.ArraySet) IMountService(android.os.storage.IMountService) UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException)

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