Use binder thread instead of main thread in HotwordDetectionService

Bug: 180945857
Test: atest CtsVoiceInteractionTestCases
Test: atest CtsVoiceInteractionTestCases --instant
Change-Id: Ib3424b49eb3ae15dbddf6126ae296bcaf7d6b73b
This commit is contained in:
lpeter
2021-05-10 15:01:35 +08:00
parent 22f83b56f7
commit e0fafd2146

View File

@@ -16,9 +16,6 @@
package android.service.voice;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import android.annotation.CallSuper;
import android.annotation.DurationMillisLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -33,10 +30,8 @@ import android.content.Intent;
import android.hardware.soundtrigger.SoundTrigger;
import android.media.AudioFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.RemoteException;
@@ -67,6 +62,8 @@ import java.util.function.IntConsumer;
* to inform the system that a keyphrase was not detected. The system then relays this result to
* the {@link VoiceInteractionService} through {@link HotwordDetector.Callback}.
*
* Note: Methods in this class may be called concurrently
*
* @hide
*/
@SystemApi
@@ -138,8 +135,6 @@ public abstract class HotwordDetectionService extends Service {
public static final String SERVICE_INTERFACE =
"android.service.voice.HotwordDetectionService";
private Handler mHandler;
@Nullable
private ContentCaptureManager mContentCaptureManager;
@@ -154,13 +149,12 @@ public abstract class HotwordDetectionService extends Service {
if (DBG) {
Log.d(TAG, "#detectFromDspSource");
}
mHandler.sendMessage(obtainMessage(HotwordDetectionService::onDetect,
HotwordDetectionService.this,
HotwordDetectionService.this.onDetect(
new AlwaysOnHotwordDetector.EventPayload(
event.triggerInData, event.captureAvailable,
event.captureFormat, event.captureSession, event.data),
timeoutMillis,
new Callback(callback)));
new Callback(callback));
}
@Override
@@ -169,11 +163,10 @@ public abstract class HotwordDetectionService extends Service {
if (DBG) {
Log.d(TAG, "#updateState");
}
mHandler.sendMessage(obtainMessage(HotwordDetectionService::onUpdateStateInternal,
HotwordDetectionService.this,
HotwordDetectionService.this.onUpdateStateInternal(
options,
sharedMemory,
callback));
callback);
}
@Override
@@ -189,19 +182,15 @@ public abstract class HotwordDetectionService extends Service {
}
switch (audioSource) {
case AUDIO_SOURCE_MICROPHONE:
mHandler.sendMessage(obtainMessage(
HotwordDetectionService::onDetect,
HotwordDetectionService.this,
new Callback(callback)));
HotwordDetectionService.this.onDetect(
new Callback(callback));
break;
case AUDIO_SOURCE_EXTERNAL:
mHandler.sendMessage(obtainMessage(
HotwordDetectionService::onDetect,
HotwordDetectionService.this,
HotwordDetectionService.this.onDetect(
audioStream,
audioFormat,
options,
new Callback(callback)));
new Callback(callback));
break;
default:
Log.i(TAG, "Unsupported audio source " + audioSource);
@@ -216,13 +205,6 @@ public abstract class HotwordDetectionService extends Service {
}
};
@CallSuper
@Override
public void onCreate() {
super.onCreate();
mHandler = Handler.createAsync(Looper.getMainLooper());
}
@Override
@Nullable
public final IBinder onBind(@NonNull Intent intent) {