summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/view/InputMethodClient.java8
-rw-r--r--services/core/java/com/android/server/InputMethodManagerService.java93
2 files changed, 47 insertions, 54 deletions
diff --git a/core/java/com/android/internal/view/InputMethodClient.java b/core/java/com/android/internal/view/InputMethodClient.java
index 802ce3e734d7..cea030a3d489 100644
--- a/core/java/com/android/internal/view/InputMethodClient.java
+++ b/core/java/com/android/internal/view/InputMethodClient.java
@@ -75,12 +75,12 @@ public final class InputMethodClient {
public static final int UNBIND_REASON_DISCONNECT_IME = 3;
public static final int UNBIND_REASON_NO_IME = 4;
public static final int UNBIND_REASON_SWITCH_IME_FAILED = 5;
- public static final int UNBIND_REASON_RESET_IME = 6;
+ public static final int UNBIND_REASON_SWITCH_USER = 6;
@Retention(SOURCE)
@IntDef({UNBIND_REASON_UNSPECIFIED, UNBIND_REASON_SWITCH_CLIENT, UNBIND_REASON_SWITCH_IME,
UNBIND_REASON_DISCONNECT_IME, UNBIND_REASON_NO_IME, UNBIND_REASON_SWITCH_IME_FAILED,
- UNBIND_REASON_RESET_IME})
+ UNBIND_REASON_SWITCH_USER})
public @interface UnbindReason {}
public static String getUnbindReason(@UnbindReason final int reason) {
@@ -97,8 +97,8 @@ public final class InputMethodClient {
return "NO_IME";
case UNBIND_REASON_SWITCH_IME_FAILED:
return "SWITCH_IME_FAILED";
- case UNBIND_REASON_RESET_IME:
- return "RESET_IME";
+ case UNBIND_REASON_SWITCH_USER:
+ return "SWITCH_USER";
default:
return "Unknown=" + reason;
}
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
index ab57fa760c11..b6f0f4c7ab66 100644
--- a/services/core/java/com/android/server/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -599,15 +599,35 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
restoreEnabledInputMethods(mContext, prevValue, newValue);
}
} else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
- synchronized (mMethodMap) {
- resetStateIfCurrentLocaleChangedLocked();
- }
+ onActionLocaleChanged();
} else {
Slog.w(TAG, "Unexpected intent " + intent);
}
}
}
+ /**
+ * Handles {@link Intent#ACTION_LOCALE_CHANGED}.
+ *
+ * <p>Note: For historical reasons, {@link Intent#ACTION_LOCALE_CHANGED} has been sent to all
+ * the users. We should ignore this event if this is about any background user's locale.</p>
+ *
+ * <p>Caution: This method must not be called when system is not ready.</p>
+ */
+ void onActionLocaleChanged() {
+ synchronized (mMethodMap) {
+ final LocaleList possibleNewLocale = mRes.getConfiguration().getLocales();
+ if (possibleNewLocale != null && possibleNewLocale.equals(mLastSystemLocales)) {
+ return;
+ }
+ buildInputMethodListLocked(true);
+ // If the locale is changed, needs to reset the default ime
+ resetDefaultImeLocked(mContext);
+ updateFromSettingsLocked(true);
+ mLastSystemLocales = possibleNewLocale;
+ }
+ }
+
// Apply the results of a restore operation to the set of enabled IMEs. Note that this
// does not attempt to validate on the fly with any installed device policy, so must only
// be run in the context of initial device setup.
@@ -979,51 +999,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
}
- private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged,
- final boolean resetDefaultEnabledIme) {
- if (!mSystemReady) {
- // not system ready
- return;
- }
- final LocaleList newLocales = mRes.getConfiguration().getLocales();
- if (!updateOnlyWhenLocaleChanged
- || (newLocales != null && !newLocales.equals(mLastSystemLocales))) {
- if (!updateOnlyWhenLocaleChanged) {
- hideCurrentInputLocked(0, null);
- resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_RESET_IME);
- }
- if (DEBUG) {
- Slog.i(TAG, "LocaleList has been changed to " + newLocales);
- }
- buildInputMethodListLocked(resetDefaultEnabledIme);
- if (!updateOnlyWhenLocaleChanged) {
- final String selectedImiId = mSettings.getSelectedInputMethod();
- if (TextUtils.isEmpty(selectedImiId)) {
- // This is the first time of the user switch and
- // set the current ime to the proper one.
- resetDefaultImeLocked(mContext);
- }
- } else {
- // If the locale is changed, needs to reset the default ime
- resetDefaultImeLocked(mContext);
- }
- updateFromSettingsLocked(true);
- mLastSystemLocales = newLocales;
- if (!updateOnlyWhenLocaleChanged) {
- try {
- startInputInnerLocked();
- } catch (RuntimeException e) {
- Slog.w(TAG, "Unexpected exception", e);
- }
- }
- }
- }
-
- private void resetStateIfCurrentLocaleChangedLocked() {
- resetAllInternalStateLocked(true /* updateOnlyWhenLocaleChanged */,
- true /* resetDefaultImeLocked */);
- }
-
private void switchUserLocked(int newUserId) {
if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId
+ " currentUserId=" + mSettings.getCurrentUserId());
@@ -1050,8 +1025,26 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
// Even in such cases, IMMS works fine because it will find the most applicable
// IME for that user.
final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId);
- resetAllInternalStateLocked(false /* updateOnlyWhenLocaleChanged */,
- initialUserSwitch /* needsToResetDefaultIme */);
+ mLastSystemLocales = mRes.getConfiguration().getLocales();
+
+ // TODO: Is it really possible that switchUserLocked() happens before system ready?
+ if (mSystemReady) {
+ hideCurrentInputLocked(0, null);
+ resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_USER);
+ buildInputMethodListLocked(initialUserSwitch);
+ if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) {
+ // This is the first time of the user switch and
+ // set the current ime to the proper one.
+ resetDefaultImeLocked(mContext);
+ }
+ updateFromSettingsLocked(true);
+ try {
+ startInputInnerLocked();
+ } catch (RuntimeException e) {
+ Slog.w(TAG, "Unexpected exception", e);
+ }
+ }
+
if (initialUserSwitch) {
InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,
mSettings.getEnabledInputMethodListLocked(), newUserId,