161 lines
6.2 KiB
Java
161 lines
6.2 KiB
Java
package o;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
import java.util.ServiceLoader;
|
|
import java.util.Set;
|
|
import java.util.jar.JarFile;
|
|
import java.util.zip.ZipEntry;
|
|
import kotlinx.coroutines.internal.MainDispatcherFactory;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class ggO {
|
|
public static final ggO b = new ggO();
|
|
|
|
private ggO() {
|
|
}
|
|
|
|
public static List<MainDispatcherFactory> a() {
|
|
MainDispatcherFactory mainDispatcherFactory;
|
|
if (!C15072ggP.d()) {
|
|
return b(MainDispatcherFactory.class, MainDispatcherFactory.class.getClassLoader());
|
|
}
|
|
try {
|
|
ArrayList arrayList = new ArrayList(2);
|
|
MainDispatcherFactory mainDispatcherFactory2 = null;
|
|
try {
|
|
mainDispatcherFactory = (MainDispatcherFactory) MainDispatcherFactory.class.cast(Class.forName("kotlinx.coroutines.android.AndroidDispatcherFactory", true, MainDispatcherFactory.class.getClassLoader()).getDeclaredConstructor(new Class[0]).newInstance(new Object[0]));
|
|
} catch (ClassNotFoundException unused) {
|
|
mainDispatcherFactory = null;
|
|
}
|
|
if (mainDispatcherFactory != null) {
|
|
arrayList.add(mainDispatcherFactory);
|
|
}
|
|
try {
|
|
mainDispatcherFactory2 = (MainDispatcherFactory) MainDispatcherFactory.class.cast(Class.forName("kotlinx.coroutines.test.internal.TestMainDispatcherFactory", true, MainDispatcherFactory.class.getClassLoader()).getDeclaredConstructor(new Class[0]).newInstance(new Object[0]));
|
|
} catch (ClassNotFoundException unused2) {
|
|
}
|
|
if (mainDispatcherFactory2 != null) {
|
|
arrayList.add(mainDispatcherFactory2);
|
|
}
|
|
return arrayList;
|
|
} catch (Throwable unused3) {
|
|
return b(MainDispatcherFactory.class, MainDispatcherFactory.class.getClassLoader());
|
|
}
|
|
}
|
|
|
|
private static <S> List<S> b(Class<S> cls, ClassLoader classLoader) {
|
|
try {
|
|
StringBuilder sb = new StringBuilder("META-INF/services/");
|
|
sb.append(cls.getName());
|
|
ArrayList list = Collections.list(classLoader.getResources(sb.toString()));
|
|
C14957gcv.c(list, "");
|
|
ArrayList arrayList = new ArrayList();
|
|
Iterator it = list.iterator();
|
|
while (it.hasNext()) {
|
|
C14881gav.d(arrayList, a((URL) it.next()));
|
|
}
|
|
Set h = C14881gav.h(arrayList);
|
|
if (!(!h.isEmpty())) {
|
|
throw new IllegalArgumentException("No providers were loaded with FastServiceLoader".toString());
|
|
}
|
|
Set set = h;
|
|
C14957gcv.e(set, "");
|
|
ArrayList arrayList2 = new ArrayList(set instanceof Collection ? set.size() : 10);
|
|
Iterator it2 = set.iterator();
|
|
while (it2.hasNext()) {
|
|
Class<?> cls2 = Class.forName((String) it2.next(), false, classLoader);
|
|
if (cls.isAssignableFrom(cls2)) {
|
|
arrayList2.add(cls.cast(cls2.getDeclaredConstructor(new Class[0]).newInstance(new Object[0])));
|
|
} else {
|
|
StringBuilder sb2 = new StringBuilder("Expected service of class ");
|
|
sb2.append(cls);
|
|
sb2.append(", but found ");
|
|
sb2.append(cls2);
|
|
throw new IllegalArgumentException(sb2.toString().toString());
|
|
}
|
|
}
|
|
return arrayList2;
|
|
} catch (Throwable unused) {
|
|
return C14881gav.d(ServiceLoader.load(cls, classLoader));
|
|
}
|
|
}
|
|
|
|
private static List<String> a(URL url) {
|
|
BufferedReader bufferedReader;
|
|
String obj = url.toString();
|
|
if (!gdZ.e(obj, "jar", false)) {
|
|
bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
|
|
try {
|
|
List<String> b2 = b(bufferedReader);
|
|
gbF.d(bufferedReader, null);
|
|
return b2;
|
|
} catch (Throwable th) {
|
|
try {
|
|
throw th;
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
String d = gdZ.d(obj, "jar:file:", obj);
|
|
C14957gcv.e(d, "");
|
|
C14957gcv.e(d, "");
|
|
int a = gdZ.a((CharSequence) d, '!', 0, false);
|
|
if (a != -1) {
|
|
d = d.substring(0, a);
|
|
C14957gcv.c((Object) d, "");
|
|
}
|
|
String d2 = gdZ.d(obj, "!/", obj);
|
|
JarFile jarFile = new JarFile(d, false);
|
|
try {
|
|
bufferedReader = new BufferedReader(new InputStreamReader(jarFile.getInputStream(new ZipEntry(d2)), "UTF-8"));
|
|
try {
|
|
List<String> b3 = b(bufferedReader);
|
|
gbF.d(bufferedReader, null);
|
|
jarFile.close();
|
|
return b3;
|
|
} finally {
|
|
}
|
|
} catch (Throwable th2) {
|
|
try {
|
|
throw th2;
|
|
} catch (Throwable th3) {
|
|
try {
|
|
jarFile.close();
|
|
throw th3;
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static List<String> b(BufferedReader bufferedReader) {
|
|
LinkedHashSet linkedHashSet = new LinkedHashSet();
|
|
while (true) {
|
|
String readLine = bufferedReader.readLine();
|
|
if (readLine != null) {
|
|
String obj = gdZ.b((CharSequence) gdZ.c(readLine, "#", readLine)).toString();
|
|
String str = obj;
|
|
for (int i = 0; i < str.length(); i++) {
|
|
char charAt = str.charAt(i);
|
|
if (charAt != '.' && !Character.isJavaIdentifierPart(charAt)) {
|
|
throw new IllegalArgumentException("Illegal service provider class name: ".concat(String.valueOf(obj)).toString());
|
|
}
|
|
}
|
|
if (str.length() > 0) {
|
|
linkedHashSet.add(obj);
|
|
}
|
|
} else {
|
|
return C14881gav.d(linkedHashSet);
|
|
}
|
|
}
|
|
}
|
|
}
|