Search in sources :

Example 66 with IMountService

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

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

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

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

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

the class LockPatternUtils method setVisiblePasswordEnabled.

/**
     * Set whether the visible password is enabled for cryptkeeper screen.
     */
public void setVisiblePasswordEnabled(boolean enabled, int 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.PASSWORD_VISIBLE_KEY, enabled ? "1" : "0");
    } catch (RemoteException e) {
        Log.e(TAG, "Error changing password visible state", e);
    }
}
Also used : IBinder(android.os.IBinder) IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException)

Example 69 with IMountService

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

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

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

the class Environment method getPrimaryVolume.

private static StorageVolume getPrimaryVolume() {
    if (mPrimaryVolume == null) {
        synchronized (mLock) {
            if (mPrimaryVolume == null) {
                try {
                    IMountService mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
                    Parcelable[] volumes = mountService.getVolumeList();
                    mPrimaryVolume = (StorageVolume) volumes[0];
                } catch (Exception e) {
                    Log.e(TAG, "couldn't talk to MountService", e);
                }
            }
        }
    }
    return mPrimaryVolume;
}
Also used : IMountService(android.os.storage.IMountService)

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