@@ -8,13 +8,14 @@ import * as path from "path";
88import * as net from "net" ;
99
1010export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
11- private static BACKEND_PORT = 18182 ;
1211 private device : Mobile . IAndroidDevice ;
12+ private port : number ;
1313
1414 constructor ( _device : Mobile . IDevice ,
1515 private $mobileHelper : Mobile . IMobileHelper ,
1616 private $devicePathProvider : IDevicePathProvider ,
1717 private $injector : IInjector ,
18+ private $androidProcessService : Mobile . IAndroidProcessService ,
1819 protected $platformsData : IPlatformsData ) {
1920 super ( $platformsData ) ;
2021 this . device = < Mobile . IAndroidDevice > ( _device ) ;
@@ -85,7 +86,13 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
8586 }
8687
8788 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+ }
8996
9097 if ( await this . awaitRuntimeReloadSuccessMessage ( ) ) {
9198 await this . cleanLivesyncDirectories ( deviceAppData ) ;
@@ -121,10 +128,11 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
121128 let isResolved = false ;
122129 const socket = new net . Socket ( ) ;
123130
124- socket . connect ( AndroidDeviceLiveSyncService . BACKEND_PORT , '127.0.0.1' , ( ) => {
131+ socket . connect ( this . port , '127.0.0.1' , ( ) => {
125132 socket . write ( new Buffer ( [ 0 , 0 , 0 , 1 , 1 ] ) ) ;
126133 } ) ;
127134 socket . on ( "data" , ( data : any ) => {
135+ isResolved = true ;
128136 socket . destroy ( ) ;
129137 resolve ( true ) ;
130138 } ) ;
0 commit comments