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 Merged-In: I43a24b27983838e0ef9798eef2f45d1d4b1c9ac8
This commit is contained in:
committed by
Ivan Chiang
parent
53007b4d5b
commit
714691fc46
@@ -39,9 +39,17 @@ import java.util.concurrent.Callable;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
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 OP_MESSAGE = "Streaming hotword audio to VoiceInteractionService";
|
||||||
private static final String TASK_ID_PREFIX = "HotwordDetectedResult@";
|
private static final String TASK_ID_PREFIX = "HotwordDetectedResult@";
|
||||||
private static final String THREAD_NAME_PREFIX = "Copy-";
|
private static final String THREAD_NAME_PREFIX = "Copy-";
|
||||||
@@ -56,7 +64,7 @@ final class HotwordAudioStreamManager {
|
|||||||
private final String mVoiceInteractorAttributionTag;
|
private final String mVoiceInteractorAttributionTag;
|
||||||
private final ExecutorService mExecutorService = Executors.newCachedThreadPool();
|
private final ExecutorService mExecutorService = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
HotwordAudioStreamManager(@NonNull AppOpsManager appOpsManager,
|
HotwordAudioStreamCopier(@NonNull AppOpsManager appOpsManager,
|
||||||
int voiceInteractorUid, @NonNull String voiceInteractorPackageName,
|
int voiceInteractorUid, @NonNull String voiceInteractorPackageName,
|
||||||
@NonNull String voiceInteractorAttributionTag) {
|
@NonNull String voiceInteractorAttributionTag) {
|
||||||
mAppOpsManager = appOpsManager;
|
mAppOpsManager = appOpsManager;
|
||||||
@@ -70,7 +78,7 @@ final class HotwordAudioStreamManager {
|
|||||||
* <p>
|
* <p>
|
||||||
* The returned {@link HotwordDetectedResult} is identical the one that was passed in, except
|
* The returned {@link HotwordDetectedResult} is identical the one that was passed in, except
|
||||||
* that the {@link ParcelFileDescriptor}s within {@link HotwordDetectedResult#getAudioStreams()}
|
* 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).
|
* returned value should be passed on to the client (i.e., the voice interactor).
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
@@ -170,7 +170,7 @@ final class HotwordDetectionConnection {
|
|||||||
private final ScheduledExecutorService mScheduledExecutorService =
|
private final ScheduledExecutorService mScheduledExecutorService =
|
||||||
Executors.newSingleThreadScheduledExecutor();
|
Executors.newSingleThreadScheduledExecutor();
|
||||||
private final AppOpsManager mAppOpsManager;
|
private final AppOpsManager mAppOpsManager;
|
||||||
private final HotwordAudioStreamManager mHotwordAudioStreamManager;
|
private final HotwordAudioStreamCopier mHotwordAudioStreamCopier;
|
||||||
@Nullable private final ScheduledFuture<?> mCancellationTaskFuture;
|
@Nullable private final ScheduledFuture<?> mCancellationTaskFuture;
|
||||||
private final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false);
|
private final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false);
|
||||||
private final IBinder.DeathRecipient mAudioServerDeathRecipient = this::audioServerDied;
|
private final IBinder.DeathRecipient mAudioServerDeathRecipient = this::audioServerDied;
|
||||||
@@ -232,7 +232,7 @@ final class HotwordDetectionConnection {
|
|||||||
mVoiceInteractionServiceUid = voiceInteractionServiceUid;
|
mVoiceInteractionServiceUid = voiceInteractionServiceUid;
|
||||||
mVoiceInteractorIdentity = voiceInteractorIdentity;
|
mVoiceInteractorIdentity = voiceInteractorIdentity;
|
||||||
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
|
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
|
||||||
mHotwordAudioStreamManager = new HotwordAudioStreamManager(mAppOpsManager,
|
mHotwordAudioStreamCopier = new HotwordAudioStreamCopier(mAppOpsManager,
|
||||||
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
|
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
|
||||||
mVoiceInteractorIdentity.attributionTag);
|
mVoiceInteractorIdentity.attributionTag);
|
||||||
mDetectionComponentName = serviceName;
|
mDetectionComponentName = serviceName;
|
||||||
@@ -491,7 +491,7 @@ final class HotwordDetectionConnection {
|
|||||||
saveProximityValueToBundle(result);
|
saveProximityValueToBundle(result);
|
||||||
HotwordDetectedResult newResult;
|
HotwordDetectedResult newResult;
|
||||||
try {
|
try {
|
||||||
newResult = mHotwordAudioStreamManager.startCopyingAudioStreams(result);
|
newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: Write event
|
// TODO: Write event
|
||||||
mSoftwareCallback.onError();
|
mSoftwareCallback.onError();
|
||||||
@@ -683,7 +683,7 @@ final class HotwordDetectionConnection {
|
|||||||
saveProximityValueToBundle(result);
|
saveProximityValueToBundle(result);
|
||||||
HotwordDetectedResult newResult;
|
HotwordDetectedResult newResult;
|
||||||
try {
|
try {
|
||||||
newResult = mHotwordAudioStreamManager.startCopyingAudioStreams(result);
|
newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: Write event
|
// TODO: Write event
|
||||||
externalCallback.onError(CALLBACK_ONDETECTED_STREAM_COPY_ERROR);
|
externalCallback.onError(CALLBACK_ONDETECTED_STREAM_COPY_ERROR);
|
||||||
@@ -1015,7 +1015,7 @@ final class HotwordDetectionConnection {
|
|||||||
HotwordDetectedResult newResult;
|
HotwordDetectedResult newResult;
|
||||||
try {
|
try {
|
||||||
newResult =
|
newResult =
|
||||||
mHotwordAudioStreamManager.startCopyingAudioStreams(
|
mHotwordAudioStreamCopier.startCopyingAudioStreams(
|
||||||
triggerResult);
|
triggerResult);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: Write event
|
// TODO: Write event
|
||||||
|
|||||||
Reference in New Issue
Block a user