Merge "[Settings] Refactor Wifi Calling description text"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ec4d8ef..0c33b04 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -141,7 +141,8 @@
         <activity android:name=".network.telephony.MobileNetworkActivity"
                   android:label="@string/network_settings_title"
                   android:exported="true"
-                  android:launchMode="singleTask">
+                  android:launchMode="singleTask"
+                  android:configChanges="orientation|screenSize|keyboardHidden">
             <intent-filter android:priority="1">
                 <!-- Displays the MobileNetworkActivity and opt-in dialog for capability discovery. -->
                 <action android:name="android.telephony.ims.action.SHOW_CAPABILITY_DISCOVERY_OPT_IN" />
diff --git a/res/layout/dialog_sim_status.xml b/res/layout/dialog_sim_status.xml
index 27d12a8..c169e58 100644
--- a/res/layout/dialog_sim_status.xml
+++ b/res/layout/dialog_sim_status.xml
@@ -166,6 +166,7 @@
             android:id="@+id/esim_id_value"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:textIsSelectable="true"
             android:text="@string/device_info_not_available"/>
 
         <TextView
diff --git a/src/com/android/settings/biometrics/OWNERS b/src/com/android/settings/biometrics/OWNERS
index 23eaf7e..99dd654 100644
--- a/src/com/android/settings/biometrics/OWNERS
+++ b/src/com/android/settings/biometrics/OWNERS
@@ -1,5 +1,6 @@
 # Default reviewers for this and subdirectories.
 curtislb@google.com
+graciecheng@google.com
 ilyamaty@google.com
 jaggies@google.com
 jbolinger@google.com
diff --git a/src/com/android/settings/development/BluetoothA2dpConfigStore.java b/src/com/android/settings/development/BluetoothA2dpConfigStore.java
index 0b154d2..7fd7b13 100644
--- a/src/com/android/settings/development/BluetoothA2dpConfigStore.java
+++ b/src/com/android/settings/development/BluetoothA2dpConfigStore.java
@@ -71,10 +71,16 @@
     }
 
     public BluetoothCodecConfig createCodecConfig() {
-        return new BluetoothCodecConfig(mCodecType, mCodecPriority,
-                mSampleRate, mBitsPerSample,
-                mChannelMode, mCodecSpecific1Value,
-                mCodecSpecific2Value, mCodecSpecific3Value,
-                mCodecSpecific4Value);
+        return new BluetoothCodecConfig.Builder()
+                .setCodecType(mCodecType)
+                .setCodecPriority(mCodecPriority)
+                .setSampleRate(mSampleRate)
+                .setBitsPerSample(mBitsPerSample)
+                .setChannelMode(mChannelMode)
+                .setCodecSpecific1(mCodecSpecific1Value)
+                .setCodecSpecific2(mCodecSpecific2Value)
+                .setCodecSpecific3(mCodecSpecific3Value)
+                .setCodecSpecific4(mCodecSpecific4Value)
+                .build();
     }
 }
diff --git a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
index 765c5f8..1af6e96 100644
--- a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
@@ -30,6 +30,8 @@
 import com.android.settings.development.BluetoothA2dpConfigStore;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
+import java.util.List;
+
 /**
  * Abstract class for Bluetooth A2DP config dialog controller in developer option.
  */
@@ -170,7 +172,7 @@
      *
      * @return Array of {@link BluetoothCodecConfig}.
      */
