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)
      • getProviderProperties

        @Implementation(minSdk=31)
        @Nullable
        protected Object getProviderProperties​(Object providerStr)
      • hasProvider

        @Implementation(minSdk=31)
        protected boolean hasProvider​(String provider)
      • 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. This overload functions for all Android SDK levels.
      • 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)
      • isLocationEnabled

        @Implementation(minSdk=28)
        protected boolean isLocationEnabled()
      • setLocationEnabledForUser

        @Implementation(minSdk=28)
        protected void setLocationEnabledForUser​(boolean enabled,
                                                 UserHandle userHandle)
      • getLastKnownLocation

        @Implementation
        @Nullable
        protected Location getLastKnownLocation​(String 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=19)
        protected void requestLocationUpdates​(@Nullable
                                              LocationRequest request,
                                              PendingIntent pendingIntent)
      • removeUpdates

        @Implementation
        protected void removeUpdates​(LocationListener listener)
      • removeUpdates

        @Implementation
        protected void removeUpdates​(PendingIntent pendingIntent)
      • requestFlush

        @Implementation(minSdk=31)
        protected void requestFlush​(String provider,
                                    LocationListener listener,
                                    int requestCode)
      • requestFlush

        @Implementation(minSdk=31)
        protected void requestFlush​(String provider,
                                    PendingIntent pendingIntent,
                                    int requestCode)
      • getLocationRequests

        public List<LocationRequest> getLocationRequests​(String provider)
        Returns the list of LocationRequest currently registered under the given provider. Clients compiled against the public Android SDK should only use this method on S+, clients compiled against the system Android SDK may only use this method on Kitkat+.

        Prior to Android S LocationRequest equality is not well defined, so prefer using getLegacyLocationRequests(String) instead if equality is required for testing.

      • injectLocation

        @Implementation(minSdk=28)
        protected boolean injectLocation​(Location location)
      • getGnssBatchSize

        @Implementation(minSdk=26)
        protected int getGnssBatchSize()
      • setGnssBatchSize

        public void setGnssBatchSize​(int gnssBatchSize)
        Sets the GNSS hardware batch size. Values greater than 0 enables hardware GNSS batching APIs.
      • registerGnssBatchedLocationCallback

        @Implementation(minSdk=26)
        protected boolean registerGnssBatchedLocationCallback​(Object periodNanos,
                                                              Object wakeOnFifoFull,
                                                              Object callback,
                                                              Object handler)
      • flushGnssBatch

        @Implementation(minSdk=26)
        protected void flushGnssBatch()
      • unregisterGnssBatchedLocationCallback

        @Implementation(minSdk=26)
        protected boolean unregisterGnssBatchedLocationCallback​(Object callback)
      • getGnssHardwareModelName

        @Implementation(minSdk=28)
        @Nullable
        protected String getGnssHardwareModelName()
      • getGnssYearOfHardware

        @Implementation(minSdk=28)
        protected int getGnssYearOfHardware()
      • 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 listener)
      • unregisterGnssStatusCallback

        @Implementation(minSdk=24)
        protected void unregisterGnssStatusCallback​(GnssStatus.Callback listener)
      • simulateGnssStatusStarted

        public void simulateGnssStatusStarted()
        Simulates a GNSS status started event.
      • simulateGnssStatusFirstFix

        public void simulateGnssStatusFirstFix​(int ttff)
        Simulates a GNSS status first fix event.
      • simulateGnssStatus

        public void simulateGnssStatus​(GnssStatus status)
        Simulates a GNSS status event.
      • simulateGnssStatusStopped

        public void simulateGnssStatusStopped()
        Simulates a GNSS status stopped event.
      • removeNmeaListener

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

        public void simulateNmeaMessage​(String message,
                                        long timestamp)
        Simulates a NMEA message.
      • registerGnssMeasurementsCallback

        @Implementation(minSdk=30)
        protected boolean registerGnssMeasurementsCallback​(Object request,
                                                           Object executor,
                                                           Object callback)
      • unregisterGnssMeasurementsCallback

        @Implementation(minSdk=24)
        protected void unregisterGnssMeasurementsCallback​(GnssMeasurementsEvent.Callback listener)
      • simulateGnssMeasurementsEvent

        public void simulateGnssMeasurementsEvent​(GnssMeasurementsEvent event)
        Simulates a GNSS measurements event.
      • simulateGnssMeasurementsStatus

        public void simulateGnssMeasurementsStatus​(int status)
        Simulates a GNSS measurements status change.
      • registerAntennaInfoListener

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

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

        public void simulateGnssAntennaInfo​(List<GnssAntennaInfo> antennaInfos)
        Simulates a GNSS antenna info event.
      • simulateLocation

        public void simulateLocation​(Location location)
        A convenience function equivalent to invoking #simulateLocation(String, Location) with the provider of the given location.
      • simulateLocation

        public void simulateLocation​(String provider,
                                     Location... locations)
        Delivers to the given provider (which will be created if necessary) a new location which will be delivered to appropriate listeners and updates state accordingly. Delivery will ignore the enabled/disabled state of providers, unlike location on a real device.

        The location will also be delivered to the passive provider.

      • 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.
      • reset

        @Resetter
        public static void reset()