From b8ff8ca9d9d17f61f3f0e019ed0b62fe13d1a33f Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 18 Feb 2014 16:02:51 +0900 Subject: Straighten out database cursors behavior. Some were never closed, other closed twice. This change makes all Cursor instances behave, having the #close() call in a finally{} clause, and puts the burden of closing the cursor squarely on the creator rather than in the called methods. There is however one exception that is beyond the scope of this change: UserDictionarySettings have a Cursor member, it's never closed, and fixing the problem is not obvious. This change adds a TODO for now. It's not very clear if this change actually helps with bug#12670151, but it may be related and it's a good think to do anyway. Bug: 12670151 Change-Id: I87cc44387e7dee3da1488671b93a28d9d73f7dc0 --- .../latin/BinaryDictionaryFileDumper.java | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index b4382bc2c..e428b1d54 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -142,7 +142,7 @@ public final class BinaryDictionaryFileDumper { final ContentProviderClient client = context.getContentResolver(). acquireContentProviderClient(getProviderUriBuilder("").build()); if (null == client) return Collections.emptyList(); - + Cursor cursor = null; try { final Uri.Builder builder = getContentUriBuilderForType(clientId, client, QUERY_PATH_DICT_INFO, locale.toString()); @@ -154,24 +154,22 @@ public final class BinaryDictionaryFileDumper { final boolean isProtocolV2 = (QUERY_PARAMETER_PROTOCOL_VALUE.equals( queryUri.getQueryParameter(QUERY_PARAMETER_PROTOCOL))); - Cursor c = client.query(queryUri, DICTIONARY_PROJECTION, null, null, null); - if (isProtocolV2 && null == c) { + cursor = client.query(queryUri, DICTIONARY_PROJECTION, null, null, null); + if (isProtocolV2 && null == cursor) { reinitializeClientRecordInDictionaryContentProvider(context, client, clientId); - c = client.query(queryUri, DICTIONARY_PROJECTION, null, null, null); + cursor = client.query(queryUri, DICTIONARY_PROJECTION, null, null, null); } - if (null == c) return Collections.emptyList(); - if (c.getCount() <= 0 || !c.moveToFirst()) { - c.close(); + if (null == cursor) return Collections.emptyList(); + if (cursor.getCount() <= 0 || !cursor.moveToFirst()) { return Collections.emptyList(); } final ArrayList list = CollectionUtils.newArrayList(); do { - final String wordListId = c.getString(0); - final String wordListLocale = c.getString(1); + final String wordListId = cursor.getString(0); + final String wordListLocale = cursor.getString(1); if (TextUtils.isEmpty(wordListId)) continue; list.add(new WordListInfo(wordListId, wordListLocale)); - } while (c.moveToNext()); - c.close(); + } while (cursor.moveToNext()); return list; } catch (RemoteException e) { // The documentation is unclear as to in which cases this may happen, but it probably @@ -186,6 +184,9 @@ public final class BinaryDictionaryFileDumper { Log.e(TAG, "Unexpected exception communicating with the dictionary pack", e); return Collections.emptyList(); } finally { + if (null != cursor) { + cursor.close(); + } client.release(); } } -- cgit v1.2.3-83-g751a