Search in sources :

Example 6 with StatFs

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

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 7 with StatFs

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

the class DefaultContainerService method isUnderExternalThreshold.

/**
     * Measure a file to see if it fits in the external free space.
     *
     * @param apkFile file to check
     * @return true if file fits
     * @throws IOException when file does not exist
     */
private boolean isUnderExternalThreshold(File apkFile, boolean isForwardLocked) throws IOException {
    if (Environment.isExternalStorageEmulated()) {
        return false;
    }
    final int sizeMb = calculateContainerSize(apkFile, isForwardLocked);
    final int availSdMb;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        final StatFs sdStats = new StatFs(Environment.getExternalStorageDirectory().getPath());
        final int blocksToMb = (1 << 20) / sdStats.getBlockSize();
        availSdMb = sdStats.getAvailableBlocks() / blocksToMb;
    } else {
        availSdMb = -1;
    }
    return availSdMb > sizeMb;
}
Also used : StructStatFs(libcore.io.StructStatFs) StatFs(android.os.StatFs)

Example 8 with StatFs

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

the class DropBoxManagerService method init.

///////////////////////////////////////////////////////////////////////////
/** If never run before, scans disk contents to build in-memory tracking data. */
private synchronized void init() throws IOException {
    if (mStatFs == null) {
        if (!mDropBoxDir.isDirectory() && !mDropBoxDir.mkdirs()) {
            throw new IOException("Can't mkdir: " + mDropBoxDir);
        }
        try {
            mStatFs = new StatFs(mDropBoxDir.getPath());
            mBlockSize = mStatFs.getBlockSize();
        } catch (IllegalArgumentException e) {
            // StatFs throws this on error
            throw new IOException("Can't statfs: " + mDropBoxDir);
        }
    }
    if (mAllFiles == null) {
        File[] files = mDropBoxDir.listFiles();
        if (files == null)
            throw new IOException("Can't list files: " + mDropBoxDir);
        mAllFiles = new FileList();
        mFilesByTag = new HashMap<String, FileList>();
        // Scan pre-existing files.
        for (File file : files) {
            if (file.getName().endsWith(".tmp")) {
                Slog.i(TAG, "Cleaning temp file: " + file);
                file.delete();
                continue;
            }
            EntryFile entry = new EntryFile(file, mBlockSize);
            if (entry.tag == null) {
                Slog.w(TAG, "Unrecognized file: " + file);
                continue;
            } else if (entry.timestampMillis == 0) {
                Slog.w(TAG, "Invalid filename: " + file);
                file.delete();
                continue;
            }
            enrollEntry(entry);
        }
    }
}
Also used : StatFs(android.os.StatFs) IOException(java.io.IOException) File(java.io.File)

Example 9 with StatFs

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

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(service);
    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 10 with StatFs

use of android.os.StatFs in project Anki-Android by Ramblurr.

the class CustomExceptionHandler method getAvailableInternalMemorySize.

private long getAvailableInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}
Also used : StatFs(android.os.StatFs) 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