Search in sources :

Example 46 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 47 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 48 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)

Example 49 with VolumeInfo

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

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

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

the class MountService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
    final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ", 160);
    synchronized (mLock) {
        pw.println("Disks:");
        pw.increaseIndent();
        for (int i = 0; i < mDisks.size(); i++) {
            final DiskInfo disk = mDisks.valueAt(i);
            disk.dump(pw);
        }
        pw.decreaseIndent();
        pw.println();
        pw.println("Volumes:");
        pw.increaseIndent();
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id))
                continue;
            vol.dump(pw);
        }
        pw.decreaseIndent();
        pw.println();
        pw.println("Records:");
        pw.increaseIndent();
        for (int i = 0; i < mRecords.size(); i++) {
            final VolumeRecord note = mRecords.valueAt(i);
            note.dump(pw);
        }
        pw.decreaseIndent();
        pw.println();
        pw.println("Primary storage UUID: " + mPrimaryStorageUuid);
        pw.println("Force adoptable: " + mForceAdoptable);
        pw.println();
        pw.println("Local unlocked users: " + Arrays.toString(mLocalUnlockedUsers));
        pw.println("System unlocked users: " + Arrays.toString(mSystemUnlockedUsers));
    }
    synchronized (mObbMounts) {
        pw.println();
        pw.println("mObbMounts:");
        pw.increaseIndent();
        final Iterator<Entry<IBinder, List<ObbState>>> binders = mObbMounts.entrySet().iterator();
        while (binders.hasNext()) {
            Entry<IBinder, List<ObbState>> e = binders.next();
            pw.println(e.getKey() + ":");
            pw.increaseIndent();
            final List<ObbState> obbStates = e.getValue();
            for (final ObbState obbState : obbStates) {
                pw.println(obbState);
            }
            pw.decreaseIndent();
        }
        pw.decreaseIndent();
        pw.println();
        pw.println("mObbPathToStateMap:");
        pw.increaseIndent();
        final Iterator<Entry<String, ObbState>> maps = mObbPathToStateMap.entrySet().iterator();
        while (maps.hasNext()) {
            final Entry<String, ObbState> e = maps.next();
            pw.print(e.getKey());
            pw.print(" -> ");
            pw.println(e.getValue());
        }
        pw.decreaseIndent();
    }
    pw.println();
    pw.println("mConnector:");
    pw.increaseIndent();
    mConnector.dump(fd, pw, args);
    pw.decreaseIndent();
    pw.println();
    pw.println("mCryptConnector:");
    pw.increaseIndent();
    mCryptConnector.dump(fd, pw, args);
    pw.decreaseIndent();
    pw.println();
    pw.print("Last maintenance: ");
    pw.println(TimeUtils.formatForLogging(mLastMaintenance));
}
Also used : DiskInfo(android.os.storage.DiskInfo) VolumeInfo(android.os.storage.VolumeInfo) VolumeRecord(android.os.storage.VolumeRecord) Entry(java.util.Map.Entry) IBinder(android.os.IBinder) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RemoteCallbackList(android.os.RemoteCallbackList) List(java.util.List) LinkedList(java.util.LinkedList) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

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