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