Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
}
}
Loading