Rename HotwordAudioStreamManager and add Javadoc

"Manager" is a little vague and "Copier" is clearer with the class's
purpose.

Bug: 258323047
Test: None with this change; simple refactoring
Change-Id: I43a24b27983838e0ef9798eef2f45d1d4b1c9ac8
This commit is contained in:
Mark Punzalan
2022-11-23 08:51:27 +00:00
parent 2e6c85187e
commit 585c555cc9
3 changed files with 22 additions and 14 deletions

View File

@@ -39,9 +39,17 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
final class HotwordAudioStreamManager {
/**
* Copies the audio streams in {@link HotwordDetectedResult}s. This allows the system to manage the
* lifetime of the {@link ParcelFileDescriptor}s and ensures that the flow of data is in the right
* direction from the {@link android.service.voice.HotwordDetectionService} to the client (i.e., the
* voice interactor).
*
* @hide
*/
final class HotwordAudioStreamCopier {
private static final String TAG = "HotwordAudioStreamManager";
private static final String TAG = "HotwordAudioStreamCopier";
private static final String OP_MESSAGE = "Streaming hotword audio to VoiceInteractionService";
private static final String TASK_ID_PREFIX = "HotwordDetectedResult@";
private static final String THREAD_NAME_PREFIX = "Copy-";
@@ -56,7 +64,7 @@ final class HotwordAudioStreamManager {
private final String mVoiceInteractorAttributionTag;
private final ExecutorService mExecutorService = Executors.newCachedThreadPool();
HotwordAudioStreamManager(@NonNull AppOpsManager appOpsManager,
HotwordAudioStreamCopier(@NonNull AppOpsManager appOpsManager,
int voiceInteractorUid, @NonNull String voiceInteractorPackageName,
@NonNull String voiceInteractorAttributionTag) {
mAppOpsManager = appOpsManager;
@@ -70,7 +78,7 @@ final class HotwordAudioStreamManager {
* <p>
* The returned {@link HotwordDetectedResult} is identical the one that was passed in, except
* that the {@link ParcelFileDescriptor}s within {@link HotwordDetectedResult#getAudioStreams()}
* are replaced with descriptors from pipes managed by {@link HotwordAudioStreamManager}. The
* are replaced with descriptors from pipes managed by {@link HotwordAudioStreamCopier}. The
* returned value should be passed on to the client (i.e., the voice interactor).
* </p>
*

View File

@@ -183,7 +183,7 @@ final class HotwordDetectionConnection {
private final ScheduledExecutorService mScheduledExecutorService =
Executors.newSingleThreadScheduledExecutor();
private final AppOpsManager mAppOpsManager;
private final HotwordAudioStreamManager mHotwordAudioStreamManager;
private final HotwordAudioStreamCopier mHotwordAudioStreamCopier;
@Nullable private final ScheduledFuture<?> mCancellationTaskFuture;
private final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false);
private final IBinder.DeathRecipient mAudioServerDeathRecipient = this::audioServerDied;
@@ -245,7 +245,7 @@ final class HotwordDetectionConnection {
mVoiceInteractionServiceUid = voiceInteractionServiceUid;
mVoiceInteractorIdentity = voiceInteractorIdentity;
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
mHotwordAudioStreamManager = new HotwordAudioStreamManager(mAppOpsManager,
mHotwordAudioStreamCopier = new HotwordAudioStreamCopier(mAppOpsManager,
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
mVoiceInteractorIdentity.attributionTag);
mDetectionComponentName = serviceName;
@@ -507,7 +507,7 @@ final class HotwordDetectionConnection {
saveProximityValueToBundle(result);
HotwordDetectedResult newResult;
try {
newResult = mHotwordAudioStreamManager.startCopyingAudioStreams(result);
newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
} catch (IOException e) {
// TODO: Write event
mSoftwareCallback.onError();
@@ -642,7 +642,7 @@ final class HotwordDetectionConnection {
saveProximityValueToBundle(result);
HotwordDetectedResult newResult;
try {
newResult = mHotwordAudioStreamManager.startCopyingAudioStreams(result);
newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
} catch (IOException e) {
// TODO: Write event
externalCallback.onError(CALLBACK_ONDETECTED_STREAM_COPY_ERROR);
@@ -1001,7 +1001,7 @@ final class HotwordDetectionConnection {
HotwordDetectedResult newResult;
try {
newResult =
mHotwordAudioStreamManager.startCopyingAudioStreams(
mHotwordAudioStreamCopier.startCopyingAudioStreams(
triggerResult);
} catch (IOException e) {
// TODO: Write event

View File

@@ -183,7 +183,7 @@ final class TrustedHotwordDetectorSession {
private final ScheduledExecutorService mScheduledExecutorService =
Executors.newSingleThreadScheduledExecutor();
private final AppOpsManager mAppOpsManager;
private final HotwordAudioStreamManager mHotwordAudioStreamManager;
private final HotwordAudioStreamCopier mHotwordAudioStreamCopier;
@Nullable private final ScheduledFuture<?> mCancellationTaskFuture;
private final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false);
private final IBinder.DeathRecipient mAudioServerDeathRecipient = this::audioServerDied;
@@ -245,7 +245,7 @@ final class TrustedHotwordDetectorSession {
mVoiceInteractionServiceUid = voiceInteractionServiceUid;
mVoiceInteractorIdentity = voiceInteractorIdentity;
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
mHotwordAudioStreamManager = new HotwordAudioStreamManager(mAppOpsManager,
mHotwordAudioStreamCopier = new HotwordAudioStreamCopier(mAppOpsManager,
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
mVoiceInteractorIdentity.attributionTag);
mDetectionComponentName = serviceName;
@@ -507,7 +507,7 @@ final class TrustedHotwordDetectorSession {
saveProximityValueToBundle(result);
HotwordDetectedResult newResult;
try {
newResult = mHotwordAudioStreamManager.startCopyingAudioStreams(result);
newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
} catch (IOException e) {
// TODO: Write event
mSoftwareCallback.onError();
@@ -642,7 +642,7 @@ final class TrustedHotwordDetectorSession {
saveProximityValueToBundle(result);
HotwordDetectedResult newResult;
try {
newResult = mHotwordAudioStreamManager.startCopyingAudioStreams(result);
newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
} catch (IOException e) {
// TODO: Write event
externalCallback.onError(CALLBACK_ONDETECTED_STREAM_COPY_ERROR);
@@ -1001,7 +1001,7 @@ final class TrustedHotwordDetectorSession {
HotwordDetectedResult newResult;
try {
newResult =
mHotwordAudioStreamManager.startCopyingAudioStreams(
mHotwordAudioStreamCopier.startCopyingAudioStreams(
triggerResult);
} catch (IOException e) {
// TODO: Write event