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

Commit b6f489fc authored by Andrea Ambu's avatar Andrea Ambu Committed by Android (Google) Code Review
Browse files

Merge "speech: Wire calling in uid on support callback"

parents 2ecc7764 3833e44f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -41450,9 +41450,11 @@ package android.speech {
    method public final android.os.IBinder onBind(android.content.Intent);
    method protected abstract void onCancel(android.speech.RecognitionService.Callback);
    method public void onCheckRecognitionSupport(@NonNull android.content.Intent, @NonNull android.speech.RecognitionService.SupportCallback);
    method public void onCheckRecognitionSupport(@NonNull android.content.Intent, @NonNull android.content.AttributionSource, @NonNull android.speech.RecognitionService.SupportCallback);
    method protected abstract void onStartListening(android.content.Intent, android.speech.RecognitionService.Callback);
    method protected abstract void onStopListening(android.speech.RecognitionService.Callback);
    method public void onTriggerModelDownload(@NonNull android.content.Intent);
    method public void onTriggerModelDownload(@NonNull android.content.Intent, @NonNull android.content.AttributionSource);
    field public static final String SERVICE_INTERFACE = "android.speech.RecognitionService";
    field public static final String SERVICE_META_DATA = "android.speech";
  }
+5 −2
Original line number Diff line number Diff line
@@ -67,12 +67,15 @@ oneway interface IRecognitionService {
     * given recognizerIntent. For more information see {@link #startListening} and
     * {@link RecognizerIntent}.
     */
    void checkRecognitionSupport(in Intent recognizerIntent, in IRecognitionSupportCallback listener);
    void checkRecognitionSupport(
        in Intent recognizerIntent,
        in AttributionSource attributionSource,
        in IRecognitionSupportCallback listener);

    /**
     * Requests RecognitionService to download the support for the given recognizerIntent. For more
     * information see {@link #checkRecognitionSupport},  {@link #startListening} and
     * {@link RecognizerIntent}.
     */
    void triggerModelDownload(in Intent recognizerIntent);
    void triggerModelDownload(in Intent recognizerIntent, in AttributionSource attributionSource);
}
+73 −13
Original line number Diff line number Diff line
@@ -110,13 +110,14 @@ public abstract class RecognitionService extends Service {
                    dispatchClearCallback((IRecognitionListener) msg.obj);
                    break;
                case MSG_CHECK_RECOGNITION_SUPPORT:
                    Pair<Intent, IRecognitionSupportCallback> intentAndListener =
                            (Pair<Intent, IRecognitionSupportCallback>) msg.obj;
                    CheckRecognitionSupportArgs checkArgs = (CheckRecognitionSupportArgs) msg.obj;
                    dispatchCheckRecognitionSupport(
                            intentAndListener.first, intentAndListener.second);
                            checkArgs.mIntent, checkArgs.callback, checkArgs.mAttributionSource);
                    break;
                case MSG_TRIGGER_MODEL_DOWNLOAD:
                    dispatchTriggerModelDownload((Intent) msg.obj);
                    Pair<Intent, AttributionSource> params =
                            (Pair<Intent, AttributionSource>) msg.obj;
                    dispatchTriggerModelDownload(params.first, params.second);
                    break;
            }
        }
