@@ -15,175 +15,165 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
1515} ) : function ( o , v ) {
1616 o [ "default" ] = v ;
1717} ) ;
18- var __importStar = ( this && this . __importStar ) || function ( mod ) {
19- if ( mod && mod . __esModule ) return mod ;
20- var result = { } ;
21- if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) __createBinding ( result , mod , k ) ;
22- __setModuleDefault ( result , mod ) ;
23- return result ;
24- } ;
25- var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
26- function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
27- return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
28- function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
29- function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
30- function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
31- step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
32- } ) ;
33- } ;
18+ var __importStar = ( this && this . __importStar ) || ( function ( ) {
19+ var ownKeys = function ( o ) {
20+ ownKeys = Object . getOwnPropertyNames || function ( o ) {
21+ var ar = [ ] ;
22+ for ( var k in o ) if ( Object . prototype . hasOwnProperty . call ( o , k ) ) ar [ ar . length ] = k ;
23+ return ar ;
24+ } ;
25+ return ownKeys ( o ) ;
26+ } ;
27+ return function ( mod ) {
28+ if ( mod && mod . __esModule ) return mod ;
29+ var result = { } ;
30+ if ( mod != null ) for ( var k = ownKeys ( mod ) , i = 0 ; i < k . length ; i ++ ) if ( k [ i ] !== "default" ) __createBinding ( result , mod , k [ i ] ) ;
31+ __setModuleDefault ( result , mod ) ;
32+ return result ;
33+ } ;
34+ } ) ( ) ;
3435Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
35- exports . killEmulator = exports . launchEmulator = exports . createAvd = void 0 ;
36+ exports . createAvd = createAvd ;
37+ exports . launchEmulator = launchEmulator ;
38+ exports . killEmulator = killEmulator ;
3639const exec = __importStar ( require ( "@actions/exec" ) ) ;
3740const fs = __importStar ( require ( "fs" ) ) ;
3841/**
3942 * Creates a new AVD instance with the specified configurations.
4043 */
41- function createAvd ( arch , avdName , cores , diskSize , enableHardwareKeyboard , forceAvdCreation , heapSize , profile , ramSize , sdcardPathOrSize , systemImageApiLevel , target ) {
42- return __awaiter ( this , void 0 , void 0 , function * ( ) {
43- try {
44- console . log ( `::group::Create AVD` ) ;
45- // create a new AVD if AVD directory does not already exist or forceAvdCreation is true
46- const avdPath = `${ process . env . ANDROID_AVD_HOME } /${ avdName } .avd` ;
47- if ( ! fs . existsSync ( avdPath ) || forceAvdCreation ) {
48- const profileOption = profile . trim ( ) !== '' ? `--device '${ profile } '` : '' ;
49- const sdcardPathOrSizeOption = sdcardPathOrSize . trim ( ) !== '' ? `--sdcard '${ sdcardPathOrSize } '` : '' ;
50- console . log ( `Creating AVD.` ) ;
51- yield exec . exec ( `sh -c \\"echo no | avdmanager create avd --force -n "${ avdName } " --package 'system-images;android-${ systemImageApiLevel } ;${ target } ;${ arch } ' ${ profileOption } ${ sdcardPathOrSizeOption } "` ) ;
44+ async function createAvd ( arch , avdName , cores , diskSize , enableHardwareKeyboard , forceAvdCreation , heapSize , profile , ramSize , sdcardPathOrSize , systemImageApiLevel , target ) {
45+ try {
46+ console . log ( `::group::Create AVD` ) ;
47+ // create a new AVD if AVD directory does not already exist or forceAvdCreation is true
48+ const avdPath = `${ process . env . ANDROID_AVD_HOME } /${ avdName } .avd` ;
49+ if ( ! fs . existsSync ( avdPath ) || forceAvdCreation ) {
50+ const profileOption = profile . trim ( ) !== '' ? `--device '${ profile } '` : '' ;
51+ const sdcardPathOrSizeOption = sdcardPathOrSize . trim ( ) !== '' ? `--sdcard '${ sdcardPathOrSize } '` : '' ;
52+ console . log ( `Creating AVD.` ) ;
53+ await exec . exec ( `sh -c \\"echo no | avdmanager create avd --force -n "${ avdName } " --package 'system-images;android-${ systemImageApiLevel } ;${ target } ;${ arch } ' ${ profileOption } ${ sdcardPathOrSizeOption } "` ) ;
54+ }
55+ if ( cores || ramSize || heapSize || enableHardwareKeyboard || diskSize ) {
56+ const configEntries = [ ] ;
57+ if ( cores ) {
58+ configEntries . push ( `hw.cpu.ncore=${ cores } ` ) ;
5259 }
53- if ( cores || ramSize || heapSize || enableHardwareKeyboard || diskSize ) {
54- const configEntries = [ ] ;
55- if ( cores ) {
56- configEntries . push ( `hw.cpu.ncore=${ cores } ` ) ;
57- }
58- if ( ramSize ) {
59- configEntries . push ( `hw.ramSize=${ ramSize } ` ) ;
60- }
61- if ( heapSize ) {
62- configEntries . push ( `hw.heapSize=${ heapSize } ` ) ;
63- }
64- if ( enableHardwareKeyboard ) {
65- configEntries . push ( 'hw.keyboard=yes' ) ;
66- }
67- if ( diskSize ) {
68- configEntries . push ( `disk.dataPartition.size=${ diskSize } ` ) ;
69- }
70- if ( configEntries . length > 0 ) {
71- const configContent = configEntries . join ( '\\n' ) + '\\n' ;
72- yield exec . exec ( `sh -c \\"printf '${ configContent } ' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini"` ) ;
73- }
60+ if ( ramSize ) {
61+ configEntries . push ( `hw.ramSize=${ ramSize } ` ) ;
62+ }
63+ if ( heapSize ) {
64+ configEntries . push ( `hw.heapSize=${ heapSize } ` ) ;
65+ }
66+ if ( enableHardwareKeyboard ) {
67+ configEntries . push ( 'hw.keyboard=yes' ) ;
68+ }
69+ if ( diskSize ) {
70+ configEntries . push ( `disk.dataPartition.size=${ diskSize } ` ) ;
71+ }
72+ if ( configEntries . length > 0 ) {
73+ const configContent = configEntries . join ( '\\n' ) + '\\n' ;
74+ await exec . exec ( `sh -c \\"printf '${ configContent } ' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini"` ) ;
7475 }
7576 }
76- finally {
77- console . log ( `::endgroup::` ) ;
78- }
79- } ) ;
77+ }
78+ finally {
79+ console . log ( `::endgroup::` ) ;
80+ }
8081}
81- exports . createAvd = createAvd ;
8282/**
8383 * Launches an existing AVD instance with the specified configurations.
8484 */
85- function launchEmulator ( avdName , disableAnimations , disableLinuxHardwareAcceleration , disableSpellChecker , emulatorBootTimeout , emulatorOptions , enableHardwareKeyboard , port ) {
86- return __awaiter ( this , void 0 , void 0 , function * ( ) {
87- try {
88- console . log ( `::group::Launch Emulator` ) ;
89- // turn off hardware acceleration on Linux
90- if ( process . platform === 'linux' && disableLinuxHardwareAcceleration ) {
91- console . log ( 'Disabling Linux hardware acceleration.' ) ;
92- emulatorOptions += ' -accel off' ;
93- }
94- // start emulator
95- console . log ( 'Starting emulator.' ) ;
96- yield exec . exec ( `sh -c \\"${ process . env . ANDROID_HOME } /emulator/emulator -port ${ port } -avd "${ avdName } " ${ emulatorOptions } &"` , [ ] , {
97- listeners : {
98- stderr : ( data ) => {
99- if ( data . toString ( ) . includes ( 'invalid command-line parameter' ) ) {
100- throw new Error ( data . toString ( ) ) ;
101- }
102- } ,
85+ async function launchEmulator ( avdName , disableAnimations , disableLinuxHardwareAcceleration , disableSpellChecker , emulatorBootTimeout , emulatorOptions , enableHardwareKeyboard , port ) {
86+ try {
87+ console . log ( `::group::Launch Emulator` ) ;
88+ // turn off hardware acceleration on Linux
89+ if ( process . platform === 'linux' && disableLinuxHardwareAcceleration ) {
90+ console . log ( 'Disabling Linux hardware acceleration.' ) ;
91+ emulatorOptions += ' -accel off' ;
92+ }
93+ // start emulator
94+ console . log ( 'Starting emulator.' ) ;
95+ await exec . exec ( `sh -c \\"${ process . env . ANDROID_HOME } /emulator/emulator -port ${ port } -avd "${ avdName } " ${ emulatorOptions } &"` , [ ] , {
96+ listeners : {
97+ stderr : ( data ) => {
98+ if ( data . toString ( ) . includes ( 'invalid command-line parameter' ) ) {
99+ throw new Error ( data . toString ( ) ) ;
100+ }
103101 } ,
104- } ) ;
105- // wait for emulator to complete booting
106- yield waitForDevice ( port , emulatorBootTimeout ) ;
107- yield adb ( port , `shell input keyevent 82` ) ;
108- if ( disableAnimations ) {
109- console . log ( 'Disabling animations.' ) ;
110- yield adb ( port , `shell settings put global window_animation_scale 0.0` ) ;
111- yield adb ( port , `shell settings put global transition_animation_scale 0.0` ) ;
112- yield adb ( port , `shell settings put global animator_duration_scale 0.0` ) ;
113- }
114- if ( disableSpellChecker ) {
115- yield adb ( port , `shell settings put secure spell_checker_enabled 0` ) ;
116- }
117- if ( enableHardwareKeyboard ) {
118- yield adb ( port , `shell settings put secure show_ime_with_hard_keyboard 0` ) ;
119- }
102+ } ,
103+ } ) ;
104+ // wait for emulator to complete booting
105+ await waitForDevice ( port , emulatorBootTimeout ) ;
106+ await adb ( port , `shell input keyevent 82` ) ;
107+ if ( disableAnimations ) {
108+ console . log ( 'Disabling animations.' ) ;
109+ await adb ( port , `shell settings put global window_animation_scale 0.0` ) ;
110+ await adb ( port , `shell settings put global transition_animation_scale 0.0` ) ;
111+ await adb ( port , `shell settings put global animator_duration_scale 0.0` ) ;
112+ }
113+ if ( disableSpellChecker ) {
114+ await adb ( port , `shell settings put secure spell_checker_enabled 0` ) ;
120115 }
121- finally {
122- console . log ( `::endgroup:: `) ;
116+ if ( enableHardwareKeyboard ) {
117+ await adb ( port , `shell settings put secure show_ime_with_hard_keyboard 0 `) ;
123118 }
124- } ) ;
119+ }
120+ finally {
121+ console . log ( `::endgroup::` ) ;
122+ }
125123}
126- exports . launchEmulator = launchEmulator ;
127124/**
128125 * Kills the running emulator on the default port.
129126 */
130- function killEmulator ( port ) {
131- return __awaiter ( this , void 0 , void 0 , function * ( ) {
132- try {
133- console . log ( `::group::Terminate Emulator` ) ;
134- yield adb ( port , `emu kill` ) ;
135- }
136- catch ( error ) {
137- console . log ( error instanceof Error ? error . message : error ) ;
138- }
139- finally {
140- console . log ( `::endgroup::` ) ;
141- }
142- } ) ;
127+ async function killEmulator ( port ) {
128+ try {
129+ console . log ( `::group::Terminate Emulator` ) ;
130+ await adb ( port , `emu kill` ) ;
131+ }
132+ catch ( error ) {
133+ console . log ( error instanceof Error ? error . message : error ) ;
134+ }
135+ finally {
136+ console . log ( `::endgroup::` ) ;
137+ }
143138}
144- exports . killEmulator = killEmulator ;
145- function adb ( port , command ) {
146- return __awaiter ( this , void 0 , void 0 , function * ( ) {
147- return yield exec . exec ( `adb -s emulator-${ port } ${ command } ` ) ;
148- } ) ;
139+ async function adb ( port , command ) {
140+ return await exec . exec ( `adb -s emulator-${ port } ${ command } ` ) ;
149141}
150142/**
151143 * Wait for emulator to boot.
152144 */
153- function waitForDevice ( port , emulatorBootTimeout ) {
154- return __awaiter ( this , void 0 , void 0 , function * ( ) {
155- let booted = false ;
156- let attempts = 0 ;
157- const retryInterval = 2 ; // retry every 2 seconds
158- const maxAttempts = emulatorBootTimeout / 2 ;
159- while ( ! booted ) {
160- try {
161- let result = '' ;
162- yield exec . exec ( `adb -s emulator-${ port } shell getprop sys.boot_completed` , [ ] , {
163- listeners : {
164- stdout : ( data ) => {
165- result += data . toString ( ) ;
166- } ,
145+ async function waitForDevice ( port , emulatorBootTimeout ) {
146+ let booted = false ;
147+ let attempts = 0 ;
148+ const retryInterval = 2 ; // retry every 2 seconds
149+ const maxAttempts = emulatorBootTimeout / 2 ;
150+ while ( ! booted ) {
151+ try {
152+ let result = '' ;
153+ await exec . exec ( `adb -s emulator-${ port } shell getprop sys.boot_completed` , [ ] , {
154+ listeners : {
155+ stdout : ( data ) => {
156+ result += data . toString ( ) ;
167157 } ,
168- } ) ;
169- if ( result . trim ( ) === '1' ) {
170- console . log ( 'Emulator booted.' ) ;
171- booted = true ;
172- break ;
173- }
174- }
175- catch ( error ) {
176- console . warn ( error instanceof Error ? error . message : error ) ;
177- }
178- if ( attempts < maxAttempts ) {
179- yield delay ( retryInterval * 1000 ) ;
180- }
181- else {
182- throw new Error ( `Timeout waiting for emulator to boot.` ) ;
158+ } ,
159+ } ) ;
160+ if ( result . trim ( ) === '1' ) {
161+ console . log ( 'Emulator booted.' ) ;
162+ booted = true ;
163+ break ;
183164 }
184- attempts ++ ;
185165 }
186- } ) ;
166+ catch ( error ) {
167+ console . warn ( error instanceof Error ? error . message : error ) ;
168+ }
169+ if ( attempts < maxAttempts ) {
170+ await delay ( retryInterval * 1000 ) ;
171+ }
172+ else {
173+ throw new Error ( `Timeout waiting for emulator to boot.` ) ;
174+ }
175+ attempts ++ ;
176+ }
187177}
188178function delay ( ms ) {
189179 return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
0 commit comments