Add Tracfone to Motorola menu, move existing menu to Sprint only

Bug: 71707082
Test: MotorolaHiddenMenuKeySequenceTest
PiperOrigin-RevId: 186387666
Change-Id: I3971604d717dcea8bfd1159b281a2dc5a0f3b0f7
diff --git a/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java b/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java
index 79abff0..81f6b60 100644
--- a/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java
+++ b/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java
@@ -22,7 +22,11 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ResolveInfo;
+import android.support.annotation.VisibleForTesting;
 import com.android.dialer.common.LogUtil;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.regex.Pattern;
 
 /**
@@ -30,13 +34,14 @@
  */
 public class MotorolaHiddenMenuKeySequence {
   private static final String EXTRA_HIDDEN_MENU_CODE = "HiddenMenuCode";
+
   private static MotorolaHiddenMenuKeySequence instance = null;
 
-  private static String[] hiddenKeySequenceArray = null;
-  private static String[] hiddenKeySequenceIntentArray = null;
-  private static String[] hiddenKeyPatternArray = null;
-  private static String[] hiddenKeyPatternIntentArray = null;
-  private static boolean featureHiddenMenuEnabled = false;
+  @VisibleForTesting final List<String> hiddenKeySequences = new ArrayList<>();
+  @VisibleForTesting final List<String> hiddenKeySequenceIntents = new ArrayList<>();
+  @VisibleForTesting final List<String> hiddenKeyPatterns = new ArrayList<>();
+  @VisibleForTesting final List<String> hiddenKeyPatternIntents = new ArrayList<>();
+  @VisibleForTesting boolean featureHiddenMenuEnabled = false;
 
   /**
    * Handle input char sequence.
@@ -46,8 +51,7 @@
    * @return true if the input matches any pattern
    */
   static boolean handleCharSequence(Context context, String input) {
-    getInstance(context);
-    if (!featureHiddenMenuEnabled) {
+    if (!getInstance(context).featureHiddenMenuEnabled) {
       return false;
     }
     return handleKeySequence(context, input) || handleKeyPattern(context, input);
@@ -66,60 +70,81 @@
     return instance;
   }
 
-  private MotorolaHiddenMenuKeySequence(Context context) {
-    featureHiddenMenuEnabled = MotorolaUtils.isSupportingHiddenMenu(context);
-    // In case we do have a SPN from resource we need to match from service; otherwise we are
-    // free to go
-    if (featureHiddenMenuEnabled) {
+  @VisibleForTesting
+  MotorolaHiddenMenuKeySequence(Context context) {
+    if (MotorolaUtils.isSupportingHiddenMenu(context)) {
+      Collections.addAll(
+          hiddenKeySequences,
+          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_sequence));
+      Collections.addAll(
+          hiddenKeySequenceIntents,
+          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_sequence_intents));
+      Collections.addAll(
+          hiddenKeyPatterns,
+          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_pattern));
+      Collections.addAll(
+          hiddenKeyPatternIntents,
+          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_pattern_intents));
+      featureHiddenMenuEnabled = true;
+    }
 
-      hiddenKeySequenceArray =
-          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_sequence);
-      hiddenKeySequenceIntentArray =
-          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_sequence_intents);
-      hiddenKeyPatternArray =
-          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_pattern);
-      hiddenKeyPatternIntentArray =
-          context.getResources().getStringArray(R.array.motorola_hidden_menu_key_pattern_intents);
+    if ("tracfone".equals(System.getProperty("ro.carrier"))) {
+      addHiddenKeySequence("#83865625#", "com.motorola.extensions.TFUnlock");
+      addHiddenKeySequence("#83782887#", "com.motorola.extensions.TFStatus");
+      featureHiddenMenuEnabled = true;
+    }
 
-      if (hiddenKeySequenceArray.length != hiddenKeySequenceIntentArray.length
-          || hiddenKeyPatternArray.length != hiddenKeyPatternIntentArray.length
-          || (hiddenKeySequenceArray.length == 0 && hiddenKeyPatternArray.length == 0)) {
-        LogUtil.e(
-            "MotorolaHiddenMenuKeySequence",
-            "the key sequence array is not matching, turn off feature."
-                + "key sequence: %d != %d, key pattern %d != %d",
-            hiddenKeySequenceArray.length,
-            hiddenKeySequenceIntentArray.length,
-            hiddenKeyPatternArray.length,
-            hiddenKeyPatternIntentArray.length);
-        featureHiddenMenuEnabled = false;
-      }
+    if (hiddenKeySequences.size() != hiddenKeySequenceIntents.size()
+        || hiddenKeyPatterns.size() != hiddenKeyPatternIntents.size()
+        || (hiddenKeySequences.isEmpty() && hiddenKeyPatterns.isEmpty())) {
+      LogUtil.e(
+          "MotorolaHiddenMenuKeySequence",
+          "the key sequence array is not matching, turn off feature."
+              + "key sequence: %d != %d, key pattern %d != %d",
+          hiddenKeySequences.size(),
+          hiddenKeySequenceIntents.size(),
+          hiddenKeyPatterns.size(),
+          hiddenKeyPatternIntents.size());
+      featureHiddenMenuEnabled = false;
     }
   }
 
