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

Commit 4f7bd130 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Use binder thread instead of main thread in HotwordDetectionService"...

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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14484648

Change-Id: I7a46dbb3f283a80038460053346bd082395ae666
parents d86fb556 e8ce8920
Loading
Loading
Loading
Loading
+10 −28
Original line number Original line Diff line number Diff line
@@ -16,9 +16,6 @@


package android.service.voice;
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.DurationMillisLong;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -33,10 +30,8 @@ import android.content.Intent;
import android.hardware.soundtrigger.SoundTrigger;
import android.hardware.soundtrigger.SoundTrigger;
import android.media.AudioFormat;
import android.media.AudioFormat;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.IRemoteCallback;
import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.RemoteException;
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
 * to inform the system that a keyphrase was not detected. The system then relays this result to
 * the {@link VoiceInteractionService} through {@link HotwordDetector.Callback}.
 * the {@link VoiceInteractionService} through {@link HotwordDetector.Callback}.
 *
 *
 * Note: Methods in this class may be called concurrently
 *
 * @hide
 * @hide
 */
 */
@SystemApi
@SystemApi
@@ -138,8 +135,6 @@ public abstract class HotwordDetectionService extends Service {
    public static final String SERVICE_INTERFACE =
    public static final String SERVICE_INTERFACE =
            "android.service.voice.HotwordDetectionService";
            "android.service.voice.HotwordDetectionService";


    private Handler mHandler;

    @Nullable
    @Nullable
    private ContentCaptureManager mContentCaptureManager;
    private ContentCaptureManager mContentCaptureManager;


@@ -154,13 +149,12 @@ public abstract class HotwordDetectionService extends Service {
            if (DBG) {
            if (DBG) {
                Log.d(TAG, "#detectFromDspSource");
                Log.d(TAG, "#detectFromDspSource");
            }
            }
            mHandler.sendMessage(obtainMessage(HotwordDetectionService::onDetect,
            HotwordDetectionService.this.onDetect(
                    HotwordDetectionService.this,
                    new AlwaysOnHotwordDetector.EventPayload(
                    new AlwaysOnHotwordDetector.EventPayload(
                            event.triggerInData, event.captureAvailable,
                            event.triggerInData, event.captureAvailable,
                            event.captureFormat, event.captureSession, event.data),
                            event.captureFormat, event.captureSession, event.data),
                    timeoutMillis,
                    timeoutMillis,
                    new Callback(callback)));
                    new Callback(callback));
        }
        }


        @Override
        @Override
@@ -169,11 +163,10 @@ public abstract class HotwordDetectionService extends Service {
            if (DBG) {
            if (DBG) {
                Log.d(TAG, "#updateState");
                Log.d(TAG, "#updateState");
            }
            }
            mHandler.sendMessage(obtainMessage(HotwordDetectionService::onUpdateStateInternal,
            HotwordDetectionService.this.onUpdateStateInternal(
                    HotwordDetectionService.this,
                    options,
                    options,
                    sharedMemory,
                    sharedMemory,
                    callback));
                    callback);
        }
        }


        @Override
        @Override
@@ -189,19 +182,15 @@ public abstract class HotwordDetectionService extends Service {
            }
            }
            switch (audioSource) {
            switch (audioSource) {
                case AUDIO_SOURCE_MICROPHONE:
                case AUDIO_SOURCE_MICROPHONE:
                    mHandler.sendMessage(obtainMessage(
                    HotwordDetectionService.this.onDetect(
                            HotwordDetectionService::onDetect,
                            new Callback(callback));
                            HotwordDetectionService.this,
                            new Callback(callback)));
                    break;
                    break;
                case AUDIO_SOURCE_EXTERNAL:
                case AUDIO_SOURCE_EXTERNAL:
                    mHandler.sendMessage(obtainMessage(
                    HotwordDetectionService.this.onDetect(
                            HotwordDetectionService::onDetect,
                            HotwordDetectionService.this,
                            audioStream,
                            audioStream,
                            audioFormat,
                            audioFormat,
                            options,
                            options,
                            new Callback(callback)));
                            new Callback(callback));
                    break;
                    break;
                default:
                default:
                    Log.i(TAG, "Unsupported audio source " + audioSource);
                    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
    @Override
    @Nullable
    @Nullable
    public final IBinder onBind(@NonNull Intent intent) {
    public final IBinder onBind(@NonNull Intent intent) {