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

Commit c1fb6dc1 authored by Jerome Poichet's avatar Jerome Poichet
Browse files

Make sure cancel is called on tear down.

- Make sure cancel is called when consumer of SpeechRecognizer calls
  destroy.
- If consumer goes away, make sure to call cancel as well.

b/17584947 Pressing mic button in Music hoses audio

Change-Id: Ibe1198b37fe6167493a8694f9089d970f1eb07de
parent 496aeb1a
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -91,9 +91,20 @@ public abstract class RecognitionService extends Service {
        }
    };

    private void dispatchStartListening(Intent intent, IRecognitionListener listener) {
    private void dispatchStartListening(Intent intent, final IRecognitionListener listener) {
        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);
            RecognitionService.this.onStartListening(intent, mCurrentCallback);
        } else {
+8 −0
Original line number Diff line number Diff line
@@ -396,6 +396,14 @@ public class SpeechRecognizer {
     * Destroys the {@code SpeechRecognizer} object.
     */
    public void destroy() {
        if (mService != null) {
            try {
                mService.cancel(mListener);
            } catch (final RemoteException e) {
                // Not important
            }
        }

        if (mConnection != null) {
            mContext.unbindService(mConnection);
        }