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

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

Fix potential crash when displaying MMI error result.

Newly added code made the incorrect assumption that an MMI result would
come back as an empty string if not supplied.
We've seen crashes in the field due to a null message string coming in.

Test: Code inspection / compilation.
Test: Wrote unit tests to check null handling in these cases.
Fixes: 191617795
Change-Id: I57d0227fd725f3ae19a2ce7290afc670bd88fd93
parent 51a08cb6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1228,7 +1228,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {
    onUssdFinishedError() {
        if (mState == State.PENDING) {
            mState = State.FAILED;
            if (mMessage.length() == 0) {
            if (TextUtils.isEmpty(mMessage)) {
                mMessage = mContext.getText(com.android.internal.R.string.mmiError);
            }
            Rlog.d(LOG_TAG, "onUssdFinishedError");
+4 −6
Original line number Diff line number Diff line
@@ -346,8 +346,8 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
        return dialString;
    }

    static ImsPhoneMmiCode
    newNetworkInitiatedUssd(String ussdMessage, boolean isUssdRequest, ImsPhone phone) {
    public static ImsPhoneMmiCode newNetworkInitiatedUssd(String ussdMessage,
            boolean isUssdRequest, ImsPhone phone) {
        ImsPhoneMmiCode ret;

        ret = new ImsPhoneMmiCode(phone);
@@ -1194,12 +1194,10 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
     *
     * The radio has reset, and this is still pending
     */

    void
    onUssdFinishedError() {
    public void onUssdFinishedError() {
        if (mState == State.PENDING) {
            mState = State.FAILED;
            if (mMessage.length() == 0) {
            if (TextUtils.isEmpty(mMessage)) {
                mMessage = mContext.getText(com.android.internal.R.string.mmiError);
            }
            Rlog.d(LOG_TAG, "onUssdFinishedError: mmi=" + this);
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony.gsm;

import static junit.framework.Assert.fail;

import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -95,6 +97,16 @@ public class GsmMmiCodeTest extends TelephonyTest {
        assertTrue(mGsmMmiCode == null);
    }

    @Test
    public void testNoCrashOnEmptyMessage() {
        GsmMmiCode mmi = GsmMmiCode.newNetworkInitiatedUssd(null, true, mGsmCdmaPhoneUT, null);
        try {
            mmi.onUssdFinishedError();
        } catch (Exception e) {
            fail("Shouldn't crash!!!");
        }
    }

    private void setCarrierSupportsCallerIdVerticalServiceCodesCarrierConfig() {
        final PersistableBundle bundle = new PersistableBundle();
        bundle.putBoolean(CarrierConfigManager
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony.imsphone;

import static junit.framework.Assert.fail;

import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -101,6 +103,16 @@ public class ImsPhoneMmiCodeTest extends TelephonyTest {
        assertTrue(mImsPhoneMmiCode == null);
    }

    @Test
    public void testNoCrashOnEmptyMessage() {
        ImsPhoneMmiCode mmi = ImsPhoneMmiCode.newNetworkInitiatedUssd(null, true, mImsPhoneUT);
        try {
            mmi.onUssdFinishedError();
        } catch (Exception e) {
            fail("Shouldn't crash!!!");
        }
    }

    private void setCarrierSupportsCallerIdVerticalServiceCodesCarrierConfig() {
        final PersistableBundle bundle = new PersistableBundle();
        bundle.putBoolean(CarrierConfigManager