Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c240dcf9 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "add enrollment application UID tracking" into rvc-dev am: a163d079

Change-Id: I37fb98f8e053617296aa4b745b9130d4a1410a85
parents d8f3a3a4 a163d079
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -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 + "]";
    }
}