From 4ff7bbcb97a6b71d84c927e3e4a30dd4dd2494b9 Mon Sep 17 00:00:00 2001 From: satok <satok@google.com> Date: Thu, 3 Jun 2010 14:54:35 +0900 Subject: [PATCH] Fix a bug that force closing happens even when SUPPRESS_EXCEPTION flag is on. Change-Id: I927b11da1e62b147813fbbf01e2afce5915aed73 --- .../inputmethod/latin/KeyboardSwitcher.java | 16 +++++++++------- .../com/android/inputmethod/latin/LatinIME.java | 2 +- .../inputmethod/latin/LatinImeLogger.java | 15 +++++++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 3eb135ebe7..948fe5aa6f 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -197,8 +197,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) { mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; mPreferSymbols = mode == MODE_SYMBOLS; - setKeyboardMode(mode == MODE_SYMBOLS ? MODE_TEXT : mode, imeOptions, enableVoice, - mPreferSymbols); + if (mode == MODE_SYMBOLS) { + mode = MODE_TEXT; + } + try { + setKeyboardMode(mode, imeOptions, enableVoice, mPreferSymbols); + } catch (RuntimeException e) { + LatinImeLogger.logOnException(mode + "," + imeOptions + "," + mPreferSymbols, e); + } } void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) { @@ -213,11 +219,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mInputView.setPreviewEnabled(true); KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); LatinKeyboard keyboard = null; - try { - keyboard = getKeyboard(id); - } catch (RuntimeException e) { - LatinImeLogger.logOnException(mode + "," + imeOptions + "," + isSymbols, e); - } + keyboard = getKeyboard(id); if (mode == MODE_PHONE) { mInputView.setPhoneKeyboard(keyboard); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 46fca372c0..edc2e087f7 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -275,6 +275,7 @@ public class LatinIME extends InputMethodService }; @Override public void onCreate() { + LatinImeLogger.init(this); super.onCreate(); //setStatusIcon(R.drawable.ime_qwerty); mResources = getResources(); @@ -311,7 +312,6 @@ public class LatinIME extends InputMethodService }); } prefs.registerOnSharedPreferenceChangeListener(this); - LatinImeLogger.init(this); } private void initSuggest(String locale) { diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index 7ad0ec63b6..4742810581 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -39,7 +39,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang private static final boolean DBG = true; private static boolean sLOGPRINT = false; // SUPPRESS_EXCEPTION should be true when released to public. - private static final boolean SUPPRESS_EXCEPTION = false; + private static final boolean SUPPRESS_EXCEPTION = true; // DEFAULT_LOG_ENABLED should be false when released to public. private static final boolean DEFAULT_LOG_ENABLED = true; @@ -48,6 +48,8 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang private static final long MINIMUMSENDSIZE = 40; private static final char SEPARATER = ';'; private static final char NULL_CHAR = '\uFFFC'; + private static final int EXCEPTION_MAX_LENGTH = 400; + private static final int ID_MANUALSUGGESTION = 0; private static final int ID_AUTOSUGGESTIONCANCELLED = 1; private static final int ID_AUTOSUGGESTION = 2; @@ -368,7 +370,9 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang } private void commitInternalAndStopSelf() { - Log.e(TAG, "Exception was caused and let's die."); + if (DBG) { + Log.e(TAG, "Exception was thrown and let's die."); + } commitInternal(); LatinIME ime = ((LatinIME) mContext); ime.hideWindow(); @@ -539,10 +543,13 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); e.printStackTrace(ps); - String exceptionString = new String(baos.toByteArray()); + String exceptionString = new String(baos.toByteArray(), 0, + Math.min(EXCEPTION_MAX_LENGTH, baos.size())); sLatinImeLogger.sendLogToDropBox( ID_EXCEPTION, new String[] {metaData, exceptionString}); - Log.e(TAG, "Exception: " + exceptionString); + if (DBG) { + Log.e(TAG, "Exception: " + new String(baos.toByteArray())); + } if (SUPPRESS_EXCEPTION) { sLatinImeLogger.commitInternalAndStopSelf(); } else { -- GitLab