From 712fc24a340f13b470c5295a6a87ff128f2ac6d3 Mon Sep 17 00:00:00 2001 From: Taran Singh Date: Fri, 26 Feb 2021 20:05:54 +0000 Subject: [PATCH] Revert "Avoid IME restart for configChanges" Revert "Add cts for InputMethodService configChanges" Revert submission 13417792-b/167948419 Reason for revert: Causes bugs like b/181195100 Reverted Changes: Iff88b768c:Avoid IME restart for configChanges Ib7ce13340:Add cts for InputMethodService configChanges Bug: 167948419 Fix: 181195100 Change-Id: I36bca545b09b4f870560964ec61fa6bb344fceaf --- core/api/current.txt | 1 - core/api/test-current.txt | 4 - .../IInputMethodWrapper.java | 7 +- .../InputMethodService.java | 52 +----------- .../android/view/inputmethod/InputMethod.java | 2 +- .../view/inputmethod/InputMethodInfo.java | 51 +----------- .../android/internal/view/IInputMethod.aidl | 3 +- core/res/res/values/attrs.xml | 10 --- .../InputMethodServiceTest.java | 80 ------------------- .../InputMethodManagerService.java | 8 +- 10 files changed, 15 insertions(+), 203 deletions(-) delete mode 100644 core/tests/coretests/src/android/inputmethodservice/InputMethodServiceTest.java diff --git a/core/api/current.txt b/core/api/current.txt index 7da1b14adbd89..d3d754c0d8a5a 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -51530,7 +51530,6 @@ package android.view.inputmethod { method public int describeContents(); method public void dump(android.util.Printer, String); method public android.content.ComponentName getComponent(); - method public int getConfigChanges(); method public String getId(); method public int getIsDefaultResourceId(); method public String getPackageName(); diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 7ccb967aac211..ff96f92da2f58 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -2554,10 +2554,6 @@ package android.view.inputmethod { method @NonNull public static android.view.inputmethod.InlineSuggestionsResponse newInlineSuggestionsResponse(@NonNull java.util.List); } - public final class InputMethodInfo implements android.os.Parcelable { - ctor public InputMethodInfo(@NonNull String, @NonNull String, @NonNull CharSequence, @NonNull String, int); - } - public final class InputMethodManager { method public int getDisplayId(); method public boolean hasActiveInputConnection(@Nullable android.view.View); diff --git a/core/java/android/inputmethodservice/IInputMethodWrapper.java b/core/java/android/inputmethodservice/IInputMethodWrapper.java index 9198eb74d1f84..5cfcd667632b0 100644 --- a/core/java/android/inputmethodservice/IInputMethodWrapper.java +++ b/core/java/android/inputmethodservice/IInputMethodWrapper.java @@ -171,7 +171,7 @@ class IInputMethodWrapper extends IInputMethod.Stub SomeArgs args = (SomeArgs) msg.obj; try { inputMethod.initializeInternal((IBinder) args.arg1, msg.arg1, - (IInputMethodPrivilegedOperations) args.arg2, (int) args.arg3); + (IInputMethodPrivilegedOperations) args.arg2); } finally { args.recycle(); } @@ -280,10 +280,9 @@ class IInputMethodWrapper extends IInputMethod.Stub @BinderThread @Override public void initializeInternal(IBinder token, int displayId, - IInputMethodPrivilegedOperations privOps, int configChanges) { + IInputMethodPrivilegedOperations privOps) { mCaller.executeOrSendMessage( - mCaller.obtainMessageIOOO(DO_INITIALIZE_INTERNAL, displayId, token, privOps, - configChanges)); + mCaller.obtainMessageIOO(DO_INITIALIZE_INTERNAL, displayId, token, privOps)); } @BinderThread diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 03dd3067e64eb..7e2be01feb014 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -70,7 +70,6 @@ import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; -import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; @@ -132,7 +131,6 @@ import android.widget.TextView; import android.window.WindowMetricsHelper; import com.android.internal.annotations.GuardedBy; -import com.android.internal.annotations.VisibleForTesting; import com.android.internal.inputmethod.IInputContentUriToken; import com.android.internal.inputmethod.IInputMethodPrivilegedOperations; import com.android.internal.inputmethod.InputMethodPrivilegedOperations; @@ -515,8 +513,6 @@ public class InputMethodService extends AbstractInputMethodService { private boolean mIsAutomotive; private Handler mHandler; private boolean mImeSurfaceScheduledForRemoval; - private Configuration mLastKnownConfig; - private int mHandledConfigChanges; /** * An opaque {@link Binder} token of window requesting {@link InputMethodImpl#showSoftInput} @@ -592,14 +588,12 @@ public class InputMethodService extends AbstractInputMethodService { @MainThread @Override public final void initializeInternal(@NonNull IBinder token, int displayId, - IInputMethodPrivilegedOperations privilegedOperations, - int configChanges) { + IInputMethodPrivilegedOperations privilegedOperations) { if (InputMethodPrivilegedOperationsRegistry.isRegistered(token)) { Log.w(TAG, "The token has already registered, ignore this initialization."); return; } Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initializeInternal"); - mHandledConfigChanges = configChanges; mPrivOps.set(privilegedOperations); InputMethodPrivilegedOperationsRegistry.put(token, mPrivOps); updateInputMethodDisplay(displayId); @@ -827,9 +821,6 @@ public class InputMethodService extends AbstractInputMethodService { setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition); } final boolean isVisible = isInputViewShown(); - if (isVisible && getResources() != null) { - mLastKnownConfig = getResources().getConfiguration(); - } final boolean visibilityChanged = isVisible != wasVisible; if (resultReceiver != null) { resultReceiver.send(visibilityChanged @@ -1437,37 +1428,10 @@ public class InputMethodService extends AbstractInputMethodService { * state: {@link #onStartInput} if input is active, and * {@link #onCreateInputView} and {@link #onStartInputView} and related * appropriate functions if the UI is displayed. - *

Starting with {@link Build.VERSION_CODES#S}, IMEs can opt into handling configuration - * changes themselves instead of being restarted with - * {@link android.R.styleable#InputMethod_configChanges}. */ @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - if (shouldImeRestartForConfig(newConfig)) { - resetStateForNewConfiguration(); - } - } - - /** - * @return {@code true} if {@link InputMethodService} needs to restart to handle - * .{@link #onConfigurationChanged(Configuration)} - */ - @VisibleForTesting - boolean shouldImeRestartForConfig(@NonNull Configuration newConfig) { - if (mLastKnownConfig == null) { - return true; - } - // If the new config is the same as the config this Service is already running with, - // then don't bother calling resetStateForNewConfiguration. - int diff = mLastKnownConfig.diffPublicOnly(newConfig); - if (diff != 0) { - // remove attrs not-relevant to IME service. - diff &= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; - diff &= ActivityInfo.CONFIG_KEYBOARD; - diff &= ActivityInfo.CONFIG_NAVIGATION; - } - int unhandledDiff = (diff & ~mHandledConfigChanges); - return unhandledDiff != 0; + resetStateForNewConfiguration(); } private void resetStateForNewConfiguration() { @@ -3217,17 +3181,7 @@ public class InputMethodService extends AbstractInputMethodService { requestHideSelf(InputMethodManager.HIDE_NOT_ALWAYS); } } - - @VisibleForTesting - void setLastKnownConfig(@NonNull Configuration config) { - mLastKnownConfig = config; - } - - @VisibleForTesting - void setHandledConfigChanges(int configChanges) { - mHandledConfigChanges = configChanges; - } - + void startExtractingText(boolean inputChanged) { final ExtractEditText eet = mExtractEditText; if (eet != null && getCurrentInputStarted() diff --git a/core/java/android/view/inputmethod/InputMethod.java b/core/java/android/view/inputmethod/InputMethod.java index 6ade5e622eab6..de4554b9e6249 100644 --- a/core/java/android/view/inputmethod/InputMethod.java +++ b/core/java/android/view/inputmethod/InputMethod.java @@ -105,7 +105,7 @@ public interface InputMethod { */ @MainThread default void initializeInternal(IBinder token, int displayId, - IInputMethodPrivilegedOperations privilegedOperations, int configChanges) { + IInputMethodPrivilegedOperations privilegedOperations) { updateInputMethodDisplay(displayId); attachToken(token); } diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java index 25712f8bf9b87..5d876a6f62d35 100644 --- a/core/java/android/view/inputmethod/InputMethodInfo.java +++ b/core/java/android/view/inputmethod/InputMethodInfo.java @@ -18,23 +18,19 @@ package android.view.inputmethod; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.Context; -import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; -import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.drawable.Drawable; -import android.inputmethodservice.InputMethodService; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; @@ -64,7 +60,6 @@ import java.util.List; * @attr ref android.R.styleable#InputMethod_isDefault * @attr ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod * @attr ref android.R.styleable#InputMethod_supportsInlineSuggestions - * @attr ref android.R.styleable#InputMethod_configChanges */ public final class InputMethodInfo implements Parcelable { static final String TAG = "InputMethodInfo"; @@ -122,12 +117,6 @@ public final class InputMethodInfo implements Parcelable { */ private final boolean mInlineSuggestionsEnabled; - /** - * The flag for configurations IME assumes the responsibility for handling in - * {@link InputMethodService#onConfigurationChanged(Configuration)}}. - */ - private final int mHandledConfigChanges; - /** * @param service the {@link ResolveInfo} corresponds in which the IME is implemented. * @return a unique ID to be returned by {@link #getId()}. We have used @@ -214,8 +203,6 @@ public final class InputMethodInfo implements Parcelable { false); inlineSuggestionsEnabled = sa.getBoolean( com.android.internal.R.styleable.InputMethod_supportsInlineSuggestions, false); - mHandledConfigChanges = sa.getInt( - com.android.internal.R.styleable.InputMethod_configChanges, 0); sa.recycle(); final int depth = parser.getDepth(); @@ -300,7 +287,6 @@ public final class InputMethodInfo implements Parcelable { mIsVrOnly = source.readBoolean(); mService = ResolveInfo.CREATOR.createFromParcel(source); mSubtypes = new InputMethodSubtypeArray(source); - mHandledConfigChanges = source.readInt(); mForceDefault = false; } @@ -312,22 +298,7 @@ public final class InputMethodInfo implements Parcelable { this(buildFakeResolveInfo(packageName, className, label), false /* isAuxIme */, settingsActivity, null /* subtypes */, 0 /* isDefaultResId */, false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */, - false /* inlineSuggestionsEnabled */, false /* isVrOnly */, - 0 /* handledConfigChanges */); - } - - /** - * Temporary API for creating a built-in input method for test. - * @hide - */ - @TestApi - public InputMethodInfo(@NonNull String packageName, @NonNull String className, - @NonNull CharSequence label, @NonNull String settingsActivity, - int handledConfigChanges) { - this(buildFakeResolveInfo(packageName, className, label), false /* isAuxIme */, - settingsActivity, null /* subtypes */, 0 /* isDefaultResId */, - false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */, - false /* inlineSuggestionsEnabled */, false /* isVrOnly */, handledConfigChanges); + false /* inlineSuggestionsEnabled */, false /* isVrOnly */); } /** @@ -339,7 +310,7 @@ public final class InputMethodInfo implements Parcelable { boolean forceDefault) { this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault, true /* supportsSwitchingToNextInputMethod */, false /* inlineSuggestionsEnabled */, - false /* isVrOnly */, 0 /* handledconfigChanges */); + false /* isVrOnly */); } /** @@ -350,8 +321,7 @@ public final class InputMethodInfo implements Parcelable { List subtypes, int isDefaultResId, boolean forceDefault, boolean supportsSwitchingToNextInputMethod, boolean isVrOnly) { this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault, - supportsSwitchingToNextInputMethod, false /* inlineSuggestionsEnabled */, isVrOnly, - 0 /* handledConfigChanges */); + supportsSwitchingToNextInputMethod, false /* inlineSuggestionsEnabled */, isVrOnly); } /** @@ -361,7 +331,7 @@ public final class InputMethodInfo implements Parcelable { public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, String settingsActivity, List subtypes, int isDefaultResId, boolean forceDefault, boolean supportsSwitchingToNextInputMethod, boolean inlineSuggestionsEnabled, - boolean isVrOnly, int handledConfigChanges) { + boolean isVrOnly) { final ServiceInfo si = ri.serviceInfo; mService = ri; mId = new ComponentName(si.packageName, si.name).flattenToShortString(); @@ -373,7 +343,6 @@ public final class InputMethodInfo implements Parcelable { mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod; mInlineSuggestionsEnabled = inlineSuggestionsEnabled; mIsVrOnly = isVrOnly; - mHandledConfigChanges = handledConfigChanges; } private static ResolveInfo buildFakeResolveInfo(String packageName, String className, @@ -520,17 +489,6 @@ public final class InputMethodInfo implements Parcelable { } } - /** - * Returns the bit mask of kinds of configuration changes that this IME - * can handle itself (without being restarted by the system). - * - * @attr ref android.R.styleable#InputMethod_configChanges - */ - @ActivityInfo.Config - public int getConfigChanges() { - return mHandledConfigChanges; - } - public void dump(Printer pw, String prefix) { pw.println(prefix + "mId=" + mId + " mSettingsActivityName=" + mSettingsActivityName @@ -621,7 +579,6 @@ public final class InputMethodInfo implements Parcelable { dest.writeBoolean(mIsVrOnly); mService.writeToParcel(dest, flags); mSubtypes.writeToParcel(dest); - dest.writeInt(mHandledConfigChanges); } /** diff --git a/core/java/com/android/internal/view/IInputMethod.aidl b/core/java/com/android/internal/view/IInputMethod.aidl index 8d82e33dc29ff..c336373539844 100644 --- a/core/java/com/android/internal/view/IInputMethod.aidl +++ b/core/java/com/android/internal/view/IInputMethod.aidl @@ -35,8 +35,7 @@ import com.android.internal.view.InlineSuggestionsRequestInfo; * {@hide} */ oneway interface IInputMethod { - void initializeInternal(IBinder token, int displayId, IInputMethodPrivilegedOperations privOps, - int configChanges); + void initializeInternal(IBinder token, int displayId, IInputMethodPrivilegedOperations privOps); void onCreateInlineSuggestionsRequest(in InlineSuggestionsRequestInfo requestInfo, in IInlineSuggestionsRequestCallback cb); diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 99f58ee1f8a63..69bb20cf9c1ee 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3564,16 +3564,6 @@ - -