1 /* 2 * Copyright (C) 2006 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.uicc; 18 19 import android.os.Environment; 20 import android.util.Xml; 21 import android.telephony.Rlog; 22 23 import java.util.HashMap; 24 import java.io.FileReader; 25 import java.io.File; 26 import java.io.FileNotFoundException; 27 import java.io.IOException; 28 29 import org.xmlpull.v1.XmlPullParser; 30 import org.xmlpull.v1.XmlPullParserException; 31 32 import com.android.internal.util.XmlUtils; 33 34 /** 35 * {@hide} 36 */ 37 class VoiceMailConstants { 38 private HashMap<String, String[]> CarrierVmMap; 39 40 41 static final String LOG_TAG = "VoiceMailConstants"; 42 static final String PARTNER_VOICEMAIL_PATH ="etc/voicemail-conf.xml"; 43 44 static final int NAME = 0; 45 static final int NUMBER = 1; 46 static final int TAG = 2; 47 static final int SIZE = 3; 48 VoiceMailConstants()49 VoiceMailConstants () { 50 CarrierVmMap = new HashMap<String, String[]>(); 51 loadVoiceMail(); 52 } 53 containsCarrier(String carrier)54 boolean containsCarrier(String carrier) { 55 return CarrierVmMap.containsKey(carrier); 56 } 57 getCarrierName(String carrier)58 String getCarrierName(String carrier) { 59 String[] data = CarrierVmMap.get(carrier); 60 return data[NAME]; 61 } 62 getVoiceMailNumber(String carrier)63 String getVoiceMailNumber(String carrier) { 64 String[] data = CarrierVmMap.get(carrier); 65 return data[NUMBER]; 66 } 67 getVoiceMailTag(String carrier)68 String getVoiceMailTag(String carrier) { 69 String[] data = CarrierVmMap.get(carrier); 70 return data[TAG]; 71 } 72 loadVoiceMail()73 private void loadVoiceMail() { 74 FileReader vmReader; 75 76 final File vmFile = new File(Environment.getRootDirectory(), 77 PARTNER_VOICEMAIL_PATH); 78 79 try { 80 vmReader = new FileReader(vmFile); 81 } catch (FileNotFoundException e) { 82 Rlog.w(LOG_TAG, "Can't open " + 83 Environment.getRootDirectory() + "/" + PARTNER_VOICEMAIL_PATH); 84 return; 85 } 86 87 try { 88 XmlPullParser parser = Xml.newPullParser(); 89 parser.setInput(vmReader); 90 91 XmlUtils.beginDocument(parser, "voicemail"); 92 93 while (true) { 94 XmlUtils.nextElement(parser); 95 96 String name = parser.getName(); 97 if (!"voicemail".equals(name)) { 98 break; 99 } 100 101 String[] data = new String[SIZE]; 102 String numeric = parser.getAttributeValue(null, "numeric"); 103 data[NAME] = parser.getAttributeValue(null, "carrier"); 104 data[NUMBER] = parser.getAttributeValue(null, "vmnumber"); 105 data[TAG] = parser.getAttributeValue(null, "vmtag"); 106 107 CarrierVmMap.put(numeric, data); 108 } 109 } catch (XmlPullParserException e) { 110 Rlog.w(LOG_TAG, "Exception in Voicemail parser " + e); 111 } catch (IOException e) { 112 Rlog.w(LOG_TAG, "Exception in Voicemail parser " + e); 113 } finally { 114 try { 115 if (vmReader != null) { 116 vmReader.close(); 117 } 118 } catch (IOException e) {} 119 } 120 } 121 } 122