Skip to content

Commit 4aa6a62

Browse files
Merge pull request #1681 from smartdevicelink/bugfix/issue_1677
Fix for Two voiceCommands contains the same string
2 parents 2b18229 + 6df490d commit 4aa6a62

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.mockito.invocation.InvocationOnMock;
5353
import org.mockito.stubbing.Answer;
5454

55+
import java.util.ArrayList;
5556
import java.util.Arrays;
5657
import java.util.Collections;
5758
import java.util.List;
@@ -192,4 +193,21 @@ private void sendFakeCoreOnHMIFullNotifications() {
192193
onHMIStatusListener.onNotified(onHMIStatusFakeNotification);
193194
}
194195

196+
/**
197+
* Test If voice commands do not have unique strings, they will not be uploaded
198+
*/
199+
@Test
200+
public void testUniqueStrings() {
201+
List<VoiceCommand> voiceCommandList = new ArrayList<>();
202+
VoiceCommand command1 = new VoiceCommand(Arrays.asList("Command one", "Command two"), null);
203+
VoiceCommand command2 = new VoiceCommand(Arrays.asList("Command one", "Command two"), null);
204+
205+
voiceCommandList.add(command1);
206+
voiceCommandList.add(command2);
207+
voiceCommandManager.currentHMILevel = HMILevel.HMI_NONE;
208+
voiceCommandManager.setVoiceCommands(voiceCommandList);
209+
210+
assertNull(voiceCommandManager.voiceCommands);
211+
}
212+
195213
}

base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
import java.util.ArrayList;
5353
import java.util.HashMap;
54+
import java.util.HashSet;
5455
import java.util.List;
5556

5657
abstract class BaseVoiceCommandManager extends BaseSubManager {
@@ -136,6 +137,11 @@ public void setVoiceCommands(List<VoiceCommand> voiceCommands) {
136137
return;
137138
}
138139

140+
if (!isVoiceCommandsUnique(voiceCommands)) {
141+
DebugTool.logError(TAG, "Not all voice command strings are unique across all voice commands. Voice commands will not be set.");
142+
return;
143+
}
144+
139145
updateIdsOnVoiceCommands(voiceCommands);
140146
this.voiceCommands = new ArrayList<>(voiceCommands);
141147

@@ -225,4 +231,21 @@ public void onNotified(RPCNotification notification) {
225231
};
226232
internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener);
227233
}
234+
235+
/**
236+
* Boolean method that checks to see if all VoiceCommands in a given list are unique
237+
*
238+
* @param voiceCommands - list of VoiceCommands
239+
* @return - true if VoiceCommands are unique, false if not
240+
*/
241+
private boolean isVoiceCommandsUnique(List<VoiceCommand> voiceCommands) {
242+
HashSet<String> voiceCommandHashSet = new HashSet<>();
243+
int voiceCommandCount = 0;
244+
245+
for (VoiceCommand voiceCommand : voiceCommands) {
246+
voiceCommandHashSet.addAll(voiceCommand.getVoiceCommands());
247+
voiceCommandCount += voiceCommand.getVoiceCommands().size();
248+
}
249+
return (voiceCommandHashSet.size() == voiceCommandCount);
250+
}
228251
}

0 commit comments

Comments
 (0)