2
2
3
3
import android .util .Log ;
4
4
5
+ import com .tns .bindings .AnnotationDescriptor ;
6
+ import com .tns .bindings .ProxyGenerator ;
7
+ import com .tns .bindings .desc .ClassDescriptor ;
8
+ import com .tns .bindings .desc .reflection .ClassInfo ;
9
+ import com .tns .system .classes .loading .ClassStorageService ;
10
+
5
11
import java .io .BufferedReader ;
6
12
import java .io .BufferedWriter ;
7
13
import java .io .File ;
12
18
import java .io .InputStreamReader ;
13
19
import java .io .InvalidClassException ;
14
20
import java .io .OutputStreamWriter ;
15
- import java .util .ArrayList ;
16
21
import java .util .HashMap ;
17
22
import java .util .HashSet ;
18
- import java .util .List ;
19
23
import java .util .zip .ZipEntry ;
20
24
import java .util .zip .ZipOutputStream ;
21
25
22
- import com .tns .bindings .AnnotationDescriptor ;
23
- import com .tns .bindings .ProxyGenerator ;
24
- import com .tns .bindings .desc .ClassDescriptor ;
25
- import com .tns .bindings .desc .reflection .ClassInfo ;
26
-
27
26
import dalvik .system .DexClassLoader ;
28
27
29
28
public class DexFactory {
@@ -34,11 +33,12 @@ public class DexFactory {
34
33
private final File odexDir ;
35
34
private final String dexThumb ;
36
35
private final ClassLoader classLoader ;
36
+ private final ClassStorageService classStorageService ;
37
37
38
38
private ProxyGenerator proxyGenerator ;
39
39
private HashMap <String , Class <?>> injectedDexClasses = new HashMap <String , Class <?>>();
40
40
41
- public DexFactory (Logger logger , ClassLoader classLoader , File dexBaseDir , String dexThumb ) {
41
+ DexFactory (Logger logger , ClassLoader classLoader , File dexBaseDir , String dexThumb , ClassStorageService classStorageService ) {
42
42
this .logger = logger ;
43
43
this .classLoader = classLoader ;
44
44
this .dexDir = dexBaseDir ;
@@ -58,6 +58,7 @@ public DexFactory(Logger logger, ClassLoader classLoader, File dexBaseDir, Strin
58
58
59
59
this .updateDexThumbAndPurgeCache ();
60
60
this .proxyGenerator .setProxyThumb (this .dexThumb );
61
+ this .classStorageService = classStorageService ;
61
62
}
62
63
63
64
static long totalGenTime = 0 ;
@@ -154,36 +155,17 @@ public Class<?> resolveClass(String baseClassName, String name, String className
154
155
out .closeEntry ();
155
156
out .close ();
156
157
}
157
- //
158
158
159
- Class <?> result = null ;
160
- try {
161
- // use DexFile instead of DexClassLoader to allow class loading
162
- // within the default class loader
163
- // Note: According to the official documentation, DexFile should not
164
- // be directly used.
165
- // However, this is the only viable way to get our dynamic classes
166
- // loaded within the system class loader
159
+ Class <?> result ;
160
+ DexClassLoader dexClassLoader = new DexClassLoader (jarFilePath , this .odexDir .getAbsolutePath (), null , classLoader );
167
161
168
- if (isInterface ) {
169
- @ SuppressWarnings ("deprecation" )
170
- dalvik .system .DexFile df = dalvik .system .DexFile .loadDex (jarFilePath , new File (this .odexDir , fullClassName ).getAbsolutePath (), 0 );
171
- result = df .loadClass (fullClassName , classLoader );
172
- } else {
173
- @ SuppressWarnings ("deprecation" )
174
- dalvik .system .DexFile df = dalvik .system .DexFile .loadDex (jarFilePath , new File (this .odexDir , desiredDexClassName ).getAbsolutePath (), 0 );
175
- result = df .loadClass (desiredDexClassName , classLoader );
176
- }
177
- } catch (IOException e ) {
178
- Log .w ("JS" , String .format ("Error resolving class %s: %s. Fall back to DexClassLoader." ));
179
- if (com .tns .Runtime .isDebuggable ()) {
180
- e .printStackTrace ();
181
- }
182
- // fall back to DexClassLoader
183
- DexClassLoader dexClassLoader = new DexClassLoader (jarFilePath , this .odexDir .getAbsolutePath (), null , classLoader );
162
+ if (isInterface ) {
184
163
result = dexClassLoader .loadClass (fullClassName );
164
+ } else {
165
+ result = dexClassLoader .loadClass (desiredDexClassName );
185
166
}
186
167
168
+ classStorageService .storeClass (result .getName (), result );
187
169
this .injectedDexClasses .put (originalFullClassName , result );
188
170
189
171
return result ;
0 commit comments