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