aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-02-11 15:00:49 -0800
committerJean Chalard <jchalard@google.com>2013-02-11 19:47:15 -0800
commit8018051022419819de6b857f3c6ed2a5da518568 (patch)
treec171cd2c0fb65028078bc8bcd88f0c8efc596c58 /java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
parent82441e60e242681f2ea0d6e97105f819e3bd5071 (diff)
downloadlatinime-8018051022419819de6b857f3c6ed2a5da518568.tar.gz
latinime-8018051022419819de6b857f3c6ed2a5da518568.tar.xz
latinime-8018051022419819de6b857f3c6ed2a5da518568.zip
Some cleanups
Improve a slew of logging statements, and put commands that we don't expect to need protecting against exceptions out of a try {} block. This is a followup to Id3dc510a Change-Id: Idc6f419ac095b5b0f2d6862d58926ef888cb34e6
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java39
1 files changed, 21 insertions, 18 deletions
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);
}
}
}