Added OOS simulation option

Added OOS simulation toggle for debug build.

Bug: 244064524
Test: Manual
Change-Id: I23d63904679f6522978c6f9dbd6771f39bfbd410
diff --git a/res/layout/radio_info.xml b/res/layout/radio_info.xml
index 2a2ad89..c414fe1 100644
--- a/res/layout/radio_info.xml
+++ b/res/layout/radio_info.xml
@@ -4,16 +4,16 @@
 **
 ** Copyright 2006, The Android Open Source Project
 **
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
 **
-**     http://www.apache.org/licenses/LICENSE-2.0 
+**     http://www.apache.org/licenses/LICENSE-2.0
 **
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
 ** limitations under the License.
 */
 -->
@@ -165,12 +165,6 @@
             <TextView android:id="@+id/network_slicing_config" style="@style/info_value" />
         </LinearLayout>
 
-        <!-- Physical Channel Config -->
-        <LinearLayout style="@style/RadioInfo_entry_layout">
-            <TextView android:text="@string/radio_info_phy_chan_config" style="@style/info_label" />
-            <TextView android:id="@+id/phy_chan_config" style="@style/info_value" />
-        </LinearLayout>
-
         <!-- Horizontal Rule -->
         <View
             android:layout_width="fill_parent"
@@ -204,6 +198,14 @@
                 android:layout_height="wrap_content"
                 android:text="@string/radio_info_radio_power"/>
 
+        <!-- Simulate out of service -->
+        <Switch android:id="@+id/simulate_out_of_service"
+                android:textSize="14sp"
+                android:layout_marginTop="8dip"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/simulate_out_of_service_string"/>
+
         <!-- VoLTE provisioned -->
         <Switch android:id="@+id/volte_provisioned_switch"
                 android:textSize="14sp"
@@ -281,7 +283,7 @@
                 android:layout_height="wrap_content"
                 android:text="@string/ping_test_label"
                 />
- 
+
         <LinearLayout style="@style/RadioInfo_entry_layout">
             <TextView android:text="@string/radio_info_ping_hostname_v4" style="@style/info_label" />
             <TextView android:id="@+id/pingHostnameV4" style="@style/info_value" />
@@ -368,6 +370,12 @@
                  android:layout_height="wrap_content"
                 />
 
+        <!-- Physical Channel Config -->
+        <LinearLayout style="@style/RadioInfo_entry_layout">
+            <TextView android:text="@string/radio_info_phy_chan_config" style="@style/info_label" />
+            <TextView android:id="@+id/phy_chan_config" style="@style/info_value" />
+        </LinearLayout>
+
         <!-- CellInfo -->
         <LinearLayout style="@style/RadioInfo_entry_layout">
             <TextView android:text="@string/radio_info_cellinfo_label"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 38a86f9..44151c5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2010,6 +2010,9 @@
     <!-- Title for controlling on/off for Mobile phone's radio power. Only shown in diagnostic screen, so precise translation is not needed. -->
     <string name="radio_info_radio_power">Mobile Radio Power</string>
 
+    <!-- Title for simulating device out of service. -->
+    <string name="simulate_out_of_service_string">Simulate Out of Service (Debug Build only)</string>
+
     <!-- Phone Info screen. Menu item label.  Used for diagnostic info screens, precise translation isn't needed -->
     <string name="radioInfo_menu_viewADN">View SIM Address Book</string>
     <!-- Phone Info screen. Menu item label.  Used for diagnostic info screens, precise translation isn't needed -->
diff --git a/src/com/android/phone/settings/RadioInfo.java b/src/com/android/phone/settings/RadioInfo.java
index 288d543..8289883 100644
--- a/src/com/android/phone/settings/RadioInfo.java
+++ b/src/com/android/phone/settings/RadioInfo.java
@@ -102,6 +102,7 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.euicc.EuiccConnector;
+import com.android.internal.telephony.util.TelephonyUtils;
 import com.android.phone.R;
 
 import java.io.IOException;
@@ -256,6 +257,7 @@
     private TextView mNetworkSlicingConfig;
     private EditText mSmsc;
     private Switch mRadioPowerOnSwitch;
+    private Switch mSimulateOutOfServiceSwitch;
     private Button mCellInfoRefreshRateButton;
     private Button mDnsCheckToggleButton;
     private Button mPingTestButton;
@@ -292,6 +294,7 @@
     private boolean mCfiValue = false;
 
     private List<CellInfo> mCellInfoResult = null;
+    private final boolean[] mSimulateOos = new boolean[2];
 
     private int mPreferredNetworkTypeResult;
     private int mCellInfoRefreshRateIndex;
@@ -583,6 +586,11 @@
 
         mRadioPowerOnSwitch = (Switch) findViewById(R.id.radio_power);
 
+        mSimulateOutOfServiceSwitch = (Switch) findViewById(R.id.simulate_out_of_service);
+        if (!TelephonyUtils.IS_DEBUGGABLE) {
+            mSimulateOutOfServiceSwitch.setVisibility(View.GONE);
+        }
+
         mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps);
         mUplinkKbps = (TextView) findViewById(R.id.ul_kbps);
         updateBandwidths(0, 0);
@@ -693,6 +701,8 @@
         mSelectPhoneIndex.setOnItemSelectedListener(mSelectPhoneIndexHandler);
 
         mRadioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
+        mSimulateOutOfServiceSwitch.setOnCheckedChangeListener(mSimulateOosOnChangeListener);
+        mSimulateOutOfServiceSwitch.setChecked(mSimulateOos[mPhone.getPhoneId()]);
         mImsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
         mImsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
         mImsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
@@ -1621,6 +1631,22 @@
         }
     };
 
+    private final OnCheckedChangeListener mSimulateOosOnChangeListener =
+            (buttonView, isChecked) -> {
+        Intent intent = new Intent("com.android.internal.telephony.TestServiceState");
+        if (isChecked) {
+            log("Send OOS override broadcast intent.");
+            intent.putExtra("data_reg_state", 1);
+            mSimulateOos[mPhone.getPhoneId()] = true;
+        } else {
+            log("Remove OOS override.");
+            intent.putExtra("action", "reset");
+            mSimulateOos[mPhone.getPhoneId()] = false;
+        }
+
+        mPhone.getTelephonyTester().setServiceStateTestIntent(intent);
+    };
+
     private boolean isImsVolteProvisioned() {
         return getImsConfigProvisionedState(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
                 ImsRegistrationImplBase.REGISTRATION_TECH_LTE);