File tree 6 files changed +77
-1
lines changed
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
951
951
- Returns: ` Promise `
952
952
- Resolves with: ` id ` (see callback)
953
953
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
+
954
970
### Sync
955
971
956
972
#### sync.end()
Original file line number Diff line number Diff line change 1
1
export default interface Device {
2
2
id : string ;
3
- type : 'emulator' | 'device' | 'offline' | 'unauthorized' ;
3
+ type : 'emulator' | 'device' | 'offline' | 'unauthorized' | 'unknown' ;
4
4
}
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ import {
36
36
WaitBootCompleteCommand ,
37
37
} from './command/host-transport' ;
38
38
import {
39
+ AttachCommand ,
40
+ DetachCommand ,
39
41
ForwardCommand ,
40
42
GetDevicePathCommand ,
41
43
GetSerialNoCommand ,
@@ -603,4 +605,22 @@ export default class DeviceClient {
603
605
public waitForDevice ( ) : Bluebird < string > {
604
606
return this . connection ( ) . then ( ( conn ) => new WaitForDeviceCommand ( conn ) . execute ( this . serial ) ) ;
605
607
}
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
+ }
606
626
}
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' ;
1
3
export { default as ForwardCommand } from './forward' ;
2
4
export { default as GetDevicePathCommand } from './getdevicepath' ;
3
5
export { default as GetSerialNoCommand } from './getdevicepath' ;
You can’t perform that action at this time.
0 commit comments