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

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

Moved SIM state broadcast back to UiccController

Moved the SIM related stuffs back to UiccController.
SubscriptionManagerService will mainly handle subscription
related stuffs. The same SIM state broadcast is ported from
SubscriptionInfoUpdater.

Bug: 239607619
Test: Manual
Change-Id: I174353a8a37f6654f924491e414056ba9ea09953
parent bf960776
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony;

import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -200,7 +201,13 @@ public class CarrierServiceBindHelper {
        }
    }

    void updateForPhoneId(int phoneId, String simState) {
    /**
     * Update SIM state.
     *
     * @param phoneId The phone id.
     * @param simState The legacy SIM state.
     */
    public void updateSimState(int phoneId, @NonNull String simState) {
        logdWithLocalLog("update binding for phoneId: " + phoneId + " simState: " + simState);
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
            return;
+1 −1
Original line number Diff line number Diff line
@@ -700,7 +700,7 @@ public class SubscriptionInfoUpdater extends Handler {
        CarrierConfigManager configManager =
                (CarrierConfigManager) sContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        configManager.updateConfigForPhoneId(phoneId, simState);
        mCarrierServiceBindHelper.updateForPhoneId(phoneId, simState);
        mCarrierServiceBindHelper.updateSimState(phoneId, simState);
    }

    private void updateSubscriptionCarrierId(int phoneId, String simState) {
+143 −1
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.telephony.SubscriptionManager.SubscriptionType;
import android.telephony.SubscriptionManager.UsageSetting;
import android.telephony.TelephonyFrameworkInitializer;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager.SimState;
import android.telephony.TelephonyRegistryManager;
import android.telephony.UiccAccessRule;
import android.telephony.euicc.EuiccManager;
@@ -427,6 +428,10 @@ public class SubscriptionManagerService extends ISub.Stub {
                    @Override
                    public void onDatabaseLoaded() {
                        log("Subscription database has been loaded.");
                        for (int phoneId = 0; phoneId < mTelephonyManager.getActiveModemCount()
                                ; phoneId++) {
                            markSubscriptionsInactive(phoneId);
                        }
                    }

                    /**
@@ -826,7 +831,7 @@ public class SubscriptionManagerService extends ISub.Stub {
    /**
     * Mark all subscriptions on this SIM slot index inactive.
     *
     * @param simSlotIndex The SIM slot index.
     * @param simSlotIndex The logical SIM slot index (i.e. phone id).
     */
    public void markSubscriptionsInactive(int simSlotIndex) {
        mSubscriptionDatabaseManager.getAllSubscriptions().stream()
@@ -985,6 +990,15 @@ public class SubscriptionManagerService extends ISub.Stub {
        }
    }

    /**
     * Update the subscriptions on the logical SIM slot index (i.e. phone id).
     *
     * @param slotIndex The logical SIM slot index.
     */
    private void updateSubscriptions(int slotIndex) {

    }

    /**
     * Get all subscription info records from SIMs that are inserted now or previously inserted.
     *
@@ -3079,6 +3093,134 @@ public class SubscriptionManagerService extends ISub.Stub {
                ? subscriptionInfoInternal.toSubscriptionInfo() : null;
    }

    /**
     * Called when SIM state changed to absent.
     *
     * @param slotIndex The logical SIM slot index.
     */
    private void onSimAbsent(int slotIndex) {
        if (mSlotIndexToSubId.containsKey(slotIndex)) {
            // Re-enable the SIM when it's removed, so it will be in enabled state when it gets
            // re-inserted again. (pre-U behavior)
            mSubscriptionDatabaseManager.setUiccApplicationsEnabled(
                    mSlotIndexToSubId.get(slotIndex), true);
            // When sim is absent, set the port index to invalid port index. (pre-U behavior)
            mSubscriptionDatabaseManager.setPortIndex(mSlotIndexToSubId.get(slotIndex),
                    TelephonyManager.INVALID_PORT_INDEX);
        }
        updateSubscriptions(slotIndex);
    }

    /**
     * Called when SIM state changed to locked.
     *
     * @param slotIndex The logical SIM slot index.
     */
    private void onSimLocked(int slotIndex) {

    }

    /**
     * Called when SIM state changed to ready.
     *
     * @param slotIndex The logical SIM slot index.
     */
    private void onSimReady(int slotIndex) {

    }

    /**
     * Called when SIM state changed to not ready.
     *
     * @param slotIndex The logical SIM slot index.
     */
    private void onSimNotReady(int slotIndex) {

    }

    /**
     * Called when SIM encounters error.
     *
     * @param slotIndex The logical SIM slot index.
     */
    private void onSimError(int slotIndex) {

    }

    /**
     * Called when SIM state changed to loaded.
     *
     * @param slotIndex The logical SIM slot index.
     */
    private void onSimLoaded(int slotIndex) {
    }

    /**
     * Called when eSIM becomes inactive.
     *
     * @param slotIndex The logical SIM slot index.
     */
    public void updateSimStateForInactivePort(int slotIndex) {
        mHandler.post(() -> {
            if (mSlotIndexToSubId.containsKey(slotIndex)) {
                // Re-enable the UICC application , so it will be in enabled state when it becomes
                // active again. (pre-U behavior)
                mSubscriptionDatabaseManager.setUiccApplicationsEnabled(
                        mSlotIndexToSubId.get(slotIndex), true);
                updateSubscriptions(slotIndex);
            }
        });
    }

    /**
     * Update SIM state. This method is supposed to be called by {@link UiccController} only.
     *
     * @param slotIndex The logical SIM slot index.
     * @param simState SIM state.
     * @param executor The executor to execute the callback.
     * @param updateCompleteCallback The callback to call when subscription manager service
     * completes subscription update. SIM state changed event will be broadcasted by
     * {@link UiccController} upon receiving callback.
     */
    public void updateSimState(int slotIndex, @SimState int simState,
            @Nullable @CallbackExecutor Executor executor,
            @Nullable Runnable updateCompleteCallback) {
        mHandler.post(() -> {
            switch (simState) {
                case TelephonyManager.SIM_STATE_ABSENT:
                    onSimAbsent(slotIndex);
                    break;
                case TelephonyManager.SIM_STATE_PIN_REQUIRED:
                case TelephonyManager.SIM_STATE_PUK_REQUIRED:
                case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
                case TelephonyManager.SIM_STATE_PERM_DISABLED:
                    onSimLocked(slotIndex);
                    break;
                case TelephonyManager.SIM_STATE_READY:
                    onSimReady(slotIndex);
                    break;
                case TelephonyManager.SIM_STATE_NOT_READY:
                    onSimNotReady(slotIndex);
                    break;
                case TelephonyManager.SIM_STATE_CARD_IO_ERROR:
                    onSimError(slotIndex);
                    break;
                case TelephonyManager.SIM_STATE_CARD_RESTRICTED:
                    // No specific things needed to be done. Just return and broadcast the SIM
                    // states.
                    break;
                case TelephonyManager.SIM_STATE_LOADED:
                    onSimLoaded(slotIndex);
                    break;
                default:
                    break;
            }
            if (executor != null && updateCompleteCallback != null) {
                executor.execute(updateCompleteCallback);
            }
        });
    }

    /**
     * Log debug messages.
     *
+322 −20

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -802,8 +802,8 @@ public class UiccProfile extends IccCard {
            }
            log("setExternalState: set mPhoneId=" + mPhoneId + " mExternalState=" + mExternalState);

            UiccController.updateInternalIccState(mContext, mExternalState,
                    getIccStateReason(mExternalState), mPhoneId);
            UiccController.getInstance().updateSimState(mPhoneId, mExternalState,
                    getIccStateReason(mExternalState));
        }
    }

Loading