Android 12修改无源码 app 的字体大小和 dpi

时间:2024-10-08 09:45:17

客户需求默认字体大小和显示大小修改后,导致个别无源码应用显示不全。
根据包名单独修改应用字体大小和 dpi 解决显示问题

--- a/frameworks/base/core/java/android/app/
+++ b/frameworks/base/core/java/android/app/
@@ -168,7 +168,7 @@ import ;
 import ;
 import ;
 import ;
-
+import ; //yim
 
 /**
  * An activity is a single, focused thing that the user can do.  Almost all
@@ -1613,6 +1613,57 @@ public class Activity extends ContextThemeWrapper
         }
         mRestoredFromBundle = savedInstanceState != null;
         mCalled = true;
+       /*METHOD yim add start*/
+
+        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+        List<> runningTasks = (1);
+
+        if (runningTasks != null && !()) {
+            ComponentName topActivity = (0).topActivity;
+            String packageName = ();
+
+            if ("".equals(packageName)) {
+                Resources resources = getResources();
+
+                if (resources != null) {
+                    Configuration configuration = ();
+
+                    if (configuration != null) {
+                        if ( != 1.0f) {
+                             = 1.0f;
+                            (configuration, ());
+                        }
+
+                        DisplayMetrics displayMetrics = new DisplayMetrics();
+                        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+                        int densityDpi = ;
+
+                        if (densityDpi != 240) {
+                             = 240;
+                            (configuration, ());
+                        }
+                    }
+                }
+            }
+        }
+   /*yim add end*/
 
     }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

修改完编译验证,问题已经解决。