Merge "bugfix for: OOM error while doing voice search repeatedly" into froyo
This commit is contained in:
committed by
Android (Google) Code Review
commit
cb4c894afa
@@ -53,6 +53,9 @@ public abstract class RecognitionService extends Service {
|
||||
/** Debugging flag */
|
||||
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
|
||||
* {@link RecognitionService#onStartListening(Intent, Callback)} method
|
||||
@@ -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
|
||||
*
|
||||
@@ -210,6 +188,14 @@ public abstract class RecognitionService extends Service {
|
||||
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
|
||||
* user. An instance of this class is passed to the
|
||||
@@ -306,4 +292,42 @@ public abstract class RecognitionService extends Service {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +382,7 @@ public class SpeechRecognizer {
|
||||
mPendingTasks.clear();
|
||||
mService = null;
|
||||
mConnection = null;
|
||||
mListener.mInternalListener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user