OLD | NEW |
(Empty) | |
| 1 package org.chromium.deconstructed; |
| 2 |
| 3 import android.content.res.AssetManager; |
| 4 import android.content.res.Resources; |
| 5 import android.util.ArrayMap; |
| 6 |
| 7 import java.io.File; |
| 8 import java.lang.ref.WeakReference; |
| 9 import java.lang.reflect.InvocationTargetException; |
| 10 |
| 11 public class ResourceInstaller { |
| 12 private static final String TAG = "org.chromium.deconstructed.ResourceInstal
ler"; |
| 13 |
| 14 public static void install(File resources) |
| 15 throws NoSuchFieldException, NoSuchMethodException, InvocationTarget
Exception, |
| 16 InstantiationException, ClassNotFoundException, IllegalAccess
Exception { |
| 17 AssetManager assetManager = AssetManager.class.getConstructor().newInsta
nce(); |
| 18 if ((int) Reflect.invokeMethod(assetManager, "addAssetPath", resources.g
etPath()) == 0) { |
| 19 throw new IllegalStateException("Couldn't add assets."); |
| 20 } |
| 21 Object resourcesManager = |
| 22 Reflect.invokeStaticMethod("android.app.ResourcesManager", "getI
nstance"); |
| 23 for (WeakReference<Resources> ref : |
| 24 ((ArrayMap<?, WeakReference<Resources>>) Reflect.getField( |
| 25 resourcesManager, "mActiveResources")).values()) { |
| 26 Resources res = ref.get(); |
| 27 Reflect.setField(res, "mAssets", assetManager); |
| 28 res.updateConfiguration(res.getConfiguration(), res.getDisplayMetric
s()); |
| 29 } |
| 30 } |
| 31 } |
OLD | NEW |