Skip to content

Commit eab9e30

Browse files
jonsimantova-maurice
authored andcommitted
Updated Remote Config integration test to test blob and string types properly.
Also work around a bug in Remote Config for Android in how the Android SDK handles Variants of type Blob passed into SetDefaults(). PiperOrigin-RevId: 270152723
1 parent 51dd1ac commit eab9e30

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

remote_config/src/remote_config_android.cc

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "remote_config/src/include/firebase/remote_config.h"
16-
1715
#include <assert.h>
16+
1817
#include <set>
1918
#include <string>
2019

@@ -24,6 +23,7 @@
2423
#include "app/src/util.h"
2524
#include "app/src/util_android.h"
2625
#include "remote_config/src/common.h"
26+
#include "remote_config/src/include/firebase/remote_config.h"
2727

2828
namespace firebase {
2929
namespace remote_config {
@@ -308,8 +308,19 @@ static jobject VariantToJavaObject(JNIEnv* env, const Variant& variant) {
308308
} else if (variant.is_string()) {
309309
return env->NewStringUTF(variant.string_value());
310310
} else if (variant.is_blob()) {
311-
return static_cast<jobject>(util::ByteBufferToJavaByteArray(
312-
env, variant.blob_data(), variant.blob_size()));
311+
// Workaround a Remote Config Android SDK bug: rather than using a byte[]
312+
// array, use a String containing binary data instead.
313+
jchar* unicode_bytes = new jchar[variant.blob_size()];
314+
for (int i = 0; i < variant.blob_size(); ++i) {
315+
unicode_bytes[i] = variant.blob_data()[i];
316+
}
317+
jobject the_string = env->NewString(unicode_bytes, variant.blob_size());
318+
delete[] unicode_bytes;
319+
return the_string;
320+
// TODO(b/141322200) Remote the code above and restore the code below once
321+
// this bug is fixed.
322+
// return static_cast<jobject>(util::ByteBufferToJavaByteArray(env,
323+
// variant.blob_data(), variant.blob_size()));
313324
} else {
314325
return nullptr;
315326
}
@@ -588,7 +599,6 @@ std::vector<unsigned char> GetData(const char* key) {
588599
config::GetMethodId(config::kGetByteArray), key_string);
589600

590601
bool failed = CheckKeyRetrievalLogError(env, key, "vector");
591-
592602
env->DeleteLocalRef(key_string);
593603
if (!failed) value = util::JniByteArrayToVector(env, array);
594604
return value;
@@ -668,9 +678,9 @@ static void FutureCallback(JNIEnv* env, jobject result,
668678
auto* future_handle =
669679
reinterpret_cast<SafeFutureHandle<void>*>(callback_data);
670680
if (future_data) {
671-
future_data->api()->Complete(*future_handle,
672-
success ? kFetchFutureStatusSuccess
673-
: kFetchFutureStatusFailure);
681+
future_data->api()->Complete(
682+
*future_handle,
683+
success ? kFetchFutureStatusSuccess : kFetchFutureStatusFailure);
674684
}
675685
delete future_handle;
676686
}
@@ -685,9 +695,9 @@ Future<void> Fetch(uint64_t cache_expiration_in_seconds) {
685695
g_remote_config_class_instance, config::GetMethodId(config::kFetch),
686696
static_cast<jlong>(cache_expiration_in_seconds));
687697

688-
util::RegisterCallbackOnTask(
689-
env, task, FutureCallback, new SafeFutureHandle<void>(handle),
690-
kApiIdentifier);
698+
util::RegisterCallbackOnTask(env, task, FutureCallback,
699+
new SafeFutureHandle<void>(handle),
700+
kApiIdentifier);
691701

692702
env->DeleteLocalRef(task);
693703
return MakeFuture<void>(api, handle);

0 commit comments

Comments
 (0)