Merge "We really want f_frsize and f_bavail." into oc-dev
am: fd463121c6
Change-Id: I55aebb3b452f4d41af7e5f54d0dff27e9bc6cca6
This commit is contained in:
@@ -61,15 +61,15 @@ public class StatFs {
|
||||
*/
|
||||
@Deprecated
|
||||
public int getBlockSize() {
|
||||
return (int) mStat.f_bsize;
|
||||
return (int) mStat.f_frsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* The size, in bytes, of a block on the file system. This corresponds to
|
||||
* the Unix {@code statvfs.f_bsize} field.
|
||||
* the Unix {@code statvfs.f_frsize} field.
|
||||
*/
|
||||
public long getBlockSizeLong() {
|
||||
return mStat.f_bsize;
|
||||
return mStat.f_frsize;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ public class StatFs {
|
||||
* will want to use {@link #getAvailableBytes()} instead.
|
||||
*/
|
||||
public long getFreeBytes() {
|
||||
return mStat.f_bfree * mStat.f_bsize;
|
||||
return mStat.f_bfree * mStat.f_frsize;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,13 +136,13 @@ public class StatFs {
|
||||
* applications.
|
||||
*/
|
||||
public long getAvailableBytes() {
|
||||
return mStat.f_bavail * mStat.f_bsize;
|
||||
return mStat.f_bavail * mStat.f_frsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* The total number of bytes supported by the file system.
|
||||
*/
|
||||
public long getTotalBytes() {
|
||||
return mStat.f_blocks * mStat.f_bsize;
|
||||
return mStat.f_blocks * mStat.f_frsize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,14 +220,8 @@ public class DefaultContainerService extends IntentService {
|
||||
public long[] getFileSystemStats(String path) {
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
|
||||
try {
|
||||
final StructStatVfs stat = Os.statvfs(path);
|
||||
final long totalSize = stat.f_blocks * stat.f_bsize;
|
||||
final long availSize = stat.f_bavail * stat.f_bsize;
|
||||
return new long[] { totalSize, availSize };
|
||||
} catch (ErrnoException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
final File file = new File(path);
|
||||
return new long[] { file.getTotalSpace(), file.getUsableSpace() };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
@@ -123,10 +122,10 @@ public class CacheQuotaServiceImpl extends CacheQuotaService {
|
||||
StorageManager storageManager = getSystemService(StorageManager.class);
|
||||
long freeBytes = 0;
|
||||
if (uuid == StorageManager.UUID_PRIVATE_INTERNAL) { // regular equals because of null
|
||||
freeBytes = Environment.getDataDirectory().getFreeSpace();
|
||||
freeBytes = Environment.getDataDirectory().getUsableSpace();
|
||||
} else {
|
||||
final VolumeInfo vol = storageManager.findVolumeByUuid(uuid);
|
||||
freeBytes = vol.getPath().getFreeSpace();
|
||||
freeBytes = vol.getPath().getUsableSpace();
|
||||
}
|
||||
return Math.round(freeBytes * CACHE_RESERVE_RATIO);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CacheQuotaServiceImplTest extends ServiceTestCase<CacheQuotaService
|
||||
setContext(mContext);
|
||||
when(mContext.getSystemService(Context.STORAGE_SERVICE)).thenReturn(mStorageManager);
|
||||
|
||||
when(mFile.getFreeSpace()).thenReturn(10000L);
|
||||
when(mFile.getUsableSpace()).thenReturn(10000L);
|
||||
when(mVolume.getPath()).thenReturn(mFile);
|
||||
when(mStorageManager.findVolumeByUuid(sTestVolUuid)).thenReturn(mVolume);
|
||||
when(mStorageManager.findVolumeByUuid(sSecondTestVolUuid)).thenReturn(mVolume);
|
||||
|
||||
@@ -386,7 +386,7 @@ public class ExternalStorageProvider extends FileSystemProvider {
|
||||
row.add(Root.COLUMN_TITLE, root.title);
|
||||
row.add(Root.COLUMN_DOCUMENT_ID, root.docId);
|
||||
row.add(Root.COLUMN_AVAILABLE_BYTES,
|
||||
root.reportAvailableBytes ? root.path.getFreeSpace() : -1);
|
||||
root.reportAvailableBytes ? root.path.getUsableSpace() : -1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -16,18 +16,15 @@
|
||||
|
||||
package com.android.settingslib.deviceinfo;
|
||||
|
||||
import android.os.storage.StorageManager;
|
||||
import android.app.AppGlobals;
|
||||
import android.app.usage.StorageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* PrivateStorageInfo provides information about the total and free storage on the device.
|
||||
*/
|
||||
public class PrivateStorageInfo {
|
||||
private static final String TAG = "PrivateStorageInfo";
|
||||
public final long freeBytes;
|
||||
public final long totalBytes;
|
||||
|
||||
@@ -37,45 +34,23 @@ public class PrivateStorageInfo {
|
||||
}
|
||||
|
||||
public static PrivateStorageInfo getPrivateStorageInfo(StorageVolumeProvider sm) {
|
||||
long totalInternalStorage = sm.getPrimaryStorageSize();
|
||||
final Context context = AppGlobals.getInitialApplication();
|
||||
final StorageStatsManager stats = context.getSystemService(StorageStatsManager.class);
|
||||
|
||||
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;
|
||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE && info.isMountedReadable()) {
|
||||
privateTotalBytes += stats.getTotalBytes(info.getFsUuid());
|
||||
privateFreeBytes += stats.getFreeBytes(info.getFsUuid());
|
||||
}
|
||||
privateTotalBytes += getTotalSize(info, totalInternalStorage);
|
||||
privateFreeBytes += path.getFreeSpace();
|
||||
}
|
||||
return new PrivateStorageInfo(privateFreeBytes, privateTotalBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total size in bytes for a given volume info.
|
||||
* @param info Info of the volume to check.
|
||||
* @param totalInternalStorage Total number of bytes in the internal storage to use if the
|
||||
* volume is the internal disk.
|
||||
*/
|
||||
public static long getTotalSize(VolumeInfo info, long totalInternalStorage) {
|
||||
// Device could have more than one primary storage, which could be located in the
|
||||
// internal flash (UUID_PRIVATE_INTERNAL) or in an external disk.
|
||||
// If it's internal, try to get its total size from StorageManager first
|
||||
// (totalInternalStorage), because that size is more precise because it accounts for
|
||||
// the system partition.
|
||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE
|
||||
&& Objects.equals(info.getFsUuid(), StorageManager.UUID_PRIVATE_INTERNAL)
|
||||
&& totalInternalStorage > 0) {
|
||||
return totalInternalStorage;
|
||||
} else {
|
||||
final File path = info.getPath();
|
||||
if (path == null) {
|
||||
// Should not happen, caller should have checked.
|
||||
Log.e(TAG, "info's path is null on getTotalSize(): " + info);
|
||||
return 0;
|
||||
}
|
||||
return path.getTotalSpace();
|
||||
}
|
||||
final Context context = AppGlobals.getInitialApplication();
|
||||
final StorageStatsManager stats = context.getSystemService(StorageStatsManager.class);
|
||||
return stats.getTotalBytes(info.getFsUuid());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22231,7 +22231,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
|
||||
if (DEBUG_INSTALL) Slog.d(TAG, "Measured code size " + stats.codeSize + ", data size "
|
||||
+ stats.dataSize);
|
||||
|
||||
final long startFreeBytes = measurePath.getFreeSpace();
|
||||
final long startFreeBytes = measurePath.getUsableSpace();
|
||||
final long sizeBytes;
|
||||
if (moveCompleteApp) {
|
||||
sizeBytes = stats.codeSize + stats.dataSize;
|
||||
@@ -22295,7 +22295,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
|
||||
final long deltaFreeBytes = startFreeBytes - measurePath.getFreeSpace();
|
||||
final long deltaFreeBytes = startFreeBytes - measurePath.getUsableSpace();
|
||||
final int progress = 10 + (int) MathUtils.constrain(
|
||||
((deltaFreeBytes * 80) / sizeBytes), 0, 80);
|
||||
mMoveCallbacks.notifyStatusChanged(moveId, progress);
|
||||
|
||||
@@ -398,7 +398,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
|
||||
super(looper);
|
||||
// TODO: Handle all private volumes.
|
||||
mStats = new StatFs(Environment.getDataDirectory().getAbsolutePath());
|
||||
mPreviousBytes = mStats.getFreeBytes();
|
||||
mPreviousBytes = mStats.getAvailableBytes();
|
||||
mMinimumThresholdBytes = mStats.getTotalBytes() * MINIMUM_CHANGE_DELTA;
|
||||
}
|
||||
|
||||
@@ -413,9 +413,9 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
|
||||
|
||||
switch (msg.what) {
|
||||
case MSG_CHECK_STORAGE_DELTA: {
|
||||
long bytesDelta = Math.abs(mPreviousBytes - mStats.getFreeBytes());
|
||||
long bytesDelta = Math.abs(mPreviousBytes - mStats.getAvailableBytes());
|
||||
if (bytesDelta > mMinimumThresholdBytes) {
|
||||
mPreviousBytes = mStats.getFreeBytes();
|
||||
mPreviousBytes = mStats.getAvailableBytes();
|
||||
recalculateQuotas(getInitializedStrategy());
|
||||
}
|
||||
sendEmptyMessageDelayed(MSG_CHECK_STORAGE_DELTA, DELAY_IN_MILLIS);
|
||||
@@ -434,7 +434,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
|
||||
|
||||
// If errors occurred getting the quotas from disk, let's re-calc them.
|
||||
if (mPreviousBytes < 0) {
|
||||
mPreviousBytes = mStats.getFreeBytes();
|
||||
mPreviousBytes = mStats.getAvailableBytes();
|
||||
recalculateQuotas(strategy);
|
||||
}
|
||||
sendEmptyMessageDelayed(MSG_CHECK_STORAGE_DELTA, DELAY_IN_MILLIS);
|
||||
|
||||
Reference in New Issue
Block a user