Messaging: Use try-with-resource
Change-Id: I6649517cbd990502dfcb54f078764cf05f210268
This commit is contained in:
@@ -308,11 +308,9 @@ public class ParticipantRefresh {
|
||||
final DatabaseWrapper db = DataModel.get().getDatabase();
|
||||
final HashSet<Integer> existingSubIds = new HashSet<Integer>();
|
||||
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantsQuery.PROJECTION,
|
||||
SELF_PARTICIPANTS_CLAUSE, null, null, null, null);
|
||||
try (Cursor cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantsQuery.PROJECTION,
|
||||
SELF_PARTICIPANTS_CLAUSE, null, null, null, null)) {
|
||||
|
||||
if (cursor != null) {
|
||||
while (cursor.moveToNext()) {
|
||||
@@ -320,10 +318,6 @@ public class ParticipantRefresh {
|
||||
existingSubIds.add(subId);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return existingSubIds;
|
||||
}
|
||||
@@ -445,9 +439,7 @@ public class ParticipantRefresh {
|
||||
// For self participant, try getting name/avatar from self profile in CP2 first.
|
||||
// TODO: in case of multi-sim, profile would not be able to be used for
|
||||
// different numbers. Need to figure out that.
|
||||
Cursor selfCursor = null;
|
||||
try {
|
||||
selfCursor = ContactUtil.getSelf(db.getContext()).performSynchronousQuery();
|
||||
try (Cursor selfCursor = ContactUtil.getSelf(db.getContext()).performSynchronousQuery()) {
|
||||
if (selfCursor != null && selfCursor.getCount() > 0) {
|
||||
selfCursor.moveToNext();
|
||||
final long selfContactId = selfCursor.getLong(ContactUtil.INDEX_CONTACT_ID);
|
||||
@@ -467,10 +459,6 @@ public class ParticipantRefresh {
|
||||
// However, we need to at least log the exception so we know something was wrong.
|
||||
LogUtil.e(LogUtil.BUGLE_DATAMODEL_TAG, "Participant refresh: failed to refresh " +
|
||||
"participant. exception=" + exception);
|
||||
} finally {
|
||||
if (selfCursor != null) {
|
||||
selfCursor.close();
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
@@ -619,12 +607,10 @@ public class ParticipantRefresh {
|
||||
|
||||
final String selection = ParticipantColumns.SIM_SLOT_ID + "=? AND " +
|
||||
SELF_PARTICIPANTS_CLAUSE;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
new String[] { ParticipantColumns._ID },
|
||||
selection, new String[] { String.valueOf(ParticipantData.INVALID_SLOT_ID) },
|
||||
null, null, null);
|
||||
try (Cursor cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
new String[]{ParticipantColumns._ID},
|
||||
selection, new String[]{String.valueOf(ParticipantData.INVALID_SLOT_ID)},
|
||||
null, null, null)) {
|
||||
|
||||
if (cursor != null) {
|
||||
while (cursor.moveToNext()) {
|
||||
@@ -632,10 +618,6 @@ public class ParticipantRefresh {
|
||||
inactiveSelf.add(participantId);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return inactiveSelf;
|
||||
|
||||
Reference in New Issue
Block a user