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 18 package com.android.phone.vvm.omtp; 19 20 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_CARRIER_VVM_PACKAGE_NAME_STRING; 21 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY; 22 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_CELLULAR_DATA_REQUIRED_BOOL; 23 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_DESTINATION_NUMBER_STRING; 24 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_DISABLED_CAPABILITIES_STRING_ARRAY; 25 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_PORT_NUMBER_INT; 26 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_PREFETCH_BOOL; 27 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_SSL_PORT_NUMBER_INT; 28 import static com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper.KEY_VVM_TYPE_STRING; 29 30 import android.os.PersistableBundle; 31 import android.test.AndroidTestCase; 32 33 import java.util.Arrays; 34 import java.util.HashSet; 35 import java.util.Set; 36 37 public class OmtpVvmCarrierConfigHelperTest extends AndroidTestCase { 38 39 private static final String CARRIER_TYPE = "omtp.carrier"; 40 private static final String CARRIER_PACKAGE_NAME = "omtp.carrier.package"; 41 private static final boolean CARRIER_CELLULAR_REQUIRED = false; 42 private static final boolean CARRIER_PREFETCH = true; 43 private static final String CARRIER_DESTINATION_NUMBER = "123"; 44 private static final int CARRIER_APPLICATION_PORT = 456; 45 private static final int DEFAULT_SSL_PORT = 0; 46 private static final Set<String> DEFAULT_DISABLED_CAPABILITIES = null; 47 48 private static final String TELEPHONY_TYPE = "omtp.telephony"; 49 private static final String[] TELEPHONY_PACKAGE_NAMES = {"omtp.telephony.package"}; 50 private static final boolean TELEPHONY_CELLULAR_REQUIRED = true; 51 private static final boolean TELEPHONY_PREFETCH = false; 52 private static final String TELEPHONY_DESTINATION_NUMBER = "321"; 53 private static final int TELEPHONY_APPLICATION_PORT = 654; 54 private static final int TELEPHONY_SSL_PORT = 997; 55 private static final String[] TELEPHONY_DISABLED_CAPABILITIES = {"foo"}; 56 57 private OmtpVvmCarrierConfigHelper mHelper; 58 59 public void testCarrierConfig() { 60 mHelper = new OmtpVvmCarrierConfigHelper(getContext(), createCarrierConfig(), null); 61 verifyCarrierConfig(); 62 verifyDefaultExtraConfig(); 63 } 64 65 public void testTelephonyConfig() { 66 mHelper = new OmtpVvmCarrierConfigHelper(getContext(), null, createTelephonyConfig()); 67 verifyTelephonyConfig(); 68 verifyTelephonyExtraConfig(); 69 } 70 71 public void testMixedConfig() { 72 mHelper = new OmtpVvmCarrierConfigHelper(getContext(), createCarrierConfig(), 73 createTelephonyConfig()); 74 verifyCarrierConfig(); 75 verifyTelephonyExtraConfig(); 76 } 77 78 private PersistableBundle createCarrierConfig() { 79 PersistableBundle bundle = new PersistableBundle(); 80 bundle.putString(KEY_VVM_TYPE_STRING, CARRIER_TYPE); 81 bundle.putString(KEY_CARRIER_VVM_PACKAGE_NAME_STRING, 82 CARRIER_PACKAGE_NAME); 83 bundle.putBoolean(KEY_VVM_CELLULAR_DATA_REQUIRED_BOOL, 84 CARRIER_CELLULAR_REQUIRED); 85 bundle.putBoolean(KEY_VVM_PREFETCH_BOOL, 86 CARRIER_PREFETCH); 87 bundle.putString(KEY_VVM_DESTINATION_NUMBER_STRING, 88 CARRIER_DESTINATION_NUMBER); 89 bundle.putInt(KEY_VVM_PORT_NUMBER_INT, CARRIER_APPLICATION_PORT); 90 return bundle; 91 } 92 93 private void verifyCarrierConfig() { 94 assertEquals(CARRIER_TYPE, mHelper.getVvmType()); 95 assertEquals(new HashSet<>(Arrays.asList(CARRIER_PACKAGE_NAME)), 96 mHelper.getCarrierVvmPackageNames()); 97 assertEquals(CARRIER_CELLULAR_REQUIRED, mHelper.isCellularDataRequired()); 98 assertEquals(CARRIER_PREFETCH, mHelper.isPrefetchEnabled()); 99 assertEquals(CARRIER_APPLICATION_PORT, mHelper.getApplicationPort()); 100 assertEquals(CARRIER_DESTINATION_NUMBER, mHelper.getDestinationNumber()); 101 } 102 103 104 private void verifyDefaultExtraConfig() { 105 assertEquals(DEFAULT_SSL_PORT, mHelper.getSslPort()); 106 assertEquals(DEFAULT_DISABLED_CAPABILITIES, mHelper.getDisabledCapabilities()); 107 } 108 109 110 private PersistableBundle createTelephonyConfig() { 111 PersistableBundle bundle = new PersistableBundle(); 112 bundle.putString(KEY_VVM_TYPE_STRING, TELEPHONY_TYPE); 113 bundle.putStringArray(KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY, 114 TELEPHONY_PACKAGE_NAMES); 115 bundle.putBoolean(KEY_VVM_CELLULAR_DATA_REQUIRED_BOOL, 116 TELEPHONY_CELLULAR_REQUIRED); 117 bundle.putBoolean(KEY_VVM_PREFETCH_BOOL, 118 TELEPHONY_PREFETCH); 119 bundle.putString(KEY_VVM_DESTINATION_NUMBER_STRING, 120 TELEPHONY_DESTINATION_NUMBER); 121 bundle.putInt(KEY_VVM_PORT_NUMBER_INT, TELEPHONY_APPLICATION_PORT); 122 bundle.putInt(KEY_VVM_SSL_PORT_NUMBER_INT, TELEPHONY_SSL_PORT); 123 bundle.putStringArray(KEY_VVM_DISABLED_CAPABILITIES_STRING_ARRAY, 124 TELEPHONY_DISABLED_CAPABILITIES); 125 return bundle; 126 } 127 128 private void verifyTelephonyConfig() { 129 assertEquals(TELEPHONY_TYPE, mHelper.getVvmType()); 130 assertEquals(new HashSet<>(Arrays.asList(TELEPHONY_PACKAGE_NAMES)), 131 mHelper.getCarrierVvmPackageNames()); 132 assertEquals(TELEPHONY_CELLULAR_REQUIRED, mHelper.isCellularDataRequired()); 133 assertEquals(TELEPHONY_PREFETCH, mHelper.isPrefetchEnabled()); 134 assertEquals(TELEPHONY_APPLICATION_PORT, mHelper.getApplicationPort()); 135 assertEquals(TELEPHONY_DESTINATION_NUMBER, mHelper.getDestinationNumber()); 136 } 137 138 private void verifyTelephonyExtraConfig() { 139 assertEquals(TELEPHONY_SSL_PORT, mHelper.getSslPort()); 140 assertEquals(new HashSet<>(Arrays.asList(TELEPHONY_DISABLED_CAPABILITIES)), 141 mHelper.getDisabledCapabilities()); 142 } 143 } 144