@Implements(value=android.location.LocationManager.class, looseSignatures=true) public class ShadowLocationManager extends Object
LocationManager
. Note that the default state of location on Android devices is
location on, gps provider enabled, network provider disabled.Modifier and Type | Class | Description |
---|---|---|
static class |
ShadowLocationManager.ProviderProperties |
Properties of a provider.
|
Constructor | Description |
---|---|
ShadowLocationManager() |
Modifier and Type | Method | Description |
---|---|---|
protected boolean |
addGpsStatusListener(GpsStatus.Listener listener) |
|
protected boolean |
addNmeaListener(OnNmeaMessageListener listener,
Handler handler) |
|
protected List<String> |
getAllProviders() |
|
protected String |
getBestProvider(Criteria criteria,
boolean enabled) |
|
List<GpsStatus.Listener> |
getGpsStatusListeners() |
|
protected Location |
getLastKnownLocation(String provider) |
|
List<LocationListener> |
getLocationUpdateListeners() |
Deprecated.
Do not test listeners, instead use
simulateLocation(Location) and test the
results of those listeners being invoked. |
List<LocationListener> |
getLocationUpdateListeners(String provider) |
Deprecated.
Do not test listeners, instead use
simulateLocation(Location) and test the
results of those listeners being invoked. |
List<PendingIntent> |
getLocationUpdatePendingIntents() |
Deprecated.
Do not test pending intents, instead use
simulateLocation(Location) and
test the results of those pending intent being invoked. |
List<PendingIntent> |
getLocationUpdatePendingIntents(String provider) |
Deprecated.
Do not test pending intents, instead use
simulateLocation(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.
Use
getLocationUpdateListeners() instead. |
protected boolean |
injectLocation(Location location) |
|
protected boolean |
isLocationEnabledForUser(UserHandle userHandle) |
|
protected boolean |
isProviderEnabled(String provider) |
|
protected boolean |
registerGnssStatusCallback(GnssStatus.Callback callback,
Handler handler) |
|
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 intent) |
|
protected void |
requestLocationUpdates(long minTime,
float minDistance,
Criteria criteria,
LocationListener listener,
Looper looper) |
|
protected void |
requestLocationUpdates(Object oRequest,
Object intent) |
|
protected void |
requestLocationUpdates(Object oRequest,
Object listener,
Object looper) |
|
protected void |
requestLocationUpdates(String provider,
long minTime,
float minDistance,
PendingIntent intent) |
|
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 |
requestSingleUpdate(Criteria criteria,
PendingIntent intent) |
|
protected void |
requestSingleUpdate(Criteria criteria,
LocationListener listener,
Looper looper) |
|
protected void |
requestSingleUpdate(String provider,
PendingIntent intent) |
|
protected void |
requestSingleUpdate(String provider,
LocationListener listener,
Looper looper) |
|
void |
sendGnssStatus(GnssStatus status) |
Sends a
GnssStatus to all registered GnssStatus.Callback s. |
void |
sendNmeaMessage(String message,
long timestamp) |
Sends a NMEA message to all registered
OnNmeaMessageListener 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 |
unregisterGnssStatusCallback(GnssStatus.Callback callback) |
@Implementation protected List<String> getAllProviders()
@Implementation @Nullable protected LocationProvider getProvider(String name)
@Implementation protected List<String> getProviders(boolean enabledOnly)
@Implementation protected List<String> getProviders(@Nullable Criteria criteria, boolean enabled)
@Implementation @Nullable protected String getBestProvider(Criteria criteria, boolean enabled)
@Implementation protected boolean isProviderEnabled(String provider)
public void removeProvider(String name)
public void setProviderProperties(String name, @Nullable ShadowLocationManager.ProviderProperties properties)
public void setProviderEnabled(String name, boolean enabled)
setLocationEnabled(boolean)
in order for a provider to be considered enabled.@Implementation(minSdk=28) protected boolean isLocationEnabledForUser(UserHandle userHandle)
@Implementation(minSdk=28) protected void setLocationEnabledForUser(boolean enabled, UserHandle userHandle)
public void setLocationEnabled(boolean enabled)
Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
or Settings.Secure.LOCATION_MODE_OFF
.public void setLocationMode(int locationMode)
setLocationEnabled(boolean)
and setProviderEnabled(String, boolean)
in combination
to achieve the desired effect.@Implementation @Nullable protected Location getLastKnownLocation(String provider)
public void setLastKnownLocation(String provider, @Nullable Location location)
@Implementation protected void requestSingleUpdate(String provider, LocationListener listener, @Nullable Looper looper)
@Implementation protected void requestSingleUpdate(Criteria criteria, LocationListener listener, @Nullable Looper looper)
@Implementation protected void requestSingleUpdate(String provider, PendingIntent intent)
@Implementation protected void requestSingleUpdate(Criteria criteria, PendingIntent intent)
@Implementation protected void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)
@Implementation protected void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener, @Nullable Looper looper)
@Implementation protected void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, LocationListener listener, @Nullable Looper looper)
@Implementation protected void requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent)
@Implementation protected void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent intent)
@Implementation(minSdk=21) protected void requestLocationUpdates(@Nullable Object oRequest, Object listener, @Nullable Object looper)
@Implementation(minSdk=21) protected void requestLocationUpdates(@Nullable Object oRequest, Object intent)
@Implementation protected void removeUpdates(LocationListener listener)
@Implementation protected void removeUpdates(PendingIntent pendingIntent)
@Implementation(minSdk=28) protected boolean injectLocation(Location location)
@Implementation protected boolean addGpsStatusListener(GpsStatus.Listener listener)
@Implementation protected void removeGpsStatusListener(GpsStatus.Listener listener)
public List<GpsStatus.Listener> getGpsStatusListeners()
@Implementation(minSdk=24) protected boolean registerGnssStatusCallback(GnssStatus.Callback callback, Handler handler)
@Implementation(minSdk=24) protected void unregisterGnssStatusCallback(GnssStatus.Callback callback)
public void sendGnssStatus(GnssStatus status)
GnssStatus
to all registered GnssStatus.Callback
s.@Implementation(minSdk=24) protected boolean addNmeaListener(OnNmeaMessageListener listener, Handler handler)
@Implementation(minSdk=24) protected void removeNmeaListener(OnNmeaMessageListener listener)
public void sendNmeaMessage(String message, long timestamp)
OnNmeaMessageListener
s.@Deprecated public List<LocationListener> getRequestLocationUpdateListeners()
getLocationUpdateListeners()
instead.public void simulateLocation(Location location)
@Deprecated public List<LocationListener> getLocationUpdateListeners()
simulateLocation(Location)
and test the
results of those listeners being invoked.@Deprecated public List<LocationListener> getLocationUpdateListeners(String provider)
simulateLocation(Location)
and test the
results of those listeners being invoked.@Deprecated public List<PendingIntent> getLocationUpdatePendingIntents()
simulateLocation(Location)
and
test the results of those pending intent being invoked.@Deprecated public List<PendingIntent> getLocationUpdatePendingIntents(String provider)
simulateLocation(Location)
and
test the results of those pending intent being invoked.