Disable service category comparison for duplicate detection

Some CDMA carriers do no need service category comparison when
performing message duplicate detection.

Fix: 167913896
Test: Manual
Merged-In: I6a30fb6b5d44d129a16e361b9982f0dd06f29739
Change-Id: I6a30fb6b5d44d129a16e361b9982f0dd06f29739
(cherry picked from commit 9d28cb99582f477a3321f465e61d7c03bb82fe46)
diff --git a/res/values-mcc310-mnc012/config.xml b/res/values-mcc310-mnc012/config.xml
index 16b960d..73a4e8b 100644
--- a/res/values-mcc310-mnc012/config.xml
+++ b/res/values-mcc310-mnc012/config.xml
@@ -18,4 +18,7 @@
     <!-- The maximum waiting time in seconds for location to perform
          device based geo-fencing -->
     <integer name="max_location_waiting_time">120</integer>
+
+    <!-- Whether to compare message service category when deduping messages -->
+    <bool name="duplicate_compare_service_category">false</bool>
 </resources>
diff --git a/res/values/config.xml b/res/values/config.xml
index 8fe6aad..306cc41 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -33,6 +33,9 @@
     <!-- Whether to compare message body when deduping messages -->
     <bool name="duplicate_compare_body">false</bool>
 
+    <!-- Whether to compare message service category when deduping messages -->
+    <bool name="duplicate_compare_service_category">true</bool>
+
     <!-- Whether to reset alert message duplicate detection and geo-fencing check after
     reboot or toggling airplane mode -->
     <bool name="reset_on_power_cycle_or_airplane_mode">false</bool>
diff --git a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
index eab291e..1378ebb 100644
--- a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
+++ b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
@@ -435,6 +435,7 @@
         }
 
         boolean compareMessageBody = res.getBoolean(R.bool.duplicate_compare_body);
+        boolean compareServiceCategory = res.getBoolean(R.bool.duplicate_compare_service_category);
 
         log("Found " + cbMessages.size() + " messages since "
                 + DateFormat.getDateTimeInstance().format(dupCheckTime));
@@ -464,16 +465,15 @@
                     continue;
                 }
 
-                // Check if the message category is different. Some carriers send cell broadcast
-                // messages on different techs (i.e. GSM / CDMA), so we need to compare service
-                // category cross techs.
-                if (message.getServiceCategory() != messageToCheck.getServiceCategory()
+                // Check if the message category is different.
+                if (compareServiceCategory
+                        && message.getServiceCategory() != messageToCheck.getServiceCategory()
                         && !Objects.equals(mServiceCategoryCrossRATMap.get(
                                 message.getServiceCategory()), messageToCheck.getServiceCategory())
                         && !Objects.equals(mServiceCategoryCrossRATMap.get(
                                 messageToCheck.getServiceCategory()),
                         message.getServiceCategory())) {
-                    if (VDBG) log("GSM/CDMA category does not match.");
+                    if (VDBG) log("Category does not match.");
                     // Not a dup. Check next one.
                     continue;
                 }
diff --git a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastHandlerTest.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastHandlerTest.java
index ca4f9cb..d45b725 100644
--- a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastHandlerTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastHandlerTest.java
@@ -138,6 +138,8 @@
                 mMockedResourcesCache);
         putResources(com.android.cellbroadcastservice.R.integer.message_expiration_time,
                 (int) DateUtils.DAY_IN_MILLIS);
+        putResources(com.android.cellbroadcastservice.R.bool.duplicate_compare_service_category,
+                true);
     }
 
     @After