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