From 584eccfe95a5a25fc030d52eaf460cf74c41b407 Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Thu, 11 Aug 2022 22:00:59 +0000 Subject: [PATCH 1/2] Revert "Refactor ProximityUpdateCallbackInternal to interface" Revert submission 17936037-hotword_proximity Reason for revert: https://buganizer.corp.google.com/issues/242223069 Reverted Changes: If8c23a9c6:Refactor ProximityUpdateCallbackInternal to interf... Ib0ad1da25:Verify that proximity key is added to the hotword ... I71e9d3da9:Add proximity state to the HotwordDetectedResult Change-Id: Ibfc65901547d74d6fcfafc257653f49a17a98662 --- .../attention/AttentionManagerInternal.java | 4 ++-- .../server/attention/AttentionManagerService.java | 6 ++++-- .../HotwordDetectionConnection.java | 15 ++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/java/android/attention/AttentionManagerInternal.java b/core/java/android/attention/AttentionManagerInternal.java index 24fe0dbe5760a..47bec618cfd9c 100644 --- a/core/java/android/attention/AttentionManagerInternal.java +++ b/core/java/android/attention/AttentionManagerInternal.java @@ -83,11 +83,11 @@ public abstract class AttentionManagerInternal { } /** Internal interface for proximity callback. */ - public interface ProximityUpdateCallbackInternal { + public abstract static class ProximityUpdateCallbackInternal { /** * @param distance the estimated distance of the user (in meter) * The distance will be PROXIMITY_UNKNOWN if the proximity sensing was inconclusive. */ - void onProximityUpdate(double distance); + public abstract void onProximityUpdate(double distance); } } diff --git a/services/core/java/com/android/server/attention/AttentionManagerService.java b/services/core/java/com/android/server/attention/AttentionManagerService.java index d4ef638d08181..a948ce22497e5 100644 --- a/services/core/java/com/android/server/attention/AttentionManagerService.java +++ b/services/core/java/com/android/server/attention/AttentionManagerService.java @@ -856,6 +856,9 @@ public class AttentionManagerService extends SystemService { @GuardedBy("mLock") private void cancelAndUnbindLocked() { synchronized (mLock) { + if (mCurrentAttentionCheck == null && mCurrentProximityUpdate == null) { + return; + } if (mCurrentAttentionCheck != null) { cancel(); } @@ -937,7 +940,7 @@ public class AttentionManagerService extends SystemService { } } - class TestableProximityUpdateCallbackInternal implements ProximityUpdateCallbackInternal { + class TestableProximityUpdateCallbackInternal extends ProximityUpdateCallbackInternal { private double mLastCallbackCode = PROXIMITY_UNKNOWN; @Override @@ -1069,7 +1072,6 @@ public class AttentionManagerService extends SystemService { private void resetStates() { synchronized (mLock) { mCurrentProximityUpdate = null; - cancelAndUnbindLocked(); } mComponentName = resolveAttentionService(mContext); } diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index 2eae68bd31827..96491ac4553f6 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -192,7 +192,14 @@ final class HotwordDetectionConnection { final AttentionManagerInternal mAttentionManagerInternal; final AttentionManagerInternal.ProximityUpdateCallbackInternal mProximityCallbackInternal = - this::setProximityMeters; + new AttentionManagerInternal.ProximityUpdateCallbackInternal() { + @Override + public void onProximityUpdate(double distance) { + synchronized (mLock) { + mProximityMeters = distance; + } + } + }; volatile HotwordDetectionServiceIdentity mIdentity; @@ -1183,12 +1190,6 @@ final class HotwordDetectionConnection { } } - private void setProximityMeters(double proximityMeters) { - synchronized (mLock) { - mProximityMeters = proximityMeters; - } - } - private static void bestEffortClose(Closeable... closeables) { for (Closeable closeable : closeables) { bestEffortClose(closeable); From dbe5ad1a72efea402f35e2e3e938f0c16e1473bc Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Thu, 11 Aug 2022 22:00:59 +0000 Subject: [PATCH 2/2] Revert "Add proximity state to the HotwordDetectedResult" Revert submission 17936037-hotword_proximity Reason for revert: https://buganizer.corp.google.com/issues/242223069 Reverted Changes: If8c23a9c6:Refactor ProximityUpdateCallbackInternal to interf... Ib0ad1da25:Verify that proximity key is added to the hotword ... I71e9d3da9:Add proximity state to the HotwordDetectedResult Change-Id: I6b79d9400671362dd63be1e2a0d05280003587d3 --- .../service/voice/HotwordDetectedResult.java | 57 ++----------------- .../attention/AttentionManagerService.java | 3 - .../HotwordDetectionConnection.java | 31 ---------- 3 files changed, 4 insertions(+), 87 deletions(-) diff --git a/core/java/android/service/voice/HotwordDetectedResult.java b/core/java/android/service/voice/HotwordDetectedResult.java index ab71459ed51e0..72341453a1f4d 100644 --- a/core/java/android/service/voice/HotwordDetectedResult.java +++ b/core/java/android/service/voice/HotwordDetectedResult.java @@ -95,16 +95,6 @@ public final class HotwordDetectedResult implements Parcelable { /** Limits the max value for the triggered audio channel. */ private static final int LIMIT_AUDIO_CHANNEL_MAX_VALUE = 63; - /** - * The bundle key for proximity value - * - * TODO(b/238896013): Move the proximity logic out of bundle to proper API. - * - * @hide - */ - public static final String EXTRA_PROXIMITY_METERS = - "android.service.voice.extra.PROXIMITY_METERS"; - /** Confidence level in the trigger outcome. */ @HotwordConfidenceLevelValue private final int mConfidenceLevel; @@ -207,14 +197,6 @@ public final class HotwordDetectedResult implements Parcelable { *

