Package org.robolectric.shadows
Class ShadowLocationManager
java.lang.Object
org.robolectric.shadows.ShadowLocationManager
@Implements(value=android.location.LocationManager.class, looseSignatures=true) public class ShadowLocationManager extends Object
Shadow for
LocationManager
. Note that the default state of location on Android devices is
location on, gps provider enabled, network provider disabled.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShadowLocationManager.ProviderProperties
Properties of a provider. -
Constructor Summary
Constructors Constructor Description ShadowLocationManager()
-
Method Summary
Modifier and Type Method Description protected boolean
addGpsStatusListener(GpsStatus.Listener listener)
protected boolean
addNmeaListener(OnNmeaMessageListener listener, Handler handler)
protected boolean
addNmeaListener(Executor executor, OnNmeaMessageListener listener)
protected Object
createRealProperties(boolean requiresNetwork, boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy)
protected List<String>
getAllProviders()
protected String
getBestProvider(Criteria criteria, boolean enabled)
protected void
getCurrentLocation(String provider, CancellationSignal cancellationSignal, Executor executor, Consumer<Location> consumer)
List<GpsStatus.Listener>
getGpsStatusListeners()
protected Location
getLastKnownLocation(String provider)
List<LocationListener>
getLocationUpdateListeners()
Deprecated.Do not test listeners, instead usesimulateLocation(Location)
and test the results of those listeners being invoked.List<LocationListener>
getLocationUpdateListeners(String provider)
Deprecated.Do not test listeners, instead usesimulateLocation(Location)
and test the results of those listeners being invoked.List<PendingIntent>
getLocationUpdatePendingIntents()
Deprecated.Do not test pending intents, instead usesimulateLocation(Location)
and test the results of those pending intent being invoked.List<PendingIntent>
getLocationUpdatePendingIntents(String provider)
Deprecated.Do not test pending intents, instead usesimulateLocation(Location)
and test the results of those pending intent being invoked.protected LocationProvider
getProvider(String name)
protected List<String>
getProviders(boolean enabledOnly)
protected List<String>
getProviders(Criteria criteria, boolean enabled)
List<LocationListener>
getRequestLocationUpdateListeners()
Deprecated.UsegetLocationUpdateListeners()
instead.protected boolean
injectLocation(Location location)
protected boolean
isLocationEnabledForUser(UserHandle userHandle)
protected boolean
isProviderEnabled(String provider)
protected Constructor<LocationProvider>
loadLocationProviderConstructor()
protected boolean
registerAntennaInfoListener(Executor executor, GnssAntennaInfo.Listener listener)
protected boolean
registerGnssMeasurementsCallback(GnssMeasurementsEvent.Callback callback, Handler handler)
protected boolean
registerGnssMeasurementsCallback(Executor executor, GnssMeasurementsEvent.Callback callback)
protected boolean
registerGnssStatusCallback(GnssStatus.Callback callback, Handler handler)
protected boolean
registerGnssStatusCallback(Executor executor, GnssStatus.Callback callback)
protected void
removeGpsStatusListener(GpsStatus.Listener listener)
protected void
removeNmeaListener(OnNmeaMessageListener listener)
void
removeProvider(String name)
Completely removes a provider.protected void
removeUpdates(PendingIntent pendingIntent)
protected void
removeUpdates(LocationListener listener)
protected void
requestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent pendingIntent)
protected void
requestLocationUpdates(long minTime, float minDistance, Criteria criteria, LocationListener listener, Looper looper)
protected void
requestLocationUpdates(long minTime, float minDistance, Criteria criteria, Executor executor, LocationListener listener)
protected void
requestLocationUpdates(Object request, Object pendingIntent)
protected void
requestLocationUpdates(Object request, Object executorOrListener, Object listenerOrLooper)
protected void
requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent pendingIntent)
protected void
requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)
protected void
requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener, Looper looper)
protected void
requestLocationUpdates(String provider, long minTime, float minDistance, Executor executor, LocationListener listener)
protected void
requestSingleUpdate(Criteria criteria, PendingIntent pendingIntent)
protected void
requestSingleUpdate(Criteria criteria, LocationListener listener, Looper looper)
protected void
requestSingleUpdate(String provider, PendingIntent pendingIntent)
protected void
requestSingleUpdate(String provider, LocationListener listener, Looper looper)
static void
reset()
void
sendGnssAntennaInfo(List<GnssAntennaInfo> antennaInfos)
Sends a GNSS measurement event to all registeredGnssMeasurementsEvent.Callback
s.void
sendGnssMeasurementsEvent(GnssMeasurementsEvent event)
Sends a GNSS measurement event to all registeredGnssMeasurementsEvent.Callback
s.void
sendGnssStatus(GnssStatus status)
Sends aGnssStatus
to all registeredGnssStatus.Callback
s.void
sendNmeaMessage(String message, long timestamp)
Sends a NMEA message to all registeredOnNmeaMessageListener
s.void
setLastKnownLocation(String provider, Location location)
Sets the last known location for the given provider.void
setLocationEnabled(boolean enabled)
On P and above, turns location on or off.protected void
setLocationEnabledForUser(boolean enabled, UserHandle userHandle)
void
setLocationMode(int locationMode)
On pre-P devices, sets the device location mode.void
setProviderEnabled(String name, boolean enabled)
Sets the given provider enabled or disabled.void
setProviderProperties(String name, ShadowLocationManager.ProviderProperties properties)
Sets the properties of the given provider.void
simulateLocation(Location location)
Delivers a new location to the appropriate listeners and updates state accordingly.protected void
unregisterAntennaInfoListener(GnssAntennaInfo.Listener listener)
protected void
unregisterGnssMeasurementsCallback(GnssMeasurementsEvent.Callback callback)
protected void
unregisterGnssStatusCallback(GnssStatus.Callback callback)
-
Constructor Details
-
ShadowLocationManager
public ShadowLocationManager()
-
-
Method Details
-
getAllProviders
-
getProvider
-
loadLocationProviderConstructor
protected Constructor<LocationProvider> loadLocationProviderConstructor() throws ReflectiveOperationException- Throws:
ReflectiveOperationException
-
getProviders
-
getProviders
-
getBestProvider
-
isProviderEnabled
-
removeProvider
Completely removes a provider. -
setProviderProperties
public void setProviderProperties(String name, @Nullable ShadowLocationManager.ProviderProperties properties)Sets the properties of the given provider. The provider will be created if it doesn't exist already. -
setProviderEnabled
Sets the given provider enabled or disabled. The provider will be created if it doesn't exist already. On P and above, location must also be enabled viasetLocationEnabled(boolean)
in order for a provider to be considered enabled. -
isLocationEnabledForUser
-
setLocationEnabledForUser
@Implementation(minSdk=28) protected void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) -
setLocationEnabled
public void setLocationEnabled(boolean enabled)On P and above, turns location on or off. On pre-P devices, sets the location mode toSettings.Secure.LOCATION_MODE_HIGH_ACCURACY
orSettings.Secure.LOCATION_MODE_OFF
. -
setLocationMode
public void setLocationMode(int locationMode)On pre-P devices, sets the device location mode. For P and above, usesetLocationEnabled(boolean)
andsetProviderEnabled(String, boolean)
in combination to achieve the desired effect. -
getLastKnownLocation
-
setLastKnownLocation
Sets the last known location for the given provider. -
getCurrentLocation
@Implementation(minSdk=30) protected void getCurrentLocation(String provider, @Nullable CancellationSignal cancellationSignal, Executor executor, Consumer<Location> consumer) -
requestSingleUpdate
@Implementation protected void requestSingleUpdate(String provider, LocationListener listener, @Nullable Looper looper) -
requestSingleUpdate
@Implementation protected void requestSingleUpdate(Criteria criteria, LocationListener listener, @Nullable Looper looper) -
requestSingleUpdate
-
requestSingleUpdate
-
requestLocationUpdates
@Implementation protected void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) -
requestLocationUpdates
@Implementation protected void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener, @Nullable Looper looper) -
requestLocationUpdates
@Implementation(minSdk=30) protected void requestLocationUpdates(String provider, long minTime, float minDistance, Executor executor, LocationListener listener) -
requestLocationUpdates
@Implementation protected void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, LocationListener listener, @Nullable Looper looper) -
requestLocationUpdates
@Implementation(minSdk=30) protected void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, Executor executor, LocationListener listener) -
requestLocationUpdates
@Implementation protected void requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent pendingIntent) -
requestLocationUpdates
@Implementation protected void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent pendingIntent) -
requestLocationUpdates
@Implementation(minSdk=21) protected void requestLocationUpdates(@Nullable Object request, Object executorOrListener, Object listenerOrLooper) -
requestLocationUpdates
@Implementation(minSdk=21) protected void requestLocationUpdates(@Nullable Object request, Object pendingIntent) -
removeUpdates
-
removeUpdates
-
injectLocation
-
addGpsStatusListener
-
removeGpsStatusListener
-
getGpsStatusListeners
-
registerGnssStatusCallback
@Implementation(minSdk=24) protected boolean registerGnssStatusCallback(GnssStatus.Callback callback, Handler handler) -
registerGnssStatusCallback
@Implementation(minSdk=30) protected boolean registerGnssStatusCallback(Executor executor, GnssStatus.Callback callback) -
unregisterGnssStatusCallback
@Implementation(minSdk=24) protected void unregisterGnssStatusCallback(GnssStatus.Callback callback) -
sendGnssStatus
Sends aGnssStatus
to all registeredGnssStatus.Callback
s. -
addNmeaListener
@Implementation(minSdk=24) protected boolean addNmeaListener(OnNmeaMessageListener listener, Handler handler) -
addNmeaListener
@Implementation(minSdk=30) protected boolean addNmeaListener(Executor executor, OnNmeaMessageListener listener) -
removeNmeaListener
-
sendNmeaMessage
Sends a NMEA message to all registeredOnNmeaMessageListener
s. -
registerGnssMeasurementsCallback
@Implementation(minSdk=24) protected boolean registerGnssMeasurementsCallback(GnssMeasurementsEvent.Callback callback, Handler handler) -
registerGnssMeasurementsCallback
@Implementation(minSdk=30) protected boolean registerGnssMeasurementsCallback(Executor executor, GnssMeasurementsEvent.Callback callback) -
unregisterGnssMeasurementsCallback
@Implementation(minSdk=24) protected void unregisterGnssMeasurementsCallback(GnssMeasurementsEvent.Callback callback) -
sendGnssMeasurementsEvent
Sends a GNSS measurement event to all registeredGnssMeasurementsEvent.Callback
s. -
registerAntennaInfoListener
@Implementation(minSdk=30) protected boolean registerAntennaInfoListener(Executor executor, GnssAntennaInfo.Listener listener) -
unregisterAntennaInfoListener
@Implementation(minSdk=30) protected void unregisterAntennaInfoListener(GnssAntennaInfo.Listener listener) -
sendGnssAntennaInfo
Sends a GNSS measurement event to all registeredGnssMeasurementsEvent.Callback
s. -
getRequestLocationUpdateListeners
Deprecated.UsegetLocationUpdateListeners()
instead. -
simulateLocation
Delivers a new location to the appropriate listeners and updates state accordingly. Delivery will ignore the enabled/disabled state of providers, unlike location on a real device. -
getLocationUpdateListeners
Deprecated.Do not test listeners, instead usesimulateLocation(Location)
and test the results of those listeners being invoked.Retrieves a list of all currently registered listeners. -
getLocationUpdateListeners
Deprecated.Do not test listeners, instead usesimulateLocation(Location)
and test the results of those listeners being invoked.Retrieves a list of all currently registered listeners for the given provider. -
getLocationUpdatePendingIntents
Deprecated.Do not test pending intents, instead usesimulateLocation(Location)
and test the results of those pending intent being invoked.Retrieves a list of all currently registered pending intents. -
getLocationUpdatePendingIntents
Deprecated.Do not test pending intents, instead usesimulateLocation(Location)
and test the results of those pending intent being invoked.Retrieves a list of all currently registered pending intents for the given provider. -
createRealProperties
protected Object createRealProperties(boolean requiresNetwork, boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy) -
reset
-