{"action":"created","comment":{"url":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments/57963613","id":57963613,"diff_hunk":"@@ -1 +1,393 @@\n-// https://github.com/appcelerator/titanium_mobile/blob/master/node_modules/titanium-sdk/lib/adb.js\n+import { EventEmitter } from 'events';\n+import fs from 'fs';\n+import mkdirp from 'mkdirp';\n+import path from 'path';\n+import { spawn } from 'child_process';\n+\n+import { Connection } from './connection';\n+import { EmulatorManager } from './emulator';\n+import * as sdk from './sdk';\n+import * as util from './util';\n+\n+/**\n+ * Creates an ADB object.\n+ *\n+ * @class\n+ * @extends EventEmitter\n+ * @classdesc Provides methods to interact with the Android Debug Bridge (ADB).\n+ * @constructor\n+ */\n+export class ADB extends EventEmitter {\n+\tconstructor(opts = {}) {\n+\t\tsuper();\n+\t\tthis.opts = opts;\n+\t}\n+\n+\t/**\n+\t * Returns the version of the ADB server.\n+\t *\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tversion() {\n+\t\treturn new Connection(this)\n+\t\t\t.exec('host:version')\n+\t\t\t.then(data => '1.0.' + parseInt(data, 16));\n+\t}\n+\n+\t/**\n+\t * Runs the specified command on the Android emulator/device.\n+\t *\n+\t * @param {String} deviceId - The id of the device or emulator.\n+\t * @param {String} cmd - The command to run.\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tshell(deviceId, cmd) {\n+\t\tif (typeof deviceId !== 'string' || !deviceId) {\n+\t\t\treturn Promise.reject(new TypeError('Expected device ID to be a string.'));\n+\t\t}\n+\n+\t\tif (typeof cmd !== 'string' || !cmd) {\n+\t\t\treturn Promise.reject(new TypeError('Expected command to be a string.'));\n+\t\t}\n+\n+\t\tconst conn = new Connection(this);\n+\t\treturn conn\n+\t\t\t.exec('host:transport:' + deviceId)\n+\t\t\t.then(data => conn.exec(`shell: ${cmd.replace(/^shell\\:/, '')}`, { bufferUntilClose: true, noLength: true }));\n+\t}\n+\n+\t/**\n+\t * Attempts to find the adb executable, then start the adb server.\n+\t *\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tstartServer() {\n+\t\treturn sdk\n+\t\t\t.detect(this.opts)\n+\t\t\t.then(result => util.run(result.sdk.executables.adb, ['start-server']));\n+\t}\n+\n+\t/**\n+\t * Attempts to find the adb executable, then stop the adb server.\n+\t *\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tstopServer() {\n+\t\treturn sdk\n+\t\t\t.detect(this.opts)\n+\t\t\t.then(result => util.run(result.sdk.executables.adb, ['kill-server']));\n+\t}\n+\n+\t/**\n+\t * Forwards the specified device/emulator's socket connections to the destination.\n+\t *\n+\t * @param {String} deviceId - The id of the device or emulator.\n+\t * @param {String} src - The source port in the format \"tcp:<port>\".\n+\t * @param {String} dest - The destination port in the format \"tcp:<port>\" or \"jdwp:<pid>\".\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tforward(deviceId, src, dest) {\n+\t\tif (typeof deviceId !== 'string' || !deviceId) {\n+\t\t\treturn Promise.reject(new TypeError('Expected device ID to be a string.'));\n+\t\t}\n+\n+\t\tsrc = util.expandPath(src);\n+\t\tif (!util.existsSync(src)) {\n+\t\t\treturn Promise.reject(new TypeError(`Source file \"${src}\" does not exist.`));\n+\t\t}\n+\n+\t\treturn sdk\n+\t\t\t.detect(this.opts)\n+\t\t\t.then(result => util.run(result.sdk.executables.adb, ['-s', deviceId, 'forward', src, dest]));\n+\t}\n+\n+\t/**\n+\t * Pushes a single file to a device or emulator.\n+\t *\n+\t * @param {String} deviceId - The id of the device or emulator.\n+\t * @param {String} src - The source file to copy to the device.\n+\t * @param {String} dest - The destination to write the file.\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tpush(deviceId, src, dest) {\n+\t\tif (typeof deviceId !== 'string' || !deviceId) {\n+\t\t\treturn Promise.reject(new TypeError('Expected device ID to be a string.'));\n+\t\t}\n+\n+\t\tsrc = util.expandPath(src);\n+\t\tif (!util.existsSync(src)) {\n+\t\t\treturn Promise.reject(new TypeError(`Source file \"${src}\" does not exist.`));\n+\t\t}\n+\n+\t\treturn sdk\n+\t\t\t.detect(this.opts)\n+\t\t\t.then(result => util.run(result.sdk.executables.adb, ['-s', deviceId, 'push', src, dest]));\n+\t}\n+\n+\t/**\n+\t * Pulls a single file from a device or emulator.\n+\t *\n+\t * @param {String} deviceId - The id of the device or emulator.\n+\t * @param {String} src - The source file to copy from the device.\n+\t * @param {String} dest - The destination to write the file.\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tpull(deviceId, src, dest) {\n+\t\tif (typeof deviceId !== 'string' || !deviceId) {\n+\t\t\treturn Promise.reject(new TypeError('Expected device ID to be a string.'));\n+\t\t}\n+\n+\t\tif (typeof dest !== 'string' || !dest) {\n+\t\t\treturn Promise.reject(new TypeError('Expected destination to be a string.'));\n+\t\t}\n+\n+\t\tsrc = util.expandPath(src);\n+\t\tif (!util.existsSync(src)) {\n+\t\t\treturn Promise.reject(new TypeError(`Source file \"${src}\" does not exist.`));\n+\t\t}\n+\n+\t\tdest = util.expandPath(dest);\n+\t\tconst destDir = path.dirname(dest);\n+\n+\t\tmkdirp.sync(destDir);\n+\n+\t\treturn sdk\n+\t\t\t.detect(this.opts)\n+\t\t\t.then(result => util.run(result.sdk.executables.adb, ['-s', deviceId, 'pull', src, dest]));\n+\t}\n+\n+\t/**\n+\t * Returns the pid of the specified app for the specified device/emulator, if running.\n+\t *\n+\t * @param {String} deviceId - The id of the device or emulator.\n+\t * @param {String} appId - The application's id.\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tgetPid(deviceId, appId) {\n+\t\tif (typeof deviceId !== 'string' || !deviceId) {\n+\t\t\treturn Promise.reject(new TypeError('Expected device ID to be a string.'));\n+\t\t}\n+\n+\t\tif (typeof appId !== 'string' || !appId) {\n+\t\t\treturn Promise.reject(new TypeError('Expected app ID to be a string.'));\n+\t\t}\n+\n+\t\treturn this\n+\t\t\t.shell(deviceId, 'ps')\n+\t\t\t.then(data => {\n+\t\t\t\tif (data) {\n+\t\t\t\t\tconst lines = data.toString().split('\\n');\n+\t\t\t\t\tfor (let i = 0, j = lines.length; i < j; i++ ) {\n+\t\t\t\t\t\tlet columns = lines[i].trim().split(/\\s+/);\n+\t\t\t\t\t\tif (columns.pop() === appId) {\n+\t\t\t\t\t\t\treturn parseInt(columns[1]);\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\treturn 0;\n+\t\t\t});\n+\t}\n+\n+\t/**\n+\t * Installs an app to the specified device/emulator.\n+\t *\n+\t * @param {String} deviceId - The id of the device or emulator.\n+\t * @param {String} apkFile - The application apk file to install.\n+\t * @param {Object} [opts] - Install options.\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\tinstallApp(deviceId, apkFile, opts = {}) {","path":"src/adb.js","position":209,"original_position":209,"commit_id":"c8c61b9a8f556f4454931f09afedac87dc7cf22d","original_commit_id":"c8c61b9a8f556f4454931f09afedac87dc7cf22d","user":{"login":"cb1kenobi","id":97262,"avatar_url":"https://avatars.githubusercontent.com/u/97262?v=3","gravatar_id":"","url":"https://api.github.com/users/cb1kenobi","html_url":"https://github.com/cb1kenobi","followers_url":"https://api.github.com/users/cb1kenobi/followers","following_url":"https://api.github.com/users/cb1kenobi/following{/other_user}","gists_url":"https://api.github.com/users/cb1kenobi/gists{/gist_id}","starred_url":"https://api.github.com/users/cb1kenobi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cb1kenobi/subscriptions","organizations_url":"https://api.github.com/users/cb1kenobi/orgs","repos_url":"https://api.github.com/users/cb1kenobi/repos","events_url":"https://api.github.com/users/cb1kenobi/events{/privacy}","received_events_url":"https://api.github.com/users/cb1kenobi/received_events","type":"User","site_admin":false},"body":"`opts` is unused. Nuke it!","created_at":"2016-03-30T21:05:28Z","updated_at":"2016-03-30T21:05:28Z","html_url":"https://github.com/appcelerator/androidlib/pull/5#discussion_r57963613","pull_request_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments/57963613"},"html":{"href":"https://github.com/appcelerator/androidlib/pull/5#discussion_r57963613"},"pull_request":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5","id":63779849,"html_url":"https://github.com/appcelerator/androidlib/pull/5","diff_url":"https://github.com/appcelerator/androidlib/pull/5.diff","patch_url":"https://github.com/appcelerator/androidlib/pull/5.patch","issue_url":"https://api.github.com/repos/appcelerator/androidlib/issues/5","number":5,"state":"open","locked":false,"title":"[TIMOB-20327] Androidlib: android environment detection","user":{"login":"feons","id":7485592,"avatar_url":"https://avatars.githubusercontent.com/u/7485592?v=3","gravatar_id":"","url":"https://api.github.com/users/feons","html_url":"https://github.com/feons","followers_url":"https://api.github.com/users/feons/followers","following_url":"https://api.github.com/users/feons/following{/other_user}","gists_url":"https://api.github.com/users/feons/gists{/gist_id}","starred_url":"https://api.github.com/users/feons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feons/subscriptions","organizations_url":"https://api.github.com/users/feons/orgs","repos_url":"https://api.github.com/users/feons/repos","events_url":"https://api.github.com/users/feons/events{/privacy}","received_events_url":"https://api.github.com/users/feons/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-22T19:35:57Z","updated_at":"2016-03-30T21:05:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f8483fc43ea39a1a0cfdcadd06a395d62fc4178c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/commits","review_comments_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/comments","review_comment_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/appcelerator/androidlib/issues/5/comments","statuses_url":"https://api.github.com/repos/appcelerator/androidlib/statuses/c8c61b9a8f556f4454931f09afedac87dc7cf22d","head":{"label":"feons:timob-20327-init","ref":"timob-20327-init","sha":"c8c61b9a8f556f4454931f09afedac87dc7cf22d","user":{"login":"feons","id":7485592,"avatar_url":"https://avatars.githubusercontent.com/u/7485592?v=3","gravatar_id":"","url":"https://api.github.com/users/feons","html_url":"https://github.com/feons","followers_url":"https://api.github.com/users/feons/followers","following_url":"https://api.github.com/users/feons/following{/other_user}","gists_url":"https://api.github.com/users/feons/gists{/gist_id}","starred_url":"https://api.github.com/users/feons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feons/subscriptions","organizations_url":"https://api.github.com/users/feons/orgs","repos_url":"https://api.github.com/users/feons/repos","events_url":"https://api.github.com/users/feons/events{/privacy}","received_events_url":"https://api.github.com/users/feons/received_events","type":"User","site_admin":false},"repo":{"id":51876785,"name":"androidlib","full_name":"feons/androidlib","owner":{"login":"feons","id":7485592,"avatar_url":"https://avatars.githubusercontent.com/u/7485592?v=3","gravatar_id":"","url":"https://api.github.com/users/feons","html_url":"https://github.com/feons","followers_url":"https://api.github.com/users/feons/followers","following_url":"https://api.github.com/users/feons/following{/other_user}","gists_url":"https://api.github.com/users/feons/gists{/gist_id}","starred_url":"https://api.github.com/users/feons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feons/subscriptions","organizations_url":"https://api.github.com/users/feons/orgs","repos_url":"https://api.github.com/users/feons/repos","events_url":"https://api.github.com/users/feons/events{/privacy}","received_events_url":"https://api.github.com/users/feons/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/feons/androidlib","description":"Android Utility Library","fork":true,"url":"https://api.github.com/repos/feons/androidlib","forks_url":"https://api.github.com/repos/feons/androidlib/forks","keys_url":"https://api.github.com/repos/feons/androidlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/feons/androidlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/feons/androidlib/teams","hooks_url":"https://api.github.com/repos/feons/androidlib/hooks","issue_events_url":"https://api.github.com/repos/feons/androidlib/issues/events{/number}","events_url":"https://api.github.com/repos/feons/androidlib/events","assignees_url":"https://api.github.com/repos/feons/androidlib/assignees{/user}","branches_url":"https://api.github.com/repos/feons/androidlib/branches{/branch}","tags_url":"https://api.github.com/repos/feons/androidlib/tags","blobs_url":"https://api.github.com/repos/feons/androidlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/feons/androidlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/feons/androidlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/feons/androidlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/feons/androidlib/statuses/{sha}","languages_url":"https://api.github.com/repos/feons/androidlib/languages","stargazers_url":"https://api.github.com/repos/feons/androidlib/stargazers","contributors_url":"https://api.github.com/repos/feons/androidlib/contributors","subscribers_url":"https://api.github.com/repos/feons/androidlib/subscribers","subscription_url":"https://api.github.com/repos/feons/androidlib/subscription","commits_url":"https://api.github.com/repos/feons/androidlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/feons/androidlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/feons/androidlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/feons/androidlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/feons/androidlib/contents/{+path}","compare_url":"https://api.github.com/repos/feons/androidlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/feons/androidlib/merges","archive_url":"https://api.github.com/repos/feons/androidlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/feons/androidlib/downloads","issues_url":"https://api.github.com/repos/feons/androidlib/issues{/number}","pulls_url":"https://api.github.com/repos/feons/androidlib/pulls{/number}","milestones_url":"https://api.github.com/repos/feons/androidlib/milestones{/number}","notifications_url":"https://api.github.com/repos/feons/androidlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/feons/androidlib/labels{/name}","releases_url":"https://api.github.com/repos/feons/androidlib/releases{/id}","deployments_url":"https://api.github.com/repos/feons/androidlib/deployments","created_at":"2016-02-16T22:58:18Z","updated_at":"2016-02-16T22:58:19Z","pushed_at":"2016-03-30T03:40:38Z","git_url":"git://github.com/feons/androidlib.git","ssh_url":"git@github.com:feons/androidlib.git","clone_url":"https://github.com/feons/androidlib.git","svn_url":"https://github.com/feons/androidlib","homepage":null,"size":106,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"appcelerator:timob-20327","ref":"timob-20327","sha":"29c2a0487a6c1627b68c1a3ded0a20b02b48d0f9","user":{"login":"appcelerator","id":82188,"avatar_url":"https://avatars.githubusercontent.com/u/82188?v=3","gravatar_id":"","url":"https://api.github.com/users/appcelerator","html_url":"https://github.com/appcelerator","followers_url":"https://api.github.com/users/appcelerator/followers","following_url":"https://api.github.com/users/appcelerator/following{/other_user}","gists_url":"https://api.github.com/users/appcelerator/gists{/gist_id}","starred_url":"https://api.github.com/users/appcelerator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appcelerator/subscriptions","organizations_url":"https://api.github.com/users/appcelerator/orgs","repos_url":"https://api.github.com/users/appcelerator/repos","events_url":"https://api.github.com/users/appcelerator/events{/privacy}","received_events_url":"https://api.github.com/users/appcelerator/received_events","type":"Organization","site_admin":false},"repo":{"id":20471433,"name":"androidlib","full_name":"appcelerator/androidlib","owner":{"login":"appcelerator","id":82188,"avatar_url":"https://avatars.githubusercontent.com/u/82188?v=3","gravatar_id":"","url":"https://api.github.com/users/appcelerator","html_url":"https://github.com/appcelerator","followers_url":"https://api.github.com/users/appcelerator/followers","following_url":"https://api.github.com/users/appcelerator/following{/other_user}","gists_url":"https://api.github.com/users/appcelerator/gists{/gist_id}","starred_url":"https://api.github.com/users/appcelerator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appcelerator/subscriptions","organizations_url":"https://api.github.com/users/appcelerator/orgs","repos_url":"https://api.github.com/users/appcelerator/repos","events_url":"https://api.github.com/users/appcelerator/events{/privacy}","received_events_url":"https://api.github.com/users/appcelerator/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/appcelerator/androidlib","description":"Android Utility Library","fork":false,"url":"https://api.github.com/repos/appcelerator/androidlib","forks_url":"https://api.github.com/repos/appcelerator/androidlib/forks","keys_url":"https://api.github.com/repos/appcelerator/androidlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/appcelerator/androidlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/appcelerator/androidlib/teams","hooks_url":"https://api.github.com/repos/appcelerator/androidlib/hooks","issue_events_url":"https://api.github.com/repos/appcelerator/androidlib/issues/events{/number}","events_url":"https://api.github.com/repos/appcelerator/androidlib/events","assignees_url":"https://api.github.com/repos/appcelerator/androidlib/assignees{/user}","branches_url":"https://api.github.com/repos/appcelerator/androidlib/branches{/branch}","tags_url":"https://api.github.com/repos/appcelerator/androidlib/tags","blobs_url":"https://api.github.com/repos/appcelerator/androidlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/appcelerator/androidlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/appcelerator/androidlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/appcelerator/androidlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/appcelerator/androidlib/statuses/{sha}","languages_url":"https://api.github.com/repos/appcelerator/androidlib/languages","stargazers_url":"https://api.github.com/repos/appcelerator/androidlib/stargazers","contributors_url":"https://api.github.com/repos/appcelerator/androidlib/contributors","subscribers_url":"https://api.github.com/repos/appcelerator/androidlib/subscribers","subscription_url":"https://api.github.com/repos/appcelerator/androidlib/subscription","commits_url":"https://api.github.com/repos/appcelerator/androidlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/appcelerator/androidlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/appcelerator/androidlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/appcelerator/androidlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/appcelerator/androidlib/contents/{+path}","compare_url":"https://api.github.com/repos/appcelerator/androidlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/appcelerator/androidlib/merges","archive_url":"https://api.github.com/repos/appcelerator/androidlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/appcelerator/androidlib/downloads","issues_url":"https://api.github.com/repos/appcelerator/androidlib/issues{/number}","pulls_url":"https://api.github.com/repos/appcelerator/androidlib/pulls{/number}","milestones_url":"https://api.github.com/repos/appcelerator/androidlib/milestones{/number}","notifications_url":"https://api.github.com/repos/appcelerator/androidlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/appcelerator/androidlib/labels{/name}","releases_url":"https://api.github.com/repos/appcelerator/androidlib/releases{/id}","deployments_url":"https://api.github.com/repos/appcelerator/androidlib/deployments","created_at":"2014-06-04T05:34:26Z","updated_at":"2015-03-12T20:20:00Z","pushed_at":"2016-03-30T03:40:39Z","git_url":"git://github.com/appcelerator/androidlib.git","ssh_url":"git@github.com:appcelerator/androidlib.git","clone_url":"https://github.com/appcelerator/androidlib.git","svn_url":"https://github.com/appcelerator/androidlib","homepage":null,"size":62,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":1,"forks":4,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5"},"html":{"href":"https://github.com/appcelerator/androidlib/pull/5"},"issue":{"href":"https://api.github.com/repos/appcelerator/androidlib/issues/5"},"comments":{"href":"https://api.github.com/repos/appcelerator/androidlib/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/appcelerator/androidlib/statuses/c8c61b9a8f556f4454931f09afedac87dc7cf22d"}}}}