Skip to content

Commit b70ae36

Browse files
authored
Throw error if DELETE_FAILED_DEVICE_POLICY_MANAGER is sent (#513)
Signed-off-by: Burak Demir <[email protected]>
1 parent 006b8b3 commit b70ae36

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/adb/command/host-transport/uninstall.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import Protocol from '../../protocol';
22
import Command from '../../command';
33
import Bluebird from 'bluebird';
44

5+
class UninstallError extends Error {
6+
constructor(message: string) {
7+
super(message);
8+
}
9+
}
510
export default class UninstallCommand extends Command<boolean> {
611
execute(pkg: string): Bluebird<boolean> {
712
this._send(`shell:pm uninstall ${pkg}`);
@@ -13,6 +18,9 @@ export default class UninstallCommand extends Command<boolean> {
1318
.then(function (match) {
1419
if (match[1] === 'Success') {
1520
return true;
21+
} else if (match[1].includes('DELETE_FAILED_DEVICE_POLICY_MANAGER')) {
22+
const reason = match[1];
23+
throw new UninstallError(`${pkg} could not be uninstalled [${reason}]`);
1624
} else {
1725
// Either way, the package was uninstalled or doesn't exist,
1826
// which is good enough for us.

test/adb/command/host-transport/uninstall.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ describe('UninstallCommand', function () {
3333
});
3434
return cmd.execute('foo');
3535
});
36+
it("should failed if command responds with 'Failure [DELETE_FAILED_DEVICE_POLICY_MANAGER]'", function (done) {
37+
const conn = new MockConnection();
38+
const cmd = new UninstallCommand(conn);
39+
conn.getSocket().on('write', function (chunk) {
40+
return expect(chunk.toString()).to.equal(Protocol.encodeData('shell:pm uninstall foo').toString());
41+
});
42+
setImmediate(function () {
43+
conn.getSocket().causeRead(Protocol.OKAY);
44+
conn.getSocket().causeRead('Failure [DELETE_FAILED_DEVICE_POLICY_MANAGER]\r\n');
45+
return conn.getSocket().causeEnd();
46+
});
47+
cmd.execute('foo').catch(function (err) {
48+
expect(err.message).includes('Failure [DELETE_FAILED_DEVICE_POLICY_MANAGER]');
49+
done();
50+
});
51+
});
3652
it("should succeed even if command responds with 'Failure' with info in standard format", function () {
3753
const conn = new MockConnection();
3854
const cmd = new UninstallCommand(conn);

0 commit comments

Comments
 (0)