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

chore: Always use reboot_readiness service to detect emulator startup for API 31+ #736

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all 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
37 changes: 16 additions & 21 deletions lib/tools/system-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const SDK_BINARY_ROOTS = [
const MIN_DELAY_ADB_API_LEVEL = 28;
const REQUIRED_SERVICES = ['activity', 'package', 'mount'];
const SUBSYSTEM_STATE_OK = 'Subsystem state: true';
const NO_READINESS_SERVICE_ERROR = `Can't find service: reboot_readiness`;

/**
* Retrieve full path to the given binary.
Expand Down Expand Up @@ -960,7 +959,7 @@ systemCallMethods.launchAVD = async function launchAVD (avdName, opts = {}) {
throw new Error(`'${avdName}' Emulator has failed to boot: ${e.stderr || e.message}`);
}
}
await this.waitForEmulatorReady(readyTimeout - timer.getDuration().asMilliSeconds);
await this.waitForEmulatorReady(Math.trunc(readyTimeout - timer.getDuration().asMilliSeconds));
return proc;
};

Expand Down Expand Up @@ -1023,38 +1022,34 @@ systemCallMethods.getVersion = _.memoize(async function getVersion () {
* @throws {Error} If the emulator is not ready within the given timeout.
*/
systemCallMethods.waitForEmulatorReady = async function waitForEmulatorReady (timeoutMs = 20000) {
log.debug(`Waiting up to ${timeoutMs}ms for the emulator to be ready`);
if (await this.getApiLevel() >= 31) {
let reason;
/** @type {string|undefined} */
let state;
try {
let hasReadinessService = true;
await waitForCondition(async () => {
try {
reason = await this.shell(['cmd', 'reboot_readiness', 'check-subsystems-state', '--list-blocking']);
state = await this.shell([
'cmd', 'reboot_readiness', 'check-subsystems-state', '--list-blocking'
]);
} catch (err) {
// https://github.com/appium/appium/issues/18717
reason = err.stdout || err.stderr;
if (_.includes(reason, NO_READINESS_SERVICE_ERROR)) {
hasReadinessService = false;
return true;
} else if (!_.includes(reason, SUBSYSTEM_STATE_OK)) {
log.debug(`Waiting for emulator startup. Intermediate error: ${err.message}`);
}
state = err.stdout || err.stderr;
}
if (_.includes(state, SUBSYSTEM_STATE_OK)) {
return true;
}
return _.includes(reason, SUBSYSTEM_STATE_OK);

log.debug(`Waiting for emulator startup. Intermediate state: ${state}`);
return false;
}, {
waitMs: timeoutMs,
intervalMs: 1000,
});
if (hasReadinessService) {
return;
}
} catch (e) {
throw new Error(`Emulator is not ready within ${timeoutMs}ms${reason ? ('. Reason: ' + reason) : ''}`);
throw new Error(`Emulator is not ready within ${timeoutMs}ms${state ? ('. Reason: ' + state) : ''}`);
}
log.info(
`The device under test does not have reboot_readiness service. ` +
`Falling back to the alternative boot detection method.`
);
return;
}

/** @type {RegExp[]} */
Expand Down
Loading