Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddf21679 authored by fionaxu's avatar fionaxu
Browse files

add an API for sending secret dialer code

Telephony provides an public API for sending secret
dialer code with the format of *#*#code*#*#.
This API only sent out broadcast for the default dialer app
and is backgound-check compliant.

Bug:33753947
Test: Manual
Change-Id: I955f981bec2b74e18c711dfbed71c1bc746f76ce
parent 6a43e229
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -2232,6 +2232,30 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        return countVoiceMessages;
    }

    /**
     * send secret dialer 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.
     *
     * @param code the text to check for a secret code in
     * @return true if a secret code was encountered
     */
    public boolean sendDialerCode(String code) {
        // Secret dialer codes are in the form *#*#<code>#*#*
        if (TextUtils.isEmpty(code)) {
            return false;
        }
        int len = code.length();
        if (len > 8 && code.startsWith("*#*#") && code.endsWith("#*#*")) {
            Intent intent = new Intent(TelephonyIntents.SECRET_CODE_ACTION,
                    Uri.parse("android_secret_code://" + code.substring(4, len - 4)));
            intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            mContext.sendBroadcast(intent);
            return true;
        }
        return false;
    }

    /**
     * Returns the CDMA ERI icon index to display
     */