@@ -8,13 +8,14 @@ import * as path from "path";
8
8
import * as net from "net" ;
9
9
10
10
export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
11
- private static BACKEND_PORT = 18182 ;
12
11
private device : Mobile . IAndroidDevice ;
12
+ private port : number ;
13
13
14
14
constructor ( _device : Mobile . IDevice ,
15
15
private $mobileHelper : Mobile . IMobileHelper ,
16
16
private $devicePathProvider : IDevicePathProvider ,
17
17
private $injector : IInjector ,
18
+ private $androidProcessService : Mobile . IAndroidProcessService ,
18
19
protected $platformsData : IPlatformsData ) {
19
20
super ( $platformsData ) ;
20
21
this . device = < Mobile . IAndroidDevice > ( _device ) ;
@@ -85,7 +86,13 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
85
86
}
86
87
87
88
private async reloadApplicationFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : Promise < boolean > {
88
- await this . device . adb . executeCommand ( [ "forward" , `tcp:${ AndroidDeviceLiveSyncService . BACKEND_PORT . toString ( ) } ` , `localabstract:${ deviceAppData . appIdentifier } -livesync` ] ) ;
89
+ if ( ! this . port ) {
90
+ this . port = await this . $androidProcessService . forwardFreeTcpToAbstractPort ( {
91
+ deviceIdentifier : deviceAppData . device . deviceInfo . identifier ,
92
+ appIdentifier : deviceAppData . appIdentifier ,
93
+ abstractPort : `localabstract:${ deviceAppData . appIdentifier } -livesync`
94
+ } ) ;
95
+ }
89
96
90
97
if ( await this . awaitRuntimeReloadSuccessMessage ( ) ) {
91
98
await this . cleanLivesyncDirectories ( deviceAppData ) ;
@@ -121,10 +128,11 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
121
128
let isResolved = false ;
122
129
const socket = new net . Socket ( ) ;
123
130
124
- socket . connect ( AndroidDeviceLiveSyncService . BACKEND_PORT , '127.0.0.1' , ( ) => {
131
+ socket . connect ( this . port , '127.0.0.1' , ( ) => {
125
132
socket . write ( new Buffer ( [ 0 , 0 , 0 , 1 , 1 ] ) ) ;
126
133
} ) ;
127
134
socket . on ( "data" , ( data : any ) => {
135
+ isResolved = true ;
128
136
socket . destroy ( ) ;
129
137
resolve ( true ) ;
130
138
} ) ;
0 commit comments