From 6c8cffb50a5e21cbadbf715a69a57c749ef2626f Mon Sep 17 00:00:00 2001 From: Jonathan Basseri Date: Tue, 23 Jun 2015 14:42:04 -0700 Subject: Read XML files as InputStream. Attempting to read XML files in assets/ with openXmlResourceParser was failing with FileNotFound because files in the assets folder are not precompiled into binary XML. Our only choice is to read them as regular text streams. Bug: 21618018 Change-Id: I463791ae4a1dd5f6a72433a114bd02e39cf5a943 --- .../carrierconfig/DefaultCarrierConfigService.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/com/android/carrierconfig/DefaultCarrierConfigService.java b/src/com/android/carrierconfig/DefaultCarrierConfigService.java index 9d61e1b..2317156 100644 --- a/src/com/android/carrierconfig/DefaultCarrierConfigService.java +++ b/src/com/android/carrierconfig/DefaultCarrierConfigService.java @@ -11,6 +11,7 @@ import android.util.Log; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlPullParserFactory; import java.io.File; import java.io.FileOutputStream; @@ -34,8 +35,11 @@ public class DefaultCarrierConfigService extends CarrierService { private static final String TAG = "DefaultCarrierConfigService"; + private XmlPullParserFactory mFactory; + public DefaultCarrierConfigService() { Log.d(TAG, "Service created"); + mFactory = null; } /** @@ -56,16 +60,21 @@ public class DefaultCarrierConfigService extends CarrierService { String fileName = "carrier_config_" + id.getMcc() + id.getMnc() + ".xml"; try { - XmlPullParser input = - getApplicationContext().getAssets().openXmlResourceParser(fileName); - PersistableBundle config = readConfigFromXml(input, id); + synchronized (this) { + if (mFactory == null) { + mFactory = XmlPullParserFactory.newInstance(); + } + } + XmlPullParser parser = mFactory.newPullParser(); + parser.setInput(getApplicationContext().getAssets().open(fileName), "utf-8"); + PersistableBundle config = readConfigFromXml(parser, id); // Treat vendor.xml as if it were appended to the carrier config file we read. XmlPullParser vendorInput = getApplicationContext().getResources().getXml(R.xml.vendor); PersistableBundle vendorConfig = readConfigFromXml(vendorInput, id); config.putAll(vendorConfig); return config; } - catch (IOException e) { + catch (IOException | XmlPullParserException e) { // Return null for unknown networks - they should use the defaults. Log.e(TAG, e.toString()); return null; -- cgit v1.2.3