130 lines
4.6 KiB
Java
130 lines
4.6 KiB
Java
package io.flutter;
|
|
|
|
import io.flutter.embedding.engine.FlutterJNI;
|
|
import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager;
|
|
import io.flutter.embedding.engine.loader.FlutterLoader;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class FlutterInjector {
|
|
private static boolean accessed;
|
|
private static FlutterInjector instance;
|
|
private DeferredComponentManager deferredComponentManager;
|
|
private ExecutorService executorService;
|
|
private FlutterJNI.Factory flutterJniFactory;
|
|
private FlutterLoader flutterLoader;
|
|
|
|
public static void reset() {
|
|
accessed = false;
|
|
instance = null;
|
|
}
|
|
|
|
public final DeferredComponentManager deferredComponentManager() {
|
|
return this.deferredComponentManager;
|
|
}
|
|
|
|
public final ExecutorService executorService() {
|
|
return this.executorService;
|
|
}
|
|
|
|
public final FlutterLoader flutterLoader() {
|
|
return this.flutterLoader;
|
|
}
|
|
|
|
public final FlutterJNI.Factory getFlutterJNIFactory() {
|
|
return this.flutterJniFactory;
|
|
}
|
|
|
|
public static void setInstance(FlutterInjector flutterInjector) {
|
|
if (accessed) {
|
|
throw new IllegalStateException("Cannot change the FlutterInjector instance once it's been read. If you're trying to dependency inject, be sure to do so at the beginning of the program");
|
|
}
|
|
instance = flutterInjector;
|
|
}
|
|
|
|
public static FlutterInjector instance() {
|
|
accessed = true;
|
|
if (instance == null) {
|
|
instance = new Builder().build();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
private FlutterInjector(FlutterLoader flutterLoader, DeferredComponentManager deferredComponentManager, FlutterJNI.Factory factory, ExecutorService executorService) {
|
|
this.flutterLoader = flutterLoader;
|
|
this.deferredComponentManager = deferredComponentManager;
|
|
this.flutterJniFactory = factory;
|
|
this.executorService = executorService;
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static final class Builder {
|
|
private DeferredComponentManager deferredComponentManager;
|
|
private ExecutorService executorService;
|
|
private FlutterJNI.Factory flutterJniFactory;
|
|
private FlutterLoader flutterLoader;
|
|
|
|
public final Builder setDeferredComponentManager(DeferredComponentManager deferredComponentManager) {
|
|
this.deferredComponentManager = deferredComponentManager;
|
|
return this;
|
|
}
|
|
|
|
public final Builder setExecutorService(ExecutorService executorService) {
|
|
this.executorService = executorService;
|
|
return this;
|
|
}
|
|
|
|
public final Builder setFlutterJNIFactory(FlutterJNI.Factory factory) {
|
|
this.flutterJniFactory = factory;
|
|
return this;
|
|
}
|
|
|
|
public final Builder setFlutterLoader(FlutterLoader flutterLoader) {
|
|
this.flutterLoader = flutterLoader;
|
|
return this;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes.dex */
|
|
public class NamedThreadFactory implements ThreadFactory {
|
|
final Builder this$0;
|
|
private int threadId;
|
|
|
|
private NamedThreadFactory(Builder builder) {
|
|
this.this$0 = builder;
|
|
this.threadId = 0;
|
|
}
|
|
|
|
@Override // java.util.concurrent.ThreadFactory
|
|
public Thread newThread(Runnable runnable) {
|
|
Thread thread = new Thread(runnable);
|
|
StringBuilder sb = new StringBuilder("flutter-worker-");
|
|
int i = this.threadId;
|
|
this.threadId = i + 1;
|
|
sb.append(i);
|
|
thread.setName(sb.toString());
|
|
return thread;
|
|
}
|
|
}
|
|
|
|
private void fillDefaults() {
|
|
if (this.flutterJniFactory == null) {
|
|
this.flutterJniFactory = new FlutterJNI.Factory();
|
|
}
|
|
if (this.executorService == null) {
|
|
this.executorService = Executors.newCachedThreadPool(new NamedThreadFactory());
|
|
}
|
|
if (this.flutterLoader == null) {
|
|
this.flutterLoader = new FlutterLoader(this.flutterJniFactory.provideFlutterJNI(), this.executorService);
|
|
}
|
|
}
|
|
|
|
public final FlutterInjector build() {
|
|
fillDefaults();
|
|
return new FlutterInjector(this.flutterLoader, this.deferredComponentManager, this.flutterJniFactory, this.executorService);
|
|
}
|
|
}
|
|
}
|