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

Commit c5bfbfbd authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix potential Telecom crash if TelephonyManager throws exception.

TelephonyManager#isPotentialEmergencyNumber can throw an
IllegalStateException, and it can also rethrow remote exceptions.
Catching all is a safe means to prevent Telecom from crashing in either
case.

Fixes: 145790936
Test: Run unit test
Change-Id: Ib5556db72b02c3e113ded2bf6c61d0353e60a3b9
parent 44a7e4f1
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -519,7 +519,13 @@ public class NewOutgoingCallIntentBroadcaster {
    private boolean isPotentialEmergencyNumber(String number) {
        Log.v(this, "Checking restrictions for number : %s", Log.pii(number));
        if (number == null) return false;
        return mContext.getSystemService(TelephonyManager.class).isPotentialEmergencyNumber(number);
        try {
            return mContext.getSystemService(TelephonyManager.class).isPotentialEmergencyNumber(
                    number);
        } catch (Exception e) {
            Log.e(this, e, "isPotentialEmergencyNumber: Telephony threw an exception.");
            return false;
        }
    }

    /**
+14 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNotNull;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -49,6 +50,7 @@ import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.telephony.DisconnectCause;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.server.telecom.Call;
@@ -429,6 +431,18 @@ public class NewOutgoingCallIntentBroadcasterTest extends TelecomTestCase {
        verify(mCall).disconnect(eq(0L));
    }

    /**
     * Ensure if {@link TelephonyManager#isPotentialEmergencyNumber(String)} throws an exception of
     * any sort that we don't crash Telecom.
     */
    @SmallTest
    @Test
    public void testThrowOnIsPotentialEmergencyNumber() {
        doThrow(new IllegalStateException()).when(mComponentContextFixture.getTelephonyManager())
                .isPotentialEmergencyNumber(anyString());
        testUnmodifiedRegularCall();
    }

    private ReceiverIntentPair regularCallTestHelper(Intent intent,
            Bundle expectedAdditionalExtras) {
        Uri handle = intent.getData();