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

Commit d5b23e63 authored by Steve Statia's avatar Steve Statia Committed by Android (Google) Code Review
Browse files

Merge "Trigger notifyOpportunisticSubscriptionInfoChanged upon group disabled...

Merge "Trigger notifyOpportunisticSubscriptionInfoChanged upon group disabled flag for opportunistic subscription" into main
parents e1a1a2ad 5027df06
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -2062,7 +2062,7 @@ public class SubscriptionDatabaseManager extends Handler {
     */
    public void setGroupDisabled(int subId, boolean isGroupDisabled) {
        // group disabled does not have a corresponding SimInfo column. So we only update the cache.

        boolean isChanged = false;
        // Grab the write lock so no other threads can read or write the cache.
        mReadWriteLock.writeLock().lock();
        try {
@@ -2071,12 +2071,18 @@ public class SubscriptionDatabaseManager extends Handler {
                throw new IllegalArgumentException("setGroupDisabled: Subscription doesn't exist. "
                        + "subId=" + subId);
            }
            isChanged = subInfoCache.isGroupDisabled() != isGroupDisabled;
            mAllSubscriptionInfoInternalCache.put(subId,
                    new SubscriptionInfoInternal.Builder(subInfoCache)
                            .setGroupDisabled(isGroupDisabled).build());
        } finally {
            mReadWriteLock.writeLock().unlock();
        }

        if (isChanged) {
            log("setGroupDisabled value changed, firing the callback");
            mCallback.invokeFromExecutor(() -> mCallback.onSubscriptionChanged(subId));
        }
    }

    /**
+30 −0
Original line number Diff line number Diff line
@@ -2017,6 +2017,36 @@ public class SubscriptionDatabaseManagerTest extends TelephonyTest {
                .isEqualTo(FAKE_SATELLITE_IS_NTN_DISABLED);
    }

    @Test
    public void testSetGroupDisabled() throws Exception {
        assertThrows(IllegalArgumentException.class,
                () -> mDatabaseManagerUT.setGroupDisabled(
                        FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), true));

        insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
        mDatabaseManagerUT.setGroupDisabled(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), true);
        processAllMessages();

        assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
            FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).isGroupDisabled()).isTrue();

        verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
        Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);

        mDatabaseManagerUT.setGroupDisabled(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), true);
        processAllMessages();
        verify(mSubscriptionDatabaseManagerCallback, never()).onSubscriptionChanged(eq(1));

        assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
            FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).isGroupDisabled()).isTrue();

        mDatabaseManagerUT.setGroupDisabled(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), false);
        processAllMessages();
        verify(mSubscriptionDatabaseManagerCallback, times(1)).onSubscriptionChanged(eq(1));
        assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
                FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).isGroupDisabled()).isFalse();
    }

    @Test
    public void testUpdateSatelliteNtnWithFeatureDisabled() throws Exception {
        assertThrows(IllegalArgumentException.class,