Search in sources :

Example 1 with UiccSlotInfo

use of android.telephony.UiccSlotInfo in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionController method enablePhysicalSubscription.

private boolean enablePhysicalSubscription(SubscriptionInfo info, boolean enable) {
    if (info == null || !SubscriptionManager.isValidSubscriptionId(info.getSubscriptionId())) {
        return false;
    }
    int subId = info.getSubscriptionId();
    UiccSlotInfo slotInfo = null;
    int physicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
    UiccSlotInfo[] slotsInfo = mTelephonyManager.getUiccSlotsInfo();
    if (slotsInfo == null)
        return false;
    for (int i = 0; i < slotsInfo.length; i++) {
        UiccSlotInfo curSlotInfo = slotsInfo[i];
        if (curSlotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT) {
            if (TextUtils.equals(IccUtils.stripTrailingFs(curSlotInfo.getCardId()), IccUtils.stripTrailingFs(info.getCardString()))) {
                slotInfo = curSlotInfo;
                physicalSlotIndex = i;
                break;
            }
        }
    }
    // Can't find the existing SIM.
    if (slotInfo == null)
        return false;
    if (enable && !slotInfo.getIsActive()) {
        // We need to send intents to Euicc if we are turning on an inactive slot.
        // Euicc will decide whether to ask user to switch to DSDS, or change SIM
        // slot mapping.
        EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE);
        if (euiccManager != null && euiccManager.isEnabled()) {
            enableSubscriptionOverEuiccManager(subId, enable, physicalSlotIndex);
        } else {
            // Enable / disable uicc applications.
            if (!info.areUiccApplicationsEnabled())
                setUiccApplicationsEnabled(enable, subId);
            // or switch slot if not.
            if (mTelephonyManager.isMultiSimSupported() == MULTISIM_ALLOWED) {
                PhoneConfigurationManager.getInstance().switchMultiSimConfig(mTelephonyManager.getSupportedModemCount());
            } else {
                UiccController.getInstance().switchSlots(new int[] { physicalSlotIndex }, null);
            }
        }
        return true;
    } else {
        // Enable / disable uicc applications.
        setUiccApplicationsEnabled(enable, subId);
        return true;
    }
}
Also used : EuiccManager(android.telephony.euicc.EuiccManager) UiccSlotInfo(android.telephony.UiccSlotInfo)

Example 2 with UiccSlotInfo

use of android.telephony.UiccSlotInfo in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionControllerTest method testSetSubscriptionEnabled_disableActivePsim_cardIdWithTrailingF.

