package com.ifpdos.autotest.lancontrol.module.other;

import android.annotation.TargetApi;
import com.google.gson.internal.LinkedTreeMap;
import com.ifpdos.autotest.lancontrol.module.other.f.d;
import com.seewo.sdk.internal.model.SDKParsable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class InvocationModel implements SDKParsable {
    private static final String TAG = "InvocationModel";
    private String className;
    private String methodName;
    private Object[] parameters;

    public InvocationModel(Class cls, Method method, Object[] objArr) {
        this.className = cls.getName();
        this.methodName = method.getName();
        this.parameters = objArr;
    }

    @TargetApi(19)
    private Object doInvoke(Object obj, Method method) {
        try {
            mapParametersTypeIfNecessary(this.parameters, method.getParameterTypes());
            return method.invoke(obj, this.parameters);
        } catch (IllegalAccessException | InvocationTargetException e2) {
            b.c.d.d.c.c(TAG, "Invocation fail for " + obj + " method " + method, e2);
            return "";
        }
    }

    private Method findMethod() {
        try {
            for (Method method : Class.forName(this.className).getMethods()) {
                if (method.getName().equals(this.methodName) && method.getParameterTypes().length == this.parameters.length) {
                    return method;
                }
            }
            return null;
        } catch (ClassNotFoundException e2) {
            b.c.d.d.c.d(TAG, e2);
            return null;
        }
    }

    private Method loadMethod() {
        Method methodA;
        com.ifpdos.autotest.lancontrol.module.other.f.a aVar = new com.ifpdos.autotest.lancontrol.module.other.f.a(this.className, this.methodName, this.parameters.length);
        Method methodA2 = d.b().a(aVar);
        if (methodA2 != null) {
            return methodA2;
        }
        synchronized (d.b()) {
            methodA = d.b().a(aVar);
            if (methodA == null && (methodA = findMethod()) != null) {
                d.b().c(aVar, methodA);
            }
        }
        return methodA;
    }

    private void mapParametersTypeIfNecessary(Object[] objArr, Class<?>[] clsArr) {
        for (int i = 0; i < objArr.length; i++) {
            if ((clsArr[i] == Integer.TYPE || clsArr[i] == Integer.class) && (objArr[i] instanceof Double)) {
                objArr[i] = Integer.valueOf(((Double) objArr[i]).intValue());
            } else if ((clsArr[i] == Long.TYPE || clsArr[i] == Long.class) && (objArr[i] instanceof Double)) {
                objArr[i] = Long.valueOf(((Double) objArr[i]).longValue());
            } else if ((clsArr[i] == Byte.TYPE || clsArr[i] == Byte.class) && (objArr[i] instanceof Double)) {
                objArr[i] = Byte.valueOf(((Double) objArr[i]).byteValue());
            } else if ((clsArr[i] == Float.TYPE || clsArr[i] == Float.class) && (objArr[i] instanceof Double)) {
                objArr[i] = Float.valueOf(((Double) objArr[i]).floatValue());
            } else if ((clsArr[i] == Short.TYPE || clsArr[i] == Short.class) && (objArr[i] instanceof Double)) {
                objArr[i] = Short.valueOf(((Double) objArr[i]).shortValue());
            } else if ((objArr[i] instanceof String) && clsArr[i] != String.class) {
                objArr[i] = com.ifpdos.autotest.lancontrol.module.other.f.e.b.c().b((String) objArr[i], clsArr[i]);
            } else if ((objArr[i] instanceof LinkedTreeMap) || (objArr[i] instanceof List)) {
                objArr[i] = com.ifpdos.autotest.lancontrol.module.other.f.e.b.c().b(com.ifpdos.autotest.lancontrol.module.other.f.e.b.c().a(objArr[i]), clsArr[i]);
            }
        }
    }

    public String getClassName() {
        return this.className;
    }

    public String getMethodName() {
        return this.methodName;
    }

    public Object invoke(Object obj) {
        Method methodLoadMethod;
        if (obj == null) {
            b.c.d.d.c.b(TAG, "Null impl for " + this.className);
            return null;
        }
        try {
            if (this.parameters == null) {
                this.parameters = new Object[0];
            }
            methodLoadMethod = loadMethod();
        } catch (Exception e2) {
            b.c.d.d.c.d(TAG, e2);
        }
        if (methodLoadMethod != null) {
            return doInvoke(obj, methodLoadMethod);
        }
        b.c.d.d.c.b(TAG, "Method not found! for " + this.methodName);
        return null;
    }

    public Object invokeStatic() {
        Method methodLoadMethod = loadMethod();
        if (methodLoadMethod != null) {
            return doInvoke(null, methodLoadMethod);
        }
        return null;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder(this.className);
        sb.append("# ");
        Object[] objArr = this.parameters;
        if (objArr == null || objArr.length == 0) {
            sb.append(this.methodName);
            sb.append("();");
        } else {
            sb.append(this.methodName);
            sb.append("(");
            int i = 0;
            while (true) {
                Object[] objArr2 = this.parameters;
                if (i >= objArr2.length) {
                    break;
                }
                sb.append(objArr2[i] == null ? "null" : objArr2[i].toString());
                if (i < this.parameters.length - 1) {
                    sb.append(", ");
                }
                i++;
            }
            sb.append(");");
        }
        return sb.toString();
    }
}
