Messaging: Use try-with-resource
Change-Id: I6649517cbd990502dfcb54f078764cf05f210268
This commit is contained in:
@@ -148,13 +148,11 @@ public class DeleteConversationAction extends Action implements Parcelable {
|
||||
Assert.notNull(conversationId);
|
||||
|
||||
final List<Uri> messageUris = new ArrayList<>();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
new String[] { MessageColumns.SMS_MESSAGE_URI },
|
||||
MessageColumns.CONVERSATION_ID + "=?",
|
||||
new String[] { conversationId },
|
||||
null, null, null);
|
||||
try (Cursor cursor = db.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
new String[]{MessageColumns.SMS_MESSAGE_URI},
|
||||
MessageColumns.CONVERSATION_ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null)) {
|
||||
while (cursor.moveToNext()) {
|
||||
String messageUri = cursor.getString(0);
|
||||
try {
|
||||
@@ -164,10 +162,6 @@ public class DeleteConversationAction extends Action implements Parcelable {
|
||||
+ messageUri);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
for (Uri messageUri : messageUris) {
|
||||
int count = MmsUtils.deleteMessage(messageUri);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -298,21 +299,15 @@ class SyncMessageBatch {
|
||||
// with those details.
|
||||
|
||||
String foundConversationId = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
try (Cursor cursor = db.rawQuery("SELECT " + ConversationColumns._ID
|
||||
+ " FROM " + DatabaseHelper.CONVERSATIONS_TABLE
|
||||
+ " WHERE " + ConversationColumns._ID + "=" + conversationId,
|
||||
null)) {
|
||||
// Look for an existing conversation in the db with the conversation id
|
||||
cursor = db.rawQuery("SELECT " + ConversationColumns._ID
|
||||
+ " FROM " + DatabaseHelper.CONVERSATIONS_TABLE
|
||||
+ " WHERE " + ConversationColumns._ID + "=" + conversationId,
|
||||
null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
Assert.isTrue(cursor.getCount() == 1);
|
||||
foundConversationId = cursor.getString(0);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
ParticipantData foundSelfParticipant =
|
||||
|
||||
Reference in New Issue
Block a user