Skip to content

Commit

Permalink
Add option to print config.ini and hardware-qemu.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
AfzalivE committed Feb 26, 2021
1 parent 5e12798 commit acde134
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion lib/emulator-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}'` : '';
Expand Down Expand Up @@ -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`);
Expand Down
8 changes: 7 additions & 1 deletion lib/input-validator.js
Original file line number Diff line number Diff line change
@@ -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'];
Expand Down Expand Up @@ -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}'.`);
Expand Down
6 changes: 5 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/emulator-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export async function launchEmulator(
disableAutofill: boolean,
longPressTimeout: number,
enableHwKeyboard: boolean,
enableLogcat: boolean
enableLogcat: boolean,
printConfigIni: boolean
): Promise<void> {
// create a new AVD
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
Expand Down Expand Up @@ -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`);
Expand Down
6 changes: 6 additions & 0 deletions src/input-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}'.`);
Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
checkApiLevel,
checkTarget,
checkArch,
checkPrintConfigIni,
checkDisableAnimations,
checkEmulatorBuild,
checkDisableSpellchecker,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -165,7 +171,8 @@ async function run() {
disableAutofill,
longPressTimeout,
enableHwKeyboard,
enableLogcat
enableLogcat,
printConfigIni
);

// execute the custom script
Expand Down

0 comments on commit acde134

Please sign in to comment.