Search in sources :

Example 61 with VolumeInfo

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

the class StorageNotification method start.

@Override
public void start() {
    mNotificationManager = mContext.getSystemService(NotificationManager.class);
    mStorageManager = mContext.getSystemService(StorageManager.class);
    mStorageManager.registerListener(mListener);
    mContext.registerReceiver(mSnoozeReceiver, new IntentFilter(ACTION_SNOOZE_VOLUME), android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null);
    mContext.registerReceiver(mFinishReceiver, new IntentFilter(ACTION_FINISH_WIZARD), android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null);
    // Kick current state into place
    final List<DiskInfo> disks = mStorageManager.getDisks();
    for (DiskInfo disk : disks) {
        onDiskScannedInternal(disk, disk.volumeCount);
    }
    final List<VolumeInfo> vols = mStorageManager.getVolumes();
    for (VolumeInfo vol : vols) {
        onVolumeStateChangedInternal(vol);
    }
    mContext.getPackageManager().registerMoveCallback(mMoveCallback, new Handler());
    updateMissingPrivateVolumes();
}
Also used : IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) StorageManager(android.os.storage.StorageManager) DiskInfo(android.os.storage.DiskInfo) Handler(android.os.Handler) VolumeInfo(android.os.storage.VolumeInfo)

Example 62 with VolumeInfo

use of android.os.storage.VolumeInfo in project platform_frameworks_base by android.

the class Sm method runListVolumes.

public void runListVolumes() throws RemoteException {
    final String filter = nextArg();
    final int filterType;
    if ("public".equals(filter)) {
        filterType = VolumeInfo.TYPE_PUBLIC;
    } else if ("private".equals(filter)) {
        filterType = VolumeInfo.TYPE_PRIVATE;
    } else if ("emulated".equals(filter)) {
        filterType = VolumeInfo.TYPE_EMULATED;
    } else {
        filterType = -1;
    }
    final VolumeInfo[] vols = mSm.getVolumes(0);
    for (VolumeInfo vol : vols) {
        if (filterType == -1 || filterType == vol.getType()) {
            final String envState = VolumeInfo.getEnvironmentForState(vol.getState());
            System.out.println(vol.getId() + " " + envState + " " + vol.getFsUuid());
        }
    }
}
Also used : VolumeInfo(android.os.storage.VolumeInfo)

Example 63 with VolumeInfo

use of android.os.storage.VolumeInfo in project platform_frameworks_base by android.

the class ApplicationPackageManager method getPackageCandidateVolumes.

@Override
@NonNull
public List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    final VolumeInfo currentVol = getPackageCurrentVolume(app);
    final List<VolumeInfo> vols = storage.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    for (VolumeInfo vol : vols) {
        if (Objects.equals(vol, currentVol) || isPackageCandidateVolume(mContext, app, vol)) {
            candidates.add(vol);
        }
    }
    return candidates;
}
Also used : StorageManager(android.os.storage.StorageManager) ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) NonNull(android.annotation.NonNull)

Example 64 with VolumeInfo

use of android.os.storage.VolumeInfo in project platform_frameworks_base by android.

the class PackageHelper method resolveInstallVolume.

/**
     * Given a requested {@link PackageInfo#installLocation} and calculated
     * install size, pick the actual volume to install the app. Only considers
     * internal and private volumes, and prefers to keep an existing package on
     * its current volume.
     *
     * @return the {@link VolumeInfo#fsUuid} to install onto, or {@code null}
     *         for internal storage.
     */
public static String resolveInstallVolume(Context context, String packageName, int installLocation, long sizeBytes) throws IOException {
    final boolean forceAllowOnExternal = Settings.Global.getInt(context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
    // TODO: handle existing apps installed in ASEC; currently assumes
    // they'll end up back on internal storage
    ApplicationInfo existingInfo = null;
    try {
        existingInfo = context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (NameNotFoundException ignored) {
    }
    final StorageManager storageManager = context.getSystemService(StorageManager.class);
    final boolean fitsOnInternal = fitsOnInternal(context, sizeBytes);
    final ArraySet<String> allCandidates = new ArraySet<>();
    VolumeInfo bestCandidate = null;
    long bestCandidateAvailBytes = Long.MIN_VALUE;
    for (VolumeInfo vol : storageManager.getVolumes()) {
        if (vol.type == VolumeInfo.TYPE_PRIVATE && vol.isMountedWritable()) {
            final long availBytes = storageManager.getStorageBytesUntilLow(new File(vol.path));
            if (availBytes >= sizeBytes) {
                allCandidates.add(vol.fsUuid);
            }
            if (availBytes >= bestCandidateAvailBytes) {
                bestCandidate = vol;
                bestCandidateAvailBytes = availBytes;
            }
        }
    }
    // System apps always forced to internal storage
    if (existingInfo != null && existingInfo.isSystemApp()) {
        installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
    }
    // If app expresses strong desire for internal storage, honor it
    if (!forceAllowOnExternal && installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
        if (existingInfo != null && !Objects.equals(existingInfo.volumeUuid, StorageManager.UUID_PRIVATE_INTERNAL)) {
            throw new IOException("Cannot automatically move " + packageName + " from " + existingInfo.volumeUuid + " to internal storage");
        }
        if (fitsOnInternal) {
            return StorageManager.UUID_PRIVATE_INTERNAL;
        } else {
            throw new IOException("Requested internal only, but not enough space");
        }
    }
    // If app already exists somewhere, we must stay on that volume
    if (existingInfo != null) {
        if (Objects.equals(existingInfo.volumeUuid, StorageManager.UUID_PRIVATE_INTERNAL) && fitsOnInternal) {
            return StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (allCandidates.contains(existingInfo.volumeUuid)) {
            return existingInfo.volumeUuid;
        } else {
            throw new IOException("Not enough space on existing volume " + existingInfo.volumeUuid + " for " + packageName + " upgrade");
        }
    }
    // volume with most space
    if (bestCandidate != null) {
        return bestCandidate.fsUuid;
    } else if (fitsOnInternal) {
        return StorageManager.UUID_PRIVATE_INTERNAL;
    } else {
        throw new IOException("No special requests, but no room anywhere");
    }
}
Also used : ArraySet(android.util.ArraySet) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 65 with VolumeInfo

use of android.os.storage.VolumeInfo in project platform_frameworks_base by android.

the class StorageNotification method buildWizardMigratePendingIntent.

private PendingIntent buildWizardMigratePendingIntent(MoveInfo move) {
    final Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.deviceinfo.StorageWizardMigrateProgress");
    intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId);
    final VolumeInfo vol = mStorageManager.findVolumeByQualifiedUuid(move.volumeUuid);
    if (vol != null) {
        intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
    }
    return PendingIntent.getActivityAsUser(mContext, move.moveId, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) 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