aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-01-27 01:26:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-01-27 01:26:00 +0000
commita3c215a1e51bcee7087d5e676fdeaafc2ad96328 (patch)
tree6252944e81370cde9f554736f5bcefe3e12bd689 /src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java
parent3acc21a7154ded85273f31cf2e17d4d39b98236d (diff)
parentc14418b2d1064fb215dfc4035b40483c8575dde7 (diff)
downloadContactsProvider-a3c215a1e51bcee7087d5e676fdeaafc2ad96328.tar.gz
Merge "Make sure to close cursors" into main
Diffstat (limited to 'src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java')
-rw-r--r--src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java b/src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java
index ca29edc6..59e213bb 100644
--- a/src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java
+++ b/src/com/android/providers/contacts/PhoneLookupWithStarPrefix.java
@@ -154,7 +154,7 @@ import android.util.Log;
* Check each phone number in the given cursor to detemine if it's a match with the given phone
* number. Return the matching ones in a new cursor.
* @param number phone number to be match
- * @param cursor contains a series of number s to be match
+ * @param cursor contains a series of numbers to be matched
* @param defaultCountryIso The lowercase two letter ISO 3166-1 country code. It is recommended
* to pass in {@link TelephonyManager#getNetworkCountryIso()}.
* @return A new cursor with all matching phone numbers.
@@ -166,19 +166,23 @@ import android.util.Log;
}
final MatrixCursor matrixCursor = new MatrixCursor(cursor.getColumnNames());
-
- cursor.moveToPosition(-1);
- while (cursor.moveToNext()) {
- final int numberIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
- final String numberToMatch = cursor.getString(numberIndex);
- if (PhoneNumberUtils.areSamePhoneNumber(number, numberToMatch, defaultCountryIso)) {
- final MatrixCursor.RowBuilder b = matrixCursor.newRow();
- for (int column = 0; column < cursor.getColumnCount(); column++) {
- b.add(cursor.getColumnName(column), cursorValue(cursor, column));
+ try {
+ cursor.moveToPosition(-1);
+ while (cursor.moveToNext()) {
+ final int numberIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
+ final String numberToMatch = cursor.getString(numberIndex);
+ if (PhoneNumberUtils.areSamePhoneNumber(number, numberToMatch, defaultCountryIso)) {
+ final MatrixCursor.RowBuilder b = matrixCursor.newRow();
+ for (int column = 0; column < cursor.getColumnCount(); column++) {
+ b.add(cursor.getColumnName(column), cursorValue(cursor, column));
+ }
}
}
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
-
return matrixCursor;
}
}