Search in sources :

Example 56 with VolumeInfo

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

the class MountService method unmount.

@Override
public void unmount(String volId) {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();
    final VolumeInfo vol = findVolumeByIdOrThrow(volId);
    // TODO: expand PMS to know about multiple volumes
    if (vol.isPrimaryPhysical()) {
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mUnmountLock) {
                mUnmountSignal = new CountDownLatch(1);
                mPms.updateExternalMediaStatus(false, true);
                waitForLatch(mUnmountSignal, "mUnmountSignal");
                mUnmountSignal = null;
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    try {
        mConnector.execute("volume", "unmount", vol.id);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : VolumeInfo(android.os.storage.VolumeInfo) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 57 with VolumeInfo

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

the class MountService method onVolumeCreatedLocked.

private void onVolumeCreatedLocked(VolumeInfo vol) {
    // power off alarm need the access to external storage for audio files.
    // So in power off alarm mode, primary storage need to be mounted.
    boolean isAlarmBoot = SystemProperties.getBoolean("ro.alarm_boot", false);
    if (mPms.isOnlyCoreApps() && !isAlarmBoot) {
        Slog.d(TAG, "System booted in core-only mode; ignoring volume " + vol.getId());
        return;
    }
    if (vol.type == VolumeInfo.TYPE_EMULATED) {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        final VolumeInfo privateVol = storage.findPrivateForEmulated(vol);
        if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, mPrimaryStorageUuid) && VolumeInfo.ID_PRIVATE_INTERNAL.equals(privateVol.id)) {
            Slog.v(TAG, "Found primary storage at " + vol);
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
            mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
        } else if (Objects.equals(privateVol.fsUuid, mPrimaryStorageUuid)) {
            Slog.v(TAG, "Found primary storage at " + vol);
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
            mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
        }
    } else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
        // TODO: only look at first public partition
        if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, mPrimaryStorageUuid) && vol.disk.isDefaultPrimary()) {
            Slog.v(TAG, "Found primary storage at " + vol);
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
        }
        // make sdcard visible.
        if (vol.disk.isAdoptable() || vol.disk.isSd()) {
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
        }
        vol.mountUserId = mCurrentUserId;
        mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
    } else if (vol.type == VolumeInfo.TYPE_PRIVATE) {
        mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
    } else {
        Slog.d(TAG, "Skipping automatic mounting of " + vol);
    }
}
Also used : StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo)

Example 58 with VolumeInfo

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

the class PrivateStorageInfo method getPrivateStorageInfo.

public static PrivateStorageInfo getPrivateStorageInfo(StorageVolumeProvider sm) {
    long totalInternalStorage = sm.getPrimaryStorageSize();
    long privateFreeBytes = 0;
    long privateTotalBytes = 0;
    for (VolumeInfo info : sm.getVolumes()) {
        final File path = info.getPath();
        if (info.getType() != VolumeInfo.TYPE_PRIVATE || path == null) {
            continue;
        }
        privateTotalBytes += getTotalSize(info, totalInternalStorage);
        privateFreeBytes += path.getFreeSpace();
    }
    return new PrivateStorageInfo(privateFreeBytes, privateTotalBytes);
}
Also used : VolumeInfo(android.os.storage.VolumeInfo) File(java.io.File)

Example 59 with VolumeInfo

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

the class StorageNotification method updateMissingPrivateVolumes.

private void updateMissingPrivateVolumes() {
    final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
    for (VolumeRecord rec : recs) {
        if (rec.getType() != VolumeInfo.TYPE_PRIVATE)
            continue;
        final String fsUuid = rec.getFsUuid();
        final VolumeInfo info = mStorageManager.findVolumeByUuid(fsUuid);
        if ((info != null && info.isMountedWritable()) || rec.isSnoozed()) {
            // Yay, private volume is here, or user snoozed
            mNotificationManager.cancelAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE, UserHandle.ALL);
        } else {
            // Boo, annoy the user to reinsert the private volume
            final CharSequence title = mContext.getString(R.string.ext_media_missing_title, rec.getNickname());
            final CharSequence text = mContext.getString(R.string.ext_media_missing_message);
            Notification.Builder builder = new Notification.Builder(mContext).setSmallIcon(R.drawable.ic_sd_card_48dp).setColor(mContext.getColor(R.color.system_notification_accent_color)).setContentTitle(title).setContentText(text).setContentIntent(buildForgetPendingIntent(rec)).setStyle(new Notification.BigTextStyle().bigText(text)).setVisibility(Notification.VISIBILITY_PUBLIC).setLocalOnly(true).setCategory(Notification.CATEGORY_SYSTEM).setDeleteIntent(buildSnoozeIntent(fsUuid));
            SystemUI.overrideNotificationAppName(mContext, builder);
            mNotificationManager.notifyAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE, builder.build(), UserHandle.ALL);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) VolumeInfo(android.os.storage.VolumeInfo) Notification(android.app.Notification)

Example 60 with VolumeInfo

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

the class StorageNotification method updateMissingPrivateVolumes.

private void updateMissingPrivateVolumes() {
    final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
    for (VolumeRecord rec : recs) {
        if (rec.getType() != VolumeInfo.TYPE_PRIVATE)
            continue;
        final String fsUuid = rec.getFsUuid();
        final VolumeInfo info = mStorageManager.findVolumeByUuid(fsUuid);
        if ((info != null && info.isMountedWritable()) || rec.isSnoozed()) {
            // Yay, private volume is here, or user snoozed
            mNotificationManager.cancelAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE, UserHandle.ALL);
        } else {
            // Boo, annoy the user to reinsert the private volume
            final CharSequence title = mContext.getString(R.string.ext_media_missing_title, rec.getNickname());
            final CharSequence text = mContext.getString(R.string.ext_media_missing_message);
            Notification.Builder builder = new Notification.Builder(mContext).setSmallIcon(R.drawable.ic_sd_card_48dp).setColor(mContext.getColor(R.color.system_notification_accent_color)).setContentTitle(title).setContentText(text).setContentIntent(buildForgetPendingIntent(rec)).setStyle(new Notification.BigTextStyle().bigText(text)).setVisibility(Notification.VISIBILITY_PUBLIC).setLocalOnly(true).setCategory(Notification.CATEGORY_SYSTEM).setDeleteIntent(buildSnoozeIntent(fsUuid));
            SystemUI.overrideNotificationAppName(mContext, builder);
            mNotificationManager.notifyAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE, builder.build(), UserHandle.ALL);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) VolumeInfo(android.os.storage.VolumeInfo) Notification(android.app.Notification)

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