Modify "Call Barring" UI to remove pref options per carrier

When KEY_CALL_BARRING_SUPPORTS_PASSWORD_CHANGE_BOOL or
KEY_CALL_BARRING_SUPPORTS_DEACTIVATE_ALL_BOOL are disabled, remove
the "Change Password" or "Deactivate Barring" preference, respectively.

Test: Modify CarrierConfig locally and verify corresponding UI is removed.
Bug: 80510612
Change-Id: I5a56469f239acba363804f93c08fa0311c8c559a
diff --git a/src/com/android/phone/GsmUmtsCallBarringOptions.java b/src/com/android/phone/GsmUmtsCallBarringOptions.java
index 4b875ee..a6f9844 100644
--- a/src/com/android/phone/GsmUmtsCallBarringOptions.java
+++ b/src/com/android/phone/GsmUmtsCallBarringOptions.java
@@ -18,12 +18,15 @@
 
 import android.app.ActionBar;
 import android.app.Dialog;
+import android.content.Context;
 import android.os.AsyncResult;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.os.PersistableBundle;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
+import android.telephony.CarrierConfigManager;
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
@@ -360,6 +363,25 @@
             Log.d(LOG_TAG, "onCreate, reading callbarring_options.xml file finished!");
         }
 
+        CarrierConfigManager configManager = (CarrierConfigManager)
+                mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
+        PersistableBundle carrierConfig;
+        if (mSubscriptionInfoHelper.hasSubId()) {
+            carrierConfig = configManager.getConfigForSubId(mSubscriptionInfoHelper.getSubId());
+        } else {
+            carrierConfig = configManager.getConfig();
+        }
+        boolean isPwChangeButtonVisible = true;
+        boolean isDisableAllButtonVisible = true;
+        if (carrierConfig != null) {
+            isPwChangeButtonVisible = carrierConfig.getBoolean(
+                    CarrierConfigManager.KEY_CALL_BARRING_SUPPORTS_PASSWORD_CHANGE_BOOL, true);
+            isDisableAllButtonVisible = carrierConfig.getBoolean(
+                    CarrierConfigManager.KEY_CALL_BARRING_SUPPORTS_DEACTIVATE_ALL_BOOL, true);
+        } else {
+            Log.w(LOG_TAG, "Couldn't access CarrierConfig bundle");
+        }
+
         // Get UI object references
         PreferenceScreen prefSet = getPreferenceScreen();
         mButtonBAOC = (CallBarringEditPreference) prefSet.findPreference(BUTTON_BAOC_KEY);
@@ -371,6 +393,15 @@
                 prefSet.findPreference(BUTTON_BA_ALL_KEY);
         mButtonChangePW = (EditPinPreference) prefSet.findPreference(BUTTON_BA_CHANGE_PW_KEY);
 
+        // Some carriers do not use PW change and disable all buttons. Hide them if this is the
+        // case.
+        if (!isDisableAllButtonVisible) {
+            prefSet.removePreference(mButtonDisableAll);
+        }
+        if (!isPwChangeButtonVisible) {
+            prefSet.removePreference(mButtonChangePW);
+        }
+
         // Assign click listener and update state
         mButtonBAOC.setOnPinEnteredListener(this);
         mButtonBAOIC.setOnPinEnteredListener(this);