Skip to content

Commit

Permalink
adb over tcp
Browse files Browse the repository at this point in the history
  • Loading branch information
naman14 committed May 28, 2017
1 parent 9768e81 commit ec6e1b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions adbhelper.js
Expand Up @@ -69,6 +69,22 @@ function stopScreenRecording(deviceId, pid) {

}

function establishTCPConnection(deviceId) {
let deviceIp = getDeviceIp(deviceId);

GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId + " tcpip 5555"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
let [res, out, error] = GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId + " connect " + deviceIp+":5555"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);

return out.toString().trim();

}

function getDeviceIp(deviceId) {
let [res, out, error] = GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId +" shell ip route | awk '{print $9}'"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
return out.toString().trim();

}


function isEmpty(str) {
return (!str || str.length === 0 || !str.trim());
Expand Down
12 changes: 12 additions & 0 deletions extension.js
Expand Up @@ -116,6 +116,11 @@ const AndroidMenu = new Lang.Class({
}
},

_connectTCP: function(device) {
let status = AdbHelper.establishTCPConnection(device.deviceId)
Main.notify(status)
},

_addMenuItems: function(devices) {

this.menu.removeAll();
Expand Down Expand Up @@ -151,6 +156,13 @@ const AndroidMenu = new Lang.Class({
}));
section.addMenuItem(recordScreenItem);

let remoteItem = new AndroidMenuItem({label: "Establish remote connection", icon: "android_icon"});

remoteItem.connect('activate', Lang.bind(this, function() {
this._connectTCP(device)
}));
section.addMenuItem(remoteItem);

this.menu.addMenuItem(section)
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

Expand Down

0 comments on commit ec6e1b7

Please sign in to comment.