Search in sources :

Example 41 with VolumeInfo

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

the class DiskStatsLoggingService method onStartJob.

@Override
public boolean onStartJob(JobParameters params) {
    // subsequent runs.
    if (!isCharging(this) || !isDumpsysTaskEnabled(getContentResolver())) {
        jobFinished(params, true);
        return false;
    }
    VolumeInfo volume = getPackageManager().getPrimaryStorageCurrentVolume();
    // volume is null if the primary storage is not yet mounted.
    if (volume == null) {
        return false;
    }
    AppCollector collector = new AppCollector(this, volume);
    final int userId = UserHandle.myUserId();
    UserEnvironment environment = new UserEnvironment(userId);
    LogRunnable task = new LogRunnable();
    task.setRootDirectory(environment.getExternalStorageDirectory());
    task.setDownloadsDirectory(environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
    task.setSystemSize(FileCollector.getSystemSize(this));
    task.setLogOutputFile(new File(DUMPSYS_CACHE_PATH));
    task.setAppCollector(collector);
    task.setJobService(this, params);
    AsyncTask.execute(task);
    return true;
}
Also used : VolumeInfo(android.os.storage.VolumeInfo) UserEnvironment(android.os.Environment.UserEnvironment) File(java.io.File)

Example 42 with VolumeInfo

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

the class ExternalStorageProvider method updateVolumesLocked.

private void updateVolumesLocked() {
    mRoots.clear();
    VolumeInfo primaryVolume = null;
    final int userId = UserHandle.myUserId();
    final List<VolumeInfo> volumes = mStorageManager.getVolumes();
    for (VolumeInfo volume : volumes) {
        if (!volume.isMountedReadable())
            continue;
        final String rootId;
        final String title;
        if (volume.getType() == VolumeInfo.TYPE_EMULATED) {
            // a time, and it's always considered the primary
            if (DEBUG)
                Log.d(TAG, "Found primary volume: " + volume);
            rootId = ROOT_ID_PRIMARY_EMULATED;
            if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) {
                // This is basically the user's primary device storage.
                // Use device name for the volume since this is likely same thing
                // the user sees when they mount their phone on another device.
                String deviceName = Settings.Global.getString(getContext().getContentResolver(), Settings.Global.DEVICE_NAME);
                // Device name should always be set. In case it isn't, though,
                // fall back to a localized "Internal Storage" string.
                title = !TextUtils.isEmpty(deviceName) ? deviceName : getContext().getString(R.string.root_internal_storage);
            } else {
                // This should cover all other storage devices, like an SD card
                // or USB OTG drive plugged in. Using getBestVolumeDescription()
                // will give us a nice string like "Samsung SD card" or "SanDisk USB drive"
                final VolumeInfo privateVol = mStorageManager.findPrivateForEmulated(volume);
                title = mStorageManager.getBestVolumeDescription(privateVol);
            }
        } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC && volume.getMountUserId() == userId) {
            rootId = volume.getFsUuid();
            title = mStorageManager.getBestVolumeDescription(volume);
        } else {
            // Unsupported volume; ignore
            continue;
        }
        if (TextUtils.isEmpty(rootId)) {
            Log.d(TAG, "Missing UUID for " + volume.getId() + "; skipping");
            continue;
        }
        if (mRoots.containsKey(rootId)) {
            Log.w(TAG, "Duplicate UUID " + rootId + " for " + volume.getId() + "; skipping");
            continue;
        }
        final RootInfo root = new RootInfo();
        mRoots.put(rootId, root);
        root.rootId = rootId;
        root.flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD;
        final DiskInfo disk = volume.getDisk();
        if (DEBUG)
            Log.d(TAG, "Disk for root " + rootId + " is " + disk);
        if (disk != null && disk.isSd()) {
            root.flags |= Root.FLAG_REMOVABLE_SD;
        } else if (disk != null && disk.isUsb()) {
            root.flags |= Root.FLAG_REMOVABLE_USB;
        }
        if (volume.isPrimary()) {
            // save off the primary volume for subsequent "Home" dir initialization.
            primaryVolume = volume;
            root.flags |= Root.FLAG_ADVANCED;
        }
        // Dunno when this would NOT be the case, but never hurts to be correct.
        if (volume.isMountedWritable()) {
            root.flags |= Root.FLAG_SUPPORTS_CREATE;
        }
        root.title = title;
        if (volume.getType() == VolumeInfo.TYPE_PUBLIC) {
            root.flags |= Root.FLAG_HAS_SETTINGS;
        }
        if (volume.isVisibleForRead(userId)) {
            root.visiblePath = volume.getPathForUser(userId);
        } else {
            root.visiblePath = null;
        }
        root.path = volume.getInternalPathForUser(userId);
        try {
            root.docId = getDocIdForFile(root.path);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }
    // by calling either getPathForUser, or getInternalPathForUser.
    if (primaryVolume != null && primaryVolume.isVisible()) {
        final RootInfo root = new RootInfo();
        root.rootId = ROOT_ID_HOME;
        mRoots.put(root.rootId, root);
        root.title = getContext().getString(R.string.root_documents);
        // Only report bytes on *volumes*...as a matter of policy.
        root.reportAvailableBytes = false;
        root.flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD;
        // Dunno when this would NOT be the case, but never hurts to be correct.
        if (primaryVolume.isMountedWritable()) {
            root.flags |= Root.FLAG_SUPPORTS_CREATE;
        }
        // Create the "Documents" directory on disk (don't use the localized title).
        root.visiblePath = new File(primaryVolume.getPathForUser(userId), Environment.DIRECTORY_DOCUMENTS);
        root.path = new File(primaryVolume.getInternalPathForUser(userId), Environment.DIRECTORY_DOCUMENTS);
        try {
            root.docId = getDocIdForFile(root.path);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }
    Log.d(TAG, "After updating volumes, found " + mRoots.size() + " active roots");
    // Note this affects content://com.android.externalstorage.documents/root/39BD-07C5
    // as well as content://com.android.externalstorage.documents/document/*/children,
    // so just notify on content://com.android.externalstorage.documents/.
    getContext().getContentResolver().notifyChange(BASE_URI, null, false);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) DiskInfo(android.os.storage.DiskInfo) VolumeInfo(android.os.storage.VolumeInfo) File(java.io.File) Point(android.graphics.Point)

Example 43 with VolumeInfo

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

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)

