From f5326db368ba35faf861f690b09d0ea9c8d5080f Mon Sep 17 00:00:00 2001 From: roldenburg Date: Tue, 20 Feb 2018 17:14:12 -0800 Subject: Add Tracfone to Motorola menu, move existing menu to Sprint only Bug: 71707082 Test: MotorolaHiddenMenuKeySequenceTest PiperOrigin-RevId: 186387666 Change-Id: I3971604d717dcea8bfd1159b281a2dc5a0f3b0f7 --- .../dialer/oem/MotorolaHiddenMenuKeySequence.java | 111 +++++++++++++-------- java/com/android/dialer/oem/MotorolaUtils.java | 3 +- .../res/values-mcc310-mnc120/motorola_config.xml | 56 +++++++++++ .../dialer/oem/res/values/motorola_config.xml | 45 ++------- 4 files changed, 132 insertions(+), 83 deletions(-) (limited to 'java/com/android/dialer/oem') diff --git a/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java b/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java index 79abff08e..81f6b607c 100644 --- a/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java +++ b/java/com/android/dialer/oem/MotorolaHiddenMenuKeySequence.java @@ -22,7 +22,11 @@ import android.content.ActivityNotFoundException; 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 @@ import java.util.regex.Pattern; */ 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 hiddenKeySequences = new ArrayList<>(); + @VisibleForTesting final List hiddenKeySequenceIntents = new ArrayList<>(); + @VisibleForTesting final List hiddenKeyPatterns = new ArrayList<>(); + @VisibleForTesting final List hiddenKeyPatternIntents = new ArrayList<>(); + @VisibleForTesting boolean featureHiddenMenuEnabled = false; /** * Handle input char sequence. @@ -46,8 +51,7 @@ public class MotorolaHiddenMenuKeySequence { * @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 @@ public class MotorolaHiddenMenuKeySequence { 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) { - - 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 (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; - } + @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; + } + + if ("tracfone".equals(System.getProperty("ro.carrier"))) { + addHiddenKeySequence("#83865625#", "com.motorola.extensions.TFUnlock"); + addHiddenKeySequence("#83782887#", "com.motorola.extensions.TFStatus"); + featureHiddenMenuEnabled = true; } + + 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 c1e2da256..1446a0219 100644 --- a/java/com/android/dialer/oem/MotorolaUtils.java +++ b/java/com/android/dialer/oem/MotorolaUtils.java @@ -43,7 +43,8 @@ public class MotorolaUtils { // 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 c5cb0d1f7..417a4b845 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 @@ true + + + + + ##66236# + ##2539# + ##786# + ##72786# + ##3282# + ##33284# + ##3424# + ##564# + ##4567257# + ##873283# + ##6343# + ##27263# + ##258# + ##8422# + ##4382# + + + com.motorola.intent.action.LAUNCH_HIDDEN_MENU + + + + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + com.motorola.android.intent.action.omadm.sprint.hfa + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + @string/motorola_hidden_menu_intent + + + + + + ##[0-9]{6}# + + + + + @string/motorola_hidden_menu_intent + \ 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 ba451e715..fd9cee0a9 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 @@ false - - ##66236# - ##2539# - ##786# - ##72786# - ##3282# - ##33284# - ##3424# - ##564# - ##4567257# - ##873283# - ##6343# - ##27263# - ##258# - ##8422# - ##4382# - com.motorola.intent.action.LAUNCH_HIDDEN_MENU + - - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - com.motorola.android.intent.action.omadm.sprint.hfa - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - @string/motorola_hidden_menu_intent - - - ##[0-9]{6}# - - @string/motorola_hidden_menu_intent