@@ -187,7 +187,7 @@ export class AppiumDriver {
187187 try {
188188 const sessionIfno = await driver . init ( args . appiumCaps ) ;
189189 log ( sessionIfno , args . verbose ) ;
190- AppiumDriver . applyDeviceAdditionsSettings ( args , sessionIfno ) ;
190+ await AppiumDriver . applyDeviceAdditionsSettings ( driver , args , sessionIfno ) ;
191191
192192 hasStarted = true ;
193193 } catch ( error ) {
@@ -209,10 +209,15 @@ export class AppiumDriver {
209209 return new AppiumDriver ( driver , wd , webio , driverConfig , args ) ;
210210 }
211211
212- private static applyDeviceAdditionsSettings ( args : INsCapabilities , sessionIfno : any ) {
212+ private static async applyDeviceAdditionsSettings ( driver , args : INsCapabilities , sessionIfno : any ) {
213213 if ( ! args . device . config || ! args . device . config . density || ! args . device . config . offset ) {
214214 args . device . config = { } ;
215- const density : number = sessionIfno [ 1 ] . deviceScreenDensity / 100 ;
215+ let density : number = sessionIfno [ 1 ] . deviceScreenDensity / 100 ;
216+ console . log ( `Get density from appium session: ${ density } ` ) ;
217+ if ( ! density ) {
218+ density = await AppiumDriver . executeShellCommand ( driver , { command : "wm" , args : [ "density" ] } ) ;
219+ console . log ( `Device density recieved from adb shell command ${ density } ` ) ;
220+ }
216221 args . device . config [ 'density' ] = density ;
217222
218223 if ( args . appiumCaps . platformName . toLowerCase ( ) === "android" ) {
@@ -733,16 +738,17 @@ export class AppiumDriver {
733738 }
734739 }
735740
736- public async executeShellCommand ( commandAndargs : { command : string , "args" : Array < any > } ) {
737- const output = await this . _driver . execute ( "mobile: shell" , commandAndargs ) ;
741+ public static async executeShellCommand ( driver , commandAndargs : { command : string , "args" : Array < any > } ) {
742+ const output = await driver . execute ( "mobile: shell" , commandAndargs ) ;
738743 return output ;
739744 }
745+
740746 public async setDontKeepActivities ( value : boolean ) {
741747 if ( this . _args . isAndroid ) {
742748 const status = value ? 1 : 0 ;
743- const output = await this . executeShellCommand ( { command : "settings" , args : [ 'put' , 'global' , 'always_finish_activities' , status ] } ) ;
749+ const output = await AppiumDriver . executeShellCommand ( this . _driver , { command : "settings" , args : [ 'put' , 'global' , 'always_finish_activities' , status ] } ) ;
744750 //check if set
745- const check = await this . executeShellCommand ( { command : "settings" , args : [ 'get' , 'global' , 'always_finish_activities' ] } )
751+ const check = await AppiumDriver . executeShellCommand ( this . _driver , { command : "settings" , args : [ 'get' , 'global' , 'always_finish_activities' ] } )
746752 console . info ( `always_finish_activities: ${ check } ` )
747753 } else {
748754 // Do nothing for iOS ...
0 commit comments