mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-08-31 17:49:33 +00:00
Add support for enabling hardware keyboard.
This commit is contained in:
@@ -155,6 +155,7 @@ jobs:
|
|||||||
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
|
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
|
||||||
| `disable-spellchecker` | Optional | `false` | Whether to disable spellchecker - `true` or `false`. |
|
| `disable-spellchecker` | Optional | `false` | Whether to disable spellchecker - `true` or `false`. |
|
||||||
| `disable-linux-hw-accel` | Optional | `true` | Whether to disable hardware acceleration on Linux machines - `true` or `false`. Note that this is true by default as Github-hosted Linux runners do not support hardware acceleration. |
|
| `disable-linux-hw-accel` | Optional | `true` | Whether to disable hardware acceleration on Linux machines - `true` or `false`. Note that this is true by default as Github-hosted Linux runners do not support hardware acceleration. |
|
||||||
|
| `enable-hw-keyboard` | Optional | `false` | Whether to enable hardware keyboard - `true` or `false`. |
|
||||||
| `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. |
|
| `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. |
|
| `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` |
|
| `ndk` | Optional | N/A | Version of NDK to install - e.g. `21.0.6113669` |
|
||||||
|
|||||||
@@ -227,6 +227,27 @@ describe('disable-linux-hw-accel validator tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('enable-hw-keyboard validator tests', () => {
|
||||||
|
it('Throws if enable-hw-keyboard is not a boolean', () => {
|
||||||
|
const func = () => {
|
||||||
|
validator.checkEnableHardwareKeyboard('yes');
|
||||||
|
};
|
||||||
|
expect(func).toThrowError(`Input for input.enable-hw-keyboard should be either 'true' or 'false'.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Validates successfully if enable-hardware-keyboard is either true or false', () => {
|
||||||
|
const func1 = () => {
|
||||||
|
validator.checkEnableHardwareKeyboard('true');
|
||||||
|
};
|
||||||
|
expect(func1).not.toThrow();
|
||||||
|
|
||||||
|
const func2 = () => {
|
||||||
|
validator.checkEnableHardwareKeyboard('false');
|
||||||
|
};
|
||||||
|
expect(func2).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('emulator-build validator tests', () => {
|
describe('emulator-build validator tests', () => {
|
||||||
it('Throws if emulator-build is not a number', () => {
|
it('Throws if emulator-build is not a number', () => {
|
||||||
const func = () => {
|
const func = () => {
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ inputs:
|
|||||||
disable-linux-hw-accel:
|
disable-linux-hw-accel:
|
||||||
description: 'whether to disable hardware acceleration on Linux machines - `true` or `false`'
|
description: 'whether to disable hardware acceleration on Linux machines - `true` or `false`'
|
||||||
default: 'true'
|
default: 'true'
|
||||||
|
enable-hw-keyboard:
|
||||||
|
description: 'whether to enable hardware keyboard - `true` or `false`.'
|
||||||
|
default: 'false'
|
||||||
emulator-build:
|
emulator-build:
|
||||||
description: 'build number of a specific version of the emulator binary to use - e.g. `6061023` for emulator v29.3.0.0'
|
description: 'build number of a specific version of the emulator binary to use - e.g. `6061023` for emulator v29.3.0.0'
|
||||||
working-directory:
|
working-directory:
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
|
|||||||
/**
|
/**
|
||||||
* Creates and launches a new AVD instance with the specified configurations.
|
* Creates and launches a new AVD instance with the specified configurations.
|
||||||
*/
|
*/
|
||||||
function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration) {
|
function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
|
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
|
||||||
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
|
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
|
||||||
@@ -51,6 +51,9 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardP
|
|||||||
if (ramSize) {
|
if (ramSize) {
|
||||||
yield exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
|
yield exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
|
||||||
}
|
}
|
||||||
|
if (enableHardwareKeyboard) {
|
||||||
|
yield exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
|
||||||
|
}
|
||||||
//turn off hardware acceleration on Linux
|
//turn off hardware acceleration on Linux
|
||||||
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
|
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
|
||||||
console.log('Disabling Linux hardware acceleration.');
|
console.log('Disabling Linux hardware acceleration.');
|
||||||
@@ -70,7 +73,6 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardP
|
|||||||
// wait for emulator to complete booting
|
// wait for emulator to complete booting
|
||||||
yield waitForDevice();
|
yield waitForDevice();
|
||||||
yield exec.exec(`adb shell input keyevent 82`);
|
yield exec.exec(`adb shell input keyevent 82`);
|
||||||
// disable animations
|
|
||||||
if (disableAnimations) {
|
if (disableAnimations) {
|
||||||
console.log('Disabling animations.');
|
console.log('Disabling animations.');
|
||||||
yield exec.exec(`adb shell settings put global window_animation_scale 0.0`);
|
yield exec.exec(`adb shell settings put global window_animation_scale 0.0`);
|
||||||
@@ -80,6 +82,9 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardP
|
|||||||
if (disableSpellChecker) {
|
if (disableSpellChecker) {
|
||||||
yield exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
|
yield exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
|
||||||
}
|
}
|
||||||
|
if (enableHardwareKeyboard) {
|
||||||
|
yield exec.exec(`adb shell settings put secure show_ime_with_hard_keyboard 0`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.launchEmulator = launchEmulator;
|
exports.launchEmulator = launchEmulator;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.checkEmulatorBuild = exports.checkDisableLinuxHardwareAcceleration = exports.checkDisableSpellchecker = exports.checkDisableAnimations = exports.checkForceAvdCreation = exports.checkChannel = exports.checkArch = exports.checkTarget = exports.checkApiLevel = exports.VALID_CHANNELS = exports.VALID_ARCHS = exports.VALID_TARGETS = exports.MIN_API_LEVEL = void 0;
|
exports.checkEmulatorBuild = exports.checkEnableHardwareKeyboard = exports.checkDisableLinuxHardwareAcceleration = exports.checkDisableSpellchecker = exports.checkDisableAnimations = exports.checkForceAvdCreation = exports.checkChannel = exports.checkArch = exports.checkTarget = exports.checkApiLevel = exports.VALID_CHANNELS = exports.VALID_ARCHS = exports.VALID_TARGETS = exports.MIN_API_LEVEL = void 0;
|
||||||
exports.MIN_API_LEVEL = 15;
|
exports.MIN_API_LEVEL = 15;
|
||||||
exports.VALID_TARGETS = ['default', 'google_apis', 'aosp_atd', 'google_atd', 'google_apis_playstore', 'android-wear', 'android-wear-cn', 'android-tv', 'google-tv'];
|
exports.VALID_TARGETS = ['default', 'google_apis', 'aosp_atd', 'google_atd', 'google_apis_playstore', 'android-wear', 'android-wear-cn', 'android-tv', 'google-tv'];
|
||||||
exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a'];
|
exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a'];
|
||||||
@@ -56,6 +56,12 @@ function checkDisableLinuxHardwareAcceleration(disableLinuxHardwareAcceleration)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.checkDisableLinuxHardwareAcceleration = checkDisableLinuxHardwareAcceleration;
|
exports.checkDisableLinuxHardwareAcceleration = checkDisableLinuxHardwareAcceleration;
|
||||||
|
function checkEnableHardwareKeyboard(enableHardwareKeyboard) {
|
||||||
|
if (!isValidBoolean(enableHardwareKeyboard)) {
|
||||||
|
throw new Error(`Input for input.enable-hw-keyboard should be either 'true' or 'false'.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.checkEnableHardwareKeyboard = checkEnableHardwareKeyboard;
|
||||||
function checkEmulatorBuild(emulatorBuild) {
|
function checkEmulatorBuild(emulatorBuild) {
|
||||||
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
|
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
|
||||||
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
|
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
|
||||||
|
|||||||
+6
-1
@@ -99,6 +99,11 @@ function run() {
|
|||||||
input_validator_1.checkDisableLinuxHardwareAcceleration(disableLinuxHardwareAccelerationInput);
|
input_validator_1.checkDisableLinuxHardwareAcceleration(disableLinuxHardwareAccelerationInput);
|
||||||
const disableLinuxHardwareAcceleration = disableLinuxHardwareAccelerationInput === 'true';
|
const disableLinuxHardwareAcceleration = disableLinuxHardwareAccelerationInput === 'true';
|
||||||
console.log(`disable Linux hardware acceleration: ${disableLinuxHardwareAcceleration}`);
|
console.log(`disable Linux hardware acceleration: ${disableLinuxHardwareAcceleration}`);
|
||||||
|
// enable hardware keyboard
|
||||||
|
const enableHardwareKeyboardInput = core.getInput('enable-hw-keyboard');
|
||||||
|
input_validator_1.checkEnableHardwareKeyboard(enableHardwareKeyboardInput);
|
||||||
|
const enableHardwareKeyboard = enableHardwareKeyboardInput === 'true';
|
||||||
|
console.log(`enable hardware keyboard: ${enableHardwareKeyboard}`);
|
||||||
// emulator build
|
// emulator build
|
||||||
const emulatorBuildInput = core.getInput('emulator-build');
|
const emulatorBuildInput = core.getInput('emulator-build');
|
||||||
if (emulatorBuildInput) {
|
if (emulatorBuildInput) {
|
||||||
@@ -139,7 +144,7 @@ function run() {
|
|||||||
// install SDK
|
// install SDK
|
||||||
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);
|
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);
|
||||||
// launch an emulator
|
// launch an emulator
|
||||||
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration);
|
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard);
|
||||||
// execute the custom script
|
// execute the custom script
|
||||||
try {
|
try {
|
||||||
// move to custom working directory if set
|
// move to custom working directory if set
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ export async function launchEmulator(
|
|||||||
emulatorOptions: string,
|
emulatorOptions: string,
|
||||||
disableAnimations: boolean,
|
disableAnimations: boolean,
|
||||||
disableSpellChecker: boolean,
|
disableSpellChecker: boolean,
|
||||||
disableLinuxHardwareAcceleration: boolean
|
disableLinuxHardwareAcceleration: boolean,
|
||||||
|
enableHardwareKeyboard: boolean
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
|
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
|
||||||
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
|
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
|
||||||
@@ -40,6 +41,10 @@ export async function launchEmulator(
|
|||||||
await exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
|
await exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enableHardwareKeyboard) {
|
||||||
|
await exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
|
||||||
|
}
|
||||||
|
|
||||||
//turn off hardware acceleration on Linux
|
//turn off hardware acceleration on Linux
|
||||||
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
|
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
|
||||||
console.log('Disabling Linux hardware acceleration.');
|
console.log('Disabling Linux hardware acceleration.');
|
||||||
@@ -63,7 +68,6 @@ export async function launchEmulator(
|
|||||||
await waitForDevice();
|
await waitForDevice();
|
||||||
await exec.exec(`adb shell input keyevent 82`);
|
await exec.exec(`adb shell input keyevent 82`);
|
||||||
|
|
||||||
// disable animations
|
|
||||||
if (disableAnimations) {
|
if (disableAnimations) {
|
||||||
console.log('Disabling animations.');
|
console.log('Disabling animations.');
|
||||||
await exec.exec(`adb shell settings put global window_animation_scale 0.0`);
|
await exec.exec(`adb shell settings put global window_animation_scale 0.0`);
|
||||||
@@ -73,6 +77,9 @@ export async function launchEmulator(
|
|||||||
if (disableSpellChecker) {
|
if (disableSpellChecker) {
|
||||||
await exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
|
await exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
|
||||||
}
|
}
|
||||||
|
if (enableHardwareKeyboard) {
|
||||||
|
await exec.exec(`adb shell settings put secure show_ime_with_hard_keyboard 0`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ export function checkDisableLinuxHardwareAcceleration(disableLinuxHardwareAccele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkEnableHardwareKeyboard(enableHardwareKeyboard: string): void {
|
||||||
|
if (!isValidBoolean(enableHardwareKeyboard)) {
|
||||||
|
throw new Error(`Input for input.enable-hw-keyboard should be either 'true' or 'false'.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function checkEmulatorBuild(emulatorBuild: string): void {
|
export function checkEmulatorBuild(emulatorBuild: string): void {
|
||||||
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
|
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
|
||||||
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
|
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
|
||||||
|
|||||||
+10
-2
@@ -9,7 +9,8 @@ import {
|
|||||||
checkDisableSpellchecker,
|
checkDisableSpellchecker,
|
||||||
checkDisableLinuxHardwareAcceleration,
|
checkDisableLinuxHardwareAcceleration,
|
||||||
checkForceAvdCreation,
|
checkForceAvdCreation,
|
||||||
checkChannel
|
checkChannel,
|
||||||
|
checkEnableHardwareKeyboard
|
||||||
} from './input-validator';
|
} from './input-validator';
|
||||||
import { launchEmulator, killEmulator } from './emulator-manager';
|
import { launchEmulator, killEmulator } from './emulator-manager';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
@@ -94,6 +95,12 @@ async function run() {
|
|||||||
const disableLinuxHardwareAcceleration = disableLinuxHardwareAccelerationInput === 'true';
|
const disableLinuxHardwareAcceleration = disableLinuxHardwareAccelerationInput === 'true';
|
||||||
console.log(`disable Linux hardware acceleration: ${disableLinuxHardwareAcceleration}`);
|
console.log(`disable Linux hardware acceleration: ${disableLinuxHardwareAcceleration}`);
|
||||||
|
|
||||||
|
// enable hardware keyboard
|
||||||
|
const enableHardwareKeyboardInput = core.getInput('enable-hw-keyboard');
|
||||||
|
checkEnableHardwareKeyboard(enableHardwareKeyboardInput);
|
||||||
|
const enableHardwareKeyboard = enableHardwareKeyboardInput === 'true';
|
||||||
|
console.log(`enable hardware keyboard: ${enableHardwareKeyboard}`);
|
||||||
|
|
||||||
// emulator build
|
// emulator build
|
||||||
const emulatorBuildInput = core.getInput('emulator-build');
|
const emulatorBuildInput = core.getInput('emulator-build');
|
||||||
if (emulatorBuildInput) {
|
if (emulatorBuildInput) {
|
||||||
@@ -154,7 +161,8 @@ async function run() {
|
|||||||
emulatorOptions,
|
emulatorOptions,
|
||||||
disableAnimations,
|
disableAnimations,
|
||||||
disableSpellchecker,
|
disableSpellchecker,
|
||||||
disableLinuxHardwareAcceleration
|
disableLinuxHardwareAcceleration,
|
||||||
|
enableHardwareKeyboard
|
||||||
);
|
);
|
||||||
|
|
||||||
// execute the custom script
|
// execute the custom script
|
||||||
|
|||||||
Reference in New Issue
Block a user