1 /* 2 * Copyright (C) 2016 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.phone.vvm.omtp; 18 19 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY; 20 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_CELLULAR_DATA_REQUIRED_BOOL; 21 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_DESTINATION_NUMBER_STRING; 22 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_DISABLED_CAPABILITIES_STRING_ARRAY; 23 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_PORT_NUMBER_INT; 24 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_PREFETCH_BOOL; 25 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_SSL_PORT_NUMBER_INT; 26 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_TYPE_STRING; 27 28 import android.os.PersistableBundle; 29 30 import junit.framework.TestCase; 31 32 import org.xmlpull.v1.XmlPullParser; 33 import org.xmlpull.v1.XmlPullParserException; 34 import org.xmlpull.v1.XmlPullParserFactory; 35 36 import java.io.StringReader; 37 import java.util.Arrays; 38 39 public class TelephonyVvmConfigManagerTest extends TestCase { 40 41 private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 42 + "<list name=\"carrier_config_list\">\n"; 43 private static final String XML_FOOTER = "</list>"; 44 45 private static final String CARRIER = " <pbundle_as_map>\n" 46 + " <string-array name=\"mccmnc\">\n" 47 + " <item value=\"12345\"/>\n" 48 + " <item value=\"67890\"/>\n" 49 + " </string-array>\n" 50 + " <int name=\"vvm_port_number_int\" value=\"54321\"/>\n" 51 + " <string name=\"vvm_destination_number_string\">11111</string>\n" 52 + " <string-array name=\"carrier_vvm_package_name_string_array\">\n" 53 + " <item value=\"com.android.phone\"/>\n" 54 + " </string-array>\n" 55 + " <string name=\"vvm_type_string\">vvm_type_omtp</string>\n" 56 + " <boolean name=\"vvm_cellular_data_required\" value=\"true\"/>\n" 57 + " <boolean name=\"vvm_prefetch\" value=\"true\"/>\n" 58 + " <int name=\"vvm_ssl_port_number_int\" value=\"997\"/>\n" 59 + " <string-array name=\"vvm_disabled_capabilities_string_array\">\n" 60 + " <item value =\"foo\"/>\n" 61 + " <item value =\"bar\"/>\n" 62 + " </string-array>\n" 63 + " </pbundle_as_map>\n"; 64 65 private static final String CARRIER_EMPTY = "<pbundle_as_map></pbundle_as_map>\n"; 66 67 68 public void testLoadConfigFromXml() { 69 TelephonyVvmConfigManager manager = createManager(XML_HEADER + CARRIER + XML_FOOTER); 70 verifyCarrier(manager.getConfig("12345")); 71 verifyCarrier(manager.getConfig("67890")); 72 } 73 74 public void testLoadConfigFromXml_Multiple() { 75 TelephonyVvmConfigManager manager = 76 createManager(XML_HEADER + CARRIER + CARRIER + XML_FOOTER); 77 verifyCarrier(manager.getConfig("12345")); 78 verifyCarrier(manager.getConfig("67890")); 79 } 80 81 public void testLoadConfigFromXml_Empty() { 82 createManager(XML_HEADER + CARRIER_EMPTY + XML_FOOTER); 83 } 84 85 86 private void verifyCarrier(PersistableBundle config) { 87 assertTrue(Arrays.equals(new String[]{"12345", "67890"}, 88 config.getStringArray(TelephonyVvmConfigManager.KEY_MCCMNC))); 89 assertEquals(54321, config.getInt(KEY_VVM_PORT_NUMBER_INT)); 90 assertEquals("11111", config.getString(KEY_VVM_DESTINATION_NUMBER_STRING)); 91 assertTrue(Arrays.equals(new String[]{"com.android.phone"}, 92 config.getStringArray(KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY))); 93 assertEquals("vvm_type_omtp", config.getString(KEY_VVM_TYPE_STRING)); 94 assertEquals(true, config.getBoolean(KEY_VVM_PREFETCH_BOOL)); 95 assertEquals(true, config.getBoolean(KEY_VVM_CELLULAR_DATA_REQUIRED_BOOL)); 96 assertEquals(997, config.getInt(KEY_VVM_SSL_PORT_NUMBER_INT)); 97 assertTrue(Arrays.equals(new String[]{"foo", "bar"}, 98 config.getStringArray(KEY_VVM_DISABLED_CAPABILITIES_STRING_ARRAY))); 99 } 100 101 private TelephonyVvmConfigManager createManager(String xml) { 102 try { 103 XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); 104 parser.setInput(new StringReader(xml)); 105 return new TelephonyVvmConfigManager(parser); 106 } catch (XmlPullParserException e) { 107 throw new RuntimeException(e); 108 } 109 } 110 111 } 112