@@ -26,6 +26,12 @@ const GPS_COORDINATES_PATTERN = /data="(-?[\d.]+)\s+(-?[\d.]+)\s+(-?[\d.]+)"/;
26
26
* @property {?number|string } [satellites=12] - Number of satellites being tracked (1-12).
27
27
* This value is ignored on real devices.
28
28
* @property {?number|string } [speed] - Valid speed value.
29
+ * https://developer.android.com/reference/android/location/Location#setSpeed(float)
30
+ * @property {?number|string } [bearing] - Valid bearing value.
31
+ * https://developer.android.com/reference/android/location/Location#setBearing(float)
32
+ * @property {?number|string } [accuracy] - Valid accuracy value.
33
+ * https://developer.android.com/reference/android/location/Location#setAccuracy(float),
34
+ * https://developer.android.com/reference/android/location/Criteria
29
35
* Should be greater than 0.0 meters/second for real devices or 0.0 knots
30
36
* for emulators.
31
37
*/
@@ -61,6 +67,8 @@ export async function setGeoLocation (location, isEmulator = false) {
61
67
const latitude = /** @type {string } */ ( formatLocationValue ( 'latitude' ) ) ;
62
68
const altitude = formatLocationValue ( 'altitude' , false ) ;
63
69
const speed = formatLocationValue ( 'speed' , false ) ;
70
+ const bearing = formatLocationValue ( 'bearing' , false ) ;
71
+ const accuracy = formatLocationValue ( 'accuracy' , false ) ;
64
72
if ( isEmulator ) {
65
73
/** @type {string[] } */
66
74
const args = [ longitude , latitude ] ;
@@ -97,8 +105,23 @@ export async function setGeoLocation (location, isEmulator = false) {
97
105
args . push ( '-e' , 'altitude' , altitude ) ;
98
106
}
99
107
if ( ! _ . isNil ( speed ) ) {
108
+ if ( _ . toNumber ( speed ) < 0 ) {
109
+ throw new Error ( `${ speed } is expected to be 0.0 or greater.` ) ;
110
+ }
100
111
args . push ( '-e' , 'speed' , speed ) ;
101
112
}
113
+ if ( ! _ . isNil ( bearing ) ) {
114
+ if ( ! _ . inRange ( _ . toNumber ( bearing ) , 0 , 360 ) ) {
115
+ throw new Error ( `${ accuracy } is expected to be [0, 360) range.` ) ;
116
+ }
117
+ args . push ( '-e' , 'bearing' , bearing ) ;
118
+ }
119
+ if ( ! _ . isNil ( accuracy ) ) {
120
+ if ( _ . toNumber ( accuracy ) < 0 ) {
121
+ throw new Error ( `${ accuracy } is expected to be 0.0 or greater.` ) ;
122
+ }
123
+ args . push ( '-e' , 'accuracy' , accuracy ) ;
124
+ }
102
125
args . push ( LOCATION_SERVICE ) ;
103
126
await this . adb . shell ( args ) ;
104
127
}
0 commit comments