MultiDex.java
11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package android.support.multidex;
import ad;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build.VERSION;
import android.util.Log;
import dalvik.system.DexFile;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipFile;
public final class MultiDex
{
private static final String a = "code_cache" + File.separator + "secondary-dexes";
private static final Set<String> b = new HashSet();
private static final boolean c = a(System.getProperty("java.vm.version"));
private static ApplicationInfo a(Context paramContext)
throws PackageManager.NameNotFoundException
{
PackageManager localPackageManager;
try
{
localPackageManager = paramContext.getPackageManager();
paramContext = paramContext.getPackageName();
if ((localPackageManager == null) || (paramContext == null)) {
return null;
}
}
catch (RuntimeException paramContext)
{
Log.w("MultiDex", "Failure while trying to obtain ApplicationInfo from Context. Must be running in test mode. Skip patching.", paramContext);
return null;
}
return localPackageManager.getApplicationInfo(paramContext, 128);
}
private static Method a(Object paramObject, String paramString, Class<?>... paramVarArgs)
throws NoSuchMethodException
{
Class localClass = paramObject.getClass();
while (localClass != null) {
try
{
Method localMethod = localClass.getDeclaredMethod(paramString, paramVarArgs);
if (!localMethod.isAccessible()) {
localMethod.setAccessible(true);
}
return localMethod;
}
catch (NoSuchMethodException localNoSuchMethodException)
{
localClass = localClass.getSuperclass();
}
}
throw new NoSuchMethodException("Method " + paramString + " with parameters " + Arrays.asList(paramVarArgs) + " not found in " + paramObject.getClass());
}
private static void a(ClassLoader paramClassLoader, File paramFile, List<File> paramList)
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, InvocationTargetException, NoSuchMethodException, IOException
{
Object localObject;
ArrayList localArrayList;
if (!paramList.isEmpty())
{
if (Build.VERSION.SDK_INT < 19) {
break label229;
}
localObject = b(paramClassLoader, "pathList").get(paramClassLoader);
localArrayList = new ArrayList();
paramList = new ArrayList(paramList);
a(localObject, "dexElements", (Object[])a(localObject, "makeDexElements", new Class[] { ArrayList.class, File.class, ArrayList.class }).invoke(localObject, new Object[] { paramList, paramFile, localArrayList }));
if (localArrayList.size() > 0)
{
paramFile = localArrayList.iterator();
while (paramFile.hasNext()) {
Log.w("MultiDex", "Exception in makeDexElement", (IOException)paramFile.next());
}
paramList = b(paramClassLoader, "dexElementsSuppressedExceptions");
localObject = (IOException[])paramList.get(paramClassLoader);
if (localObject != null) {
break label194;
}
paramFile = (IOException[])localArrayList.toArray(new IOException[localArrayList.size()]);
}
}
for (;;)
{
paramList.set(paramClassLoader, paramFile);
return;
label194:
paramFile = new IOException[localArrayList.size() + localObject.length];
localArrayList.toArray(paramFile);
System.arraycopy(localObject, 0, paramFile, localArrayList.size(), localObject.length);
}
label229:
if (Build.VERSION.SDK_INT >= 14)
{
paramClassLoader = b(paramClassLoader, "pathList").get(paramClassLoader);
paramList = new ArrayList(paramList);
a(paramClassLoader, "dexElements", (Object[])a(paramClassLoader, "makeDexElements", new Class[] { ArrayList.class, File.class }).invoke(paramClassLoader, new Object[] { paramList, paramFile }));
return;
}
a.a(paramClassLoader, paramList);
}
private static boolean a(String paramString)
{
bool2 = false;
bool1 = bool2;
if (paramString != null)
{
localObject = Pattern.compile("(\\d+)\\.(\\d+)(\\.\\d+)?").matcher(paramString);
bool1 = bool2;
if (!((Matcher)localObject).matches()) {}
}
try
{
int i = Integer.parseInt(((Matcher)localObject).group(1));
int j = Integer.parseInt(((Matcher)localObject).group(2));
if (i <= 2)
{
bool1 = bool2;
if (i == 2)
{
bool1 = bool2;
if (j <= 0) {}
}
}
else
{
bool1 = true;
}
}
catch (NumberFormatException localNumberFormatException)
{
for (;;)
{
bool1 = bool2;
}
}
Object localObject = new StringBuilder("VM with version ").append(paramString);
if (bool1) {}
for (paramString = " has multidex support";; paramString = " does not have multidex support")
{
Log.i("MultiDex", paramString);
return bool1;
}
}
private static boolean a(List<File> paramList)
{
paramList = paramList.iterator();
while (paramList.hasNext()) {
if (!ad.a((File)paramList.next())) {
return false;
}
}
return true;
}
private static Field b(Object paramObject, String paramString)
throws NoSuchFieldException
{
Class localClass = paramObject.getClass();
while (localClass != null) {
try
{
Field localField = localClass.getDeclaredField(paramString);
if (!localField.isAccessible()) {
localField.setAccessible(true);
}
return localField;
}
catch (NoSuchFieldException localNoSuchFieldException)
{
localClass = localClass.getSuperclass();
}
}
throw new NoSuchFieldException("Field " + paramString + " not found in " + paramObject.getClass());
}
private static void b(Context paramContext)
throws Exception
{
paramContext = new File(paramContext.getFilesDir(), "secondary-dexes");
File[] arrayOfFile;
if (paramContext.isDirectory())
{
Log.i("MultiDex", "Clearing old secondary dex dir (" + paramContext.getPath() + ").");
arrayOfFile = paramContext.listFiles();
if (arrayOfFile == null) {
Log.w("MultiDex", "Failed to list secondary dex dir content (" + paramContext.getPath() + ").");
}
}
else
{
return;
}
int j = arrayOfFile.length;
int i = 0;
if (i < j)
{
File localFile = arrayOfFile[i];
Log.i("MultiDex", "Trying to delete old file " + localFile.getPath() + " of size " + localFile.length());
if (!localFile.delete()) {
Log.w("MultiDex", "Failed to delete old file " + localFile.getPath());
}
for (;;)
{
i += 1;
break;
Log.i("MultiDex", "Deleted old file " + localFile.getPath());
}
}
if (!paramContext.delete())
{
Log.w("MultiDex", "Failed to delete secondary dex dir " + paramContext.getPath());
return;
}
Log.i("MultiDex", "Deleted old secondary dex dir " + paramContext.getPath());
}
public static void install(Context paramContext)
{
Log.i("MultiDex", "install");
if (c) {
Log.i("MultiDex", "VM has multidex support, MultiDex support library is disabled.");
}
ApplicationInfo localApplicationInfo;
Object localObject;
for (;;)
{
return;
if (Build.VERSION.SDK_INT < 4) {
throw new RuntimeException("Multi dex installation failed. SDK " + Build.VERSION.SDK_INT + " is unsupported. Min SDK version is 4.");
}
try
{
localApplicationInfo = a(paramContext);
if (localApplicationInfo != null)
{
synchronized (b)
{
localObject = localApplicationInfo.sourceDir;
if (b.contains(localObject)) {
return;
}
}
b.add(localObject);
}
}
catch (Exception paramContext)
{
Log.e("MultiDex", "Multidex installation failure", paramContext);
throw new RuntimeException("Multi dex installation failed (" + paramContext.getMessage() + ").");
}
}
if (Build.VERSION.SDK_INT > 20) {
Log.w("MultiDex", "MultiDex is not guaranteed to work in SDK version " + Build.VERSION.SDK_INT + ": SDK version higher than 20 should be backed by runtime with built-in multidex capabilty but it's not the case here: java.vm.version=\"" + System.getProperty("java.vm.version") + "\"");
}
try
{
localObject = paramContext.getClassLoader();
if (localObject == null)
{
Log.e("MultiDex", "Context class loader is null. Must be running in test mode. Skip patching.");
return;
}
}
catch (RuntimeException paramContext)
{
Log.w("MultiDex", "Failure while trying to obtain Context class loader. Must be running in test mode. Skip patching.", paramContext);
return;
}
try
{
b(paramContext);
File localFile = new File(localApplicationInfo.dataDir, a);
List localList = ad.a(paramContext, localApplicationInfo, localFile, false);
if (a(localList))
{
a((ClassLoader)localObject, localFile, localList);
Log.i("MultiDex", "install done");
return;
}
}
catch (Throwable localThrowable)
{
for (;;)
{
Log.w("MultiDex", "Something went wrong when trying to clear old MultiDex extraction, continuing without cleaning.", localThrowable);
continue;
Log.w("MultiDex", "Files were not valid zip files. Forcing a reload.");
paramContext = ad.a(paramContext, localApplicationInfo, localThrowable, true);
if (!a(paramContext)) {
break;
}
a((ClassLoader)localObject, localThrowable, paramContext);
}
throw new RuntimeException("Zip files were not valid.");
}
}
static final class a
{
static void a(ClassLoader paramClassLoader, List<File> paramList)
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, IOException
{
int i = paramList.size();
Field localField = MultiDex.a(paramClassLoader, "path");
StringBuilder localStringBuilder = new StringBuilder((String)localField.get(paramClassLoader));
String[] arrayOfString = new String[i];
File[] arrayOfFile = new File[i];
ZipFile[] arrayOfZipFile = new ZipFile[i];
DexFile[] arrayOfDexFile = new DexFile[i];
paramList = paramList.listIterator();
while (paramList.hasNext())
{
File localFile = (File)paramList.next();
String str = localFile.getAbsolutePath();
localStringBuilder.append(':').append(str);
i = paramList.previousIndex();
arrayOfString[i] = str;
arrayOfFile[i] = localFile;
arrayOfZipFile[i] = new ZipFile(localFile);
arrayOfDexFile[i] = DexFile.loadDex(str, str + ".dex", 0);
}
localField.set(paramClassLoader, localStringBuilder.toString());
MultiDex.a(paramClassLoader, "mPaths", arrayOfString);
MultiDex.a(paramClassLoader, "mFiles", arrayOfFile);
MultiDex.a(paramClassLoader, "mZips", arrayOfZipFile);
MultiDex.a(paramClassLoader, "mDexs", arrayOfDexFile);
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/android/support/multidex/MultiDex.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/