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

Commit c5bb3c1c authored by Humza Azam's avatar Humza Azam
Browse files

Wait for card presence before starting OTA

Bug: 130657563
Test: Built and succesfully checked for OTA
      atest FrameworksTelephonyTest:EuiccCardControllerTest
Change-Id: Iad5a7397f7508a930b6aa180da35ce84d6c7b3a5
Merged-In: Iad5a7397f7508a930b6aa180da35ce84d6c7b3a5
(cherry picked from commit 8b2d1e44)
parent 554b825b
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -69,6 +69,11 @@ public class EuiccCardController extends IEuiccCardController.Stub {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED.equals(intent.getAction())) {
                // We want to keep listening if card is not present yet since the first state might
                // be an error state
                if (!isEmbeddedCardPresent()) {
                    return;
                }
                if (isEmbeddedSlotActivated()) {
                    mEuiccController.startOtaUpdatingIfNecessary();
                }
@@ -160,6 +165,24 @@ public class EuiccCardController extends IEuiccCardController.Stub {
        return false;
    }

    /** Whether embedded card is present or not */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public boolean isEmbeddedCardPresent() {
        UiccSlot[] slots = mUiccController.getUiccSlots();
        if (slots == null) {
            return false;
        }
        for (UiccSlot slotInfo : slots) {
            if (slotInfo != null
                    && !slotInfo.isRemovable()
                    && slotInfo.getCardState() != null
                    && slotInfo.getCardState().isCardPresent()) {
                return true;
            }
        }
        return false;
    }

    private void checkCallingPackage(String callingPackage) {
        // Check the caller is LPA.
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ public class IccCardStatus {
        CARDSTATE_RESTRICTED;

        @UnsupportedAppUsage
        boolean isCardPresent() {
        public boolean isCardPresent() {
            return this == CARDSTATE_PRESENT ||
                this == CARDSTATE_RESTRICTED;
        }
+51 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.telephony.euicc.EuiccManager;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.uicc.IccCardStatus.CardState;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccSlot;

@@ -62,6 +63,8 @@ public class EuiccCardControllerTest extends TelephonyTest {
    @Mock
    private UiccSlot mActivatedEsimSlot;
    @Mock
    private UiccSlot mNotPresentEsimSlot;
    @Mock
    private UiccSlot mActivatedRemovableSlot;
    @Mock
    private EuiccController mEuiccController;
@@ -96,6 +99,10 @@ public class EuiccCardControllerTest extends TelephonyTest {
        when(mTelephonyManager.getPhoneCount()).thenReturn(1);
        when(mActivatedEsimSlot.isEuicc()).thenReturn(true);
        when(mActivatedEsimSlot.isActive()).thenReturn(true);
        when(mActivatedEsimSlot.getCardState()).thenReturn(CardState.CARDSTATE_PRESENT);
        when(mNotPresentEsimSlot.isEuicc()).thenReturn(true);
        when(mNotPresentEsimSlot.isActive()).thenReturn(true);
        when(mNotPresentEsimSlot.getCardState()).thenReturn(CardState.CARDSTATE_ERROR);
        when(mInactivatedEsimSlot.isEuicc()).thenReturn(true);
        when(mInactivatedEsimSlot.isActive()).thenReturn(false);
        when(mInactivatedEsimSlot.isRemovable()).thenReturn(false);
@@ -164,7 +171,34 @@ public class EuiccCardControllerTest extends TelephonyTest {
    }

    @Test
    public void testStartOtaUpdatingIfNecessary_onEmbeddedSlot() {
    public void testIsEmbeddedCardPresent() {
        mEuiccCardController =
                new EuiccCardController(mContext, null, mEuiccController, mUiccController);
        when(mUiccController.getUiccSlots())
                .thenReturn(new UiccSlot[] {mActivatedRemovableSlot});
        assertFalse(mEuiccCardController.isEmbeddedCardPresent());

        when(mUiccController.getUiccSlots())
                .thenReturn(new UiccSlot[] {mActivatedEsimSlot});
        assertTrue(mEuiccCardController.isEmbeddedCardPresent());

        when(mUiccController.getUiccSlots())
                .thenReturn(new UiccSlot[] {mNotPresentEsimSlot});
        assertFalse(mEuiccCardController.isEmbeddedCardPresent());

        when(mUiccController.getUiccSlots())
                .thenReturn(new UiccSlot[] {
                        mActivatedEsimSlot, mNotPresentEsimSlot, mActivatedRemovableSlot});
        assertTrue(mEuiccCardController.isEmbeddedCardPresent());

        when(mUiccController.getUiccSlots())
                .thenReturn(new UiccSlot[] {
                        mNotPresentEsimSlot, mActivatedEsimSlot, mActivatedRemovableSlot});
        assertTrue(mEuiccCardController.isEmbeddedCardPresent());
    }

    @Test
    public void testStartOtaUpdatingIfNecessary_onEmbeddedSlot_Present() {
        // isBootUp = true
        mSp.edit().remove(KEY_LAST_BOOT_COUNT);
        Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.BOOT_COUNT, 0);
@@ -179,6 +213,22 @@ public class EuiccCardControllerTest extends TelephonyTest {
        } catch (InterruptedException ignore) { }
    }

    @Test
    public void testStartOtaUpdatingIfNecessary_onEmbeddedSlot_NotPresent() {
        // isBootUp = true
        mSp.edit().remove(KEY_LAST_BOOT_COUNT);
        Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.BOOT_COUNT, 0);
        when(mUiccController.getUiccSlots()).thenReturn(new UiccSlot[] {mNotPresentEsimSlot});

        mEuiccCardController =
            new EuiccCardController(mContext, null, mEuiccController, mUiccController);
        mContext.sendBroadcast(new Intent(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED));
        try {
            mOtaLatch.await(5000, TimeUnit.MILLISECONDS);
            assertFalse(mOtaStarted);
        } catch (InterruptedException ignore) { }
    }

    @Test
    public void testStartOtaUpdatingIfNecessary_notBootUp() {
        // isBootUp = false