-    protected BluetoothCodecConfig[] getSelectableConfigs(BluetoothDevice device) {
+    protected List<BluetoothCodecConfig> getSelectableConfigs(BluetoothDevice device) {
         final BluetoothA2dp bluetoothA2dp = mBluetoothA2dp;
         if (bluetoothA2dp == null) {
             return null;
@@ -198,11 +200,7 @@
             Log.d(TAG, "Unable to get selectable config. No active device.");
             return null;
         }
-        final BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice);
-        if (configs == null) {
-            Log.d(TAG, "Unable to get selectable config. Selectable configs is empty.");
-            return null;
-        }
+        final List<BluetoothCodecConfig> configs = getSelectableConfigs(activeDevice);
         for (BluetoothCodecConfig config : configs) {
             if (config.getCodecType() == codecTypeValue) {
                 return config;
@@ -220,7 +218,7 @@
     public void onHDAudioEnabled(boolean enabled) {}
 
     static int getHighestCodec(BluetoothA2dp bluetoothA2dp, BluetoothDevice activeDevice,
-            BluetoothCodecConfig[] configs) {
+            List<BluetoothCodecConfig> configs) {
         if (configs == null) {
             Log.d(TAG, "Unable to get highest codec. Configs are empty");
             return BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
@@ -231,8 +229,8 @@
             return BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
         }
         for (int i = 0; i < CODEC_TYPES.length; i++) {
-            for (int j = 0; j < configs.length; j++) {
-                if ((configs[j].getCodecType() == CODEC_TYPES[i])) {
+            for (BluetoothCodecConfig config : configs) {
+                if (config.getCodecType() == CODEC_TYPES[i]) {
                     return CODEC_TYPES[i];
                 }
             }
diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
index b1b58e5..5f916f3 100644
--- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
@@ -77,7 +77,7 @@
         // Check HD audio is enabled, display the available list.
         if (bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
                 == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
-            BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice);
+            List<BluetoothCodecConfig> configs = getSelectableConfigs(activeDevice);
             if (configs != null) {
                 return getIndexFromConfig(configs);
             }
@@ -153,10 +153,10 @@
         writeConfigurationValues(/* index= */ 0);
     }
 
-    private List<Integer> getIndexFromConfig(BluetoothCodecConfig[] configs) {
+    private List<Integer> getIndexFromConfig(List<BluetoothCodecConfig> configs) {
         List<Integer> indexArray = new ArrayList<>();
-        for (int i = 0; i < configs.length; i++) {
-            indexArray.add(convertCfgToBtnIndex(configs[i].getCodecType()));
+        for (BluetoothCodecConfig config : configs) {
+            indexArray.add(convertCfgToBtnIndex(config.getCodecType()));
         }
         return indexArray;
     }
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index 25e0ae0..aa58663 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -23,9 +23,11 @@
 import android.os.PersistableBundle;
 import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyCallback;
 import android.telephony.TelephonyManager;
 import android.util.Log;
 
+import androidx.annotation.VisibleForTesting;
 import androidx.lifecycle.Lifecycle;
 import androidx.lifecycle.LifecycleObserver;
 import androidx.lifecycle.OnLifecycleEvent;
@@ -59,16 +61,25 @@
     private CarrierConfigManager mCarrierConfigManager;
     private PreferenceEntriesBuilder mBuilder;
     private SubscriptionsChangeListener mSubscriptionsListener;
+    private int mCallState = TelephonyManager.CALL_STATE_IDLE;
+    private PhoneCallStateTelephonyCallback mTelephonyCallback;
 
     public EnabledNetworkModePreferenceController(Context context, String key) {
         super(context, key);
         mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
         mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
+        if (mTelephonyCallback == null) {
+            mTelephonyCallback = new PhoneCallStateTelephonyCallback();
+        }
     }
 
     @Override
     public int getAvailabilityStatus(int subId) {
         boolean visible;
+        if (!isCallStateIdle()) {
+            return AVAILABLE_UNSEARCHABLE;
+        }
+
         final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
         if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
             visible = false;
@@ -87,23 +98,28 @@
 
         return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
     }
+    protected boolean isCallStateIdle() {
+        return mCallState == TelephonyManager.CALL_STATE_IDLE;
+    }
 
     @OnLifecycleEvent(ON_START)
     public void onStart() {
         mSubscriptionsListener.start();
-        if (mAllowedNetworkTypesListener == null) {
+        if (mAllowedNetworkTypesListener == null || mTelephonyCallback == null) {
             return;
         }
         mAllowedNetworkTypesListener.register(mContext, mSubId);
+        mTelephonyCallback.register(mTelephonyManager, mSubId);
     }
 
     @OnLifecycleEvent(ON_STOP)
     public void onStop() {
         mSubscriptionsListener.stop();
-        if (mAllowedNetworkTypesListener == null) {
+        if (mAllowedNetworkTypesListener == null || mTelephonyCallback == null) {
             return;
         }
         mAllowedNetworkTypesListener.unregister(mContext, mSubId);
+        mTelephonyCallback.unregister();
     }
 
     @Override
@@ -125,6 +141,7 @@
         listPreference.setEntryValues(mBuilder.getEntryValues());
         listPreference.setValue(Integer.toString(mBuilder.getSelectedEntryValue()));
         listPreference.setSummary(mBuilder.getSummary());
+        listPreference.setEnabled(isCallStateIdle());
     }
 
     @Override
@@ -157,7 +174,6 @@
                         updatePreference();
                     });
         }
-
         lifecycle.addObserver(this);
     }
 
@@ -828,6 +844,43 @@
 
     }
 
+    @VisibleForTesting
+    class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
+            TelephonyCallback.CallStateListener {
+
+        private TelephonyManager mTelephonyManager;
+
+        @Override
+        public void onCallStateChanged(int state) {
+            Log.d(LOG_TAG, "onCallStateChanged:" + state);
+            mCallState = state;
+            mBuilder.updateConfig();
+            updatePreference();
+        }
+
+        public void register(TelephonyManager telephonyManager, int subId) {
+            mTelephonyManager = telephonyManager;
+
+            // assign current call state so that it helps to show correct preference state even
+            // before first onCallStateChanged() by initial registration.
+            mCallState = mTelephonyManager.getCallState(subId);
+            mTelephonyManager.registerTelephonyCallback(
+                    mContext.getMainExecutor(), mTelephonyCallback);
+        }
+
+        public void unregister() {
+            mCallState = TelephonyManager.CALL_STATE_IDLE;
+            if (mTelephonyManager != null) {
+                mTelephonyManager.unregisterTelephonyCallback(this);
+            }
+        }
+    }
+
+    @VisibleForTesting
+    PhoneCallStateTelephonyCallback getTelephonyCallback() {
+        return mTelephonyCallback;
+    }
+
     @Override
     public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
     }
diff --git a/src/com/android/settings/password/OWNERS b/src/com/android/settings/password/OWNERS
index 636800f..3b2013b 100644
--- a/src/com/android/settings/password/OWNERS
+++ b/src/com/android/settings/password/OWNERS
@@ -1,5 +1,6 @@
 # Default reviewers for this and subdirectories.
 curtislb@google.com
+graciecheng@google.com
 ilyamaty@google.com
 jaggies@google.com
 jbolinger@google.com
@@ -8,4 +9,4 @@
 paulcrowley@google.com
 rubinxu@google.com
 
-# Emergency approvers in case the above are not available
\ No newline at end of file
+# Emergency approvers in case the above are not available
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
index a12131d..c1648bf 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
@@ -47,6 +47,7 @@
 import org.robolectric.RuntimeEnvironment;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
@@ -85,8 +86,12 @@
                 mBluetoothA2dpConfigStore));
         mPreference = spy(new BaseBluetoothDialogPreferenceImpl(mContext));
 
-        mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC);
-        mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC);
+        mCodecConfigAAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
+                .build();
+        mCodecConfigSBC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
+                .build();
         mCodecConfigs[0] = mCodecConfigAAC;
         mCodecConfigs[1] = mCodecConfigSBC;
 
