一、文件管理器apk
FileInfoAdapter.java
1、添加导包
import android.os.SystemProperties;
import com.mediatek.common.storage.IStorageManagerEx;
import com.mediatek.common.MediatekClassFactory;
2、
//change start
public String getSizeString(String sizeNum, float fsizeMult) {
String sizeStr = "";
int index = sizeNum.indexOf("G");
if (Float.parseFloat(sizeNum.substring(0, index)) > 32) {
float fsize = Float.parseFloat(sizeNum.substring(0, index)) / fsizeMult;
if (String.valueOf(fsize).length() > 5) {
sizeStr = String.valueOf(fsize).substring(0, 5);
}
return sizeNum.replace(sizeNum.substring(0, index), sizeStr);
} else {
return sizeNum;
}
}
//change end
private void setSizeText(TextView textView, FileInfo fileInfo) {
if (fileInfo.isDirectory()) {
if (MountPointManager.getInstance().isMountPoint(fileInfo.getFileAbsolutePath())) {
StringBuilder sb = new StringBuilder();
//change start
long freeSpace;
String freeSpaceString;
long totalSpace;
String totalSpaces;
float fsizeMult = Float.parseFloat(SystemProperties.get("ro.file.sizemult", "5.48"));
String status = fileInfo.getFileAbsolutePath();
//KK版本
IStorageManagerEx sm = MediatekClassFactory.createInstance(IStorageManagerEx.class);
boolean sdExist = sm.getSdSwapState();
//JB版本
//boolean sdExist = false;
//sdExist = (Boolean)MediatekClassFactory.createInstance(IStorageManagerEx.class,
// IStorageManagerEx.GET_SWAP_STATE);
if (sdExist) {
if (status.equals("/storage/sdcard1")) {
freeSpace = (long)(fileInfo.getFile().getTotalSpace() * fsizeMult-(fileInfo.getFile().getTotalSpace()-fileInfo.getFile().getFreeSpace()));
freeSpaceString = FileUtils.sizeToString(freeSpace);
totalSpace = (long)(fileInfo.getFile().getTotalSpace() * fsizeMult);
totalSpaces = FileUtils.sizeToString(totalSpace);
freeSpaceString = getSizeString(freeSpaceString, fsizeMult);
totalSpaces = getSizeString(totalSpaces, fsizeMult);
} else {
freeSpace = fileInfo.getFile().getFreeSpace();
freeSpaceString = FileUtils.sizeToString(freeSpace);
totalSpace = fileInfo.getFile().getTotalSpace();
totalSpaces = FileUtils.sizeToString(totalSpace);
}
} else {
if (status.equals("/storage/sdcard0")) {
freeSpace = (long)(fileInfo.getFile().getTotalSpace() * fsizeMult-(fileInfo.getFile().getTotalSpace()-fileInfo.getFile().getFreeSpace()));
freeSpaceString = FileUtils.sizeToString(freeSpace);
totalSpace = (long)(fileInfo.getFile().getTotalSpace() * fsizeMult);
totalSpaces = FileUtils.sizeToString(totalSpace);
freeSpaceString = getSizeString(freeSpaceString, fsizeMult);
totalSpaces = getSizeString(totalSpaces, fsizeMult);
} else {
freeSpace = fileInfo.getFile().getFreeSpace();
freeSpaceString = FileUtils.sizeToString(freeSpace);
totalSpace = fileInfo.getFile().getTotalSpace();
totalSpaces = FileUtils.sizeToString(totalSpace);
}
}
//change end
LogUtils.d(TAG, "setSizeText, file name = " + fileInfo.getFileName()
+ ",file path = " + fileInfo.getFileAbsolutePath());
LogUtils.d(TAG, "setSizeText, freeSpace = " + freeSpace + ",totalSpace = "
+ totalSpace);
sb.append(mResources.getString(R.string.free_space)).append(" ");
sb.append(freeSpaceString).append(" \n");
sb.append(mResources.getString(R.string.total_space)).append(" ");
sb.append(totalSpaces).append(" ");
textView.setText(sb.toString());
textView.setVisibility(View.VISIBLE);
} else {
// it is a directory
textView.setVisibility(View.GONE);
}
} else {
StringBuilder sb = new StringBuilder();
sb.append(mResources.getString(R.string.size)).append(" ");
sb.append(fileInfo.getFileSizeStr());
textView.setText(sb.toString());
textView.setVisibility(View.VISIBLE);
}
}
二、Setings.apk
StorageMeasurement.java
private void measureApproximateStorage(IMediaContainerService imcs) {
/*final String path = mVolume != null ? mVolume.getPath()
: Environment.getDataDirectory().getPath();*/
/**
* M: MTK add reserve data feature on sd share load, so on the sd share load
* when calculating the internal storage total size and avail size, use the
* external storage path(such as /sdcard/emulated/0) instead of it.
*/
final String path;
Intent intent = new Intent();
mStorageVolume = intent.getParcelableExtra(StorageVolume.EXTRA_STORAGE_VOLUME);
//change start
boolean sdExist = false;
IStorageManagerEx sm = MediatekClassFactory.createInstance(IStorageManagerEx.class);
if (FeatureOption.MTK_2SDCARD_SWAP && (mStorageVolume == null)) {
sdExist = sm.getSdSwapState(); //(Boolean)MediatekClassFactory.createInstance(IStorageManagerEx.class,
//IStorageManagerEx.GET_SWAP_STATE);
}
//change end
if(mVolume != null) {
path = mVolume.getPath();
} else {
if(FeatureOption.MTK_SHARED_SDCARD) {
path = Environment.getLegacyExternalStorageDirectory().getPath();
} else {
path = Environment.getDataDirectory().getPath();
}
}
try {
final long[] stats = imcs.getFileSystemStats(path);
if(mVolume!=null && sdExist == true && mVolume.getPath().toString().equals ("/storage/sdcard1")&&!((SystemProperties.get("ro.sdcard.size")).equals("0")))
{
Log.w(TAG, "ro.sdcard.size="+SystemProperties.get("ro.sdcard.size"));
mTotalSize = sdcard_size*1048576;
mAvailSize = sdcard_size*1048576-stats[0]+stats[1];
}
else if(mVolume!=null && sdExist == false && mVolume.getPath().toString().equals ("/storage/sdcard0")&&!((SystemProperties.get("ro.sdcard.size")).equals("0")))
{
mTotalSize = sdcard_size*1048576;
mAvailSize = sdcard_size*1048576-stats[0]+stats[1];
}
else if(path.toString().equals (Environment.getDataDirectory().getPath().toString())&&!((SystemProperties.get("ro.phone.size")).equals("0")))
{
Log.w(TAG, "ro.phone.size="+SystemProperties.get("ro.phone.size"));
mTotalSize = phone_size*1048576;
mAvailSize = phone_size*1048576-stats[0]+stats[1];
}
//change start
//MTK_SHARED_SDCARD的宏是否打开、是否插入sd卡、路径是否为/storage/sdcard1
//stats[0]:真实的总容量大小 stats[1]:真实的剩余总容量大小
else if(!(FeatureOption.MTK_SHARED_SDCARD) && sdExist == true && path.toString().equals ("/storage/sdcard1"))
{
//1048576 = 1M; 8422162432L = 8G;
long eight_G = 8422162432L;
mTotalSize = eight_G*4-3865470566L+53687091L;
mAvailSize = mTotalSize-(stats[0]-stats[1]);
}
else if(!(FeatureOption.MTK_SHARED_SDCARD) && sdExist == false && path.toString().equals ("/storage/sdcard0"))
{
//1048576 = 1M; 8422162432L = 8G;
long eight_G = 8422162432L;
mTotalSize = eight_G*4-3865470566L+53687091L;
mAvailSize = mTotalSize-(stats[0]-stats[1]);
}
//change end
else if(FeatureOption.MTK_SHARED_SDCARD && sdExist == false && path.toString().equals ("/storage/sdcard0")&&!((SystemProperties.get("ro.phone.size")).equals("0")))
{
Log.w("lhy", "ro.phone.size="+SystemProperties.get("ro.phone.size"));
mTotalSize = phone_size*1048576;
mAvailSize = phone_size*1048576-stats[0]+stats[1];
}
else
{
Log.w(TAG, "2 stats[0]="+stats[0]);
mTotalSize = stats[0];
mAvailSize = stats[1];
}
} catch (Exception e) {
Log.w(TAG, "Problem in container service", e);
}
sendInternalApproximateUpdate();
}
三、alps\frameworks\base\core\java\android\os\StatFs.java文件
public class StatFs {
private StructStatVfs mStat;
private String status;
/**
* Construct a new StatFs for looking at the stats of the filesystem at
* {@code path}. Upon construction, the stat of the file system will be
* performed, and the values retrieved available from the methods on this
* class.
*
* @param path path in the desired file system to stat.
*/
public StatFs(String path) {
mStat = doStat(path);
status = path;
}
......
/*@Deprecated
public int getBlockCount() {
return (int) mStat.f_blocks;
}*/
@Deprecated
//总量
public int getBlockCount() {
if (status.equals("/data")) {
// return (int) (mStat.f_blocks * 2.2); //2G
return (int) (mStat.f_blocks * 4.5); //4G
}
else
{
if (mStat.f_blocks < 1428256)
{
//安兔兔显示作假
//1*1024 = 0.03125G;
//32*1024 = 1G;
return (int) (890*1024); //27.8G
}
else{
return (int) mStat.f_blocks;
}
}
}
......
/*@Deprecated
public int getAvailableBlocks() {
return (int) mStat.f_bavail;
}*/
@Deprecated
//剩余的
public int getAvailableBlocks() {
if (status.equals("/data")) {
// return (int) (mStat.f_bavail* 2.2); //2G
return (int) (mStat.f_bavail * 3.5); //4G
}
else
{
if (mStat.f_bavail < 1428256)
{
return (int) (890*1024-(mStat.f_blocks-mStat.f_bavail)+48*1024); //27.7G:剩余
}
else{
return (int) mStat.f_bavail;
}
}
}