Skip to content

Commit cd21ed0

Browse files
committed
Catch ArrayIndexOutOfBoundsException thrown by ReadableNativeMap.hasKey
1 parent 3b4a4e8 commit cd21ed0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private void startForegroundService() {
294294
Log.d(TAG, "[VoiceConnectionService] startForegroundService");
295295
ReadableMap foregroundSettings = getForegroundSettings(null);
296296

297-
if (foregroundSettings == null || !foregroundSettings.hasKey("channelId")) {
297+
if (!this.isForegroundServiceConfigured()) {
298298
Log.w(TAG, "[VoiceConnectionService] Not creating foregroundService because not configured");
299299
return;
300300
}
@@ -342,13 +342,25 @@ private void stopForegroundService() {
342342
Log.d(TAG, "[VoiceConnectionService] stopForegroundService");
343343
ReadableMap foregroundSettings = getForegroundSettings(null);
344344

345-
if (foregroundSettings == null || !foregroundSettings.hasKey("channelId")) {
346-
Log.d(TAG, "[VoiceConnectionService] Discarding stop foreground service, no service configured");
345+
if (!this.isForegroundServiceConfigured()) {
346+
Log.w(TAG, "[VoiceConnectionService] Not creating foregroundService because not configured");
347347
return;
348348
}
349+
349350
stopForeground(FOREGROUND_SERVICE_TYPE_MICROPHONE);
350351
}
351352

353+
private boolean isForegroundServiceConfigured() {
354+
ReadableMap foregroundSettings = getForegroundSettings(null);
355+
try {
356+
return foregroundSettings != null && foregroundSettings.hasKey("channelId");
357+
} catch (Exception e) {
358+
// Fix ArrayIndexOutOfBoundsException thrown by ReadableNativeMap.hasKey
359+
Log.w(TAG, "[VoiceConnectionService] Not creating foregroundService due to configuration retrieval error" + e.toString());
360+
return false;
361+
}
362+
}
363+
352364
private void wakeUpApplication(String uuid, String number, String displayName) {
353365
Log.d(TAG, "[VoiceConnectionService] wakeUpApplication, uuid:" + uuid + ", number :" + number + ", displayName:" + displayName);
354366

0 commit comments

Comments
 (0)