Skip to content

Commit cd36ba0

Browse files
authored
Merge pull request #582 from react-native-webrtc/fix_store_settings
Fix setSettings not updating _settings in RNCallkeepModule due to singleton
2 parents 8de84e3 + 641119e commit cd36ba0

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,11 @@ public void initializeTelecomManager() {
218218

219219
@ReactMethod
220220
public void setSettings(ReadableMap options) {
221+
Log.d(TAG, "[RNCallKeepModule] setSettings : " + options);
221222
if (options == null) {
222223
return;
223224
}
224-
Log.d(TAG, "[RNCallKeepModule] setSettings: " + options);
225-
storeSettings(options);
226-
227-
_settings = getSettings(null);
225+
_settings = storeSettings(options);
228226
}
229227

230228
@ReactMethod
@@ -239,7 +237,7 @@ public void removeListeners(Integer count) {
239237

240238
@ReactMethod
241239
public void setup(ReadableMap options) {
242-
Log.d(TAG, "[RNCallKeepModule] setup");
240+
Log.d(TAG, "[RNCallKeepModule] setup : " + options);
243241

244242
VoiceConnectionService.setAvailable(false);
245243
VoiceConnectionService.setInitialized(true);
@@ -270,7 +268,7 @@ public void setup(ReadableMap options) {
270268

271269
@ReactMethod
272270
public void registerPhoneAccount(ReadableMap options) {
273-
storeSettings(options);
271+
setSettings(options);
274272

275273
if (!isConnectionServiceAvailable()) {
276274
Log.w(TAG, "[RNCallKeepModule] registerPhoneAccount ignored due to no ConnectionService");
@@ -806,7 +804,7 @@ public void setForegroundServiceSettings(ReadableMap foregroundServerSettings) {
806804
settings.putMap("foregroundService", MapUtils.readableToWritableMap(foregroundServerSettings));
807805
}
808806

809-
storeSettings(settings);
807+
setSettings(settings);
810808
}
811809

812810
@ReactMethod
@@ -1056,11 +1054,11 @@ private Context getAppContext() {
10561054
}
10571055

10581056
// Store all callkeep settings in JSON
1059-
private void storeSettings(ReadableMap options) {
1060-
Context context = getInstance(null, false).getAppContext();
1057+
private WritableMap storeSettings(ReadableMap options) {
1058+
Context context = getAppContext();
10611059
if (context == null) {
10621060
Log.w(TAG, "[RNCallKeepModule][storeSettings] no react context found.");
1063-
return;
1061+
return MapUtils.readableToWritableMap(options);
10641062
}
10651063

10661064
SharedPreferences sharedPref = context.getSharedPreferences("rn-callkeep", Context.MODE_PRIVATE);
@@ -1069,15 +1067,17 @@ private void storeSettings(ReadableMap options) {
10691067
String jsonString = jsonObject.toString();
10701068
sharedPref.edit().putString("settings", jsonString).apply();
10711069
} catch (JSONException e) {
1070+
Log.w(TAG, "[RNCallKeepModule][storeSettings] exception: " + e);
10721071
}
1072+
return MapUtils.readableToWritableMap(options);
10731073
}
10741074

10751075
private static void fetchStoredSettings(@Nullable Context fromContext) {
1076-
if (instance == null && fromContext == null) {
1076+
Context context = fromContext != null ? fromContext : instance.getAppContext();
1077+
if (instance == null && context == null) {
10771078
Log.w(TAG, "[RNCallKeepModule][fetchStoredSettings] no instance nor fromContext.");
10781079
return;
10791080
}
1080-
Context context = fromContext != null ? fromContext : instance.getAppContext();
10811081
_settings = new WritableNativeMap();
10821082
if (context == null) {
10831083
Log.w(TAG, "[RNCallKeepModule][fetchStoredSettings] no react context found.");

0 commit comments

Comments
 (0)