+  private void addHiddenKeySequence(String keySequence, String intentAction) {
+    hiddenKeySequences.add(keySequence);
+    hiddenKeySequenceIntents.add(intentAction);
+  }
+
   private static boolean handleKeyPattern(Context context, String input) {
+    MotorolaHiddenMenuKeySequence instance = getInstance(context);
+
     int len = input.length();
-    if (len <= 3 || hiddenKeyPatternArray == null || hiddenKeyPatternIntentArray == null) {
+    if (len <= 3
+        || instance.hiddenKeyPatterns == null
+        || instance.hiddenKeyPatternIntents == null) {
       return false;
     }
 
-    for (int i = 0; i < hiddenKeyPatternArray.length; i++) {
-      if ((Pattern.compile(hiddenKeyPatternArray[i])).matcher(input).matches()) {
-        return sendIntent(context, input, hiddenKeyPatternIntentArray[i]);
+    for (int i = 0; i < instance.hiddenKeyPatterns.size(); i++) {
+      if (Pattern.matches(instance.hiddenKeyPatterns.get(i), input)) {
+        return sendIntent(context, input, instance.hiddenKeyPatternIntents.get(i));
       }
     }
     return false;
   }
 
   private static boolean handleKeySequence(Context context, String input) {
+    MotorolaHiddenMenuKeySequence instance = getInstance(context);
+
     int len = input.length();
-    if (len <= 3 || hiddenKeySequenceArray == null || hiddenKeySequenceIntentArray == null) {
+    if (len <= 3
+        || instance.hiddenKeySequences == null
+        || instance.hiddenKeySequenceIntents == null) {
       return false;
     }
 
-    for (int i = 0; i < hiddenKeySequenceArray.length; i++) {
-      if (hiddenKeySequenceArray[i].equals(input)) {
-        return sendIntent(context, input, hiddenKeySequenceIntentArray[i]);
+    for (int i = 0; i < instance.hiddenKeySequences.size(); i++) {
+      if (instance.hiddenKeySequences.get(i).equals(input)) {
+        return sendIntent(context, input, instance.hiddenKeySequenceIntents.get(i));
       }
     }
     return false;
diff --git a/java/com/android/dialer/oem/MotorolaUtils.java b/java/com/android/dialer/oem/MotorolaUtils.java
index c1e2da2..1446a02 100644
--- a/java/com/android/dialer/oem/MotorolaUtils.java
+++ b/java/com/android/dialer/oem/MotorolaUtils.java
@@ -43,7 +43,8 @@
   // package is enabled.
   @VisibleForTesting public static final String WIFI_CALL_PACKAGE_NAME = "com.motorola.sprintwfc";
   // Thi is used to check if a Motorola device supports hidden menu feature.
-  private static final String HIDDEN_MENU_FEATURE = "com.motorola.software.sprint.hidden_menu";
+  @VisibleForTesting
+  static final String HIDDEN_MENU_FEATURE = "com.motorola.software.sprint.hidden_menu";
 
   private static boolean hasCheckedSprintWifiCall;
   private static boolean supportSprintWifiCall;
diff --git a/java/com/android/dialer/oem/res/values-mcc310-mnc120/motorola_config.xml b/java/com/android/dialer/oem/res/values-mcc310-mnc120/motorola_config.xml
index c5cb0d1..417a4b8 100644
--- a/java/com/android/dialer/oem/res/values-mcc310-mnc120/motorola_config.xml
+++ b/java/com/android/dialer/oem/res/values-mcc310-mnc120/motorola_config.xml
@@ -17,4 +17,60 @@
 
 <resources>
   <bool name="motorola_sprint_hd_codec">true</bool>
+
+  <!-- Hidden menu configuration for Motorola. -->
+  <!-- This defines the specific key sequence that will be caught in the SpecialCharSequenceMgr
+       such as, ##OMADM# -->
+  <string-array name="motorola_hidden_menu_key_sequence">
+    <item>##66236#</item>   <!--##OMADM#-->
+    <item>##2539#</item>    <!--##AKEY#-->
+    <item>##786#</item>     <!--##RTN#-->
+    <item>##72786#</item>   <!--##SCRTN#-->
+    <item>##3282#</item>    <!--##DATA#-->
+    <item>##33284#</item>   <!--##DEBUG#-->
+    <item>##3424#</item>    <!--##DIAG#-->
+    <item>##564#</item>     <!--##LOG#-->
+    <item>##4567257#</item> <!--##GLMSCLR#-->
+    <item>##873283#</item>  <!--##UPDATE#-->
+    <item>##6343#</item>    <!--##MEID#-->
+    <item>##27263#</item>   <!--##BRAND#-->
+    <item>##258#</item>     <!--##BLV#-->
+    <item>##8422#</item>    <!--##UICC#-->
+    <item>##4382#</item>    <!--CMAS/WEA-->
+  </string-array>
+
+  <string name="motorola_hidden_menu_intent">com.motorola.intent.action.LAUNCH_HIDDEN_MENU</string>
+
+  <!-- This defines the intents that will be send out when the key sequence is matched, this must be
+       in the same order with he KeySequence array. -->
+  <string-array name="motorola_hidden_menu_key_sequence_intents">
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>com.motorola.android.intent.action.omadm.sprint.hfa</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+    <item>@string/motorola_hidden_menu_intent</item>
+  </string-array>
+
+  <!-- This defines the specific key patterns that will be caught in the SpecialCharSequenceMgr
+       such as, ##[0-9]{3,7}# -->
+  <string-array name="motorola_hidden_menu_key_pattern">
+    <!--##MSL#, here MSL is 6 digits SPC code, ##OTKSL#, OTKSL is also digits code -->
+    <item>##[0-9]{6}#</item>
+  </string-array>
+
+  <!-- This defines the intents that will be send out when the key sequence is matched, this must be
+     in the same order with he KeyPattern array. -->
+  <string-array name="motorola_hidden_menu_key_pattern_intents">
+    <item>@string/motorola_hidden_menu_intent</item>
+  </string-array>
 </resources>
\ No newline at end of file
diff --git a/java/com/android/dialer/oem/res/values/motorola_config.xml b/java/com/android/dialer/oem/res/values/motorola_config.xml
index ba451e7..fd9cee0 100644
--- a/java/com/android/dialer/oem/res/values/motorola_config.xml
+++ b/java/com/android/dialer/oem/res/values/motorola_config.xml
@@ -20,59 +20,26 @@
   <bool name="motorola_sprint_hd_codec">false</bool>
 
   <!-- Hidden menu configuration for Motorola. -->
-  <!-- This defines the specific key seuquence that will be catched in the SpecialCharSequenceMgr
+  <!-- This defines the specific key sequence that will be caught in the SpecialCharSequenceMgr
        such as, ##OMADM# -->
   <string-array name="motorola_hidden_menu_key_sequence">
-    <item>##66236#</item>   <!--##OMADM#-->
-    <item>##2539#</item>    <!--##AKEY#-->
-    <item>##786#</item>     <!--##RTN#-->
-    <item>##72786#</item>   <!--##SCRTN#-->
-    <item>##3282#</item>    <!--##DATA#-->
-    <item>##33284#</item>   <!--##DEBUG#-->
-    <item>##3424#</item>    <!--##DIAG#-->
-    <item>##564#</item>     <!--##LOG#-->
-    <item>##4567257#</item> <!--##GLMSCLR#-->
-    <item>##873283#</item>  <!--##UPDATE#-->
-    <item>##6343#</item>    <!--##MEID#-->
-    <item>##27263#</item>   <!--##BRAND#-->
-    <item>##258#</item>     <!--##BLV#-->
-    <item>##8422#</item>    <!--##UICC#-->
-    <item>##4382#</item>    <!--CMAS/WEA-->
   </string-array>
 
-  <string name="motorola_hidden_menu_intent">com.motorola.intent.action.LAUNCH_HIDDEN_MENU</string>
+  <string name="motorola_hidden_menu_intent"></string>
 
-  <!-- This defines the intents that will be send out when the key quence is matched, this must be
+  <!-- This defines the intents that will be send out when the key sequence is matched, this must be
        in the same order with he KeySequence array. -->
   <string-array name="motorola_hidden_menu_key_sequence_intents">
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>com.motorola.android.intent.action.omadm.sprint.hfa</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
-    <item>@string/motorola_hidden_menu_intent</item>
   </string-array>
 
-  <!-- This defines the specific key patterns that will be catched in the SpecialCharSequenceMgr
+  <!-- This defines the specific key patterns that will be caught in the SpecialCharSequenceMgr
        such as, ##[0-9]{3,7}# -->
   <string-array name="motorola_hidden_menu_key_pattern">
-    <!--##MSL#, here MSL is 6 digits SPC code, ##OTKSL#, OTKSL is also digits code -->
-    <item>##[0-9]{6}#</item>
   </string-array>
 
-  <!-- This defines the intents that will be send out when the key quence is matched, this must be
+  <!-- This defines the intents that will be send out when the key sequence is matched, this must be
        in the same order with he KeyPattern array. -->
   <string-array name="motorola_hidden_menu_key_pattern_intents">
-    <item>@string/motorola_hidden_menu_intent</item>
   </string-array>
 
   <!-- This defines the provider names for cequint callerid applications
@@ -80,4 +47,4 @@
   <string-array name="cequint_providers">
     <item>com.cequint.ecid</item>
   </string-array>
-</resources>
\ No newline at end of file
+</resources>