Skip to content

Fix RemoteConfig info initialization issues #1639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2024
Merged
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
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
9 changes: 8 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,15 @@ 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;
util::CheckAndClearJniExceptions(env);
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
Loading