From 493a3a3c517706f083cf35c313f69cd6837849b4 Mon Sep 17 00:00:00 2001 From: fayey Date: Mon, 31 Jul 2023 23:39:58 +0000 Subject: [PATCH] Ambient Activation p1.1 This change is intended to pass the attributionTag the assistant app provides, to the AOHD, VQD and AOHD ctor, and to the Identity for attributing ops when delivering data to the Interactor. Changes are flag protected by the boolean IS_IDENTITY_WITH_ATTRIBUTION_TAG set to false as default. Bug: 287264308 Bug: 290642124 Test: manual-tested with test apk which provides attributionTag and verified by adb shell dumpsys appops --package PACKAGE_NAME Change-Id: I69c8f90af02c36042639bfa8605bbb84ed4c00d9 --- .../android/service/voice/AbstractDetector.java | 13 ++++++++++++- .../service/voice/AlwaysOnHotwordDetector.java | 13 +++++++++++-- .../service/voice/SoftwareHotwordDetector.java | 7 +++++-- .../android/service/voice/VisualQueryDetector.java | 6 ++++-- .../service/voice/VoiceInteractionService.java | 7 ++++--- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/core/java/android/service/voice/AbstractDetector.java b/core/java/android/service/voice/AbstractDetector.java index 8648e386fbbbe..7af7fe6108e6f 100644 --- a/core/java/android/service/voice/AbstractDetector.java +++ b/core/java/android/service/voice/AbstractDetector.java @@ -65,6 +65,13 @@ abstract class AbstractDetector implements HotwordDetector { */ private final IBinder mToken = new Binder(); + /** + * A flag controls whether attributionTag will be passed into the Identity. + * TODO(b/289087412): This flag will be converted and confirm to the trunk stable flag + * configuration. + */ + static final boolean IS_IDENTITY_WITH_ATTRIBUTION_TAG = false; + AbstractDetector( IVoiceInteractionManagerService managerService, Executor executor, @@ -153,12 +160,16 @@ abstract class AbstractDetector implements HotwordDetector { @Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory, @NonNull IHotwordRecognitionStatusCallback callback, - int detectorType) { + int detectorType, + @Nullable String attributionTag) { if (DEBUG) { Slog.d(TAG, "initAndVerifyDetector()"); } Identity identity = new Identity(); identity.packageName = ActivityThread.currentOpPackageName(); + if (IS_IDENTITY_WITH_ATTRIBUTION_TAG) { + identity.attributionTag = attributionTag; + } try { mManagerService.initAndVerifyDetector(identity, options, sharedMemory, mToken, callback, detectorType); diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index 9d283347466ba..21f676e3fe2f7 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -324,6 +324,7 @@ public class AlwaysOnHotwordDetector extends AbstractDetector { private final Handler mHandler; private final IBinder mBinder = new Binder(); private final boolean mSupportSandboxedDetectionService; + private final String mAttributionTag; @GuardedBy("mLock") private boolean mIsAvailabilityOverriddenByTestApi = false; @@ -846,13 +847,17 @@ public class AlwaysOnHotwordDetector extends AbstractDetector { * @param targetSdkVersion The target SDK version. * @param SupportSandboxedDetectionService {@code true} if HotwordDetectionService should be * triggered, otherwise {@code false}. + * @param attributionTag an optional attribution tag passed form the + * {@link VoiceInteractionService} context via the + * {@link createAlwaysOnHotwordDetectorInternal(String, Locale, boolean, PersistableBundle, + * SharedMemory, ModuleProperties, Executor, Callback)}. * * @hide */ public AlwaysOnHotwordDetector(String text, Locale locale, Executor executor, Callback callback, KeyphraseEnrollmentInfo keyphraseEnrollmentInfo, IVoiceInteractionManagerService modelManagementService, int targetSdkVersion, - boolean supportSandboxedDetectionService) { + boolean supportSandboxedDetectionService, @Nullable String attributionTag) { super(modelManagementService, executor, callback); mHandler = new MyHandler(Looper.getMainLooper()); @@ -865,6 +870,7 @@ public class AlwaysOnHotwordDetector extends AbstractDetector { mInternalCallback = new SoundTriggerListener(mHandler); mModelManagementService = modelManagementService; mSupportSandboxedDetectionService = supportSandboxedDetectionService; + mAttributionTag = attributionTag; } // Do nothing. This method should not be abstract. @@ -876,11 +882,14 @@ public class AlwaysOnHotwordDetector extends AbstractDetector { @Nullable SoundTrigger.ModuleProperties moduleProperties) { if (mSupportSandboxedDetectionService) { initAndVerifyDetector(options, sharedMemory, mInternalCallback, - DETECTOR_TYPE_TRUSTED_HOTWORD_DSP); + DETECTOR_TYPE_TRUSTED_HOTWORD_DSP, mAttributionTag); } try { Identity identity = new Identity(); identity.packageName = ActivityThread.currentOpPackageName(); + if (IS_IDENTITY_WITH_ATTRIBUTION_TAG) { + identity.attributionTag = mAttributionTag; + } if (moduleProperties == null) { moduleProperties = mModelManagementService .listModuleProperties(identity) diff --git a/core/java/android/service/voice/SoftwareHotwordDetector.java b/core/java/android/service/voice/SoftwareHotwordDetector.java index 7ab4fafcf3121..128bc0daedeaf 100644 --- a/core/java/android/service/voice/SoftwareHotwordDetector.java +++ b/core/java/android/service/voice/SoftwareHotwordDetector.java @@ -56,12 +56,14 @@ class SoftwareHotwordDetector extends AbstractDetector { private final HotwordDetector.Callback mCallback; private final AudioFormat mAudioFormat; private final Executor mExecutor; + private final String mAttributionTag; SoftwareHotwordDetector( IVoiceInteractionManagerService managerService, AudioFormat audioFormat, Executor executor, - HotwordDetector.Callback callback) { + HotwordDetector.Callback callback, + String attributionTag) { super(managerService, executor, callback); mManagerService = managerService; @@ -69,13 +71,14 @@ class SoftwareHotwordDetector extends AbstractDetector { mCallback = callback; mExecutor = executor != null ? executor : new HandlerExecutor( new Handler(Looper.getMainLooper())); + mAttributionTag = attributionTag; } @Override void initialize(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) { initAndVerifyDetector(options, sharedMemory, new InitializationStateListener(mExecutor, mCallback), - DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE); + DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE, mAttributionTag); } void onDetectorRemoteException() { diff --git a/core/java/android/service/voice/VisualQueryDetector.java b/core/java/android/service/voice/VisualQueryDetector.java index 93b7964705bae..9e0eb4bdfcd9d 100644 --- a/core/java/android/service/voice/VisualQueryDetector.java +++ b/core/java/android/service/voice/VisualQueryDetector.java @@ -60,15 +60,17 @@ public class VisualQueryDetector { private final Executor mExecutor; private final IVoiceInteractionManagerService mManagerService; private final VisualQueryDetectorInitializationDelegate mInitializationDelegate; + private final String mAttributionTag; VisualQueryDetector( IVoiceInteractionManagerService managerService, @NonNull @CallbackExecutor Executor executor, - Callback callback) { + Callback callback, @Nullable String attributionTag) { mManagerService = managerService; mCallback = callback; mExecutor = executor; mInitializationDelegate = new VisualQueryDetectorInitializationDelegate(); + mAttributionTag = attributionTag; } /** @@ -246,7 +248,7 @@ public class VisualQueryDetector { void initialize(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) { initAndVerifyDetector(options, sharedMemory, new InitializationStateListener(mExecutor, mCallback), - DETECTOR_TYPE_VISUAL_QUERY_DETECTOR); + DETECTOR_TYPE_VISUAL_QUERY_DETECTOR, mAttributionTag); } @Override diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index ab9ae0acc01ed..8cec17fe53400 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -734,7 +734,7 @@ public class VoiceInteractionService extends Service { AlwaysOnHotwordDetector dspDetector = new AlwaysOnHotwordDetector(keyphrase, locale, executor, callback, mKeyphraseEnrollmentInfo, mSystemService, getApplicationContext().getApplicationInfo().targetSdkVersion, - supportHotwordDetectionService); + supportHotwordDetectionService, getAttributionTag()); mActiveDetectors.add(dspDetector); try { @@ -895,7 +895,7 @@ public class VoiceInteractionService extends Service { SoftwareHotwordDetector softwareHotwordDetector = new SoftwareHotwordDetector(mSystemService, /* audioFormat= */ null, - executor, callback); + executor, callback, getAttributionTag()); mActiveDetectors.add(softwareHotwordDetector); try { @@ -965,7 +965,8 @@ public class VoiceInteractionService extends Service { } VisualQueryDetector visualQueryDetector = - new VisualQueryDetector(mSystemService, executor, callback); + new VisualQueryDetector(mSystemService, executor, callback, + getAttributionTag()); HotwordDetector visualQueryDetectorInitializationDelegate = visualQueryDetector.getInitializationDelegate(); mActiveDetectors.add(visualQueryDetectorInitializationDelegate);