- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
78 lines
2.4 KiB
Java
78 lines
2.4 KiB
Java
package androidx.lifecycle;
|
|
|
|
import android.os.Handler;
|
|
import androidx.lifecycle.Lifecycle;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ServiceLifecycleDispatcher {
|
|
private final Handler handler;
|
|
private DispatchRunnable lastDispatchRunnable;
|
|
private final LifecycleRegistry registry;
|
|
|
|
public Lifecycle getLifecycle() {
|
|
return this.registry;
|
|
}
|
|
|
|
public ServiceLifecycleDispatcher(LifecycleOwner provider) {
|
|
Intrinsics.checkNotNullParameter(provider, "provider");
|
|
this.registry = new LifecycleRegistry(provider);
|
|
this.handler = new Handler();
|
|
}
|
|
|
|
private final void postDispatchRunnable(Lifecycle.Event event) {
|
|
DispatchRunnable dispatchRunnable = this.lastDispatchRunnable;
|
|
if (dispatchRunnable != null) {
|
|
dispatchRunnable.run();
|
|
}
|
|
DispatchRunnable dispatchRunnable2 = new DispatchRunnable(this.registry, event);
|
|
this.lastDispatchRunnable = dispatchRunnable2;
|
|
Handler handler = this.handler;
|
|
Intrinsics.checkNotNull(dispatchRunnable2);
|
|
handler.postAtFrontOfQueue(dispatchRunnable2);
|
|
}
|
|
|
|
public void onServicePreSuperOnCreate() {
|
|
postDispatchRunnable(Lifecycle.Event.ON_CREATE);
|
|
}
|
|
|
|
public void onServicePreSuperOnBind() {
|
|
postDispatchRunnable(Lifecycle.Event.ON_START);
|
|
}
|
|
|
|
public void onServicePreSuperOnStart() {
|
|
postDispatchRunnable(Lifecycle.Event.ON_START);
|
|
}
|
|
|
|
public void onServicePreSuperOnDestroy() {
|
|
postDispatchRunnable(Lifecycle.Event.ON_STOP);
|
|
postDispatchRunnable(Lifecycle.Event.ON_DESTROY);
|
|
}
|
|
|
|
public static final class DispatchRunnable implements Runnable {
|
|
private final Lifecycle.Event event;
|
|
private final LifecycleRegistry registry;
|
|
private boolean wasExecuted;
|
|
|
|
public final Lifecycle.Event getEvent() {
|
|
return this.event;
|
|
}
|
|
|
|
public DispatchRunnable(LifecycleRegistry registry, Lifecycle.Event event) {
|
|
Intrinsics.checkNotNullParameter(registry, "registry");
|
|
Intrinsics.checkNotNullParameter(event, "event");
|
|
this.registry = registry;
|
|
this.event = event;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (this.wasExecuted) {
|
|
return;
|
|
}
|
|
this.registry.handleLifecycleEvent(this.event);
|
|
this.wasExecuted = true;
|
|
}
|
|
}
|
|
}
|