Android进行字符串替换

做项目中经常遇到客户要求ddr,flash,摄像头像素等信息作假,还要求在Antutu,Aida64,CPU-Z,DevCheck等检测app中显示正确,但是我们毕竟能做的有限,所以很多情况下只能通过TextView.java进行字符串替换达到作假的效果,在这里将修改记录一下,以防后面忘记或者丢失,具体修改如下:(提一句:antutu这个app调用的api是append,跟其他检测app不一样)

diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
old mode 100644
new mode 100755
index 450bb1e77ec8..cbda951841cc
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -6114,6 +6114,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
 
         ((Editable) mText).append(text, start, end);
 
+               String pkg2 = mContext.getPackageName();
+        if(pkg2.equals("com.antutu.ABenchMark")) {
+                  Log.d("hzw","mText = " + mText.toString());
+           if(mText.toString().contains("10.09") || mText.toString().contains("10.08")) {
+              mText = ((Editable)mText).replace(0,5,"10.1");
+           }
+        }
+
         if (mAutoLinkMask != 0) {
             boolean linksWereAdded = Linkify.addLinks(mSpannable, mAutoLinkMask);
             // Do not change the movement method for text that support text selection as it
@@ -6404,6 +6412,44 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     @android.view.RemotableViewMethod
     public final void setText(CharSequence text) {
         setText(text, mBufferType);
+
+               String pkg = mContext.getPackageName();
+        String str = String.valueOf(text);  
+        //Log.d("wzh","str = " + str);
+        if(pkg.equals("com.finalwire.aida64") || pkg.equals("com.cpuid.cpu_z") || pkg.equals("mark.fakedevicetest")){                    
+            if(str.contains("4+") || str.contains("10.08") || str.contains("10.09") || str.contains("2924 MB") || str.contains("3 GB")){
+                str = str.replace("4+","5.0").replace("10.08","10.1").replace("10.09","10.1").replace("2924 MB","3924 MB").replace("3 GB","4 GB");
+                setText(str,mBufferType);
+            }else {
+                setText(text,mBufferType);
+            }             
+                      
+        }else if(pkg.equals("com.android.settings")){
+                               if(str.contains("3.0 GB")) {
+                                       str = str.replace("3.0 GB","4.0 GB");
+                                       setText(str,mBufferType);
+                               }else{
+                                       setText(text,mBufferType);
+                               }
+               }else if(pkg.equals("flar2.devcheck")) {
+                               if(str.contains("1.9 MP")) {
+                                       str = str.replace("1.9 MP","5 MP");
+                                       setText(str,mBufferType);
+                               }else if(str.contains("5 MP")){
+                                       str = str.replace("5 MP","8 MP");
+                                       setText(str,mBufferType);
+                               }else if(str.contains("10.08")){
+                                       str = str.replace("10.08","10.1");
+                                       setText(str,mBufferType);
+                               }else if(str.contains("10.09")){
+                                       str = str.replace("10.09","10.1");
+                                       setText(str,mBufferType);
+                               }else{
+                                       setText(text,mBufferType);
+                               }
+               }else{
+             setText(text,mBufferType);
+        }
     }
 
     /**

你可能感兴趣的:(Android,安卓,平板,android,java,平板)