Add logic to hide HCO and VCO for TTY based on RTT

When specified in the carrier config, hide the HCO and VCO options for
TTY in accessiblity settings if RTT is available on the device/carrier.

Fixes: 137672992
Test: manual
Change-Id: If2e1762c4ad378e7f57e5a82377b6722d3595977
diff --git a/src/com/android/phone/settings/TtyModeListPreference.java b/src/com/android/phone/settings/TtyModeListPreference.java
index 89cac47..ba415c5 100644
--- a/src/com/android/phone/settings/TtyModeListPreference.java
+++ b/src/com/android/phone/settings/TtyModeListPreference.java
@@ -18,17 +18,23 @@
 
 import android.content.Context;
 import android.content.Intent;
+import android.os.PersistableBundle;
 import android.os.UserHandle;
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.provider.Settings;
+import android.provider.Settings.Secure;
 import android.telecom.TelecomManager;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionManager;
 import android.util.AttributeSet;
 import android.util.Log;
 
 import com.android.phone.PhoneGlobals;
 import com.android.phone.R;
 
+import java.util.Arrays;
+
 public class TtyModeListPreference extends ListPreference
         implements Preference.OnPreferenceChangeListener {
     private static final String LOG_TAG = TtyModeListPreference.class.getSimpleName();
@@ -44,6 +50,19 @@
         int settingsTtyMode = Settings.Secure.getInt(getContext().getContentResolver(),
                 Settings.Secure.PREFERRED_TTY_MODE,
                 TelecomManager.TTY_MODE_OFF);
+        if (shouldHideHcoAndVco()) {
+            setEntries(Arrays.copyOfRange(
+                    getContext().getResources().getTextArray(R.array.tty_mode_entries), 0, 2));
+            setEntryValues(Arrays.copyOfRange(
+                    getContext().getResources().getTextArray(R.array.tty_mode_values), 0, 2));
+            if (settingsTtyMode == TelecomManager.TTY_MODE_HCO
+                    || settingsTtyMode == TelecomManager.TTY_MODE_VCO) {
+                // If the persisted setting is HCO or VCO, set it to full here
+                settingsTtyMode = TelecomManager.TTY_MODE_FULL;
+                Settings.Secure.putInt(getContext().getContentResolver(), Secure.PREFERRED_TTY_MODE,
+                        settingsTtyMode);
+            }
+        }
         setValue(Integer.toString(settingsTtyMode));
         updatePreferredTtyModeSummary(settingsTtyMode);
     }
@@ -101,6 +120,18 @@
         }
     }
 
+    private boolean shouldHideHcoAndVco() {
+        CarrierConfigManager carrierConfigManager =
+                getContext().getSystemService(CarrierConfigManager.class);
+        PersistableBundle config = carrierConfigManager.getConfigForSubId(
+                SubscriptionManager.getDefaultVoiceSubscriptionId());
+        boolean carrierShouldHideHcoVco = config != null && config.getBoolean(
+                CarrierConfigManager.KEY_HIDE_TTY_HCO_VCO_WITH_RTT_BOOL, false);
+        boolean isRttSupported = PhoneGlobals.getInstance().phoneMgr.isRttSupported(
+                SubscriptionManager.getDefaultVoiceSubscriptionId());
+        return carrierShouldHideHcoVco && isRttSupported;
+    }
+
     private static void log(String msg) {
         Log.d(LOG_TAG, msg);
     }