File tree Expand file tree Collapse file tree 6 files changed +77
-1
lines changed
Expand file tree Collapse file tree 6 files changed +77
-1
lines changed Original file line number Diff line number Diff line change @@ -951,6 +951,22 @@ Waits until ADB can see the device. Note that you must know the serial in advanc
951951- Returns: ` Promise `
952952- Resolves with: ` id ` (see callback)
953953
954+ #### device.attach():
955+ Reattaches ADB to the device's ADB USB interface. This re-enables communication between ADB and device, reversing ` client.detach() ` .
956+
957+ - ** callback(err)** Optional. Use this or the returned ` Promise ` .
958+ - ** err** ` null ` if the device device was reattached successfully, ` Error ` otherwise (can occur if the device is not detached).
959+ - Returns: ` Promise `
960+ - Resolves with: ` true `
961+
962+ #### device.detach():
963+ Detaches ADB's USB interface from ADB. This releases the device from ADB control, allowing other processes to use it.
964+
965+ - ** callback(err)** Optional. Use this or the returned ` Promise ` .
966+ - ** err** ` null ` if the device device was detached successfully, ` Error ` otherwise (can occur if the device is not attached).
967+ - Returns: ` Promise `
968+ - Resolves with: ` true `
969+
954970### Sync
955971
956972#### sync.end()
Original file line number Diff line number Diff line change 11export default interface Device {
22 id : string ;
3- type : 'emulator' | 'device' | 'offline' | 'unauthorized' ;
3+ type : 'emulator' | 'device' | 'offline' | 'unauthorized' | 'unknown' ;
44}
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ import {
3636 WaitBootCompleteCommand ,
3737} from './command/host-transport' ;
3838import {
39+ AttachCommand ,
40+ DetachCommand ,
3941 ForwardCommand ,
4042 GetDevicePathCommand ,
4143 GetSerialNoCommand ,
@@ -603,4 +605,22 @@ export default class DeviceClient {
603605 public waitForDevice ( ) : Bluebird < string > {
604606 return this . connection ( ) . then ( ( conn ) => new WaitForDeviceCommand ( conn ) . execute ( this . serial ) ) ;
605607 }
608+
609+ /**
610+ * Reattaches ADB to the device's ADB USB interface. This re-enables communication between ADB and device, reversing `client.detach()`.
611+ *
612+ * @returns true
613+ */
614+ public attach ( ) : Bluebird < boolean > {
615+ return this . connection ( ) . then ( ( conn ) => new AttachCommand ( conn ) . execute ( this . serial ) ) ;
616+ }
617+
618+ /**
619+ * Detaches ADB's USB interface from ADB. This releases the device from ADB control, allowing other processes to use it.
620+ *
621+ * @returns true
622+ */
623+ public detach ( ) : Bluebird < boolean > {
624+ return this . connection ( ) . then ( ( conn ) => new DetachCommand ( conn ) . execute ( this . serial ) ) ;
625+ }
606626}
Original file line number Diff line number Diff line change 1+ import Command from '../../command' ;
2+ import Protocol from '../../protocol' ;
3+ import Bluebird from 'bluebird' ;
4+
5+ export default class AttachCommand extends Command < boolean > {
6+ execute ( serial : string ) : Bluebird < boolean > {
7+ this . _send ( `host-serial:${ serial } :attach` ) ;
8+ return this . parser . readAscii ( 4 ) . then ( ( reply ) => {
9+ switch ( reply ) {
10+ case Protocol . OKAY :
11+ return true ;
12+ case Protocol . FAIL :
13+ return this . parser . readError ( ) ;
14+ default :
15+ return this . parser . unexpected ( reply , 'OKAY or FAIL' ) ;
16+ }
17+ } ) ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ import Command from '../../command' ;
2+ import Protocol from '../../protocol' ;
3+ import Bluebird from 'bluebird' ;
4+
5+ export default class DetachCommand extends Command < boolean > {
6+ execute ( serial : string ) : Bluebird < boolean > {
7+ this . _send ( `host-serial:${ serial } :detach` ) ;
8+ return this . parser . readAscii ( 4 ) . then ( ( reply ) => {
9+ switch ( reply ) {
10+ case Protocol . OKAY :
11+ return true ;
12+ case Protocol . FAIL :
13+ return this . parser . readError ( ) ;
14+ default :
15+ return this . parser . unexpected ( reply , 'OKAY or FAIL' ) ;
16+ }
17+ } ) ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ export { default as AttachCommand } from './attach' ;
2+ export { default as DetachCommand } from './detach' ;
13export { default as ForwardCommand } from './forward' ;
24export { default as GetDevicePathCommand } from './getdevicepath' ;
35export { default as GetSerialNoCommand } from './getdevicepath' ;
You can’t perform that action at this time.
0 commit comments