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

Commit 814e6ef6 authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge changes Ic011551f,I13ff9bb0

* changes:
  Have UiccController compitible with dynamicy ss <-> ds switch
  Update ProxyController to be compatible with dynamic ss <-> ds switch
parents a9ecead7 f6c35543
Loading
Loading
Loading
Loading
+27 −18
Original line number Original line Diff line number Diff line
@@ -16,6 +16,9 @@


package com.android.internal.telephony;
package com.android.internal.telephony;


import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA_LTE;

import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.ComponentName;
@@ -167,7 +170,7 @@ public class PhoneFactory {


                // Instantiate UiccController so that all other classes can just
                // Instantiate UiccController so that all other classes can just
                // call getInstance()
                // call getInstance()
                sUiccController = UiccController.make(context, sCommandsInterfaces);
                sUiccController = UiccController.make(context);


                Rlog.i(LOG_TAG, "Creating SubscriptionController");
                Rlog.i(LOG_TAG, "Creating SubscriptionController");
                SubscriptionController sc = SubscriptionController.init(context);
                SubscriptionController sc = SubscriptionController.init(context);
@@ -180,22 +183,7 @@ public class PhoneFactory {
                }
                }


                for (int i = 0; i < numPhones; i++) {
                for (int i = 0; i < numPhones; i++) {
                    Phone phone = null;
                    sPhones[i] = createPhone(context, i);
                    int phoneType = TelephonyManager.getPhoneType(networkModes[i]);
                    if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
                        phone = new GsmCdmaPhone(context,
                                sCommandsInterfaces[i], sPhoneNotifier, i,
                                PhoneConstants.PHONE_TYPE_GSM,
                                TelephonyComponentFactory.getInstance());
                    } else if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
                        phone = new GsmCdmaPhone(context,
                                sCommandsInterfaces[i], sPhoneNotifier, i,
                                PhoneConstants.PHONE_TYPE_CDMA_LTE,
                                TelephonyComponentFactory.getInstance());
                    }
                    Rlog.i(LOG_TAG, "Creating Phone with type = " + phoneType + " sub = " + i);

                    sPhones[i] = phone;
                }
                }


                // Set the default phone in base class.
                // Set the default phone in base class.
