Skip to content

Commit

Permalink
Fix RemoteConfig info initialization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
a-maurice committed Sep 6, 2024
1 parent 66a9570 commit 5e70f1d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ code.
- Changes
- Messaging: Changed SetListener to send the last token received
before the listener was set.
- Remote Config: Fixed ConfigInfo fields to default to 0 when
not throttled or having previous fetch data.

### 12.2.0
- Changes
Expand Down
8 changes: 7 additions & 1 deletion remote_config/src/android/remote_config_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,14 @@ static void JConfigInfoToConfigInfo(JNIEnv* env, jobject jinfo,
ConfigInfo* info) {
FIREBASE_DEV_ASSERT(env->IsInstanceOf(jinfo, config_info::GetClass()));

info->fetch_time = env->CallLongMethod(
int64_t fetch_time = env->CallLongMethod(
jinfo, config_info::GetMethodId(config_info::kGetFetchTimeMillis));
// The C++ fetch_time is a uint64_t, so if we are given a negative number,
// use 0 instead, to prevent getting a very large number.
if (fetch_time < 0) {
fetch_time = 0;
}
info->fetch_time = fetch_time;
int64_t status_code = env->CallIntMethod(
jinfo, config_info::GetMethodId(config_info::kGetLastFetchStatus));
switch (status_code) {
Expand Down
2 changes: 1 addition & 1 deletion remote_config/src/include/firebase/remote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct ConfigUpdate {
/// Normally returned as a result of the GetInfo() function.
struct ConfigInfo {
/// @brief The time (in milliseconds since the epoch) that the last fetch
/// operation completed.
/// operation completed. 0 if no fetch attempt has been made yet.
uint64_t fetch_time;

/// @brief The status of the last fetch request.
Expand Down
11 changes: 6 additions & 5 deletions remote_config/src/ios/remote_config_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
static NSString *true_pattern = @"^(1|true|t|yes|y|on)$";
static NSString *false_pattern = @"^(0|false|f|no|n|off|)$";

// If a fetch was throttled, this is set to the time when the throttling is
// finished, in milliseconds since epoch.
static NSNumber *g_throttled_end_time = @0;

// Saved default keys.
static std::vector<std::string> *g_default_keys = nullptr;

Expand Down Expand Up @@ -148,6 +144,11 @@ static void GetInfoFromFIRRemoteConfig(FIRRemoteConfig *rc_instance, ConfigInfo
FIREBASE_DEV_ASSERT(out_info != nullptr);
out_info->fetch_time = round(rc_instance.lastFetchTime.timeIntervalSince1970 *
::firebase::internal::kMillisecondsPerSecond);
// The C++ throttled_end_time is a uint64_t, so if we are given a negative number,
// use 0 instead, to prevent getting a very large number.
if (throttled_end_time < 0) {
throttled_end_time = 0;
}
out_info->throttled_end_time = throttled_end_time * ::firebase::internal::kMillisecondsPerSecond;
switch (rc_instance.lastFetchStatus) {
case FIRRemoteConfigFetchStatusNoFetchYet:
Expand Down Expand Up @@ -201,7 +202,7 @@ static ConfigUpdate ConvertConfigUpdateKeys(NSSet<NSString *> *keys) {

namespace internal {
RemoteConfigInternal::RemoteConfigInternal(const firebase::App &app)
: app_(app), future_impl_(kRemoteConfigFnCount) {
: app_(app), future_impl_(kRemoteConfigFnCount), throttled_end_time_in_sec_(0) {
FIRApp *platform_app = app_.GetPlatformApp();
impl_.reset(new FIRRemoteConfigPointer([FIRRemoteConfig remoteConfigWithApp:platform_app]));
}
Expand Down

0 comments on commit 5e70f1d

Please sign in to comment.