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

Commit 55df2858 authored by Thomas Nguyen's avatar Thomas Nguyen
Browse files

Fix NPE in SatelliteSessionController and TelephonyCountryDetector

Flag: EXEMPT bugfix
Bug: 405381601
Test: SatelliteManagerTestOnMockService SatelliteSessionControllerTest TelephonyCountryDetectorTest
Manual system tests

Change-Id: Ie090638f6682cc02e5961e6e7e2d70acf0bfde9b
parent 53895b42
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -236,7 +236,15 @@ public class TelephonyCountryDetector extends Handler {
        }

        List<String> result = new ArrayList<>();
        for (Phone phone : PhoneFactory.getPhones()) {
        Phone[] phones;
        try {
            phones = PhoneFactory.getPhones();
        } catch (IllegalStateException e) {
            logd("getCurrentNetworkCountryIso: PhoneFactory.getPhones() failed, e=" + e);
            return result;
        }

        for (Phone phone : phones) {
            String countryIso = getNetworkCountryIsoForPhone(phone);
            if (isValid(countryIso)) {
                String countryIsoInUpperCase = countryIso.toUpperCase(Locale.US);
+19 −4
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.flags.FeatureFlags;
import com.android.internal.telephony.satellite.metrics.SessionMetricsStats;
import com.android.internal.telephony.util.ArrayUtils;
import com.android.internal.util.IState;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.telephony.Rlog;
@@ -623,8 +624,15 @@ public class SatelliteSessionController extends StateMachine {
     * @return {@code true} if state machine is in enabling state and {@code false} otherwise.
     */
    public boolean isInEnablingState() {
        if (DBG) plogd("isInEnablingState: getCurrentState=" + getCurrentState());
        return getCurrentState() == mEnablingState;
        try {
            IState currentState = getCurrentState();
            if (DBG) plogd("isInEnablingState: getCurrentState=" + currentState);
            return currentState == mEnablingState;
        } catch (Exception e) {
            plogw("isInEnablingState: Exception: " + e
                + ", mCurrentState=" + mCurrentState);
            return mCurrentState == SatelliteManager.SATELLITE_MODEM_STATE_ENABLING_SATELLITE;
        }
    }

    /**
@@ -633,8 +641,15 @@ public class SatelliteSessionController extends StateMachine {
     * @return {@code true} if state machine is in disabling state and {@code false} otherwise.
     */
    public boolean isInDisablingState() {
        if (DBG) plogd("isInDisablingState: getCurrentState=" + getCurrentState());
        return getCurrentState() == mDisablingState;
        try {
            IState currentState = getCurrentState();
            if (DBG) plogd("isInDisablingState: getCurrentState=" + currentState);
            return currentState == mDisablingState;
        } catch (Exception e) {
            plogw("isInDisablingState: Exception: " + e
                + ", mCurrentState=" + mCurrentState);
            return mCurrentState == SatelliteManager.SATELLITE_MODEM_STATE_DISABLING_SATELLITE;
        }
    }

    /**
+7 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class TelephonyCountryDetectorTest extends TelephonyTest {
        mTestableLooper = new TestableLooper(mLooper);

        mLocaleTrackers = new LocaleTracker[]{mMockLocaleTracker, mMockLocaleTracker2};
        replaceInstance(PhoneFactory.class, "sMadeDefaults", null, true);
        replaceInstance(PhoneFactory.class, "sPhones", null, new Phone[] {mPhone, mPhone2});
        when(mPhone.getServiceStateTracker()).thenReturn(mSST);
        when(mPhone.getPhoneId()).thenReturn(0);
@@ -196,6 +197,12 @@ public class TelephonyCountryDetectorTest extends TelephonyTest {
        assertTrue(mCountryDetectorUT.getCurrentNetworkCountryIso().contains("CA"));
    }

    @Test
    public void testGetCurrentNetworkCountryIso_DefaultPhoneNotCreated() throws Exception {
        replaceInstance(PhoneFactory.class, "sMadeDefaults", null, false);
        assertTrue(mCountryDetectorUT.getCurrentNetworkCountryIso().isEmpty());
    }

    @Test
    public void testCachedNetworkCountryCodeUpdate() {
        assertTrue(mCountryDetectorUT.getCachedNetworkCountryIsoInfo().isEmpty());