Skip to content

Commit

Permalink
fix(dynamic): Android14 writable dex file
Browse files Browse the repository at this point in the history
Fixed the issue causing crashes due to writable dex files on Android 14.
#1344
  • Loading branch information
AntonioShare authored Dec 24, 2024
1 parent dc5bafb commit abb1bd6
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

package com.tencent.shadow.dynamic.apk;

import android.os.Build;

import com.tencent.shadow.core.common.InstalledApk;

import java.io.File;
import java.lang.reflect.Field;
import java.util.Objects;

import dalvik.system.DexClassLoader;

Expand All @@ -35,6 +39,7 @@ public String[] loadWhiteList(InstalledApk installedApk) {
}

public String[] loadWhiteList(InstalledApk installedApk, String whiteListClassName, String whiteListFieldName) {
checkDexReadOnly(installedApk);
DexClassLoader dexClassLoader = new DexClassLoader(
installedApk.apkFilePath,
installedApk.oDexPath,
Expand Down Expand Up @@ -72,4 +77,13 @@ private static String[] concatenate(String[] a, String[] b) {
System.arraycopy(b, 0, c, aLen, bLen);
return c;
}

private static void checkDexReadOnly(InstalledApk installedApk) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
boolean readOnly = new File(Objects.requireNonNull(installedApk.apkFilePath)).setReadOnly();
if (!readOnly) {
throw new RuntimeException("apk file is not read only");
}
}
}
}

0 comments on commit abb1bd6

Please sign in to comment.