Skip to content

Commit 4e0dd2c

Browse files
Allow increasing main storage size (sdcard is separate storage) (#219)
* Allow increasing disk size - Issue #184 * Fix checkDiskSize validator * Fix lint errors * Size modifier without a number is unacceptable "G" is not the same as "1G" * Implement checkDiskSize validator tests
1 parent 62d9706 commit 4e0dd2c

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ jobs:
149149
| `cores` | Optional | 2 | Number of cores to use for the emulator (`hw.cpu.ncore` in config.ini). |
150150
| `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` |
151151
| `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`. |
152+
| `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` |
152153
| `avd-name` | Optional | `test` | Custom AVD name used for creating the Android Virtual Device. |
153154
| `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`. |
154155
| `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`. |

__tests__/input-validator.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,54 @@ describe('emulator-build validator tests', () => {
270270
expect(func).not.toThrow();
271271
});
272272
});
273+
274+
describe('checkDiskSize validator tests', () => {
275+
it('Empty size is acceptable, means default', () => {
276+
const func = () => {
277+
validator.checkDiskSize('');
278+
};
279+
expect(func).not.toThrow();
280+
});
281+
282+
it('Numbers means bytes', () => {
283+
expect(() => {
284+
validator.checkDiskSize('8000000000');
285+
}).not.toThrow();
286+
});
287+
288+
it('Uppercase size modifier', () => {
289+
expect(() => {
290+
validator.checkDiskSize('8000000K');
291+
}).not.toThrow();
292+
expect(() => {
293+
validator.checkDiskSize('8000M');
294+
}).not.toThrow();
295+
expect(() => {
296+
validator.checkDiskSize('8G');
297+
}).not.toThrow();
298+
});
299+
300+
it('Lowercase size modifier', () => {
301+
expect(() => {
302+
validator.checkDiskSize('8000000k');
303+
}).not.toThrow();
304+
expect(() => {
305+
validator.checkDiskSize('8000m');
306+
}).not.toThrow();
307+
expect(() => {
308+
validator.checkDiskSize('8g');
309+
}).not.toThrow();
310+
});
311+
312+
it('Modifier without a number is unacceptable', () => {
313+
expect(() => {
314+
validator.checkDiskSize('G');
315+
}).toThrowError(`Unexpected disk size: 'G'.`);
316+
});
317+
318+
it('Double modifier is unacceptable', () => {
319+
expect(() => {
320+
validator.checkDiskSize('14gg');
321+
}).toThrowError(`Unexpected disk size: '14gg'.`);
322+
});
323+
});

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ inputs:
2323
description: 'size of RAM to use for this AVD, in KB or MB, denoted with K or M. - e.g. `2048M`'
2424
sdcard-path-or-size:
2525
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`'
26+
disk-size:
27+
description: 'disk size to use for this AVD. Either in bytes or KB, MB or GB, when denoted with K, M or G'
2628
avd-name:
2729
description: 'custom AVD name used for creating the Android Virtual Device'
2830
default: 'test'

src/emulator-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function launchEmulator(
1414
cores: string,
1515
ramSize: string,
1616
sdcardPathOrSize: string,
17+
diskSize: string,
1718
avdName: string,
1819
forceAvdCreation: boolean,
1920
emulatorOptions: string,
@@ -45,6 +46,10 @@ export async function launchEmulator(
4546
await exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
4647
}
4748

49+
if (diskSize) {
50+
await exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
51+
}
52+
4853
//turn off hardware acceleration on Linux
4954
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
5055
console.log('Disabling Linux hardware acceleration.');

src/input-validator.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,20 @@ export function checkEmulatorBuild(emulatorBuild: string): void {
6969
function isValidBoolean(value: string): boolean {
7070
return value === 'true' || value === 'false';
7171
}
72+
73+
export function checkDiskSize(diskSize: string): void {
74+
// Disk size can be empty - the default value
75+
if (diskSize) {
76+
// Can also be number of bytes
77+
if (isNaN(Number(diskSize)) || !Number.isInteger(Number(diskSize))) {
78+
// Disk size can have a size multiplier at the end K, M or G
79+
const diskSizeUpperCase = diskSize.toUpperCase();
80+
if (diskSizeUpperCase.endsWith('K') || diskSizeUpperCase.endsWith('M') || diskSizeUpperCase.endsWith('G')) {
81+
const diskSizeNoModifier: string = diskSize.slice(0, -1);
82+
if (0 == diskSizeNoModifier.length || isNaN(Number(diskSizeNoModifier)) || !Number.isInteger(Number(diskSizeNoModifier))) {
83+
throw new Error(`Unexpected disk size: '${diskSize}'.`);
84+
}
85+
}
86+
}
87+
}
88+
}

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
checkDisableLinuxHardwareAcceleration,
1111
checkForceAvdCreation,
1212
checkChannel,
13-
checkEnableHardwareKeyboard
13+
checkEnableHardwareKeyboard,
14+
checkDiskSize
1415
} from './input-validator';
1516
import { launchEmulator, killEmulator } from './emulator-manager';
1617
import * as exec from '@actions/exec';
@@ -63,6 +64,10 @@ async function run() {
6364
const sdcardPathOrSize = core.getInput('sdcard-path-or-size');
6465
console.log(`SD card path or size: ${sdcardPathOrSize}`);
6566

67+
const diskSize = core.getInput('disk-size');
68+
checkDiskSize(diskSize);
69+
console.log(`Disk size: ${diskSize}`);
70+
6671
// custom name used for creating the AVD
6772
const avdName = core.getInput('avd-name');
6873
console.log(`AVD name: ${avdName}`);
@@ -156,6 +161,7 @@ async function run() {
156161
cores,
157162
ramSize,
158163
sdcardPathOrSize,
164+
diskSize,
159165
avdName,
160166
forceAvdCreation,
161167
emulatorOptions,

0 commit comments

Comments
 (0)