Skip to content

Commit 114e740

Browse files
authored
Merge pull request #674 from react-native-webrtc/lighten_module_constructor
Move fetchStoredSettings outside of the RNCallKeepModule constructor to avoid race condition with singleton
2 parents 332abdd + 1b59802 commit 114e740

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public static RNCallKeepModule getInstance(ReactApplicationContext reactContext,
130130
if (instance == null) {
131131
Log.d(TAG, "[RNCallKeepModule] getInstance : " + (reactContext == null ? "null" : "ok"));
132132
instance = new RNCallKeepModule(reactContext);
133+
instance.registerReceiver();
134+
instance.fetchStoredSettings(reactContext);
133135
}
134136
if (realContext) {
135137
instance.setContext(reactContext);
@@ -151,8 +153,6 @@ private RNCallKeepModule(ReactApplicationContext reactContext) {
151153

152154
this.reactContext = reactContext;
153155
delayedEvents = new WritableNativeArray();
154-
this.registerReceiver();
155-
this.fetchStoredSettings(reactContext);
156156
}
157157

158158
private boolean isSelfManaged() {
@@ -1024,7 +1024,7 @@ private boolean hasPhoneAccount() {
10241024
telecomManager.getPhoneAccount(handle).isEnabled();
10251025
}
10261026

1027-
private void registerReceiver() {
1027+
protected void registerReceiver() {
10281028
if (!isReceiverRegistered) {
10291029
isReceiverRegistered = true;
10301030
voiceBroadcastReceiver = new VoiceBroadcastReceiver();
@@ -1078,7 +1078,7 @@ private WritableMap storeSettings(ReadableMap options) {
10781078
return MapUtils.readableToWritableMap(options);
10791079
}
10801080

1081-
private static void fetchStoredSettings(@Nullable Context fromContext) {
1081+
protected static void fetchStoredSettings(@Nullable Context fromContext) {
10821082
Context context = fromContext != null ? fromContext : instance.getAppContext();
10831083
if (instance == null && context == null) {
10841084
Log.w(TAG, "[RNCallKeepModule][fetchStoredSettings] no instance nor fromContext.");

0 commit comments

Comments
 (0)