Messaging: Use try-with-resource
Change-Id: I6649517cbd990502dfcb54f078764cf05f210268
This commit is contained in:
@@ -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,
|
||||
APN_FULL_PROJECTION, CURRENT_SELECTION,
|
||||
null/*selectionArgs*/,
|
||||
null/*groupBy*/, null/*having*/, null/*orderBy*/);
|
||||
try (Cursor cursor = db.query(APN_TABLE,
|
||||
APN_FULL_PROJECTION, CURRENT_SELECTION,
|
||||
null/*selectionArgs*/,
|
||||
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,
|
||||
ID_PROJECTION,
|
||||
selectionBuilder.toString(),
|
||||
selectionArgs.toArray(new String[0]),
|
||||
null/*groupBy*/, null/*having*/, null/*orderBy*/);
|
||||
try (Cursor cursor = db.query(APN_TABLE,
|
||||
ID_PROJECTION,
|
||||
selectionBuilder.toString(),
|
||||
selectionArgs.toArray(new String[0]),
|
||||
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,
|
||||
ApnDatabase.APN_PROJECTION,
|
||||
null, null, null, null, null, null);
|
||||
try (Cursor cursor = database.query(ApnDatabase.APN_TABLE,
|
||||
ApnDatabase.APN_PROJECTION,
|
||||
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(
|
||||
context, context.getContentResolver(),
|
||||
Mms.CONTENT_URI, new String[] { Mms._ID },
|
||||
selection, selectionArgs, null);
|
||||
try (Cursor cursor = SqliteWrapper.query(
|
||||
context, context.getContentResolver(),
|
||||
Mms.CONTENT_URI, new String[]{Mms._ID},
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user