diff --git a/api/current.txt b/api/current.txt index b180f7d56fa87..808cb6fd19fe0 100644 --- a/api/current.txt +++ b/api/current.txt @@ -18637,6 +18637,7 @@ package android.service.textservice { method public android.os.Bundle getBundle(); method public java.lang.String getLocale(); method public void onCancel(); + method public void onClose(); method public abstract void onCreate(); method public abstract android.view.textservice.SuggestionsInfo onGetSuggestions(android.view.textservice.TextInfo, int); method public android.view.textservice.SuggestionsInfo[] onGetSuggestionsMultiple(android.view.textservice.TextInfo[], int, boolean); diff --git a/core/java/android/service/textservice/SpellCheckerService.java b/core/java/android/service/textservice/SpellCheckerService.java index 2ecf307bad826..28251a6245c90 100644 --- a/core/java/android/service/textservice/SpellCheckerService.java +++ b/core/java/android/service/textservice/SpellCheckerService.java @@ -145,6 +145,14 @@ public abstract class SpellCheckerService extends Service { */ public void onCancel() {} + /** + * Request to close this session. + * This function will run on the incoming IPC thread. + * So, this is not called on the main thread, + * but will be called in series on another thread. + */ + public void onClose() {} + /** * @return Locale for this session */ @@ -162,7 +170,7 @@ public abstract class SpellCheckerService extends Service { // Preventing from exposing ISpellCheckerSession.aidl, create an internal class. private static class InternalISpellCheckerSession extends ISpellCheckerSession.Stub { - private final ISpellCheckerSessionListener mListener; + private ISpellCheckerSessionListener mListener; private final Session mSession; private final String mLocale; private final Bundle mBundle; @@ -192,6 +200,12 @@ public abstract class SpellCheckerService extends Service { mSession.onCancel(); } + @Override + public void onClose() { + mSession.onClose(); + mListener = null; + } + public String getLocale() { return mLocale; } diff --git a/core/java/android/view/textservice/SpellCheckerSession.java b/core/java/android/view/textservice/SpellCheckerSession.java index 5c3f08918aef9..01b114cfd9294 100644 --- a/core/java/android/view/textservice/SpellCheckerSession.java +++ b/core/java/android/view/textservice/SpellCheckerSession.java @@ -152,6 +152,7 @@ public class SpellCheckerSession { public void close() { mIsUsed = false; try { + mSpellCheckerSessionListenerImpl.close(); mTextServicesManager.finishSpellCheckerService(mSpellCheckerSessionListenerImpl); } catch (RemoteException e) { // do nothing @@ -190,6 +191,7 @@ public class SpellCheckerSession { private static class SpellCheckerSessionListenerImpl extends ISpellCheckerSessionListener.Stub { private static final int TASK_CANCEL = 1; private static final int TASK_GET_SUGGESTIONS_MULTIPLE = 2; + private static final int TASK_CLOSE = 3; private final Queue mPendingTasks = new LinkedList(); private final Handler mHandler; @@ -224,6 +226,9 @@ public class SpellCheckerSession { case TASK_GET_SUGGESTIONS_MULTIPLE: processGetSuggestionsMultiple(scp); break; + case TASK_CLOSE: + processClose(); + break; } } @@ -247,6 +252,13 @@ public class SpellCheckerSession { suggestionsLimit, sequentialWords)); } + public void close() { + if (DBG) { + Log.w(TAG, "close"); + } + processOrEnqueueTask(new SpellCheckerParams(TASK_CLOSE, null, 0, false)); + } + public boolean isDisconnected() { return mOpened && mISpellCheckerSession == null; } @@ -284,6 +296,21 @@ public class SpellCheckerSession { } } + private void processClose() { + if (!checkOpenConnection()) { + return; + } + if (DBG) { + Log.w(TAG, "Close spell checker tasks."); + } + try { + mISpellCheckerSession.onClose(); + mISpellCheckerSession = null; + } catch (RemoteException e) { + Log.e(TAG, "Failed to close " + e); + } + } + private void processGetSuggestionsMultiple(SpellCheckerParams scp) { if (!checkOpenConnection()) { return; diff --git a/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl b/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl index 5a006039d3e73..3c61968664f3d 100644 --- a/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl +++ b/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl @@ -25,4 +25,5 @@ oneway interface ISpellCheckerSession { void onGetSuggestionsMultiple( in TextInfo[] textInfos, int suggestionsLimit, boolean multipleWords); void onCancel(); + void onClose(); }