@@ -258,7 +246,7 @@ public class PhoneFactory {


                sPhoneSwitcher = PhoneSwitcher.make(maxActivePhones, sContext, Looper.myLooper());
                sPhoneSwitcher = PhoneSwitcher.make(maxActivePhones, sContext, Looper.myLooper());


                sProxyController = ProxyController.getInstance(context, sPhones, sPhoneSwitcher);
                sProxyController = ProxyController.getInstance(context);


                sIntentBroadcaster = IntentBroadcaster.getInstance(context);
                sIntentBroadcaster = IntentBroadcaster.getInstance(context);


@@ -272,6 +260,18 @@ public class PhoneFactory {
        }
        }
    }
    }


    private static Phone createPhone(Context context, int phoneId) {
        int phoneType = TelephonyManager.getPhoneType(RILConstants.PREFERRED_NETWORK_MODE);
        Rlog.i(LOG_TAG, "Creating Phone with type = " + phoneType + " phoneId = " + phoneId);

        // We always use PHONE_TYPE_CDMA_LTE now.
        if (phoneType == PHONE_TYPE_CDMA) phoneType = PHONE_TYPE_CDMA_LTE;

        return new GsmCdmaPhone(context,
                sCommandsInterfaces[phoneId], sPhoneNotifier, phoneId, phoneType,
                TelephonyComponentFactory.getInstance());
    }

    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public static Phone getDefaultPhone() {
    public static Phone getDefaultPhone() {
        synchronized (sLockProxyPhones) {
        synchronized (sLockProxyPhones) {
@@ -456,6 +456,15 @@ public class PhoneFactory {
        }
        }
    }
    }


    /**
     * Get Command Interfaces.
     */
    public static CommandsInterface[] getCommandsInterfaces() {
        synchronized (sLockProxyPhones) {
            return sCommandsInterfaces;
        }
    }

    /**
    /**
     * Adds a local log category.
     * Adds a local log category.
     *
     *
+3 −6
Original line number Original line Diff line number Diff line
@@ -42,14 +42,11 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
    private static final boolean DBG = true;
    private static final boolean DBG = true;
    private static final boolean VDBG = false; // STOPSHIP if true
    private static final boolean VDBG = false; // STOPSHIP if true


    @UnsupportedAppUsage
    private final Phone[] mPhone;
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private final Context mContext;
    private final Context mContext;
    private final AppOpsManager mAppOps;
    private final AppOpsManager mAppOps;


    public PhoneSubInfoController(Context context, Phone[] phone) {
    public PhoneSubInfoController(Context context) {
        mPhone = phone;
        if (ServiceManager.getService("iphonesubinfo") == null) {
        if (ServiceManager.getService("iphonesubinfo") == null) {
            ServiceManager.addService("iphonesubinfo", this);
            ServiceManager.addService("iphonesubinfo", this);
        }
        }
@@ -221,7 +218,7 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
            phoneId = 0;
            phoneId = 0;
        }
        }
        return mPhone[phoneId];
        return PhoneFactory.getPhone(phoneId);
    }
    }


    /**
    /**
@@ -465,7 +462,7 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
            phoneId = 0;
            phoneId = 0;
        }
        }
        final Phone phone = mPhone[phoneId];
        final Phone phone = PhoneFactory.getPhone(phoneId);
        if (phone == null) {
        if (phone == null) {
            return null;
            return null;
        }
        }
+43 −9
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.internal.telephony;
package com.android.internal.telephony;


import static java.util.Arrays.copyOf;

import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -30,6 +32,7 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.util.Log;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.ims.RcsMessageController;
import com.android.internal.telephony.ims.RcsMessageController;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -45,6 +48,8 @@ public class ProxyController {
    private static final int EVENT_APPLY_RC_RESPONSE        = 3;
    private static final int EVENT_APPLY_RC_RESPONSE        = 3;
    private static final int EVENT_FINISH_RC_RESPONSE       = 4;
    private static final int EVENT_FINISH_RC_RESPONSE       = 4;
    private static final int EVENT_TIMEOUT                  = 5;
    private static final int EVENT_TIMEOUT                  = 5;
    @VisibleForTesting
    public static final int EVENT_MULTI_SIM_CONFIG_CHANGED  = 6;


    private static final int SET_RC_STATUS_IDLE             = 0;
    private static final int SET_RC_STATUS_IDLE             = 0;
    private static final int SET_RC_STATUS_STARTING         = 1;
    private static final int SET_RC_STATUS_STARTING         = 1;
@@ -105,9 +110,9 @@ public class ProxyController {




    //***** Class Methods
    //***** Class Methods
    public static ProxyController getInstance(Context context, Phone[] phone, PhoneSwitcher ps) {
    public static ProxyController getInstance(Context context) {
        if (sProxyController == null) {
        if (sProxyController == null) {
            sProxyController = new ProxyController(context, phone, ps);
            sProxyController = new ProxyController(context);
        }
        }
        return sProxyController;
        return sProxyController;
    }
    }
@@ -117,17 +122,17 @@ public class ProxyController {
        return sProxyController;
        return sProxyController;
    }
    }


    private ProxyController(Context context, Phone[] phone, PhoneSwitcher phoneSwitcher) {
    private ProxyController(Context context) {
        logd("Constructor - Enter");
        logd("Constructor - Enter");


        mContext = context;
        mContext = context;
        mPhones = phone;
        mPhones = PhoneFactory.getPhones();
        mPhoneSwitcher = phoneSwitcher;
        mPhoneSwitcher = PhoneSwitcher.getInstance();


        RcsMessageController.init(context);
        RcsMessageController.init(context);


        mUiccPhoneBookController = new UiccPhoneBookController(mPhones);
        mUiccPhoneBookController = new UiccPhoneBookController();
        mPhoneSubInfoController = new PhoneSubInfoController(mContext, mPhones);
        mPhoneSubInfoController = new PhoneSubInfoController(mContext);
        mSmsController = new SmsController(mContext);
        mSmsController = new SmsController(mContext);
        mSetRadioAccessFamilyStatus = new int[mPhones.length];
        mSetRadioAccessFamilyStatus = new int[mPhones.length];
        mNewRadioAccessFamily = new int[mPhones.length];
        mNewRadioAccessFamily = new int[mPhones.length];
@@ -146,6 +151,9 @@ public class ProxyController {
            mPhones[i].registerForRadioCapabilityChanged(
            mPhones[i].registerForRadioCapabilityChanged(
                    mHandler, EVENT_NOTIFICATION_RC_CHANGED, null);
                    mHandler, EVENT_NOTIFICATION_RC_CHANGED, null);
        }
        }

        PhoneConfigurationManager.registerForMultiSimConfigChange(
                mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
        logd("Constructor - Exit");
        logd("Constructor - Exit");
    }
    }


@@ -291,7 +299,8 @@ public class ProxyController {
        return true;
        return true;
    }
    }


    private Handler mHandler = new Handler() {
    @VisibleForTesting
    public final Handler mHandler = new Handler() {
        @Override
        @Override
        public void handleMessage(Message msg) {
        public void handleMessage(Message msg) {
            logd("handleMessage msg.what=" + msg.what);
            logd("handleMessage msg.what=" + msg.what);
@@ -316,12 +325,37 @@ public class ProxyController {
                    onTimeoutRadioCapability(msg);
                    onTimeoutRadioCapability(msg);
                    break;
                    break;


                case EVENT_MULTI_SIM_CONFIG_CHANGED:
                    onMultiSimConfigChanged();
                    break;

                default:
                default:
                    break;
                    break;
            }
            }
        }
        }
    };
    };


    private void onMultiSimConfigChanged() {
        int oldPhoneCount = mPhones.length;
        mPhones = PhoneFactory.getPhones();

        // Re-size arrays.
        mSetRadioAccessFamilyStatus = copyOf(mSetRadioAccessFamilyStatus, mPhones.length);
        mNewRadioAccessFamily = copyOf(mNewRadioAccessFamily, mPhones.length);
        mOldRadioAccessFamily = copyOf(mOldRadioAccessFamily, mPhones.length);
        mCurrentLogicalModemIds = copyOf(mCurrentLogicalModemIds, mPhones.length);
        mNewLogicalModemIds = copyOf(mNewLogicalModemIds, mPhones.length);

        // Clear to be sure we're in the initial state
        clearTransaction();

        // Register radio cap change for new phones.
        for (int i = oldPhoneCount; i < mPhones.length; i++) {
            mPhones[i].registerForRadioCapabilityChanged(
                    mHandler, EVENT_NOTIFICATION_RC_CHANGED, null);
        }
    }

    /**
    /**
     * Handle START response
     * Handle START response
     * @param msg obj field isa RadioCapability
     * @param msg obj field isa RadioCapability
+2 −7
Original line number Original line Diff line number Diff line
@@ -25,22 +25,17 @@ import android.telephony.Rlog;
import com.android.internal.telephony.IIccPhoneBook;
import com.android.internal.telephony.IIccPhoneBook;
import com.android.internal.telephony.uicc.AdnRecord;
import com.android.internal.telephony.uicc.AdnRecord;


import java.lang.ArrayIndexOutOfBoundsException;
import java.lang.NullPointerException;
import java.util.List;
import java.util.List;


public class UiccPhoneBookController extends IIccPhoneBook.Stub {
public class UiccPhoneBookController extends IIccPhoneBook.Stub {
    private static final String TAG = "UiccPhoneBookController";
    private static final String TAG = "UiccPhoneBookController";
    @UnsupportedAppUsage
    private Phone[] mPhone;


    /* only one UiccPhoneBookController exists */
    /* only one UiccPhoneBookController exists */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public UiccPhoneBookController(Phone[] phone) {
    public UiccPhoneBookController() {
        if (ServiceManager.getService("simphonebook") == null) {
        if (ServiceManager.getService("simphonebook") == null) {
               ServiceManager.addService("simphonebook", this);
               ServiceManager.addService("simphonebook", this);
        }
        }
        mPhone = phone;
    }
    }


    @Override
    @Override
@@ -139,7 +134,7 @@ public class UiccPhoneBookController extends IIccPhoneBook.Stub {


        int phoneId = SubscriptionController.getInstance().getPhoneId(subId);
        int phoneId = SubscriptionController.getInstance().getPhoneId(subId);
        try {
        try {
            return mPhone[phoneId].getIccPhoneBookInterfaceManager();
            return PhoneFactory.getPhone(phoneId).getIccPhoneBookInterfaceManager();
        } catch (NullPointerException e) {
        } catch (NullPointerException e) {
            Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId );
            Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId );
            e.printStackTrace(); //To print stack trace
            e.printStackTrace(); //To print stack trace
+44 −5
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.internal.telephony.uicc;
import static android.telephony.TelephonyManager.UNINITIALIZED_CARD_ID;
import static android.telephony.TelephonyManager.UNINITIALIZED_CARD_ID;
import static android.telephony.TelephonyManager.UNSUPPORTED_CARD_ID;
import static android.telephony.TelephonyManager.UNSUPPORTED_CARD_ID;


import static java.util.Arrays.copyOf;

import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.app.BroadcastOptions;
import android.app.BroadcastOptions;
import android.content.Context;
import android.content.Context;
@@ -42,6 +44,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.PhoneConfigurationManager;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.RadioConfig;
import com.android.internal.telephony.RadioConfig;
@@ -120,6 +123,7 @@ public class UiccController extends Handler {
    private static final int EVENT_RADIO_UNAVAILABLE = 7;
    private static final int EVENT_RADIO_UNAVAILABLE = 7;
    private static final int EVENT_SIM_REFRESH = 8;
    private static final int EVENT_SIM_REFRESH = 8;
    private static final int EVENT_EID_READY = 9;
    private static final int EVENT_EID_READY = 9;
    private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 10;


    // this needs to be here, because on bootup we dont know which index maps to which UiccSlot
    // this needs to be here, because on bootup we dont know which index maps to which UiccSlot
    @UnsupportedAppUsage
    @UnsupportedAppUsage
@@ -186,20 +190,23 @@ public class UiccController extends Handler {
    // LocalLog buffer to hold important SIM related events for debugging
    // LocalLog buffer to hold important SIM related events for debugging
    static LocalLog sLocalLog = new LocalLog(100);
    static LocalLog sLocalLog = new LocalLog(100);


    public static UiccController make(Context c, CommandsInterface[] ci) {
    /**
     * API to make UiccController singleton if not already created.
     */
    public static UiccController make(Context c) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (mInstance != null) {
            if (mInstance != null) {
                throw new RuntimeException("UiccController.make() should only be called once");
                throw new RuntimeException("UiccController.make() should only be called once");
            }
            }
            mInstance = new UiccController(c, ci);
            mInstance = new UiccController(c);
            return mInstance;
            return mInstance;
        }
        }
    }
    }


    private UiccController(Context c, CommandsInterface []ci) {
    private UiccController(Context c) {
        if (DBG) log("Creating UiccController");
        if (DBG) log("Creating UiccController");
        mContext = c;
        mContext = c;
        mCis = ci;
        mCis = PhoneFactory.getCommandsInterfaces();
        if (DBG) {
        if (DBG) {
            String logStr = "config_num_physical_slots = " + c.getResources().getInteger(
            String logStr = "config_num_physical_slots = " + c.getResources().getInteger(
                    com.android.internal.R.integer.config_num_physical_slots);
                    com.android.internal.R.integer.config_num_physical_slots);
@@ -215,7 +222,7 @@ public class UiccController extends Handler {
        }
        }


        mUiccSlots = new UiccSlot[numPhysicalSlots];
        mUiccSlots = new UiccSlot[numPhysicalSlots];
        mPhoneIdToSlotId = new int[ci.length];
        mPhoneIdToSlotId = new int[mCis.length];
        Arrays.fill(mPhoneIdToSlotId, INVALID_SLOT_ID);
        Arrays.fill(mPhoneIdToSlotId, INVALID_SLOT_ID);
        if (VDBG) logPhoneIdToSlotIdMapping();
        if (VDBG) logPhoneIdToSlotIdMapping();
        mRadioConfig = RadioConfig.getInstance(mContext);
        mRadioConfig = RadioConfig.getInstance(mContext);
@@ -245,6 +252,9 @@ public class UiccController extends Handler {
        mEuiccSlots = mContext.getResources()
        mEuiccSlots = mContext.getResources()
                .getIntArray(com.android.internal.R.array.non_removable_euicc_slots);
                .getIntArray(com.android.internal.R.array.non_removable_euicc_slots);
        mHasBuiltInEuicc = hasBuiltInEuicc();
        mHasBuiltInEuicc = hasBuiltInEuicc();

        PhoneConfigurationManager.registerForMultiSimConfigChange(
                this, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
    }
    }


    /**
    /**
@@ -519,6 +529,9 @@ public class UiccController extends Handler {
                    if (DBG) log("Received EVENT_EID_READY");
                    if (DBG) log("Received EVENT_EID_READY");
                    onEidReady(ar, phoneId);
                    onEidReady(ar, phoneId);
                    break;
                    break;
                case EVENT_MULTI_SIM_CONFIG_CHANGED:
                    if (DBG) log("Received EVENT_MULTI_SIM_CONFIG_CHANGED");
                    onMultiSimConfigChanged();
                default:
                default:
                    Rlog.e(LOG_TAG, " Unknown Event " + msg.what);
                    Rlog.e(LOG_TAG, " Unknown Event " + msg.what);
                    break;
                    break;
@@ -526,6 +539,32 @@ public class UiccController extends Handler {
        }
        }
    }
    }


    private void onMultiSimConfigChanged() {
        int prevActiveModemCount = mCis.length;
        mCis = PhoneFactory.getCommandsInterfaces();

        // Resize array.
        mPhoneIdToSlotId = copyOf(mPhoneIdToSlotId, mCis.length);

        for (int i = prevActiveModemCount; i < mCis.length; i++) {
            mCis[i].registerForIccStatusChanged(this, EVENT_ICC_STATUS_CHANGED, i);

            /*
             * To support FDE (deprecated), additional check is needed:
             *
             * if (!StorageManager.inCryptKeeperBounce()) {
             *     mCis[i].registerForAvailable(this, EVENT_RADIO_AVAILABLE, i);
             * } else {
             *     mCis[i].registerForOn(this, EVENT_RADIO_ON, i);
             * }
             */
            mCis[i].registerForAvailable(this, EVENT_RADIO_AVAILABLE, i);

            mCis[i].registerForNotAvailable(this, EVENT_RADIO_UNAVAILABLE, i);
            mCis[i].registerForIccRefresh(this, EVENT_SIM_REFRESH, i);
        }
    }

    private Integer getCiIndex(Message msg) {
    private Integer getCiIndex(Message msg) {
        AsyncResult ar;
        AsyncResult ar;
        Integer index = new Integer(PhoneConstants.DEFAULT_SLOT_INDEX);
        Integer index = new Integer(PhoneConstants.DEFAULT_SLOT_INDEX);
Loading