Skip to content

Commit 564bcde

Browse files
committed
Fix the implementation.
1 parent f050111 commit 564bcde

File tree

3 files changed

+74
-7
lines changed

3 files changed

+74
-7
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerfEarly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void onSessionChanged(@NonNull SessionDetails sessionDetails) {
7171
public boolean isDataCollectionEnabled() {
7272
// If there is no cached config data available for data collection, be conservative.
7373
// Return false.
74-
if (!configResolver.isCollectionEnabledCacheAvailable()) {
74+
if (!configResolver.isCollectionEnabledConfigValueAvailable()) {
7575
return false;
7676
}
7777
return ConfigResolver.getInstance().isPerformanceMonitoringEnabled();

firebase-perf/src/main/java/com/google/firebase/perf/config/ConfigResolver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,13 @@ public Boolean getIsPerformanceCollectionEnabled() {
156156
return null;
157157
}
158158

159-
public boolean isCollectionEnabledCacheAvailable() {
159+
/**
160+
* Returns whether data collection flag is fetched either through device cache or remote config.
161+
*/
162+
public boolean isCollectionEnabledConfigValueAvailable() {
163+
Optional<Boolean> remoteConfigValue = getRemoteConfigBoolean(SdkEnabled.getInstance());
160164
Optional<Boolean> deviceCacheValue = getDeviceCacheBoolean(CollectionEnabled.getInstance());
161-
return deviceCacheValue.isAvailable();
165+
return deviceCacheValue.isAvailable() || remoteConfigValue.isAvailable();
162166
}
163167

164168
/** Returns whether developers have deactivated Firebase Performance event collection. */

firebase-perf/src/test/java/com/google/firebase/perf/config/ConfigResolverTest.java

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,17 +498,80 @@ public void getIsServiceCollectionEnabled_sdkDisabledVersionFlagNoFrc_returnDefa
498498
}
499499

500500
@Test
501-
public void getIsPerformanceCollectionCacheAvailable_noDeviceCache_returnsFalse() {
501+
public void
502+
getIsPerformanceCollectionConfigValueAvailable_noDeviceCacheNoRemoteConfig_returnsFalse() {
503+
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
504+
.thenReturn(Optional.absent());
505+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
506+
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
507+
.thenReturn(Optional.absent());
508+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isFalse();
509+
}
510+
511+
@Test
512+
public void
513+
getIsPerformanceCollectionConfigValueAvailable_noDeviceCacheHasRemoteConfigValueFalse_returnsTrue() {
502514
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
503515
.thenReturn(Optional.absent());
504-
assertThat(testConfigResolver.isCollectionEnabledCacheAvailable()).isFalse();
516+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
517+
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
518+
.thenReturn(Optional.of(false));
519+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
505520
}
506521

507522
@Test
508-
public void getIsPerformanceCollectionCacheAvailable_hasDeviceCache_returnsTrue() {
523+
public void
524+
getIsPerformanceCollectionConfigValueAvailable_HasDeviceCacheNoRemoteConfigValue_returnsTrue() {
509525
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
526+
.thenReturn(Optional.of(false));
527+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
528+
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
529+
.thenReturn(Optional.absent());
530+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
531+
}
532+
533+
@Test
534+
public void
535+
getIsPerformanceCollectionConfigValueAvailable_HasDeviceCacheFalseHasRemoteConfigValueFalse_returnsTrue() {
536+
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
537+
.thenReturn(Optional.of(false));
538+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
539+
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
540+
.thenReturn(Optional.of(false));
541+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
542+
}
543+
544+
@Test
545+
public void
546+
getIsPerformanceCollectionConfigValueAvailable_noDeviceCacheHasRemoteConfigValueTrue_returnsTrue() {
547+
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
548+
.thenReturn(Optional.of(false));
549+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
550+
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
551+
.thenReturn(Optional.of(true));
552+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
553+
}
554+
555+
@Test
556+
public void
557+
getIsPerformanceCollectionConfigValueAvailable_hasDeviceCacheHasRemoteConfigValueFalse_returnsTrue() {
558+
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
559+
.thenReturn(Optional.of(true));
560+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
561+
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
562+
.thenReturn(Optional.of(false));
563+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
564+
}
565+
566+
@Test
567+
public void
568+
getIsPerformanceCollectionConfigValueAvailable_hasDeviceCacheHasRemoteConfig_returnsTrue() {
569+
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
570+
.thenReturn(Optional.of(true));
571+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
572+
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
510573
.thenReturn(Optional.of(true));
511-
assertThat(testConfigResolver.isCollectionEnabledCacheAvailable()).isTrue();
574+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
512575
}
513576

514577
@Test

0 commit comments

Comments
 (0)