Skip to content

Commit

Permalink
[tinker] Avoid using registerDexModule to trigger dex2oat on system b…
Browse files Browse the repository at this point in the history
…elow Android S.
  • Loading branch information
tys282000 committed Dec 7, 2021
1 parent 59e838e commit 10595b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,19 @@ private static void triggerPMDexOptOnDemand(Context context, String dexPath, Str
} catch (Throwable thr) {
ShareTinkerLog.printErrStackTrace(TAG, thr, "[-] Fail to call reconcileSecondaryDexFiles.");
}
try {
registerDexModule(context, dexPath);
} catch (Throwable thr) {
ShareTinkerLog.printErrStackTrace(TAG, thr, "[-] Fail to call registerDexModule.");
}
if (oatFile.exists()) {
ShareTinkerLog.i(TAG, "[+] Dexopt was triggered by registerDexModule successfully.");
return;
if (ShareTinkerInternals.isNewerOrEqualThanVersion(31 /* Android S */, true)) {
// registerDexModule will force classloader context change into VariableClassLoaderContext,
// which makes ART skip caching class verification info on Android Q and R. The running
// performance of patched app will have no improvement.
try {
registerDexModule(context, dexPath);
} catch (Throwable thr) {
ShareTinkerLog.printErrStackTrace(TAG, thr, "[-] Fail to call registerDexModule.");
}
if (oatFile.exists()) {
ShareTinkerLog.i(TAG, "[+] Dexopt was triggered by registerDexModule successfully.");
return;
}
}
try {
performDexOptSecondary(context);
Expand Down Expand Up @@ -285,7 +290,8 @@ private static void performDexOptSecondary(Context context) throws IllegalStateE
"compile",
"-f",
"--secondary-dex",
"-m", "speed-profile",
"-m", ShareTinkerInternals.isNewerOrEqualThanVersion(31 /* Android S */, true)
? "verify" : "speed-profile",
context.getPackageName()
};
executePMSShellCommand(context, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ private static boolean isVmJitInternal() {
return false;
}

public static boolean isNewerOrEqualThanVersion(int apiLevel, boolean includePreviewVer) {
if (includePreviewVer && Build.VERSION.SDK_INT >= 23) {
return Build.VERSION.SDK_INT >= apiLevel
|| ((Build.VERSION.SDK_INT == apiLevel - 1) && Build.VERSION.PREVIEW_SDK_INT > 0);
} else {
return Build.VERSION.SDK_INT >= apiLevel;
}
}

public static String getExceptionCauseString(final Throwable ex) {
if (ex == null) return "";

Expand Down

0 comments on commit 10595b9

Please sign in to comment.