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

Commit 18572586 authored by Jack Yu's avatar Jack Yu Committed by Android (Google) Code Review
Browse files

Merge "Support group disabled bit correctly"

parents 31f76468 a4950431
Loading
Loading
Loading
Loading
+32 −8
Original line number Diff line number Diff line
@@ -1221,8 +1221,8 @@ public class SubscriptionDatabaseManager extends Handler {
        try {
            SubscriptionInfoInternal subInfoCache = mAllSubscriptionInfoInternalCache.get(subId);
            if (subInfoCache == null) {
                throw new IllegalArgumentException("Subscription doesn't exist. subId=" + subId
                        + ", columnName=cardId");
                throw new IllegalArgumentException("setCardId: Subscription doesn't exist. subId="
                        + subId);
            }
            mAllSubscriptionInfoInternalCache.put(subId,
                    new SubscriptionInfoInternal.Builder(subInfoCache)
@@ -1763,6 +1763,36 @@ public class SubscriptionDatabaseManager extends Handler {
                SubscriptionInfoInternal.Builder::setSatelliteEnabled);
    }

    /**
     * Set whether group of the subscription is disabled. This is only useful if it's a grouped
     * opportunistic subscription. In this case, if all primary (non-opportunistic)
     * subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile),
     * we should disable this opportunistic subscription.
     *
     * @param subId Subscription id.
     * @param isGroupDisabled if group of the subscription is disabled.
     *
     * @throws IllegalArgumentException if the subscription does not exist.
     */
    public void setGroupDisabled(int subId, boolean isGroupDisabled) {
        // group disabled does not have a corresponding SimInfo column. So we only update the cache.

        // Grab the write lock so no other threads can read or write the cache.
        mReadWriteLock.writeLock().lock();
        try {
            SubscriptionInfoInternal subInfoCache = mAllSubscriptionInfoInternalCache.get(subId);
            if (subInfoCache == null) {
                throw new IllegalArgumentException("setGroupDisabled: Subscription doesn't exist. "
                        + "subId=" + subId);
            }
            mAllSubscriptionInfoInternalCache.put(subId,
                    new SubscriptionInfoInternal.Builder(subInfoCache)
                            .setGroupDisabled(isGroupDisabled).build());
        } finally {
            mReadWriteLock.writeLock().unlock();
        }
    }

    /**
     * Load the entire database into the cache.
     */
@@ -2004,12 +2034,6 @@ public class SubscriptionDatabaseManager extends Handler {
        }
    }

    /**
     * @return {@code true} if the database has been loaded into the cache.
     */
    public boolean isDatabaseLoaded() {
        return mDatabaseLoaded;
    }
    /**
     * Log debug messages.
     *
+31 −0
Original line number Diff line number Diff line
@@ -921,6 +921,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                            SubscriptionManager.INVALID_SIM_SLOT_INDEX);
                    mSlotIndexToSubId.remove(simSlotIndex);
                });
        updateGroupDisabled();
    }

    /**
@@ -1346,6 +1347,7 @@ public class SubscriptionManagerService extends ISub.Stub {
            MultiSimSettingController.getInstance().notifyAllSubscriptionLoaded();
        }

        updateGroupDisabled();
        updateDefaultSubId();
    }

@@ -1489,6 +1491,8 @@ public class SubscriptionManagerService extends ISub.Stub {
            }
        }

        updateGroupDisabled();

        final int preferredUsageSetting = config.getInt(
                CarrierConfigManager.KEY_CELLULAR_USAGE_SETTING_INT,
                SubscriptionManager.USAGE_SETTING_UNKNOWN);
@@ -1900,6 +1904,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                }

                int subId = insertSubscriptionInfo(iccId, slotIndex, displayName, subscriptionType);
                updateGroupDisabled();
                mSlotIndexToSubId.put(slotIndex, subId);
            } else {
                // Record already exists.
@@ -2214,6 +2219,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                mSubscriptionDatabaseManager.setGroupUuid(subId, uuidString);
                mSubscriptionDatabaseManager.setGroupOwner(subId, callingPackage);
            }
            updateGroupDisabled();

            MultiSimSettingController.getInstance().notifySubscriptionGroupChanged(groupUUID);
            return groupUUID;
@@ -2405,6 +2411,8 @@ public class SubscriptionManagerService extends ISub.Stub {
                            subInfo.getSubscriptionId(), callingPackage);
                }
            }

            updateGroupDisabled();
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
@@ -2464,6 +2472,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                mSubscriptionDatabaseManager.setGroupOwner(subId, callingPackage);
            }

            updateGroupDisabled();
            MultiSimSettingController.getInstance().notifySubscriptionGroupChanged(groupUuid);
            logl("addSubscriptionsIntoGroup: add subs " + Arrays.toString(subIdList)
                    + " to the group.");
@@ -3734,6 +3743,28 @@ public class SubscriptionManagerService extends ISub.Stub {
                Binder.getCallingUid()));
    }

    /**
     * Update the {@link SubscriptionInfo#isGroupDisabled()} bit for the opportunistic
     * subscriptions.
     *
     * If all primary (non-opportunistic) subscriptions in the group are deactivated
     * (unplugged pSIM or deactivated eSIM profile), we should disable this opportunistic
     * subscriptions.
     */
    @VisibleForTesting
    public void updateGroupDisabled() {
        List<SubscriptionInfo> activeSubscriptions = getActiveSubscriptionInfoList(
                mContext.getOpPackageName(), mContext.getFeatureId());
        for (SubscriptionInfo oppSubInfo : getOpportunisticSubscriptions(
                mContext.getOpPackageName(), mContext.getFeatureId())) {
            boolean groupDisabled = activeSubscriptions.stream()
                    .noneMatch(subInfo -> !subInfo.isOpportunistic()
                            && Objects.equals(oppSubInfo.getGroupUuid(), subInfo.getGroupUuid()));
            mSubscriptionDatabaseManager.setGroupDisabled(
                    oppSubInfo.getSubscriptionId(), groupDisabled);
        }
    }

    /**
     * Log debug messages.
     *
+24 −7
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ import android.telephony.UiccAccessRule;
import android.test.mock.MockContentResolver;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.ArraySet;
import android.util.Base64;

import com.android.internal.telephony.ContextFixture;
@@ -134,6 +135,8 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
    private SubscriptionManagerServiceCallback mMockedSubscriptionManagerServiceCallback;
    private EuiccController mEuiccController;

    private Set<Integer> mActiveSubs = new ArraySet<>();

    @Rule
    public TestRule compatChangeRule = new PlatformCompatChangeRule();

@@ -156,6 +159,8 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        doReturn(FAKE_ICCID1).when(mUiccCard).getCardId();
        doReturn(FAKE_ICCID1).when(mUiccPort).getIccId();

        doReturn(new int[0]).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();

        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                Telephony.Carriers.CONTENT_URI.getAuthority(), mSubscriptionProvider);

@@ -250,6 +255,15 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
            processAllMessages();
            verify(mMockedSubscriptionManagerServiceCallback).onSubscriptionChanged(eq(subId));
            Mockito.clearInvocations(mMockedSubscriptionManagerServiceCallback);

            if (subInfo.getSimSlotIndex() >= 0) {
                mActiveSubs.add(subId);
            } else {
                mActiveSubs.remove(subId);
            }

            doReturn(mActiveSubs.stream().mapToInt(i->i).toArray()).when(mSubscriptionManager)
                    .getCompleteActiveSubscriptionIdList();
            return subId;
        } catch (Exception e) {
            fail("Failed to insert subscription. e=" + e);
@@ -373,7 +387,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
    @Test
    public void testGetAllSubInfoList() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        doReturn(new int[]{1, 2}).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);

@@ -442,8 +455,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
    @Test
    @EnableCompatChanges({SubscriptionManagerService.REQUIRE_DEVICE_IDENTIFIERS_FOR_GROUP_UUID})
    public void testGetSubscriptionsInGroup() {
        doReturn(new int[]{1, 2}).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();

        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        SubscriptionInfoInternal anotherSubInfo =
                new SubscriptionInfoInternal.Builder(FAKE_SUBSCRIPTION_INFO2)
@@ -659,7 +670,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

    @Test
    public void testGetActiveSubscriptionInfoList() {
        doReturn(new int[]{1}).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();
        // Grant MODIFY_PHONE_STATE permission for insertion.
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
@@ -837,7 +847,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

    @Test
    public void testGetActiveSubInfoCount() {
        doReturn(new int[]{1, 2}).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);

@@ -1003,7 +1012,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

    @Test
    public void testSetUsageSetting() {
        doReturn(new int[]{1}).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);

        // Should fail without MODIFY_PHONE_STATE
@@ -1048,7 +1056,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

    @Test
    public void testSetOpportunistic() {
        doReturn(new int[]{1}).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);

        // Should fail without MODIFY_PHONE_STATE
@@ -1792,4 +1799,14 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(subInfo.getAllowedNetworkTypesForReasons()).isEqualTo("user="
                + RadioAccessFamily.getRafFromNetworkType(RILConstants.PREFERRED_NETWORK_MODE));
    }

    @Test
    public void testGroupDisable() {
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        insertSubscription(new SubscriptionInfoInternal.Builder(FAKE_SUBSCRIPTION_INFO2)
                .setGroupUuid(FAKE_UUID1).build());

        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(2).isGroupDisabled())
                .isFalse();
    }
}