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

Commit 3083cf5e authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Handle potential IllegalStateExceptions in Telecom.

The EmergencyNumber APIs can potentially throw an IllegalStateException
in some cases.  Adding catch blocks to ensure they don't crash Telecom.

Test: Run telecom unit tests.
Bug: 134100020
Change-Id: Ia24725be3be6124cdb4d29bc7dd900722363766d
parent 97acc377
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -1176,8 +1176,14 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
            // Let's not allow resetting of the emergency flag. Once a call becomes an emergency
            // call, it will remain so for the rest of it's lifetime.
            if (!mIsEmergencyCall) {
                try {
                    mIsEmergencyCall = mHandle != null &&
                        getTelephonyManager().isEmergencyNumber(mHandle.getSchemeSpecificPart());
                            getTelephonyManager().isEmergencyNumber(
                                    mHandle.getSchemeSpecificPart());
                } catch (IllegalStateException ise) {
                    Log.e(this, ise, "setHandle: can't determine if number is emergency");
                    mIsEmergencyCall = false;
                }
                mAnalytics.setCallIsEmergency(mIsEmergencyCall);
            }
            if (!mIsTestEmergencyCall) {
@@ -1192,11 +1198,16 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
    }

    private boolean isTestEmergencyCall(String number) {
        Map<Integer, List<EmergencyNumber>> eMap = getTelephonyManager().getEmergencyNumberList();
        try {
            Map<Integer, List<EmergencyNumber>> eMap =
                    getTelephonyManager().getEmergencyNumberList();
            return eMap.values().stream().flatMap(Collection::stream)
                    .anyMatch(eNumber ->
                            eNumber.isFromSources(EmergencyNumber.EMERGENCY_NUMBER_SOURCE_TEST) &&
                                    number.equals(eNumber.getNumber()));
        } catch (IllegalStateException ise) {
            return false;
        }
    }

    public String getCallerDisplayName() {
+11 −3
Original line number Diff line number Diff line
@@ -1943,13 +1943,22 @@ public class CallsManager extends Call.ListenerBase

        boolean endEarly = false;
        String disconnectReason = "";

        String callRedirectionApp = mRoleManagerAdapter.getDefaultCallRedirectionApp();

        boolean isPotentialEmergencyNumber;
        try {
            isPotentialEmergencyNumber =
                    handle != null && getTelephonyManager().isPotentialEmergencyNumber(
                            handle.getSchemeSpecificPart());
        } catch (IllegalStateException ise) {
            isPotentialEmergencyNumber = false;
        }

        if (shouldCancelCall) {
            Log.w(this, "onCallRedirectionComplete: call is canceled");
            endEarly = true;
            disconnectReason = "Canceled from Call Redirection Service";

            // Show UX when user-defined call redirection service does not response; the UX
            // is not needed to show if the call is disconnected (e.g. by the user)
            if (uiAction.equals(CallRedirectionProcessor.UI_TYPE_USER_DEFINED_TIMEOUT)
@@ -1970,8 +1979,7 @@ public class CallsManager extends Call.ListenerBase
            Log.w(this, "onCallRedirectionComplete: phoneAccountHandle is null");
            endEarly = true;
            disconnectReason = "Null phoneAccountHandle from Call Redirection Service";
        } else if (getTelephonyManager().isPotentialEmergencyNumber(
                handle.getSchemeSpecificPart())) {
        } else if (isPotentialEmergencyNumber) {
            Log.w(this, "onCallRedirectionComplete: emergency number %s is redirected from Call"
                    + " Redirection Service", handle.getSchemeSpecificPart());
            endEarly = true;
+7 −3
Original line number Diff line number Diff line
@@ -70,8 +70,12 @@ public final class TelephonyUtil {
    }

    public static boolean shouldProcessAsEmergency(Context context, Uri handle) {
        try {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(
                    Context.TELEPHONY_SERVICE);
            return handle != null && tm.isEmergencyNumber(handle.getSchemeSpecificPart());
        } catch (IllegalStateException ise) {
            return false;
        }
    }
}