修改ROM的容量

1 基本需求

为了节省成本,把emmc的容量减小,同时外接TF卡,把内置的内容存放在TF卡上面,但是又需要修改某些测试类app的读取系统的信息,所以要进行修改.
(PS:真的是各种无良厂商!)

2 修改方法

第一种方案就是在framework中TextView 中的setText()截取当前的应用是否是安兔兔,判断关键字符值并作假修改。
修改方式:大概就是下面的修改方法

frameworks/base/core/java/android/widget/TextView.java
private void setText(CharSequence text, BufferType type,
                        boolean notifyBefore, int oldlen) {
    
    
    mTextSetFromXmlOrResourceId = false;
    if (text == null) {
    
    
        text = "";
    }
    String packageName = getContext().getPackageName();
    if (packageName.equals("com.antutu.ABenchMark")
                || packageName.equals("com.cpuid.cpu_z")
                || packageName.equals("com.ludashi.benchmark")) {
    
    
        //这两个是我们在frameworks/base/core/res/res/valuess/configs.xml中写死的值
        String fakeRamSize = getContext().getResources().getString(com.android.internal.R.string.custom_ram_size);
        String fakeRomSize = getContext().getResources().getString(com.android.internal.R.string.custom_rom_size);
        //然后就是用我们自己定义的字符串去替换,三方的字符串
        if (fakeRamSize != null && !fakeRamSize.equals("") && s.startsWith("Total:") && s.endsWith("MB")) {
    
    
                String totals = s.substring(s.indexOf(":") + 1, s.indexOf("B") + 1);
                text = s.replace(totals, fakeRamSize);
        }
        if (fakeRomSize != null && !fakeRomSize.equals("") && s.startsWith("Total:") && s.endsWith("GB")) {
    
    
                String totals = s.substring(s.indexOf(":") + 1, s.indexOf("B") + 1);
                text = s.replace(totals, fakeRomSize);
        }
        if (fakeRamSize != null && !fakeRamSize.equals("") && s.contains("/") && s.endsWith("MB")) {
    
    
                String totals = s.substring(s.lastIndexOf("/") + 1, s.lastIndexOf("B") + 1);
                text = s.replace(totals, fakeRamSize);
        }
        if (fakeRomSize != null && !fakeRomSize.equals("") && s.contains("/") && s.endsWith("GB")) {
    
    
                String totals = s.substring(s.lastIndexOf("/") + 1, s.lastIndexOf("B") + 1);
                text = s.replace(totals, fakeRomSize);
        }
    }   
}

但是实现起来发现并不行,应该是某应用学聪明了吧。然后就进行下一步的修改验证。

build.prop中添加一个选项ro.faker.rom.size=8L
public long getBlockCountLong() {
    
    
        long fakerRomSize = SystemProperties.getLong("ro.faker.rom.size", 0L);
        return fakerRomSize == 0L
                ? (int) mStat.f_blocks
                : (int) (1024 * 1024 * 1024L * fakerRomSize / getBlockSizeLong());
    }
 
getBlockCount()这个方法最好也改一下,这是过时的方法,但是仍可以使用

通过这种方法就可以让某应用获取到的就是我们想要的效果.
如果只是这样修改会发现有些还是没有修改过来,询问我们自己的应用发现使用的方法不一样.然后又进行了一下修改.

public int getBlockCount() {
    
    
		/* Modify by arunboy 20191209 */
        long fakerRomSize = SystemProperties.getLong("ro.faker.rom.size", 0L);
		return fakerRomSize == 0L 
		    ? (int) mStat.f_blocks 
			: (int) (1024 * 1024 * 1024L * fakerRomSize / getBlockSizeLong());
    }


public long getTotalBytes() {
    
    
		/* Modify by arunboy 20191209 */
		long fakerRomSize = SystemProperties.getLong("ro.faker.rom.size", 0L);
		return fakerRomSize == 0L 
		    ? mStat.f_blocks * mStat.f_bsize 
			: (1024 * 1024 * 1024L * fakerRomSize / getBlockSizeLong()) * mStat.f_bsize;
        //return mStat.f_blocks * mStat.f_bsize;
    }

把上面两个方法也进行修改,就可以达到想要的效果了.

参考文档:https://blog.csdn.net/Keep_Holding_On/article/details/84389525

猜你喜欢

转载自blog.csdn.net/arunboy/article/details/103457364
ROM