Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public static FirebasePerformance getInstance() {
* @param firebaseRemoteConfigProvider The {@link Provider} for FirebaseRemoteConfig instance.
* @param firebaseInstallationsApi The FirebaseInstallationsApi instance.
* @param transportFactoryProvider The {@link Provider} for the the {@link TransportFactory}.
* @param remoteConfigManager The RemoteConfigManager instance.
* @param configResolver The ConfigResolver instance.
* @param sessionManager The SessionManager instance.
*/
Expand All @@ -162,7 +161,6 @@ public static FirebasePerformance getInstance() {
Provider<RemoteConfigComponent> firebaseRemoteConfigProvider,
FirebaseInstallationsApi firebaseInstallationsApi,
Provider<TransportFactory> transportFactoryProvider,
RemoteConfigManager remoteConfigManager,
ConfigResolver configResolver,
SessionManager sessionManager) {

Expand All @@ -185,8 +183,8 @@ public static FirebasePerformance getInstance() {
// TODO(b/110178816): Explore moving off of main thread.
mMetadataBundle = extractMetadata(appContext);

remoteConfigManager.setFirebaseRemoteConfigProvider(firebaseRemoteConfigProvider);
this.configResolver = configResolver;
this.configResolver.getRemoteConfigManager().setFirebaseRemoteConfigProvider(firebaseRemoteConfigProvider);
this.configResolver.setMetadataBundle(mMetadataBundle);
this.configResolver.setApplicationContext(appContext);
sessionManager.setApplicationContext(appContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ConfigResolver {
private static volatile ConfigResolver instance;

// Configuration Storage objects.
private final RemoteConfigManager remoteConfigManager;
private RemoteConfigManager remoteConfigManager;
private ImmutableBundle metadataBundle;
private DeviceCacheManager deviceCacheManager;

Expand All @@ -75,7 +75,7 @@ public ConfigResolver(
@Nullable ImmutableBundle metadataBundle,
@Nullable DeviceCacheManager deviceCacheManager) {
this.remoteConfigManager =
remoteConfigManager == null ? RemoteConfigManager.getInstance() : remoteConfigManager;
remoteConfigManager != null ? remoteConfigManager : new RemoteConfigManager();
this.metadataBundle = metadataBundle == null ? new ImmutableBundle() : metadataBundle;
this.deviceCacheManager =
deviceCacheManager == null ? DeviceCacheManager.getInstance() : deviceCacheManager;
Expand All @@ -98,6 +98,11 @@ public void setDeviceCacheManager(DeviceCacheManager deviceCacheManager) {
this.deviceCacheManager = deviceCacheManager;
}

@VisibleForTesting
public void setRemoteConfigManager(RemoteConfigManager remoteConfigManager) {
this.remoteConfigManager = remoteConfigManager;
}

public void setContentProviderContext(Context context) {
setApplicationContext(context.getApplicationContext());
}
Expand Down Expand Up @@ -916,4 +921,8 @@ private boolean isGaugeCaptureFrequencyMsValid(long frequencyMilliseconds) {
private boolean isSessionsMaxDurationMinutesValid(long maxDurationMin) {
return maxDurationMin > 0;
}

public RemoteConfigManager getRemoteConfigManager() {
return remoteConfigManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
public class RemoteConfigManager {

private static final AndroidLogger logger = AndroidLogger.getInstance();
private static final RemoteConfigManager instance = new RemoteConfigManager();
private static final String FIREPERF_FRC_NAMESPACE_NAME = "fireperf";
private static final long TIME_AFTER_WHICH_A_FETCH_IS_CONSIDERED_STALE_MS =
TimeUnit.HOURS.toMillis(12);
Expand All @@ -67,7 +66,7 @@ public class RemoteConfigManager {

// TODO(b/258263016): Migrate to go/firebase-android-executors
@SuppressLint("ThreadPoolCreation")
private RemoteConfigManager() {
public RemoteConfigManager() {
this(
DeviceCacheManager.getInstance(),
new ThreadPoolExecutor(
Expand Down Expand Up @@ -96,11 +95,6 @@ private RemoteConfigManager() {
this.remoteConfigFetchDelayInMs = remoteConfigFetchDelayInMs;
}

/** Gets the singleton instance. */
public static RemoteConfigManager getInstance() {
return instance;
}

/**
* Sets the {@link Provider} for {@link RemoteConfigComponent} from which we can extract the
* {@link FirebaseRemoteConfig} instance whenever it gets available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ Provider<TransportFactory> providesTransportFactoryProvider() {
return transportFactoryProvider;
}

@Provides
RemoteConfigManager providesRemoteConfigManager() {
return RemoteConfigManager.getInstance();
}

@Provides
ConfigResolver providesConfigResolver() {
return ConfigResolver.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class FirebasePerformanceTest {
"firebase_performance_collection_deactivated";
private static final String FIREPERF_ENABLED_KEY = "firebase_performance_collection_enabled";

@Nullable private RemoteConfigManager spyRemoteConfigManager = null;
@Nullable private RemoteConfigManager spyRemoteConfigManager = spy(new RemoteConfigManager());
@Nullable private ConfigResolver spyConfigResolver = null;

@Nullable private SessionManager spySessionManager = null;
Expand Down Expand Up @@ -100,9 +100,10 @@ public void setUp() throws NameNotFoundException {
sharedPreferences.edit().clear().commit();
DeviceCacheManager.clearInstance();

spyRemoteConfigManager = spy(RemoteConfigManager.getInstance());
ConfigResolver.clearInstance();
spyConfigResolver = spy(ConfigResolver.getInstance());
ConfigResolver configResolver = ConfigResolver.getInstance();
configResolver.setRemoteConfigManager(spyRemoteConfigManager);
spyConfigResolver = spy(configResolver);

spySessionManager = spy(SessionManager.getInstance());
fakeDirectExecutorService = new FakeDirectExecutorService();
Expand Down Expand Up @@ -470,6 +471,7 @@ public void firebasePerformanceInitialization_providesRcProvider_remoteConfigMan
() -> FirebaseApp.getInstance().get(TransportFactory.class));

verify(spyRemoteConfigManager).setFirebaseRemoteConfigProvider(firebaseRemoteConfigProvider);
assertThat(spyRemoteConfigManager.isFirebaseRemoteConfigAvailable()).isTrue();
}

@Test
Expand Down Expand Up @@ -577,7 +579,6 @@ private FirebasePerformance initializeFirebasePerformancePreferences(
firebaseRemoteConfigProvider,
mock(FirebaseInstallationsApi.class),
transportFactoryProvider,
spyRemoteConfigManager,
spyConfigResolver,
spySessionManager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void setUp() {

@Test
public void getInstance_verifiesSingleton() {
RemoteConfigManager instanceOne = RemoteConfigManager.getInstance();
RemoteConfigManager instanceTwo = RemoteConfigManager.getInstance();
RemoteConfigManager instanceOne = ConfigResolver.getInstance().getRemoteConfigManager();
RemoteConfigManager instanceTwo = ConfigResolver.getInstance().getRemoteConfigManager();

assertThat(instanceOne).isSameInstanceAs(instanceTwo);
}
Expand Down