diff --git a/README.md b/README.md index 325e58ee6..283afd647 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ jobs: | `disable-spellchecker` | Optional | `false` | Whether to disable spellchecker - `true` or `false`. | | `disable-linux-hw-accel` | Optional | `auto` | Whether to disable hardware acceleration on Linux machines - `true`, `false` or `auto`.| | `enable-hw-keyboard` | Optional | `false` | Whether to enable hardware keyboard - `true` or `false`. | +| `after-boot-delay` | Optional | `false` | Additional delay (seconds) to let the device continue booting before starting to use it. - e.g. `600`. | | `emulator-build` | Optional | N/A | Build number of a specific version of the emulator binary to use e.g. `6061023` for emulator v29.3.0.0. | | `working-directory` | Optional | `./` | A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository. Will be used for `script` & `pre-emulator-launch-script`. | | `ndk` | Optional | N/A | Version of NDK to install - e.g. `21.0.6113669` | diff --git a/action-types.yml b/action-types.yml index 1c1d4617c..62cc61e0d 100644 --- a/action-types.yml +++ b/action-types.yml @@ -45,6 +45,8 @@ inputs: type: string enable-hw-keyboard: type: boolean + after-boot-delay: + type: integer emulator-build: type: string working-directory: diff --git a/action.yml b/action.yml index 13ba8e368..c7364cd75 100644 --- a/action.yml +++ b/action.yml @@ -50,6 +50,8 @@ inputs: default: 'false' emulator-build: description: 'build number of a specific version of the emulator binary to use - e.g. `6061023` for emulator v29.3.0.0' + after-boot-delay: + description: 'Additional delay (seconds) to let the device continue booting before starting to use it.' working-directory: description: 'A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository' ndk: diff --git a/lib/emulator-manager.js b/lib/emulator-manager.js index c0fa07c79..2cb7c4815 100644 --- a/lib/emulator-manager.js +++ b/lib/emulator-manager.js @@ -39,7 +39,7 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600; /** * Creates and launches a new AVD instance with the specified configurations. */ -function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) { +function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard, afterBootDelay) { return __awaiter(this, void 0, void 0, function* () { try { console.log(`::group::Launch Emulator`); @@ -84,6 +84,12 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSiz }); // wait for emulator to complete booting yield waitForDevice(); + if (afterBootDelay) { + yield exec.exec(`date`); + // wait additional delay to let the device continue booting + yield delay(afterBootDelay * 1000); + yield exec.exec(`date`); + } yield exec.exec(`adb shell input keyevent 82`); if (disableAnimations) { console.log('Disabling animations.'); diff --git a/lib/main.js b/lib/main.js index a4fd8d3f3..75718daf6 100644 --- a/lib/main.js +++ b/lib/main.js @@ -126,6 +126,10 @@ function run() { (0, input_validator_1.checkEnableHardwareKeyboard)(enableHardwareKeyboardInput); const enableHardwareKeyboard = enableHardwareKeyboardInput === 'true'; console.log(`enable hardware keyboard: ${enableHardwareKeyboard}`); + // set afterBootDelay + const afterBootDelayInput = core.getInput('after-boot-delay'); + const afterBootDelay = Number(afterBootDelayInput); + console.log(`after boot delay: ${afterBootDelay}`); // emulator build const emulatorBuildInput = core.getInput('emulator-build'); if (emulatorBuildInput) { @@ -191,7 +195,7 @@ function run() { console.log(`::endgroup::`); } // launch an emulator - yield (0, emulator_manager_1.launchEmulator)(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard); + yield (0, emulator_manager_1.launchEmulator)(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard, afterBootDelay); // execute the custom script try { // move to custom working directory if set diff --git a/src/emulator-manager.ts b/src/emulator-manager.ts index 5fca23e82..b4e44db80 100644 --- a/src/emulator-manager.ts +++ b/src/emulator-manager.ts @@ -22,7 +22,8 @@ export async function launchEmulator( disableAnimations: boolean, disableSpellChecker: boolean, disableLinuxHardwareAcceleration: boolean, - enableHardwareKeyboard: boolean + enableHardwareKeyboard: boolean, + afterBootDelay: number ): Promise { try { console.log(`::group::Launch Emulator`); @@ -78,6 +79,12 @@ export async function launchEmulator( // wait for emulator to complete booting await waitForDevice(); + + if (afterBootDelay) { + // wait additional delay to let the device continue booting + await delay(afterBootDelay * 1000); + } + await exec.exec(`adb shell input keyevent 82`); if (disableAnimations) { diff --git a/src/main.ts b/src/main.ts index 48827a912..8202a06d9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -121,6 +121,11 @@ async function run() { const enableHardwareKeyboard = enableHardwareKeyboardInput === 'true'; console.log(`enable hardware keyboard: ${enableHardwareKeyboard}`); + // set afterBootDelay + const afterBootDelayInput = core.getInput('after-boot-delay'); + const afterBootDelay = Number(afterBootDelayInput); + console.log(`after boot delay: ${afterBootDelay}`); + // emulator build const emulatorBuildInput = core.getInput('emulator-build'); if (emulatorBuildInput) { @@ -210,7 +215,8 @@ async function run() { disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, - enableHardwareKeyboard + enableHardwareKeyboard, + afterBootDelay ); // execute the custom script