安卓源码--修改存储大小
来源:互联网 发布:板式家具折单软件 编辑:程序博客网 时间:2024/06/05 03:12
一、文件管理器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; } } }
0 0
- 安卓源码--修改存储大小
- Android 源码 修改 分区大小
- MTK源码修改settings->storage和文件浏览器的USB存储大小
- 【安卓】Android6.0的String源码被修改
- 安卓源码--修改设置语言选择列表
- 安卓获取机身内存和外部sdCard的方法及存储大小
- 修改Bootstrap源码支持不同大小nandflash
- 安卓源码+内核修改编译(修改内核调试标志绕过反调试)
- 安卓获取手机屏幕大小
- 安卓 测量 屏幕 大小
- 安卓Drawable改变大小
- 安卓获取屏幕大小
- 安卓本地存储
- 安卓--数据存储
- 安卓存储路径
- 安卓存储
- 【安卓存储SharedPreferences】
- 安卓文件存储
- 为文本添加发亮的效果
- 将java源码打成jar包
- 关于LIUNX的常用命令
- easyui动态添加文本域
- Compressive Tracking(CT)
- 安卓源码--修改存储大小
- Poj.1730 Perfect Pth Powers【数学】 2015/11/13
- Java正则表达式教程
- nyoj--1087--摆方格(规律)
- 辗转相除法求最大公约数的原理
- LeetCode_Two Sum
- ARC 学习笔记(三)
- Copy与Property
- [GDUT]:1057: 5C还是5S