package com.tencent.mm.ipcinvoker;

import android.os.Bundle;
import android.os.Parcelable;
import android.os.RemoteException;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ipcinvoker.b.a;
import com.tencent.mm.ipcinvoker.h.b;
import java.util.HashSet;
import java.util.Set;

public class f {
    static /* synthetic */ Bundle c(Parcelable parcelable) {
        AppMethodBeat.i(114034);
        Bundle b = b(parcelable);
        AppMethodBeat.o(114034);
        return b;
    }

    public static <T extends a<InputType, ResultType>, InputType extends Parcelable, ResultType extends Parcelable> boolean a(String str, InputType inputType, Class<T> cls, c<ResultType> cVar) {
        AppMethodBeat.i(114030);
        if (str == null || str.length() == 0) {
            b.e("IPC.IPCInvoker", "invokeAsync failed, process is null or nil.", new Object[0]);
            AppMethodBeat.o(114030);
            return false;
        } else if (cls == null) {
            b.e("IPC.IPCInvoker", "invokeAsync failed, taskClass is null(process : %s).", new Object[]{str});
            AppMethodBeat.o(114030);
            return false;
        } else {
            boolean s = l.s(new 1(str, cls, inputType, cVar));
            AppMethodBeat.o(114030);
            return s;
        }
    }

    public static void a(String str, j jVar) {
        AppMethodBeat.i(114031);
        b PL = b.PL();
        Set set = (Set) PL.eFN.get(str);
        if (set == null) {
            set = new HashSet();
        }
        set.add(jVar);
        PL.eFN.put(str, set);
        AppMethodBeat.o(114031);
    }

    public static <T extends i<InputType, ResultType>, InputType extends Parcelable, ResultType extends Parcelable> ResultType a(String str, InputType inputType, Class<T> cls) {
        AppMethodBeat.i(114032);
        if (str == null || str.length() == 0) {
            b.e("IPC.IPCInvoker", "invokeSync failed, process is null or nil.", new Object[0]);
            AppMethodBeat.o(114032);
            return null;
        } else if (e.lg(str)) {
            Object am = ((i) k.i(cls, i.class)).am(inputType);
            if (am == null) {
                AppMethodBeat.o(114032);
                return null;
            }
            Parcelable parcelable = (Parcelable) am;
            AppMethodBeat.o(114032);
            return parcelable;
        } else {
            a ld = b.PL().ld(str);
            if (ld == null) {
                b.e("IPC.IPCInvoker", "invokeSync failed, get bridge is null by process(%s).", new Object[]{str});
                AppMethodBeat.o(114032);
                return null;
            }
            try {
                Bundle f = ld.f(b(inputType), cls.getName());
                if (f == null) {
                    AppMethodBeat.o(114032);
                    return null;
                }
                f.setClassLoader(f.class.getClassLoader());
                ResultType parcelable2 = f.getParcelable("__remote_task_result_data");
                AppMethodBeat.o(114032);
                return parcelable2;
            } catch (RemoteException e) {
                b.d("IPC.IPCInvoker", "invokeSync failed, ipc invoke error : %s", new Object[]{e});
                AppMethodBeat.o(114032);
                return null;
            }
        }
    }

    private static Bundle b(Parcelable parcelable) {
        AppMethodBeat.i(114033);
        Bundle bundle = new Bundle();
        bundle.putParcelable("__remote_task_data", parcelable);
        AppMethodBeat.o(114033);
        return bundle;
    }
}
