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

Unified Diff: apk/hijack/org/chromium/deconstructed/ApplicationInstaller.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/BUILD.gn ('k') | apk/hijack/org/chromium/deconstructed/DeconstructedApplication.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apk/hijack/org/chromium/deconstructed/ApplicationInstaller.java
diff --git a/apk/hijack/org/chromium/deconstructed/ApplicationInstaller.java b/apk/hijack/org/chromium/deconstructed/ApplicationInstaller.java
new file mode 100644
index 0000000000000000000000000000000000000000..a34286b35322789024eef4fa2b18446e5d5a4398
--- /dev/null
+++ b/apk/hijack/org/chromium/deconstructed/ApplicationInstaller.java
@@ -0,0 +1,42 @@
+package org.chromium.deconstructed;
+
+import android.app.Application;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+public class ApplicationInstaller {
+ public static void install(Application currentApplication, Application realApplication)
+ throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException,
+ NoSuchMethodException {
+ Object currentActivityThread =
+ Reflect.invokeStaticMethod("android.app.ActivityThread", "currentActivityThread");
+ if (Reflect.getField(currentActivityThread, "mInitialApplication") == currentApplication) {
+ Reflect.setField(currentActivityThread, "mInitialApplication", realApplication);
+ }
+
+ List<Application> allApplications =
+ (List<Application>) Reflect.getField(currentActivityThread, "mAllApplications");
+ for (int i = 0; i < allApplications.size(); i++) {
+ if (allApplications.get(i) == currentApplication) {
+ allApplications.set(i, realApplication);
+ }
+ }
+
+ for (String fieldName : new String[] {"mPackages", "mResourcePackages"}) {
+ Map<String, WeakReference<?>> packageMap =
+ (Map<String, WeakReference<?>>) Reflect.getField(
+ currentActivityThread, fieldName);
+ for (Map.Entry<String, WeakReference<?>> entry : packageMap.entrySet()) {
+ Object loadedApk = entry.getValue().get();
+ if (loadedApk == null) continue;
+ if (Reflect.getField(loadedApk, "mApplication") == currentApplication) {
+ Reflect.setField(loadedApk, "mApplication", realApplication);
+ Reflect.setField(realApplication, "mLoadedApk", loadedApk);
+ }
+ }
+ }
+ }
+}
« no previous file with comments | « apk/BUILD.gn ('k') | apk/hijack/org/chromium/deconstructed/DeconstructedApplication.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698