From 5ee254bf11c02c0f700423585056d2afbd34b3a1 Mon Sep 17 00:00:00 2001 From: Mugdha Lakhani Date: Thu, 4 May 2023 18:38:10 +0000 Subject: [PATCH] Add support for Input ads from the SDK runtime. Symtom: EditText created from the SDK runtime is not able to accept input using the soft keyboard. The root cause is a failed check in ImeService when it tries to match the caller uid with the uid PM associates with the sdk sandbox package. Since SDK sandbox package can be running in a process that can have a UID from a range, rather than a single UID, this check often fails. Updated the check to use a PackageManager method that understands this nuance about sdk sandbox package and ensures the UID falls within the range of sdk sandbox UIDs. Bug: b/242985591 Test: Using the SDK sandbox manual test app. Change-Id: I3da937bf379f39c8204db5b7d7d1c41c6a6e942e --- .../java/com/android/server/inputmethod/InputMethodUtils.java | 4 ++-- .../server/inputmethod/InputMethodManagerServiceTestBase.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java index 17536fcb820e1..c97d8e21eef13 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java @@ -194,8 +194,8 @@ final class InputMethodUtils { int uid, String packageName) { // PackageManagerInternal#getPackageUid() doesn't check MATCH_INSTANT/MATCH_APEX as of // writing. So setting 0 should be fine. - return packageManagerInternal.getPackageUid(packageName, 0 /* flags */, - UserHandle.getUserId(uid)) == uid; + return packageManagerInternal.isSameApp(packageName, /* flags= */ 0, uid, + UserHandle.getUserId(uid)); } /** diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java index c80ecbf621429..1a8e00cab39d4 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java @@ -207,6 +207,8 @@ public class InputMethodManagerServiceTestBase { when(mMockActivityManagerInternal.isSystemReady()).thenReturn(true); when(mMockPackageManagerInternal.getPackageUid(anyString(), anyLong(), anyInt())) .thenReturn(Binder.getCallingUid()); + when(mMockPackageManagerInternal.isSameApp(anyString(), anyLong(), anyInt(), anyInt())) + .thenReturn(true); when(mMockWindowManagerInternal.onToggleImeRequested(anyBoolean(), any(), any(), anyInt())) .thenReturn(TEST_IME_TARGET_INFO); when(mMockInputMethodClient.asBinder()).thenReturn(mMockInputMethodBinder);