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 forLocationManager. 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 classShadowLocationManager.ProviderPropertiesProperties of a provider.
-
Constructor Summary
Constructors Constructor Description ShadowLocationManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected booleanaddGpsStatusListener(GpsStatus.Listener listener)protected booleanaddNmeaListener(OnNmeaMessageListener listener, Handler handler)protected List<String>getAllProviders()protected StringgetBestProvider(Criteria criteria, boolean enabled)List<GpsStatus.Listener>getGpsStatusListeners()protected LocationgetLastKnownLocation(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 LocationProvidergetProvider(String name)protected List<String>getProviders(boolean enabledOnly)protected List<String>getProviders(Criteria criteria, boolean enabled)List<LocationListener>getRequestLocationUpdateListeners()Deprecated.UsegetLocationUpdateListeners()instead.protected booleaninjectLocation(Location location)protected booleanisLocationEnabledForUser(UserHandle userHandle)protected booleanisProviderEnabled(String provider)protected booleanregisterGnssStatusCallback(GnssStatus.Callback callback, Handler handler)protected voidremoveGpsStatusListener(GpsStatus.Listener listener)protected voidremoveNmeaListener(OnNmeaMessageListener listener)voidremoveProvider(String name)Completely removes a provider.protected voidremoveUpdates(PendingIntent pendingIntent)protected voidremoveUpdates(LocationListener listener)protected voidrequestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent intent)protected voidrequestLocationUpdates(long minTime, float minDistance, Criteria criteria, LocationListener listener, Looper looper)protected voidrequestLocationUpdates(Object oRequest, Object intent)protected voidrequestLocationUpdates(Object oRequest, Object listener, Object looper)protected voidrequestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent)protected voidrequestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)protected voidrequestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener, Looper looper)protected voidrequestSingleUpdate(Criteria criteria, PendingIntent intent)protected voidrequestSingleUpdate(Criteria criteria, LocationListener listener, Looper looper)protected voidrequestSingleUpdate(String provider, PendingIntent intent)protected voidrequestSingleUpdate(String provider, LocationListener listener, Looper looper)voidsendGnssStatus(GnssStatus status)Sends aGnssStatusto all registeredGnssStatus.Callbacks.voidsendNmeaMessage(String message, long timestamp)Sends a NMEA message to all registeredOnNmeaMessageListeners.voidsetLastKnownLocation(String provider, Location location)Sets the last known location for the given provider.voidsetLocationEnabled(boolean enabled)On P and above, turns location on or off.protected voidsetLocationEnabledForUser(boolean enabled, UserHandle userHandle)voidsetLocationMode(int locationMode)On pre-P devices, sets the device location mode.voidsetProviderEnabled(String name, boolean enabled)Sets the given provider enabled or disabled.voidsetProviderProperties(String name, ShadowLocationManager.ProviderProperties properties)Sets the properties of the given provider.voidsimulateLocation(Location location)Delivers a new location to the appropriate listeners and updates state accordingly.protected voidunregisterGnssStatusCallback(GnssStatus.Callback callback)
-
-
-
Method Detail
-
getProvider
@Implementation @Nullable protected LocationProvider getProvider(String name)
-
getProviders
@Implementation protected List<String> getProviders(@Nullable Criteria criteria, boolean enabled)
-
getBestProvider
@Implementation @Nullable protected String getBestProvider(Criteria criteria, boolean enabled)
-
isProviderEnabled
@Implementation protected boolean isProviderEnabled(String provider)
-
removeProvider
public void removeProvider(String name)
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
public void setProviderEnabled(String name, boolean enabled)
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
@Implementation(minSdk=28) protected boolean isLocationEnabledForUser(UserHandle userHandle)
-
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_ACCURACYorSettings.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
@Implementation @Nullable protected Location getLastKnownLocation(String provider)
-
setLastKnownLocation
public void setLastKnownLocation(String provider, @Nullable Location location)
Sets the last known location for the given provider.
-
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
@Implementation protected void requestSingleUpdate(String provider, PendingIntent intent)
-
requestSingleUpdate
@Implementation protected void requestSingleUpdate(Criteria criteria, PendingIntent intent)
-
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 protected void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, LocationListener listener, @Nullable Looper looper)
-
requestLocationUpdates
@Implementation protected void requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent)
-
requestLocationUpdates
@Implementation protected void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent intent)
-
requestLocationUpdates
@Implementation(minSdk=21) protected void requestLocationUpdates(@Nullable Object oRequest, Object listener, @Nullable Object looper)
-
requestLocationUpdates
@Implementation(minSdk=21) protected void requestLocationUpdates(@Nullable Object oRequest, Object intent)
-
removeUpdates
@Implementation protected void removeUpdates(LocationListener listener)
-
removeUpdates
@Implementation protected void removeUpdates(PendingIntent pendingIntent)
-
injectLocation
@Implementation(minSdk=28) protected boolean injectLocation(Location location)
-
addGpsStatusListener
@Implementation protected boolean addGpsStatusListener(GpsStatus.Listener listener)
-
removeGpsStatusListener
@Implementation protected void removeGpsStatusListener(GpsStatus.Listener listener)
-
getGpsStatusListeners
public List<GpsStatus.Listener> getGpsStatusListeners()
-
registerGnssStatusCallback
@Implementation(minSdk=24) protected boolean registerGnssStatusCallback(GnssStatus.Callback callback, Handler handler)
-
unregisterGnssStatusCallback
@Implementation(minSdk=24) protected void unregisterGnssStatusCallback(GnssStatus.Callback callback)
-
sendGnssStatus
public void sendGnssStatus(GnssStatus status)
Sends aGnssStatusto all registeredGnssStatus.Callbacks.
-
addNmeaListener
@Implementation(minSdk=24) protected boolean addNmeaListener(OnNmeaMessageListener listener, Handler handler)
-
removeNmeaListener
@Implementation(minSdk=24) protected void removeNmeaListener(OnNmeaMessageListener listener)
-
sendNmeaMessage
public void sendNmeaMessage(String message, long timestamp)
Sends a NMEA message to all registeredOnNmeaMessageListeners.
-
getRequestLocationUpdateListeners
@Deprecated public List<LocationListener> getRequestLocationUpdateListeners()
Deprecated.UsegetLocationUpdateListeners()instead.
-
simulateLocation
public void simulateLocation(Location location)
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 public List<LocationListener> 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 public List<LocationListener> getLocationUpdateListeners(String provider)
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 public List<PendingIntent> 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 public List<PendingIntent> getLocationUpdatePendingIntents(String provider)
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.
-
-