Skip to content

Commit

Permalink
chore: Always use reboot_readiness service to detect emulator startup…
Browse files Browse the repository at this point in the history
… for API 31+
  • Loading branch information
mykola-mokhnach committed May 7, 2024
1 parent aed6258 commit e1578e8
Showing 1 changed file with 16 additions and 21 deletions.
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

0 comments on commit e1578e8

Please sign in to comment.