private void loadKeyboardForLocale(final Locale newLocale) {
   final Keyboard cachedKeyboard = mLocaleToKeyboardMap.get(newLocale);
   if (cachedKeyboard != null) {
     mKeyboard = cachedKeyboard;
     return;
   }
   final InputMethodSubtype subtype;
   synchronized (mLock) {
     subtype = mLocaleToSubtypeMap.get(newLocale);
   }
   if (subtype == null) {
     return;
   }
   final EditorInfo editorInfo = new EditorInfo();
   editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
   final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(mContext, editorInfo);
   final Resources res = mContext.getResources();
   final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
   final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
   builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
   builder.setSubtype(subtype);
   builder.setIsSpellChecker(false /* isSpellChecker */);
   final KeyboardLayoutSet layoutSet = builder.build();
   mKeyboard = layoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET);
 }
  @Override
  public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intentAction)) {
      Log.i(TAG, "Package has been replaced: " + context.getPackageName());
      // Need to restore additional subtypes because system always clears additional
      // subtypes when the package is replaced.
      RichInputMethodManager.init(context);
      final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
      final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes(context);
      richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
      LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
    } else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
      Log.i(TAG, "Boot has been completed");
      LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
    } else if (IntentCompatUtils.is_ACTION_USER_INITIALIZE(intentAction)) {
      Log.i(TAG, "User initialize");
      LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
    } else if (Intent.ACTION_LOCALE_CHANGED.equals(intentAction)) {
      Log.i(TAG, "System locale changed");
      KeyboardLayoutSet.onSystemLocaleChanged();
    }

    // The process that hosts this broadcast receiver is invoked and remains alive even after
    // 1) the package has been re-installed, 2) the device has just booted,
    // 3) a new user has been created.
    // There is no good reason to keep the process alive if this IME isn't a current IME.
    final InputMethodManager imm =
        (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    // Called to check whether this IME has been triggered by the current user or not
    final boolean isInputMethodManagerValidForUserOfThisProcess =
        !imm.getInputMethodList().isEmpty();
    final boolean isCurrentImeOfCurrentUser =
        isInputMethodManagerValidForUserOfThisProcess
            && UncachedInputMethodManagerUtils.isThisImeCurrent(context, imm);
    if (!isCurrentImeOfCurrentUser) {
      final int myPid = Process.myPid();
      Log.i(TAG, "Killing my process: pid=" + myPid);
      Process.killProcess(myPid);
    }
  }