Add switch to enable/disable cbrs

Add switch to enable or disable cbrs
based on whether it is supported or not

Bug: 121291721
Test: Tested enable/disable of the setting on device

Change-Id: Ia79b177966412b2128a6d9cab3549d704253d7b5
diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java
index 2791efa..251bfbc 100644
--- a/src/com/android/settings/RadioInfo.java
+++ b/src/com/android/settings/RadioInfo.java
@@ -213,6 +213,7 @@
     private Switch imsVtProvisionedSwitch;
     private Switch imsWfcProvisionedSwitch;
     private Switch eabProvisionedSwitch;
+    private Switch cbrsDataSwitch;
     private Spinner preferredNetworkType;
     private Spinner cellInfoRefreshRateSpinner;
 
@@ -450,6 +451,9 @@
         imsWfcProvisionedSwitch = (Switch) findViewById(R.id.wfc_provisioned_switch);
         eabProvisionedSwitch = (Switch) findViewById(R.id.eab_provisioned_switch);
 
+        cbrsDataSwitch = (Switch) findViewById(R.id.cbrs_data_switch);
+        cbrsDataSwitch.setVisibility(isCbrsSupported() ? View.VISIBLE : View.GONE);
+
         radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
 
         mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps);
@@ -526,6 +530,11 @@
         imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
         eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
 
+        if (isCbrsSupported()) {
+            cbrsDataSwitch.setChecked(getCbrsDataState());
+            cbrsDataSwitch.setOnCheckedChangeListener(mCbrsDataSwitchChangeListener);
+        }
+
         mTelephonyManager.listen(mPhoneStateListener,
                   PhoneStateListener.LISTEN_CALL_STATE
         //b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
@@ -1483,4 +1492,38 @@
         }
     };
 
+    boolean isCbrsSupported() {
+        return getResources().getBoolean(
+              com.android.internal.R.bool.config_cbrs_supported);
+    }
+
+    void updateCbrsDataState(boolean state) {
+        Log.d(TAG, "setCbrsDataSwitchState() state:" + ((state)? "on":"off"));
+        if (mTelephonyManager != null) {
+            QueuedWork.queue(new Runnable() {
+                public void run() {
+                  mTelephonyManager.setOpportunisticNetworkState(state);
+                  cbrsDataSwitch.setChecked(getCbrsDataState());
+                }
+            }, false);
+        }
+    }
+
+    boolean getCbrsDataState() {
+        boolean state = false;
+        if (mTelephonyManager != null) {
+            state = mTelephonyManager.isOpportunisticNetworkEnabled();
+        }
+        Log.d(TAG, "getCbrsDataState() state:" +((state)? "on":"off"));
+        return state;
+    }
+
+    OnCheckedChangeListener mCbrsDataSwitchChangeListener = new OnCheckedChangeListener() {
+        @Override
+        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+            updateCbrsDataState(isChecked);
+        }
+    };
+
+
 }