Loading core/java/android/speech/RecognitionService.java +49 −25 Original line number Original line Diff line number Diff line Loading @@ -53,6 +53,9 @@ public abstract class RecognitionService extends Service { /** Debugging flag */ /** Debugging flag */ private static final boolean DBG = false; private static final boolean DBG = false; /** Binder of the recognition service */ private RecognitionServiceBinder mBinder = new RecognitionServiceBinder(this); /** /** * The current callback of an application that invoked the * The current callback of an application that invoked the * {@link RecognitionService#onStartListening(Intent, Callback)} method * {@link RecognitionService#onStartListening(Intent, Callback)} method Loading Loading @@ -136,31 +139,6 @@ public abstract class RecognitionService extends Service { } } } } /** Binder of the recognition service */ private final IRecognitionService.Stub mBinder = new IRecognitionService.Stub() { public void startListening(Intent recognizerIntent, IRecognitionListener listener) { if (DBG) Log.d(TAG, "startListening called by:" + listener.asBinder()); if (checkPermissions(listener)) { mHandler.sendMessage(Message.obtain(mHandler, MSG_START_LISTENING, new StartListeningArgs(recognizerIntent, listener))); } } public void stopListening(IRecognitionListener listener) { if (DBG) Log.d(TAG, "stopListening called by:" + listener.asBinder()); if (checkPermissions(listener)) { mHandler.sendMessage(Message.obtain(mHandler, MSG_STOP_LISTENING, listener)); } } public void cancel(IRecognitionListener listener) { if (DBG) Log.d(TAG, "cancel called by:" + listener.asBinder()); if (checkPermissions(listener)) { mHandler.sendMessage(Message.obtain(mHandler, MSG_CANCEL, listener)); } } }; /** /** * Checks whether the caller has sufficient permissions * Checks whether the caller has sufficient permissions * * Loading Loading @@ -210,6 +188,14 @@ public abstract class RecognitionService extends Service { return mBinder; return mBinder; } } @Override public void onDestroy() { if (DBG) Log.d(TAG, "onDestroy"); mCurrentCallback = null; mBinder.clearReference(); super.onDestroy(); } /** /** * This class receives callbacks from the speech recognition service and forwards them to the * This class receives callbacks from the speech recognition service and forwards them to the * user. An instance of this class is passed to the * user. An instance of this class is passed to the Loading Loading @@ -306,4 +292,42 @@ public abstract class RecognitionService extends Service { mListener.onRmsChanged(rmsdB); mListener.onRmsChanged(rmsdB); } } } } /** Binder of the recognition service */ private static class RecognitionServiceBinder extends IRecognitionService.Stub { private RecognitionService mInternalService; public RecognitionServiceBinder(RecognitionService service) { mInternalService = service; } public void startListening(Intent recognizerIntent, IRecognitionListener listener) { if (DBG) Log.d(TAG, "startListening called by:" + listener.asBinder()); if (mInternalService != null && mInternalService.checkPermissions(listener)) { mInternalService.mHandler.sendMessage(Message.obtain(mInternalService.mHandler, MSG_START_LISTENING, mInternalService.new StartListeningArgs( recognizerIntent, listener))); } } public void stopListening(IRecognitionListener listener) { if (DBG) Log.d(TAG, "stopListening called by:" + listener.asBinder()); if (mInternalService != null && mInternalService.checkPermissions(listener)) { mInternalService.mHandler.sendMessage(Message.obtain(mInternalService.mHandler, MSG_STOP_LISTENING, listener)); } } public void cancel(IRecognitionListener listener) { if (DBG) Log.d(TAG, "cancel called by:" + listener.asBinder()); if (mInternalService != null && mInternalService.checkPermissions(listener)) { mInternalService.mHandler.sendMessage(Message.obtain(mInternalService.mHandler, MSG_CANCEL, listener)); } } public void clearReference() { mInternalService = null; } } } } core/java/android/speech/SpeechRecognizer.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -382,6 +382,7 @@ public class SpeechRecognizer { mPendingTasks.clear(); mPendingTasks.clear(); mService = null; mService = null; mConnection = null; mConnection = null; mListener.mInternalListener = null; } } /** /** Loading Loading
core/java/android/speech/RecognitionService.java +49 −25 Original line number Original line Diff line number Diff line Loading @@ -53,6 +53,9 @@ public abstract class RecognitionService extends Service { /** Debugging flag */ /** Debugging flag */ private static final boolean DBG = false; private static final boolean DBG = false; /** Binder of the recognition service */ private RecognitionServiceBinder mBinder = new RecognitionServiceBinder(this); /** /** * The current callback of an application that invoked the * The current callback of an application that invoked the * {@link RecognitionService#onStartListening(Intent, Callback)} method * {@link RecognitionService#onStartListening(Intent, Callback)} method Loading Loading @@ -136,31 +139,6 @@ public abstract class RecognitionService extends Service { } } } } /** Binder of the recognition service */ private final IRecognitionService.Stub mBinder = new IRecognitionService.Stub() { public void startListening(Intent recognizerIntent, IRecognitionListener listener) { if (DBG) Log.d(TAG, "startListening called by:" + listener.asBinder()); if (checkPermissions(listener)) { mHandler.sendMessage(Message.obtain(mHandler, MSG_START_LISTENING, new StartListeningArgs(recognizerIntent, listener))); } } public void stopListening(IRecognitionListener listener) { if (DBG) Log.d(TAG, "stopListening called by:" + listener.asBinder()); if (checkPermissions(listener)) { mHandler.sendMessage(Message.obtain(mHandler, MSG_STOP_LISTENING, listener)); } } public void cancel(IRecognitionListener listener) { if (DBG) Log.d(TAG, "cancel called by:" + listener.asBinder()); if (checkPermissions(listener)) { mHandler.sendMessage(Message.obtain(mHandler, MSG_CANCEL, listener)); } } }; /** /** * Checks whether the caller has sufficient permissions * Checks whether the caller has sufficient permissions * * Loading Loading @@ -210,6 +188,14 @@ public abstract class RecognitionService extends Service { return mBinder; return mBinder; } } @Override public void onDestroy() { if (DBG) Log.d(TAG, "onDestroy"); mCurrentCallback = null; mBinder.clearReference(); super.onDestroy(); } /** /** * This class receives callbacks from the speech recognition service and forwards them to the * This class receives callbacks from the speech recognition service and forwards them to the * user. An instance of this class is passed to the * user. An instance of this class is passed to the Loading Loading @@ -306,4 +292,42 @@ public abstract class RecognitionService extends Service { mListener.onRmsChanged(rmsdB); mListener.onRmsChanged(rmsdB); } } } } /** Binder of the recognition service */ private static class RecognitionServiceBinder extends IRecognitionService.Stub { private RecognitionService mInternalService; public RecognitionServiceBinder(RecognitionService service) { mInternalService = service; } public void startListening(Intent recognizerIntent, IRecognitionListener listener) { if (DBG) Log.d(TAG, "startListening called by:" + listener.asBinder()); if (mInternalService != null && mInternalService.checkPermissions(listener)) { mInternalService.mHandler.sendMessage(Message.obtain(mInternalService.mHandler, MSG_START_LISTENING, mInternalService.new StartListeningArgs( recognizerIntent, listener))); } } public void stopListening(IRecognitionListener listener) { if (DBG) Log.d(TAG, "stopListening called by:" + listener.asBinder()); if (mInternalService != null && mInternalService.checkPermissions(listener)) { mInternalService.mHandler.sendMessage(Message.obtain(mInternalService.mHandler, MSG_STOP_LISTENING, listener)); } } public void cancel(IRecognitionListener listener) { if (DBG) Log.d(TAG, "cancel called by:" + listener.asBinder()); if (mInternalService != null && mInternalService.checkPermissions(listener)) { mInternalService.mHandler.sendMessage(Message.obtain(mInternalService.mHandler, MSG_CANCEL, listener)); } } public void clearReference() { mInternalService = null; } } } }
core/java/android/speech/SpeechRecognizer.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -382,6 +382,7 @@ public class SpeechRecognizer { mPendingTasks.clear(); mPendingTasks.clear(); mService = null; mService = null; mConnection = null; mConnection = null; mListener.mInternalListener = null; } } /** /** Loading