Example 44 with VolumeInfo

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

the class AppCollectorTest method testOneValidApp.

@Test
public void testOneValidApp() throws Exception {
    addApplication("com.test.app", "testuuid");
    VolumeInfo volume = new VolumeInfo("testuuid", 0, null, null);
    volume.fsUuid = "testuuid";
    AppCollector collector = new AppCollector(mContext, volume);
    PackageStats stats = new PackageStats("com.test.app");
    // Set up this to handle the asynchronous call to the PackageManager. This returns the
    // package info for the specified package.
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            try {
                ((IPackageStatsObserver.Stub) invocation.getArguments()[2]).onGetStatsCompleted(stats, true);
            } catch (Exception e) {
                // We fail instead of just letting the exception fly because throwing
                // out of the callback like this on the background thread causes the test
                // runner to crash, rather than reporting the failure.
                fail();
            }
            return null;
        }
    }).when(mPm).getPackageSizeInfoAsUser(eq("com.test.app"), eq(0), any());
    // Because getPackageStats is a blocking call, we block execution of the test until the
    // call finishes. In order to finish the call, we need the above answer to execute.
    List<PackageStats> myStats = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            myStats.addAll(collector.getPackageStats(TIMEOUT));
            latch.countDown();
        }
    }).start();
    latch.await();
    assertThat(myStats).containsExactly(stats);
}
Also used : ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PackageStats(android.content.pm.PackageStats) IPackageStatsObserver(android.content.pm.IPackageStatsObserver) Test(org.junit.Test)

Example 45 with VolumeInfo

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

the class AppCollectorTest method testMultipleUsersOneApp.

@Test
public void testMultipleUsersOneApp() throws Exception {
    addApplication("com.test.app", "testuuid");
    ApplicationInfo otherUsersApp = new ApplicationInfo();
    otherUsersApp.packageName = "com.test.app";
    otherUsersApp.volumeUuid = "testuuid";
    otherUsersApp.uid = 1;
    mUsers.add(new UserInfo(1, "", 0));
    VolumeInfo volume = new VolumeInfo("testuuid", 0, null, null);
    volume.fsUuid = "testuuid";
    AppCollector collector = new AppCollector(mContext, volume);
    PackageStats stats = new PackageStats("com.test.app");
    PackageStats otherStats = new PackageStats("com.test.app");
    otherStats.userHandle = 1;
    // Set up this to handle the asynchronous call to the PackageManager. This returns the
    // package info for our packages.
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            try {
                ((IPackageStatsObserver.Stub) invocation.getArguments()[2]).onGetStatsCompleted(stats, true);
                // Now callback for the other uid.
                ((IPackageStatsObserver.Stub) invocation.getArguments()[2]).onGetStatsCompleted(otherStats, true);
            } catch (Exception e) {
                // We fail instead of just letting the exception fly because throwing
                // out of the callback like this on the background thread causes the test
                // runner to crash, rather than reporting the failure.
                fail();
            }
            return null;
        }
    }).when(mPm).getPackageSizeInfoAsUser(eq("com.test.app"), eq(0), any());
    // Because getPackageStats is a blocking call, we block execution of the test until the
    // call finishes. In order to finish the call, we need the above answer to execute.
    List<PackageStats> myStats = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            myStats.addAll(collector.getPackageStats(TIMEOUT));
            latch.countDown();
        }
    }).start();
    latch.await();
    assertThat(myStats).containsAllOf(stats, otherStats);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) VolumeInfo(android.os.storage.VolumeInfo) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PackageStats(android.content.pm.PackageStats) IPackageStatsObserver(android.content.pm.IPackageStatsObserver) Test(org.junit.Test)

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