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

Commit 388eab41 authored by fionaxu's avatar fionaxu
Browse files

sendDialerCode API review

1. address the feeback from API review:
throw exception rather than a boolean return
throw Security exception for permission denial and non-default dailer app.
throw invalidStateException if telephonyServie unavaialble.
2. sendDialerCode API will only check permission and package match without
enforcing the format of secret code(*#*# CODE #*#*) as throwing an unchecked
exception for wrong bad format seems to be an overkill regarding the API usage.
Dialer calls this API for each keyboard press to check format and send the intent
altogether which is no longer appropriate if we plan to return void and will
reduce frquent API calls.
3. allow callers with carrier privilege
4. not require MODIFY_PHONE_STATE as third party dialer apps won't be
granted
5. TODO mark android.provider.Telephony.SECRET_CODE to be protected
after calling apps move to this API.

Bug:35767402
Test: Manual
Change-Id: I8287aa93f2f79d356935a48cf808705d9b49984b
parent f9747661
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -40002,7 +40002,8 @@ package android.telephony {
    method public boolean isVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle);
    method public boolean isWorldPhone();
    method public void listen(android.telephony.PhoneStateListener, int);
    method public boolean sendDialerCode(java.lang.String);
    method public deprecated boolean sendDialerCode(java.lang.String);
    method public void sendDialerSpecialCode(java.lang.String);
    method public java.lang.String sendEnvelopeWithStatus(java.lang.String);
    method public void sendUssdRequest(java.lang.String, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler);
    method public void setDataEnabled(boolean);
+2 −1
Original line number Diff line number Diff line
@@ -43409,7 +43409,8 @@ package android.telephony {
    method public boolean isWorldPhone();
    method public void listen(android.telephony.PhoneStateListener, int);
    method public boolean needsOtaServiceProvisioning();
    method public boolean sendDialerCode(java.lang.String);
    method public deprecated boolean sendDialerCode(java.lang.String);
    method public void sendDialerSpecialCode(java.lang.String);
    method public java.lang.String sendEnvelopeWithStatus(java.lang.String);
    method public void sendUssdRequest(java.lang.String, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler);
    method public int setAllowedCarriers(int, java.util.List<android.service.carrier.CarrierIdentifier>);
+2 −1
Original line number Diff line number Diff line
@@ -40193,7 +40193,8 @@ package android.telephony {
    method public boolean isVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle);
    method public boolean isWorldPhone();
    method public void listen(android.telephony.PhoneStateListener, int);
    method public boolean sendDialerCode(java.lang.String);
    method public deprecated boolean sendDialerCode(java.lang.String);
    method public void sendDialerSpecialCode(java.lang.String);
    method public java.lang.String sendEnvelopeWithStatus(java.lang.String);
    method public void sendUssdRequest(java.lang.String, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler);
    method public void setDataEnabled(boolean);
+26 −1
Original line number Diff line number Diff line
@@ -3080,7 +3080,7 @@ public class TelephonyManager {
     *
     * @param inputCode The special dialer code to send which follows the format of *#*#<code>#*#*
     * @return true if sent sucessfully, false otherwise
     *
     * @deprecated use {@link #sendDialerSpecialCode(String)} ()} instead.
     */
    public boolean sendDialerCode(String inputCode) {
        try {
@@ -3096,6 +3096,31 @@ public class TelephonyManager {
        }
    }

    /**
     * Send the special dialer code. The IPC caller must be the current default dialer or has
     * carrier privileges.
     * @see #hasCarrierPrivileges
     *
     * @param inputCode The special dialer code to send
     *
     * @throws SecurityException if the caller does not have carrier privileges or is not the
     *         current default dialer
     *
     * @throws IllegalStateException if telephony service is unavailable.
     */
    public void sendDialerSpecialCode(String inputCode) {
        try {
            final ITelephony telephony = getITelephony();
            telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode);
        } catch (RemoteException ex) {
            // This could happen if binder process crashes.
            ex.rethrowFromSystemServer();
        } catch (NullPointerException ex) {
            // This could happen before phone restarts due to crashing
            throw new IllegalStateException("Telephony service unavailable");
        }
    }

    /**
     * Returns the IMS private user identity (IMPI) that was loaded from the ISIM.
     * @return the IMPI, or null if not present or not loaded
+3 −0
Original line number Diff line number Diff line
@@ -532,6 +532,9 @@ interface ITelephony {
    // Send the special dialer code. The IPC caller must be the current default dialer.
    boolean sendDialerCode(String callingPackageName, String inputCode);

    // Send the special dialer code. The IPC caller must be the current default dialer.
    void sendDialerSpecialCode(String callingPackageName, String inputCode);

    /**
     * Returns the network type for data transmission
     * Legacy call, permission-free