Search in sources :

Example 51 with StatFs

use of android.os.StatFs in project QuickAndroid by ImKarl.

the class QAFileManager method getSDCardInternalAvailableSize.

/** 
     * 获取内置SDCard可用大小
     * @return 
     */
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getSDCardInternalAvailableSize() {
    if (!existSDCardInternal()) {
        return -1;
    }
    File path = new File(getSDCardInternalRoot());
    StatFs stat = new StatFs(path.getPath());
    if (QASdkVersion.isSupport(QASdkVersion.JELLY_BEAN_MR2)) {
        return stat.getAvailableBytes();
    } else {
        long availableBlocks = stat.getAvailableBlocks();
        long blockSize = stat.getBlockSize();
        return availableBlocks * blockSize;
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File) TargetApi(android.annotation.TargetApi)

Example 52 with StatFs

use of android.os.StatFs in project android_frameworks_base by DirtyUnicorns.

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)

Example 53 with StatFs

use of android.os.StatFs in project android_frameworks_base by DirtyUnicorns.

the class LowStorageTest method fillupdisk.

// Fill up 100% of the data partition
public void fillupdisk(Context context) {
    final Context contextfill = context;
    new Thread() {

        @Override
        public void run() {
            try {
                // Fill up all the memory
                File path = Environment.getDataDirectory();
                StatFs stat = new StatFs(path.getPath());
                int totalBlocks = stat.getBlockCount();
                int noOfBlockToFill = stat.getAvailableBlocks();
                FileOutputStream fs = contextfill.openFileOutput("testdata", Context.MODE_APPEND);
                for (int i = 0; i < (noOfBlockToFill / NO_OF_BLOCKS_TO_FILL); i++) {
                    byte[] buf = new byte[mBlockSize * NO_OF_BLOCKS_TO_FILL];
                    fs.write(buf);
                    fs.flush();
                }
                // Fill up the last few block
                byte[] buf = new byte[(noOfBlockToFill % NO_OF_BLOCKS_TO_FILL) * mBlockSize];
                fs.write(buf);
                fs.flush();
                fs.close();
                // Finished, update the info
                synchronized (fillUpDone) {
                    fillUpDone.notify();
                }
            } catch (Exception e) {
                Log.v(TAG, e.toString());
            }
        }
    }.start();
}
Also used : Context(android.content.Context) StatFs(android.os.StatFs) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 54 with StatFs

use of android.os.StatFs in project android_frameworks_base by DirtyUnicorns.

the class DropBoxTest method testAgeLimits.

public void testAgeLimits() throws Exception {
    File dir = getEmptyDir("testAgeLimits");
    int blockSize = new StatFs(dir.getPath()).getBlockSize();
    // Limit storage to 10 blocks with an expiration of 1 second
    int kb = blockSize * 10 / 1024;
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_AGE_SECONDS, "1");
    Settings.Global.putString(cr, Settings.Global.DROPBOX_QUOTA_KB, Integer.toString(kb));
    // Write one normal entry and another so big that it is instantly tombstoned
    long before = System.currentTimeMillis();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    dropbox.addText("DropBoxTest", "TEST");
    addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
    // Verify that things are as expected
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
    assertEquals("TEST", e0.getText(80));
    assertEquals(null, e1.getText(80));
    assertEquals(-1, getEntrySize(e1));
    e0.close();
    e1.close();
    // Wait a second and write another entry -- old ones should be expunged
    Thread.sleep(2000);
    dropbox.addText("DropBoxTest", "TEST1");
    e0 = dropbox.getNextEntry(null, before);
    assertTrue(null == dropbox.getNextEntry(null, e0.getTimeMillis()));
    assertEquals("TEST1", e0.getText(80));
    e0.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) StatFs(android.os.StatFs) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

Example 55 with StatFs

use of android.os.StatFs in project android_frameworks_base by DirtyUnicorns.

the class DropBoxTest method testSizeLimits.

