A33平台中一些客户定制软件中要求把存储容量显示做成4G、8G、16G显示,这样在终端客户就不需要解释容量显示不正确的问题:
在这一问题上,我们首先会想到一个“availSize”或者“totalSize”,通过跟踪我们发现,在\android\frameworks\base\packages\DefaultContainerService\src\com\android\defcontainer\DefaultContainerService.java 中:
......
@Override
public long[] getFileSystemStats(String path) {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
final StructStatVfs stat = Libcore.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);
}
}
......
修改如下:
......
public long[] getFileSystemStats(String path) {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
final StructStatVfs stat = Libcore.os.statvfs(path);
boolean phonysize = false; // set true if need phony size, Await
long totalSize = stat.f_blocks * stat.f_bsize;
long availSize = stat.f_bavail * stat.f_bsize;
if(phonysize) {
long usedsize = totalSize - availSize;
//if("/mnt/sdcard".equals(path)) { // set path to "/mnt/sdcard" if single user
if("/data".equals(path)) { // set path to "/data" if multiusers
if((totalSize > 8*1024L*1024*1024) && (totalSize < 16*1024L*1024*1024)) {
totalSize = 16*1024L*1024*1024;
} else if ((totalSize > 4*1024L*1024*1024) && (totalSize < 8*1024L*1024*1024)) {
totalSize = 8*1024L*1024*1024;
} else if (totalSize < 4*1024L*1024*1024) {
totalSize = 4*1024L*1024*1024;
}
}
availSize = totalSize - usedsize;
}
return new long[] { totalSize, availSize };
} catch (ErrnoException e) {
throw new IllegalStateException(e);
}
}