Skip to content

Commit 750e7a9

Browse files
author
Brandon Huang
committed
Use try catches to handle hashmap null object references
1 parent e0e68bd commit 750e7a9

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ private class VoiceBroadcastReceiver extends BroadcastReceiver {
485485
public void onReceive(Context context, Intent intent) {
486486
WritableMap args = Arguments.createMap();
487487
HashMap<String, String> attributeMap = (HashMap<String, String>)intent.getSerializableExtra("attributeMap");
488+
if (attributeMap == null) {
489+
return;
490+
}
488491

489492
switch (intent.getAction()) {
490493
case ACTION_END_CALL:

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ public class VoiceConnection extends Connection {
5353
if (name != null && !name.equals("")) {
5454
setCallerDisplayName(name, TelecomManager.PRESENTATION_ALLOWED);
5555
}
56+
Log.e(TAG, "Constructor");
5657
}
5758

5859
@Override
5960
public void onExtrasChanged(Bundle extras) {
6061
super.onExtrasChanged(extras);
61-
handle = (HashMap<String, String>)extras.getSerializable("attributeMap");
62+
HashMap attributeMap = (HashMap<String, String>)extras.getSerializable("attributeMap");
63+
if (attributeMap != null) {
64+
handle = attributeMap;
65+
}
6266
}
6367

6468
@Override
@@ -86,7 +90,11 @@ public void onAnswer() {
8690

8791
@Override
8892
public void onPlayDtmfTone(char dtmf) {
89-
handle.put("DTMF", Character.toString(dtmf));
93+
try {
94+
handle.put("DTMF", Character.toString(dtmf));
95+
} catch (Throwable exception) {
96+
Log.e(TAG, "Handle map error", exception);
97+
}
9098
sendCallRequestToActivity(ACTION_DTMF_TONE, handle);
9199
}
92100

@@ -96,7 +104,11 @@ public void onDisconnect() {
96104
setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
97105
sendCallRequestToActivity(ACTION_END_CALL, handle);
98106
Log.d(TAG, "onDisconnect executed");
99-
((VoiceConnectionService)context).deinitConnection(handle.get(EXTRA_CALL_UUID));
107+
try {
108+
((VoiceConnectionService) context).deinitConnection(handle.get(EXTRA_CALL_UUID));
109+
} catch(Throwable exception) {
110+
Log.e(TAG, "Handle map error", exception);
111+
}
100112
destroy();
101113
}
102114

@@ -125,7 +137,11 @@ public void onAbort() {
125137
setDisconnected(new DisconnectCause(DisconnectCause.REJECTED));
126138
sendCallRequestToActivity(ACTION_END_CALL, handle);
127139
Log.d(TAG, "onAbort executed");
128-
((VoiceConnectionService)context).deinitConnection(handle.get(EXTRA_CALL_UUID));
140+
try {
141+
((VoiceConnectionService) context).deinitConnection(handle.get(EXTRA_CALL_UUID));
142+
} catch(Throwable exception) {
143+
Log.e(TAG, "Handle map error", exception);
144+
}
129145
destroy();
130146
}
131147

@@ -149,7 +165,11 @@ public void onReject() {
149165
setDisconnected(new DisconnectCause(DisconnectCause.REJECTED));
150166
sendCallRequestToActivity(ACTION_END_CALL, handle);
151167
Log.d(TAG, "onReject executed");
152-
((VoiceConnectionService)context).deinitConnection(handle.get(EXTRA_CALL_UUID));
168+
try {
169+
((VoiceConnectionService) context).deinitConnection(handle.get(EXTRA_CALL_UUID));
170+
} catch(Throwable exception) {
171+
Log.e(TAG, "Handle map error", exception);
172+
}
153173
destroy();
154174
}
155175

@@ -168,9 +188,8 @@ public void run() {
168188
Bundle extras = new Bundle();
169189
extras.putSerializable("attributeMap", attributeMap);
170190
intent.putExtras(extras);
191+
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
171192
}
172-
173-
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
174193
}
175194
});
176195
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ public void run() {
197197
Bundle extras = new Bundle();
198198
extras.putSerializable("attributeMap", attributeMap);
199199
intent.putExtras(extras);
200+
LocalBroadcastManager.getInstance(instance).sendBroadcast(intent);
200201
}
201-
202-
LocalBroadcastManager.getInstance(instance).sendBroadcast(intent);
203202
}
204203
});
205204
}

0 commit comments

Comments
 (0)