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

Commit 84b79855 authored by Nicholas Ambur's avatar Nicholas Ambur
Browse files

add enrollment application UID tracking

KeyphraseEnrollmentInfo class now keeps track of the different enrollment
application UIDs. It can be queries whether a given UID matches an
existing enrollment application.

Bug: 148159858
Test: build and test that enrollment application can still enroll models
with new UID check

Change-Id: Ib60ebb259e4e3ddaa07da15e2cf55fd6099ad4d0
parent 7022df64
Loading
Loading
Loading
Loading
+25 −2
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.res.XmlResourceParser;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Slog;
import android.util.Slog;
import android.util.Xml;
import android.util.Xml;


@@ -43,6 +44,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.Locale;
import java.util.Map;
import java.util.Map;
import java.util.Set;


/**
/**
 * Enrollment information about the different available keyphrases.
 * Enrollment information about the different available keyphrases.
@@ -116,7 +118,12 @@ public class KeyphraseEnrollmentInfo {
    /**
    /**
     * List of available keyphrases.
     * 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.
     * 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";
            mParseError = "No enrollment applications found";
            mKeyphrasePackageMap = Collections.<KeyphraseMetadata, String>emptyMap();
            mKeyphrasePackageMap = Collections.<KeyphraseMetadata, String>emptyMap();
            mKeyphrases = null;
            mKeyphrases = null;
            mEnrollmentApplicationUids = Collections.emptySet();
            return;
            return;
        }
        }


        List<String> parseErrors = new LinkedList<String>();
        List<String> parseErrors = new LinkedList<String>();
        mKeyphrasePackageMap = new HashMap<KeyphraseMetadata, String>();
        mKeyphrasePackageMap = new HashMap<KeyphraseMetadata, String>();
        mEnrollmentApplicationUids = new ArraySet<>();
        for (ResolveInfo ri : ris) {
        for (ResolveInfo ri : ris) {
            try {
            try {
                ApplicationInfo ai = pm.getApplicationInfo(
                ApplicationInfo ai = pm.getApplicationInfo(
@@ -162,6 +171,7 @@ public class KeyphraseEnrollmentInfo {
                        getKeyphraseMetadataFromApplicationInfo(pm, ai, parseErrors);
                        getKeyphraseMetadataFromApplicationInfo(pm, ai, parseErrors);
                if (metadata != null) {
                if (metadata != null) {
                    mKeyphrasePackageMap.put(metadata, ai.packageName);
                    mKeyphrasePackageMap.put(metadata, ai.packageName);
                    mEnrollmentApplicationUids.add(ai.uid);
                }
                }
            } catch (PackageManager.NameNotFoundException e) {
            } catch (PackageManager.NameNotFoundException e) {
                String error = "error parsing voice enrollment meta-data for "
                String error = "error parsing voice enrollment meta-data for "
@@ -372,9 +382,22 @@ public class KeyphraseEnrollmentInfo {
        return null;
        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
    @Override
    public String toString() {
    public String toString() {
        return "KeyphraseEnrollmentInfo [Keyphrases=" + mKeyphrasePackageMap.toString()
        return "KeyphraseEnrollmentInfo [KeyphrasePackageMap=" + mKeyphrasePackageMap.toString()
                + ", enrollmentApplicationUids=" + mEnrollmentApplicationUids.toString()
                + ", ParseError=" + mParseError + "]";
                + ", ParseError=" + mParseError + "]";
    }
    }
}
}