From 07ba2b7f8311b708720cbc31bd0c4b7ee1eb6a09 Mon Sep 17 00:00:00 2001 From: Nicholas Ambur Date: Wed, 4 Sep 2019 18:31:52 -0700 Subject: [PATCH] change KeyphraseEnrollmentInfo to store services Current hotword enrollment is done through a transparent activity which when triggered causes a breif interuption on the UI. Because there is no actual UI component to this activity, it is being transitioned from an activity to a service. applications supporting MANAGE_VOICE_KEYPHRASES are moved from ativity to service based to allow for enrollment which does not effect the UI Bug: 139954183 Test: confirmed enrollment and unenrollment intents can start the registered enrollment service. Change-Id: I1e2d80e08efaf47a5c1c8760e2979143df436a93 --- .../soundtrigger/KeyphraseEnrollmentInfo.java | 16 +++++++++------- .../service/voice/AlwaysOnHotwordDetector.java | 9 ++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java b/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java index 160376bf6cbac..4d71eebf69c7e 100644 --- a/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java +++ b/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java @@ -58,8 +58,8 @@ public class KeyphraseEnrollmentInfo { */ private static final String VOICE_KEYPHRASE_META_DATA = "android.voice_enrollment"; /** - * Activity Action: Show activity for managing the keyphrases for hotword detection. - * This needs to be defined by an activity that supports enrolling users for hotword/keyphrase + * Intent Action: for managing the keyphrases for hotword detection. + * This needs to be defined by a service that supports enrolling users for hotword/keyphrase * detection. */ public static final String ACTION_MANAGE_VOICE_KEYPHRASES = @@ -101,7 +101,7 @@ public class KeyphraseEnrollmentInfo { // Find the apps that supports enrollment for hotword keyhphrases, // Pick a privileged app and obtain the information about the supported keyphrases // from its metadata. - List ris = pm.queryIntentActivities( + List ris = pm.queryIntentServices( new Intent(ACTION_MANAGE_VOICE_KEYPHRASES), PackageManager.MATCH_DEFAULT_ONLY); if (ris == null || ris.isEmpty()) { // No application capable of enrolling for voice keyphrases is present. @@ -116,11 +116,11 @@ public class KeyphraseEnrollmentInfo { for (ResolveInfo ri : ris) { try { ApplicationInfo ai = pm.getApplicationInfo( - ri.activityInfo.packageName, PackageManager.GET_META_DATA); + ri.serviceInfo.packageName, PackageManager.GET_META_DATA); if ((ai.privateFlags & ApplicationInfo.PRIVATE_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"); + Slog.w(TAG, ai.packageName + " is not a privileged system app"); continue; } if (!Manifest.permission.MANAGE_VOICE_KEYPHRASES.equals(ai.permission)) { @@ -130,6 +130,8 @@ public class KeyphraseEnrollmentInfo { continue; } + Slog.i(TAG, ai.packageName + " added to keyphrase"); + KeyphraseMetadata metadata = getKeyphraseMetadataFromApplicationInfo(pm, ai, parseErrors); if (metadata != null) { @@ -137,7 +139,7 @@ public class KeyphraseEnrollmentInfo { } } catch (PackageManager.NameNotFoundException e) { String error = "error parsing voice enrollment meta-data for " - + ri.activityInfo.packageName; + + ri.serviceInfo.packageName; parseErrors.add(error + ": " + e); Slog.w(TAG, error, e); } @@ -290,7 +292,7 @@ public class KeyphraseEnrollmentInfo { } /** - * Returns an intent to launch an activity that manages the given keyphrase + * Returns an intent to launch an service that manages the given keyphrase * for the locale. * * @param action The enrollment related action that this intent is supposed to perform. diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index bd953cad2b759..cf56eae4a052c 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -20,7 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; -import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.hardware.soundtrigger.IRecognitionStatusCallback; import android.hardware.soundtrigger.KeyphraseEnrollmentInfo; @@ -32,7 +32,6 @@ import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra; import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel; import android.hardware.soundtrigger.SoundTrigger.ModuleProperties; import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig; -import android.hardware.soundtrigger.SoundTrigger.RecognitionEvent; import android.media.AudioFormat; import android.os.AsyncTask; import android.os.Handler; @@ -447,7 +446,7 @@ public class AlwaysOnHotwordDetector { /** * Creates an intent to start the enrollment for the associated keyphrase. - * This intent must be invoked using {@link Activity#startActivityForResult(Intent, int)}. + * This intent must be invoked using {@link Context#startForegroundService(Intent)}. * Starting re-enrollment is only valid if the keyphrase is un-enrolled, * i.e. {@link #STATE_KEYPHRASE_UNENROLLED}, * otherwise {@link #createReEnrollIntent()} should be preferred. @@ -469,7 +468,7 @@ public class AlwaysOnHotwordDetector { /** * Creates an intent to start the un-enrollment for the associated keyphrase. - * This intent must be invoked using {@link Activity#startActivityForResult(Intent, int)}. + * This intent must be invoked using {@link Context#startForegroundService(Intent)}. * Starting re-enrollment is only valid if the keyphrase is already enrolled, * i.e. {@link #STATE_KEYPHRASE_ENROLLED}, otherwise invoking this may result in an error. * @@ -490,7 +489,7 @@ public class AlwaysOnHotwordDetector { /** * Creates an intent to start the re-enrollment for the associated keyphrase. - * This intent must be invoked using {@link Activity#startActivityForResult(Intent, int)}. + * This intent must be invoked using {@link Context#startForegroundService(Intent)}. * Starting re-enrollment is only valid if the keyphrase is already enrolled, * i.e. {@link #STATE_KEYPHRASE_ENROLLED}, otherwise invoking this may result in an error. *