1 /* 2 * Copyright (C) 2015 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 android.telecom.cts; 18 19 import static android.telecom.cts.TestUtils.ACCOUNT_ID_1; 20 import static android.telecom.cts.TestUtils.ACCOUNT_LABEL; 21 import static android.telecom.cts.TestUtils.COMPONENT; 22 import static android.telecom.cts.TestUtils.PACKAGE; 23 24 import android.content.ComponentName; 25 import android.content.Context; 26 import android.graphics.Color; 27 import android.net.Uri; 28 import android.os.PersistableBundle; 29 import android.telecom.PhoneAccount; 30 import android.telecom.PhoneAccountHandle; 31 import android.telecom.TelecomManager; 32 import android.telephony.CarrierConfigManager; 33 import android.telephony.SubscriptionManager; 34 import android.test.InstrumentationTestCase; 35 import android.text.TextUtils; 36 37 import java.util.Arrays; 38 39 /** 40 * Verifies the behavior of TelecomManager.getSimCallManager() with respect to the default dialer 41 */ 42 public class SimCallManagerTest extends InstrumentationTestCase { 43 public static final PhoneAccountHandle TEST_PHONE_ACCOUNT_HANDLE = 44 new PhoneAccountHandle(new ComponentName(PACKAGE, COMPONENT), ACCOUNT_ID_1); 45 46 public static final PhoneAccount TEST_SIM_CALL_MANAGER_ACCOUNT = PhoneAccount.builder( 47 TEST_PHONE_ACCOUNT_HANDLE, ACCOUNT_LABEL) 48 .setAddress(Uri.parse("tel:555-TEST")) 49 .setSubscriptionAddress(Uri.parse("tel:555-TEST")) 50 .setCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER) 51 .setHighlightColor(Color.RED) 52 .setShortDescription(ACCOUNT_LABEL) 53 .setSupportedUriSchemes(Arrays.asList("tel")) 54 .build(); 55 56 private Context mContext; 57 private TelecomManager mTelecomManager; 58 private String mPreviousDefaultDialer = null; 59 private String mSystemDialer = null; 60 61 @Override setUp()62 protected void setUp() throws Exception { 63 super.setUp(); 64 mContext = getInstrumentation().getContext(); 65 66 if (!TestUtils.shouldTestTelecom(mContext)) { 67 return; 68 } 69 mPreviousDefaultDialer = TestUtils.getDefaultDialer(getInstrumentation()); 70 // Reset the current dialer to the system dialer, to ensure that we start each test 71 // without being the default dialer. 72 mSystemDialer = TestUtils.getSystemDialer(getInstrumentation()); 73 if (!TextUtils.isEmpty(mSystemDialer)) { 74 TestUtils.setDefaultDialer(getInstrumentation(), mSystemDialer); 75 } 76 mTelecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); 77 } 78 79 @Override tearDown()80 protected void tearDown() throws Exception { 81 if (!TextUtils.isEmpty(mPreviousDefaultDialer)) { 82 // Restore the default dialer to whatever the default dialer was before the tests 83 // were started. This may or may not be the system dialer. 84 TestUtils.setDefaultDialer(getInstrumentation(), mPreviousDefaultDialer); 85 } 86 super.tearDown(); 87 } 88 testGetSimCallManager()89 public void testGetSimCallManager() throws Exception { 90 if (!TestUtils.shouldTestTelecom(mContext)) { 91 return; 92 } 93 94 // By default, getSimCallManager should return either the carrier configured sim call 95 // manager or the system dialer's sim call manager. 96 assertEquals(mSystemDialer, mTelecomManager.getDefaultDialerPackage()); 97 assertNotSame(TEST_PHONE_ACCOUNT_HANDLE, mTelecomManager.getSimCallManager()); 98 99 ComponentName carrierConfigSimCallManager = null; 100 CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService( 101 Context.CARRIER_CONFIG_SERVICE); 102 PersistableBundle configBundle = configManager.getConfig(); 103 if (configBundle != null) { 104 final String componentString = configBundle.getString( 105 CarrierConfigManager.KEY_DEFAULT_SIM_CALL_MANAGER_STRING); 106 if (!TextUtils.isEmpty(componentString)) { 107 carrierConfigSimCallManager = ComponentName.unflattenFromString(componentString); 108 } 109 } 110 111 // If the default dialer has not registered a sim call manager, getSimCallManager should 112 // return the carrier configured sim call manager (which can be null). 113 PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager(); 114 TestUtils.setDefaultDialer(getInstrumentation(), TestUtils.PACKAGE); 115 assertEquals(TestUtils.PACKAGE, mTelecomManager.getDefaultDialerPackage()); 116 assertNotSame(TEST_PHONE_ACCOUNT_HANDLE, mTelecomManager.getSimCallManager()); 117 assertEquals("Sim call manager should be the carrier configured value if no default-dialer" 118 + " provided value", 119 carrierConfigSimCallManager, 120 simCallManager == null ? null : simCallManager.getComponentName()); 121 122 // Once the default dialer has registered a sim call manager, getSimCallManager should 123 // return the new sim call manager. 124 mTelecomManager.registerPhoneAccount(TEST_SIM_CALL_MANAGER_ACCOUNT); 125 assertEquals("Sim call manager should be default dialer's sim call manager if provided" 126 + " by default dialer", 127 TEST_PHONE_ACCOUNT_HANDLE, 128 mTelecomManager.getSimCallManager()); 129 130 // If the dialer is no longer the default dialer, it is no longer the sim call manager. 131 TestUtils.setDefaultDialer(getInstrumentation(), mSystemDialer); 132 assertNotSame(TEST_PHONE_ACCOUNT_HANDLE, mTelecomManager.getSimCallManager()); 133 } 134 testGetSimCallManagerForSub()135 public void testGetSimCallManagerForSub() { 136 if (!TestUtils.shouldTestTelecom(mContext)) { 137 return; 138 } 139 assertNull(mTelecomManager.getSimCallManagerForSubscription( 140 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)); 141 } 142 } 143