From fd652d522cfc16e3e3768c400794cea10b2a9fb8 Mon Sep 17 00:00:00 2001 From: lpeter Date: Tue, 2 Feb 2021 01:04:44 +0800 Subject: Get the HotwordDetectionService from the xml metadata Bug: 178171920 Test: atest CtsVoiceInteractionTestCases Merged-In: Ic19ae8b0ad8b646836fca7417e68b9b36429d5f0 Change-Id: I2a97491c7bbfd3a04ec3d9488beb158287d22e10 --- core/api/system-current.txt | 1 + .../service/voice/VoiceInteractionServiceInfo.java | 9 +++++++++ core/res/res/values/attrs.xml | 3 +++ core/res/res/values/public.xml | 2 ++ .../VoiceInteractionManagerServiceImpl.java | 15 ++++++++++++--- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 1977babe0bfb..6e3136a9718b 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -290,6 +290,7 @@ package android { public static final class R.attr { field public static final int allowClearUserDataOnFailedRestore = 16844288; // 0x1010600 + field public static final int hotwordDetectionService = 16844326; // 0x1010626 field public static final int isVrOnly = 16844152; // 0x1010578 field public static final int minExtensionVersion = 16844305; // 0x1010611 field public static final int requiredSystemPropertyName = 16844133; // 0x1010565 diff --git a/core/java/android/service/voice/VoiceInteractionServiceInfo.java b/core/java/android/service/voice/VoiceInteractionServiceInfo.java index f7710e6a82ce..ff03cc14e73b 100644 --- a/core/java/android/service/voice/VoiceInteractionServiceInfo.java +++ b/core/java/android/service/voice/VoiceInteractionServiceInfo.java @@ -18,6 +18,7 @@ package android.service.voice; import android.Manifest; import android.annotation.NonNull; +import android.annotation.Nullable; import android.app.AppGlobals; import android.content.ComponentName; import android.content.pm.PackageManager; @@ -44,6 +45,7 @@ public class VoiceInteractionServiceInfo { private ServiceInfo mServiceInfo; private String mSessionService; private String mRecognitionService; + private String mHotwordDetectionService; private String mSettingsActivity; private boolean mSupportsAssist; private boolean mSupportsLaunchFromKeyguard; @@ -133,6 +135,8 @@ public class VoiceInteractionServiceInfo { false); mSupportsLocalInteraction = array.getBoolean(com.android.internal. R.styleable.VoiceInteractionService_supportsLocalInteraction, false); + mHotwordDetectionService = array.getString(com.android.internal.R.styleable + .VoiceInteractionService_hotwordDetectionService); array.recycle(); if (mSessionService == null) { mParseError = "No sessionService specified"; @@ -181,4 +185,9 @@ public class VoiceInteractionServiceInfo { public boolean getSupportsLocalInteraction() { return mSupportsLocalInteraction; } + + @Nullable + public String getHotwordDetectionService() { + return mHotwordDetectionService; + } } diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index eb867090f8ba..14df77527a08 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -8500,6 +8500,9 @@ interaction requests from an Activity. This flag is new in {@link android.os.Build.VERSION_CODES#N} and not used in previous versions. --> + + + diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index 9e8f8eaa855c..04dea3f7a2c6 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -163,8 +163,13 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mValid = true; mSessionComponentName = new ComponentName(service.getPackageName(), mInfo.getSessionService()); - // TODO : Need to get the hotword detection service from the xml metadata - mHotwordDetectionComponentName = null; + final String hotwordDetectionServiceName = mInfo.getHotwordDetectionService(); + if (hotwordDetectionServiceName != null) { + mHotwordDetectionComponentName = new ComponentName(service.getPackageName(), + hotwordDetectionServiceName); + } else { + mHotwordDetectionComponentName = null; + } mIWindowManager = IWindowManager.Stub.asInterface( ServiceManager.getService(Context.WINDOW_SERVICE)); IntentFilter filter = new IntentFilter(); @@ -388,7 +393,11 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne if (DEBUG) { Slog.d(TAG, "setHotwordDetectionConfigLocked"); } - + if (mHotwordDetectionComponentName == null) { + Slog.e(TAG, "Calling setHotwordDetectionConfigLocked, but hotword detection service" + + " name not found"); + return VoiceInteractionService.HOTWORD_CONFIG_FAILURE; + } if (!isIsolatedProcessLocked(mHotwordDetectionComponentName)) { return VoiceInteractionService.HOTWORD_CONFIG_FAILURE; } -- cgit v1.2.3-59-g8ed1b