Commit b3344029 authored by xujialang's avatar xujialang

更新-反射调整

parent 1ddaec50
......@@ -29,18 +29,30 @@ public class NameInterfaceHelp {
public static String getFGClassPath() {
if (TextUtils.isEmpty(FG_Class_Path)) {
try {
LogUtil.d("OutShow 反射获取 getFGClassPath");
Class<?> kpClass = Class.forName(NameInterfaceHelp.getClassPath());
Method isHideMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod);
Object fgStr = isHideMethod.invoke(null, "FG");
if (kpClass == null) {
LogUtil.d("OutShow 反射获取 getFGClassPath kpClass==null");
}
Method fNameMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod, String.class);
if (fNameMethod == null) {
LogUtil.d("OutShow 反射获取 getFGClassPath fNameMethod==null");
}
Object fgStr = fNameMethod.invoke(null, "FG");
if (fgStr == null) {
LogUtil.d("OutShow 反射获取 getFGClassPath fgStr==null");
FG_Class_Path = "";
} else {
LogUtil.d("OutShow 反射获取 getFGClassPath fgStr=" + fgStr);
FG_Class_Path = (String) fgStr;
}
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException ignored) {
LogUtil.d("OutShow 反射获取 getFGClassPath (catch) " + ignored);
}
}
LogUtil.d("OutShow 反射获取 getFGClassPath=" + FG_Class_Path);
return FG_Class_Path;
}
......@@ -51,8 +63,8 @@ public class NameInterfaceHelp {
if (TextUtils.isEmpty(FG_Start_Method_Name)) {
try {
Class<?> kpClass = Class.forName(NameInterfaceHelp.getClassPath());
Method isHideMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod);
Object fgStr = isHideMethod.invoke(null, "surprise");
Method fNameMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod, String.class);
Object fgStr = fNameMethod.invoke(null, "surprise");
if (fgStr == null) {
FG_Start_Method_Name = "";
} else {
......@@ -60,8 +72,10 @@ public class NameInterfaceHelp {
}
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException ignored) {
LogUtil.d("OutShow 反射获取 getFGStartMethodName (catch) " + ignored);
}
}
LogUtil.d("OutShow getFGStartMethodName=" + FG_Start_Method_Name);
return FG_Start_Method_Name;
}
......@@ -72,8 +86,8 @@ public class NameInterfaceHelp {
if (TextUtils.isEmpty(FG_StartCallback_Class_Path)) {
try {
Class<?> kpClass = Class.forName(NameInterfaceHelp.getClassPath());
Method isHideMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod);
Object fgStr = isHideMethod.invoke(null, "StartCallback");
Method fNameMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod, String.class);
Object fgStr = fNameMethod.invoke(null, "StartCallback");
if (fgStr == null) {
FG_StartCallback_Class_Path = "";
} else {
......@@ -81,8 +95,10 @@ public class NameInterfaceHelp {
}
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException ignored) {
LogUtil.d("OutShow 反射获取 getStartCallbackClassPath (catch) " + ignored);
}
}
LogUtil.d("OutShow getStartCallbackClassPath=" + FG_StartCallback_Class_Path);
return FG_StartCallback_Class_Path;
}
......@@ -90,11 +106,11 @@ public class NameInterfaceHelp {
* 获取保活NotificationConfig类的路径
*/
public static String getNotificationConfigClassPath() {
if (TextUtils.isEmpty(FG_StartCallback_Class_Path)) {
if (TextUtils.isEmpty(FG_NotificationConfig_Class_Path)) {
try {
Class<?> kpClass = Class.forName(NameInterfaceHelp.getClassPath());
Method isHideMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod);
Object fgStr = isHideMethod.invoke(null, "NotificationConfig");
Method fNameMethod = kpClass.getMethod(NameInterfaceHelp.GetFGStringMethod, String.class);
Object fgStr = fNameMethod.invoke(null, "NotificationConfig");
if (fgStr == null) {
FG_NotificationConfig_Class_Path = "";
} else {
......@@ -102,17 +118,37 @@ public class NameInterfaceHelp {
}
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException ignored) {
LogUtil.d("OutShow 反射获取 getNotificationConfigClassPath (catch) " + ignored);
}
}
LogUtil.d("OutShow getNotificationConfigClassPath=" + FG_NotificationConfig_Class_Path);
return FG_NotificationConfig_Class_Path;
}
public static Object getNewCallBack() {
try {
Class<?> kpClass = Class.forName(NameInterfaceHelp.getClassPath());
Method callBackMethod = kpClass.getMethod(NameInterfaceHelp.GetNewCallBackMethod);
Object obj = callBackMethod.invoke(null);
LogUtil.d("OutShow 反射获取 getNewCallBack");
return obj;
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException ignored) {
LogUtil.d("OutShow 反射获取 getNewCallBack (catch) " + ignored);
}
return null;
}
/**
* 获取FG相关名称或路径的方法名称
*/
public static String GetFGStringMethod = "getFName";
public static String GetNewCallBackMethod = "getNewCallBack";
/**
* 获取保活方法的方法名称
......
......@@ -6,6 +6,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.RemoteViews;
import com.zl.sdk.ad.topOn.TopOnAdManager;
import com.zl.sdk.bean.AdAppInfo;
......@@ -260,25 +261,33 @@ public final class OutHelp implements KPListener {
LogUtil.d(TAG + "拉起外展");
try {
Class<?> fgClass = Class.forName(NameInterfaceHelp.getFGClassPath());
Method surpriseMethod = fgClass.getMethod(NameInterfaceHelp.getFGStartMethodName());
String fgPath = NameInterfaceHelp.getFGClassPath();
LogUtil.d(TAG + "拉起外展 fgPath=" + fgPath);
Class<?> fgClass = Class.forName(fgPath);
if (fgClass == null) {
LogUtil.d(TAG + "拉起外展 fgClass=null");
callback.fail("fgClass=null");
return;
}
Class<?> startCallbackClass = Class.forName(NameInterfaceHelp.getStartCallbackClassPath());
Constructor<?> constructor = startCallbackClass.getConstructor();
Object callObj = constructor.newInstance();
if (startCallbackClass == null) {
LogUtil.d(TAG + "拉起外展 startCallbackClass=null");
callback.fail("startCallbackClass=null");
return;
}
Object newCallBack = Proxy.newProxyInstance(
startCallbackClass.getClassLoader(),
new Class[]{startCallbackClass},
new StartCallbackProxy(callObj, callback)
);
Class<?> notifyClass = Class.forName(NameInterfaceHelp.getNotificationConfigClassPath());
Object callObj = NameInterfaceHelp.getNewCallBack();
Object notificationConfig = null;
Class<?> notifyClass = Class.forName(NameInterfaceHelp.getNotificationConfigClassPath());
Object notificationConfig = null;
if (notifyClass != null) {
notificationConfig = notifyClass.getConstructor().newInstance();
Constructor constructor = notifyClass.getDeclaredConstructor(RemoteViews.class);
notificationConfig = constructor.newInstance(new Object[]{null});
//这个参数传0 就是不悬挂在桌面,1000 就是悬挂一秒,-1 就是持续悬挂
Field[] fields = notifyClass.getDeclaredFields();
for (Field field : fields) {
......@@ -289,6 +298,29 @@ public final class OutHelp implements KPListener {
}
}
Method surpriseMethod = fgClass.getMethod(NameInterfaceHelp.getFGStartMethodName(),
Context.class,
Intent.class,
String.class,
boolean.class,
startCallbackClass,
notifyClass);
if (surpriseMethod == null) {
LogUtil.d(TAG + "拉起外展 surpriseMethod=null");
callback.fail("surpriseMethod=null");
return;
}
Object newCallBack = Proxy.newProxyInstance(
startCallbackClass.getClassLoader(),
new Class[]{startCallbackClass},
new StartCallbackProxy(callObj, callback)
);
surpriseMethod.invoke(null, mContext, intent, "", true, newCallBack, notificationConfig);
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
......@@ -341,10 +373,10 @@ public final class OutHelp implements KPListener {
@Override
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
if (callback != null) {
if ("onSuccess".equals(method.getName()) || objects.length == 1) {
if ("onSuccess".equals(method.getName())) {
LogUtil.d(TAG + "拉起外展:onSuccess");
callback.success();
} else if ("onFail".equals(method.getName()) || objects.length == 2) {
} else if ("onFail".equals(method.getName())) {
LogUtil.d(TAG + "拉起外展:onFail");
if (objects.length >= 2) {
LogUtil.d(TAG + "拉起外展:onFail reason=" + objects[1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment