Skip to content

Commit d5e3f08

Browse files
dryganetsfacebook-github-bot
authored andcommitted
Fix #6228: Crash in Android dialog module.
Summary: Android dialog module has a race condition as a result of which it crashes. See this issue: #6228. The mIsInForeground flag is set on UI thread but was used from the ReactMethod thread. Now all public methods of FragmentManagerHelper called from UI thread only. Asserts are added in appropriate places to prevent future regressions. Make sure that dialogs work after this change. It will be nearly impossible to reproduce the issue manually but automatic regression tests should be able to catch this. At least our tests were crashing on some dialog scenarios from time to time. [ANDROID] [MINOR] [BUGFIX] - Race condition fix in Android Dialogs module. Closes #17392 Reviewed By: achen1 Differential Revision: D6708787 Pulled By: mdvacca fbshipit-source-id: 99beb3ea3046286cc973f7677e98ff36f162b09b
1 parent 06ebaf2 commit d5e3f08

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/dialog/DialogModule.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.facebook.react.bridge.ReactMethod;
2929
import com.facebook.react.bridge.ReadableArray;
3030
import com.facebook.react.bridge.ReadableMap;
31+
import com.facebook.react.bridge.UiThreadUtil;
3132
import com.facebook.react.common.MapBuilder;
3233
import com.facebook.react.module.annotations.ReactModule;
3334

@@ -95,6 +96,7 @@ public FragmentManagerHelper(android.app.FragmentManager fragmentManager) {
9596
}
9697

9798
public void showPendingAlert() {
99+
UiThreadUtil.assertOnUiThread();
98100
if (mFragmentToShow == null) {
99101
return;
100102
}
@@ -123,6 +125,8 @@ private void dismissExisting() {
123125
}
124126

125127
public void showNewAlert(boolean isInForeground, Bundle arguments, Callback actionCallback) {
128+
UiThreadUtil.assertOnUiThread();
129+
126130
dismissExisting();
127131

128132
AlertFragmentListener actionListener =
@@ -218,8 +222,8 @@ public void onHostResume() {
218222
public void showAlert(
219223
ReadableMap options,
220224
Callback errorCallback,
221-
Callback actionCallback) {
222-
FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
225+
final Callback actionCallback) {
226+
final FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
223227
if (fragmentManagerHelper == null) {
224228
errorCallback.invoke("Tried to show an alert while not attached to an Activity");
225229
return;
@@ -253,7 +257,13 @@ public void showAlert(
253257
args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE));
254258
}
255259

256-
fragmentManagerHelper.showNewAlert(mIsInForeground, args, actionCallback);
260+
UiThreadUtil.runOnUiThread(new Runnable() {
261+
@Override
262+
public void run() {
263+
fragmentManagerHelper.showNewAlert(mIsInForeground, args, actionCallback);
264+
}
265+
});
266+
257267
}
258268

259269
/**

0 commit comments

Comments
 (0)