@Test
public void testSetSubscriptionEnabled_disableActivePsim_cardIdWithTrailingF() {
    String iccId = "123F";
    mSubscriptionControllerUT.addSubInfoRecord(iccId, 0);
    mSubscriptionControllerUT.registerForUiccAppsEnabled(mHandler, 0, null, false);
    UiccSlotInfo slot = getFakeUiccSlotInfo(true, 0, iccId + "FF");
    UiccSlotInfo[] uiccSlotInfos = { slot };
    doReturn(uiccSlotInfos).when(mTelephonyManager).getUiccSlotsInfo();
    mSubscriptionControllerUT.setSubscriptionEnabled(false, 1);
    verify(mHandler).sendMessageAtTime(any(), anyLong());
    assertFalse(mSubscriptionControllerUT.getActiveSubscriptionInfo(1, mContext.getOpPackageName(), null).areUiccApplicationsEnabled());
}
Also used : UiccSlotInfo(android.telephony.UiccSlotInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlakyTest(androidx.test.filters.FlakyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 3 with UiccSlotInfo

use of android.telephony.UiccSlotInfo in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionControllerTest method testGetEnabledSubscriptionIdDualSIM.

@Test
public void testGetEnabledSubscriptionIdDualSIM() {
    doReturn(SINGLE_SIM).when(mTelephonyManager).getSimCount();
    doReturn(SINGLE_SIM).when(mTelephonyManager).getPhoneCount();
    doReturn(SINGLE_SIM).when(mTelephonyManager).getActiveModemCount();
    // A dual SIM device may have logical slot 0 mapped to physical slot 0
    // (i.e. logical slot 1 mapped to physical slot 1)
    UiccSlotInfo slot0 = getFakeUiccSlotInfo(true, 0);
    UiccSlotInfo slot1 = getFakeUiccSlotInfo(true, 1);
    UiccSlotInfo[] uiccSlotInfos = { slot0, slot1 };
    UiccSlot[] uiccSlots = { mUiccSlot, mUiccSlot };
    doReturn(2).when(mTelephonyManager).getPhoneCount();
    doReturn(2).when(mTelephonyManager).getActiveModemCount();
    doReturn(uiccSlotInfos).when(mTelephonyManager).getUiccSlotsInfo();
    doReturn(uiccSlots).when(mUiccController).getUiccSlots();
    assertEquals(2, UiccController.getInstance().getUiccSlots().length);
    ContentResolver resolver = mContext.getContentResolver();
    // logical 0 should find physical 0, has settings enabled subscription 0
    Settings.Global.putInt(resolver, Settings.Global.ENABLED_SUBSCRIPTION_FOR_SLOT + 0, 0);
    Settings.Global.putInt(resolver, Settings.Global.ENABLED_SUBSCRIPTION_FOR_SLOT + 1, 1);
    int enabledSubscription = mSubscriptionControllerUT.getEnabledSubscriptionId(0);
    int secondEabledSubscription = mSubscriptionControllerUT.getEnabledSubscriptionId(1);
    assertEquals(0, enabledSubscription);
    assertEquals(1, secondEabledSubscription);
}
Also used : UiccSlotInfo(android.telephony.UiccSlotInfo) UiccSlot(com.android.internal.telephony.uicc.UiccSlot) ContentResolver(android.content.ContentResolver) MockContentResolver(android.test.mock.MockContentResolver) FlakyTest(androidx.test.filters.FlakyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 4 with UiccSlotInfo

use of android.telephony.UiccSlotInfo in project android_packages_apps_Settings by omnirom.

the class UiccSlotUtil method switchToRemovableSlot.

/**
 * Switches to the removable slot. It waits for SIM_STATE_LOADED after switch. If slotId is
 * INVALID_PHYSICAL_SLOT_ID, the method will use the first detected inactive removable slot.
 *
 * @param slotId the physical removable slot id.
 * @param context the application context.
 * @throws UiccSlotsException if there is an error.
 */
public static synchronized void switchToRemovableSlot(int slotId, Context context) throws UiccSlotsException {
    if (ThreadUtils.isMainThread()) {
        throw new IllegalThreadStateException("Do not call switchToRemovableSlot on the main thread.");
    }
    TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
    if (telMgr.isMultiSimEnabled()) {
        // If this device supports multiple active slots, don't mess with TelephonyManager.
        Log.i(TAG, "Multiple active slots supported. Not calling switchSlots.");
        return;
    }
    UiccSlotInfo[] slots = telMgr.getUiccSlotsInfo();
    if (slotId == INVALID_PHYSICAL_SLOT_ID) {
        for (int i = 0; i < slots.length; i++) {
            if (slots[i].isRemovable() && !slots[i].getIsActive() && slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR && slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) {
                performSwitchToRemovableSlot(i, context);
                return;
            }
        }
    } else {
        if (slotId >= slots.length || !slots[slotId].isRemovable()) {
            throw new UiccSlotsException("The given slotId is not a removable slot: " + slotId);
        }
        if (!slots[slotId].getIsActive()) {
            performSwitchToRemovableSlot(slotId, context);
        }
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) UiccSlotInfo(android.telephony.UiccSlotInfo)

Example 5 with UiccSlotInfo

use of android.telephony.UiccSlotInfo in project android_packages_apps_Settings by omnirom.

the class SimSlotChangeReceiver method isSimSlotStateValid.

// Checks whether the SIM slot state is valid for slot change event.
private boolean isSimSlotStateValid(Context context) {
    final TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
    UiccSlotInfo[] slotInfos = telMgr.getUiccSlotsInfo();
    if (slotInfos == null) {
        Log.e(TAG, "slotInfos is null. Unable to get slot infos.");
        return false;
    }
    boolean isAllCardStringsEmpty = true;
    for (int i = 0; i < slotInfos.length; i++) {
        UiccSlotInfo slotInfo = slotInfos[i];
        if (slotInfo == null) {
            return false;
        }
        // RESTRICTED.
        if (slotInfo.getCardStateInfo() == UiccSlotInfo.CARD_STATE_INFO_ERROR || slotInfo.getCardStateInfo() == UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) {
            Log.i(TAG, "The SIM state is in an error. Drop the event. SIM info: " + slotInfo);
            return false;
        }
        UiccCardInfo cardInfo = findUiccCardInfoBySlot(telMgr, i);
        if (cardInfo == null) {
            continue;
        }
        if (!TextUtils.isEmpty(slotInfo.getCardId()) || !TextUtils.isEmpty(cardInfo.getIccId())) {
            isAllCardStringsEmpty = false;
        }
    }
    // between SIM slots switch the slot status is not stable at this moment.
    if (isAllCardStringsEmpty) {
        Log.i(TAG, "All UICC card strings are empty. Drop this event.");
        return false;
    }
    return true;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) UiccSlotInfo(android.telephony.UiccSlotInfo) UiccCardInfo(android.telephony.UiccCardInfo)

Aggregations

UiccSlotInfo (android.telephony.UiccSlotInfo)15 Test (org.junit.Test)6 SubscriptionInfo (android.telephony.SubscriptionInfo)4 TelephonyManager (android.telephony.TelephonyManager)3 SmallTest (android.test.suitebuilder.annotation.SmallTest)3 FlakyTest (androidx.test.filters.FlakyTest)3 ContentResolver (android.content.ContentResolver)2 MockContentResolver (android.test.mock.MockContentResolver)2 UiccSlot (com.android.internal.telephony.uicc.UiccSlot)2 ArrayList (java.util.ArrayList)2 SubscriptionManager (android.telephony.SubscriptionManager)1 UiccCardInfo (android.telephony.UiccCardInfo)1 EuiccManager (android.telephony.euicc.EuiccManager)1 ArraySet (android.util.ArraySet)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Config (org.robolectric.annotation.Config)1