Skip to content

Commit 09b7957

Browse files
authored
Fix RemoteConfig info initialization issues (#1639)
* Fix RemoteConfig info initialization issues * Update remote_config_android.cc
1 parent 66a9570 commit 09b7957

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

release_build_files/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ code.
635635
- Changes
636636
- Messaging: Changed SetListener to send the last token received
637637
before the listener was set.
638+
- Remote Config: Fixed ConfigInfo fields to default to 0 when
639+
not throttled or having previous fetch data.
638640

639641
### 12.2.0
640642
- Changes

remote_config/src/android/remote_config_android.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,15 @@ static void JConfigInfoToConfigInfo(JNIEnv* env, jobject jinfo,
496496
ConfigInfo* info) {
497497
FIREBASE_DEV_ASSERT(env->IsInstanceOf(jinfo, config_info::GetClass()));
498498

499-
info->fetch_time = env->CallLongMethod(
499+
int64_t fetch_time = env->CallLongMethod(
500500
jinfo, config_info::GetMethodId(config_info::kGetFetchTimeMillis));
501+
// The C++ fetch_time is a uint64_t, so if we are given a negative number,
502+
// use 0 instead, to prevent getting a very large number.
503+
if (fetch_time < 0) {
504+
fetch_time = 0;
505+
}
506+
info->fetch_time = fetch_time;
507+
util::CheckAndClearJniExceptions(env);
501508
int64_t status_code = env->CallIntMethod(
502509
jinfo, config_info::GetMethodId(config_info::kGetLastFetchStatus));
503510
switch (status_code) {

remote_config/src/include/firebase/remote_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct ConfigUpdate {
9494
/// Normally returned as a result of the GetInfo() function.
9595
struct ConfigInfo {
9696
/// @brief The time (in milliseconds since the epoch) that the last fetch
97-
/// operation completed.
97+
/// operation completed. 0 if no fetch attempt has been made yet.
9898
uint64_t fetch_time;
9999

100100
/// @brief The status of the last fetch request.

remote_config/src/ios/remote_config_ios.mm

+6-5
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@
5252
static NSString *true_pattern = @"^(1|true|t|yes|y|on)$";
5353
static NSString *false_pattern = @"^(0|false|f|no|n|off|)$";
5454

55-
// If a fetch was throttled, this is set to the time when the throttling is
56-
// finished, in milliseconds since epoch.
57-
static NSNumber *g_throttled_end_time = @0;
58-
5955
// Saved default keys.
6056
static std::vector<std::string> *g_default_keys = nullptr;
6157

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

202203
namespace internal {
203204
RemoteConfigInternal::RemoteConfigInternal(const firebase::App &app)
204-
: app_(app), future_impl_(kRemoteConfigFnCount) {
205+
: app_(app), future_impl_(kRemoteConfigFnCount), throttled_end_time_in_sec_(0) {
205206
FIRApp *platform_app = app_.GetPlatformApp();
206207
impl_.reset(new FIRRemoteConfigPointer([FIRRemoteConfig remoteConfigWithApp:platform_app]));
207208
}

0 commit comments

Comments
 (0)