@@ -35,7 +35,19 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
35
35
this . applicationManager = this . $injector . resolve ( applicationManagerPath . AndroidApplicationManager , { adb : this . adb , identifier : this . identifier } ) ;
36
36
this . fileSystem = this . $injector . resolve ( fileSystemPath . AndroidDeviceFileSystem , { adb : this . adb , identifier : this . identifier } ) ;
37
37
38
- let details : IAndroidDeviceDetails = this . getDeviceDetails ( ) . wait ( ) ;
38
+ let details : IAndroidDeviceDetails ;
39
+ try {
40
+ details = this . getDeviceDetails ( [ "getprop" ] ) . wait ( ) ;
41
+ } catch ( err ) {
42
+ this . $logger . trace ( `Error while calling getprop: ${ err . message } ` ) ;
43
+ }
44
+
45
+ if ( ! details || ! details . name ) {
46
+ // In older CLI versions we are calling cat /system/build.prop to get details.
47
+ // Keep this logic for compatibility and possibly for devices for which getprop is not working
48
+ details = this . getDeviceDetails ( [ "cat" , "/system/build.prop" ] ) . wait ( ) ;
49
+ }
50
+
39
51
this . deviceInfo = {
40
52
identifier : this . identifier ,
41
53
displayName : details . name ,
@@ -58,18 +70,22 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
58
70
this . $logcatHelper . start ( this . identifier ) ;
59
71
}
60
72
61
- private getDeviceDetails ( ) : IFuture < IAndroidDeviceDetails > {
73
+ private getDeviceDetails ( shellCommandArgs : string [ ] ) : IFuture < IAndroidDeviceDetails > {
62
74
return ( ( ) => {
63
- let details = this . adb . executeShellCommand ( [ "cat" , "/system/build.prop" ] ) . wait ( ) ;
75
+ let details = this . adb . executeShellCommand ( shellCommandArgs ) . wait ( ) ;
76
+
64
77
let parsedDetails : any = { } ;
65
78
details . split ( / \r ? \n | \r / ) . forEach ( ( value : any ) => {
66
- //sample line is "ro.build.version.release=4.4"
67
- let match = / (?: r o \. b u i l d \. v e r s i o n | r o \. p r o d u c t ) \. ( .+ ) = ( .+ ) / . exec ( value ) ;
79
+ // sample line is "ro.build.version.release=4.4" in /system/build.prop
80
+ // sample line from getprop is: [ro.build.version.release]: [6.0]
81
+ // NOTE: some props do not have value: [ro.build.version.base_os]: []
82
+ let match = / (?: \[ ? r o \. b u i l d \. v e r s i o n | r o \. p r o d u c t ) \. ( .+ ?) ] ? (?: \: | = ) (?: \s * ?\[ ) ? ( .* ?) ] ? $ / . exec ( value ) ;
68
83
if ( match ) {
69
84
parsedDetails [ match [ 1 ] ] = match [ 2 ] ;
70
85
}
71
86
} ) ;
72
87
88
+ this . $logger . trace ( parsedDetails ) ;
73
89
return parsedDetails ;
74
90
} ) . future < IAndroidDeviceDetails > ( ) ( ) ;
75
91
}
0 commit comments