Skip to content

Commit 6fdf885

Browse files
committed
Retrieve settings from ConnectionService context
1 parent 8d090a9 commit 6fdf885

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public static RNCallKeepModule getInstance(ReactApplicationContext reactContext,
136136
return instance;
137137
}
138138

139-
public static WritableMap getSettings() {
139+
public static WritableMap getSettings(@Nullable Context context) {
140140
if (_settings == null) {
141-
fetchStoredSettings();
141+
fetchStoredSettings(context);
142142
}
143143

144144
return _settings;
@@ -222,7 +222,7 @@ public void setSettings(ReadableMap options) {
222222
Log.d(TAG, "[RNCallKeepModule] setSettings: " + options);
223223
storeSettings(options);
224224

225-
_settings = getSettings();
225+
_settings = getSettings(null);
226226
}
227227

228228
@ReactMethod
@@ -770,7 +770,7 @@ public void setForegroundServiceSettings(ReadableMap foregroundServerSettings) {
770770
}
771771

772772
// Retrieve settings and set the `foregroundService` value
773-
WritableMap settings = getSettings();
773+
WritableMap settings = getSettings(null);
774774
if (settings != null) {
775775
settings.putMap("foregroundService", MapUtils.readableToWritableMap(foregroundServerSettings));
776776
}
@@ -1036,11 +1036,12 @@ private void storeSettings(ReadableMap options) {
10361036
}
10371037
}
10381038

1039-
private static void fetchStoredSettings() {
1040-
if (instance == null) {
1039+
private static void fetchStoredSettings(@Nullable Context fromContext) {
1040+
if (instance == null && fromContext == null) {
1041+
Log.w(TAG, "[RNCallKeepModule][fetchStoredSettings] no instance nor fromContext.");
10411042
return;
10421043
}
1043-
Context context = instance.getAppContext();
1044+
Context context = fromContext != null ? fromContext : instance.getAppContext();
10441045
_settings = new WritableNativeMap();
10451046
if (context == null) {
10461047
Log.w(TAG, "[RNCallKeepModule][fetchStoredSettings] no react context found.");

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ public static void setAvailable(Boolean value) {
117117
isAvailable = value;
118118
}
119119

120-
public static WritableMap getSettings() {
121-
WritableMap settings = RNCallKeepModule.getSettings();
120+
public static WritableMap getSettings(@Nullable Context context) {
121+
WritableMap settings = RNCallKeepModule.getSettings(context);
122122
return settings;
123123
}
124124

125-
public static ReadableMap getForegroundSettings() {
126-
WritableMap settings = VoiceConnectionService.getSettings();
125+
public static ReadableMap getForegroundSettings(@Nullable Context context) {
126+
WritableMap settings = VoiceConnectionService.getSettings(context);
127127
if (settings == null) {
128128
return null;
129129
}
@@ -193,7 +193,7 @@ public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManage
193193
String name = extra.getString(EXTRA_CALLER_NAME);
194194
String callUUID = extra.getString(EXTRA_CALL_UUID);
195195
Boolean isForeground = VoiceConnectionService.isRunning(this.getApplicationContext());
196-
WritableMap settings = this.getSettings();
196+
WritableMap settings = this.getSettings(this);
197197
Integer timeout = settings.hasKey("displayCallReachabilityTimeout") ? settings.getInt("displayCallReachabilityTimeout") : null;
198198

199199
Log.d(TAG, "[VoiceConnectionService] onCreateIncomingConnection, name:" + name + ", number" + number +

0 commit comments

Comments
 (0)