public void testSizeLimits() throws Exception {
    File dir = getEmptyDir("testSizeLimits");
    int blockSize = new StatFs(dir.getPath()).getBlockSize();
    // Limit storage to 10 blocks
    int kb = blockSize * 10 / 1024;
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_QUOTA_KB, Integer.toString(kb));
    // Three tags using a total of 12 blocks:
    // DropBoxTest0 [ ][ ]
    // DropBoxTest1 [x][ ][    ][ ][xxx(20 blocks)xxx]
    // DropBoxTest2 [xxxxxxxxxx][ ][ ]
    //
    // The blocks marked "x" will be removed due to storage restrictions.
    // Use random fill (so it doesn't compress), subtract a little for gzip overhead
    final int overhead = 64;
    long before = System.currentTimeMillis();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize * 2 - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize * 20 - overhead);
    addRandomEntry(dropbox, "DropBoxTest2", blockSize * 4 - overhead);
    addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
    DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
    DropBoxManager.Entry e4 = dropbox.getNextEntry(null, e3.getTimeMillis());
    DropBoxManager.Entry e5 = dropbox.getNextEntry(null, e4.getTimeMillis());
    DropBoxManager.Entry e6 = dropbox.getNextEntry(null, e5.getTimeMillis());
    DropBoxManager.Entry e7 = dropbox.getNextEntry(null, e6.getTimeMillis());
    DropBoxManager.Entry e8 = dropbox.getNextEntry(null, e7.getTimeMillis());
    DropBoxManager.Entry e9 = dropbox.getNextEntry(null, e8.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e9.getTimeMillis()));
    assertEquals("DropBoxTest0", e0.getTag());
    assertEquals("DropBoxTest0", e1.getTag());
    assertEquals(blockSize - overhead, getEntrySize(e0));
    assertEquals(blockSize - overhead, getEntrySize(e1));
    assertEquals("DropBoxTest1", e2.getTag());
    assertEquals("DropBoxTest1", e3.getTag());
    assertEquals("DropBoxTest1", e4.getTag());
    assertEquals("DropBoxTest1", e5.getTag());
    assertEquals("DropBoxTest1", e6.getTag());
    // Tombstone
    assertEquals(-1, getEntrySize(e2));
    assertEquals(blockSize - overhead, getEntrySize(e3));
    assertEquals(blockSize * 2 - overhead, getEntrySize(e4));
    assertEquals(blockSize - overhead, getEntrySize(e5));
    assertEquals(-1, getEntrySize(e6));
    assertEquals("DropBoxTest2", e7.getTag());
    assertEquals("DropBoxTest2", e8.getTag());
    assertEquals("DropBoxTest2", e9.getTag());
    // Tombstone
    assertEquals(-1, getEntrySize(e7));
    assertEquals(blockSize - overhead, getEntrySize(e8));
    assertEquals(blockSize - overhead, getEntrySize(e9));
    e0.close();
    e1.close();
    e2.close();
    e3.close();
    e4.close();
    e5.close();
    e6.close();
    e7.close();
    e8.close();
    e9.close();
    // Specifying a tag name skips tombstone records.
    DropBoxManager.Entry t0 = dropbox.getNextEntry("DropBoxTest1", before);
    DropBoxManager.Entry t1 = dropbox.getNextEntry("DropBoxTest1", t0.getTimeMillis());
    DropBoxManager.Entry t2 = dropbox.getNextEntry("DropBoxTest1", t1.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest1", t2.getTimeMillis()));
    assertEquals("DropBoxTest1", t0.getTag());
    assertEquals("DropBoxTest1", t1.getTag());
    assertEquals("DropBoxTest1", t2.getTag());
    assertEquals(blockSize - overhead, getEntrySize(t0));
    assertEquals(blockSize * 2 - overhead, getEntrySize(t1));
    assertEquals(blockSize - overhead, getEntrySize(t2));
    t0.close();
    t1.close();
    t2.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) StatFs(android.os.StatFs) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

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