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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « apk/BUILD.gn ('k') | apk/hijack/org/chromium/deconstructed/DeconstructedApplication.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 package org.chromium.deconstructed;
2
3 import android.app.Application;
4
5 import java.lang.ref.WeakReference;
6 import java.lang.reflect.InvocationTargetException;
7 import java.util.List;
8 import java.util.Map;
9
10 public class ApplicationInstaller {
11 public static void install(Application currentApplication, Application realA pplication)
12 throws ClassNotFoundException, InvocationTargetException, NoSuchFiel dException,
13 NoSuchMethodException {
14 Object currentActivityThread =
15 Reflect.invokeStaticMethod("android.app.ActivityThread", "curren tActivityThread");
16 if (Reflect.getField(currentActivityThread, "mInitialApplication") == cu rrentApplication) {
17 Reflect.setField(currentActivityThread, "mInitialApplication", realA pplication);
18 }
19
20 List<Application> allApplications =
21 (List<Application>) Reflect.getField(currentActivityThread, "mAl lApplications");
22 for (int i = 0; i < allApplications.size(); i++) {
23 if (allApplications.get(i) == currentApplication) {
24 allApplications.set(i, realApplication);
25 }
26 }
27
28 for (String fieldName : new String[] {"mPackages", "mResourcePackages"}) {
29 Map<String, WeakReference<?>> packageMap =
30 (Map<String, WeakReference<?>>) Reflect.getField(
31 currentActivityThread, fieldName);
32 for (Map.Entry<String, WeakReference<?>> entry : packageMap.entrySet ()) {
33 Object loadedApk = entry.getValue().get();
34 if (loadedApk == null) continue;
35 if (Reflect.getField(loadedApk, "mApplication") == currentApplic ation) {
36 Reflect.setField(loadedApk, "mApplication", realApplication) ;
37 Reflect.setField(realApplication, "mLoadedApk", loadedApk);
38 }
39 }
40 }
41 }
42 }
OLDNEW
« 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