Skip to content

Commit 5bd7b4a

Browse files
committed
Add missing generated .js files.
1 parent 1e2ef72 commit 5bd7b4a

File tree

4 files changed

+125
-84
lines changed

4 files changed

+125
-84
lines changed

lib/emulator-manager.js

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,55 +35,64 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
3535
/**
3636
* Creates and launches a new AVD instance with the specified configurations.
3737
*/
38-
function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) {
38+
function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) {
3939
return __awaiter(this, void 0, void 0, function* () {
40-
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
41-
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
42-
if (!fs.existsSync(avdPath) || forceAvdCreation) {
43-
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
44-
const sdcardPathOrSizeOption = sdcardPathOrSize.trim() !== '' ? `--sdcard '${sdcardPathOrSize}'` : '';
45-
console.log(`Creating AVD.`);
46-
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}' ${profileOption} ${sdcardPathOrSizeOption}"`);
47-
}
48-
if (cores) {
49-
yield exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
50-
}
51-
if (ramSize) {
52-
yield exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
53-
}
54-
if (enableHardwareKeyboard) {
55-
yield exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
56-
}
57-
//turn off hardware acceleration on Linux
58-
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
59-
console.log('Disabling Linux hardware acceleration.');
60-
emulatorOptions += ' -accel off';
61-
}
62-
// start emulator
63-
console.log('Starting emulator.');
64-
yield exec.exec(`sh -c \\"${process.env.ANDROID_SDK_ROOT}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
65-
listeners: {
66-
stderr: (data) => {
67-
if (data.toString().includes('invalid command-line parameter')) {
68-
throw new Error(data.toString());
40+
try {
41+
console.log(`::group::Launch Emulator`);
42+
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
43+
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
44+
if (!fs.existsSync(avdPath) || forceAvdCreation) {
45+
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
46+
const sdcardPathOrSizeOption = sdcardPathOrSize.trim() !== '' ? `--sdcard '${sdcardPathOrSize}'` : '';
47+
console.log(`Creating AVD.`);
48+
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}' ${profileOption} ${sdcardPathOrSizeOption}"`);
49+
}
50+
if (cores) {
51+
yield exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
52+
}
53+
if (ramSize) {
54+
yield exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
55+
}
56+
if (enableHardwareKeyboard) {
57+
yield exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
58+
}
59+
if (diskSize) {
60+
yield exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
61+
}
62+
//turn off hardware acceleration on Linux
63+
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
64+
console.log('Disabling Linux hardware acceleration.');
65+
emulatorOptions += ' -accel off';
66+
}
67+
// start emulator
68+
console.log('Starting emulator.');
69+
yield exec.exec(`sh -c \\"${process.env.ANDROID_SDK_ROOT}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
70+
listeners: {
71+
stderr: (data) => {
72+
if (data.toString().includes('invalid command-line parameter')) {
73+
throw new Error(data.toString());
74+
}
6975
}
7076
}
77+
});
78+
// wait for emulator to complete booting
79+
yield waitForDevice();
80+
yield exec.exec(`adb shell input keyevent 82`);
81+
if (disableAnimations) {
82+
console.log('Disabling animations.');
83+
yield exec.exec(`adb shell settings put global window_animation_scale 0.0`);
84+
yield exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
85+
yield exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
86+
}
87+
if (disableSpellChecker) {
88+
yield exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
89+
}
90+
if (enableHardwareKeyboard) {
91+
yield exec.exec(`adb shell settings put secure show_ime_with_hard_keyboard 0`);
7192
}
72-
});
73-
// wait for emulator to complete booting
74-
yield waitForDevice();
75-
yield exec.exec(`adb shell input keyevent 82`);
76-
if (disableAnimations) {
77-
console.log('Disabling animations.');
78-
yield exec.exec(`adb shell settings put global window_animation_scale 0.0`);
79-
yield exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
80-
yield exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
81-
}
82-
if (disableSpellChecker) {
83-
yield exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
8493
}
85-
if (enableHardwareKeyboard) {
86-
yield exec.exec(`adb shell settings put secure show_ime_with_hard_keyboard 0`);
94+
finally {
95+
console.log(`::endgroup::`);
8796
}
8897
});
8998
}
@@ -94,11 +103,15 @@ exports.launchEmulator = launchEmulator;
94103
function killEmulator() {
95104
return __awaiter(this, void 0, void 0, function* () {
96105
try {
106+
console.log(`::group::Terminate Emulator`);
97107
yield exec.exec(`adb -s emulator-5554 emu kill`);
98108
}
99109
catch (error) {
100110
console.log(error.message);
101111
}
112+
finally {
113+
console.log(`::endgroup::`);
114+
}
102115
});
103116
}
104117
exports.killEmulator = killEmulator;

lib/input-validator.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
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;
3+
exports.checkDiskSize = 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;
44
exports.MIN_API_LEVEL = 15;
55
exports.VALID_TARGETS = ['default', 'google_apis', 'aosp_atd', 'google_atd', 'google_apis_playstore', 'android-wear', 'android-wear-cn', 'android-tv', 'google-tv'];
66
exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a'];
@@ -71,3 +71,20 @@ exports.checkEmulatorBuild = checkEmulatorBuild;
7171
function isValidBoolean(value) {
7272
return value === 'true' || value === 'false';
7373
}
74+
function checkDiskSize(diskSize) {
75+
// Disk size can be empty - the default value
76+
if (diskSize) {
77+
// Can also be number of bytes
78+
if (isNaN(Number(diskSize)) || !Number.isInteger(Number(diskSize))) {
79+
// Disk size can have a size multiplier at the end K, M or G
80+
const diskSizeUpperCase = diskSize.toUpperCase();
81+
if (diskSizeUpperCase.endsWith('K') || diskSizeUpperCase.endsWith('M') || diskSizeUpperCase.endsWith('G')) {
82+
const diskSizeNoModifier = diskSize.slice(0, -1);
83+
if (0 == diskSizeNoModifier.length || isNaN(Number(diskSizeNoModifier)) || !Number.isInteger(Number(diskSizeNoModifier))) {
84+
throw new Error(`Unexpected disk size: '${diskSize}'.`);
85+
}
86+
}
87+
}
88+
}
89+
}
90+
exports.checkDiskSize = checkDiskSize;

lib/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const channel_id_mapper_1 = require("./channel-id-mapper");
3838
function run() {
3939
return __awaiter(this, void 0, void 0, function* () {
4040
try {
41+
console.log(`::group::Configure emulator`);
4142
// only support running on macOS or Linux
4243
if (process.platform !== 'darwin') {
4344
if (process.platform === 'linux') {
@@ -73,6 +74,9 @@ function run() {
7374
// SD card path or size used for creating the AVD
7475
const sdcardPathOrSize = core.getInput('sdcard-path-or-size');
7576
console.log(`SD card path or size: ${sdcardPathOrSize}`);
77+
const diskSize = core.getInput('disk-size');
78+
input_validator_1.checkDiskSize(diskSize);
79+
console.log(`Disk size: ${diskSize}`);
7680
// custom name used for creating the AVD
7781
const avdName = core.getInput('avd-name');
7882
console.log(`AVD name: ${avdName}`);
@@ -141,10 +145,11 @@ function run() {
141145
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
142146
console.log(`${script}`);
143147
}));
148+
console.log(`::endgroup::`);
144149
// install SDK
145150
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);
146151
// launch an emulator
147-
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard);
152+
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, ramSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard);
148153
// execute the custom script
149154
try {
150155
// move to custom working directory if set

lib/sdk-installer.js

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,45 +43,51 @@ const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/comman
4343
*/
4444
function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion) {
4545
return __awaiter(this, void 0, void 0, function* () {
46-
const isOnMac = process.platform === 'darwin';
47-
if (!isOnMac) {
48-
yield exec.exec(`sh -c \\"sudo chown $USER:$USER ${process.env.ANDROID_SDK_ROOT} -R`);
46+
try {
47+
console.log(`::group::Install Android SDK`);
48+
const isOnMac = process.platform === 'darwin';
49+
if (!isOnMac) {
50+
yield exec.exec(`sh -c \\"sudo chown $USER:$USER ${process.env.ANDROID_SDK_ROOT} -R`);
51+
}
52+
const cmdlineToolsPath = `${process.env.ANDROID_SDK_ROOT}/cmdline-tools`;
53+
if (!fs.existsSync(cmdlineToolsPath)) {
54+
console.log('Installing new cmdline-tools.');
55+
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
56+
const downloadPath = yield tc.downloadTool(sdkUrl);
57+
yield tc.extractZip(downloadPath, cmdlineToolsPath);
58+
yield io.mv(`${cmdlineToolsPath}/cmdline-tools`, `${cmdlineToolsPath}/latest`);
59+
}
60+
// add paths for commandline-tools and platform-tools
61+
core.addPath(`${cmdlineToolsPath}/latest:${cmdlineToolsPath}/latest/bin:${process.env.ANDROID_SDK_ROOT}/platform-tools`);
62+
// set standard AVD path
63+
core.exportVariable('ANDROID_AVD_HOME', `${process.env.HOME}/.android/avd`);
64+
// accept all Android SDK licenses
65+
yield exec.exec(`sh -c \\"yes | sdkmanager --licenses > /dev/null"`);
66+
console.log('Installing latest build tools, platform tools, and platform.');
67+
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
68+
console.log('Installing latest emulator.');
69+
yield exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`);
70+
if (emulatorBuild) {
71+
console.log(`Installing emulator build ${emulatorBuild}.`);
72+
// TODO find out the correct download URLs for all build ids
73+
const downloadUrlSuffix = Number(emulatorBuild.charAt(0)) > 6 ? `_x64-${emulatorBuild}` : `-${emulatorBuild}`;
74+
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-${isOnMac ? 'darwin' : 'linux'}${downloadUrlSuffix}.zip`);
75+
yield exec.exec(`unzip -o -q emulator.zip -d ${process.env.ANDROID_SDK_ROOT}`);
76+
yield io.rmRF('emulator.zip');
77+
}
78+
console.log('Installing system images.');
79+
yield exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' --channel=${channelId} > /dev/null"`);
80+
if (ndkVersion) {
81+
console.log(`Installing NDK ${ndkVersion}.`);
82+
yield exec.exec(`sh -c \\"sdkmanager --install 'ndk;${ndkVersion}' --channel=${channelId} > /dev/null"`);
83+
}
84+
if (cmakeVersion) {
85+
console.log(`Installing CMake ${cmakeVersion}.`);
86+
yield exec.exec(`sh -c \\"sdkmanager --install 'cmake;${cmakeVersion}' --channel=${channelId} > /dev/null"`);
87+
}
4988
}
50-
const cmdlineToolsPath = `${process.env.ANDROID_SDK_ROOT}/cmdline-tools`;
51-
if (!fs.existsSync(cmdlineToolsPath)) {
52-
console.log('Installing new cmdline-tools.');
53-
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
54-
const downloadPath = yield tc.downloadTool(sdkUrl);
55-
yield tc.extractZip(downloadPath, cmdlineToolsPath);
56-
yield io.mv(`${cmdlineToolsPath}/cmdline-tools`, `${cmdlineToolsPath}/latest`);
57-
}
58-
// add paths for commandline-tools and platform-tools
59-
core.addPath(`${cmdlineToolsPath}/latest:${cmdlineToolsPath}/latest/bin:${process.env.ANDROID_SDK_ROOT}/platform-tools`);
60-
// set standard AVD path
61-
core.exportVariable('ANDROID_AVD_HOME', `${process.env.HOME}/.android/avd`);
62-
// accept all Android SDK licenses
63-
yield exec.exec(`sh -c \\"yes | sdkmanager --licenses > /dev/null"`);
64-
console.log('Installing latest build tools, platform tools, and platform.');
65-
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
66-
console.log('Installing latest emulator.');
67-
yield exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`);
68-
if (emulatorBuild) {
69-
console.log(`Installing emulator build ${emulatorBuild}.`);
70-
// TODO find out the correct download URLs for all build ids
71-
const downloadUrlSuffix = Number(emulatorBuild.charAt(0)) > 6 ? `_x64-${emulatorBuild}` : `-${emulatorBuild}`;
72-
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-${isOnMac ? 'darwin' : 'linux'}${downloadUrlSuffix}.zip`);
73-
yield exec.exec(`unzip -o -q emulator.zip -d ${process.env.ANDROID_SDK_ROOT}`);
74-
yield io.rmRF('emulator.zip');
75-
}
76-
console.log('Installing system images.');
77-
yield exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' --channel=${channelId} > /dev/null"`);
78-
if (ndkVersion) {
79-
console.log(`Installing NDK ${ndkVersion}.`);
80-
yield exec.exec(`sh -c \\"sdkmanager --install 'ndk;${ndkVersion}' --channel=${channelId} > /dev/null"`);
81-
}
82-
if (cmakeVersion) {
83-
console.log(`Installing CMake ${cmakeVersion}.`);
84-
yield exec.exec(`sh -c \\"sdkmanager --install 'cmake;${cmakeVersion}' --channel=${channelId} > /dev/null"`);
89+
finally {
90+
console.log(`::endgroup::`);
8591
}
8692
});
8793
}

0 commit comments

Comments
 (0)