The use of this method is discouraged, and support for it will be removed in future * versions of Android. * - *

After the trigger happens, a special case of proximity-related extra, with the key of - * 'android.service.voice.extra.PROXIMITY_METERS' and the value of distance in meters (double), - * will be stored to enable proximity logic. The proximity meters is provided by the system, - * on devices that support detecting proximity of nearby users, to help disambiguate which - * nearby device should respond. When the proximity is unknown, the proximity value will not - * be stored. This mapping will be excluded from the max bundle size calculation because this - * mapping is included after the result is returned from the hotword detector service. - * *

This is a PersistableBundle so it doesn't allow any remotable objects or other contents * that can be used to communicate with other processes. */ @@ -333,23 +315,8 @@ public final class HotwordDetectedResult implements Parcelable { "audioChannel"); } if (!mExtras.isEmpty()) { - // Remove the proximity key from the bundle before checking the bundle size. The - // proximity value is added after the privileged module and can avoid the - // maxBundleSize limitation. - if (mExtras.containsKey(EXTRA_PROXIMITY_METERS)) { - double proximityMeters = mExtras.getDouble(EXTRA_PROXIMITY_METERS); - mExtras.remove(EXTRA_PROXIMITY_METERS); - // Skip checking parcelable size if the new bundle size is 0. Newly empty bundle - // has parcelable size of 4, but the default bundle has parcelable size of 0. - if (mExtras.size() > 0) { - Preconditions.checkArgumentInRange(getParcelableSize(mExtras), 0, - getMaxBundleSize(), "extras"); - } - mExtras.putDouble(EXTRA_PROXIMITY_METERS, proximityMeters); - } else { - Preconditions.checkArgumentInRange(getParcelableSize(mExtras), 0, - getMaxBundleSize(), "extras"); - } + Preconditions.checkArgumentInRange(getParcelableSize(mExtras), 0, getMaxBundleSize(), + "extras"); } } @@ -546,14 +513,6 @@ public final class HotwordDetectedResult implements Parcelable { *

The use of this method is discouraged, and support for it will be removed in future * versions of Android. * - *

After the trigger happens, a special case of proximity-related extra, with the key of - * 'android.service.voice.extra.PROXIMITY_METERS' and the value of distance in meters (double), - * will be stored to enable proximity logic. The proximity meters is provided by the system, - * on devices that support detecting proximity of nearby users, to help disambiguate which - * nearby device should respond. When the proximity is unknown, the proximity value will not - * be stored. This mapping will be excluded from the max bundle size calculation because this - * mapping is included after the result is returned from the hotword detector service. - * *

This is a PersistableBundle so it doesn't allow any remotable objects or other contents * that can be used to communicate with other processes. */ @@ -854,14 +813,6 @@ public final class HotwordDetectedResult implements Parcelable { *

The use of this method is discouraged, and support for it will be removed in future * versions of Android. * - *

After the trigger happens, a special case of proximity-related extra, with the key of - * 'android.service.voice.extra.PROXIMITY_METERS' and the value of distance in meters (double), - * will be stored to enable proximity logic. The proximity meters is provided by the system, - * on devices that support detecting proximity of nearby users, to help disambiguate which - * nearby device should respond. When the proximity is unknown, the proximity value will not - * be stored. This mapping will be excluded from the max bundle size calculation because this - * mapping is included after the result is returned from the hotword detector service. - * *

