diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 8c6c0eb5..c92dd984 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -218,13 +218,11 @@ public void initializeTelecomManager() { @ReactMethod public void setSettings(ReadableMap options) { + Log.d(TAG, "[RNCallKeepModule] setSettings : " + options); if (options == null) { return; } - Log.d(TAG, "[RNCallKeepModule] setSettings: " + options); - storeSettings(options); - - _settings = getSettings(null); + _settings = storeSettings(options); } @ReactMethod @@ -239,7 +237,7 @@ public void removeListeners(Integer count) { @ReactMethod public void setup(ReadableMap options) { - Log.d(TAG, "[RNCallKeepModule] setup"); + Log.d(TAG, "[RNCallKeepModule] setup : " + options); VoiceConnectionService.setAvailable(false); VoiceConnectionService.setInitialized(true); @@ -270,7 +268,7 @@ public void setup(ReadableMap options) { @ReactMethod public void registerPhoneAccount(ReadableMap options) { - storeSettings(options); + setSettings(options); if (!isConnectionServiceAvailable()) { Log.w(TAG, "[RNCallKeepModule] registerPhoneAccount ignored due to no ConnectionService"); @@ -806,7 +804,7 @@ public void setForegroundServiceSettings(ReadableMap foregroundServerSettings) { settings.putMap("foregroundService", MapUtils.readableToWritableMap(foregroundServerSettings)); } - storeSettings(settings); + setSettings(settings); } @ReactMethod @@ -1056,11 +1054,11 @@ private Context getAppContext() { } // Store all callkeep settings in JSON - private void storeSettings(ReadableMap options) { - Context context = getInstance(null, false).getAppContext(); + private WritableMap storeSettings(ReadableMap options) { + Context context = getAppContext(); if (context == null) { Log.w(TAG, "[RNCallKeepModule][storeSettings] no react context found."); - return; + return MapUtils.readableToWritableMap(options); } SharedPreferences sharedPref = context.getSharedPreferences("rn-callkeep", Context.MODE_PRIVATE); @@ -1069,15 +1067,17 @@ private void storeSettings(ReadableMap options) { String jsonString = jsonObject.toString(); sharedPref.edit().putString("settings", jsonString).apply(); } catch (JSONException e) { + Log.w(TAG, "[RNCallKeepModule][storeSettings] exception: " + e); } + return MapUtils.readableToWritableMap(options); } private static void fetchStoredSettings(@Nullable Context fromContext) { - if (instance == null && fromContext == null) { + Context context = fromContext != null ? fromContext : instance.getAppContext(); + if (instance == null && context == null) { Log.w(TAG, "[RNCallKeepModule][fetchStoredSettings] no instance nor fromContext."); return; } - Context context = fromContext != null ? fromContext : instance.getAppContext(); _settings = new WritableNativeMap(); if (context == null) { Log.w(TAG, "[RNCallKeepModule][fetchStoredSettings] no react context found.");