欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android M low ram device优化apk安装速度 博客分类: Android android

程序员文章站 2024-03-02 11:30:04
...
安装apk慢是因为dex2oat行为导致的,要优化可以牺牲一些检查,强制用vmSafeMode去安装,facebook举例,低端机器从安装10分钟改善为1分钟不到。修改方法如下:
  1 diff --git a/base/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/base/services/core/java/com/android/server/pm/PackageDexOptimizer.java
  2 index f35552d..8ae1e13 100644
  3 --- a/base/services/core/java/com/android/server/pm/PackageDexOptimizer.java
  4 +++ b/base/services/core/java/com/android/server/pm/PackageDexOptimizer.java
  5 @@ -115,7 +115,12 @@ final class PackageDexOptimizer {
  6              return DEX_OPT_SKIPPED;
  7          }
  8
  9 +/*
10          final boolean vmSafeMode = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0;
11 + */
12 +        boolean vmSafeMode = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0;
13          final boolean debuggable = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
14
15          final List<String> paths = pkg.getAllCodePathsExcludingResourceOnly();
16 @@ -171,6 +176,13 @@ final class PackageDexOptimizer {
17                          throw new IllegalStateException("Invalid dexopt needed: " + dexoptNeeded);
18                      }
19
20 +                    if (pkg.applicationInfo.packageName.contains("facebook")) {
21 +                        vmSafeMode = true;
22 +                    }
23                      Log.i(TAG, "Running dexopt (" + dexoptType + ") on: " + path + " pkg="
24                              + pkg.applicationInfo.packageName + " isa=" + dexCodeInstructionSet
25                              + " vmSafeMode=" + vmSafeMode + " debuggable=" + debuggable
相关标签: android