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

Commit 22968950 authored by Sandeep Siddhartha's avatar Sandeep Siddhartha
Browse files

Activity for enrollment

- Make the enrollment attrs public
- Add a dummy activity for enrollment

- Manually tested that the meta-data is correctly read by the
  VoiceInteractionService when the enrollment application is under
  /system/priv-app

Change-Id: I36676ed8ffc919109031c26bac047d0c51a77e13
parent e912ac01
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1002,6 +1002,9 @@ package android {
    field public static final int scrollbars = 16842974; // 0x10100de
    field public static final int scrollingCache = 16843006; // 0x10100fe
    field public static final deprecated int searchButtonText = 16843269; // 0x1010205
    field public static final int searchKeyphrase = 16843874; // 0x1010462
    field public static final int searchKeyphraseId = 16843873; // 0x1010461
    field public static final int searchKeyphraseSupportedLocales = 16843875; // 0x1010463
    field public static final int searchMode = 16843221; // 0x10101d5
    field public static final int searchSettingsDescription = 16843402; // 0x101028a
    field public static final int searchSuggestAuthority = 16843222; // 0x10101d6
+18 −8
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Slog;
import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
@@ -93,18 +93,20 @@ public class KeyphraseEnrollmentInfo {
                if ((ai.flags & ApplicationInfo.FLAG_PRIVILEGED) == 0) {
                    // The application isn't privileged (/system/priv-app).
                    // The enrollment application needs to be a privileged system app.
                    Slog.w(TAG, ai.packageName + "is not a privileged system app");
                    continue;
                }
                if (!Manifest.permission.MANAGE_VOICE_KEYPHRASES.equals(ai.permission)) {
                    // The application trying to manage keyphrases doesn't
                    // require the MANAGE_VOICE_KEYPHRASES permission.
                    Slog.w(TAG, ai.packageName + " does not require MANAGE_VOICE_KEYPHRASES");
                    continue;
                }
                mEnrollmentPackage = ai.packageName;
                found = true;
                break;
            } catch (PackageManager.NameNotFoundException e) {
                Log.w(TAG, "error parsing voice enrollment meta-data", e);
                Slog.w(TAG, "error parsing voice enrollment meta-data", e);
            }
        }

@@ -163,15 +165,15 @@ public class KeyphraseEnrollmentInfo {
            }
        } catch (XmlPullParserException e) {
            mParseError = "Error parsing keyphrase enrollment meta-data: " + e;
            Log.w(TAG, "error parsing keyphrase enrollment meta-data", e);
            Slog.w(TAG, "error parsing keyphrase enrollment meta-data", e);
            return;
        } catch (IOException e) {
            mParseError = "Error parsing keyphrase enrollment meta-data: " + e;
            Log.w(TAG, "error parsing keyphrase enrollment meta-data", e);
            Slog.w(TAG, "error parsing keyphrase enrollment meta-data", e);
            return;
        } catch (PackageManager.NameNotFoundException e) {
            mParseError = "Error parsing keyphrase enrollment meta-data: " + e;
            Log.w(TAG, "error parsing keyphrase enrollment meta-data", e);
            Slog.w(TAG, "error parsing keyphrase enrollment meta-data", e);
            return;
        } finally {
            if (parser != null) parser.close();
@@ -182,6 +184,14 @@ public class KeyphraseEnrollmentInfo {
        return mParseError;
    }

    /**
     * @return An array of available keyphrases that can be enrolled on the system.
     *         It may be null if no keyphrases can be enrolled.
     */
    public KeyphraseInfo[] getKeyphrases() {
        return mKeyphrases;
    }

    /**
     * Returns an intent to launch an activity that manages the given keyphrase
     * for the locale.
@@ -194,7 +204,7 @@ public class KeyphraseEnrollmentInfo {
     */
    public Intent getManageKeyphraseIntent(boolean enroll, String keyphrase, String locale) {
        if (mEnrollmentPackage == null || mEnrollmentPackage.isEmpty()) {
            Log.w(TAG, "No enrollment application exists");
            Slog.w(TAG, "No enrollment application exists");
            return null;
        }

@@ -218,7 +228,7 @@ public class KeyphraseEnrollmentInfo {
     */
    public boolean isKeyphraseEnrollmentSupported(String keyphrase, String locale) {
        if (mKeyphrases == null || mKeyphrases.length == 0) {
            Log.w(TAG, "Enrollment application doesn't support keyphrases");
            Slog.w(TAG, "Enrollment application doesn't support keyphrases");
            return false;
        }
        for (KeyphraseInfo keyphraseInfo : mKeyphrases) {
@@ -230,7 +240,7 @@ public class KeyphraseEnrollmentInfo {
                return true;
            }
        }
        Log.w(TAG, "Enrollment application doesn't support the given keyphrase");
        Slog.w(TAG, "Enrollment application doesn't support the given keyphrase");
        return false;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -19,4 +19,9 @@ public class KeyphraseInfo {
            this.supportedLocales.add(locale);
        }
    }

    @Override
    public String toString() {
        return "id=" + id + ", keyphrase=" + keyphrase + ", supported-locales=" + supportedLocales;
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IVoiceInteractionManagerService;

/**
@@ -108,4 +109,13 @@ public class VoiceInteractionService extends Service {
        return mDspInfo != null
                && mKeyphraseEnrollmentInfo.isKeyphraseEnrollmentSupported(keyphrase, locale);
    }

    /**
     * @return Details of keyphrases available for enrollment.
     * @hide
     */
    @VisibleForTesting
    protected final KeyphraseEnrollmentInfo getKeyphraseEnrollmentInfo() {
        return mKeyphraseEnrollmentInfo;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -2186,6 +2186,9 @@
  <public type="attr" name="translateY" />
  <public type="attr" name="selectableItemBackgroundBorderless" />
  <public type="attr" name="elegantTextHeight" />
  <public type="attr" name="searchKeyphraseId" />
  <public type="attr" name="searchKeyphrase" />
  <public type="attr" name="searchKeyphraseSupportedLocales" />

  <public-padding type="dimen" name="l_resource_pad" end="0x01050010" />

Loading