Move binding current method into the controller
This is a step in a larger refactoring. Bug: 205676419 Test: make Change-Id: I0c86ea0e1f96070f039d960a2e5ef6e93c4cfab0
This commit is contained in:
@@ -22,6 +22,7 @@ import static com.android.server.inputmethod.InputMethodManagerService.MSG_INITI
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -34,11 +35,14 @@ import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Trace;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Slog;
|
||||
import android.view.inputmethod.InputMethod;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.inputmethod.InputBindResult;
|
||||
import com.android.internal.inputmethod.UnbindReason;
|
||||
import com.android.internal.view.IInputMethod;
|
||||
import com.android.server.inputmethod.InputMethodManagerService.ClientState;
|
||||
@@ -203,10 +207,6 @@ final class InputMethodBindingController {
|
||||
return mCurIntent;
|
||||
}
|
||||
|
||||
void setCurIntent(@Nullable Intent curIntent) {
|
||||
mCurIntent = curIntent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current binding sequence number, incremented every time there is
|
||||
* a new bind performed.
|
||||
@@ -377,6 +377,42 @@ final class InputMethodBindingController {
|
||||
mService.clearCurMethodLocked();
|
||||
}
|
||||
|
||||
@GuardedBy("mMethodMap")
|
||||
@NonNull
|
||||
InputBindResult bindCurrentMethodLocked(int displayIdToShowIme) {
|
||||
InputMethodInfo info = mMethodMap.get(mSelectedMethodId);
|
||||
if (info == null) {
|
||||
throw new IllegalArgumentException("Unknown id: " + mSelectedMethodId);
|
||||
}
|
||||
|
||||
Intent intent = createImeBindingIntent(info.getComponent());
|
||||
mCurIntent = intent;
|
||||
|
||||
if (bindCurrentInputMethodServiceMainConnectionLocked()) {
|
||||
mService.addFreshWindowTokenLocked(displayIdToShowIme, info.getId());
|
||||
return new InputBindResult(
|
||||
InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING,
|
||||
null, null, mCurId, mCurSeq, false);
|
||||
}
|
||||
|
||||
mCurIntent = null;
|
||||
Slog.w(InputMethodManagerService.TAG,
|
||||
"Failure connecting to input method service: " + intent);
|
||||
return InputBindResult.IME_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Intent createImeBindingIntent(ComponentName component) {
|
||||
Intent intent = new Intent(InputMethod.SERVICE_INTERFACE);
|
||||
intent.setComponent(component);
|
||||
intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
|
||||
com.android.internal.R.string.input_method_binding_label);
|
||||
intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
|
||||
mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS),
|
||||
PendingIntent.FLAG_IMMUTABLE));
|
||||
return intent;
|
||||
}
|
||||
|
||||
@GuardedBy("mMethodMap")
|
||||
void unbindMainConnectionLocked() {
|
||||
mContext.unbindService(mMainConnection);
|
||||
@@ -413,6 +449,4 @@ final class InputMethodBindingController {
|
||||
return mHasConnection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -589,10 +589,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
return mBindingController.getCurIntent();
|
||||
}
|
||||
|
||||
private void setCurIntent(@Nullable Intent curIntent) {
|
||||
mBindingController.setCurIntent(curIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* The token we have made for the currently active input method, to
|
||||
* identify it in the future.
|
||||
@@ -2422,32 +2418,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
|
||||
mBindingController.unbindCurrentMethodLocked();
|
||||
|
||||
return bindCurrentMethodLocked(displayIdToShowIme);
|
||||
}
|
||||
|
||||
|
||||
@GuardedBy("mMethodMap")
|
||||
@NonNull
|
||||
private InputBindResult bindCurrentMethodLocked(int displayIdToShowIme) {
|
||||
String selectedMethodId = getSelectedMethodId();
|
||||
InputMethodInfo info = mMethodMap.get(selectedMethodId);
|
||||
if (info == null) {
|
||||
throw new IllegalArgumentException("Unknown id: " + selectedMethodId);
|
||||
}
|
||||
|
||||
Intent intent = createImeBindingIntent(info.getComponent());
|
||||
setCurIntent(intent);
|
||||
|
||||
if (mBindingController.bindCurrentInputMethodServiceMainConnectionLocked()) {
|
||||
addFreshWindowTokenLocked(displayIdToShowIme, info.getId());
|
||||
return new InputBindResult(
|
||||
InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING,
|
||||
null, null, getCurId(), getSequenceNumber(), false);
|
||||
}
|
||||
|
||||
setCurIntent(null);
|
||||
Slog.w(TAG, "Failure connecting to input method service: " + intent);
|
||||
return InputBindResult.IME_NOT_CONNECTED;
|
||||
return mBindingController.bindCurrentMethodLocked(displayIdToShowIme);
|
||||
}
|
||||
|
||||
private boolean isSelectedMethodBound(int displayIdToShowIme) {
|
||||
@@ -2501,20 +2472,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Intent createImeBindingIntent(ComponentName component) {
|
||||
Intent intent = new Intent(InputMethod.SERVICE_INTERFACE);
|
||||
intent.setComponent(component);
|
||||
intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
|
||||
com.android.internal.R.string.input_method_binding_label);
|
||||
intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
|
||||
mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS),
|
||||
PendingIntent.FLAG_IMMUTABLE));
|
||||
return intent;
|
||||
}
|
||||
|
||||
@GuardedBy("mMethodMap")
|
||||
private void addFreshWindowTokenLocked(int displayIdToShowIme, String methodId) {
|
||||
void addFreshWindowTokenLocked(int displayIdToShowIme, String methodId) {
|
||||
Binder token = new Binder();
|
||||
setCurToken(token);
|
||||
setLastBindTime(SystemClock.uptimeMillis());
|
||||
|
||||
Reference in New Issue
Block a user