Search in sources :

Example 46 with StorageManager

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

the class PackageManagerService method movePrimaryStorage.

@Override
public int movePrimaryStorage(String volumeUuid) throws RemoteException {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
    final int realMoveId = mNextMoveId.getAndIncrement();
    final Bundle extras = new Bundle();
    extras.putString(VolumeRecord.EXTRA_FS_UUID, volumeUuid);
    mMoveCallbacks.notifyCreated(realMoveId, extras);
    final IPackageMoveObserver callback = new IPackageMoveObserver.Stub() {

        @Override
        public void onCreated(int moveId, Bundle extras) {
        // Ignored
        }

        @Override
        public void onStatusChanged(int moveId, int status, long estMillis) {
            mMoveCallbacks.notifyStatusChanged(realMoveId, status, estMillis);
        }
    };
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    storage.setPrimaryStorageUuid(volumeUuid, callback);
    return realMoveId;
}
Also used : Bundle(android.os.Bundle) StorageManager(android.os.storage.StorageManager) IPackageMoveObserver(android.content.pm.IPackageMoveObserver)

Example 47 with StorageManager

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

the class PackageManagerService method prepareUserData.

/**
     * Prepare storage areas for given user on all mounted devices.
     */
void prepareUserData(int userId, int userSerial, int flags) {
    synchronized (mInstallLock) {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        for (VolumeInfo vol : storage.getWritablePrivateVolumes()) {
            final String volumeUuid = vol.getFsUuid();
            prepareUserDataLI(volumeUuid, userId, userSerial, flags, true);
        }
    }
}
Also used : StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo)

Example 48 with StorageManager

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

the class PackageHelper method fitsOnInternal.

public static boolean fitsOnInternal(Context context, long sizeBytes) {
    final StorageManager storage = context.getSystemService(StorageManager.class);
    final File target = Environment.getDataDirectory();
    return (sizeBytes <= storage.getStorageBytesUntilLow(target));
}
Also used : StorageManager(android.os.storage.StorageManager) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 49 with StorageManager

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

the class PackageHelper method fitsOnExternal.

public static boolean fitsOnExternal(Context context, long sizeBytes) {
    final StorageManager storage = context.getSystemService(StorageManager.class);
    final StorageVolume primary = storage.getPrimaryVolume();
    return (sizeBytes > 0) && !primary.isEmulated() && Environment.MEDIA_MOUNTED.equals(primary.getState()) && sizeBytes <= storage.getStorageBytesUntilLow(primary.getPathFile());
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager)

Example 50 with StorageManager

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

the class PackageManagerTests method mountMedia.

boolean mountMedia() {
    // We can't mount emulated storage.
    if (Environment.isExternalStorageEmulated()) {
        return true;
    }
    if (checkMediaState(Environment.MEDIA_MOUNTED)) {
        return true;
    }
    final String path = Environment.getExternalStorageDirectory().toString();
    StorageListener observer = new StorageListener(Environment.MEDIA_MOUNTED);
    StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
    sm.registerListener(observer);
    try {
        // Wait on observer
        synchronized (observer) {
            int ret = getMs().mountVolume(path);
            if (ret != StorageResultCode.OperationSucceeded) {
                throw new Exception("Could not mount the media");
            }
            long waitTime = 0;
            while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
                observer.wait(WAIT_TIME_INCR);
                waitTime += WAIT_TIME_INCR;
            }
            if (!observer.isDone()) {
                throw new Exception("Timed out waiting for unmount media notification");
            }
            return true;
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception : " + e);
        return false;
    } finally {
        sm.unregisterListener(observer);
    }
}
Also used : StorageListener(android.os.storage.StorageListener) StorageManager(android.os.storage.StorageManager) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) ErrnoException(android.system.ErrnoException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) PackageParserException(android.content.pm.PackageParser.PackageParserException)

Aggregations

StorageManager (android.os.storage.StorageManager)161 File (java.io.File)43 IOException (java.io.IOException)42 VolumeInfo (android.os.storage.VolumeInfo)38 FileNotFoundException (java.io.FileNotFoundException)32 ParcelFileDescriptor (android.os.ParcelFileDescriptor)25 LargeTest (android.test.suitebuilder.annotation.LargeTest)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)17 RemoteException (android.os.RemoteException)14 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 StorageVolume (android.os.storage.StorageVolume)13 PackageParserException (android.content.pm.PackageParser.PackageParserException)12 NotFoundException (android.content.res.Resources.NotFoundException)12 StorageListener (android.os.storage.StorageListener)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ErrnoException (android.system.ErrnoException)12 NonNull (android.annotation.NonNull)10 ZipFile (java.util.zip.ZipFile)10