diff --git a/README.md b/README.md index c0f1c5605..de71f3763 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ jobs: | `longpress-timeout` | Optional | 500 | Longpress timeout in milliseconds. | | `enable-hw-keyboard` | Optional | `false` | Whether to enable the hw keyboard and disable soft keyboard - `true` or `false`. | | `enable-logcat` | Optional | `false` | Whether to read and save logcat output to `artifacts/logcat.log` | +| `print-config-ini` | Optional | `false` | Whether to print `config.ini` and `hardware-qemu.ini` upon emulator start. | | `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. | | `ndk` | Optional | N/A | Version of NDK to install - e.g. `21.0.6113669` | diff --git a/action.yml b/action.yml index 6de143526..6260a5ac4 100644 --- a/action.yml +++ b/action.yml @@ -48,6 +48,9 @@ inputs: enable-logcat: description: Enable reading and saving logcat output to `artifacts/logcat.log`. default: 'false' + print-config-ini: + description: Print config.ini and harware-qemu.ini + 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' working-directory: diff --git a/lib/emulator-manager.js b/lib/emulator-manager.js index 29a775079..52ed0f167 100644 --- a/lib/emulator-manager.js +++ b/lib/emulator-manager.js @@ -35,7 +35,7 @@ let ENABLE_LOGCAT = false; /** * Creates and launches a new AVD instance with the specified configurations. */ -function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, vmHeapSize, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellChecker, disableAutofill, longPressTimeout, enableHwKeyboard, enableLogcat) { +function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, vmHeapSize, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellChecker, disableAutofill, longPressTimeout, enableHwKeyboard, enableLogcat, printConfigIni) { return __awaiter(this, void 0, void 0, function* () { // create a new AVD const profileOption = profile.trim() !== '' ? `--device '${profile}'` : ''; @@ -69,6 +69,11 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, vmHeapS } } }); + if (printConfigIni) { + // hardware-qemu.ini is generated after emulator is started + yield exec.exec(`sh -c \\"more ~/.android/avd/"${avdName}".avd"/config.ini`); + yield exec.exec(`sh -c \\"more ~/.android/avd/"${avdName}".avd"/hardware-qemu.ini`); + } // wait for emulator to complete booting yield waitForDevice(); yield exec.exec(`adb shell input keyevent 82`); diff --git a/lib/input-validator.js b/lib/input-validator.js index 768d3776f..ee4e701ad 100644 --- a/lib/input-validator.js +++ b/lib/input-validator.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkEmulatorBuild = exports.checkLongPressTimeout = exports.checkEnableLogcat = exports.checkEnableHwKeyboard = exports.checkDisableAutofill = exports.checkDisableSpellchecker = exports.checkDisableAnimations = exports.checkArch = exports.checkTarget = exports.checkApiLevel = exports.VALID_ARCHS = exports.VALID_TARGETS = exports.MIN_API_LEVEL = void 0; +exports.checkEmulatorBuild = exports.checkLongPressTimeout = exports.checkPrintConfigIni = exports.checkEnableLogcat = exports.checkEnableHwKeyboard = exports.checkDisableAutofill = exports.checkDisableSpellchecker = exports.checkDisableAnimations = exports.checkArch = exports.checkTarget = exports.checkApiLevel = exports.VALID_ARCHS = exports.VALID_TARGETS = exports.MIN_API_LEVEL = void 0; exports.MIN_API_LEVEL = 15; exports.VALID_TARGETS = ['default', 'google_apis', 'google_apis_playstore']; exports.VALID_ARCHS = ['x86', 'x86_64']; @@ -55,6 +55,12 @@ function checkEnableLogcat(enableLogcat) { } } exports.checkEnableLogcat = checkEnableLogcat; +function checkPrintConfigIni(printConfigIni) { + if (!isValidBoolean(printConfigIni)) { + throw new Error(`Input for input.print-config-ini should be either 'true' or 'false'.`); + } +} +exports.checkPrintConfigIni = checkPrintConfigIni; function checkLongPressTimeout(timeout) { if (isNaN(Number(timeout)) || !Number.isInteger(Number(timeout))) { throw new Error(`Unexpected longpress-timeout: '${timeout}'.`); diff --git a/lib/main.js b/lib/main.js index ac0c12fd4..0ea46f784 100644 --- a/lib/main.js +++ b/lib/main.js @@ -94,6 +94,10 @@ function run() { input_validator_1.checkEnableLogcat(enableLogcatInput); const enableLogcat = enableLogcatInput === 'true'; console.log(`enable logcat: ${enableLogcat}`); + const printConfigIniInput = core.getInput('print-config-ini'); + input_validator_1.checkPrintConfigIni(printConfigIniInput); + const printConfigIni = printConfigIniInput === 'true'; + console.log(`print config.ini: ${printConfigIni}`); // disable spellchecker const disableSpellcheckerInput = core.getInput('disable-spellchecker'); input_validator_1.checkDisableSpellchecker(disableSpellcheckerInput); @@ -144,7 +148,7 @@ function run() { // install SDK yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion); // launch an emulator - yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, ramSize, vmHeapSize, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker, disableAutofill, longPressTimeout, enableHwKeyboard, enableLogcat); + yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, ramSize, vmHeapSize, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker, disableAutofill, longPressTimeout, enableHwKeyboard, enableLogcat, printConfigIni); // 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 079a6c77c..f808aa28c 100644 --- a/src/emulator-manager.ts +++ b/src/emulator-manager.ts @@ -22,7 +22,8 @@ export async function launchEmulator( disableAutofill: boolean, longPressTimeout: number, enableHwKeyboard: boolean, - enableLogcat: boolean + enableLogcat: boolean, + printConfigIni: boolean ): Promise { // create a new AVD const profileOption = profile.trim() !== '' ? `--device '${profile}'` : ''; @@ -66,6 +67,12 @@ export async function launchEmulator( } }); + if (printConfigIni) { + // hardware-qemu.ini is generated after emulator is started + await exec.exec(`sh -c \\"more ~/.android/avd/"${avdName}".avd"/config.ini`); + await exec.exec(`sh -c \\"more ~/.android/avd/"${avdName}".avd"/hardware-qemu.ini`); + } + // wait for emulator to complete booting await waitForDevice(); await exec.exec(`adb shell input keyevent 82`); diff --git a/src/input-validator.ts b/src/input-validator.ts index 23045f026..9df1534b4 100644 --- a/src/input-validator.ts +++ b/src/input-validator.ts @@ -53,6 +53,12 @@ export function checkEnableLogcat(enableLogcat: string): void { } } +export function checkPrintConfigIni(printConfigIni: string): void { + if (!isValidBoolean(printConfigIni)) { + throw new Error(`Input for input.print-config-ini should be either 'true' or 'false'.`); + } +} + export function checkLongPressTimeout(timeout: string): void { if (isNaN(Number(timeout)) || !Number.isInteger(Number(timeout))) { throw new Error(`Unexpected longpress-timeout: '${timeout}'.`); diff --git a/src/main.ts b/src/main.ts index c349227ec..a8f2e7d9f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import { checkApiLevel, checkTarget, checkArch, + checkPrintConfigIni, checkDisableAnimations, checkEmulatorBuild, checkDisableSpellchecker, @@ -90,6 +91,11 @@ async function run() { const enableLogcat = enableLogcatInput === 'true'; console.log(`enable logcat: ${enableLogcat}`); + const printConfigIniInput = core.getInput('print-config-ini'); + checkPrintConfigIni(printConfigIniInput); + const printConfigIni = printConfigIniInput === 'true'; + console.log(`print config.ini: ${printConfigIni}`); + // disable spellchecker const disableSpellcheckerInput = core.getInput('disable-spellchecker'); checkDisableSpellchecker(disableSpellcheckerInput); @@ -165,7 +171,8 @@ async function run() { disableAutofill, longPressTimeout, enableHwKeyboard, - enableLogcat + enableLogcat, + printConfigIni ); // execute the custom script