am c6aaa48e: Merge "Some cleanups"

# Via Android (Google) Code Review (1) and Jean Chalard (1)
* commit 'c6aaa48ea7fa021112cc163730b5bce574c6877b':
  Some cleanups
main
Jean Chalard 2013-02-11 21:10:22 -08:00 committed by Android Git Automerger
commit 08a2bbc738
1 changed files with 21 additions and 18 deletions

View File

@ -117,8 +117,6 @@ public final class BinaryDictionaryFileDumper {
*/ */
private static List<WordListInfo> getWordListWordListInfos(final Locale locale, private static List<WordListInfo> getWordListWordListInfos(final Locale locale,
final Context context, final boolean hasDefaultWordList) { final Context context, final boolean hasDefaultWordList) {
try {
final ContentResolver resolver = context.getContentResolver();
final String clientId = context.getString(R.string.dictionary_pack_client_id); final String clientId = context.getString(R.string.dictionary_pack_client_id);
final Uri.Builder builder = getProviderUriBuilder(clientId); final Uri.Builder builder = getProviderUriBuilder(clientId);
builder.appendPath(QUERY_PATH_DICT_INFO); builder.appendPath(QUERY_PATH_DICT_INFO);
@ -130,6 +128,8 @@ public final class BinaryDictionaryFileDumper {
} }
final Uri dictionaryPackUri = builder.build(); final Uri dictionaryPackUri = builder.build();
final ContentResolver resolver = context.getContentResolver();
try {
final Cursor c = resolver.query(dictionaryPackUri, DICTIONARY_PROJECTION, null, null, final Cursor c = resolver.query(dictionaryPackUri, DICTIONARY_PROJECTION, null, null,
null); null);
if (null == c) { if (null == c) {
@ -153,8 +153,11 @@ public final class BinaryDictionaryFileDumper {
c.close(); c.close();
return list; return list;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Since we are testing for the dictionary pack presence before doing anything that may // Any method call on the content resolver may unexpectedly crash without notice
// crash, it's probably impossible for the code to come here. However it's very // 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 // 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. // 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); Log.e(TAG, "IllegalArgumentException: the dictionary pack can't be contacted?", e);
@ -162,7 +165,7 @@ public final class BinaryDictionaryFileDumper {
} catch (Exception e) { } catch (Exception e) {
// Just in case we hit a problem in communication with the dictionary pack. // Just in case we hit a problem in communication with the dictionary pack.
// We don't want to die. // 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(); return Collections.<WordListInfo>emptyList();
} }
} }
@ -277,7 +280,7 @@ public final class BinaryDictionaryFileDumper {
return AssetFileAddress.makeFromFileName(finalFileName); return AssetFileAddress.makeFromFileName(finalFileName);
} catch (Exception e) { } catch (Exception e) {
if (DEBUG) { 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) { if (null != outputFile) {
// This may or may not fail. The file may not have been created if the // 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 != decryptedStream) decryptedStream.close();
if (null != bufferedInputStream) bufferedInputStream.close(); if (null != bufferedInputStream) bufferedInputStream.close();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Exception while closing a file descriptor : " + e); Log.e(TAG, "Exception while closing a file descriptor", e);
} }
try { try {
if (null != bufferedOutputStream) bufferedOutputStream.close(); if (null != bufferedOutputStream) bufferedOutputStream.close();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Exception while closing a file : " + e); Log.e(TAG, "Exception while closing a file", e);
} }
} }
} }