1 /* 2 * Copyright (C) 2021 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.imsserviceentitlement.utils; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.ArgumentMatchers.eq; 22 import static org.mockito.Mockito.verify; 23 24 import android.content.Context; 25 import android.os.PersistableBundle; 26 import android.telephony.CarrierConfigManager; 27 import android.telephony.SubscriptionManager; 28 import android.telephony.ims.ImsMmTelManager; 29 import android.telephony.ims.ProvisioningManager; 30 31 import androidx.test.core.app.ApplicationProvider; 32 import androidx.test.runner.AndroidJUnit4; 33 34 import org.junit.Rule; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.mockito.Mock; 38 import org.mockito.junit.MockitoJUnit; 39 import org.mockito.junit.MockitoRule; 40 41 @RunWith(AndroidJUnit4.class) 42 public class ImsUtilsTest { 43 @Rule public final MockitoRule rule = MockitoJUnit.rule(); 44 45 @Mock CarrierConfigManager mMockCarrierConfigManager; 46 @Mock ImsMmTelManager mMockImsMmTelManager; 47 @Mock ProvisioningManager mMockProvisioningManager; 48 49 private Context mContext = ApplicationProvider.getApplicationContext(); 50 51 @Test isWfcEnabledByUser_invalidSubId_defaultValues()52 public void isWfcEnabledByUser_invalidSubId_defaultValues() { 53 ImsUtils imsUtils = 54 ImsUtils.getInstance(mContext, SubscriptionManager.INVALID_SUBSCRIPTION_ID); 55 56 assertThat(imsUtils.isWfcEnabledByUser()).isFalse(); 57 } 58 59 @Test disableAndResetVoWiFiImsSettings_hasCarrierConfig()60 public void disableAndResetVoWiFiImsSettings_hasCarrierConfig() { 61 PersistableBundle carrierConfig = new PersistableBundle(); 62 carrierConfig.putInt(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT, 1); 63 carrierConfig.putInt(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_MODE_INT, 2); 64 ImsUtils imsUtils = 65 new ImsUtils(carrierConfig, mMockImsMmTelManager, mMockProvisioningManager); 66 67 imsUtils.disableAndResetVoWiFiImsSettings(); 68 69 verify(mMockImsMmTelManager).setVoWiFiSettingEnabled(eq(false)); 70 verify(mMockImsMmTelManager).setVoWiFiModeSetting(eq(1)); 71 verify(mMockImsMmTelManager).setVoWiFiRoamingModeSetting(eq(2)); 72 } 73 74 @Test disableWfc()75 public void disableWfc() { 76 ImsUtils imsUtils = new ImsUtils( 77 new PersistableBundle(), mMockImsMmTelManager, mMockProvisioningManager); 78 79 imsUtils.disableWfc(); 80 81 verify(mMockImsMmTelManager).setVoWiFiSettingEnabled(false); 82 } 83 } 84