Skip to content

Commit

Permalink
Merge c2e289a into da631d2
Browse files Browse the repository at this point in the history
  • Loading branch information
visumickey committed Aug 15, 2023
2 parents da631d2 + c2e289a commit 26e2d9a
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
1 change: 1 addition & 0 deletions firebase-perf/CHANGELOG.md
@@ -1,4 +1,5 @@
# Unreleased
* [fixed] Make fireperf data collection state is reliable for Firebase Sessions library.

# 20.4.0
* [feature] Integrated with Firebase sessions library to enable upcoming features related to
Expand Down
Expand Up @@ -69,8 +69,12 @@ public void onSessionChanged(@NonNull SessionDetails sessionDetails) {

@Override
public boolean isDataCollectionEnabled() {
// TODO(b/289036760): Get configResolver to read metadata by here.
return false;
// If there is no cached config data available for data collection, be conservative.
// Return false.
if (!configResolver.isCollectionEnabledConfigValueAvailable()) {
return false;
}
return ConfigResolver.getInstance().isPerformanceMonitoringEnabled();
}

@NonNull
Expand Down
Expand Up @@ -156,6 +156,15 @@ public Boolean getIsPerformanceCollectionEnabled() {
return null;
}

/**
* Returns whether data collection flag is fetched either through device cache or remote config.
*/
public boolean isCollectionEnabledConfigValueAvailable() {
Optional<Boolean> remoteConfigValue = getRemoteConfigBoolean(SdkEnabled.getInstance());
Optional<Boolean> deviceCacheValue = getDeviceCacheBoolean(CollectionEnabled.getInstance());
return deviceCacheValue.isAvailable() || remoteConfigValue.isAvailable();
}

/** Returns whether developers have deactivated Firebase Performance event collection. */
@Nullable
public Boolean getIsPerformanceCollectionDeactivated() {
Expand Down
Expand Up @@ -497,6 +497,83 @@ public void getIsServiceCollectionEnabled_sdkDisabledVersionFlagNoFrc_returnDefa
assertThat(testConfigResolver.getIsServiceCollectionEnabled()).isTrue();
}

@Test
public void
getIsPerformanceCollectionConfigValueAvailable_noDeviceCacheNoRemoteConfig_returnsFalse() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
.thenReturn(Optional.absent());
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
.thenReturn(Optional.absent());
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isFalse();
}

@Test
public void
getIsPerformanceCollectionConfigValueAvailable_noDeviceCacheHasRemoteConfigValueFalse_returnsTrue() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
.thenReturn(Optional.absent());
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
.thenReturn(Optional.of(false));
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
}

@Test
public void
getIsPerformanceCollectionConfigValueAvailable_HasDeviceCacheNoRemoteConfigValue_returnsTrue() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
.thenReturn(Optional.of(false));
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
.thenReturn(Optional.absent());
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
}

@Test
public void
getIsPerformanceCollectionConfigValueAvailable_HasDeviceCacheFalseHasRemoteConfigValueFalse_returnsTrue() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
.thenReturn(Optional.of(false));
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
.thenReturn(Optional.of(false));
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
}

@Test
public void
getIsPerformanceCollectionConfigValueAvailable_noDeviceCacheHasRemoteConfigValueTrue_returnsTrue() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
.thenReturn(Optional.of(false));
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
.thenReturn(Optional.of(true));
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
}

@Test
public void
getIsPerformanceCollectionConfigValueAvailable_hasDeviceCacheHasRemoteConfigValueFalse_returnsTrue() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
.thenReturn(Optional.of(true));
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
.thenReturn(Optional.of(false));
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
}

@Test
public void
getIsPerformanceCollectionConfigValueAvailable_hasDeviceCacheHasRemoteConfig_returnsTrue() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
.thenReturn(Optional.of(true));
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(false);
when(mockRemoteConfigManager.getBoolean(FIREBASE_PERFORMANCE_SDK_ENABLED_FRC_KEY))
.thenReturn(Optional.of(true));
assertThat(testConfigResolver.isCollectionEnabledConfigValueAvailable()).isTrue();
}

@Test
public void getIsPerformanceCollectionEnabled_notDeviceCacheOrMetadata_returnsNull() {
when(mockDeviceCacheManager.getBoolean(FIREBASE_PERFORMANCE_COLLECTION_ENABLED_CACHE_KEY))
Expand Down

0 comments on commit 26e2d9a

Please sign in to comment.