package o;

import android.content.Context;
import androidx.work.WorkerParameters;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Km0 {
    static {
        C0669Zu.l("WorkerFactory");
    }

    public static AbstractC0995dM a(Context context, String str, WorkerParameters workerParameters) {
        Class clsAsSubclass;
        AbstractC0995dM abstractC0995dM = null;
        try {
            clsAsSubclass = Class.forName(str).asSubclass(AbstractC0995dM.class);
        } catch (Throwable unused) {
            C0669Zu.e().getClass();
            clsAsSubclass = null;
        }
        if (clsAsSubclass != null) {
            try {
                abstractC0995dM = (AbstractC0995dM) clsAsSubclass.getDeclaredConstructor(Context.class, WorkerParameters.class).newInstance(context, workerParameters);
            } catch (Throwable unused2) {
                C0669Zu.e().getClass();
            }
        }
        if (abstractC0995dM == null || !abstractC0995dM.f490o) {
            return abstractC0995dM;
        }
        throw new IllegalStateException("WorkerFactory (" + Km0.class.getName() + ") returned an instance of a ListenableWorker (" + str + ") which has already been invoked. createWorker() must always return a new instance of a ListenableWorker.");
    }
}
