@@ -119,7 +119,7 @@ public class GeolocationModule extends KrollModule implements Handler.Callback,
119
119
private static final double SIMPLE_LOCATION_PASSIVE_DISTANCE = 0.0 ;
120
120
private static final double SIMPLE_LOCATION_PASSIVE_TIME = 0 ;
121
121
private static final double SIMPLE_LOCATION_NETWORK_DISTANCE = 10.0 ;
122
- private static final double SIMPLE_LOCATION_NETWORK_TIME = 10000 ;
122
+ private static final double SIMPLE_LOCATION_NETWORK_TIME = 3000 ;
123
123
private static final double SIMPLE_LOCATION_GPS_DISTANCE = 3.0 ;
124
124
private static final double SIMPLE_LOCATION_GPS_TIME = 3000 ;
125
125
private static final double SIMPLE_LOCATION_NETWORK_DISTANCE_RULE = 200 ;
@@ -136,6 +136,7 @@ public class GeolocationModule extends KrollModule implements Handler.Callback,
136
136
//currentLocation is conditionally updated. lastLocation is unconditionally updated
137
137
//since currentLocation determines when to send out updates, and lastLocation is passive
138
138
private Location lastLocation ;
139
+ private ArrayList <KrollFunction > currentPositionCallback = new ArrayList <>();
139
140
140
141
private FusedLocationProvider fusedLocationProvider ;
141
142
@@ -200,6 +201,20 @@ public boolean handleMessage(Message message)
200
201
public void onLocationChanged (Location location )
201
202
{
202
203
lastLocation = location ;
204
+
205
+ // Execute current position callbacks.
206
+ if (currentPositionCallback .size () > 0 ) {
207
+ ArrayList <KrollFunction > currentPositionCallbackClone =
208
+ (ArrayList <KrollFunction >) currentPositionCallback .clone ();
209
+ currentPositionCallback .clear ();
210
+ for (KrollFunction callback : currentPositionCallbackClone ) {
211
+ callback .call (this .getKrollObject (),
212
+ new Object [] { buildLocationEvent (
213
+ lastLocation , tiLocation .locationManager .getProvider (lastLocation .getProvider ())) });
214
+ }
215
+ }
216
+
217
+ // Fire 'location' event listeners.
203
218
if (shouldUseUpdate (location )) {
204
219
fireEvent (TiC .EVENT_LOCATION ,
205
220
buildLocationEvent (location , tiLocation .locationManager .getProvider (location .getProvider ())));
@@ -225,50 +240,42 @@ public void onProviderStateChanged(String providerName, int state)
225
240
switch (state ) {
226
241
case LocationProviderProxy .STATE_DISABLED :
227
242
message += " is disabled" ;
228
- Log .i (TAG , message , Log .DEBUG_MODE );
229
- fireEvent (TiC .EVENT_LOCATION , buildLocationErrorEvent (state , message ));
230
-
231
243
break ;
232
244
233
245
case LocationProviderProxy .STATE_ENABLED :
234
246
message += " is enabled" ;
235
- Log .d (TAG , message , Log .DEBUG_MODE );
236
-
237
247
break ;
238
248
239
249
case LocationProviderProxy .STATE_OUT_OF_SERVICE :
240
250
message += " is out of service" ;
241
- Log .d (TAG , message , Log .DEBUG_MODE );
242
- fireEvent (TiC .EVENT_LOCATION , buildLocationErrorEvent (state , message ));
243
-
244
251
break ;
245
252
246
253
case LocationProviderProxy .STATE_UNAVAILABLE :
247
254
message += " is unavailable" ;
248
- Log .d (TAG , message , Log .DEBUG_MODE );
249
- fireEvent (TiC .EVENT_LOCATION , buildLocationErrorEvent (state , message ));
250
-
251
255
break ;
252
256
253
257
case LocationProviderProxy .STATE_AVAILABLE :
254
258
message += " is available" ;
255
- Log .d (TAG , message , Log .DEBUG_MODE );
256
-
257
259
break ;
258
260
259
261
case LocationProviderProxy .STATE_UNKNOWN :
260
- message += " is in a unknown state [" + state + "]" ;
261
- Log .d (TAG , message , Log .DEBUG_MODE );
262
- fireEvent (TiC .EVENT_LOCATION , buildLocationErrorEvent (state , message ));
263
-
264
- break ;
265
-
266
262
default :
267
263
message += " is in a unknown state [" + state + "]" ;
268
- Log .d (TAG , message , Log .DEBUG_MODE );
269
- fireEvent (TiC .EVENT_LOCATION , buildLocationErrorEvent (state , message ));
270
-
271
- break ;
264
+ }
265
+ Log .d (TAG , message , Log .DEBUG_MODE );
266
+
267
+ if (state != LocationProviderProxy .STATE_ENABLED && state != LocationProviderProxy .STATE_AVAILABLE ) {
268
+ fireEvent (TiC .EVENT_LOCATION , buildLocationErrorEvent (state , message ));
269
+
270
+ // Execute current position callbacks.
271
+ if (currentPositionCallback .size () > 0 ) {
272
+ ArrayList <KrollFunction > currentPositionCallbackClone =
273
+ (ArrayList <KrollFunction >) currentPositionCallback .clone ();
274
+ currentPositionCallback .clear ();
275
+ for (KrollFunction callback : currentPositionCallbackClone ) {
276
+ callback .call (this .getKrollObject (), new Object [] { buildLocationErrorEvent (state , message ) });
277
+ }
278
+ }
272
279
}
273
280
}
274
281
@@ -670,6 +677,20 @@ public void getCurrentPosition(KrollFunction callback)
670
677
}
671
678
if (callback != null ) {
672
679
Location latestKnownLocation = tiLocation .getLastKnownLocation ();
680
+ if (latestKnownLocation == null ) {
681
+ latestKnownLocation = lastLocation ;
682
+ }
683
+
684
+ // TIMOB-27572: Samsung devices require a location provider to be registered
685
+ // in order to obtain last known location.
686
+ if (latestKnownLocation == null ) {
687
+ if (numLocationListeners == 0 ) {
688
+ numLocationListeners ++;
689
+ enableLocationProviders (simpleLocationProviders );
690
+ }
691
+ currentPositionCallback .add (callback );
692
+ return ;
693
+ }
673
694
674
695
if (latestKnownLocation != null ) {
675
696
callback .call (
0 commit comments