Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1642)

Unified Diff: apk/hijack/org/chromium/deconstructed/ResourceInstaller.java

Issue 949803002: Deconstructed APK prototyping Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « apk/hijack/org/chromium/deconstructed/Reflect.java ('k') | apk/java/org/chromium/simple/MainActivity.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apk/hijack/org/chromium/deconstructed/ResourceInstaller.java
diff --git a/apk/hijack/org/chromium/deconstructed/ResourceInstaller.java b/apk/hijack/org/chromium/deconstructed/ResourceInstaller.java
new file mode 100644
index 0000000000000000000000000000000000000000..f2928d55a2c7cb9df471074c11d90e3802c5f6c3
--- /dev/null
+++ b/apk/hijack/org/chromium/deconstructed/ResourceInstaller.java
@@ -0,0 +1,31 @@
+package org.chromium.deconstructed;
+
+import android.content.res.AssetManager;
+import android.content.res.Resources;
+import android.util.ArrayMap;
+
+import java.io.File;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+
+public class ResourceInstaller {
+ private static final String TAG = "org.chromium.deconstructed.ResourceInstaller";
+
+ public static void install(File resources)
+ throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException,
+ InstantiationException, ClassNotFoundException, IllegalAccessException {
+ AssetManager assetManager = AssetManager.class.getConstructor().newInstance();
+ if ((int) Reflect.invokeMethod(assetManager, "addAssetPath", resources.getPath()) == 0) {
+ throw new IllegalStateException("Couldn't add assets.");
+ }
+ Object resourcesManager =
+ Reflect.invokeStaticMethod("android.app.ResourcesManager", "getInstance");
+ for (WeakReference<Resources> ref :
+ ((ArrayMap<?, WeakReference<Resources>>) Reflect.getField(
+ resourcesManager, "mActiveResources")).values()) {
+ Resources res = ref.get();
+ Reflect.setField(res, "mAssets", assetManager);
+ res.updateConfiguration(res.getConfiguration(), res.getDisplayMetrics());
+ }
+ }
+}
« no previous file with comments | « apk/hijack/org/chromium/deconstructed/Reflect.java ('k') | apk/java/org/chromium/simple/MainActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698