use telephony API to sent secret dial code

Telephony provides an API to send secret code broadcast in a
bgcheck compliant way.

Bug:33753947
Test: Manual
Change-Id: Ibe0968a193c026f8a234af88ad5e72beebaa83f4
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 52c5621..4e4dc30 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2066,6 +2066,30 @@
     }
 
     /**
+     * Send the dialer code if called from the current default dialer and the input code follows the
+     * format of *#*#<code>#*#*
+     * <p>
+     * Requires Permission:
+     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
+     *
+     * @param inputCode The dialer code to send
+     * @return true if successfully sent, false otherwise
+     */
+    @Override
+    public boolean sendDialerCode(String callingPackage, String inputCode) {
+        enforceModifyPermission();
+        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+        if (TextUtils.equals(callingPackage,
+                TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
+            final Phone phone = getPhone(getDefaultSubscription());
+            if (phone != null) {
+                return phone.sendDialerCode(inputCode);
+            }
+        }
+        return false;
+    }
+
+    /**
      * Returns the data network type.
      * Legacy call, permission-free.
      *
diff --git a/src/com/android/phone/SpecialCharSequenceMgr.java b/src/com/android/phone/SpecialCharSequenceMgr.java
index 4e2120e..2aa1043 100644
--- a/src/com/android/phone/SpecialCharSequenceMgr.java
+++ b/src/com/android/phone/SpecialCharSequenceMgr.java
@@ -108,7 +108,7 @@
             || handleRegulatoryInfoDisplay(context, dialString)
             || handlePinEntry(context, dialString, pukInputActivity)
             || handleAdnEntry(context, dialString)
-            || handleSecretCode(context, dialString)) {
+            || handleSecretCode(dialString)) {
             return true;
         }
 
@@ -143,25 +143,16 @@
     }
 
     /**
-     * Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*.
-     * If a secret code is encountered an Intent is started with the android_secret_code://<code>
-     * URI.
+     * Handles secret codes to launch arbitrary receivers in the form of *#*#<code>#*#*.
+     * If a secret code is encountered, an broadcast intent is sent 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
+     * @return true if a secret code was encountered and intent is sent out
      */
-    static private boolean handleSecretCode(Context context, String input) {
-        // Secret codes are in the form *#*#<code>#*#*
-        int len = input.length();
-        if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
-            Intent intent = new Intent(TelephonyIntents.SECRET_CODE_ACTION,
-                    Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
-            context.sendBroadcast(intent);
-            return true;
-        }
-
-        return false;
+    static private boolean handleSecretCode(String input) {
+        Phone phone = PhoneGlobals.getPhone();
+        return phone.sendDialerCode(input);
     }
 
     static private boolean handleAdnEntry(Context context, String input) {