Skip to content

Commit 26e2d9a

Browse files
authored
Merge c2e289a into da631d2
2 parents da631d2 + c2e289a commit 26e2d9a

File tree

4 files changed

+93
-2
lines changed

4 files changed

+93
-2
lines changed

firebase-perf/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [fixed] Make fireperf data collection state is reliable for Firebase Sessions library.
23

34
# 20.4.0
45
* [feature] Integrated with Firebase sessions library to enable upcoming features related to

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ public void onSessionChanged(@NonNull SessionDetails sessionDetails) {
6969

7070
@Override
7171
public boolean isDataCollectionEnabled() {
72-
// TODO(b/289036760): Get configResolver to read metadata by here.
73-
return false;
72+
// If there is no cached config data available for data collection, be conservative.
73+
// Return false.
74+
if (!configResolver.isCollectionEnabledConfigValueAvailable()) {
75+
return false;
76+
}
77+
return ConfigResolver.getInstance().isPerformanceMonitoringEnabled();
7478
}
7579

7680
@NonNull

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

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ public Boolean getIsPerformanceCollectionEnabled() {
156156
return null;
157157
}
158158

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());
164+
Optional<Boolean> deviceCacheValue = getDeviceCacheBoolean(CollectionEnabled.getInstance());
165+
return deviceCacheValue.isAvailable() || remoteConfigValue.isAvailable();
166+
}
167+
159168
/** Returns whether developers have deactivated Firebase Performance event collection. */
160169
@Nullable
161170
public Boolean getIsPerformanceCollectionDeactivated() {

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

+77
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,83 @@ public void getIsServiceCollectionEnabled_sdkDisabledVersionFlagNoFrc_returnDefa
497497
assertThat(testConfigResolver.getIsServiceCollectionEnabled()).isTrue();
498498
}
499499

500+
@Test
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() {
514+
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
515+
.thenReturn(Optional.absent());
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();
520+
}
521+
522+
@Test
523+
public void
524+
getIsPerformanceCollectionConfigValueAvailable_HasDeviceCacheNoRemoteConfigValue_returnsTrue() {
525+
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))
573+
.thenReturn(Optional.of(true));
574+
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
575+
}
576+
500577
@Test
501578
public void getIsPerformanceCollectionEnabled_notDeviceCacheOrMetadata_returnsNull() {
502579
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))

0 commit comments

Comments
 (0)