@@ -160,17 +165,19 @@
 
     @Test
     public void getSelectableConfigs_verifyConfig() {
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(
             mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
 
-        assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs);
+        assertThat(mController.getSelectableConfigs(null)).isEqualTo(Arrays.asList(mCodecConfigs));
     }
 
     @Test
     public void getSelectableByCodecType_verifyConfig() {
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(
             mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
@@ -181,7 +188,8 @@
 
     @Test
     public void getSelectableByCodecType_unavailable() {
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(
             mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
@@ -192,7 +200,8 @@
 
     @Test
     public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() {
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(
             mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
index 0996ae3..a042ebe 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
@@ -44,6 +44,7 @@
 import org.robolectric.RuntimeEnvironment;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
@@ -80,25 +81,23 @@
         mPreference = new BluetoothBitPerSampleDialogPreference(mContext);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
         mController.displayPreference(mScreen);
-        mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_NONE,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_16 | BluetoothCodecConfig.BITS_PER_SAMPLE_24,
-                BluetoothCodecConfig.CHANNEL_MODE_NONE,
-                0, 0, 0, 0);
-        mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_NONE,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_24,
-                BluetoothCodecConfig.CHANNEL_MODE_NONE,
-                0, 0, 0, 0);
+        mCodecConfigAAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
+                .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_16
+                                | BluetoothCodecConfig.BITS_PER_SAMPLE_24)
+                .build();
+        mCodecConfigSBC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
+                .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_24)
+                .build();
         when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
     }
 
     @Test
     public void writeConfigurationValues_selectDefault_setHighest() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
 
@@ -127,7 +126,8 @@
     @Test
     public void getSelectableIndex_verifyList() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
         List<Integer> indexList = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
index 81fb3fe..75d8fc4 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
@@ -44,6 +44,7 @@
 import org.robolectric.RuntimeEnvironment;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
@@ -80,25 +81,23 @@
         mPreference = new BluetoothChannelModeDialogPreference(mContext);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
         mController.displayPreference(mScreen);
-        mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_NONE,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
-                BluetoothCodecConfig.CHANNEL_MODE_STEREO,
-                0, 0, 0, 0);
-        mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_NONE,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
-                BluetoothCodecConfig.CHANNEL_MODE_MONO | BluetoothCodecConfig.CHANNEL_MODE_STEREO,
-                0, 0, 0, 0);
+        mCodecConfigAAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
+                .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_STEREO)
+                .build();
+        mCodecConfigSBC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
+                .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_MONO
+                            | BluetoothCodecConfig.CHANNEL_MODE_STEREO)
+                .build();
         when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
     }
 
     @Test
     public void writeConfigurationValues_selectDefault_setHighest() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
 
