diff --git a/lib/tools/settings-client-commands.js b/lib/tools/settings-client-commands.js index 24ce49ae..f52c647f 100644 --- a/lib/tools/settings-client-commands.js +++ b/lib/tools/settings-client-commands.js @@ -25,6 +25,8 @@ const SMS_LIST_RECEIVER = `${SETTINGS_HELPER_ID}/.receivers.SmsReader`; const SMS_LIST_RETRIEVAL_ACTION = `${SETTINGS_HELPER_ID}.sms.read`; const APPIUM_IME = `${SETTINGS_HELPER_ID}/.AppiumIME`; const UNICODE_IME = `${SETTINGS_HELPER_ID}/.UnicodeIME`; +const DEFAULT_SATELLITES_COUNT = 12; +const DEFAULT_ALTITUDE = 0.0; const commands = {}; @@ -171,7 +173,11 @@ commands.setDeviceSysLocaleViaSettingApp = async function setDeviceSysLocaleViaS * @property {number|string} longitude - Valid longitude value. * @property {number|string} latitude - Valid latitude value. * @property {?number|string} altitude - Valid altitude value. - * @property {?number|string} speed - Valid speed value. Should be greater than 0.0 meters/second. + * @property {?number|string} satellites [12] - Number of satellites being tracked (1-12). + * This value is ignored on real devices. + * @property {?number|string} speed - Valid speed value. + * Should be greater than 0.0 meters/second for real devices or 0.0 knots + * for emulators. */ /** @@ -205,10 +211,30 @@ commands.setGeoLocation = async function setGeoLocation (location, isEmulator = const altitude = formatLocationValue('altitude', false); const speed = formatLocationValue('speed', false); if (isEmulator) { + const args = [longitude, latitude]; + if (!_.isNil(altitude)) { + args.push(altitude); + } + const satellites = parseInt(location.satellites, 10); + if (!Number.isNaN(satellites) && satellites > 0 && satellites <= 12) { + if (args.length < 3) { + args.push(`${DEFAULT_ALTITUDE}`); + } + args.push(`${satellites}`); + } + if (!_.isNil(speed)) { + if (args.length < 3) { + args.push(`${DEFAULT_ALTITUDE}`); + } + if (args.length < 4) { + args.push(`${DEFAULT_SATELLITES_COUNT}`); + } + args.push(speed); + } await this.resetTelnetAuthToken(); - await this.adbExec(['emu', 'geo', 'fix', longitude, latitude]); + await this.adbExec(['emu', 'geo', 'fix', ...args]); // A workaround for https://code.google.com/p/android/issues/detail?id=206180 - await this.adbExec(['emu', 'geo', 'fix', longitude.replace('.', ','), latitude.replace('.', ',')]); + await this.adbExec(['emu', 'geo', 'fix', ...(args.map((arg) => arg.replace('.', ',')))]); } else { const args = [ 'am', 'startservice',