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
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
2828namespace firebase {
2929namespace 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