summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Thornton <thorntonc@google.com> 2016-05-05 17:20:44 -0700
committer Chris Thornton <thorntonc@google.com> 2016-05-05 17:20:44 -0700
commitd9729d1df877d88e7dbdc1b2675a331cea519338 (patch)
treee7108be58bbba8692806f47ca0ae3a9e0105390a
parentf8892359b0ae07031160a71cf3f7e3a86604c2b1 (diff)
Fix NPE in KeyphraseEnrollmentInfo.toString()
If there are no enrollment applications on the system, but someone still makes a KeyphraseEnrollmentInfo and tries to print it, it would generate a NPE on a map object. Instead of setting the map to null when we don't find any enrollment applications, we can just set it to an empty map. Bug:28622866 Change-Id: I023e6fd90effd3143c19817a0d6637a013bebc31
-rw-r--r--core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java23
1 files changed, 11 insertions, 12 deletions
diff --git a/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java b/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java
index 458c584084c9..f82c9e2b3f35 100644
--- a/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java
+++ b/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java
@@ -35,6 +35,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -105,7 +106,7 @@ public class KeyphraseEnrollmentInfo {
if (ris == null || ris.isEmpty()) {
// No application capable of enrolling for voice keyphrases is present.
mParseError = "No enrollment applications found";
- mKeyphrasePackageMap = null;
+ mKeyphrasePackageMap = Collections.<KeyphraseMetadata, String>emptyMap();
mKeyphrases = null;
return;
}
@@ -328,17 +329,15 @@ public class KeyphraseEnrollmentInfo {
* and locale, null otherwise.
*/
public KeyphraseMetadata getKeyphraseMetadata(String keyphrase, Locale locale) {
- if (mKeyphrases == null || mKeyphrases.length == 0) {
- Slog.w(TAG, "Enrollment application doesn't support keyphrases");
- return null;
- }
- for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) {
- // Check if the given keyphrase is supported in the locale provided by
- // the enrollment application.
- if (keyphraseMetadata.supportsPhrase(keyphrase)
- && keyphraseMetadata.supportsLocale(locale)) {
- return keyphraseMetadata;
- }
+ if (mKeyphrases != null && mKeyphrases.length > 0) {
+ for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) {
+ // Check if the given keyphrase is supported in the locale provided by
+ // the enrollment application.
+ if (keyphraseMetadata.supportsPhrase(keyphrase)
+ && keyphraseMetadata.supportsLocale(locale)) {
+ return keyphraseMetadata;
+ }
+ }
}
Slog.w(TAG, "No Enrollment application supports the given keyphrase/locale");
return null;