DSBridge-Android
DSBridge-Android copied to clipboard
Some potencial ANR issue located in handling JSON
Hi, Thank you for this awsome project. I just got a question for you. Does these json code call from Main thread? Maybe it causes performance issue.
` @Keep private void addInternalJavascriptObject() { addJavascriptObject(new Object() {
@Keep
@JavascriptInterface
public boolean hasNativeMethod(Object args) throws JSONException {
JSONObject jsonObject = (JSONObject) args;
String methodName = jsonObject.getString("name").trim();
String type = jsonObject.getString("type").trim();
String[] nameStr = parseNamespace(methodName);
Object jsb = javaScriptNamespaceInterfaces.get(nameStr[0]);
if (jsb != null) {
Class<?> cls = jsb.getClass();
boolean asyn = false;
Method method = null;
try {
method = cls.getMethod(nameStr[1],
new Class[]{Object.class, CompletionHandler.class});
asyn = true;
} catch (Exception e) {
try {
method = cls.getMethod(nameStr[1], new Class[]{Object.class});
} catch (Exception ex) {
}
}
if (method != null) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
JavascriptInterface annotation = method.getAnnotation(JavascriptInterface.class);
if (annotation == null) {
return false;
}
}
if ("all".equals(type) || (asyn && "asyn".equals(type) || (!asyn && "syn".equals(type)))) {
return true;
}
}
}
return false;
}
`
@zengqiang24 This method is called from JavaBridge thread not main thread