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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user