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

Commit bf2e94de authored by Sergey Volnov's avatar Sergey Volnov
Browse files

Redirect all speech recognition traffic through system server.

Test: atest CtsVoiceRecognitionTestCases
Bug: 176578753
Change-Id: I5783257b76fa21c2a6f1d2e589fb843b93753350
parent 091fcad4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -38726,7 +38726,9 @@ package android.speech {
    field public static final int ERROR_NO_MATCH = 7; // 0x7
    field public static final int ERROR_RECOGNIZER_BUSY = 8; // 0x8
    field public static final int ERROR_SERVER = 4; // 0x4
    field public static final int ERROR_SERVER_DISCONNECTED = 11; // 0xb
    field public static final int ERROR_SPEECH_TIMEOUT = 6; // 0x6
    field public static final int ERROR_TOO_MANY_REQUESTS = 10; // 0xa
    field public static final String RESULTS_RECOGNITION = "results_recognition";
  }
+3 −2
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ oneway interface IRecognitionService {
     * @param featureId The feature in the package
     */
    void startListening(in Intent recognizerIntent, in IRecognitionListener listener,
            String packageName, String featureId);
            String packageName, String featureId, int callingUid);

    /**
     * Stops listening for speech. Speech captured so far will be recognized as
@@ -62,6 +62,7 @@ oneway interface IRecognitionService {
     * @param listener to receive callbacks, note that this must be non-null
     * @param packageName the package name calling this API
     * @param featureId The feature in the package
     * @param isShutdown Whether the cancellation is caused by a client calling #shutdown
     */
    void cancel(in IRecognitionListener listener, String packageName, String featureId);
    void cancel(in IRecognitionListener listener, String packageName, String featureId, boolean isShutdown);
}
+8 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.speech;

import android.content.ComponentName;

import android.speech.IRecognitionServiceManagerCallback;

/**
@@ -23,6 +25,10 @@ import android.speech.IRecognitionServiceManagerCallback;
 *
 * {@hide}
 */
interface IRecognitionServiceManager {
    void createSession(in IRecognitionServiceManagerCallback callback);
oneway interface IRecognitionServiceManager {
    void createSession(
        in ComponentName componentName,
        in IBinder clientToken,
        boolean onDevice,
        in IRecognitionServiceManagerCallback callback);
}
+1 −1
Original line number Diff line number Diff line
@@ -25,5 +25,5 @@ import android.speech.IRecognitionService;
 */
oneway interface IRecognitionServiceManagerCallback {
    void onSuccess(in IRecognitionService service);
    void onError();
    void onError(int errorCode);
}
+3 −15
Original line number Diff line number Diff line
@@ -105,17 +105,6 @@ public abstract class RecognitionService extends Service {
            int callingUid) {
        if (mCurrentCallback == null) {
            if (DBG) Log.d(TAG, "created new mCurrentCallback, listener = " + listener.asBinder());
            try {
                listener.asBinder().linkToDeath(new IBinder.DeathRecipient() {
                    @Override
                    public void binderDied() {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_CANCEL, listener));
                    }
                }, 0);
            } catch (RemoteException re) {
                Log.e(TAG, "dead listener on startListening");
                return;
            }
            mCurrentCallback = new Callback(listener, callingUid);
            RecognitionService.this.onStartListening(intent, mCurrentCallback);
        } else {
@@ -352,7 +341,6 @@ public abstract class RecognitionService extends Service {
         * Return the Linux uid assigned to the process that sent you the current transaction that
         * is being processed. This is obtained from {@link Binder#getCallingUid()}.
         */
        // TODO(b/176578753): need to make sure this is fixed when proxied through system.
        public int getCallingUid() {
            return mCallingUid;
        }
@@ -368,7 +356,7 @@ public abstract class RecognitionService extends Service {

        @Override
        public void startListening(Intent recognizerIntent, IRecognitionListener listener,
                String packageName, String featureId) {
                String packageName, String featureId, int callingUid) {
            Preconditions.checkNotNull(packageName);

            if (DBG) Log.d(TAG, "startListening called by:" + listener.asBinder());
@@ -377,7 +365,7 @@ public abstract class RecognitionService extends Service {
                    packageName, featureId)) {
                service.mHandler.sendMessage(Message.obtain(service.mHandler,
                        MSG_START_LISTENING, service.new StartListeningArgs(
                                recognizerIntent, listener, Binder.getCallingUid())));
                                recognizerIntent, listener, callingUid)));
            }
        }

@@ -397,7 +385,7 @@ public abstract class RecognitionService extends Service {

        @Override
        public void cancel(IRecognitionListener listener, String packageName,
                String featureId) {
                String featureId, boolean isShutdown) {
            Preconditions.checkNotNull(packageName);

            if (DBG) Log.d(TAG, "cancel called by:" + listener.asBinder());
Loading