AirshipLocationManager extends AirshipComponent implements AirshipLocationClient { @Override protected void init() { super.init(); this.backgroundThread.start(); this.backgroundHandler = new Handler(this.backgroundThread.getLooper()); preferenceDataStore.addListener(preferenceChangeListener); activityMonitor.addApplicationListener(listener); updateServiceConnection(); airshipChannel.addChannelRegistrationPayloadExtender(new AirshipChannel.ChannelRegistrationPayloadExtender() { @NonNull @Override public ChannelRegistrationPayload.Builder extend(@NonNull ChannelRegistrationPayload.Builder builder) { if (isDataCollectionEnabled()) { return builder.setLocationSettings(isLocationUpdatesEnabled()); } return builder; } }); analytics.addHeaderDelegate(new Analytics.AnalyticsHeaderDelegate() { @NonNull @Override public Map<String, String> onCreateAnalyticsHeaders() { return createAnalyticsHeaders(); } }); } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  AirshipLocationManager(@NonNull Context context,
                                  @NonNull PreferenceDataStore preferenceDataStore,
                                  @NonNull AirshipChannel airshipChannel,
                                  @NonNull Analytics analytics); @VisibleForTesting  AirshipLocationManager(@NonNull final Context context,
                           @NonNull PreferenceDataStore preferenceDataStore,
                           @NonNull AirshipChannel airshipChannel,
                           @NonNull Analytics analytics,
                           @NonNull ActivityMonitor activityMonitor); @NonNull static AirshipLocationManager shared(); @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @AirshipComponentGroups.Group int getComponentGroup(); @Override boolean isLocationUpdatesEnabled(); @Override void setLocationUpdatesEnabled(boolean enabled); @Override boolean isBackgroundLocationAllowed(); @Override void setBackgroundLocationAllowed(boolean enabled); void setLocationRequestOptions(@Nullable LocationRequestOptions options); @NonNull LocationRequestOptions getLocationRequestOptions(); void addLocationListener(@NonNull LocationListener listener); void removeLocationListener(@NonNull LocationListener listener); @NonNull PendingResult<Location> requestSingleLocation(); @NonNull PendingResult<Location> requestSingleLocation(@NonNull final LocationRequestOptions requestOptions); @Override boolean isOptIn(); void recordLocation(@NonNull Location location, @Nullable LocationRequestOptions options, @LocationEvent.UpdateType int updateType);  }
@Test public void testAnalyticHeaders() { ArgumentCaptor<Analytics.AnalyticsHeaderDelegate> captor = ArgumentCaptor.forClass(Analytics.AnalyticsHeaderDelegate.class); locationManager.init(); verify(mockAnalytics).addHeaderDelegate(captor.capture()); Analytics.AnalyticsHeaderDelegate delegate = captor.getValue(); assertNotNull(delegate); Map<String, String> expectedHeaders = new HashMap<>(); expectedHeaders.put("X-UA-Location-Permission", "NOT_ALLOWED"); expectedHeaders.put("X-UA-Location-Service-Enabled", "false"); Map<String, String> headers = delegate.onCreateAnalyticsHeaders(); assertEquals(expectedHeaders, headers); }