Search in sources :

Example 46 with IMountService

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

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 47 with IMountService

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

the class PackageHelperTests method cleanupContainers.

private void cleanupContainers() throws RemoteException {
    Log.d(TAG, "cleanUp");
    IMountService ms = getMs();
    String[] containers = ms.getSecureContainerList();
    for (int i = 0; i < containers.length; i++) {
        if (containers[i].startsWith(PREFIX)) {
            Log.d(TAG, "cleaing up " + containers[i]);
            ms.destroySecureContainer(containers[i], true);
        }
    }
}
Also used : IMountService(android.os.storage.IMountService)

Example 48 with IMountService

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

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 49 with IMountService

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

the class LockPatternUtils method setVisiblePatternEnabled.

/**
     * Set whether the visible pattern is enabled.
     */
public void setVisiblePatternEnabled(boolean enabled, int userId) {
    setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled, userId);
    // Update for crypto if owner
    if (userId != UserHandle.USER_SYSTEM) {
        return;
    }
    IBinder service = ServiceManager.getService("mount");
    if (service == null) {
        Log.e(TAG, "Could not find the mount service to update the user info");
        return;
    }
    IMountService mountService = IMountService.Stub.asInterface(service);
    try {
        mountService.setField(StorageManager.PATTERN_VISIBLE_KEY, enabled ? "1" : "0");
    } catch (RemoteException e) {
        Log.e(TAG, "Error changing pattern visible state", e);
    }
}
Also used : IBinder(android.os.IBinder) IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException)

Example 50 with IMountService

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

the class LockPatternUtils method updateEncryptionPassword.

/** Update the encryption password if it is enabled **/
private void updateEncryptionPassword(final int type, final String password) {
    if (!isDeviceEncryptionEnabled()) {
        return;
    }
    final IBinder service = ServiceManager.getService("mount");
    if (service == null) {
        Log.e(TAG, "Could not find the mount service to update the encryption password");
        return;
    }
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... dummy) {
            IMountService mountService = IMountService.Stub.asInterface(service);
            try {
                mountService.changeEncryptionPassword(type, password);
            } catch (RemoteException e) {
                Log.e(TAG, "Error changing encryption password", e);
            }
            return null;
        }
    }.execute();
}
Also used : IBinder(android.os.IBinder) IMountService(android.os.storage.IMountService) 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