Messaging: Use try-with-resource
Change-Id: I6649517cbd990502dfcb54f078764cf05f210268
This commit is contained in:
@@ -399,9 +399,7 @@ class DefaultApnSettingsLoader implements ApnSettingsLoader {
|
||||
return;
|
||||
}
|
||||
// MCC/MNC is good, loading/querying APNs from XML
|
||||
XmlResourceParser xml = null;
|
||||
try {
|
||||
xml = mContext.getResources().getXml(R.xml.apns);
|
||||
try (XmlResourceParser xml = mContext.getResources().getXml(R.xml.apns)) {
|
||||
new ApnsXmlParser(xml, apnValues -> {
|
||||
final String mcc = trimWithNullCheck(apnValues.getAsString(APN_MCC));
|
||||
final String mnc = trimWithNullCheck(apnValues.getAsString(APN_MNC));
|
||||
@@ -425,10 +423,6 @@ class DefaultApnSettingsLoader implements ApnSettingsLoader {
|
||||
}).parse();
|
||||
} catch (final Resources.NotFoundException e) {
|
||||
Log.w(MmsService.TAG, "Can not get apns.xml " + e);
|
||||
} finally {
|
||||
if (xml != null) {
|
||||
xml.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,9 +92,7 @@ class DefaultCarrierConfigValuesLoader implements CarrierConfigValuesLoader {
|
||||
private void loadFromResources(final int subId, final Bundle values) {
|
||||
// Get a subscription-dependent context for loading the mms_config.xml
|
||||
final Context subContext = Utils.getSubDepContext(mContext, subId);
|
||||
XmlResourceParser xml = null;
|
||||
try {
|
||||
xml = subContext.getResources().getXml(R.xml.mms_config);
|
||||
try (XmlResourceParser xml = subContext.getResources().getXml(R.xml.mms_config)) {
|
||||
new CarrierConfigXmlParser(xml, (type, key, value) -> {
|
||||
try {
|
||||
if (KEY_TYPE_INT.equals(type)) {
|
||||
@@ -111,10 +109,6 @@ class DefaultCarrierConfigValuesLoader implements CarrierConfigValuesLoader {
|
||||
}).parse();
|
||||
} catch (final Resources.NotFoundException e) {
|
||||
Log.w(MmsService.TAG, "Can not get mms_config.xml");
|
||||
} finally {
|
||||
if (xml != null) {
|
||||
xml.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,22 +251,16 @@ public class BugleDatabaseOperations {
|
||||
Assert.isNotMainThread();
|
||||
String conversationId = null;
|
||||
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
// Look for an existing conversation in the db with this thread id
|
||||
cursor = dbWrapper.rawQuery("SELECT " + ConversationColumns._ID
|
||||
try (Cursor cursor = dbWrapper.rawQuery("SELECT " + ConversationColumns._ID
|
||||
+ " FROM " + DatabaseHelper.CONVERSATIONS_TABLE
|
||||
+ " WHERE " + ConversationColumns.SMS_THREAD_ID + "=" + threadId,
|
||||
null);
|
||||
null)) {
|
||||
// Look for an existing conversation in the db with this thread id
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
Assert.isTrue(cursor.getCount() == 1);
|
||||
conversationId = cursor.getString(0);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return conversationId;
|
||||
@@ -285,13 +279,11 @@ public class BugleDatabaseOperations {
|
||||
Assert.isNotMainThread();
|
||||
long threadId = -1;
|
||||
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
new String[]{ConversationColumns.SMS_THREAD_ID},
|
||||
ConversationColumns._ID + " =?",
|
||||
new String[]{conversationId},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
Assert.isTrue(cursor.getCount() == 1);
|
||||
@@ -299,10 +291,6 @@ public class BugleDatabaseOperations {
|
||||
threadId = cursor.getLong(0);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return threadId;
|
||||
@@ -320,23 +308,17 @@ public class BugleDatabaseOperations {
|
||||
|
||||
static boolean isBlockedParticipant(final DatabaseWrapper db, final String value,
|
||||
final String column) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
try (Cursor cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
new String[]{ParticipantColumns.BLOCKED},
|
||||
column + "=? AND " + ParticipantColumns.SUB_ID + "=?",
|
||||
new String[]{value,
|
||||
Integer.toString(ParticipantData.OTHER_THAN_SELF_SUB_ID)},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
return cursor.getInt(0) == 1;
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return false; // if there's no row, it's not blocked :-)
|
||||
}
|
||||
@@ -524,12 +506,10 @@ public class BugleDatabaseOperations {
|
||||
new String[]{ conversationId },
|
||||
null, null, null);
|
||||
if (cursor != null) {
|
||||
try {
|
||||
try (cursor) {
|
||||
if (cursor.moveToFirst()) {
|
||||
return cursor.getLong(0);
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -675,21 +655,15 @@ public class BugleDatabaseOperations {
|
||||
// Make sure the selfId passed in is valid and active.
|
||||
final String selection = ParticipantColumns._ID + "=? AND " +
|
||||
ParticipantColumns.SIM_SLOT_ID + "<>?";
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
new String[]{ParticipantColumns._ID}, selection,
|
||||
new String[]{selfId, String.valueOf(ParticipantData.INVALID_SLOT_ID)},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
|
||||
if (cursor != null && cursor.getCount() > 0) {
|
||||
values.put(ConversationColumns.CURRENT_SELF_ID, selfId);
|
||||
return true;
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -700,22 +674,17 @@ public class BugleDatabaseOperations {
|
||||
Assert.isTrue(dbWrapper.getDatabase().inTransaction());
|
||||
|
||||
long sortTimestamp = 0L;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
// Check to find the latest message in the conversation
|
||||
cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
REFRESH_CONVERSATION_MESSAGE_PROJECTION,
|
||||
MessageColumns.CONVERSATION_ID + "=?",
|
||||
new String[]{conversationId}, null, null,
|
||||
MessageColumns.RECEIVED_TIMESTAMP + " DESC", "1" /* limit */);
|
||||
MessageColumns.RECEIVED_TIMESTAMP + " DESC", "1" /* limit */)) {
|
||||
// Check to find the latest message in the conversation
|
||||
/* limit */
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
sortTimestamp = cursor.getLong(1);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -854,21 +823,15 @@ public class BugleDatabaseOperations {
|
||||
public static String getConversationSelfId(final DatabaseWrapper dbWrapper,
|
||||
final String conversationId) {
|
||||
Assert.isNotMainThread();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
new String[]{ConversationColumns.CURRENT_SELF_ID},
|
||||
ConversationColumns._ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
return cursor.getString(0);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -903,21 +866,15 @@ public class BugleDatabaseOperations {
|
||||
public static String getSmsServiceCenterForConversation(final DatabaseWrapper dbWrapper,
|
||||
final String conversationId) {
|
||||
Assert.isNotMainThread();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
new String[]{ConversationColumns.SMS_SERVICE_CENTER},
|
||||
ConversationColumns._ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
return cursor.getString(0);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -927,20 +884,14 @@ public class BugleDatabaseOperations {
|
||||
final String participantId) {
|
||||
Assert.isNotMainThread();
|
||||
ParticipantData participant = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantData.ParticipantsQuery.PROJECTION,
|
||||
ParticipantColumns._ID + " =?",
|
||||
new String[] { participantId }, null, null, null);
|
||||
new String[]{participantId}, null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
participant = ParticipantData.getFromCursor(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return participant;
|
||||
@@ -964,24 +915,18 @@ public class BugleDatabaseOperations {
|
||||
Assert.isNotMainThread();
|
||||
final ArrayList<ParticipantData> participants =
|
||||
new ArrayList<ParticipantData>();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantData.ParticipantsQuery.PROJECTION,
|
||||
ParticipantColumns._ID + " IN ( " + "SELECT "
|
||||
+ ConversationParticipantsColumns.PARTICIPANT_ID + " AS "
|
||||
+ ParticipantColumns._ID
|
||||
+ " FROM " + DatabaseHelper.CONVERSATION_PARTICIPANTS_TABLE
|
||||
+ " WHERE " + ConversationParticipantsColumns.CONVERSATION_ID + " =? )",
|
||||
new String[] { conversationId }, null, null, null);
|
||||
new String[]{conversationId}, null, null, null)) {
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
participants.add(ParticipantData.getFromCursor(cursor));
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return participants;
|
||||
@@ -1001,19 +946,13 @@ public class BugleDatabaseOperations {
|
||||
static MessagePartData readMessagePartData(final DatabaseWrapper dbWrapper,
|
||||
final String partId) {
|
||||
MessagePartData messagePartData = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.PARTS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTS_TABLE,
|
||||
MessagePartData.getProjection(), PartColumns._ID + "=?",
|
||||
new String[] { partId }, null, null, null);
|
||||
new String[]{partId}, null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
messagePartData = MessagePartData.createFromCursor(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return messagePartData;
|
||||
}
|
||||
@@ -1023,20 +962,14 @@ public class BugleDatabaseOperations {
|
||||
final Uri smsMessageUri) {
|
||||
Assert.isNotMainThread();
|
||||
MessageData message = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
MessageData.getProjection(), MessageColumns.SMS_MESSAGE_URI + "=?",
|
||||
new String[] { smsMessageUri.toString() }, null, null, null);
|
||||
new String[]{smsMessageUri.toString()}, null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
message = new MessageData();
|
||||
message.bind(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
@@ -1046,20 +979,14 @@ public class BugleDatabaseOperations {
|
||||
final String messageId) {
|
||||
Assert.isNotMainThread();
|
||||
MessageData message = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
MessageData.getProjection(), MessageColumns._ID + "=?",
|
||||
new String[] { messageId }, null, null, null);
|
||||
new String[]{messageId}, null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
message = new MessageData();
|
||||
message.bind(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
@@ -1074,11 +1001,9 @@ public class BugleDatabaseOperations {
|
||||
final MessageData message, final boolean checkAttachmentFilesExist) {
|
||||
final ContentResolver contentResolver =
|
||||
Factory.get().getApplicationContext().getContentResolver();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.PARTS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTS_TABLE,
|
||||
MessagePartData.getProjection(), PartColumns.MESSAGE_ID + "=?",
|
||||
new String[] { message.getMessageId() }, null, null, null);
|
||||
new String[]{message.getMessageId()}, null, null, null)) {
|
||||
while (cursor.moveToNext()) {
|
||||
final MessagePartData messagePartData = MessagePartData.createFromCursor(cursor);
|
||||
if (checkAttachmentFilesExist && messagePartData.isAttachment() &&
|
||||
@@ -1104,10 +1029,6 @@ public class BugleDatabaseOperations {
|
||||
message.addPart(messagePartData);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1262,18 +1183,17 @@ public class BugleDatabaseOperations {
|
||||
final String conversationId) {
|
||||
Assert.isNotMainThread();
|
||||
Assert.isTrue(dbWrapper.getDatabase().inTransaction());
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
// TODO: The refreshConversationMetadataInTransaction method below uses this
|
||||
// same query; maybe they should share this logic?
|
||||
|
||||
// Check to see if there are any (non-draft) messages in the conversation
|
||||
cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
REFRESH_CONVERSATION_MESSAGE_PROJECTION,
|
||||
MessageColumns.CONVERSATION_ID + "=? AND " +
|
||||
MessageColumns.STATUS + "!=" + MessageData.BUGLE_STATUS_OUTGOING_DRAFT,
|
||||
new String[]{conversationId}, null, null,
|
||||
MessageColumns.RECEIVED_TIMESTAMP + " DESC", "1" /* limit */);
|
||||
MessageColumns.RECEIVED_TIMESTAMP + " DESC", "1" /* limit */)) {
|
||||
// TODO: The refreshConversationMetadataInTransaction method below uses this
|
||||
// same query; maybe they should share this logic?
|
||||
|
||||
// Check to see if there are any (non-draft) messages in the conversation
|
||||
/* limit */
|
||||
if (cursor.getCount() == 0) {
|
||||
dbWrapper.delete(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
ConversationColumns._ID + "=?", new String[]{conversationId});
|
||||
@@ -1283,10 +1203,6 @@ public class BugleDatabaseOperations {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,15 +1222,14 @@ public class BugleDatabaseOperations {
|
||||
boolean keepArchived) {
|
||||
Assert.isNotMainThread();
|
||||
Assert.isTrue(dbWrapper.getDatabase().inTransaction());
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
// Check to see if there are any (non-draft) messages in the conversation
|
||||
cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
REFRESH_CONVERSATION_MESSAGE_PROJECTION,
|
||||
MessageColumns.CONVERSATION_ID + "=? AND " +
|
||||
MessageColumns.STATUS + "!=" + MessageData.BUGLE_STATUS_OUTGOING_DRAFT,
|
||||
new String[]{conversationId}, null, null,
|
||||
MessageColumns.RECEIVED_TIMESTAMP + " DESC", "1" /* limit */);
|
||||
MessageColumns.RECEIVED_TIMESTAMP + " DESC", "1" /* limit */)) {
|
||||
// Check to see if there are any (non-draft) messages in the conversation
|
||||
/* limit */
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
// Refresh latest message in conversation
|
||||
@@ -1326,10 +1241,6 @@ public class BugleDatabaseOperations {
|
||||
latestMessageId, latestMessageTimestamp, senderBlocked || keepArchived,
|
||||
shouldAutoSwitchSelfId);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1351,21 +1262,15 @@ public class BugleDatabaseOperations {
|
||||
if (!TextUtils.isEmpty(messageId)) {
|
||||
refresh = false;
|
||||
// Look for an existing conversation in the db with this conversation id
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
new String[]{ConversationColumns.LATEST_MESSAGE_ID},
|
||||
ConversationColumns._ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
refresh = TextUtils.equals(cursor.getString(0), messageId);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (refresh) {
|
||||
@@ -1457,18 +1362,13 @@ public class BugleDatabaseOperations {
|
||||
static boolean getConversationExists(final DatabaseWrapper dbWrapper,
|
||||
final String conversationId) {
|
||||
// Look for an existing conversation in the db with this conversation id
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
new String[]{ /* No projection */},
|
||||
ConversationColumns._ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
/* No projection */
|
||||
return cursor.getCount() == 1;
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1578,16 +1478,14 @@ public class BugleDatabaseOperations {
|
||||
final String conversationId, final String conversationSelfId) {
|
||||
Assert.isNotMainThread();
|
||||
MessageData message = null;
|
||||
Cursor cursor = null;
|
||||
dbWrapper.beginTransaction();
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
MessageData.getProjection(),
|
||||
MessageColumns.STATUS + "=? AND " + MessageColumns.CONVERSATION_ID + "=?",
|
||||
new String[]{
|
||||
Integer.toString(MessageData.BUGLE_STATUS_OUTGOING_DRAFT),
|
||||
conversationId
|
||||
}, null, null, null);
|
||||
}, null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
message = new MessageData();
|
||||
@@ -1603,9 +1501,6 @@ public class BugleDatabaseOperations {
|
||||
dbWrapper.setTransactionSuccessful();
|
||||
} finally {
|
||||
dbWrapper.endTransaction();
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
@@ -1770,20 +1665,14 @@ public class BugleDatabaseOperations {
|
||||
public static String getConversationFromOtherParticipantDestination(
|
||||
final DatabaseWrapper db, final String otherDestination) {
|
||||
Assert.isNotMainThread();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
try (Cursor cursor = db.query(DatabaseHelper.CONVERSATIONS_TABLE,
|
||||
new String[]{ConversationColumns._ID},
|
||||
ConversationColumns.OTHER_PARTICIPANT_NORMALIZED_DESTINATION + "=?",
|
||||
new String[] { otherDestination }, null, null, null);
|
||||
new String[]{otherDestination}, null, null, null)) {
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
return cursor.getString(0);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1146,15 +1146,13 @@ public abstract class MessageNotificationState extends NotificationState {
|
||||
public static void checkFailedMessages() {
|
||||
final DatabaseWrapper db = DataModel.get().getDatabase();
|
||||
|
||||
final Cursor messageDataCursor = db.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
try (Cursor messageDataCursor = db.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
MessageData.getProjection(),
|
||||
FailedMessageQuery.FAILED_MESSAGES_WHERE_CLAUSE,
|
||||
null /*selectionArgs*/,
|
||||
null /*groupBy*/,
|
||||
null /*having*/,
|
||||
FailedMessageQuery.FAILED_ORDER_BY);
|
||||
|
||||
try {
|
||||
FailedMessageQuery.FAILED_ORDER_BY)) {
|
||||
final Context context = Factory.get().getApplicationContext();
|
||||
final Resources resources = context.getResources();
|
||||
final NotificationManagerCompat notificationManager =
|
||||
@@ -1192,8 +1190,8 @@ public abstract class MessageNotificationState extends NotificationState {
|
||||
LogUtil.d(TAG, "Found " + failedMessages.size() + " failed messages");
|
||||
}
|
||||
if (failedMessages.size() > 0) {
|
||||
final NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(context,
|
||||
final Builder builder =
|
||||
new Builder(context,
|
||||
NotificationsUtil.DEFAULT_CHANNEL_ID);
|
||||
|
||||
CharSequence line1;
|
||||
@@ -1298,10 +1296,6 @@ public abstract class MessageNotificationState extends NotificationState {
|
||||
PendingIntentConstants.MSG_SEND_ERROR);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (messageDataCursor != null) {
|
||||
messageDataCursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
try (Cursor cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantsQuery.PROJECTION,
|
||||
SELF_PARTICIPANTS_CLAUSE, null, null, null, null);
|
||||
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,
|
||||
try (Cursor cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
new String[]{ParticipantColumns._ID},
|
||||
selection, new String[]{String.valueOf(ParticipantData.INVALID_SLOT_ID)},
|
||||
null, null, null);
|
||||
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;
|
||||
|
||||
@@ -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,
|
||||
try (Cursor cursor = db.query(DatabaseHelper.MESSAGES_TABLE,
|
||||
new String[]{MessageColumns.SMS_MESSAGE_URI},
|
||||
MessageColumns.CONVERSATION_ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null);
|
||||
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 {
|
||||
// Look for an existing conversation in the db with the conversation id
|
||||
cursor = db.rawQuery("SELECT " + ConversationColumns._ID
|
||||
try (Cursor cursor = db.rawQuery("SELECT " + ConversationColumns._ID
|
||||
+ " FROM " + DatabaseHelper.CONVERSATIONS_TABLE
|
||||
+ " WHERE " + ConversationColumns._ID + "=" + conversationId,
|
||||
null);
|
||||
null)) {
|
||||
// Look for an existing conversation in the db with the conversation id
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
Assert.isTrue(cursor.getCount() == 1);
|
||||
foundConversationId = cursor.getString(0);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
ParticipantData foundSelfParticipant =
|
||||
|
||||
@@ -466,23 +466,17 @@ public class ConversationListItemData {
|
||||
ConversationListItemData conversation = null;
|
||||
|
||||
// Look for an existing conversation in the db with this conversation id
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
// TODO: Should we be able to read a row from just the conversation table?
|
||||
cursor = dbWrapper.query(getConversationListView(),
|
||||
try (Cursor cursor = dbWrapper.query(getConversationListView(),
|
||||
PROJECTION,
|
||||
ConversationColumns._ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null);
|
||||
null, null, null)) {
|
||||
// TODO: Should we be able to read a row from just the conversation table?
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
conversation = new ConversationListItemData();
|
||||
conversation.bind(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return conversation;
|
||||
|
||||
@@ -152,22 +152,16 @@ public class ParticipantData implements Parcelable {
|
||||
|
||||
public static ParticipantData getFromId(final DatabaseWrapper dbWrapper,
|
||||
final String participantId) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantsQuery.PROJECTION,
|
||||
ParticipantColumns._ID + " =?",
|
||||
new String[] { participantId }, null, null, null);
|
||||
new String[]{participantId}, null, null, null)) {
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
return ParticipantData.getFromCursor(cursor);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -155,7 +156,7 @@ public abstract class ImageRequest<D extends ImageRequestDescriptor>
|
||||
if (unknownSize) {
|
||||
final InputStream inputStream = getInputStreamForResource();
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
try (inputStream) {
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeStream(inputStream, null, options);
|
||||
// This is called when dimensions of image were unknown to allow db update
|
||||
@@ -164,8 +165,6 @@ public abstract class ImageRequest<D extends ImageRequestDescriptor>
|
||||
} else {
|
||||
mDescriptor.updateSourceDimensions(options.outWidth, options.outHeight);
|
||||
}
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
} else {
|
||||
throw new FileNotFoundException();
|
||||
|
||||
@@ -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.
|
||||
@@ -265,23 +266,18 @@ public class VCardRequest implements MediaRequest<VCardResource> {
|
||||
for (final VCardEntry.PhotoData photo : photos) {
|
||||
final byte[] photoBytes = photo.getBytes();
|
||||
if (photoBytes != null) {
|
||||
final InputStream inputStream = new ByteArrayInputStream(photoBytes);
|
||||
try {
|
||||
try (InputStream inputStream = new ByteArrayInputStream(photoBytes)) {
|
||||
avatarUri = UriUtil.persistContentToScratchSpace(inputStream);
|
||||
if (avatarUri != null) {
|
||||
// Just load the first avatar and be done. Want more? wait for V2.
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (final IOException e) {
|
||||
} catch (IOException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to generated avatar.
|
||||
if (avatarUri == null) {
|
||||
|
||||
@@ -1026,10 +1026,8 @@ public class PduPersister {
|
||||
|
||||
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
||||
final String[] projection = new String[] {MediaStore.MediaColumns.DATA};
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection, null,
|
||||
null, null);
|
||||
try (Cursor cursor = context.getContentResolver().query(uri, projection, null,
|
||||
null, null)) {
|
||||
if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
|
||||
throw new IllegalArgumentException("Given Uri could not be found" +
|
||||
" in media store");
|
||||
@@ -1040,10 +1038,6 @@ public class PduPersister {
|
||||
} catch (final SQLiteException e) {
|
||||
throw new IllegalArgumentException("Given Uri is not formatted in a way " +
|
||||
"so that it can be found in media store.");
|
||||
} finally {
|
||||
if (null != cursor) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Given Uri scheme is not supported");
|
||||
|
||||
@@ -184,12 +184,10 @@ public class ApnDatabase extends SQLiteOpenHelper {
|
||||
* @return The list of user changed apns
|
||||
*/
|
||||
public static List<ContentValues> loadUserDataFromOldTable(final SQLiteDatabase db) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.query(APN_TABLE,
|
||||
try (Cursor cursor = db.query(APN_TABLE,
|
||||
APN_FULL_PROJECTION, CURRENT_SELECTION,
|
||||
null/*selectionArgs*/,
|
||||
null/*groupBy*/, null/*having*/, null/*orderBy*/);
|
||||
null/*groupBy*/, null/*having*/, null/*orderBy*/)) {
|
||||
if (cursor != null) {
|
||||
final List<ContentValues> result = Lists.newArrayList();
|
||||
while (cursor.moveToNext()) {
|
||||
@@ -202,10 +200,6 @@ public class ApnDatabase extends SQLiteOpenHelper {
|
||||
}
|
||||
} catch (final SQLiteException e) {
|
||||
LogUtil.w(TAG, "ApnDatabase.loadUserDataFromOldTable: no old user data: " + e, e);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -243,13 +237,14 @@ public class ApnDatabase extends SQLiteOpenHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.query(APN_TABLE,
|
||||
try (Cursor cursor = db.query(APN_TABLE,
|
||||
ID_PROJECTION,
|
||||
selectionBuilder.toString(),
|
||||
selectionArgs.toArray(new String[0]),
|
||||
null/*groupBy*/, null/*having*/, null/*orderBy*/);
|
||||
null/*groupBy*/, null/*having*/, null/*orderBy*/)) {
|
||||
/*groupBy*/
|
||||
/*having*/
|
||||
/*orderBy*/
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
db.update(APN_TABLE, row, ID_SELECTION, new String[]{cursor.getString(0)});
|
||||
} else {
|
||||
@@ -263,10 +258,6 @@ public class ApnDatabase extends SQLiteOpenHelper {
|
||||
}
|
||||
} catch (final SQLiteException e) {
|
||||
LogUtil.e(TAG, "ApnDatabase.saveUserDataFromOldTable: query error " + e, e);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,18 +601,12 @@ public class BugleApnSettingsLoader implements ApnSettingsLoader {
|
||||
*/
|
||||
public static String getFirstTryApn(final SQLiteDatabase database, final String mccMnc) {
|
||||
String key = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = queryLocalDatabase(database, mccMnc, null/*apnName*/);
|
||||
try (Cursor cursor = queryLocalDatabase(database, mccMnc, null/*apnName*/)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
key = cursor.getString(ApnDatabase.COLUMN_ID);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
// Nothing to do
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -125,19 +125,13 @@ public class BugleCarrierConfigValuesLoader implements CarrierConfigValuesLoader
|
||||
// Get a subscription-dependent context for loading the mms_config.xml
|
||||
final Context subContext = getSubDepContext(mContext, subId);
|
||||
// Load and parse the XML
|
||||
XmlResourceParser parser = null;
|
||||
try {
|
||||
parser = subContext.getResources().getXml(R.xml.mms_config);
|
||||
try (XmlResourceParser parser = subContext.getResources().getXml(R.xml.mms_config)) {
|
||||
final ApnsXmlProcessor processor = ApnsXmlProcessor.get(parser);
|
||||
processor.setMmsConfigHandler((mccMnc, key, value, type) ->
|
||||
update(values, type, key, value));
|
||||
processor.process();
|
||||
} catch (final Resources.NotFoundException e) {
|
||||
LogUtil.w(LogUtil.BUGLE_TAG, "Can not find mms_config.xml");
|
||||
} finally {
|
||||
if (parser != null) {
|
||||
parser.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -196,15 +197,13 @@ public class MmsSmsUtils {
|
||||
final Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(),
|
||||
uri, ID_PROJECTION, null, null, null);
|
||||
if (cursor != null) {
|
||||
try {
|
||||
try (cursor) {
|
||||
if (cursor.moveToFirst()) {
|
||||
return cursor.getLong(0);
|
||||
} else {
|
||||
LogUtil.e(LogUtil.BUGLE_DATAMODEL_TAG,
|
||||
"getOrCreateThreadId returned no rows!");
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -748,14 +748,12 @@ public class MmsUtils {
|
||||
ALL_THREADS_URI,
|
||||
RECIPIENTS_PROJECTION, "_id=?", new String[] { String.valueOf(threadId) }, null);
|
||||
if (thread != null) {
|
||||
try {
|
||||
try (thread) {
|
||||
if (thread.moveToFirst()) {
|
||||
// recipientIds will be a space-separated list of ids into the
|
||||
// canonical addresses table.
|
||||
return thread.getString(RECIPIENT_IDS);
|
||||
}
|
||||
} finally {
|
||||
thread.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -1520,18 +1518,12 @@ public class MmsUtils {
|
||||
final SQLiteDatabase database = ApnDatabase.getApnDatabase().getWritableDatabase();
|
||||
|
||||
// Do we already have the table?
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = database.query(ApnDatabase.APN_TABLE,
|
||||
try (Cursor cursor = database.query(ApnDatabase.APN_TABLE,
|
||||
ApnDatabase.APN_PROJECTION,
|
||||
null, null, null, null, null, null);
|
||||
null, null, null, null, null, null)) {
|
||||
} catch (final Exception e) {
|
||||
// Apparently there's no table, create it now.
|
||||
ApnDatabase.forceBuildAndLoadApnTables();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
sUseSystemApn = turnOn;
|
||||
@@ -1626,12 +1618,10 @@ public class MmsUtils {
|
||||
null/*selectionArgs*/,
|
||||
null/*sortOrder*/);
|
||||
if (cursor != null) {
|
||||
try {
|
||||
try (cursor) {
|
||||
if (cursor.moveToFirst()) {
|
||||
return DatabaseMessages.MmsAddr.get(cursor);
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -2033,12 +2023,10 @@ public class MmsUtils {
|
||||
new String(rawTransactionId)
|
||||
};
|
||||
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = SqliteWrapper.query(
|
||||
try (Cursor cursor = SqliteWrapper.query(
|
||||
context, context.getContentResolver(),
|
||||
Mms.CONTENT_URI, new String[]{Mms._ID},
|
||||
selection, selectionArgs, null);
|
||||
selection, selectionArgs, null)) {
|
||||
final int dupCount = cursor.getCount();
|
||||
if (dupCount > 0) {
|
||||
// We already received the same notification before.
|
||||
@@ -2052,8 +2040,6 @@ public class MmsUtils {
|
||||
}
|
||||
} catch (final SQLiteException e) {
|
||||
LogUtil.e(TAG, "query failure: " + e, e);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -2503,12 +2489,9 @@ public class MmsUtils {
|
||||
if (dumpFile != null) {
|
||||
try {
|
||||
final FileOutputStream fos = new FileOutputStream(dumpFile);
|
||||
final BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
try {
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(fos)) {
|
||||
bos.write(rawPdu);
|
||||
bos.flush();
|
||||
} finally {
|
||||
bos.close();
|
||||
}
|
||||
DebugUtils.ensureReadable(dumpFile);
|
||||
} catch (final IOException e) {
|
||||
|
||||
@@ -166,7 +166,7 @@ public final class ContactRecipientAdapter extends BaseRecipientAdapter {
|
||||
cursorResult.enterpriseCursor};
|
||||
for (Cursor cursor : cursors) {
|
||||
if (cursor != null) {
|
||||
try {
|
||||
try (cursor) {
|
||||
final List<RecipientEntry> tempEntries = new ArrayList<>();
|
||||
HashSet<Long> existingContactIds = new HashSet<>();
|
||||
while (cursor.moveToNext()) {
|
||||
@@ -185,8 +185,6 @@ public final class ContactRecipientAdapter extends BaseRecipientAdapter {
|
||||
Collections.sort(tempEntries, mComparator);
|
||||
}
|
||||
entries.addAll(tempEntries);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -445,17 +446,11 @@ public class ContactUtil {
|
||||
return null;
|
||||
}
|
||||
String firstName = null;
|
||||
Cursor nameCursor = null;
|
||||
try {
|
||||
nameCursor = ContactUtil.lookupStructuredName(context, contactId, true)
|
||||
.performSynchronousQuery();
|
||||
try (Cursor nameCursor = ContactUtil.lookupStructuredName(context, contactId, true)
|
||||
.performSynchronousQuery()) {
|
||||
if (nameCursor != null && nameCursor.moveToFirst()) {
|
||||
firstName = nameCursor.getString(ContactUtil.INDEX_STRUCTURED_NAME_GIVEN_NAME);
|
||||
}
|
||||
} finally {
|
||||
if (nameCursor != null) {
|
||||
nameCursor.close();
|
||||
}
|
||||
}
|
||||
return firstName;
|
||||
}
|
||||
|
||||
@@ -56,15 +56,12 @@ public class DebugUtils {
|
||||
final File inputFile = getDebugFile(dumpFileName, false);
|
||||
if (inputFile != null) {
|
||||
final FileInputStream fis = new FileInputStream(inputFile);
|
||||
final BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
try {
|
||||
try (BufferedInputStream bis = new BufferedInputStream(fis)) {
|
||||
// dump file
|
||||
data = ByteStreams.toByteArray(bis);
|
||||
if (data == null || data.length < 1) {
|
||||
LogUtil.e(LogUtil.BUGLE_TAG, "receiveFromDumpFile: empty data");
|
||||
}
|
||||
} finally {
|
||||
bis.close();
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
|
||||
@@ -222,18 +222,12 @@ public class ImageUtils {
|
||||
public static String getContentType(final ContentResolver cr, final Uri uri) {
|
||||
// Figure out the content type of media.
|
||||
String contentType = null;
|
||||
Cursor cursor = null;
|
||||
if (UriUtil.isMediaStoreUri(uri)) {
|
||||
try {
|
||||
cursor = cr.query(uri, MEDIA_CONTENT_PROJECTION, null, null, null);
|
||||
try (Cursor cursor = cr.query(uri, MEDIA_CONTENT_PROJECTION, null, null, null)) {
|
||||
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
contentType = cursor.getString(INDEX_CONTENT_TYPE);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (contentType == null) {
|
||||
@@ -315,7 +309,7 @@ public class ImageUtils {
|
||||
*/
|
||||
public static boolean isGif(InputStream inputStream) {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
try (inputStream) {
|
||||
byte[] gifHeaderBytes = new byte[6];
|
||||
int value = inputStream.read(gifHeaderBytes, 0, 6);
|
||||
if (value == 6) {
|
||||
@@ -324,12 +318,6 @@ public class ImageUtils {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -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.
|
||||
@@ -37,17 +38,14 @@ public class MediaMetadataRetrieverWrapper {
|
||||
|
||||
public void setDataSource(Uri uri) throws IOException {
|
||||
ContentResolver resolver = Factory.get().getApplicationContext().getContentResolver();
|
||||
AssetFileDescriptor fd = resolver.openAssetFileDescriptor(uri, "r");
|
||||
try (AssetFileDescriptor fd = resolver.openAssetFileDescriptor(uri, "r")) {
|
||||
if (fd == null) {
|
||||
throw new IOException("openAssetFileDescriptor returned null for " + uri);
|
||||
}
|
||||
try {
|
||||
mRetriever.setDataSource(fd.getFileDescriptor());
|
||||
} catch (RuntimeException e) {
|
||||
release();
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
fd.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -155,22 +156,14 @@ public class UriUtil {
|
||||
public static long getContentSize(final Uri uri) {
|
||||
Assert.isNotMainThread();
|
||||
if (isLocalResourceUri(uri)) {
|
||||
ParcelFileDescriptor pfd = null;
|
||||
try {
|
||||
pfd = Factory.get().getApplicationContext()
|
||||
.getContentResolver().openFileDescriptor(uri, "r");
|
||||
try (ParcelFileDescriptor pfd = Factory.get().getApplicationContext()
|
||||
.getContentResolver().openFileDescriptor(uri, "r")) {
|
||||
return Math.max(pfd.getStatSize(), 0);
|
||||
} catch (final FileNotFoundException e) {
|
||||
LogUtil.e(LogUtil.BUGLE_TAG, "Error getting content size", e);
|
||||
} finally {
|
||||
if (pfd != null) {
|
||||
try {
|
||||
pfd.close();
|
||||
} catch (final IOException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Assert.fail("Unsupported uri type!");
|
||||
}
|
||||
|
||||
@@ -270,23 +270,18 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
|
||||
return null;
|
||||
}
|
||||
final Uri uri = MessagingContentProvider.buildConversationMetadataUri(conversationId);
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri,
|
||||
try (Cursor cursor = context.getContentResolver().query(uri,
|
||||
ConversationListItemData.PROJECTION,
|
||||
null, // selection
|
||||
null, // selection args
|
||||
null); // sort order
|
||||
null // sort order
|
||||
)) {
|
||||
if (cursor != null && cursor.getCount() > 0) {
|
||||
final ConversationListItemData conv = new ConversationListItemData();
|
||||
cursor.moveToFirst();
|
||||
conv.bind(cursor);
|
||||
return conv;
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user