From 10e8b9397717cc04b9a2aaee4b91f9d7ccbbf8e6 Mon Sep 17 00:00:00 2001 From: Satoshi Kataoka Date: Mon, 20 May 2013 19:51:28 -0700 Subject: [PATCH] Fix a crash on a secondary user Bug: 9054063 Change-Id: I092ab6e0077578d0aca57d2e41dfbc00b46e1ba4 --- .../inputmethod/latin/RichInputMethodManager.java | 7 +++++++ .../latin/setup/LauncherIconVisibilityManager.java | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java index 94513e635..0dd302afa 100644 --- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java +++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java @@ -54,6 +54,13 @@ public final class RichInputMethodManager { return sInstance; } + // Caveat: This may cause IPC + public static boolean isInputMethodManagerValidForUserOfThisProcess(final Context context) { + // Basically called to check whether this IME has been triggered by the current user or not + return !((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)). + getInputMethodList().isEmpty(); + } + public static void init(final Context context) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); sInstance.initInternal(context, prefs); diff --git a/java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java b/java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java index 1b893a65d..6a7cd9b6f 100644 --- a/java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java +++ b/java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java @@ -68,8 +68,15 @@ public final class LauncherIconVisibilityManager extends BroadcastReceiver { // 1) the package has been re-installed, 2) the device has been booted, // 3) a multiuser has been created. // There is no good reason to keep the process alive if this IME isn't a current IME. - RichInputMethodManager.init(context); - if (!SetupActivity.isThisImeCurrent(context)) { + final boolean isCurrentImeOfCurrentUser; + if (RichInputMethodManager.isInputMethodManagerValidForUserOfThisProcess(context)) { + RichInputMethodManager.init(context); + isCurrentImeOfCurrentUser = SetupActivity.isThisImeCurrent(context); + } else { + isCurrentImeOfCurrentUser = false; + } + + if (!isCurrentImeOfCurrentUser) { final int myPid = Process.myPid(); Log.i(TAG, "Killing my process: pid=" + myPid); Process.killProcess(myPid);