File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
src/adb/command/host-transport
test/adb/command/host-transport Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,11 @@ import Protocol from '../../protocol';
22import Command from '../../command' ;
33import Bluebird from 'bluebird' ;
44
5+ class UninstallError extends Error {
6+ constructor ( message : string ) {
7+ super ( message ) ;
8+ }
9+ }
510export 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.
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments