Class ShadowLocationManager

    • Constructor Detail

      • ShadowLocationManager

        public ShadowLocationManager()
    • Method Detail

      • getAllProviders

        @Implementation
        protected List<String> getAllProviders()
      • getProviders

        @Implementation
        protected List<String> getProviders​(boolean enabledOnly)
      • 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 via setLocationEnabled(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)
      • 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 pendingIntent)
      • requestSingleUpdate

        @Implementation
        protected void requestSingleUpdate​(Criteria criteria,
                                           PendingIntent pendingIntent)
      • 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

        @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)
      • 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)
      • removeNmeaListener

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

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

        @Implementation(minSdk=24)
        protected void unregisterGnssMeasurementsCallback​(GnssMeasurementsEvent.Callback callback)
      • registerAntennaInfoListener

        @Implementation(minSdk=30)
        protected boolean registerAntennaInfoListener​(Object executor,
                                                      Object listener)
      • unregisterAntennaInfoListener

        @Implementation(minSdk=30)
        protected void unregisterAntennaInfoListener​(Object listener)
      • sendGnssAntennaInfo

        public void sendGnssAntennaInfo​(List<?> antennaInfos)
        Sends a GNSS antenna info to all registered GnssAntennaInfo.Listeners.
      • 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 use simulateLocation(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 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 List<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 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.
        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

        @Resetter
        public static void reset()