我们在做国外gms项目的过程中,经常会涉及到套MADA信息的情况,但是在套MADA信息后后出现一个问题,三方检测app中检测到的品牌等信息会跟套的一致,这就会导致我们的软件被测试打回,当然修改TextView是种方法,但是不通用,而且会有漏修改的情况 ,那么有没有一种方法实现动态修改品牌信息呢,有的,以下就是博主最近刚发现的,不是自创,纯借花献佛。
修改patch如下:
csharp
diff --git a/sys/frameworks/base/core/java/android/app/ContextImpl.java b/sys/frameworks/base/core/java/android/app/ContextImpl.java
index 2ba42ecc1b2..e5ecc1cca8e 100644
--- a/sys/frameworks/base/core/java/android/app/ContextImpl.java
+++ b/sys/frameworks/base/core/java/android/app/ContextImpl.java
@@ -113,6 +113,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.nio.ByteOrder;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -3479,6 +3481,19 @@ class ContextImpl extends Context {
opPackageName = mBasePackageName;
}
}
+ //add by lyw
+ //解决微信平板手机不能同时在线问题
+ if ("com.tencent.mm".equals(mBasePackageName)) {
+ modifySystemPropertyField("BRAND", "inspur");
+ modifySystemPropertyField("MODEL", "PD5012");
+ } else if ("com.finalwire.aida64".equals(mBasePackageName)) {
+ modifySystemPropertyField("BRAND", "VIVO");
+ modifySystemPropertyField("MODEL", "S17 Pro");
+ } else if ("flar2.devcheck".equals(mBasePackageName)) {
+ modifySystemPropertyField("BRAND", "HUAWEI");
+ modifySystemPropertyField("MODEL", "P30 Pro");
+ }
+ //add end
mOpPackageName = overrideOpPackageName != null ? overrideOpPackageName : opPackageName;
mParams = Objects.requireNonNull(params);
@@ -3487,6 +3502,50 @@ class ContextImpl extends Context {
mContentResolver = new ApplicationContentResolver(this, mainThread);
}
+ /**
+ * add by lyw
+ *
+ * @param fieldName
+ * @param newValue
+ * @return
+ */
+ private boolean modifySystemPropertyField(String fieldName, Object newValue) {
+ try {
+ Class<?> systemPropertiesClass = android.os.Build.class;
+ Field field = systemPropertiesClass.getDeclaredField(fieldName);
+ field.setAccessible(true);
+ removeFinalModifier(field);
+ field.set(null, newValue);
+ Object actualValue = field.get(null);
+ return newValue.equals(actualValue);
+ } catch (Exception e) {
+ Log.e("Modifier", "Failed to modify field", e);
+ return false;
+ }
+ }
+
+ /**
+ * add by lyw
+ *
+ * @param field
+ * @throws Exception
+ */
+ private void removeFinalModifier(Field field) throws Exception {
+ try {
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ } catch (NoSuchFieldException e) {
+ try {
+ Field accessFlagsField = Field.class.getDeclaredField("accessFlags");
+ accessFlagsField.setAccessible(true);
+ accessFlagsField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ } catch (NoSuchFieldException ex) {
+ throw new RuntimeException("Unable to remove final modifier", ex);
+ }
+ }
+ }
+
private @NonNull AttributionSource createAttributionSource(@Nullable String attributionTag,
@Nullable AttributionSource nextAttributionSource,
@Nullable Set<String> renouncedPermissions) {
实现的效果:
因为博主当前项目是接手的同事的代码,系统中已经被同事修改禁止安装AIDA64了,所以无法验证AIDA64,下面附上几款常见检测app验证结果。
DevCheck验证结果:

安兔兔验证结果:

DeviceInfoHW验证结果:
