Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow increasing main storage size (sdcard is separate storage) #219

Merged
merged 5 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ jobs:
| `cores` | Optional | 2 | Number of cores to use for the emulator (`hw.cpu.ncore` in config.ini). |
| `ram-size` | Optional | N/A | Size of RAM to use for this AVD, in KB or MB, denoted with K or M. - e.g. `2048M` |
| `sdcard-path-or-size` | Optional | N/A | Path to the SD card image for this AVD or the size of a new SD card image to create for this AVD, in KB or MB, denoted with K or M. - e.g. `path/to/sdcard`, or `1000M`. |
| `disk-size` | Optional | N/A | Disk size to use for this AVD. Either in bytes or KB, MB or GB, when denoted with K, M or G. - e.g. `2048M` |
| `avd-name` | Optional | `test` | Custom AVD name used for creating the Android Virtual Device. |
| `force-avd-creation` | Optional | `true` | Whether to force create the AVD by overwriting an existing AVD with the same name as `avd-name` - `true` or `false`. |
| `emulator-options` | Optional | See below | Command-line options used when launching the emulator (replacing all default options) - e.g. `-no-window -no-snapshot -camera-back emulated`. |
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ inputs:
description: 'size of RAM to use for this AVD, in KB or MB, denoted with K or M. - e.g. `2048M`'
sdcard-path-or-size:
description: 'path to the SD card image for this AVD or the size of a new SD card image to create for this AVD, in KB or MB, denoted with K or M. - e.g. `path/to/sdcard`, or `1000M`'
disk-size:
description: 'disk size to use for this AVD. Either in bytes or KB, MB or GB, when denoted with K, M or G'
avd-name:
description: 'custom AVD name used for creating the Android Virtual Device'
default: 'test'
Expand Down
5 changes: 5 additions & 0 deletions src/emulator-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function launchEmulator(
cores: string,
ramSize: string,
sdcardPathOrSize: string,
diskSize: string,
avdName: string,
forceAvdCreation: boolean,
emulatorOptions: string,
Expand Down Expand Up @@ -45,6 +46,10 @@ export async function launchEmulator(
await exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
}

if (diskSize) {
await exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
}

//turn off hardware acceleration on Linux
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
console.log('Disabling Linux hardware acceleration.');
Expand Down
17 changes: 17 additions & 0 deletions src/input-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,20 @@ export function checkEmulatorBuild(emulatorBuild: string): void {
function isValidBoolean(value: string): boolean {
return value === 'true' || value === 'false';
}

export function checkDiskSize(diskSize: string): void {
ViliusSutkus89 marked this conversation as resolved.
Show resolved Hide resolved
// Disk size can be empty - the default value
if (diskSize) {
// Can also be number of bytes
if (isNaN(Number(diskSize)) || !Number.isInteger(Number(diskSize))) {
// Disk size can have a size multiplier at the end K, M or G
const diskSizeUpperCase = diskSize.toUpperCase();
if (diskSizeUpperCase.endsWith('K') || diskSizeUpperCase.endsWith('M') || diskSizeUpperCase.endsWith('G')) {
const diskSizeNoModifier: string = diskSize.slice(0, -1);
if (isNaN(Number(diskSizeNoModifier)) || !Number.isInteger(Number(diskSizeNoModifier))) {
throw new Error(`Unexpected disk size: '${diskSize}'.`);
}
}
}
}
}
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
checkDisableLinuxHardwareAcceleration,
checkForceAvdCreation,
checkChannel,
checkEnableHardwareKeyboard
checkEnableHardwareKeyboard,
checkDiskSize
} from './input-validator';
import { launchEmulator, killEmulator } from './emulator-manager';
import * as exec from '@actions/exec';
Expand Down Expand Up @@ -63,6 +64,10 @@ async function run() {
const sdcardPathOrSize = core.getInput('sdcard-path-or-size');
console.log(`SD card path or size: ${sdcardPathOrSize}`);

const diskSize = core.getInput('disk-size');
checkDiskSize(diskSize);
console.log(`Disk size: ${diskSize}`);

// custom name used for creating the AVD
const avdName = core.getInput('avd-name');
console.log(`AVD name: ${avdName}`);
Expand Down Expand Up @@ -156,6 +161,7 @@ async function run() {
cores,
ramSize,
sdcardPathOrSize,
diskSize,
avdName,
forceAvdCreation,
emulatorOptions,
Expand Down