Class ShadowLocationManager


  • @Implements(value=android.location.LocationManager.class,
                looseSignatures=true)
    public class ShadowLocationManager
    extends java.lang.Object
    Shadow for LocationManager. Note that the default state of location on Android devices is location on, gps provider enabled, network provider disabled.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected boolean addGpsStatusListener​(android.location.GpsStatus.Listener listener)  
      protected boolean addNmeaListener​(android.location.OnNmeaMessageListener listener, android.os.Handler handler)  
      protected java.util.List<java.lang.String> getAllProviders()  
      protected java.lang.String getBestProvider​(android.location.Criteria criteria, boolean enabled)  
      java.util.List<android.location.GpsStatus.Listener> getGpsStatusListeners()  
      protected android.location.Location getLastKnownLocation​(java.lang.String provider)  
      java.util.List<android.location.LocationListener> getLocationUpdateListeners()
      Deprecated.
      Do not test listeners, instead use simulateLocation(Location) and test the results of those listeners being invoked.
      java.util.List<android.location.LocationListener> getLocationUpdateListeners​(java.lang.String provider)
      Deprecated.
      Do not test listeners, instead use simulateLocation(Location) and test the results of those listeners being invoked.
      java.util.List<android.app.PendingIntent> getLocationUpdatePendingIntents()
      Deprecated.
      Do not test pending intents, instead use simulateLocation(Location) and test the results of those pending intent being invoked.
      java.util.List<android.app.PendingIntent> getLocationUpdatePendingIntents​(java.lang.String provider)
      Deprecated.
      Do not test pending intents, instead use simulateLocation(Location) and test the results of those pending intent being invoked.
      protected android.location.LocationProvider getProvider​(java.lang.String name)  
      protected java.util.List<java.lang.String> getProviders​(boolean enabledOnly)  
      protected java.util.List<java.lang.String> getProviders​(android.location.Criteria criteria, boolean enabled)  
      java.util.List<android.location.LocationListener> getRequestLocationUpdateListeners()
      Deprecated.
      protected boolean injectLocation​(android.location.Location location)  
      protected boolean isLocationEnabledForUser​(android.os.UserHandle userHandle)  
      protected boolean isProviderEnabled​(java.lang.String provider)  
      protected boolean registerGnssStatusCallback​(android.location.GnssStatus.Callback callback, android.os.Handler handler)  
      protected void removeGpsStatusListener​(android.location.GpsStatus.Listener listener)  
      protected void removeNmeaListener​(android.location.OnNmeaMessageListener listener)  
      void removeProvider​(java.lang.String name)
      Completely removes a provider.
      protected void removeUpdates​(android.app.PendingIntent pendingIntent)  
      protected void removeUpdates​(android.location.LocationListener listener)  
      protected void requestLocationUpdates​(long minTime, float minDistance, android.location.Criteria criteria, android.app.PendingIntent intent)  
      protected void requestLocationUpdates​(long minTime, float minDistance, android.location.Criteria criteria, android.location.LocationListener listener, android.os.Looper looper)  
      protected void requestLocationUpdates​(java.lang.Object oRequest, java.lang.Object intent)  
      protected void requestLocationUpdates​(java.lang.Object oRequest, java.lang.Object listener, java.lang.Object looper)  
      protected void requestLocationUpdates​(java.lang.String provider, long minTime, float minDistance, android.app.PendingIntent intent)  
      protected void requestLocationUpdates​(java.lang.String provider, long minTime, float minDistance, android.location.LocationListener listener)  
      protected void requestLocationUpdates​(java.lang.String provider, long minTime, float minDistance, android.location.LocationListener listener, android.os.Looper looper)  
      protected void requestSingleUpdate​(android.location.Criteria criteria, android.app.PendingIntent intent)  
      protected void requestSingleUpdate​(android.location.Criteria criteria, android.location.LocationListener listener, android.os.Looper looper)  
      protected void requestSingleUpdate​(java.lang.String provider, android.app.PendingIntent intent)  
      protected void requestSingleUpdate​(java.lang.String provider, android.location.LocationListener listener, android.os.Looper looper)  
      void sendGnssStatus​(android.location.GnssStatus status)
      Sends a GnssStatus to all registered GnssStatus.Callbacks.
      void sendNmeaMessage​(java.lang.String message, long timestamp)
      Sends a NMEA message to all registered OnNmeaMessageListeners.
      void setLastKnownLocation​(java.lang.String provider, android.location.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, android.os.UserHandle userHandle)  
      void setLocationMode​(int locationMode)
      On pre-P devices, sets the device location mode.
      void setProviderEnabled​(java.lang.String name, boolean enabled)
      Sets the given provider enabled or disabled.
      void setProviderProperties​(java.lang.String name, ShadowLocationManager.ProviderProperties properties)
      Sets the properties of the given provider.
      void simulateLocation​(android.location.Location location)
      Delivers a new location to the appropriate listeners and updates state accordingly.
      protected void unregisterGnssStatusCallback​(android.location.GnssStatus.Callback callback)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ShadowLocationManager

        public ShadowLocationManager()
    • Method Detail

      • getAllProviders

        @Implementation
        protected java.util.List<java.lang.String> getAllProviders()
      • getProvider

        @Implementation
        @Nullable
        protected android.location.LocationProvider getProvider​(java.lang.String name)
      • getProviders

        @Implementation
        protected java.util.List<java.lang.String> getProviders​(boolean enabledOnly)
      • getProviders

        @Implementation
        protected java.util.List<java.lang.String> getProviders​(@Nullable
                                                                android.location.Criteria criteria,
                                                                boolean enabled)
      • getBestProvider

        @Implementation
        @Nullable
        protected java.lang.String getBestProvider​(android.location.Criteria criteria,
                                                   boolean enabled)
      • isProviderEnabled

        @Implementation
        protected boolean isProviderEnabled​(java.lang.String provider)
      • removeProvider

        public void removeProvider​(java.lang.String name)
        Completely removes a provider.
      • setProviderProperties

        public void setProviderProperties​(java.lang.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​(java.lang.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 via setLocationEnabled(boolean) in order for a provider to be considered enabled.
      • isLocationEnabledForUser

        @Implementation(minSdk=28)
        protected boolean isLocationEnabledForUser​(android.os.UserHandle userHandle)
      • setLocationEnabledForUser

        @Implementation(minSdk=28)
        protected void setLocationEnabledForUser​(boolean enabled,
                                                 android.os.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 to Settings.Secure.LOCATION_MODE_HIGH_ACCURACY or Settings.Secure.LOCATION_MODE_OFF.
      • getLastKnownLocation

        @Implementation
        @Nullable
        protected android.location.Location getLastKnownLocation​(java.lang.String provider)
      • setLastKnownLocation

        public void setLastKnownLocation​(java.lang.String provider,
                                         @Nullable
                                         android.location.Location location)
        Sets the last known location for the given provider.
      • requestSingleUpdate

        @Implementation
        protected void requestSingleUpdate​(java.lang.String provider,
                                           android.location.LocationListener listener,
                                           @Nullable
                                           android.os.Looper looper)
      • requestSingleUpdate

        @Implementation
        protected void requestSingleUpdate​(android.location.Criteria criteria,
                                           android.location.LocationListener listener,
                                           @Nullable
                                           android.os.Looper looper)
      • requestSingleUpdate

        @Implementation
        protected void requestSingleUpdate​(java.lang.String provider,
                                           android.app.PendingIntent intent)
      • requestSingleUpdate

        @Implementation
        protected void requestSingleUpdate​(android.location.Criteria criteria,
                                           android.app.PendingIntent intent)
      • requestLocationUpdates

        @Implementation
        protected void requestLocationUpdates​(java.lang.String provider,
                                              long minTime,
                                              float minDistance,
                                              android.location.LocationListener listener)
      • requestLocationUpdates

        @Implementation
        protected void requestLocationUpdates​(java.lang.String provider,
                                              long minTime,
                                              float minDistance,
                                              android.location.LocationListener listener,
                                              @Nullable
                                              android.os.Looper looper)
      • requestLocationUpdates

        @Implementation
        protected void requestLocationUpdates​(long minTime,
                                              float minDistance,
                                              android.location.Criteria criteria,
                                              android.location.LocationListener listener,
                                              @Nullable
                                              android.os.Looper looper)
      • requestLocationUpdates

        @Implementation
        protected void requestLocationUpdates​(java.lang.String provider,
                                              long minTime,
                                              float minDistance,
                                              android.app.PendingIntent intent)
      • requestLocationUpdates

        @Implementation
        protected void requestLocationUpdates​(long minTime,
                                              float minDistance,
                                              android.location.Criteria criteria,
                                              android.app.PendingIntent intent)
      • requestLocationUpdates

        @Implementation(minSdk=21)
        protected void requestLocationUpdates​(@Nullable
                                              java.lang.Object oRequest,
                                              java.lang.Object listener,
                                              @Nullable
                                              java.lang.Object looper)
      • requestLocationUpdates

        @Implementation(minSdk=21)
        protected void requestLocationUpdates​(@Nullable
                                              java.lang.Object oRequest,
                                              java.lang.Object intent)
      • removeUpdates

        @Implementation
        protected void removeUpdates​(android.location.LocationListener listener)
      • removeUpdates

        @Implementation
        protected void removeUpdates​(android.app.PendingIntent pendingIntent)
      • injectLocation

        @Implementation(minSdk=28)
        protected boolean injectLocation​(android.location.Location location)
      • addGpsStatusListener

        @Implementation
        protected boolean addGpsStatusListener​(android.location.GpsStatus.Listener listener)
      • removeGpsStatusListener

        @Implementation
        protected void removeGpsStatusListener​(android.location.GpsStatus.Listener listener)
      • getGpsStatusListeners

        public java.util.List<android.location.GpsStatus.Listener> getGpsStatusListeners()
      • registerGnssStatusCallback

        @Implementation(minSdk=24)
        protected boolean registerGnssStatusCallback​(android.location.GnssStatus.Callback callback,
                                                     android.os.Handler handler)
      • unregisterGnssStatusCallback

        @Implementation(minSdk=24)
        protected void unregisterGnssStatusCallback​(android.location.GnssStatus.Callback callback)
      • sendGnssStatus

        public void sendGnssStatus​(android.location.GnssStatus status)
        Sends a GnssStatus to all registered GnssStatus.Callbacks.
      • addNmeaListener

        @Implementation(minSdk=24)
        protected boolean addNmeaListener​(android.location.OnNmeaMessageListener listener,
                                          android.os.Handler handler)
      • removeNmeaListener

        @Implementation(minSdk=24)
        protected void removeNmeaListener​(android.location.OnNmeaMessageListener listener)
      • sendNmeaMessage

        public void sendNmeaMessage​(java.lang.String message,
                                    long timestamp)
        Sends a NMEA message to all registered OnNmeaMessageListeners.
      • getRequestLocationUpdateListeners

        @Deprecated
        public java.util.List<android.location.LocationListener> getRequestLocationUpdateListeners()
        Deprecated.
      • simulateLocation

        public void simulateLocation​(android.location.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 java.util.List<android.location.LocationListener> getLocationUpdateListeners()
        Deprecated.
        Do not test listeners, instead use simulateLocation(Location) and test the results of those listeners being invoked.
        Retrieves a list of all currently registered listeners.
      • getLocationUpdateListeners

        @Deprecated
        public java.util.List<android.location.LocationListener> getLocationUpdateListeners​(java.lang.String provider)
        Deprecated.
        Do not test listeners, instead use simulateLocation(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 java.util.List<android.app.PendingIntent> getLocationUpdatePendingIntents()
        Deprecated.
        Do not test pending intents, instead use simulateLocation(Location) and test the results of those pending intent being invoked.
        Retrieves a list of all currently registered pending intents.
      • getLocationUpdatePendingIntents

        @Deprecated
        public java.util.List<android.app.PendingIntent> getLocationUpdatePendingIntents​(java.lang.String provider)
        Deprecated.
        Do not test pending intents, instead use simulateLocation(Location) and test the results of those pending intent being invoked.
        Retrieves a list of all currently registered pending intents for the given provider.