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

Commit c7feba78 authored by Mengjun Leng's avatar Mengjun Leng Committed by Tyler Gunn
Browse files

Add APIs for call connected indicator

When a call is connected, device can start playing a tone or vibrating
to prompt user the call status, especially when device is near to ear.

Test: manual
Test: atest RingerTest & CallConnectedIndicatorSettingsTest
Bug: 146090790
Bug: 405460896
Flag: com.android.server.telecom.flags.call_connected_indicator_preference

Change-Id: I8377a7c80e8125a7cf44573f86ce864d52872285
parent 31d43b4d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -14887,6 +14887,7 @@ package android.telecom {
    method public int getAllPhoneAccountsCount();
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List<android.telecom.PhoneAccountHandle> getCallCapablePhoneAccounts(boolean);
    method @FlaggedApi("com.android.internal.telephony.flags.work_profile_api_split") @NonNull @RequiresPermission(allOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.INTERACT_ACROSS_PROFILES}) public java.util.List<android.telecom.PhoneAccountHandle> getCallCapablePhoneAccountsAcrossProfiles(boolean);
    method @FlaggedApi("com.android.server.telecom.flags.call_connected_indicator_preference") @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getCallConnectedIndicatorPreference();
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}, conditional=true) public int getCallState();
    method public android.telecom.PhoneAccountHandle getConnectionManager();
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getCurrentTtyMode();
@@ -14897,9 +14898,13 @@ package android.telecom {
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean isInEmergencyCall();
    method @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") @RequiresPermission(allOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isInSelfManagedCall(@NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isRinging();
    method @FlaggedApi("com.android.server.telecom.flags.call_connected_indicator_preference") @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setCallConnectedIndicatorPreference(int);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setUserSelectedOutgoingPhoneAccount(@Nullable android.telecom.PhoneAccountHandle);
    field public static final String ACTION_CURRENT_TTY_MODE_CHANGED = "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
    field public static final String ACTION_TTY_PREFERRED_MODE_CHANGED = "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
    field @FlaggedApi("com.android.server.telecom.flags.call_connected_indicator_preference") public static final int CALL_CONNECTED_INDICATOR_NONE = 0; // 0x0
    field @FlaggedApi("com.android.server.telecom.flags.call_connected_indicator_preference") public static final int CALL_CONNECTED_INDICATOR_TONE = 1; // 0x1
    field @FlaggedApi("com.android.server.telecom.flags.call_connected_indicator_preference") public static final int CALL_CONNECTED_INDICATOR_VIBRATION = 2; // 0x2
    field public static final int CALL_SOURCE_EMERGENCY_DIALPAD = 1; // 0x1
    field public static final int CALL_SOURCE_EMERGENCY_SHORTCUT = 2; // 0x2
    field public static final int CALL_SOURCE_UNSPECIFIED = 0; // 0x0
+101 −0
Original line number Diff line number Diff line
@@ -1122,6 +1122,55 @@ public class TelecomManager {
    /** @hide **/
    public static final String TRANSACTION_CALL_ID_KEY = "TelecomCallId";

    /**
     * Indicates that when a call moves from {@link android.telecom.Call#STATE_DIALING} to
     * {@link android.telecom.Call#STATE_ACTIVE}, the system should not generate any call connected
     * indication.
     * <p>
     * Used with {@link #setCallConnectedIndicatorPreference and
     * {@link #getCallConnectedIndicatorPreference()}.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_CALL_CONNECTED_INDICATOR_PREFERENCE)
    public static final int CALL_CONNECTED_INDICATOR_NONE = 0;

    /**
     * Indicates that when a call moves from {@link android.telecom.Call#STATE_DIALING} to
     * {@link android.telecom.Call#STATE_ACTIVE}, the system should play a tone which indicates that
     * the call has connected.
     * <p>
     * Used with {@link #setCallConnectedIndicatorPreference and
     * {@link #getCallConnectedIndicatorPreference()}.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_CALL_CONNECTED_INDICATOR_PREFERENCE)
    public static final int CALL_CONNECTED_INDICATOR_TONE = (1 << 0);

    /**
     * Indicates that when a call moves from {@link android.telecom.Call#STATE_DIALING} to
     * {@link android.telecom.Call#STATE_ACTIVE}, the system should make a haptic vibration which
     * indicates that the call has connected.
     * <p>
     * Used with {@link #setCallConnectedIndicatorPreference and
     * {@link #getCallConnectedIndicatorPreference()}.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_CALL_CONNECTED_INDICATOR_PREFERENCE)
    public static final int CALL_CONNECTED_INDICATOR_VIBRATION = (1 << 1);

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @FlaggedApi(Flags.FLAG_CALL_CONNECTED_INDICATOR_PREFERENCE)
    @IntDef(
            prefix = {"CALL_CONNECTED_INDICATOR_"},
            flag = true,
            value = {CALL_CONNECTED_INDICATOR_NONE, CALL_CONNECTED_INDICATOR_TONE,
                    CALL_CONNECTED_INDICATOR_VIBRATION})
    public @interface CallConnectedIndicator {}

    /**
     * @hide
     */
@@ -2994,6 +3043,58 @@ public class TelecomManager {
        }
    }

    /**
     * Retrieves the user's chosen call connected indicator preference.
     * <p>
     * See {@link #setCallConnectedIndicatorPreference(int)} for more information.
     * @return Returns the current preference for the call connected indicator.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_CALL_CONNECTED_INDICATOR_PREFERENCE)
    @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
    public @CallConnectedIndicator int getCallConnectedIndicatorPreference() {
        ITelecomService service = getTelecomService();
        if (service != null) {
            try {
                return service.getCallConnectedIndicatorPreference(mContext.getOpPackageName());
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException getCallConnectedIndicatorPreference: " + e);
                throw e.rethrowFromSystemServer();
            }
        }
        throw new IllegalStateException("Telecom is not available");
    }

    /**
     * Specifies the user's call connected indicator preference.
     * <p>
     * When a call transitions from {@link android.telecom.Call#STATE_DIALING} to
     * {@link android.telecom.Call#STATE_ACTIVE}, the system can indicate that the call has
     * connected by playing a call connected tone and/or generating a haptic vibration.
     * @param preference The preference of the call connected indicator.
     * @throws IllegalArgumentException if an invalid preference is specified.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_CALL_CONNECTED_INDICATOR_PREFERENCE)
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setCallConnectedIndicatorPreference(@CallConnectedIndicator int preference) {
        ITelecomService service = getTelecomService();
        if (service != null) {
            try {
                service.setCallConnectedIndicatorPreference(
                        mContext.getOpPackageName(), preference);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException setCallConnectedIndicatorPreference: " + e);
                throw e.rethrowFromSystemServer();
            }
        } else {
            throw new IllegalStateException("Telecom is not available");
        }
    }


    private boolean isSystemProcess() {
        return Process.myUid() == Process.SYSTEM_UID;
    }
+10 −0
Original line number Diff line number Diff line
@@ -421,4 +421,14 @@ interface ITelecomService {
     * @see TelecomServiceImpl#waitForAudioToUpdate
     */
     void waitForAudioToUpdate(boolean expectActive);

    /*
     * @see TelecomServiceImpl#getCallConnectedIndicatorPreference
     */
    int getCallConnectedIndicatorPreference(in String callingPackage);

    /**
     * @see TelecomServiceImpl#setCallConnectedIndicatorPreference
     */
    void setCallConnectedIndicatorPreference(in String callingPackage, in int preference);
}