@@ -14,6 +14,16 @@ const scope: PlatformRequestScope = {
1414 progress : { report : ( ) => undefined } ,
1515} ;
1616
17+ const RUNNING_EMULATOR_PROBES : ReadonlyArray < readonly [ string , string ] > = [
18+ [ 'ro.boot.qemu.avd_name' , 'Pixel_9_Pro_XL\n' ] ,
19+ [ 'sys.boot_completed' , '1\n' ] ,
20+ [ 'ro.product.model' , 'sdk_gphone16k_arm64\n' ] ,
21+ [ 'ro.build.version.release' , '17\n' ] ,
22+ [ 'ro.build.characteristics' , 'phone\n' ] ,
23+ [ 'has-feature' , 'false\n' ] ,
24+ [ 'pm\0list\0features' , '' ] ,
25+ ] ;
26+
1727test . each ( [
1828 [ 'include-stopped' , true ] ,
1929 [ 'running-only' , false ] ,
@@ -30,11 +40,8 @@ test.each([
3040 'List of devices attached\nemulator-5554 device model:Pixel_9_Pro_XL\nphysical-1 device model:Phone\n' ,
3141 ) ;
3242 }
33- if ( key . includes ( 'ro.boot.qemu.avd_name' ) ) return result ( 'Pixel_9_Pro_XL\n' ) ;
34- if ( key . includes ( 'sys.boot_completed' ) ) return result ( '1\n' ) ;
35- if ( key . includes ( 'ro.build.characteristics' ) ) return result ( 'phone\n' ) ;
36- if ( key . includes ( 'has-feature' ) ) return result ( 'false\n' ) ;
37- if ( key . includes ( 'pm\0list\0features' ) ) return result ( '' ) ;
43+ const probe = RUNNING_EMULATOR_PROBES . find ( ( [ fragment ] ) => key . includes ( fragment ) ) ;
44+ if ( probe ) return result ( probe [ 1 ] ) ;
3845 throw new Error ( `Unexpected command: ${ request . executable } ${ request . args . join ( ' ' ) } ` ) ;
3946 } ) ;
4047
@@ -44,17 +51,50 @@ test.each([
4451 ) ;
4552
4653 assert . deepEqual (
47- devices . map ( ( candidate ) => [ candidate . id , candidate . name , candidate . booted ] ) ,
54+ devices . map ( ( candidate ) => [
55+ candidate . id ,
56+ candidate . name ,
57+ candidate . booted ,
58+ candidate . model ,
59+ candidate . osVersion ,
60+ ] ) ,
4861 [
49- [ 'emulator-5554' , 'Pixel 9 Pro XL' , true ] ,
50- ...( includesStoppedAvd ? [ [ 'Living_Room_TV' , 'Living_Room_TV' , false ] as const ] : [ ] ) ,
62+ [ 'emulator-5554' , 'Pixel 9 Pro XL' , true , 'sdk_gphone16k_arm64' , '17' ] ,
63+ ...( includesStoppedAvd
64+ ? [ [ 'Living_Room_TV' , 'Living_Room_TV' , false , undefined , undefined ] as const ]
65+ : [ ] ) ,
5166 ] ,
5267 ) ;
5368 assert . ok ( calls . every ( ( call ) => call . timeoutMs === 10_000 ) ) ;
5469 assert . ok ( calls . every ( ( call ) => call . allowFailure === true ) ) ;
5570 } ,
5671) ;
5772
73+ test ( 'Android inventory leaves model and OS version unset when the getprop probe fails' , async ( ) => {
74+ const host = createHost ( async ( request ) => {
75+ const key = request . args . join ( '\0' ) ;
76+ if ( key === 'devices\0-l' )
77+ return result ( 'List of devices attached\nR5CT1 device model:SM_S921B\n' ) ;
78+ if ( key . includes ( 'ro.product.model' ) || key . includes ( 'ro.build.version.release' ) ) {
79+ return result ( '' , 'error: closed' , 1 ) ;
80+ }
81+ if ( key . includes ( 'sys.boot_completed' ) ) return result ( '1\n' ) ;
82+ if ( key . includes ( 'ro.build.characteristics' ) ) return result ( 'phone\n' ) ;
83+ if ( key . includes ( 'has-feature' ) ) return result ( 'false\n' ) ;
84+ if ( key . includes ( 'pm\0list\0features' ) ) return result ( '' ) ;
85+ throw new Error ( `Unexpected command: ${ request . executable } ${ request . args . join ( ' ' ) } ` ) ;
86+ } ) ;
87+
88+ const [ device ] = await createAndroidInventory ( host ) . discover (
89+ { androidAvdSelection : 'running-only' } ,
90+ scope ,
91+ ) ;
92+
93+ assert . equal ( device ?. name , 'SM S921B' ) ;
94+ assert . equal ( device ?. model , undefined ) ;
95+ assert . equal ( device ?. osVersion , undefined ) ;
96+ } ) ;
97+
5898test ( 'Android inventory fails closed when adb is unavailable' , async ( ) => {
5999 const host = createHost ( async ( ) => result ( '' ) , { adb : undefined } ) ;
60100 await assert . rejects (
0 commit comments