use of com.android.internal.view.InputBindResult in project android_frameworks_base by ParanoidAndroid.
the class InputMethodManagerService method windowGainedFocus.
@Override
public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode, int windowFlags, EditorInfo attribute, IInputContext inputContext) {
// Needs to check the validity before clearing calling identity
final boolean calledFromValidUser = calledFromValidUser();
InputBindResult res = null;
long ident = Binder.clearCallingIdentity();
try {
synchronized (mMethodMap) {
if (DEBUG)
Slog.v(TAG, "windowGainedFocus: " + client.asBinder() + " controlFlags=#" + Integer.toHexString(controlFlags) + " softInputMode=#" + Integer.toHexString(softInputMode) + " windowFlags=#" + Integer.toHexString(windowFlags));
ClientState cs = mClients.get(client.asBinder());
if (cs == null) {
throw new IllegalArgumentException("unknown client " + client.asBinder());
}
try {
if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
// Check with the window manager to make sure this client actually
// has a window with focus. If not, reject. This is thread safe
// because if the focus changes some time before or after, the
// next client receiving focus that has any interest in input will
// be calling through here after that change happens.
Slog.w(TAG, "Focus gain on non-focused client " + cs.client + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
return null;
}
} catch (RemoteException e) {
}
if (!calledFromValidUser) {
Slog.w(TAG, "A background user is requesting window. Hiding IME.");
Slog.w(TAG, "If you want to interect with IME, you need " + "android.permission.INTERACT_ACROSS_USERS_FULL");
hideCurrentInputLocked(0, null);
return null;
}
if (mCurFocusedWindow == windowToken) {
Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client + " attribute=" + attribute + ", token = " + windowToken);
if (attribute != null) {
return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
}
return null;
}
mCurFocusedWindow = windowToken;
// Should we auto-show the IME even if the caller has not
// specified what should be done with it?
// We only do this automatically if the window can resize
// to accommodate the IME (so what the user sees will give
// them good context without input information being obscured
// by the IME) or if running on a large screen where there
// is more room for the target window + IME.
final boolean doAutoShow = (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE || mRes.getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE);
final boolean isTextEditor = (controlFlags & InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0;
// We want to start input before showing the IME, but after closing
// it. We want to do this after closing it to help the IME disappear
// more quickly (not get stuck behind it initializing itself for the
// new focused input, even if its window wants to hide the IME).
boolean didStart = false;
switch(softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
if (!isTextEditor || !doAutoShow) {
if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
// soft input window if it is shown.
if (DEBUG)
Slog.v(TAG, "Unspecified window will hide input");
hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
}
} else if (isTextEditor && doAutoShow && (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
// is more room for the target window + IME.
if (DEBUG)
Slog.v(TAG, "Unspecified window will show input");
if (attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
didStart = true;
}
showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
}
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
// Do nothing.
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
if ((softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
if (DEBUG)
Slog.v(TAG, "Window asks to hide input going forward");
hideCurrentInputLocked(0, null);
}
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
if (DEBUG)
Slog.v(TAG, "Window asks to hide input");
hideCurrentInputLocked(0, null);
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
if ((softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
if (DEBUG)
Slog.v(TAG, "Window asks to show input going forward");
if (attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
didStart = true;
}
showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
}
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
if (DEBUG)
Slog.v(TAG, "Window asks to always show input");
if (attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
didStart = true;
}
showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
break;
}
if (!didStart && attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
}
}
} finally {
Binder.restoreCallingIdentity(ident);
}
return res;
}
use of com.android.internal.view.InputBindResult in project android_frameworks_base by ParanoidAndroid.
the class InputMethodManagerService method startInputUncheckedLocked.
InputBindResult startInputUncheckedLocked(ClientState cs, IInputContext inputContext, EditorInfo attribute, int controlFlags) {
// If no method is currently selected, do nothing.
if (mCurMethodId == null) {
return mNoBinding;
}
if (mCurClient == null) {
mInputBoundToKeyguard = mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
if (DEBUG) {
Slog.v(TAG, "New bind. keyguard = " + mInputBoundToKeyguard);
}
}
if (mCurClient != cs) {
// If the client is changing, we need to switch over to the new
// one.
unbindCurrentClientLocked();
if (DEBUG)
Slog.v(TAG, "switching to client: client = " + cs.client.asBinder());
// If the screen is on, inform the new client it is active
if (mScreenOn) {
executeOrSendMessage(cs.client, mCaller.obtainMessageIO(MSG_SET_ACTIVE, mScreenOn ? 1 : 0, cs));
}
}
// Bump up the sequence for this client and attach it.
mCurSeq++;
if (mCurSeq <= 0)
mCurSeq = 1;
mCurClient = cs;
mCurInputContext = inputContext;
mCurAttribute = attribute;
// Check if the input method is changing.
if (mCurId != null && mCurId.equals(mCurMethodId)) {
if (cs.curSession != null) {
// then just return it.
return attachNewInputLocked((controlFlags & InputMethodManager.CONTROL_START_INITIAL) != 0);
}
if (mHaveConnection) {
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(null, null, mCurId, mCurSeq);
} else if (SystemClock.uptimeMillis() < (mLastBindTime + TIME_TO_RECONNECT)) {
// to see if we can get back in touch with the service.
return new InputBindResult(null, null, mCurId, mCurSeq);
} else {
EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, SystemClock.uptimeMillis() - mLastBindTime, 0);
}
}
}
return startInputInnerLocked();
}
use of com.android.internal.view.InputBindResult in project android_frameworks_base by ParanoidAndroid.
the class InputMethodManagerService method onSessionCreated.
void onSessionCreated(IInputMethod method, IInputMethodSession session, InputChannel channel) {
synchronized (mMethodMap) {
if (mCurMethod != null && method != null && mCurMethod.asBinder() == method.asBinder()) {
if (mCurClient != null) {
clearClientSessionLocked(mCurClient);
mCurClient.curSession = new SessionState(mCurClient, method, session, channel);
InputBindResult res = attachNewInputLocked(true);
if (res.method != null) {
executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(MSG_BIND_METHOD, mCurClient.client, res));
}
return;
}
}
}
// Session abandoned. Close its associated input channel.
channel.dispose();
}
use of com.android.internal.view.InputBindResult in project android_frameworks_base by ResurrectionRemix.
the class InputMethodManagerService method windowGainedFocus.
private InputBindResult windowGainedFocus(/* @InputMethodClient.StartInputReason */
final int startInputReason, IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode, int windowFlags, EditorInfo attribute, IInputContext inputContext, /* @InputConnectionInspector.missingMethods */
final int missingMethods) {
// Needs to check the validity before clearing calling identity
final boolean calledFromValidUser = calledFromValidUser();
InputBindResult res = null;
long ident = Binder.clearCallingIdentity();
try {
synchronized (mMethodMap) {
if (DEBUG)
Slog.v(TAG, "windowGainedFocus: reason=" + InputMethodClient.getStartInputReason(startInputReason) + " client=" + client.asBinder() + " inputContext=" + inputContext + " missingMethods=" + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) + " attribute=" + attribute + " controlFlags=#" + Integer.toHexString(controlFlags) + " softInputMode=#" + Integer.toHexString(softInputMode) + " windowFlags=#" + Integer.toHexString(windowFlags));
ClientState cs = mClients.get(client.asBinder());
if (cs == null) {
throw new IllegalArgumentException("unknown client " + client.asBinder());
}
try {
if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
// Check with the window manager to make sure this client actually
// has a window with focus. If not, reject. This is thread safe
// because if the focus changes some time before or after, the
// next client receiving focus that has any interest in input will
// be calling through here after that change happens.
Slog.w(TAG, "Focus gain on non-focused client " + cs.client + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
return null;
}
} catch (RemoteException e) {
}
if (!calledFromValidUser) {
Slog.w(TAG, "A background user is requesting window. Hiding IME.");
Slog.w(TAG, "If you want to interect with IME, you need " + "android.permission.INTERACT_ACROSS_USERS_FULL");
hideCurrentInputLocked(0, null);
return null;
}
if (mCurFocusedWindow == windowToken) {
Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client + " attribute=" + attribute + ", token = " + windowToken);
if (attribute != null) {
return startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, controlFlags);
}
return null;
}
mCurFocusedWindow = windowToken;
mCurFocusedWindowClient = cs;
// Should we auto-show the IME even if the caller has not
// specified what should be done with it?
// We only do this automatically if the window can resize
// to accommodate the IME (so what the user sees will give
// them good context without input information being obscured
// by the IME) or if running on a large screen where there
// is more room for the target window + IME.
final boolean doAutoShow = (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE || mRes.getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE);
final boolean isTextEditor = (controlFlags & InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0;
// We want to start input before showing the IME, but after closing
// it. We want to do this after closing it to help the IME disappear
// more quickly (not get stuck behind it initializing itself for the
// new focused input, even if its window wants to hide the IME).
boolean didStart = false;
switch(softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
if (!isTextEditor || !doAutoShow) {
if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
// soft input window if it is shown.
if (DEBUG)
Slog.v(TAG, "Unspecified window will hide input");
hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
}
} else if (isTextEditor && doAutoShow && (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
// is more room for the target window + IME.
if (DEBUG)
Slog.v(TAG, "Unspecified window will show input");
if (attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, controlFlags);
didStart = true;
}
showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
}
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
// Do nothing.
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
if ((softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
if (DEBUG)
Slog.v(TAG, "Window asks to hide input going forward");
hideCurrentInputLocked(0, null);
}
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
if (DEBUG)
Slog.v(TAG, "Window asks to hide input");
hideCurrentInputLocked(0, null);
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
if ((softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
if (DEBUG)
Slog.v(TAG, "Window asks to show input going forward");
if (attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, controlFlags);
didStart = true;
}
showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
}
break;
case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
if (DEBUG)
Slog.v(TAG, "Window asks to always show input");
if (attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, controlFlags);
didStart = true;
}
showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
break;
}
if (!didStart && attribute != null) {
res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, controlFlags);
}
}
} finally {
Binder.restoreCallingIdentity(ident);
}
return res;
}
use of com.android.internal.view.InputBindResult in project android_frameworks_base by ResurrectionRemix.
the class InputMethodManagerService method handleMessage.
@Override
public boolean handleMessage(Message msg) {
SomeArgs args;
switch(msg.what) {
case MSG_SHOW_IM_SUBTYPE_PICKER:
final boolean showAuxSubtypes;
switch(msg.arg1) {
case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO:
// This is undocumented so far, but IMM#showInputMethodPicker() has been
// implemented so that auxiliary subtypes will be excluded when the soft
// keyboard is invisible.
showAuxSubtypes = mInputShown;
break;
case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES:
showAuxSubtypes = true;
break;
case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES:
showAuxSubtypes = false;
break;
default:
Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1);
return false;
}
showInputMethodMenu(showAuxSubtypes);
return true;
case MSG_SHOW_IM_SUBTYPE_ENABLER:
showInputMethodAndSubtypeEnabler((String) msg.obj);
return true;
case MSG_SHOW_IM_CONFIG:
showConfigureInputMethods();
return true;
case MSG_UNBIND_INPUT:
try {
((IInputMethod) msg.obj).unbindInput();
} catch (RemoteException e) {
// There is nothing interesting about the method dying.
}
return true;
case MSG_BIND_INPUT:
args = (SomeArgs) msg.obj;
try {
((IInputMethod) args.arg1).bindInput((InputBinding) args.arg2);
} catch (RemoteException e) {
}
args.recycle();
return true;
case MSG_SHOW_SOFT_INPUT:
args = (SomeArgs) msg.obj;
try {
if (DEBUG)
Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" + msg.arg1 + ", " + args.arg2 + ")");
((IInputMethod) args.arg1).showSoftInput(msg.arg1, (ResultReceiver) args.arg2);
} catch (RemoteException e) {
}
args.recycle();
return true;
case MSG_HIDE_SOFT_INPUT:
args = (SomeArgs) msg.obj;
try {
if (DEBUG)
Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " + args.arg2 + ")");
((IInputMethod) args.arg1).hideSoftInput(0, (ResultReceiver) args.arg2);
} catch (RemoteException e) {
}
args.recycle();
return true;
case MSG_HIDE_CURRENT_INPUT_METHOD:
synchronized (mMethodMap) {
hideCurrentInputLocked(0, null);
}
return true;
case MSG_ATTACH_TOKEN:
args = (SomeArgs) msg.obj;
try {
if (DEBUG)
Slog.v(TAG, "Sending attach of token: " + args.arg2);
((IInputMethod) args.arg1).attachToken((IBinder) args.arg2);
} catch (RemoteException e) {
}
args.recycle();
return true;
case MSG_CREATE_SESSION:
{
args = (SomeArgs) msg.obj;
IInputMethod method = (IInputMethod) args.arg1;
InputChannel channel = (InputChannel) args.arg2;
try {
method.createSession(channel, (IInputSessionCallback) args.arg3);
} catch (RemoteException e) {
} finally {
// because the remote proxy will get its own copy when unparceled.
if (channel != null && Binder.isProxy(method)) {
channel.dispose();
}
}
args.recycle();
return true;
}
case MSG_START_INPUT:
{
int missingMethods = msg.arg1;
args = (SomeArgs) msg.obj;
try {
SessionState session = (SessionState) args.arg1;
setEnabledSessionInMainThread(session);
session.method.startInput((IInputContext) args.arg2, missingMethods, (EditorInfo) args.arg3);
} catch (RemoteException e) {
}
args.recycle();
return true;
}
case MSG_RESTART_INPUT:
{
int missingMethods = msg.arg1;
args = (SomeArgs) msg.obj;
try {
SessionState session = (SessionState) args.arg1;
setEnabledSessionInMainThread(session);
session.method.restartInput((IInputContext) args.arg2, missingMethods, (EditorInfo) args.arg3);
} catch (RemoteException e) {
}
args.recycle();
return true;
}
case MSG_UNBIND_CLIENT:
try {
((IInputMethodClient) msg.obj).onUnbindMethod(msg.arg1, msg.arg2);
} catch (RemoteException e) {
// There is nothing interesting about the last client dying.
}
return true;
case MSG_BIND_CLIENT:
{
args = (SomeArgs) msg.obj;
IInputMethodClient client = (IInputMethodClient) args.arg1;
InputBindResult res = (InputBindResult) args.arg2;
try {
client.onBindMethod(res);
} catch (RemoteException e) {
Slog.w(TAG, "Client died receiving input method " + args.arg2);
} finally {
// because the remote proxy will get its own copy when unparceled.
if (res.channel != null && Binder.isProxy(client)) {
res.channel.dispose();
}
}
args.recycle();
return true;
}
case MSG_SET_ACTIVE:
try {
((ClientState) msg.obj).client.setActive(msg.arg1 != 0);
} catch (RemoteException e) {
Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " + ((ClientState) msg.obj).pid + " uid " + ((ClientState) msg.obj).uid);
}
return true;
case MSG_SET_INTERACTIVE:
handleSetInteractive(msg.arg1 != 0);
return true;
case MSG_SWITCH_IME:
handleSwitchInputMethod(msg.arg1 != 0);
return true;
case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER:
{
final int sequenceNumber = msg.arg1;
final ClientState clientState = (ClientState) msg.obj;
try {
clientState.client.setUserActionNotificationSequenceNumber(sequenceNumber);
} catch (RemoteException e) {
Slog.w(TAG, "Got RemoteException sending " + "setUserActionNotificationSequenceNumber(" + sequenceNumber + ") notification to pid " + clientState.pid + " uid " + clientState.uid);
}
return true;
}
// --------------------------------------------------------------
case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1);
return true;
case MSG_SYSTEM_UNLOCK_USER:
final int userId = msg.arg1;
onUnlockUser(userId);
return true;
}
return false;
}
Aggregations