Skip to content

Commit

Permalink
Merge pull request appium#171 from MicroFocus/master
Browse files Browse the repository at this point in the history
Fixed issues with Android 7 (issue #6665 in Appium)
  • Loading branch information
imurchie committed Sep 20, 2016
2 parents 7b152b1 + 2816872 commit 16a71ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/tools/adb-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ methods.getPIDsByName = async function (name) {
if (name.length > 15) {
name = name.substr(name.length - 15);
}
let stdout = await this.shell(["ps", name]);
let stdout = await this.shell(["set `ps | grep '" + name + "'`;echo $2"]);
stdout = stdout.trim();
let pids = [];
for (let line of stdout.split("\n")) {
Expand Down
10 changes: 9 additions & 1 deletion lib/tools/system-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ systemCallMethods.adbExec = async function (cmd, opts = {}) {
// setting default timeout for each command to prevent infinite wait.
opts.timeout = opts.timeout || DEFAULT_ADB_EXEC_TIMEOUT;
let execFunc = async () => {
let linkerWarningRe = /^WARNING: linker.+$/m;
try {
if (!(cmd instanceof Array)) {
cmd = [cmd];
Expand All @@ -175,7 +176,6 @@ systemCallMethods.adbExec = async function (cmd, opts = {}) {
let {stdout} = await exec(this.executable.path, args, opts);
// sometimes ADB prints out stupid stdout warnings that we don't want
// to include in any of the response data, so let's strip it out
let linkerWarningRe = /^WARNING: linker.+$/m;
stdout = stdout.replace(linkerWarningRe, '').trim();
return stdout;
} catch (e) {
Expand All @@ -186,6 +186,14 @@ systemCallMethods.adbExec = async function (cmd, opts = {}) {
await sleep(1000);
await this.getDevicesWithRetry();
}
if (e.stderr) {
return e.stderr;
}
if (e.stdout) {
let stdout = e.stdout;
stdout = stdout.replace(linkerWarningRe, '').trim();
return stdout;
}
throw new Error(`Error executing adbExec. Original error: ${e.message}` +
JSON.stringify(e));
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/adb-commands-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ describe('adb commands', () => {
describe('getPIDsByName', withMocks({adb}, (mocks) => {
it('should call shell and parse pids correctly', async () => {
mocks.adb.expects("shell")
.once().withExactArgs(["ps", '.contactmanager'])
.once().withExactArgs(["set `ps | grep '.contactmanager'`;echo $2"])
.returns(psOutput);
(await adb.getPIDsByName(contactManagerPackage))[0].should.equal(5078);
mocks.adb.verify();
Expand Down

0 comments on commit 16a71ff

Please sign in to comment.