1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony.gsm; 18 19 import java.io.File; 20 import java.io.FileNotFoundException; 21 import java.io.FileReader; 22 import java.io.IOException; 23 import java.util.HashMap; 24 25 import org.xmlpull.v1.XmlPullParser; 26 import org.xmlpull.v1.XmlPullParserException; 27 28 import android.os.Environment; 29 import android.util.Log; 30 import android.util.Xml; 31 32 import com.android.internal.util.XmlUtils; 33 34 public class SpnOverride { 35 private HashMap<String, String> CarrierSpnMap; 36 37 38 static final String LOG_TAG = "GSM"; 39 static final String PARTNER_SPN_OVERRIDE_PATH ="etc/spn-conf.xml"; 40 41 SpnOverride () { 42 CarrierSpnMap = new HashMap<String, String>(); 43 loadSpnOverrides(); 44 } 45 46 boolean containsCarrier(String carrier) { 47 return CarrierSpnMap.containsKey(carrier); 48 } 49 50 String getSpn(String carrier) { 51 return CarrierSpnMap.get(carrier); 52 } 53 54 private void loadSpnOverrides() { 55 FileReader spnReader; 56 57 final File spnFile = new File(Environment.getRootDirectory(), 58 PARTNER_SPN_OVERRIDE_PATH); 59 60 try { 61 spnReader = new FileReader(spnFile); 62 } catch (FileNotFoundException e) { 63 Log.w(LOG_TAG, "Can't open " + 64 Environment.getRootDirectory() + "/" + PARTNER_SPN_OVERRIDE_PATH); 65 return; 66 } 67 68 try { 69 XmlPullParser parser = Xml.newPullParser(); 70 parser.setInput(spnReader); 71 72 XmlUtils.beginDocument(parser, "spnOverrides"); 73 74 while (true) { 75 XmlUtils.nextElement(parser); 76 77 String name = parser.getName(); 78 if (!"spnOverride".equals(name)) { 79 break; 80 } 81 82 String numeric = parser.getAttributeValue(null, "numeric"); 83 String data = parser.getAttributeValue(null, "spn"); 84 85 CarrierSpnMap.put(numeric, data); 86 } 87 } catch (XmlPullParserException e) { 88 Log.w(LOG_TAG, "Exception in spn-conf parser " + e); 89 } catch (IOException e) { 90 Log.w(LOG_TAG, "Exception in spn-conf parser " + e); 91 } 92 } 93 94 } 95