This is a PersistableBundle so it doesn't allow any remotable objects or other contents * that can be used to communicate with other processes. */ @@ -931,10 +882,10 @@ public final class HotwordDetectedResult implements Parcelable { } @DataClass.Generated( - time = 1658357814396L, + time = 1625541522353L, codegenVersion = "1.0.23", sourceFile = "frameworks/base/core/java/android/service/voice/HotwordDetectedResult.java", - inputSignatures = "public static final int CONFIDENCE_LEVEL_NONE\npublic static final int CONFIDENCE_LEVEL_LOW\npublic static final int CONFIDENCE_LEVEL_LOW_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM_HIGH\npublic static final int CONFIDENCE_LEVEL_HIGH\npublic static final int CONFIDENCE_LEVEL_VERY_HIGH\npublic static final int HOTWORD_OFFSET_UNSET\npublic static final int AUDIO_CHANNEL_UNSET\nprivate static final int LIMIT_HOTWORD_OFFSET_MAX_VALUE\nprivate static final int LIMIT_AUDIO_CHANNEL_MAX_VALUE\npublic static final java.lang.String EXTRA_PROXIMITY_METERS\nprivate final @android.service.voice.HotwordDetectedResult.HotwordConfidenceLevelValue int mConfidenceLevel\nprivate @android.annotation.Nullable android.media.MediaSyncEvent mMediaSyncEvent\nprivate int mHotwordOffsetMillis\nprivate int mHotwordDurationMillis\nprivate int mAudioChannel\nprivate boolean mHotwordDetectionPersonalized\nprivate final int mScore\nprivate final int mPersonalizedScore\nprivate final int mHotwordPhraseId\nprivate final @android.annotation.NonNull android.os.PersistableBundle mExtras\nprivate static int sMaxBundleSize\nprivate static int defaultConfidenceLevel()\nprivate static int defaultScore()\nprivate static int defaultPersonalizedScore()\npublic static int getMaxScore()\nprivate static int defaultHotwordPhraseId()\npublic static int getMaxHotwordPhraseId()\nprivate static android.os.PersistableBundle defaultExtras()\npublic static int getMaxBundleSize()\npublic @android.annotation.Nullable android.media.MediaSyncEvent getMediaSyncEvent()\npublic static int getParcelableSize(android.os.Parcelable)\npublic static int getUsageSize(android.service.voice.HotwordDetectedResult)\nprivate static int bitCount(long)\nprivate void onConstructed()\nclass HotwordDetectedResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)") + inputSignatures = "public static final int CONFIDENCE_LEVEL_NONE\npublic static final int CONFIDENCE_LEVEL_LOW\npublic static final int CONFIDENCE_LEVEL_LOW_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM_HIGH\npublic static final int CONFIDENCE_LEVEL_HIGH\npublic static final int CONFIDENCE_LEVEL_VERY_HIGH\npublic static final int HOTWORD_OFFSET_UNSET\npublic static final int AUDIO_CHANNEL_UNSET\nprivate static final int LIMIT_HOTWORD_OFFSET_MAX_VALUE\nprivate static final int LIMIT_AUDIO_CHANNEL_MAX_VALUE\nprivate final @android.service.voice.HotwordDetectedResult.HotwordConfidenceLevelValue int mConfidenceLevel\nprivate @android.annotation.Nullable android.media.MediaSyncEvent mMediaSyncEvent\nprivate int mHotwordOffsetMillis\nprivate int mHotwordDurationMillis\nprivate int mAudioChannel\nprivate boolean mHotwordDetectionPersonalized\nprivate final int mScore\nprivate final int mPersonalizedScore\nprivate final int mHotwordPhraseId\nprivate final @android.annotation.NonNull android.os.PersistableBundle mExtras\nprivate static int sMaxBundleSize\nprivate static int defaultConfidenceLevel()\nprivate static int defaultScore()\nprivate static int defaultPersonalizedScore()\npublic static int getMaxScore()\nprivate static int defaultHotwordPhraseId()\npublic static int getMaxHotwordPhraseId()\nprivate static android.os.PersistableBundle defaultExtras()\npublic static int getMaxBundleSize()\npublic @android.annotation.Nullable android.media.MediaSyncEvent getMediaSyncEvent()\npublic static int getParcelableSize(android.os.Parcelable)\npublic static int getUsageSize(android.service.voice.HotwordDetectedResult)\nprivate static int bitCount(long)\nprivate void onConstructed()\nclass HotwordDetectedResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)") @Deprecated private void __metadata() {} diff --git a/services/core/java/com/android/server/attention/AttentionManagerService.java b/services/core/java/com/android/server/attention/AttentionManagerService.java index a948ce22497e5..d16fe1240d0c3 100644 --- a/services/core/java/com/android/server/attention/AttentionManagerService.java +++ b/services/core/java/com/android/server/attention/AttentionManagerService.java @@ -343,9 +343,6 @@ public class AttentionManagerService extends SystemService { * * Calling this multiple times for duplicate requests will be no-ops, returning true. * - * TODO(b/239130847): Maintain the proximity state in AttentionManagerService and change this - * to a polling API. - * * @return {@code true} if the framework was able to dispatch the request */ @VisibleForTesting diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index 96491ac4553f6..1e0e8366c385e 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -18,8 +18,6 @@ package com.android.server.voiceinteraction; import static android.Manifest.permission.CAPTURE_AUDIO_HOTWORD; import static android.Manifest.permission.RECORD_AUDIO; -import static android.service.attention.AttentionService.PROXIMITY_UNKNOWN; -import static android.service.voice.HotwordDetectedResult.EXTRA_PROXIMITY_METERS; import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_EXTERNAL; import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_MICROPHONE; import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_SUCCESS; @@ -60,7 +58,6 @@ import static com.android.server.voiceinteraction.SoundTriggerSessionPermissions import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppOpsManager; -import android.attention.AttentionManagerInternal; import android.content.ComponentName; import android.content.ContentCaptureOptions; import android.content.Context; @@ -189,19 +186,6 @@ final class HotwordDetectionConnection { final int mUser; final Context mContext; - final AttentionManagerInternal mAttentionManagerInternal; - - final AttentionManagerInternal.ProximityUpdateCallbackInternal mProximityCallbackInternal = - new AttentionManagerInternal.ProximityUpdateCallbackInternal() { - @Override - public void onProximityUpdate(double distance) { - synchronized (mLock) { - mProximityMeters = distance; - } - } - }; - - volatile HotwordDetectionServiceIdentity mIdentity; private IMicrophoneHotwordDetectionVoiceInteractionCallback mSoftwareCallback; private Instant mLastRestartInstant; @@ -222,8 +206,6 @@ final class HotwordDetectionConnection { private @NonNull ServiceConnection mRemoteHotwordDetectionService; private IBinder mAudioFlinger; private boolean mDebugHotwordLogging = false; - @GuardedBy("mLock") - private double mProximityMeters = PROXIMITY_UNKNOWN; HotwordDetectionConnection(Object lock, Context context, int voiceInteractionServiceUid, Identity voiceInteractorIdentity, ComponentName serviceName, int userId, @@ -251,8 +233,6 @@ final class HotwordDetectionConnection { mServiceConnectionFactory = new ServiceConnectionFactory(intent, bindInstantServiceAllowed); mRemoteHotwordDetectionService = mServiceConnectionFactory.createLocked(); - mAttentionManagerInternal = LocalServices.getService(AttentionManagerInternal.class); - mAttentionManagerInternal.onStartProximityUpdates(mProximityCallbackInternal); mLastRestartInstant = Instant.now(); updateStateAfterProcessStart(options, sharedMemory); @@ -417,7 +397,6 @@ final class HotwordDetectionConnection { if (mAudioFlinger != null) { mAudioFlinger.unlinkToDeath(mAudioServerDeathRecipient, /* flags= */ 0); } - mAttentionManagerInternal.onStopProximityUpdates(mProximityCallbackInternal); } void updateStateLocked(PersistableBundle options, SharedMemory sharedMemory) { @@ -485,7 +464,6 @@ final class HotwordDetectionConnection { mSoftwareCallback.onError(); return; } - saveProximityMetersToBundle(result); mSoftwareCallback.onDetected(result, null, null); if (result != null) { Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(result) @@ -613,7 +591,6 @@ final class HotwordDetectionConnection { externalCallback.onError(CALLBACK_ONDETECTED_GOT_SECURITY_EXCEPTION); return; } - saveProximityMetersToBundle(result); externalCallback.onKeyphraseDetected(recognitionEvent, result); if (result != null) { Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(result) @@ -1182,14 +1159,6 @@ final class HotwordDetectionConnection { }); } - private void saveProximityMetersToBundle(HotwordDetectedResult result) { - synchronized (mLock) { - if (result != null && mProximityMeters != PROXIMITY_UNKNOWN) { - result.getExtras().putDouble(EXTRA_PROXIMITY_METERS, mProximityMeters); - } - } - } - private static void bestEffortClose(Closeable... closeables) { for (Closeable closeable : closeables) { bestEffortClose(closeable);