diff options
Diffstat (limited to 'java/src')
7 files changed, 37 insertions, 29 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index e087a4565..ab851bd64 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -164,10 +164,10 @@ public class KeyboardBuilder<KP extends KeyboardParams> { try { parseKeyboard(parser); } catch (XmlPullParserException e) { - Log.w(BUILDER_TAG, "keyboard XML parse error: " + e); + Log.w(BUILDER_TAG, "keyboard XML parse error", e); throw new IllegalArgumentException(e); } catch (IOException e) { - Log.w(BUILDER_TAG, "keyboard XML parse error: " + e); + Log.w(BUILDER_TAG, "keyboard XML parse error", e); throw new RuntimeException(e); } finally { parser.close(); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java index 6ad9d286f..0ec6b0176 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java @@ -74,6 +74,7 @@ public final class KeyboardCodesSet { private static final int CODE_LEFT_CURLY_BRACKET = '{'; private static final int CODE_RIGHT_CURLY_BRACKET = '}'; + // This array should be aligned with the array RTL below. private static final int[] DEFAULT = { Constants.CODE_TAB, Constants.CODE_ENTER, @@ -117,6 +118,7 @@ public final class KeyboardCodesSet { DEFAULT[12], DEFAULT[13], DEFAULT[14], + DEFAULT[15], CODE_RIGHT_PARENTHESIS, CODE_LEFT_PARENTHESIS, CODE_GREATER_THAN_SIGN, @@ -140,6 +142,9 @@ public final class KeyboardCodesSet { }; static { + if (DEFAULT.length != RTL.length) { + throw new RuntimeException("Internal inconsistency"); + } for (int i = 0; i < ID_TO_NAME.length; i++) { sNameToIdMap.put(ID_TO_NAME[i], i); } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 2fb4182e4..879f1db49 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -117,19 +117,19 @@ public final class BinaryDictionaryFileDumper { */ private static List<WordListInfo> getWordListWordListInfos(final Locale locale, final Context context, final boolean hasDefaultWordList) { - try { - final ContentResolver resolver = context.getContentResolver(); - final String clientId = context.getString(R.string.dictionary_pack_client_id); - final Uri.Builder builder = getProviderUriBuilder(clientId); - builder.appendPath(QUERY_PATH_DICT_INFO); - builder.appendPath(locale.toString()); - builder.appendQueryParameter(QUERY_PARAMETER_PROTOCOL, QUERY_PARAMETER_PROTOCOL_VALUE); - if (!hasDefaultWordList) { - builder.appendQueryParameter(QUERY_PARAMETER_MAY_PROMPT_USER, - QUERY_PARAMETER_TRUE); - } - final Uri dictionaryPackUri = builder.build(); + final String clientId = context.getString(R.string.dictionary_pack_client_id); + final Uri.Builder builder = getProviderUriBuilder(clientId); + builder.appendPath(QUERY_PATH_DICT_INFO); + builder.appendPath(locale.toString()); + builder.appendQueryParameter(QUERY_PARAMETER_PROTOCOL, QUERY_PARAMETER_PROTOCOL_VALUE); + if (!hasDefaultWordList) { + builder.appendQueryParameter(QUERY_PARAMETER_MAY_PROMPT_USER, + QUERY_PARAMETER_TRUE); + } + final Uri dictionaryPackUri = builder.build(); + final ContentResolver resolver = context.getContentResolver(); + try { final Cursor c = resolver.query(dictionaryPackUri, DICTIONARY_PROJECTION, null, null, null); if (null == c) { @@ -153,8 +153,11 @@ public final class BinaryDictionaryFileDumper { c.close(); return list; } catch (IllegalArgumentException e) { - // Since we are testing for the dictionary pack presence before doing anything that may - // crash, it's probably impossible for the code to come here. However it's very + // Any method call on the content resolver may unexpectedly crash without notice + // if the content provider is not present (for example, while crypting a device). + // Testing seems to indicate that ContentResolver#query() merely returns null + // while ContentResolver#delete throws IllegalArgumentException but this is + // undocumented, so all ContentResolver methods should be protected. A crash here is // dangerous because crashing here would brick any encrypted device - we need the // keyboard to be up and working to enter the password. So let's be as safe as possible. Log.e(TAG, "IllegalArgumentException: the dictionary pack can't be contacted?", e); @@ -162,7 +165,7 @@ public final class BinaryDictionaryFileDumper { } catch (Exception e) { // Just in case we hit a problem in communication with the dictionary pack. // We don't want to die. - Log.e(TAG, "Exception communicating with the dictionary pack : " + e); + Log.e(TAG, "Exception communicating with the dictionary pack", e); return Collections.<WordListInfo>emptyList(); } } @@ -277,7 +280,7 @@ public final class BinaryDictionaryFileDumper { return AssetFileAddress.makeFromFileName(finalFileName); } catch (Exception e) { if (DEBUG) { - Log.i(TAG, "Can't open word list in mode " + mode + " : " + e); + Log.i(TAG, "Can't open word list in mode " + mode, e); } if (null != outputFile) { // This may or may not fail. The file may not have been created if the @@ -295,12 +298,12 @@ public final class BinaryDictionaryFileDumper { if (null != decryptedStream) decryptedStream.close(); if (null != bufferedInputStream) bufferedInputStream.close(); } catch (Exception e) { - Log.e(TAG, "Exception while closing a file descriptor : " + e); + Log.e(TAG, "Exception while closing a file descriptor", e); } try { if (null != bufferedOutputStream) bufferedOutputStream.close(); } catch (Exception e) { - Log.e(TAG, "Exception while closing a file : " + e); + Log.e(TAG, "Exception while closing a file", e); } } } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 1cdc3b564..a96738b3e 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -210,7 +210,7 @@ final class BinaryDictionaryGetter { } } } catch (java.io.IOException e) { - Log.e(TAG, "IOException trying to cleanup files : " + e); + Log.e(TAG, "IOException trying to cleanup files", e); } } diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 28ed88a73..97dc6a8ac 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -321,9 +321,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { tempFile.renameTo(file); clearFusionDictionary(); } catch (IOException e) { - Log.e(TAG, "IO exception while writing file: " + e); + Log.e(TAG, "IO exception while writing file", e); } catch (UnsupportedFormatException e) { - Log.e(TAG, "Unsupported format: " + e); + Log.e(TAG, "Unsupported format", e); } finally { if (out != null) { try { diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java index eb5c387a8..62f2a9750 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java @@ -122,9 +122,9 @@ public final class UserHistoryDictIOUtils { BinaryDictInputOutput.writeDictionaryBinary(destination, fusionDict, formatOptions); Log.d(TAG, "end writing"); } catch (IOException e) { - Log.e(TAG, "IO exception while writing file: " + e); + Log.e(TAG, "IO exception while writing file", e); } catch (UnsupportedFormatException e) { - Log.e(TAG, "Unsupported fomat: " + e); + Log.e(TAG, "Unsupported format", e); } } @@ -184,11 +184,11 @@ public final class UserHistoryDictIOUtils { BinaryDictIOUtils.readUnigramsAndBigramsBinary(buffer, unigrams, frequencies, bigrams); } catch (IOException e) { - Log.e(TAG, "IO exception while reading file: " + e); + Log.e(TAG, "IO exception while reading file", e); } catch (UnsupportedFormatException e) { - Log.e(TAG, "Unsupported format: " + e); + Log.e(TAG, "Unsupported format", e); } catch (ArrayIndexOutOfBoundsException e) { - Log.e(TAG, "ArrayIndexOutOfBoundsException while reading file: " + e); + Log.e(TAG, "ArrayIndexOutOfBoundsException while reading file", e); } addWordsFromWordMap(unigrams, frequencies, bigrams, dict); } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java index b0e471643..cd3f9e442 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java @@ -352,7 +352,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { if (DBG) { throw e; } else { - Log.e(TAG, "Exception while spellcheking: " + e); + Log.e(TAG, "Exception while spellcheking", e); return AndroidSpellCheckerService.getNotInDictEmptySuggestions(); } } |