Search in sources :

Example 51 with VolumeInfo

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

the class MountService method addInternalVolumeLocked.

private void addInternalVolumeLocked() {
    // Create a stub volume that represents internal storage
    final VolumeInfo internal = new VolumeInfo(VolumeInfo.ID_PRIVATE_INTERNAL, VolumeInfo.TYPE_PRIVATE, null, null);
    internal.state = VolumeInfo.STATE_MOUNTED;
    internal.path = Environment.getDataDirectory().getAbsolutePath();
    mVolumes.put(internal.id, internal);
}
Also used : VolumeInfo(android.os.storage.VolumeInfo)

Example 52 with VolumeInfo

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

the class MountService method onUnlockUser.

private void onUnlockUser(int userId) {
    Slog.d(TAG, "onUnlockUser " + userId);
    // bind mount against.
    try {
        mConnector.execute("volume", "user_started", userId);
    } catch (NativeDaemonConnectorException ignored) {
    }
    // correctly, then synthesize events for any already-mounted volumes.
    synchronized (mVolumes) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            if (vol.isVisibleForRead(userId) && vol.isMountedReadable()) {
                final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, false);
                mHandler.obtainMessage(H_VOLUME_BROADCAST, userVol).sendToTarget();
                final String envState = VolumeInfo.getEnvironmentForState(vol.getState());
                mCallbacks.notifyStorageStateChanged(userVol.getPath(), envState, envState);
            }
        }
        mSystemUnlockedUsers = ArrayUtils.appendInt(mSystemUnlockedUsers, userId);
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) VolumeInfo(android.os.storage.VolumeInfo)

Example 53 with VolumeInfo

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

the class MountService method setPrimaryStorageUuid.

@Override
public void setPrimaryStorageUuid(String volumeUuid, IPackageMoveObserver callback) {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();
    final VolumeInfo from;
    final VolumeInfo to;
    synchronized (mLock) {
        if (Objects.equals(mPrimaryStorageUuid, volumeUuid)) {
            throw new IllegalArgumentException("Primary storage already at " + volumeUuid);
        }
        if (mMoveCallback != null) {
            throw new IllegalStateException("Move already in progress");
        }
        mMoveCallback = callback;
        mMoveTargetUuid = volumeUuid;
        // the current storage location, so we have nothing to move.
        if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, mPrimaryStorageUuid) || Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) {
            Slog.d(TAG, "Skipping move to/from primary physical");
            onMoveStatusLocked(MOVE_STATUS_COPY_FINISHED);
            onMoveStatusLocked(PackageManager.MOVE_SUCCEEDED);
            mHandler.obtainMessage(H_RESET).sendToTarget();
            return;
        } else {
            from = findStorageForUuid(mPrimaryStorageUuid);
            to = findStorageForUuid(volumeUuid);
            if (from == null) {
                Slog.w(TAG, "Failing move due to missing from volume " + mPrimaryStorageUuid);
                onMoveStatusLocked(PackageManager.MOVE_FAILED_INTERNAL_ERROR);
                return;
            } else if (to == null) {
                Slog.w(TAG, "Failing move due to missing to volume " + volumeUuid);
                onMoveStatusLocked(PackageManager.MOVE_FAILED_INTERNAL_ERROR);
                return;
            }
        }
    }
    try {
        mConnector.execute("volume", "move_storage", from.id, to.id);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : VolumeInfo(android.os.storage.VolumeInfo)

Example 54 with VolumeInfo

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

the class MountService method onDiskScannedLocked.

private void onDiskScannedLocked(DiskInfo disk) {
    int volumeCount = 0;
    for (int i = 0; i < mVolumes.size(); i++) {
        final VolumeInfo vol = mVolumes.valueAt(i);
        if (Objects.equals(disk.id, vol.getDiskId())) {
            volumeCount++;
        }
    }
    final Intent intent = new Intent(DiskInfo.ACTION_DISK_SCANNED);
    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
    intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.id);
    intent.putExtra(DiskInfo.EXTRA_VOLUME_COUNT, volumeCount);
    mHandler.obtainMessage(H_INTERNAL_BROADCAST, intent).sendToTarget();
    final CountDownLatch latch = mDiskScanLatches.remove(disk.id);
    if (latch != null) {
        latch.countDown();
    }
    disk.volumeCount = volumeCount;
    mCallbacks.notifyDiskScanned(disk, volumeCount);
}
Also used : VolumeInfo(android.os.storage.VolumeInfo) Intent(android.content.Intent) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 55 with VolumeInfo

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

the class MountService method mount.

@Override
public void mount(String volId) {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();
    final VolumeInfo vol = findVolumeByIdOrThrow(volId);
    if (isMountDisallowed(vol)) {
        throw new SecurityException("Mounting " + volId + " restricted by policy");
    }
    try {
        mConnector.execute("volume", "mount", vol.id, vol.mountFlags, vol.mountUserId);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : VolumeInfo(android.os.storage.VolumeInfo)

Aggregations

VolumeInfo (android.os.storage.VolumeInfo)145 StorageManager (android.os.storage.StorageManager)43 File (java.io.File)31 ArrayList (java.util.ArrayList)26 Intent (android.content.Intent)21 CountDownLatch (java.util.concurrent.CountDownLatch)18 DiskInfo (android.os.storage.DiskInfo)16 VolumeRecord (android.os.storage.VolumeRecord)16 Test (org.junit.Test)12 NonNull (android.annotation.NonNull)10 Notification (android.app.Notification)10 PendingIntent (android.app.PendingIntent)10 StorageVolume (android.os.storage.StorageVolume)10 IOException (java.io.IOException)10 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)10 Bundle (android.os.Bundle)9 ApplicationInfo (android.content.pm.ApplicationInfo)8 PackageStats (android.content.pm.PackageStats)8 FragmentManager (android.app.FragmentManager)5 FragmentTransaction (android.app.FragmentTransaction)5