Search in sources :

Example 31 with StatFs

use of android.os.StatFs in project superCleanMaster by joyoyao.

the class StorageUtil method getSystemSpaceInfo.

public static SDCardInfo getSystemSpaceInfo(Context context) {
    File path = Environment.getDataDirectory();
    // File path = context.getCacheDir().getAbsoluteFile();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    long availableBlocks = stat.getAvailableBlocks();
    long totalSize = blockSize * totalBlocks;
    long availSize = availableBlocks * blockSize;
    SDCardInfo info = new SDCardInfo();
    info.total = totalSize;
    info.free = availSize;
    return info;
}
Also used : StatFs(android.os.StatFs) SDCardInfo(com.yzy.supercleanmaster.model.SDCardInfo) File(java.io.File)

Example 32 with StatFs

use of android.os.StatFs in project android-app-common-tasks by multidots.

the class CropImage method calculatePicturesRemaining.

private static int calculatePicturesRemaining(Activity activity) {
    try {
        /*if (!ImageManager.hasStorage()) {
                return NO_STORAGE_ERROR;
            } else {*/
        String storageDirectory;
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            storageDirectory = Environment.getExternalStorageDirectory().toString();
        } else {
            storageDirectory = activity.getFilesDir().toString();
        }
        StatFs stat = new StatFs(storageDirectory);
        float remaining = ((float) stat.getAvailableBlocks() * (float) stat.getBlockSize()) / 400000F;
        return (int) remaining;
    //}
    } catch (Exception ex) {
        // blank since we really don't know.
        return CANNOT_STAT_ERROR;
    }
}
Also used : StatFs(android.os.StatFs) IOException(java.io.IOException)

Example 33 with StatFs

use of android.os.StatFs in project android-app-common-tasks by multidots.

the class CropImage method calculatePicturesRemaining.

private static int calculatePicturesRemaining(Activity activity) {
    try {
        /*if (!ImageManager.hasStorage()) {
                return NO_STORAGE_ERROR;
            } else {*/
        String storageDirectory;
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            storageDirectory = Environment.getExternalStorageDirectory().toString();
        } else {
            storageDirectory = activity.getFilesDir().toString();
        }
        StatFs stat = new StatFs(storageDirectory);
        float remaining = ((float) stat.getAvailableBlocks() * (float) stat.getBlockSize()) / 400000F;
        return (int) remaining;
    //}
    } catch (Exception ex) {
        // blank since we really don't know.
        return CANNOT_STAT_ERROR;
    }
}
Also used : StatFs(android.os.StatFs) IOException(java.io.IOException)

Example 34 with StatFs

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

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

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

the class AppCacheTest method testFreeStorage.

// TODO: flaky test, omit from LargeTest for now
//@LargeTest
public void testFreeStorage() throws Exception {
    boolean TRACKING = true;
    StatFs st = new StatFs("/data");
    long blks1 = getFreeStorageBlks(st);
    if (localLOGV || TRACKING)
        Log.i(TAG, "Available free blocks=" + blks1);
    long availableMem = getFreeStorageSize(st);
    File cacheDir = mContext.getCacheDir();
    assertNotNull(cacheDir);
    createTestFiles1(cacheDir, "testtmpdir", 5);
    long blks2 = getFreeStorageBlks(st);
    if (localLOGV || TRACKING)
        Log.i(TAG, "Available blocks after writing test files in application cache=" + blks2);
    // Create receiver and register it
    FreeStorageReceiver receiver = new FreeStorageReceiver();
    mContext.registerReceiver(receiver, new IntentFilter(FreeStorageReceiver.ACTION_FREE));
    PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, new Intent(FreeStorageReceiver.ACTION_FREE), 0);
    // Invoke PackageManager api
    if (!invokePMFreeStorage(availableMem, receiver, pi)) {
        fail("Could not invoke PackageManager free storage API");
    }
    long blks3 = getFreeStorageBlks(st);
    if (localLOGV || TRACKING)
        Log.i(TAG, "Available blocks after freeing cache" + blks3);
    assertEquals(receiver.getResultCode(), 1);
    mContext.unregisterReceiver(receiver);
    // Verify result  
    verifyTestFiles1(cacheDir, "testtmpdir", 5);
}
Also used : IntentFilter(android.content.IntentFilter) StatFs(android.os.StatFs) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) 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