@@ -124,7 +123,8 @@
     @Test
     public void getSelectableIndex_verifyList() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
         List<Integer> indexList = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
index 0f01e00..3a34aa0 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
@@ -45,6 +45,9 @@
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 
+import java.util.Arrays;
+import java.util.List;
+
 @RunWith(RobolectricTestRunner.class)
 public class BluetoothCodecDialogPreferenceControllerTest {
 
@@ -85,29 +88,41 @@
         mPreference = new BluetoothCodecDialogPreference(mContext);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
         mController.displayPreference(mScreen);
-        mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
-                BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST,
-                BluetoothCodecConfig.SAMPLE_RATE_96000 | BluetoothCodecConfig.SAMPLE_RATE_176400,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_32,
-                BluetoothCodecConfig.CHANNEL_MODE_MONO | BluetoothCodecConfig.CHANNEL_MODE_STEREO,
-                0, 0, 0, 0);
-        mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
-                BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST,
-                BluetoothCodecConfig.SAMPLE_RATE_48000 | BluetoothCodecConfig.SAMPLE_RATE_88200,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_16 | BluetoothCodecConfig.BITS_PER_SAMPLE_24,
-                BluetoothCodecConfig.CHANNEL_MODE_STEREO,
-                0, 0, 0, 0);
-        mCodecConfigAPTX = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX);
-        mCodecConfigAPTXHD = new BluetoothCodecConfig(
-                BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD);
-        mCodecConfigLDAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC);
+        mCodecConfigSBC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
+                .setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST)
+                .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000
+                        | BluetoothCodecConfig.SAMPLE_RATE_176400)
+                .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_32)
+                .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_MONO
+                        | BluetoothCodecConfig.CHANNEL_MODE_STEREO)
+                .build();
+        mCodecConfigAAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
+                .setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST)
+                .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000
+                        | BluetoothCodecConfig.SAMPLE_RATE_88200)
+                .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_16
+                        | BluetoothCodecConfig.BITS_PER_SAMPLE_24)
+                .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_STEREO)
+                .build();
+        mCodecConfigAPTX = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX)
+                .build();
+        mCodecConfigAPTXHD = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD)
+                .build();
+        mCodecConfigLDAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC)
+                .build();
         when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
     }
 
     @Test
     public void writeConfigurationValues_selectDefault_setHighest() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
+                        Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
                 BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
@@ -121,7 +136,8 @@
     public void writeConfigurationValues_checkCodec() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
                 mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
+                        Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
 
@@ -148,7 +164,8 @@
     public void writeConfigurationValues_resetHighestConfig() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
                 mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                        Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
         mController.writeConfigurationValues(2);
@@ -178,7 +195,7 @@
 
     @Test
     public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() {
-        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
+        List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
         mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC,
                 /* codecsLocalCapabilities= */ null,
                 mCodecConfigs);
@@ -194,7 +211,7 @@
     }
     @Test
     public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() {
-        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
+        List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
         mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC,
                 /* codecsLocalCapabilities= */ null,
                 mCodecConfigs);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
