Skip to content

Commit

Permalink
Add option to change long-press timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
AfzalivE committed Feb 24, 2021
1 parent 640f06b commit 393c3c5
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
| `disable-spellchecker` | Optional | `false` | Whether to disable spellchecker - `true` or `false`. |
| `disable-autofill` | Optional | `false` | Whether to disable autofill - `true` or `false`. |
| `longpress-timeout` | Optional | 500 | Longpress timeout in milliseconds. |
| `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
23 changes: 23 additions & 0 deletions __tests__/input-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ describe('disable-autofill validator tests', () => {
});
});

describe('longpress-timeout validator tests', () => {
it('Throws if longpress-timeout is not a number', () => {
const func = () => {
validator.checkLongPressTimeout('abc123');
};
expect(func).toThrowError(`Unexpected longpress-timeout: 'abc123'.`);
});

it('Throws if longpress-timeout is not an integer', () => {
const func = () => {
validator.checkLongPressTimeout('123.123');
};
expect(func).toThrowError(`Unexpected longpress-timeout: '123.123'.`);
});

it('Validates successfully with valid longpress-timeout', () => {
const func = () => {
validator.checkLongPressTimeout('6061023');
};
expect(func).not.toThrow();
});
});

describe('emulator-build validator tests', () => {
it('Throws if emulator-build is not a number', () => {
const func = () => {
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ inputs:
disable-autofill:
description: Whether to disable autofill - `true` or `false`.
default: 'false'
longpress-timeout:
description: Longpress timeout in milliseconds.
default: 500
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
5 changes: 4 additions & 1 deletion lib/emulator-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
/**
* Creates and launches a new AVD instance with the specified configurations.
*/
function launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellChecker, disableAutofill) {
function launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellChecker, disableAutofill, longPressTimeout) {
return __awaiter(this, void 0, void 0, function* () {
// create a new AVD
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
Expand Down Expand Up @@ -72,6 +72,9 @@ function launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdNa
if (disableAutofill) {
yield exec.exec(`adb shell settings put secure autofill_service null`);
}
if (longPressTimeout) {
yield exec.exec(`adb shell settings put secure long_press_timeout ${longPressTimeout}`);
}
});
}
exports.launchEmulator = launchEmulator;
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.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.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 @@ -43,6 +43,12 @@ function checkDisableAutofill(disableAutofill) {
}
}
exports.checkDisableAutofill = checkDisableAutofill;
function checkLongPressTimeout(timeout) {
if (isNaN(Number(timeout)) || !Number.isInteger(Number(timeout))) {
throw new Error(`Unexpected longpress-timeout: '${timeout}'.`);
}
}
exports.checkLongPressTimeout = checkLongPressTimeout;
function checkEmulatorBuild(emulatorBuild) {
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
Expand Down
7 changes: 6 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ function run() {
input_validator_1.checkDisableAutofill(disableAutofillInput);
const disableAutofill = disableAutofillInput === 'true';
console.log(`disable autofill: ${disableAutofill}`);
// update longpress timeout
const longPressTimeoutInput = core.getInput('longpress-timeout');
input_validator_1.checkLongPressTimeout(longPressTimeoutInput);
const longPressTimeout = Number(longPressTimeoutInput);
console.log(`update longpress-timeout: ${longPressTimeoutInput}`);
// emulator build
const emulatorBuildInput = core.getInput('emulator-build');
if (emulatorBuildInput) {
Expand Down Expand Up @@ -122,7 +127,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, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker, disableAutofill);
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker, disableAutofill, longPressTimeout);
// execute the custom script
try {
// move to custom working directory if set
Expand Down
6 changes: 5 additions & 1 deletion src/emulator-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export async function launchEmulator(
emulatorOptions: string,
disableAnimations: boolean,
disableSpellChecker: boolean,
disableAutofill: boolean
disableAutofill: boolean,
longPressTimeout: number
): Promise<void> {
// create a new AVD
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
Expand Down Expand Up @@ -60,6 +61,9 @@ export async function launchEmulator(
if (disableAutofill) {
await exec.exec(`adb shell settings put secure autofill_service null`);
}
if (longPressTimeout) {
await exec.exec(`adb shell settings put secure long_press_timeout ${longPressTimeout}`);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/input-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export function checkDisableAutofill(disableAutofill: string): void {
}
}

export function checkLongPressTimeout(timeout: string): void {
if (isNaN(Number(timeout)) || !Number.isInteger(Number(timeout))) {
throw new Error(`Unexpected longpress-timeout: '${timeout}'.`);
}
}

export function checkEmulatorBuild(emulatorBuild: string): void {
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
Expand Down
10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core';
import { installAndroidSdk } from './sdk-installer';
import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmulatorBuild, checkDisableSpellchecker, checkDisableAutofill } from './input-validator';
import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmulatorBuild, checkDisableSpellchecker, checkDisableAutofill, checkLongPressTimeout } from './input-validator';
import { launchEmulator, killEmulator } from './emulator-manager';
import * as exec from '@actions/exec';
import { parseScript } from './script-parser';
Expand Down Expand Up @@ -69,6 +69,12 @@ async function run() {
const disableAutofill = disableAutofillInput === 'true';
console.log(`disable autofill: ${disableAutofill}`);

// update longpress timeout
const longPressTimeoutInput = core.getInput('longpress-timeout');
checkLongPressTimeout(longPressTimeoutInput);
const longPressTimeout = Number(longPressTimeoutInput);
console.log(`update longpress-timeout: ${longPressTimeoutInput}`);

// emulator build
const emulatorBuildInput = core.getInput('emulator-build');
if (emulatorBuildInput) {
Expand Down Expand Up @@ -110,7 +116,7 @@ async function run() {
await installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);

// launch an emulator
await launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker, disableAutofill);
await launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker, disableAutofill, longPressTimeout);

// execute the custom script
try {
Expand Down

0 comments on commit 393c3c5

Please sign in to comment.