From 5e87483f3424cbbbf532d7ab1fbb1804433e5b60 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 29 Oct 2019 07:37:19 -0400 Subject: [PATCH] Move addAssetPath to shared --- app/src/main/java/com/topjohnwu/magisk/Hacks.kt | 6 +----- shared/src/main/java/com/topjohnwu/magisk/DynAPK.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/Hacks.kt b/app/src/main/java/com/topjohnwu/magisk/Hacks.kt index f0b2380ab..0245f9591 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Hacks.kt +++ b/app/src/main/java/com/topjohnwu/magisk/Hacks.kt @@ -27,12 +27,8 @@ import com.topjohnwu.magisk.utils.currentLocale import com.topjohnwu.magisk.utils.defaultLocale import java.util.* -private val addAssetPath by lazy { - AssetManager::class.java.getMethod("addAssetPath", String::class.java) -} - fun AssetManager.addAssetPath(path: String) { - addAssetPath.invoke(this, path) + DynAPK.addAssetPath(this, path) } fun Context.wrap(global: Boolean = true): Context diff --git a/shared/src/main/java/com/topjohnwu/magisk/DynAPK.java b/shared/src/main/java/com/topjohnwu/magisk/DynAPK.java index 28be1d9e7..8dc790c81 100644 --- a/shared/src/main/java/com/topjohnwu/magisk/DynAPK.java +++ b/shared/src/main/java/com/topjohnwu/magisk/DynAPK.java @@ -1,8 +1,10 @@ package com.topjohnwu.magisk; import android.content.Context; +import android.content.res.AssetManager; import java.io.File; +import java.lang.reflect.Method; import java.util.Map; import static android.os.Build.VERSION.SDK_INT; @@ -24,6 +26,7 @@ public class DynAPK { public static final int MAGISKHIDE = 4; private static File dynDir; + private static Method addAssetPath; private static File getDynDir(Context c) { if (dynDir == null) { @@ -62,6 +65,14 @@ public class DynAPK { 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 int version; public Map componentMap;