index ef209a2..e50b716 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
@@ -43,6 +43,8 @@
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 
+import java.util.Arrays;
+
 @RunWith(RobolectricTestRunner.class)
 public class BluetoothQualityDialogPreferenceControllerTest {
 
@@ -77,18 +79,16 @@
         mPreference = new BluetoothQualityDialogPreference(mContext);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
         mController.displayPreference(mScreen);
-        mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_48000 | BluetoothCodecConfig.SAMPLE_RATE_88200,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
-                BluetoothCodecConfig.CHANNEL_MODE_NONE,
-                0, 0, 0, 0);
-        mCodecConfigLDAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_96000,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
-                BluetoothCodecConfig.CHANNEL_MODE_NONE,
-                1001, 0, 0, 0);
+        mCodecConfigAAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
+                .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000
+                        | BluetoothCodecConfig.SAMPLE_RATE_88200)
+                .build();
+        mCodecConfigLDAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC)
+                .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000)
+                .setCodecSpecific1(1001)
+                .build();
         when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
     }
 
@@ -116,7 +116,8 @@
     @Test
     public void updateState_codeTypeIsLDAC_enablePreference() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
         mController.updateState(mPreference);
@@ -127,7 +128,8 @@
     @Test
     public void updateState_codeTypeAAC_disablePreference() {
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
         mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
index c649fdf..fca154d 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
@@ -44,6 +44,7 @@
 import org.robolectric.RuntimeEnvironment;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
@@ -81,26 +82,26 @@
         mPreference = new BluetoothSampleRateDialogPreference(mContext);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
         mController.displayPreference(mScreen);
-        mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_48000 | BluetoothCodecConfig.SAMPLE_RATE_88200,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
-                BluetoothCodecConfig.CHANNEL_MODE_NONE,
-                0, 0, 0, 0);
-        mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
-                BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
-                BluetoothCodecConfig.SAMPLE_RATE_96000,
-                BluetoothCodecConfig.BITS_PER_SAMPLE_NONE,
-                BluetoothCodecConfig.CHANNEL_MODE_NONE,
-                0, 0, 0, 0);
+        mCodecConfigAAC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC)
+                .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000
+                                | BluetoothCodecConfig.SAMPLE_RATE_88200)
+                .build();
+        mCodecConfigSBC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
+                .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000)
+                .build();
         when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
     }
 
     @Test
     public void writeConfigurationValues_selectDefault_setHighest() {
-        mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC);
+        BluetoothCodecConfig mCodecConfigSBC = new BluetoothCodecConfig.Builder()
+                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
+                .build();
         BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
-        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
+        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
+                Arrays.asList(mCodecConfigs));
         when(mBluetoothA2dp.getCodecStatus(
             mActiveDevice)).thenReturn(mCodecStatus);
         mController.onBluetoothServiceConnected(mBluetoothA2dp);
@@ -132,7 +133,10 @@
 
     @Test
     public void getSelectableIndex_verifyList() {
-        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
+        List<BluetoothCodecConfig> mCodecConfigs = new ArrayList() {{
+                    add(mCodecConfigAAC);
+                    add(mCodecConfigSBC);
+                }};
         mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
         when(mBluetoothA2dp.getCodecStatus(
             mActiveDevice)).thenReturn(mCodecStatus);
diff --git a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
index 81841b7..20f8a55 100644
--- a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
@@ -19,6 +19,7 @@
 import static androidx.lifecycle.Lifecycle.Event.ON_START;
 
 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
 import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
 import static com.android.settings.network.telephony.MobileNetworkUtils.getRafFromNetworkType;
 import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
@@ -32,6 +33,8 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -154,6 +157,30 @@
 
     @UiThreadTest
     @Test
+    public void getAvailabilityStatus_callStateIsIdle_returnAvailable() {
+        mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
+        mController.getTelephonyCallback().onCallStateChanged(TelephonyManager.CALL_STATE_IDLE);
+
+        mController.updateState(mPreference);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+        assertTrue(mPreference.isEnabled());
+    }
+
+    @UiThreadTest
+    @Test
+    public void getAvailabilityStatus_duringCalling_returnAvailable() {
+        mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
+        mController.getTelephonyCallback().onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK);
+
+        mController.updateState(mPreference);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+        assertFalse(mPreference.isEnabled());
+    }
+
+    @UiThreadTest
+    @Test
     public void updateState_LteWorldPhone_GlobalHasLte() {
         mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);