From 95b509ea982a7ddd9ddc2205878406509f549c74 Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Tue, 9 Nov 2021 12:39:20 +0100 Subject: [PATCH] Extract reusing current connection logic Bug: 205676419 Test: make Change-Id: Iea3dff8bd25d4404e4164c32db1216418cffbc62 --- .../InputMethodManagerService.java | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 3b95738f5c42c..962952a4b4a87 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2467,31 +2467,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return attachNewInputLocked(startInputReason, (startInputFlags & StartInputFlags.INITIAL_CONNECTION) != 0); } - if (hasConnection()) { - if (mCurMethod != null) { - // Return to client, and we will get back with it when - // we have had a session made for it. - requestClientSessionLocked(cs); - return new InputBindResult( - InputBindResult.ResultCode.SUCCESS_WAITING_IME_SESSION, - null, null, getCurId(), getSequenceNumber(), false); - } else if (SystemClock.uptimeMillis() - < (getLastBindTime() + TIME_TO_RECONNECT)) { - // In this case we have connected to the service, but - // don't yet have its interface. If it hasn't been too - // long since we did the connection, we'll return to - // the client and wait to get the service interface so - // we can report back. If it has been too long, we want - // to fall through so we can try a disconnect/reconnect - // to see if we can get back in touch with the service. - return new InputBindResult( - InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, - null, null, getCurId(), getSequenceNumber(), false); - } else { - EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, - getSelectedMethodId(), SystemClock.uptimeMillis() - getLastBindTime(), - 0); - } + + InputBindResult bindResult = tryReuseConnectionLocked(cs); + if (bindResult != null) { + return bindResult; } } @@ -2528,6 +2507,37 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } + @GuardedBy("mMethodMap") + @Nullable + private InputBindResult tryReuseConnectionLocked(@NonNull ClientState cs) { + if (hasConnection()) { + if (mCurMethod != null) { + // Return to client, and we will get back with it when + // we have had a session made for it. + requestClientSessionLocked(cs); + return new InputBindResult( + InputBindResult.ResultCode.SUCCESS_WAITING_IME_SESSION, + null, null, getCurId(), getSequenceNumber(), false); + } else if (SystemClock.uptimeMillis() + < (getLastBindTime() + TIME_TO_RECONNECT)) { + // In this case we have connected to the service, but + // don't yet have its interface. If it hasn't been too + // long since we did the connection, we'll return to + // the client and wait to get the service interface so + // we can report back. If it has been too long, we want + // to fall through so we can try a disconnect/reconnect + // to see if we can get back in touch with the service. + return new InputBindResult( + InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, + null, null, getCurId(), getSequenceNumber(), false); + } else { + EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, + getSelectedMethodId(), SystemClock.uptimeMillis() - getLastBindTime(), 0); + } + } + return null; + } + @NonNull private Intent createImeBindingIntent(ComponentName component) { Intent intent = new Intent(InputMethod.SERVICE_INTERFACE);