use new config override_dnd to replace override_dnd_default

Previously we are using override_dnd_default to control if alerts
audio should ignore DND settings. override_dnd_default is the default
value of the overrinding dnd settings(sharedpred). updating
override_dnd_default value per carrier requirements won't take effect
in OTA as we persists user preferences. We should use a separate config
to control override dnd in general rather than using sharedpreference.
The new logic: 1) override_dnd_default only serve the purpose of default
settings values. Read override_dnd sharedpreference value only when the toggle
is visible 2) range.mOverrideDND is the per channel config 3)
override_dnd is the main config for all channels

Bug: 169452408
Test: Manual
Change-Id: I9b72fdf84cdabf67f545abd14a7c53c6b6af6cae
diff --git a/res/values-mcc222/config.xml b/res/values-mcc222/config.xml
index 531d781..b6854c8 100644
--- a/res/values-mcc222/config.xml
+++ b/res/values-mcc222/config.xml
@@ -15,7 +15,7 @@
 -->
 <resources>
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
     <!-- Whether to append date-time to the alert title -->
     <bool name="show_date_time_title">true</bool>
     <!-- 4371, 4384 -->
diff --git a/res/values-mcc334/config.xml b/res/values-mcc334/config.xml
index 1d3f24e..2175a4c 100644
--- a/res/values-mcc334/config.xml
+++ b/res/values-mcc334/config.xml
@@ -28,7 +28,7 @@
     </string-array>
 
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
 
     <!-- Link method -->
     <string name="link_method" translatable="false">none</string>
diff --git a/res/values-mcc420/config.xml b/res/values-mcc420/config.xml
index d15ff6e..eea0bbb 100644
--- a/res/values-mcc420/config.xml
+++ b/res/values-mcc420/config.xml
@@ -23,7 +23,7 @@
     <bool name="show_amber_alert_settings">false</bool>
 
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
     <!-- Channels to receive emergency alerts -->
     <!-- 4371~4372, 4384~4385 -->
     <string-array name="cmas_alert_extreme_channels_range_strings" translatable="false">
diff --git a/res/values-mcc422/config.xml b/res/values-mcc422/config.xml
index f0e18ef..3329da8 100644
--- a/res/values-mcc422/config.xml
+++ b/res/values-mcc422/config.xml
@@ -29,7 +29,7 @@
         <item>0x111D:rat=gsm, emergency=true</item>
     </string-array>
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
     <!-- test alerts toggle default true for Oman users -->
     <bool name="test_alerts_enabled_default">true</bool>
     <string-array name="cmas_alert_extreme_channels_range_strings" translatable="false"></string-array>
diff --git a/res/values-mcc424/config.xml b/res/values-mcc424/config.xml
index 62bd87c..0ef06e1 100644
--- a/res/values-mcc424/config.xml
+++ b/res/values-mcc424/config.xml
@@ -29,7 +29,7 @@
     <bool name="state_local_test_alerts_enabled_default">true</bool>
 
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
     <!-- 4379, 4392 -->
     <string-array name="emergency_alerts_channels_range_strings" translatable="false">
         <item>0x111B:rat=gsm, emergency=true</item>
diff --git a/res/values-mcc716/config.xml b/res/values-mcc716/config.xml
index 12219dc..22f312e 100644
--- a/res/values-mcc716/config.xml
+++ b/res/values-mcc716/config.xml
@@ -61,7 +61,7 @@
     <bool name="show_date_in_numeric_format">true</bool>
 
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
 
     <!-- Link method -->
     <string name="link_method" translatable="false">none</string>
diff --git a/res/values-mcc730/config.xml b/res/values-mcc730/config.xml
index 74e4d2c..3e82f67 100644
--- a/res/values-mcc730/config.xml
+++ b/res/values-mcc730/config.xml
@@ -58,7 +58,7 @@
     </string-array>
 
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
     <!-- Append date-time to the alert title -->
     <bool name="show_date_time_title">true</bool>
     <!-- if appending date-time to alert title, whether to include year -->
diff --git a/res/values-mcc732/config.xml b/res/values-mcc732/config.xml
index 361342d..83f798f 100644
--- a/res/values-mcc732/config.xml
+++ b/res/values-mcc732/config.xml
@@ -28,7 +28,7 @@
     </string-array>
 
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
 
     <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
     <bool name="config_showAreaUpdateInfoSettings">true</bool>
diff --git a/res/values-mcc740/config.xml b/res/values-mcc740/config.xml
index 361342d..83f798f 100644
--- a/res/values-mcc740/config.xml
+++ b/res/values-mcc740/config.xml
@@ -28,7 +28,7 @@
     </string-array>
 
     <!-- Play alert sound in full volume regardless Do Not Disturb is on -->
-    <bool name="override_dnd_default">true</bool>
+    <bool name="override_dnd">true</bool>
 
     <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app -->
     <bool name="config_showAreaUpdateInfoSettings">true</bool>
diff --git a/res/values/config.xml b/res/values/config.xml
index c49ec38..c2ab3eb 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -92,6 +92,8 @@
     <bool name="show_message_history_in_launcher">false</bool>
     <!-- Allow user to enable/disable audio speech alert (text-to-speech for received messages)-->
     <bool name="show_alert_speech_setting">false</bool>
+    <!-- always overriding dnd settings: Play alert sound in full volume regardless DND is on. Applied to all channels -->
+    <bool name="override_dnd">false</bool>
 
     <!-- Specify second language code to receive emergency alerts -->
     <string name="emergency_alert_second_language_code" translatable="false"></string>
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
index 18f9d3c..55d8154 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
@@ -571,9 +571,13 @@
                         ? range.mVibrationPattern
                         : CellBroadcastSettings.getResources(mContext, message.getSubscriptionId())
                         .getIntArray(R.array.default_vibration_pattern));
-
-        if (prefs.getBoolean(CellBroadcastSettings.KEY_OVERRIDE_DND, false)
-                || (range != null && range.mOverrideDnd)) {
+        // read key_override_dnd only when the toggle is visible.
+        // range.mOverrideDnd is per channel configuration. override_dnd is the main config
+        // applied for all channels.
+        Resources res = CellBroadcastSettings.getResources(mContext, message.getSubscriptionId());
+        if ((res.getBoolean(R.bool.show_override_dnd_settings)
+                && prefs.getBoolean(CellBroadcastSettings.KEY_OVERRIDE_DND, false))
+                || (range != null && range.mOverrideDnd) || res.getBoolean(R.bool.override_dnd)) {
             audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_OVERRIDE_DND_EXTRA, true);
         }