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

Commit 27230bee authored by Andrea Ambu's avatar Andrea Ambu
Browse files

speech: Allow isolated process to start ODSR

Bug: 230581623
Test: manual

Change-Id: I80cafe81b43c21ea2d626a86b4b13233c0c7fa92
parent 4d41feb8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SharedMemory;
import android.speech.IRecognitionServiceManager;
import android.util.Log;
import android.view.contentcapture.ContentCaptureManager;
import android.view.contentcapture.IContentCaptureManager;
@@ -127,6 +128,8 @@ public abstract class HotwordDetectionService extends Service {

    @Nullable
    private ContentCaptureManager mContentCaptureManager;
    @Nullable
    private IRecognitionServiceManager mIRecognitionServiceManager;

    private final IHotwordDetectionService mInterface = new IHotwordDetectionService.Stub() {
        @Override
@@ -195,6 +198,11 @@ public abstract class HotwordDetectionService extends Service {
                    HotwordDetectionService.this, manager, options);
        }

        @Override
        public void updateRecognitionServiceManager(IRecognitionServiceManager manager) {
            mIRecognitionServiceManager = manager;
        }

        @Override
        public void ping(IRemoteCallback callback) throws RemoteException {
            callback.sendResult(null);
@@ -222,6 +230,9 @@ public abstract class HotwordDetectionService extends Service {
    public @Nullable Object getSystemService(@ServiceName @NonNull String name) {
        if (Context.CONTENT_CAPTURE_MANAGER_SERVICE.equals(name)) {
            return mContentCaptureManager;
        } else if (Context.SPEECH_RECOGNITION_SERVICE.equals(name)
                && mIRecognitionServiceManager != null) {
            return mIRecognitionServiceManager.asBinder();
        } else {
            return super.getSystemService(name);
        }
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.PersistableBundle;
import android.os.SharedMemory;
import android.service.voice.IDspHotwordDetectionCallback;
import android.view.contentcapture.IContentCaptureManager;
import android.speech.IRecognitionServiceManager;

/**
 * Provide the interface to communicate with hotword detection service.
@@ -57,6 +58,9 @@ oneway interface IHotwordDetectionService {
        in IContentCaptureManager contentCaptureManager,
        in ContentCaptureOptions options);

    void updateRecognitionServiceManager(
        in IRecognitionServiceManager recognitionServiceManager);

    /**
     * Simply requests the service to trigger the callback, so that the system can check its
     * identity.
+5 −5
Original line number Diff line number Diff line
@@ -735,12 +735,12 @@ public class SpeechRecognizer {
            return true;
        }

        mManagerService = IRecognitionServiceManager.Stub.asInterface(
                ServiceManager.getService(Context.SPEECH_RECOGNITION_SERVICE));

        if (DBG) {
            Log.i(TAG, "#maybeInitializeManagerService instantiated =" + mManagerService);
        IBinder service = ServiceManager.getService(Context.SPEECH_RECOGNITION_SERVICE);
        if (service == null && mOnDevice) {
            service = (IBinder) mContext.getSystemService(Context.SPEECH_RECOGNITION_SERVICE);
        }
        mManagerService = IRecognitionServiceManager.Stub.asInterface(service);

        if (mManagerService == null) {
            if (mListener != null) {
                mListener.onError(ERROR_CLIENT);
+7 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.permission.PermissionManager;
import android.speech.IRecognitionListener;
@@ -103,6 +104,12 @@ final class SpeechRecognitionManagerServiceImpl extends
            serviceComponent = getOnDeviceComponentNameLocked();
        }

        if (!onDevice && Process.isIsolated(Binder.getCallingUid())) {
            Slog.w(TAG, "Isolated process can only start on device speech recognizer.");
            tryRespondWithError(callback, SpeechRecognizer.ERROR_CLIENT);
            return;
        }

        if (serviceComponent == null) {
            if (mMaster.debug) {
                Slog.i(TAG, "Service component is undefined, responding with error.");
+10 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import android.service.voice.IDspHotwordDetectionCallback;
import android.service.voice.IHotwordDetectionService;
import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback;
import android.service.voice.VoiceInteractionManagerInternal.HotwordDetectionServiceIdentity;
import android.speech.IRecognitionServiceManager;
import android.text.TextUtils;
import android.util.Pair;
import android.util.Slog;
@@ -923,6 +924,7 @@ final class HotwordDetectionConnection {

            updateAudioFlinger(connection, mAudioFlinger);
            updateContentCaptureManager(connection);
            updateSpeechService(connection);
            updateServiceIdentity(connection);
            return connection;
        }
@@ -1060,6 +1062,14 @@ final class HotwordDetectionConnection {
                        new ContentCaptureOptions(null)));
    }

    private static void updateSpeechService(ServiceConnection connection) {
        IBinder b = ServiceManager.getService(Context.SPEECH_RECOGNITION_SERVICE);
        IRecognitionServiceManager binderService = IRecognitionServiceManager.Stub.asInterface(b);
        connection.run(service -> {
            service.updateRecognitionServiceManager(binderService);
        });
    }

    private void updateServiceIdentity(ServiceConnection connection) {
        connection.run(service -> service.ping(new IRemoteCallback.Stub() {
            @Override