Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8ce8920 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use binder thread instead of main thread in HotwordDetectionService" into sc-dev

parents c4c9e2ca e0fafd21
Loading
Loading
Loading
Loading
+10 −28
Original line number Diff line number Diff line
@@ -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) {