Skip to content

fix(android,remote_config): ensureInitialized() task should ignore return value (fixes #5222) #5467

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 3 commits into from
Mar 25, 2021

Conversation

Salakar
Copy link
Member

@Salakar Salakar commented Mar 25, 2021

Description

Currently on Android the task returned by RemoteConfig.ensureInitialized() returns a FirebaseRemoteConfigInfo instance which gets sent to the Flutter standard message codec and causes a crash as this isn't a supported value that can be serialized by the codec.

As we don't at this point care about the value of the task result, I've wrapped the task in a whenAll which will just return void when completed.

Related Issues

Fixes #5222

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

Salakar added 3 commits March 25, 2021 13:15
…turn value (fixes #5222)

Currently on Android the task returned by RemoteConfig.ensureInitialized() returns a `FirebaseRemoteConfigInfo` instance which gets sent to the Flutter standard message codec and causes a crash as this isn't a supported value that can be serialized by the codec. As we don't at this point care about the value of the task result, I've wrapped then task in a `whenAll` which will just return void when completed.
@google-cla google-cla bot added the cla: yes label Mar 25, 2021
Comment on lines +136 to +137
int fetchTimeout = Objects.requireNonNull(call.argument("fetchTimeout"));
int minimumFetchInterval = Objects.requireNonNull(call.argument("minimumFetchInterval"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never null as these come from Dart where they are required values.

@@ -144,7 +145,7 @@ public void onMethodCall(MethodCall call, final MethodChannel.Result result) {
}
case "RemoteConfig#setDefaults":
{
Map<String, Object> defaults = call.argument("defaults");
Map<String, Object> defaults = Objects.requireNonNull(call.argument("defaults"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never null as this comes from Dart where it is a required value.

case FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED:
return "throttled";
case FirebaseRemoteConfig.LAST_FETCH_STATUS_NO_FETCH_YET:
return "noFetchYet";
case FirebaseRemoteConfig.LAST_FETCH_STATUS_FAILURE:
default:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate return cases, default and failure return the same thing

case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT:
return "default";
case FirebaseRemoteConfig.VALUE_SOURCE_REMOTE:
return "remote";
case FirebaseRemoteConfig.VALUE_SOURCE_STATIC:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate return cases, default and static return the same thing

@@ -56,8 +58,7 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) {
cachedThreadPool,
() -> {
Map<String, Object> configProperties = getConfigProperties(remoteConfig);
Map<String, Object> configValues = new HashMap<>();
configValues.putAll(configProperties);
Map<String, Object> configValues = new HashMap<>(configProperties);
Copy link
Member Author

@Salakar Salakar Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the initial values direct to the constructor. Previous putAll call after construction was unnecessary in this case.

Task<?> methodCallTask;
FirebaseRemoteConfig remoteConfig = getRemoteConfig(call.arguments());

switch (call.method) {
case "RemoteConfig#ensureInitialized":
{
methodCallTask = remoteConfig.ensureInitialized();
methodCallTask = Tasks.whenAll(remoteConfig.ensureInitialized());
Copy link
Member Author

@Salakar Salakar Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THE FIX: Currently on Android the task returned by RemoteConfig.ensureInitialized() returns a FirebaseRemoteConfigInfo instance which gets sent to the Flutter standard message codec and causes a crash as this isn't a supported value that can be serialized by the codec.

As we don't at this point care about the value of the task result, I've wrapped the task in a whenAll which will just return void when completed.

@@ -22,6 +22,7 @@ void main() {
'welcome': 'default welcome',
'hello': 'default hello',
});
await remoteConfig.ensureInitialized();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a call to the previously crashing method to the tests setup - this is why we haven't seen the crash on tests.

Copy link
Member

@russellwheatley russellwheatley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided it passes CI, LGTM.

@Salakar Salakar merged commit 879da23 into master Mar 25, 2021
@Salakar Salakar deleted the @salakar/fix-5222 branch March 25, 2021 22:59
@firebase firebase locked and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [remote_config] java.lang.IllegalArgumentException: Unsupported value: com.google.firebase.remoteconfig.internal.FirebaseRemoteConfigInfoImpl
2 participants