FileDocCategorySizeDatePackage
CdmaSubscriptionSourceManager.javaAPI DocAndroid 5.1 API8628Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony.cdma

CdmaSubscriptionSourceManager

public class CdmaSubscriptionSourceManager extends android.os.Handler
Class that handles the CDMA subscription source changed events from RIL

Fields Summary
static final String
LOG_TAG
private static final int
EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED
private static final int
EVENT_GET_CDMA_SUBSCRIPTION_SOURCE
private static final int
EVENT_RADIO_ON
private static final int
EVENT_SUBSCRIPTION_STATUS_CHANGED
private static final int
SUBSCRIPTION_ACTIVATED
public static final int
SUBSCRIPTION_SOURCE_UNKNOWN
public static final int
SUBSCRIPTION_FROM_RUIM
public static final int
SUBSCRIPTION_FROM_NV
public static final int
PREFERRED_CDMA_SUBSCRIPTION
private static CdmaSubscriptionSourceManager
sInstance
private static final Object
sReferenceCountMonitor
private static int
sReferenceCount
private com.android.internal.telephony.CommandsInterface
mCi
private android.content.Context
mContext
private android.os.RegistrantList
mCdmaSubscriptionSourceChangedRegistrants
private AtomicInteger
mCdmaSubscriptionSource
Constructors Summary
private CdmaSubscriptionSourceManager(android.content.Context context, com.android.internal.telephony.CommandsInterface ci)


    // Constructor
         
        mContext = context;
        mCi = ci;
        mCi.registerForCdmaSubscriptionChanged(this, EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED, null);
        mCi.registerForOn(this, EVENT_RADIO_ON, null);
        int subscriptionSource = getDefault(context);
        log("cdmaSSM constructor: " + subscriptionSource);
        mCdmaSubscriptionSource.set(subscriptionSource);
        mCi.registerForSubscriptionStatusChanged(this, EVENT_SUBSCRIPTION_STATUS_CHANGED, null);
    
Methods Summary
public voiddispose(android.os.Handler h)
Unregisters for the registered event with RIL

        mCdmaSubscriptionSourceChangedRegistrants.remove(h);
        synchronized (sReferenceCountMonitor) {
            sReferenceCount--;
            if (sReferenceCount <= 0) {
                mCi.unregisterForCdmaSubscriptionChanged(this);
                mCi.unregisterForOn(this);
                mCi.unregisterForSubscriptionStatusChanged(this);
                sInstance = null;
            }
        }
    
public intgetCdmaSubscriptionSource()
Returns the current CDMA subscription source value

return
CDMA subscription source value

        log("getcdmasubscriptionSource: " + mCdmaSubscriptionSource.get());
        return mCdmaSubscriptionSource.get();
    
public static intgetDefault(android.content.Context context)
Gets the default CDMA subscription source

return
Default CDMA subscription source from Settings DB if present.

        // Get the default value from the Settings
        int subscriptionSource = Settings.Global.getInt(context.getContentResolver(),
                Settings.Global.CDMA_SUBSCRIPTION_MODE, PREFERRED_CDMA_SUBSCRIPTION);
        Rlog.d(LOG_TAG, "subscriptionSource from settings: " + subscriptionSource);
        return subscriptionSource;
    
public static com.android.internal.telephony.cdma.CdmaSubscriptionSourceManagergetInstance(android.content.Context context, com.android.internal.telephony.CommandsInterface ci, android.os.Handler h, int what, java.lang.Object obj)
This function creates a single instance of this class

return
object of type CdmaSubscriptionSourceManager

        synchronized (sReferenceCountMonitor) {
            if (null == sInstance) {
                sInstance = new CdmaSubscriptionSourceManager(context, ci);
            }
            CdmaSubscriptionSourceManager.sReferenceCount++;
        }
        sInstance.registerForCdmaSubscriptionSourceChanged(h, what, obj);
        return sInstance;
    
private voidhandleGetCdmaSubscriptionSource(android.os.AsyncResult ar)
Handles the call to get the subscription source

param
ar AsyncResult object that contains the result of get CDMA subscription source call

        if ((ar.exception == null) && (ar.result != null)) {
            int newSubscriptionSource = ((int[]) ar.result)[0];

            if (newSubscriptionSource != mCdmaSubscriptionSource.get()) {
                log("Subscription Source Changed : " + mCdmaSubscriptionSource + " >> "
                        + newSubscriptionSource);
                mCdmaSubscriptionSource.set(newSubscriptionSource);

                // Notify registrants of the new CDMA subscription source
                mCdmaSubscriptionSourceChangedRegistrants.notifyRegistrants(new AsyncResult(null,
                        null, null));
            }
        } else {
            // GET_CDMA_SUBSCRIPTION is returning Failure. Probably
            // because modem created GSM Phone. If modem created
            // GSMPhone, then PhoneProxy will trigger a change in
            // Phone objects and this object will be destroyed.
            logw("Unable to get CDMA Subscription Source, Exception: " + ar.exception
                    + ", result: " + ar.result);
        }
    
public voidhandleMessage(android.os.Message msg)

        AsyncResult ar;
        switch (msg.what) {
            case EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
            case EVENT_GET_CDMA_SUBSCRIPTION_SOURCE:
            {
                log("CDMA_SUBSCRIPTION_SOURCE event = " + msg.what);
                ar = (AsyncResult) msg.obj;
                handleGetCdmaSubscriptionSource(ar);
            }
            break;
            case EVENT_RADIO_ON: {
                mCi.getCdmaSubscriptionSource(obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_SOURCE));
            }
            break;
            case EVENT_SUBSCRIPTION_STATUS_CHANGED: {
                log("EVENT_SUBSCRIPTION_STATUS_CHANGED");
                ar = (AsyncResult)msg.obj;
                if (ar.exception == null) {
                    int actStatus = ((int[])ar.result)[0];
                    log("actStatus = " + actStatus);
                    if (actStatus == SUBSCRIPTION_ACTIVATED) { // Subscription Activated
                        // In case of multi-SIM, framework should wait for the subscription ready
                        // to send any request to RIL.  Otherwise it will return failure.
                        Rlog.v(LOG_TAG,"get Cdma Subscription Source");
                        mCi.getCdmaSubscriptionSource(
                                obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_SOURCE));
                    }
                } else {
                    logw("EVENT_SUBSCRIPTION_STATUS_CHANGED, Exception:" + ar.exception);
                }
            }
            break;
            default:
                super.handleMessage(msg);
        }
    
private voidlog(java.lang.String s)

        Rlog.d(LOG_TAG, s);
    
private voidlogw(java.lang.String s)

        Rlog.w(LOG_TAG, s);
    
private voidregisterForCdmaSubscriptionSourceChanged(android.os.Handler h, int what, java.lang.Object obj)
Clients automatically register for CDMA subscription source changed event when they get an instance of this object.

        Registrant r = new Registrant (h, what, obj);
        mCdmaSubscriptionSourceChangedRegistrants.add(r);