Move addAssetPath to shared

This commit is contained in:
topjohnwu 2019-10-29 07:37:19 -04:00
parent f7aa451591
commit 5e87483f34
2 changed files with 12 additions and 5 deletions

View File

@ -27,12 +27,8 @@ import com.topjohnwu.magisk.utils.currentLocale
import com.topjohnwu.magisk.utils.defaultLocale import com.topjohnwu.magisk.utils.defaultLocale
import java.util.* import java.util.*
private val addAssetPath by lazy {
AssetManager::class.java.getMethod("addAssetPath", String::class.java)
}
fun AssetManager.addAssetPath(path: String) { fun AssetManager.addAssetPath(path: String) {
addAssetPath.invoke(this, path) DynAPK.addAssetPath(this, path)
} }
fun Context.wrap(global: Boolean = true): Context fun Context.wrap(global: Boolean = true): Context

View File

@ -1,8 +1,10 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager;
import java.io.File; import java.io.File;
import java.lang.reflect.Method;
import java.util.Map; import java.util.Map;
import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION.SDK_INT;
@ -24,6 +26,7 @@ public class DynAPK {
public static final int MAGISKHIDE = 4; public static final int MAGISKHIDE = 4;
private static File dynDir; private static File dynDir;
private static Method addAssetPath;
private static File getDynDir(Context c) { private static File getDynDir(Context c) {
if (dynDir == null) { if (dynDir == null) {
@ -62,6 +65,14 @@ public class DynAPK {
return arr; return arr;
} }
public static void addAssetPath(AssetManager asset, String path) {
try {
if (addAssetPath == null)
addAssetPath = AssetManager.class.getMethod("addAssetPath", String.class);
addAssetPath.invoke(asset, path);
} catch (Exception ignored) {}
}
public static class Data { public static class Data {
public int version; public int version;
public Map<String, String> componentMap; public Map<String, String> componentMap;