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

Commit f0e973d9 authored by Jack Yu's avatar Jack Yu
Browse files

Moved UICC application enabled callback

Moved UICC application enabled callback triggering
logic from SubscriptionDatabaseManager to
SubscriptionManagerService.

Bug: 271642122
Test: Turn on/off SIM through UX many times and did not see issues.
Test: atest SubscriptionManagerServiceTest
Change-Id: I89d1d6a1decc774f84a44a6ba97d45253e5a1bc9
parent 0d9e44be
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -373,7 +373,7 @@ public class GsmCdmaPhone extends Phone {
            mSubscriptionManagerService.registerCallback(new SubscriptionManagerServiceCallback(
                    this::post) {
                @Override
                public void onUiccApplicationsEnabled(int subId) {
                public void onUiccApplicationsEnabledChanged(int subId) {
                    reapplyUiccAppsEnablementIfNeeded(ENABLE_UICC_APPS_MAX_RETRIES);
                }
            });
@@ -4471,6 +4471,7 @@ public class GsmCdmaPhone extends Phone {
                " mTelecomVoiceServiceStateOverride=" + mTelecomVoiceServiceStateOverride + "("
                        + ServiceState.rilServiceStateToString(mTelecomVoiceServiceStateOverride)
                        + ")");
        pw.println(" mUiccApplicationsEnabled=" + mUiccApplicationsEnabled);
        pw.flush();
        try {
            mCallWaitingController.dump(pw);
@@ -4883,6 +4884,8 @@ public class GsmCdmaPhone extends Phone {
        // If no card is present or we don't have mUiccApplicationsEnabled yet, do nothing.
        if (slot == null || slot.getCardState() != IccCardStatus.CardState.CARDSTATE_PRESENT
                || mUiccApplicationsEnabled == null) {
            loge("reapplyUiccAppsEnablementIfNeeded: slot state="
                    + (slot != null ? slot.getCardState() : null));
            return;
        }

+0 −16
Original line number Diff line number Diff line
@@ -553,14 +553,6 @@ public class SubscriptionDatabaseManager extends Handler {
         * @param subId The subscription id.
         */
        public abstract void onSubscriptionChanged(int subId);

        /**
         * Called when {@link SubscriptionInfoInternal#areUiccApplicationsEnabled()}
         * changed.
         *
         * @param subId The subscription id.
         */
        public abstract void onUiccApplicationsEnabled(int subId);
    }

    /**
@@ -918,10 +910,6 @@ public class SubscriptionDatabaseManager extends Handler {
                            mAllSubscriptionInfoInternalCache.put(id, builder.build());
                            mCallback.invokeFromExecutor(()
                                    -> mCallback.onSubscriptionChanged(subId));
                            if (columnName.equals(SimInfo.COLUMN_UICC_APPLICATIONS_ENABLED)) {
                                mCallback.invokeFromExecutor(()
                                        -> mCallback.onUiccApplicationsEnabled(subId));
                            }
                        }
                    }
                }
@@ -956,10 +944,6 @@ public class SubscriptionDatabaseManager extends Handler {
            if (updateDatabase(subId, createDeltaContentValues(oldSubInfo, newSubInfo)) > 0) {
                mAllSubscriptionInfoInternalCache.put(subId, newSubInfo);
                mCallback.invokeFromExecutor(() -> mCallback.onSubscriptionChanged(subId));
                if (oldSubInfo.areUiccApplicationsEnabled()
                        != newSubInfo.areUiccApplicationsEnabled()) {
                    mCallback.invokeFromExecutor(() -> mCallback.onUiccApplicationsEnabled(subId));
                }
            }
        } finally {
            mReadWriteLock.writeLock().unlock();
+15 −19
Original line number Diff line number Diff line
@@ -378,7 +378,7 @@ public class SubscriptionManagerService extends ISub.Stub {
         *
         * @param subId The subscription id.
         */
        public void onUiccApplicationsEnabled(int subId) {}
        public void onUiccApplicationsEnabledChanged(int subId) {}
    }

    /** DeviceConfig key for whether work profile telephony feature is enabled. */
@@ -514,23 +514,6 @@ public class SubscriptionManagerService extends ISub.Stub {
                                && telephonyRegistryManager != null) {
                            telephonyRegistryManager.notifyOpportunisticSubscriptionInfoChanged();
                        }

                        // TODO: Call TelephonyMetrics.updateActiveSubscriptionInfoList when active
                        //  subscription changes.
                    }

                    /**
                     * Called when {@link SubscriptionInfoInternal#areUiccApplicationsEnabled()}
                     * changed.
                     *
                     * @param subId The subscription id.
                     */
                    @Override
                    public void onUiccApplicationsEnabled(int subId) {
                        log("onUiccApplicationsEnabled: subId=" + subId);
                        mSubscriptionManagerServiceCallbacks.forEach(
                                callback -> callback.invokeFromExecutor(
                                        () -> callback.onUiccApplicationsEnabled(subId)));
                    }
                });

@@ -3193,7 +3176,20 @@ public class SubscriptionManagerService extends ISub.Stub {

        final long identity = Binder.clearCallingIdentity();
        try {

            SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager
                    .getSubscriptionInfoInternal(subId);
            if (subInfo == null) {
                throw new IllegalArgumentException("setUiccApplicationsEnabled: Subscription "
                        + "doesn't exist. subId=" + subId);
            }

            if (subInfo.areUiccApplicationsEnabled() != enabled) {
                mSubscriptionDatabaseManager.setUiccApplicationsEnabled(subId, enabled);
                mSubscriptionManagerServiceCallbacks.forEach(
                        callback -> callback.invokeFromExecutor(
                                () -> callback.onUiccApplicationsEnabledChanged(subId)));
            }
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
+12 −2
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@@ -1256,11 +1257,20 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        mSubscriptionManagerServiceUT.setUiccApplicationsEnabled(false, 1);
        processAllMessages();
        verify(mMockedSubscriptionManagerServiceCallback).onSubscriptionChanged(eq(1));
        verify(mMockedSubscriptionManagerServiceCallback).onUiccApplicationsEnabledChanged(eq(1));

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(1);
        assertThat(subInfo).isNotNull();
        assertThat(subInfo.areUiccApplicationsEnabled()).isFalse();

        Mockito.clearInvocations(mMockedSubscriptionManagerServiceCallback);
        mSubscriptionManagerServiceUT.setUiccApplicationsEnabled(false, 1);
        processAllMessages();

        verify(mMockedSubscriptionManagerServiceCallback, never()).onSubscriptionChanged(eq(1));
        verify(mMockedSubscriptionManagerServiceCallback, never())
                .onUiccApplicationsEnabledChanged(eq(1));
    }

    @Test
@@ -2015,9 +2025,9 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        SubscriptionManagerServiceCallback callback =
                new SubscriptionManagerServiceCallback(Runnable::run) {
                    @Override
                    public void onUiccApplicationsEnabled(int subId) {
                    public void onUiccApplicationsEnabledChanged(int subId) {
                        latch.countDown();
                        logd("testOnSubscriptionChanged: onUiccApplicationsEnabled");
                        logd("testOnSubscriptionChanged: onUiccApplicationsEnabledChanged");
                    }
                };
        mSubscriptionManagerServiceUT.registerCallback(callback);