Skip to content

Commit

Permalink
* [android] add a stop method to IWXDebugProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
budao committed Jul 6, 2016
1 parent 8166216 commit b06d352
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
11 changes: 11 additions & 0 deletions android/inspector/debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@
{ "name": "callback", "type":"string"},
{ "name": "tasks", "type": "array", "items": { "$ref":"task"}}
]
},{
"name":"reload"
},{
"name":"registerDevice",
"parameters":[
{ "name": "name", "type":"string"},
{ "name": "model", "type":"string"},
{ "name": "weexVersion", "type": "string"},
{ "name": "platform", "type":"string"},
{ "name": "deviceId", "type":"string"}
]
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

Expand Down Expand Up @@ -126,6 +125,15 @@ public void onFailure(Throwable cause) {
});
}

@Override
public void stop() {
if (mWebSocketClient != null) {
mWebSocketClient.closeQuietly();
mWebSocketClient = null;
}
mBridge = null;
}

@Override
public IWXBridge getWXBridge() {
return mBridge;
Expand All @@ -139,14 +147,8 @@ public void handleMessage(BufferedSource payload, WebSocket.PayloadType type) th
try {
try {
String message = payload.readUtf8();
if (!TextUtils.isEmpty(message)) {
if (message.contains("WxDebug.callNative") /* &&false */) {
handleDebugMessage(message);
} else {
Util.throwIfNull(mPeer);
handleRemoteMessage(mPeer, message);
}
}
Util.throwIfNull(mPeer);
handleRemoteMessage(mPeer, message);
} catch (Exception e) {

} finally {
Expand All @@ -160,19 +162,6 @@ public void handleMessage(BufferedSource payload, WebSocket.PayloadType type) th
}
}

private void handleDebugMessage(String message) {
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(message);

String method = jsonObject.getString("method");
com.alibaba.fastjson.JSONObject params = jsonObject.getJSONObject("params");
if (!TextUtils.isEmpty(method) && "WxDebug.callNative".equals(method) && params != null) {
String instance = params.getString("instance");
String callback = params.getString("callback");
String tasks = params.getString("tasks");
mBridge.callNative(instance, tasks, callback);
}
}

private void handleRemoteMessage(JsonRpcPeer peer, String message)
throws IOException, MessageHandlingException, JSONException {
// Parse as a generic JSONObject first since we don't know if this is a request or response.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.taobao.weex.devtools.inspector.protocol.module;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.devtools.debug.DebugBridge;
import com.taobao.weex.devtools.inspector.jsonrpc.JsonRpcPeer;
import com.taobao.weex.devtools.inspector.protocol.ChromeDevtoolsDomain;
Expand All @@ -13,7 +10,6 @@

import org.json.JSONObject;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
Expand Down Expand Up @@ -51,6 +47,11 @@ public void callNative(JsonRpcPeer peer, JSONObject params) {
// }
}

@ChromeDevtoolsMethod
public void reload(JsonRpcPeer peer, JSONObject params) {
WXSDKEngine.reload();
}

public static class CallNative {
@JsonProperty(required = true)
public String instance;
Expand Down
4 changes: 4 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,8 @@ public void run() {
}, 1000);
}
}

public static void reload() {
reload(WXEnvironment.getApplication(), WXEnvironment.sRemoteDebugMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ public class WXBridgeManager implements Callback {
private WXThread mJSThread;
private Handler mJSHandler;
private IWXBridge mWXBridge;
private IWXDebugProxy mWxDebugProxy;

private boolean mMock = false;
/**
Expand Down Expand Up @@ -330,14 +331,16 @@ public static WXBridgeManager getInstance() {
private void launchInspector(boolean remoteDebug) {
if (WXEnvironment.isApkDebugable()) {
try {
if (mWxDebugProxy != null) {
mWxDebugProxy.stop();
}
HackedClass<Object> waBridge = WXHack.into("com.taobao.weex.devtools.debug.DebugServerProxy");

IWXDebugProxy debugProxy = (IWXDebugProxy) waBridge.constructor(Context.class, WXBridgeManager.class)
mWxDebugProxy = (IWXDebugProxy) waBridge.constructor(Context.class, WXBridgeManager.class)
.getInstance(WXEnvironment.getApplication(), WXBridgeManager.this);
if (debugProxy != null) {
debugProxy.start();
if (mWxDebugProxy != null) {
mWxDebugProxy.start();
if (remoteDebug) {
mWXBridge = debugProxy.getWXBridge();
mWXBridge = mWxDebugProxy.getWXBridge();
}
}
} catch (HackAssertionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
*/
public interface IWXDebugProxy {
void start();
void stop();
IWXBridge getWXBridge();

}

0 comments on commit b06d352

Please sign in to comment.