@@ -1814,9 +1814,9 @@ boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
18141814 public InputBindResult windowGainedFocus (IInputMethodClient client , IBinder windowToken ,
18151815 int controlFlags , int softInputMode , int windowFlags ,
18161816 EditorInfo attribute , IInputContext inputContext ) {
1817- if (! calledFromValidUser ()) {
1818- return null ;
1819- }
1817+ // Needs to check the validity before clearing calling identity
1818+ final boolean calledFromValidUser = calledFromValidUser () ;
1819+
18201820 InputBindResult res = null ;
18211821 long ident = Binder .clearCallingIdentity ();
18221822 try {
@@ -1846,6 +1846,14 @@ public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder wind
18461846 } catch (RemoteException e ) {
18471847 }
18481848
1849+ if (!calledFromValidUser ) {
1850+ Slog .w (TAG , "A background user is requesting window. Hiding IME." );
1851+ Slog .w (TAG , "If you want to interect with IME, you need "
1852+ + "android.permission.INTERACT_ACROSS_USERS_FULL" );
1853+ hideCurrentInputLocked (0 , null );
1854+ return null ;
1855+ }
1856+
18491857 if (mCurFocusedWindow == windowToken ) {
18501858 Slog .w (TAG , "Window already focused, ignoring focus gain of: " + client
18511859 + " attribute=" + attribute + ", token = " + windowToken );
0 commit comments