Added KEY_VONR_ENABLED_BOOL to obtain VoNR availability status

Bug: 205809218
Test: atest NrAdvancedCallingPreferenceControllerTest
Change-Id: I45ac1e95d669801c2d37f49943d7c16cfb7adae3
diff --git a/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java b/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java
index 7615fe3..b585ece 100644
--- a/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java
@@ -46,6 +46,7 @@
     Preference mPreference;
     private TelephonyManager mTelephonyManager;
     private PhoneCallStateTelephonyCallback mTelephonyCallback;
+    private boolean mIsVonrEnabledFromCarrierConfig = false;
     private boolean mIsVonrVisibleFromCarrierConfig = false;
     private boolean mIsNrEnableFromCarrierConfig = false;
     private boolean mHas5gCapability = false;
@@ -83,6 +84,9 @@
         if (carrierConfig == null) {
             return this;
         }
+        mIsVonrEnabledFromCarrierConfig = carrierConfig.getBoolean(
+            CarrierConfigManager.KEY_VONR_ENABLED_BOOL);
+
         mIsVonrVisibleFromCarrierConfig = carrierConfig.getBoolean(
                 CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL);
 
@@ -92,6 +96,7 @@
 
         Log.d(TAG, "mHas5gCapability: " + mHas5gCapability
                 + ",mIsNrEnabledFromCarrierConfig: " + mIsNrEnableFromCarrierConfig
+                + ",mIsVonrEnabledFromCarrierConfig: " + mIsVonrEnabledFromCarrierConfig
                 + ",mIsVonrVisibleFromCarrierConfig: " + mIsVonrVisibleFromCarrierConfig);
         return this;
     }
@@ -100,7 +105,10 @@
     public int getAvailabilityStatus(int subId) {
         init(subId);
 
-        if (mHas5gCapability && mIsNrEnableFromCarrierConfig && mIsVonrVisibleFromCarrierConfig) {
+        if (mHas5gCapability
+                && mIsNrEnableFromCarrierConfig
+                && mIsVonrEnabledFromCarrierConfig
+                && mIsVonrVisibleFromCarrierConfig) {
             return AVAILABLE;
         }
         return CONDITIONALLY_UNAVAILABLE;
diff --git a/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
index 9eb67df..fac7772 100644
--- a/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
@@ -80,7 +80,8 @@
                 mTelephonyManager).setVoNrEnabled(anyBoolean());
         mCarrierConfig = new PersistableBundle();
         doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
-        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
         mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
                 new int[]{1, 2});
 
@@ -92,7 +93,8 @@
     }
 
     @Test
-    public void getAvailabilityStatus_vonrDisabled_returnUnavailable() {
+    public void getAvailabilityStatus_vonrEnabledAndVisibleDisable_returnUnavailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, true);
         mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
 
         mController.init(SUB_ID);
@@ -102,7 +104,30 @@
     }
 
     @Test
-    public void getAvailabilityStatus_vonrEnabled_returnAvailable() {
+    public void getAvailabilityStatus_vonrDisabledAndVisibleDisable_returnUnavailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
+
+        mController.init(SUB_ID);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(
+                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_vonrDisabledAndVisibleEnable_returnUnavailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
+
+        mController.init(SUB_ID);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(
+                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_vonrEnabledAndVisibleEnable_returnAvailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, true);
         mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
 
         mController.init(SUB_ID);