Search in sources :

Example 26 with StatFs

use of android.os.StatFs in project platform_frameworks_base by android.

the class PackageManagerTests method checkInt.

private boolean checkInt(long pkgLen) {
    StatFs intStats = new StatFs(Environment.getDataDirectory().getPath());
    long intSize = (long) intStats.getBlockCount() * (long) intStats.getBlockSize();
    long iSize = (long) intStats.getAvailableBlocks() * (long) intStats.getBlockSize();
    // TODO check for thresholds here?
    return pkgLen <= iSize;
}
Also used : StatFs(android.os.StatFs)

Example 27 with StatFs

use of android.os.StatFs in project platform_frameworks_base by android.

the class AppCacheTest method testFreeApplicationCacheSomeFiles.

public void testFreeApplicationCacheSomeFiles() throws Exception {
    StatFs st = new StatFs("/data");
    long blks1 = getFreeStorageBlks(st);
    File cacheDir = mContext.getCacheDir();
    assertNotNull(cacheDir);
    createTestFiles1(cacheDir, "testtmpdir", 5);
    long blks2 = getFreeStorageBlks(st);
    Log.i(TAG, "blk1=" + blks1 + ", blks2=" + blks2);
    long diff = (blks1 - blks2 - 2);
    if (!invokePMFreeApplicationCache(diff * st.getBlockSize())) {
        fail("Could not successfully invoke PackageManager free app cache API");
    }
    long blks3 = getFreeStorageBlks(st);
    //blks3 should be greater than blks2 and less than blks1
    if (!((blks3 <= blks1) && (blks3 >= blks2))) {
        failStr("Expected " + (blks1 - blks2) + " number of blocks to be freed but freed only " + (blks1 - blks3));
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 28 with StatFs

use of android.os.StatFs in project platform_frameworks_base by android.

the class DownloadManagerStressTest method testDownloadToCacheWithAlmostFullCache.

/**
     * Tests downloading a file to system cache when there isn't enough space in the system cache 
     * to hold the entire file. DownloadManager deletes enough files to make space for the
     * new download.
     */
@LargeTest
public void testDownloadToCacheWithAlmostFullCache() throws Exception {
    // 1MB
    int DOWNLOAD_FILE_SIZE = 1024 * 1024;
    StatFs fs = new StatFs(CACHE_DIR);
    int blockSize = fs.getBlockSize();
    int availableBlocks = fs.getAvailableBlocks();
    int availableBytes = blockSize * availableBlocks;
    Log.i(TAG, "INITIAL stage, available space in /cache: " + availableBytes);
    File outFile = File.createTempFile("DM_TEST", null, new File(CACHE_DIR));
    byte[] buffer = new byte[blockSize];
    try {
        // download size, and leave that much freespace left on the cache partition
        if (DOWNLOAD_FILE_SIZE <= availableBytes) {
            int writeSizeBytes = availableBytes - (DOWNLOAD_FILE_SIZE / 2);
            int writeSizeBlocks = writeSizeBytes / blockSize;
            int remainderSizeBlocks = availableBlocks - writeSizeBlocks;
            FileOutputStream fo = null;
            try {
                fo = new FileOutputStream(outFile);
                while (fs.getAvailableBlocks() >= remainderSizeBlocks) {
                    fo.write(buffer);
                    fs.restat(CACHE_DIR);
                }
            } catch (IOException e) {
                Log.e(LOG_TAG, "error filling file: ", e);
                throw e;
            } finally {
                if (fo != null) {
                    fo.close();
                }
            }
        }
        // /cache should now be almost full. 
        long spaceAvailable = fs.getAvailableBlocks() * blockSize;
        Log.i(TAG, "BEFORE download, available space in /cache: " + spaceAvailable);
        assertTrue(DOWNLOAD_FILE_SIZE > spaceAvailable);
        // try to download 1MB file into /cache - and it should succeed
        byte[] blobData = generateData(DOWNLOAD_FILE_SIZE, DataType.TEXT);
        long dlRequest = doBasicDownload(blobData, DOWNLOAD_TO_SYSTEM_CACHE);
        verifyAndCleanupSingleFileDownload(dlRequest, blobData);
    } finally {
        if (outFile != null) {
            outFile.delete();
        }
    }
}
Also used : StatFs(android.os.StatFs) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 29 with StatFs

use of android.os.StatFs in project platform_frameworks_base by android.

the class DiskStatsService method reportFreeSpace.

private void reportFreeSpace(File path, String name, PrintWriter pw) {
    try {
        StatFs statfs = new StatFs(path.getPath());
        long bsize = statfs.getBlockSize();
        long avail = statfs.getAvailableBlocks();
        long total = statfs.getBlockCount();
        if (bsize <= 0 || total <= 0) {
            throw new IllegalArgumentException("Invalid stat: bsize=" + bsize + " avail=" + avail + " total=" + total);
        }
        pw.print(name);
        pw.print("-Free: ");
        pw.print(avail * bsize / 1024);
        pw.print("K / ");
        pw.print(total * bsize / 1024);
        pw.print("K total = ");
        pw.print(avail * 100 / total);
        pw.println("% free");
    } catch (IllegalArgumentException e) {
        pw.print(name);
        pw.print("-Error: ");
        pw.println(e.toString());
        return;
    }
}
Also used : StatFs(android.os.StatFs)

Example 30 with StatFs

use of android.os.StatFs in project platform_frameworks_base by android.

the class LowStorageTest method updateInfo.

public void updateInfo(Context context) {
    fillupdisk(this);
    synchronized (fillUpDone) {
        try {
            fillUpDone.wait(WAIT_FOR_FINISH);
        } catch (Exception e) {
            Log.v(TAG, "wait was interrupted.");
        }
    }
    try {
        // The stat didn't relect the correct data right away
        // put some extra time to make sure if get the right size.
        Thread.sleep(WAIT_FOR_SYSTEM_UPDATE);
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long availableBlocks = stat.getAvailableBlocks();
        TextView freeSizeTextView = (TextView) findViewById(R.id.freesize);
        freeSizeTextView.setText(Long.toString((availableBlocks * mBlockSize) / BYTE_SIZE));
        TextView statusTextView = (TextView) findViewById(R.id.status);
        statusTextView.setText("Finished. You can start the test now.");
    } catch (Exception e) {
        Log.v(TAG, e.toString());
    }
}
Also used : StatFs(android.os.StatFs) TextView(android.widget.TextView) File(java.io.File)

Aggregations

StatFs (android.os.StatFs)196 File (java.io.File)120 IOException (java.io.IOException)30 FileOutputStream (java.io.FileOutputStream)17 TargetApi (android.annotation.TargetApi)15 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 FileNotFoundException (java.io.FileNotFoundException)11 ContentResolver (android.content.ContentResolver)10 DropBoxManager (android.os.DropBoxManager)10 TextView (android.widget.TextView)10 DropBoxManagerService (com.android.server.DropBoxManagerService)10 Test (org.junit.Test)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 IntentFilter (android.content.IntentFilter)6 Context (android.content.Context)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 Button (android.widget.Button)5 SuppressLint (android.annotation.SuppressLint)3 SDCardInfo (com.yzy.supercleanmaster.model.SDCardInfo)3