Skip to content

Commit

Permalink
fix(android): Prevent crash in restoreInstanceState if bundleData is …
Browse files Browse the repository at this point in the history
…null (#5289)



Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
  • Loading branch information
hermitdemschoenenleben and jcesarmobile committed Dec 2, 2021
1 parent ad3f4e6 commit 622d62f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,10 @@ public void restoreInstanceState(Bundle savedInstanceState) {
// Let the plugin restore any state it needs
Bundle bundleData = savedInstanceState.getBundle(BUNDLE_PLUGIN_CALL_BUNDLE_KEY);
PluginHandle lastPlugin = getPlugin(lastPluginId);
if (lastPlugin != null) {
if (bundleData != null && lastPlugin != null) {
lastPlugin.getInstance().restoreState(bundleData);
} else {
Logger.error("Unable to restore last plugin call");
}
}
}
Expand All @@ -823,10 +825,15 @@ public void saveInstanceState(Bundle outState) {
PluginHandle handle = getPlugin(call.getPluginId());

if (handle != null) {
outState.putString(BUNDLE_LAST_PLUGIN_ID_KEY, call.getPluginId());
outState.putString(BUNDLE_LAST_PLUGIN_CALL_METHOD_NAME_KEY, call.getMethodName());
outState.putString(BUNDLE_PLUGIN_CALL_OPTIONS_SAVED_KEY, call.getData().toString());
outState.putBundle(BUNDLE_PLUGIN_CALL_BUNDLE_KEY, handle.getInstance().saveInstanceState());
Bundle bundle = handle.getInstance().saveInstanceState();
if (bundle != null) {
outState.putString(BUNDLE_LAST_PLUGIN_ID_KEY, call.getPluginId());
outState.putString(BUNDLE_LAST_PLUGIN_CALL_METHOD_NAME_KEY, call.getMethodName());
outState.putString(BUNDLE_PLUGIN_CALL_OPTIONS_SAVED_KEY, call.getData().toString());
outState.putBundle(BUNDLE_PLUGIN_CALL_BUNDLE_KEY, bundle);
} else {
Logger.error("Couldn't save last " + call.getPluginId() + "'s Plugin " + call.getMethodName() + " call");
}
}
}
}
Expand Down

0 comments on commit 622d62f

Please sign in to comment.