Search in sources :

Example 21 with VolumeInfo

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

the class MountService method getVolumeList.

@Override
public StorageVolume[] getVolumeList(int uid, String packageName, int flags) {
    final int userId = UserHandle.getUserId(uid);
    final boolean forWrite = (flags & StorageManager.FLAG_FOR_WRITE) != 0;
    final boolean realState = (flags & StorageManager.FLAG_REAL_STATE) != 0;
    final boolean includeInvisible = (flags & StorageManager.FLAG_INCLUDE_INVISIBLE) != 0;
    final boolean userKeyUnlocked;
    final boolean storagePermission;
    final long token = Binder.clearCallingIdentity();
    try {
        userKeyUnlocked = isUserKeyUnlocked(userId);
        storagePermission = mMountServiceInternal.hasExternalStorage(uid, packageName);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    boolean foundPrimary = false;
    final ArrayList<StorageVolume> res = new ArrayList<>();
    synchronized (mLock) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            switch(vol.getType()) {
                case VolumeInfo.TYPE_PUBLIC:
                case VolumeInfo.TYPE_EMULATED:
                    break;
                default:
                    continue;
            }
            boolean match = false;
            if (forWrite) {
                match = vol.isVisibleForWrite(userId);
            } else {
                match = vol.isVisibleForRead(userId) || (includeInvisible && vol.getPath() != null);
            }
            if (!match)
                continue;
            boolean reportUnmounted = false;
            if ((vol.getType() == VolumeInfo.TYPE_EMULATED) && !userKeyUnlocked) {
                reportUnmounted = true;
            } else if (!storagePermission && !realState) {
                reportUnmounted = true;
            }
            final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, reportUnmounted);
            if (vol.isPrimary()) {
                res.add(0, userVol);
                foundPrimary = true;
            } else {
                res.add(userVol);
            }
        }
    }
    if (!foundPrimary) {
        Log.w(TAG, "No primary storage defined yet; hacking together a stub");
        final boolean primaryPhysical = SystemProperties.getBoolean(StorageManager.PROP_PRIMARY_PHYSICAL, false);
        final String id = "stub_primary";
        final File path = Environment.getLegacyExternalStorageDirectory();
        final String description = mContext.getString(android.R.string.unknownName);
        final boolean primary = true;
        final boolean removable = primaryPhysical;
        final boolean emulated = !primaryPhysical;
        final long mtpReserveSize = 0L;
        final boolean allowMassStorage = false;
        final long maxFileSize = 0L;
        final UserHandle owner = new UserHandle(userId);
        final String uuid = null;
        final String state = Environment.MEDIA_REMOVED;
        res.add(0, new StorageVolume(id, StorageVolume.STORAGE_ID_INVALID, path, description, primary, removable, emulated, mtpReserveSize, allowMassStorage, maxFileSize, owner, uuid, state));
    }
    return res.toArray(new StorageVolume[res.size()]);
}
Also used : StorageVolume(android.os.storage.StorageVolume) UserHandle(android.os.UserHandle) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) File(java.io.File) AtomicFile(android.util.AtomicFile)

Example 22 with VolumeInfo

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

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 23 with VolumeInfo

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

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 24 with VolumeInfo

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

the class MountService method format.

@Override
public void format(String volId) {
    enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
    waitForReady();
    final VolumeInfo vol = findVolumeByIdOrThrow(volId);
    try {
        mConnector.execute("volume", "format", vol.id, "auto");
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : VolumeInfo(android.os.storage.VolumeInfo)

Example 25 with VolumeInfo

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

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)290 StorageManager (android.os.storage.StorageManager)81 File (java.io.File)49 Test (org.junit.Test)42 Intent (android.content.Intent)39 DiskInfo (android.os.storage.DiskInfo)29 Bundle (android.os.Bundle)28 ArrayList (java.util.ArrayList)26 VolumeRecord (android.os.storage.VolumeRecord)22 Context (android.content.Context)21 Before (org.junit.Before)21 UserHandle (android.os.UserHandle)19 LayoutInflater (android.view.LayoutInflater)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 IOException (java.io.IOException)17 StorageStatsManager (android.app.usage.StorageStatsManager)14 MenuItem (android.view.MenuItem)14 StorageVolumeProvider (com.android.settingslib.deviceinfo.StorageVolumeProvider)14 NonNull (android.annotation.NonNull)10 Notification (android.app.Notification)10