Merge "Fix NPE in KeyphraseEnrollmentInfo.toString()" into nyc-dev

This commit is contained in:
Chris Thornton
2016-05-06 18:04:17 +00:00
committed by Android (Google) Code Review

View File

@@ -35,6 +35,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@@ -105,7 +106,7 @@ public class KeyphraseEnrollmentInfo {
if (ris == null || ris.isEmpty()) { if (ris == null || ris.isEmpty()) {
// No application capable of enrolling for voice keyphrases is present. // No application capable of enrolling for voice keyphrases is present.
mParseError = "No enrollment applications found"; mParseError = "No enrollment applications found";
mKeyphrasePackageMap = null; mKeyphrasePackageMap = Collections.<KeyphraseMetadata, String>emptyMap();
mKeyphrases = null; mKeyphrases = null;
return; return;
} }
@@ -328,17 +329,15 @@ public class KeyphraseEnrollmentInfo {
* and locale, null otherwise. * and locale, null otherwise.
*/ */
public KeyphraseMetadata getKeyphraseMetadata(String keyphrase, Locale locale) { public KeyphraseMetadata getKeyphraseMetadata(String keyphrase, Locale locale) {
if (mKeyphrases == null || mKeyphrases.length == 0) { if (mKeyphrases != null && mKeyphrases.length > 0) {
Slog.w(TAG, "Enrollment application doesn't support keyphrases"); for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) {
return null; // Check if the given keyphrase is supported in the locale provided by
} // the enrollment application.
for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) { if (keyphraseMetadata.supportsPhrase(keyphrase)
// Check if the given keyphrase is supported in the locale provided by && keyphraseMetadata.supportsLocale(locale)) {
// the enrollment application. return keyphraseMetadata;
if (keyphraseMetadata.supportsPhrase(keyphrase) }
&& keyphraseMetadata.supportsLocale(locale)) { }
return keyphraseMetadata;
}
} }
Slog.w(TAG, "No Enrollment application supports the given keyphrase/locale"); Slog.w(TAG, "No Enrollment application supports the given keyphrase/locale");
return null; return null;