From 5ec1fcea6cd286eea024c3a4d9902953b2d75356 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 17 Dec 2018 07:56:14 -0800 Subject: [PATCH] Remove a special test-only mode from IMMS This CL logically reverts my previous CL [1] that allowed CTS tests to relax security restriction in InputMethodManagerService (IMMS) so that MockIme could be used even when its host APK is instaleld as an instant app. With my recent change for MockIme [2], MockIme is now a standalone APK that can always be installed as a full (non-instant) app, even when the test APK is installed as an instant app. Note that this is exactly how IMEs work for instant apps in real use cases. We have never allowed IMEs in instant APKs to be used in production environment for obvious security reasons. [1]: I4383129fd9e229a849282e874aff5d4eef1f49f8 f80087cae1227c48159a2a177729b14f4eb32e48 [2]: I4ddda5261651ee67c4ff70bc1ab1d4aef64e1a52 ecf533da5af14418ce232db5d44d27517069ad30 Fix: 121097307 Test: atest CtsInputMethodTestCases Test: make -j cts && cts-tradefed run commandAndExit cts-instant -m CtsInputMethodTestCases Change-Id: I9a5da660fc5e7e2334f7d029cded9c323f808084 --- .../InputMethodManagerService.java | 91 +------------------ 1 file changed, 4 insertions(+), 87 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 28a6ba4ceb1d6..67293b9c9ea08 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -674,13 +674,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @HardKeyboardBehavior private final int mHardKeyboardBehavior; - /** - * Whether we temporarily allow IMEs implemented in instant apps to run for testing. - * - *

Note: This is quite dangerous. Don't forget to reset after you finish testing.

- */ - private boolean mBindInstantServiceAllowed = false; - /** * Internal state snapshot when {@link #MSG_START_INPUT} message is about to be posted to the * internal message queue. Any subsequent state change inside {@link InputMethodManagerService} @@ -1135,8 +1128,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub final PackageManager pm = mContext.getPackageManager(); final List services = pm.queryIntentServicesAsUser( new Intent(InputMethod.SERVICE_INTERFACE).setPackage(packageName), - getComponentMatchingFlags(PackageManager.MATCH_DISABLED_COMPONENTS), - getChangingUserId()); + PackageManager.MATCH_DISABLED_COMPONENTS, getChangingUserId()); // No need to lock this because we access it only on getRegisteredHandler(). if (!services.isEmpty()) { mImePackageAppeared = true; @@ -1684,9 +1676,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); return false; } - if (mBindInstantServiceAllowed) { - flags |= Context.BIND_ALLOW_INSTANT; - } return mContext.bindServiceAsUser(service, conn, flags, new UserHandle(mSettings.getCurrentUserId())); } @@ -3631,16 +3620,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return false; } - @PackageManager.ResolveInfoFlags - private int getComponentMatchingFlags(@PackageManager.ResolveInfoFlags int baseFlags) { - synchronized (mMethodMap) { - if (mBindInstantServiceAllowed) { - baseFlags |= PackageManager.MATCH_INSTANT; - } - return baseFlags; - } - } - @GuardedBy("mMethodMap") void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { if (DEBUG) { @@ -3664,8 +3643,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // services depending on the unlock state for the specified user. final List services = pm.queryIntentServicesAsUser( new Intent(InputMethod.SERVICE_INTERFACE), - getComponentMatchingFlags(PackageManager.GET_META_DATA - | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS), + PackageManager.GET_META_DATA | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS, mSettings.getCurrentUserId()); final ArrayMap> additionalSubtypeMap = @@ -3707,8 +3685,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // conservative, but it seems we cannot use it for now (Issue 35176630). final List allInputMethodServices = pm.queryIntentServicesAsUser( new Intent(InputMethod.SERVICE_INTERFACE), - getComponentMatchingFlags(PackageManager.MATCH_DISABLED_COMPONENTS), - mSettings.getCurrentUserId()); + PackageManager.MATCH_DISABLED_COMPONENTS, mSettings.getCurrentUserId()); final int N = allInputMethodServices.size(); for (int i = 0; i < N; ++i) { final ServiceInfo si = allInputMethodServices.get(i).serviceInfo; @@ -4606,8 +4583,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub synchronized (mMethodMap) { p.println("Current Input Method Manager state:"); int N = mMethodList.size(); - p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount - + " mBindInstantServiceAllowed=" + mBindInstantServiceAllowed); + p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount); for (int i=0; i". if ("ime".equals(cmd)) { @@ -4750,12 +4723,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return handleDefaultCommands(cmd); } - @BinderThread - @ShellCommandResult - private int setBindInstantServiceAllowed() { - return mService.handleSetBindInstantServiceAllowed(this); - } - @BinderThread @ShellCommandResult private int refreshDebugProperties() { @@ -4774,9 +4741,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub pw.println(" Synonym of dumpsys."); pw.println(" ime [options]"); pw.println(" Manipulate IMEs. Run \"ime help\" for details."); - pw.println(" set-bind-instant-service-allowed true|false "); - pw.println(" Set whether binding to services provided by instant apps is " - + "allowed."); } } @@ -4824,53 +4788,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // ---------------------------------------------------------------------- // Shell command handlers: - /** - * Handles {@code adb shell cmd input_method set-bind-instant-service-allowed}. - * - * @param shellCommand {@link ShellCommand} object that is handling this command. - * @return Exit code of the command. - */ - @BinderThread - @RequiresPermission(android.Manifest.permission.MANAGE_BIND_INSTANT_SERVICE) - @ShellCommandResult - private int handleSetBindInstantServiceAllowed(@NonNull ShellCommand shellCommand) { - final String allowedString = shellCommand.getNextArgRequired(); - if (allowedString == null) { - shellCommand.getErrPrintWriter().println("Error: no true/false specified"); - return ShellCommandResult.FAILURE; - } - final boolean allowed = Boolean.parseBoolean(allowedString); - synchronized (mMethodMap) { - if (mContext.checkCallingOrSelfPermission( - android.Manifest.permission.MANAGE_BIND_INSTANT_SERVICE) - != PackageManager.PERMISSION_GRANTED) { - shellCommand.getErrPrintWriter().print( - "Caller must have MANAGE_BIND_INSTANT_SERVICE permission"); - return ShellCommandResult.FAILURE; - } - - if (mBindInstantServiceAllowed == allowed) { - // Nothing to do. - return ShellCommandResult.SUCCESS; - } - mBindInstantServiceAllowed = allowed; - - // Rebuild everything. - final long ident = Binder.clearCallingIdentity(); - try { - // Reset the current IME - resetSelectedInputMethodAndSubtypeLocked(null); - // Also reset the settings of the current IME - mSettings.putSelectedInputMethod(null); - buildInputMethodListLocked(false /* resetDefaultEnabledIme */); - updateInputMethodsFromSettingsLocked(true /* enabledMayChange */); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - return ShellCommandResult.SUCCESS; - } - /** * Handles {@code adb shell ime list}. * @param shellCommand {@link ShellCommand} object that is handling this command.