if (safeKeyMap(switchMap, NETDATA_PRINT)) {
SocketMonitor.startMonitor();
}
public class SocketMonitor {
public static void startMonitor() {
}
static {
startMonitorInternal();
}
private static Set<Class> monitoredClass = Sets.newConcurrentHashSet();
private static void startMonitorInternal() {
LogUtil.startRecord();
//to find all class that extend java.net.Socket
XposedBridge.hookAllConstructors(Socket.class, new SingletonXC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Class<?> theSocketClass = param.thisObject.getClass();
if (monitoredClass.contains(theSocketClass)) {
return;
}
synchronized (SocketMonitor.class) {
if (monitoredClass.contains(theSocketClass)) {
return;
}
monitorSocketClass(theSocketClass);
monitoredClass.add(theSocketClass);
}
}
});
}
if (safeKeyMap(switchMap, NETDATA_PRINT)) {
SocketMonitor.startMonitor();
}
这里的if 判断调用的是startMonitor() 那么下面的那个 startMonitorInternal(); 会执行吗?两个方法名不一样啊
是的,如果这是第一次引用该类的话。Java类被调用前,会调用一次静态初始化代码块。如果已经调用过了,就不会再调用。