1
1
package me .ele .amigo ;
2
2
3
3
import android .content .Context ;
4
+ import android .os .Build ;
4
5
import android .util .Log ;
5
6
6
7
import java .io .File ;
11
12
12
13
import dalvik .system .DexClassLoader ;
13
14
14
-
15
15
public class AmigoClassLoader extends DexClassLoader {
16
16
private static final String TAG = AmigoClassLoader .class .getName ();
17
17
@@ -38,6 +38,33 @@ public static AmigoClassLoader newInstance(Context context, String checksum) {
38
38
AmigoClassLoader .class .getClassLoader ().getParent ());
39
39
}
40
40
41
+ private static String getLibraryPath (Context context , String checksum ) {
42
+ return AmigoDirs .getInstance (context ).libDir (checksum ).getAbsolutePath ();
43
+ }
44
+
45
+ private static String joinPath (File folder ) {
46
+ StringBuilder path = new StringBuilder ();
47
+ File [] libFiles = folder .listFiles ();
48
+ if (libFiles == null || libFiles .length == 0 ) {
49
+ return null ;
50
+ }
51
+
52
+ for (File libFile : libFiles ) {
53
+ path .append (File .pathSeparatorChar );
54
+ path .append (libFile .getAbsolutePath ());
55
+ }
56
+ return path .toString ();
57
+ }
58
+
59
+ private static String getDexPath (Context context , String checksum ) {
60
+ if (Build .VERSION .SDK_INT >= 21 ) {
61
+ return PatchApks .getInstance (context ).patchPath (checksum );
62
+ }
63
+
64
+ String dexPath = joinPath (AmigoDirs .getInstance (context ).dexDir (checksum ));
65
+ return dexPath != null ? dexPath : PatchApks .getInstance (context ).patchPath (checksum );
66
+ }
67
+
41
68
@ Override
42
69
protected URL findResource (String name ) {
43
70
if ((zipFile == null ) || (zipFile .getEntry (name ) == null )) {
@@ -71,32 +98,4 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
71
98
return AmigoClassLoader .class .getClassLoader ().loadClass (name );
72
99
}
73
100
}
74
-
75
- private static String getLibraryPath (Context context , String checksum ) {
76
- return AmigoDirs .getInstance (context ).libDir (checksum ).getAbsolutePath ();
77
- }
78
-
79
- private static String joinPath (File folder ) {
80
- StringBuilder path = new StringBuilder ();
81
- File [] libFiles = folder .listFiles ();
82
- if (libFiles == null || libFiles .length == 0 ) {
83
- return null ;
84
- }
85
-
86
- for (File libFile : libFiles ) {
87
- path .append (File .pathSeparatorChar );
88
- path .append (libFile .getAbsolutePath ());
89
- }
90
- return path .toString ();
91
- }
92
-
93
- private static String getDexPath (Context context , String checksum ) {
94
- String dexPath = joinPath (AmigoDirs .getInstance (context ).dexDir (checksum ));
95
- if (dexPath == null ) {
96
- throw new RuntimeException ("Amigo: no patch dex available for checksum[" + checksum +
97
- "]" );
98
- }
99
- return dexPath ;
100
- }
101
-
102
101
}
0 commit comments