@@ -211,12 +212,18 @@ public abstract class RecognitionService extends Service {
    }

    private void dispatchCheckRecognitionSupport(
            Intent intent, IRecognitionSupportCallback callback) {
        RecognitionService.this.onCheckRecognitionSupport(intent, new SupportCallback(callback));
            Intent intent, IRecognitionSupportCallback callback,
            AttributionSource attributionSource) {
        RecognitionService.this.onCheckRecognitionSupport(
                intent,
                attributionSource,
                new SupportCallback(callback));
    }

    private void dispatchTriggerModelDownload(Intent intent) {
        RecognitionService.this.onTriggerModelDownload(intent);
    private void dispatchTriggerModelDownload(
            Intent intent,
            AttributionSource attributionSource) {
        RecognitionService.this.onTriggerModelDownload(intent, attributionSource);
    }

    private static class StartListeningArgs {
@@ -233,6 +240,21 @@ public abstract class RecognitionService extends Service {
        }
    }

    private static class CheckRecognitionSupportArgs {
        public final Intent mIntent;
        public final IRecognitionSupportCallback callback;
        public final AttributionSource mAttributionSource;

        private CheckRecognitionSupportArgs(
                Intent intent,
                IRecognitionSupportCallback callback,
                AttributionSource attributionSource) {
            this.mIntent = intent;
            this.callback = callback;
            this.mAttributionSource = attributionSource;
        }
    }

    /**
     * Notifies the service that it should start listening for speech.
     *
@@ -297,6 +319,26 @@ public abstract class RecognitionService extends Service {
        supportCallback.onError(SpeechRecognizer.ERROR_CANNOT_CHECK_SUPPORT);
    }

    /**
     * Queries the service on whether it would support a {@link #onStartListening(Intent, Callback)}
     * for the same {@code recognizerIntent}.
     *
     * <p>The service will notify the caller about the level of support or error via
     * {@link SupportCallback}.
     *
     * <p>If the service does not offer the support check it will notify the caller with
     * {@link SpeechRecognizer#ERROR_CANNOT_CHECK_SUPPORT}.
     *
     * <p>Provides the calling AttributionSource to the service implementation so that permissions
     * and bandwidth could be correctly blamed.</p>
     */
    public void onCheckRecognitionSupport(
            @NonNull Intent recognizerIntent,
            @NonNull AttributionSource attributionSource,
            @NonNull SupportCallback supportCallback) {
        onCheckRecognitionSupport(recognizerIntent, supportCallback);
    }

    /**
     * Requests the download of the recognizer support for {@code recognizerIntent}.
     */
@@ -306,6 +348,18 @@ public abstract class RecognitionService extends Service {
        }
    }

    /**
     * Requests the download of the recognizer support for {@code recognizerIntent}.
     *
     * <p>Provides the calling AttributionSource to the service implementation so that permissions
     * and bandwidth could be correctly blamed.</p>
     */
    public void onTriggerModelDownload(
            @NonNull Intent recognizerIntent,
            @NonNull AttributionSource attributionSource) {
        onTriggerModelDownload(recognizerIntent);
    }

    @Override
    @SuppressLint("MissingNullability")
    public Context createContext(@NonNull ContextParams contextParams) {
@@ -524,7 +578,8 @@ public abstract class RecognitionService extends Service {
    public static class SupportCallback {
        private final IRecognitionSupportCallback mCallback;

        private SupportCallback(IRecognitionSupportCallback callback) {
        private SupportCallback(
                IRecognitionSupportCallback callback) {
            this.mCallback = callback;
        }

@@ -596,22 +651,27 @@ public abstract class RecognitionService extends Service {

        @Override
        public void checkRecognitionSupport(
                Intent recognizerIntent, IRecognitionSupportCallback callback) {
                Intent recognizerIntent,
                @NonNull AttributionSource attributionSource,
                IRecognitionSupportCallback callback) {
            final RecognitionService service = mServiceRef.get();
            if (service != null) {
                service.mHandler.sendMessage(
                        Message.obtain(service.mHandler, MSG_CHECK_RECOGNITION_SUPPORT,
                                Pair.create(recognizerIntent, callback)));
                                new CheckRecognitionSupportArgs(
                                        recognizerIntent, callback, attributionSource)));
            }
        }

        @Override
        public void triggerModelDownload(Intent recognizerIntent) {
        public void triggerModelDownload(
                Intent recognizerIntent, @NonNull AttributionSource attributionSource) {
            final RecognitionService service = mServiceRef.get();
            if (service != null) {
                service.mHandler.sendMessage(
                        Message.obtain(
                                service.mHandler, MSG_TRIGGER_MODEL_DOWNLOAD, recognizerIntent));
                                service.mHandler, MSG_TRIGGER_MODEL_DOWNLOAD,
                                Pair.create(recognizerIntent, attributionSource)));
            }
        }

+2 −1
Original line number Diff line number Diff line
@@ -663,6 +663,7 @@ public class SpeechRecognizer {
        try {
            mService.checkRecognitionSupport(
                    recognizerIntent,
                    mContext.getAttributionSource(),
                    new InternalSupportCallback(callbackExecutor, recognitionSupportCallback));
            if (DBG) Log.d(TAG, "service support command succeeded");
        } catch (final RemoteException e) {
@@ -676,7 +677,7 @@ public class SpeechRecognizer {
            return;
        }
        try {
            mService.triggerModelDownload(recognizerIntent);
            mService.triggerModelDownload(recognizerIntent, mContext.getAttributionSource());
        } catch (final RemoteException e) {
            Log.e(TAG, "downloadModel() failed", e);
            mListener.onError(ERROR_CLIENT);
+6 −3
Original line number Diff line number Diff line
@@ -233,7 +233,9 @@ final class RemoteSpeechRecognitionService extends ServiceConnector.Impl<IRecogn

    void checkRecognitionSupport(
            Intent recognizerIntent,
            AttributionSource attributionSource,
            IRecognitionSupportCallback callback) {

        if (!mConnected) {
            try {
                callback.onError(SpeechRecognizer.ERROR_SERVER_DISCONNECTED);
@@ -243,15 +245,16 @@ final class RemoteSpeechRecognitionService extends ServiceConnector.Impl<IRecogn
            }
            return;
        }
        run(service -> service.checkRecognitionSupport(recognizerIntent, callback));
        run(service ->
                service.checkRecognitionSupport(recognizerIntent, attributionSource, callback));
    }

    void triggerModelDownload(Intent recognizerIntent) {
    void triggerModelDownload(Intent recognizerIntent, AttributionSource attributionSource) {
        if (!mConnected) {
            Slog.e(TAG, "#downloadModel failed due to connection.");
            return;
        }
        run(service -> service.triggerModelDownload(recognizerIntent));
        run(service -> service.triggerModelDownload(recognizerIntent, attributionSource));
    }

    void shutdown(IBinder clientToken) {
Loading