summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDiogo Ferreira <diogo@underdev.org>2015-02-03 12:57:48 +0000
committerDiogo Ferreira <diogo@underdev.org>2015-02-03 12:57:48 +0000
commit79736d66188d0408f50be63dbf3c6d796d694a63 (patch)
treea81ef8822a5411a984485e421053ff4956ebbb22 /src
parent1efcafdc30686e013fc3eaf68ab3f1dc8fe71723 (diff)
downloadandroid_packages_apps_Dialer-79736d66188d0408f50be63dbf3c6d796d694a63.tar.gz
android_packages_apps_Dialer-79736d66188d0408f50be63dbf3c6d796d694a63.tar.bz2
android_packages_apps_Dialer-79736d66188d0408f50be63dbf3c6d796d694a63.zip
Dialer: Add special code aliases
Android already has a mechanism for special codes that transforms *#*#<code>#*#* into intents that can be caught by special intent filters in application manifests. However, sometimes, we have requirements to provide specific codes to launch self-testing or factory-testing kinds of apps. Instead of adding all those and associating them with intents, this patch adds aliases that are treated the same way as the built-in special codes. This works by configuring two arrays: - special_code_aliases: The codes (such as *#123#, ##100#, etc, any will do). - special_code_mapping: The converted codes, usually these would be (123, 100, etc) but they are not necessarily the same numeric parts as the aliases. These should be configured by overriding the special codes per-device. Change-Id: I01dc06db3210a6b775144fa8c057cd7d0e58d85c
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/android/dialer/SpecialCharSequenceMgr.java55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/com/android/dialer/SpecialCharSequenceMgr.java b/src/com/android/dialer/SpecialCharSequenceMgr.java
index 01948fa6e..32027c0da 100755
--- a/src/com/android/dialer/SpecialCharSequenceMgr.java
+++ b/src/com/android/dialer/SpecialCharSequenceMgr.java
@@ -42,6 +42,9 @@ import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;
+import java.util.HashMap;
+import java.util.Map;
+
import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler;
import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.PhoneConstants;
@@ -85,6 +88,16 @@ public class SpecialCharSequenceMgr {
*/
private static QueryHandler sPreviousAdnQueryHandler;
+ /**
+ * A mapping of special codes to their representation. This is used to allow arbitrary codes
+ * like *#123# to be mapped to be recognized and trigger the same actions in the form *#*#123#*#*.
+ */
+ private static Map<String, String> sSecretCodeAliases;
+ /**
+ * Provides proper locking semantics for initializing the secret code aliases.
+ */
+ private static Object sSecretCodeAliasesLock = new Object();
+
/** This class is never instantiated. */
private SpecialCharSequenceMgr() {
}
@@ -108,7 +121,8 @@ public class SpecialCharSequenceMgr {
|| handleRegulatoryInfoDisplay(context, dialString)
|| handlePinEntry(context, dialString)
|| handleAdnEntry(context, dialString, textField)
- || handleSecretCode(context, dialString)) {
+ || handleSecretCode(context, dialString)
+ || handleSecretCodeAlias(context, dialString)) {
return true;
}
@@ -169,6 +183,20 @@ public class SpecialCharSequenceMgr {
}
/**
+ * Handles secret codes aliases, that are mapped to the regular android_secret_code intents.
+ * If a secret code is encountered an Intent is started with the android_secret_code://<code>
+ * URI.
+ *
+ * @param context the context to use
+ * @param input the text to check for a secret code in
+ * @return true if a secret code was encountered
+ */
+ static boolean handleSecretCodeAlias(Context context, String input) {
+ String mapping = getMapping(context).get(input);
+ return mapping == null ? false : handleSecretCode(context, "*#*#" + mapping + "#*#*");
+ }
+
+ /**
* Handle ADN requests by filling in the SIM contact number into the requested
* EditText.
*
@@ -412,6 +440,31 @@ public class SpecialCharSequenceMgr {
return sb.toString();
}
+ private static Map<String, String> getMapping(Context context) {
+ if (sSecretCodeAliases == null) {
+ synchronized (sSecretCodeAliasesLock) {
+ if (sSecretCodeAliases == null) {
+ String[] aliases = context.getResources()
+ .getStringArray(R.array.special_code_aliases);
+ String[] actual = context.getResources()
+ .getStringArray(R.array.special_code_mapping);
+ if (aliases == null || actual == null
+ || aliases.length != actual.length) {
+ // Fail fast, if this is overriden it must be done correctly.
+ throw new IllegalArgumentException(
+ "Aliases and their actual representation must have the same size");
+ }
+
+ sSecretCodeAliases = new HashMap<String, String>();
+ for (int i = 0; i < aliases.length; i++) {
+ sSecretCodeAliases.put(aliases[i], actual[i]);
+ }
+ }
+ }
+ }
+ return sSecretCodeAliases;
+ }
+
/*******
* This code is used to handle SIM Contact queries
*******/