Merge "add enrollment application UID tracking" into rvc-dev

This commit is contained in:
Nicholas Ambur
2020-02-27 18:01:24 +00:00
committed by Android (Google) Code Review

View File

@@ -28,6 +28,7 @@ import android.content.res.XmlResourceParser;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Slog;
import android.util.Xml;
@@ -43,6 +44,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/**
* Enrollment information about the different available keyphrases.
@@ -116,7 +118,12 @@ public class KeyphraseEnrollmentInfo {
/**
* List of available keyphrases.
*/
final private KeyphraseMetadata[] mKeyphrases;
private final KeyphraseMetadata[] mKeyphrases;
/**
* Set of UIDs associated with the detected enrollment applications.
*/
private final Set<Integer> mEnrollmentApplicationUids;
/**
* Map between KeyphraseMetadata and the package name of the enrollment app that provides it.
@@ -136,11 +143,13 @@ public class KeyphraseEnrollmentInfo {
mParseError = "No enrollment applications found";
mKeyphrasePackageMap = Collections.<KeyphraseMetadata, String>emptyMap();
mKeyphrases = null;
mEnrollmentApplicationUids = Collections.emptySet();
return;
}
List<String> parseErrors = new LinkedList<String>();
mKeyphrasePackageMap = new HashMap<KeyphraseMetadata, String>();
mEnrollmentApplicationUids = new ArraySet<>();
for (ResolveInfo ri : ris) {
try {
ApplicationInfo ai = pm.getApplicationInfo(
@@ -162,6 +171,7 @@ public class KeyphraseEnrollmentInfo {
getKeyphraseMetadataFromApplicationInfo(pm, ai, parseErrors);
if (metadata != null) {
mKeyphrasePackageMap.put(metadata, ai.packageName);
mEnrollmentApplicationUids.add(ai.uid);
}
} catch (PackageManager.NameNotFoundException e) {
String error = "error parsing voice enrollment meta-data for "
@@ -372,9 +382,22 @@ public class KeyphraseEnrollmentInfo {
return null;
}
/**
* Tests if the input UID matches a supported enrollment application.
*
* @param uid UID of the caller to test against.
* @return Returns true if input uid matches the uid of a supported enrollment application.
* False if not.
*/
public boolean isUidSupportedEnrollmentApplication(int uid) {
Log.d(TAG, "isUidSupportedEnrollmentApplication: " + toString());
return mEnrollmentApplicationUids.contains(uid);
}
@Override
public String toString() {
return "KeyphraseEnrollmentInfo [Keyphrases=" + mKeyphrasePackageMap.toString()
return "KeyphraseEnrollmentInfo [KeyphrasePackageMap=" + mKeyphrasePackageMap.toString()
+ ", enrollmentApplicationUids=" + mEnrollmentApplicationUids.toString()
+ ", ParseError=" + mParseError + "]";
}
}