12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- #include " remote_config/src/include/firebase/remote_config.h"
16
-
17
15
#include < assert.h>
16
+
18
17
#include < set>
19
18
#include < string>
20
19
24
23
#include " app/src/util.h"
25
24
#include " app/src/util_android.h"
26
25
#include " remote_config/src/common.h"
26
+ #include " remote_config/src/include/firebase/remote_config.h"
27
27
28
28
namespace firebase {
29
29
namespace remote_config {
@@ -308,8 +308,19 @@ static jobject VariantToJavaObject(JNIEnv* env, const Variant& variant) {
308
308
} else if (variant.is_string ()) {
309
309
return env->NewStringUTF (variant.string_value ());
310
310
} 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()));
313
324
} else {
314
325
return nullptr ;
315
326
}
@@ -588,7 +599,6 @@ std::vector<unsigned char> GetData(const char* key) {
588
599
config::GetMethodId (config::kGetByteArray ), key_string);
589
600
590
601
bool failed = CheckKeyRetrievalLogError (env, key, " vector" );
591
-
592
602
env->DeleteLocalRef (key_string);
593
603
if (!failed) value = util::JniByteArrayToVector (env, array);
594
604
return value;
@@ -668,9 +678,9 @@ static void FutureCallback(JNIEnv* env, jobject result,
668
678
auto * future_handle =
669
679
reinterpret_cast <SafeFutureHandle<void >*>(callback_data);
670
680
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 );
674
684
}
675
685
delete future_handle;
676
686
}
@@ -685,9 +695,9 @@ Future<void> Fetch(uint64_t cache_expiration_in_seconds) {
685
695
g_remote_config_class_instance, config::GetMethodId (config::kFetch ),
686
696
static_cast <jlong>(cache_expiration_in_seconds));
687
697
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 );
691
701
692
702
env->DeleteLocalRef (task);
693
703
return MakeFuture<void >(api, handle);
0 commit comments