aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/KeyboardSwitcher.java39
-rw-r--r--java/src/com/android/inputmethod/latin/LatinImeLogger.java45
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboardView.java6
3 files changed, 68 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index fefe1cc42..3eb135ebe 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -212,8 +212,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
mInputView.setPreviewEnabled(true);
KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols);
-
- LatinKeyboard keyboard = getKeyboard(id);
+ LatinKeyboard keyboard = null;
+ try {
+ keyboard = getKeyboard(id);
+ } catch (RuntimeException e) {
+ LatinImeLogger.logOnException(mode + "," + imeOptions + "," + isSymbols, e);
+ }
if (mode == MODE_PHONE) {
mInputView.setPhoneKeyboard(keyboard);
@@ -271,12 +275,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
}
switch (mode) {
case MODE_TEXT:
- if (mTextMode == MODE_TEXT_QWERTY) {
- return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_NORMAL, true, hasVoice);
- } else if (mTextMode == MODE_TEXT_ALPHA) {
+ if (mTextMode == MODE_TEXT_ALPHA) {
return new KeyboardId(R.xml.kbd_alpha, KEYBOARDMODE_NORMAL, true, hasVoice);
}
- break;
+ // Normally mTextMode should be MODE_TEXT_QWERTY.
+ return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_NORMAL, true, hasVoice);
case MODE_SYMBOLS:
return makeSymbolsId(hasVoice);
case MODE_PHONE:
@@ -301,19 +304,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return mMode == MODE_TEXT;
}
- int getTextMode() {
- return mTextMode;
- }
-
- void setTextMode(int position) {
- if (position < MODE_TEXT_COUNT && position >= 0) {
- mTextMode = position;
- }
- if (isTextMode()) {
- setKeyboardMode(MODE_TEXT, mImeOptions, mHasVoice);
- }
- }
-
int getTextModeCount() {
return MODE_TEXT_COUNT;
}
@@ -387,11 +377,18 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private void changeLatinKeyboardView(int newLayout, boolean forceReset) {
if (mLayoutId != newLayout || mInputView == null || forceReset) {
+ if (mInputView != null) {
+ mInputView.closing();
+ }
if (LAYOUTS.length <= newLayout) {
newLayout = Integer.valueOf(DEFAULT_LAYOUT_ID);
}
- mInputView = (LatinKeyboardView) mInputMethodService.getLayoutInflater().inflate(
- LAYOUTS[newLayout], null);
+ try {
+ mInputView = (LatinKeyboardView) mInputMethodService.getLayoutInflater().inflate(
+ LAYOUTS[newLayout], null);
+ } catch (RuntimeException e) {
+ LatinImeLogger.logOnException(mLayoutId + "," + newLayout, e);
+ }
mInputView.setExtentionLayoutResId(LAYOUTS[newLayout]);
mInputView.setOnKeyboardActionListener(mInputMethodService);
mLayoutId = newLayout;
diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
index a871b4aff..b497c0c66 100644
--- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java
+++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
@@ -26,12 +26,16 @@ import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "LatinIMELogs";
private static boolean sDBG = false;
+ // SUPPRESS_EXCEPTION should be true when released to public.
+ private static final boolean SUPPRESS_EXCEPTION = false;
// DEFAULT_LOG_ENABLED should be false when released to public.
private static final boolean DEFAULT_LOG_ENABLED = true;
@@ -49,6 +53,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
private static final int ID_THEME_ID = 7;
private static final int ID_SETTING_AUTO_COMPLETE = 8;
private static final int ID_VERSION = 9;
+ private static final int ID_EXCEPTION = 10;
private static final String PREF_ENABLE_LOG = "enable_logging";
private static final String PREF_DEBUG_MODE = "debug_mode";
@@ -197,6 +202,13 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
}
}
+ private void addExceptionEntry(long time, String[] data) {
+ if (sDBG) {
+ Log.d(TAG, "Log Exception. (1)");
+ }
+ mLogBuffer.add(new LogEntry(time, ID_EXCEPTION, data));
+ }
+
private void flushPrivacyLogSafely() {
if (sDBG) {
Log.d(TAG, "Log theme Id. (" + mPrivacyLogBuffer.size() + ")");
@@ -270,6 +282,16 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
}
}
break;
+ case ID_EXCEPTION:
+ dataStrings = (String[]) data;
+ if (dataStrings.length < 2) {
+ if (sDBG) {
+ Log.e(TAG, "The length of logged string array is invalid.");
+ }
+ break;
+ }
+ addExceptionEntry(System.currentTimeMillis(), dataStrings);
+ break;
default:
if (sDBG) {
Log.e(TAG, "Log Tag is not entried.");
@@ -299,6 +321,12 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
mLastTimeSend = now;
}
+ private void commitInternalAndStopSelf() {
+ Log.e(TAG, "Exception was caused and let's die.");
+ commitInternal();
+ ((LatinIME) mContext).stopSelf();
+ }
+
private synchronized void sendLogToDropBox(int tag, Object s) {
long now = System.currentTimeMillis();
if (sDBG) {
@@ -405,6 +433,23 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
}
}
+ public static void logOnException(String metaData, RuntimeException e) {
+ if (sLogEnabled) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ e.printStackTrace(ps);
+ String exceptionString = new String(baos.toByteArray());
+ sLatinImeLogger.sendLogToDropBox(
+ ID_EXCEPTION, new String[] {metaData, exceptionString});
+ Log.e(TAG, "Exception: " + exceptionString);
+ if (SUPPRESS_EXCEPTION) {
+ sLatinImeLogger.commitInternalAndStopSelf();
+ } else {
+ throw e;
+ }
+ }
+ }
+
private static class LogSerializer {
private static void appendWithLength(StringBuffer sb, String data) {
sb.append(data.length());
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
index 6e3226ae5..46f04b8a2 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
@@ -472,7 +472,11 @@ public class LatinKeyboardView extends KeyboardView {
@Override
public void draw(Canvas c) {
- super.draw(c);
+ try {
+ super.draw(c);
+ } catch (RuntimeException e) {
+ LatinImeLogger.logOnException("draw in LatinKeybaordView", e);
+ }
if (DEBUG_AUTO_PLAY) {
if (mPlaying) {
mHandler2.removeMessages(MSG_TOUCH_DOWN);