FileDocCategorySizeDatePackage
TelephonyDevController.javaAPI DocAndroid 5.1 API11063Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony

TelephonyDevController

public class TelephonyDevController extends android.os.Handler
TelephonyDevController - provides a unified view of the telephony hardware resources on a device. manages the set of HardwareConfig for the framework.

Fields Summary
private static final String
LOG_TAG
private static final boolean
DBG
private static final Object
mLock
private static final int
EVENT_HARDWARE_CONFIG_CHANGED
private static TelephonyDevController
sTelephonyDevController
private static ArrayList
mModems
private static ArrayList
mSims
private static android.os.Message
sRilHardwareConfig
Constructors Summary
private TelephonyDevController()

        initFromResource();

        mModems.trimToSize();
        mSims.trimToSize();
    
Methods Summary
public static com.android.internal.telephony.TelephonyDevControllercreate()

        synchronized (mLock) {
            if (sTelephonyDevController != null) {
                throw new RuntimeException("TelephonyDevController already created!?!");
            }
            sTelephonyDevController = new TelephonyDevController();
            return sTelephonyDevController;
        }
    
public java.util.ArrayListgetAllModems()
get all modem's registered.

        synchronized (mLock) {
            ArrayList<HardwareConfig> modems = new ArrayList<HardwareConfig>();
            if (mModems.isEmpty()) {
                if (DBG) logd("getAllModems: empty list.");
            } else {
                for (HardwareConfig modem: mModems) {
                    modems.add(modem);
                }
            }

            return modems;
        }
    
public java.util.ArrayListgetAllSims()
get all sim's registered.

        synchronized (mLock) {
            ArrayList<HardwareConfig> sims = new ArrayList<HardwareConfig>();
            if (mSims.isEmpty()) {
                if (DBG) logd("getAllSims: empty list.");
            } else {
                for (HardwareConfig sim: mSims) {
                    sims.add(sim);
                }
            }

            return sims;
        }
    
public java.util.ArrayListgetAllSimsForModem(int modemIndex)
get all sim's associated with modem at index 'modemIndex'.

        synchronized (mLock) {
            if (mSims.isEmpty()) {
                loge("getAllSimsForModem: no registered sim device?!?");
                return null;
            }

            if (modemIndex > getModemCount()) {
                loge("getAllSimsForModem: out-of-bounds access for modem device " + modemIndex + " max: " + getModemCount());
                return null;
            }

            if (DBG) logd("getAllSimsForModem " + modemIndex);

            ArrayList<HardwareConfig> result = new ArrayList<HardwareConfig>();
            HardwareConfig modem = getModem(modemIndex);
            for (HardwareConfig sim: mSims) {
                if (sim.modemUuid.equals(modem.uuid)) {
                    result.add(sim);
                }
            }
            return result;
        }
    
public static com.android.internal.telephony.TelephonyDevControllergetInstance()

        synchronized (mLock) {
            if (sTelephonyDevController == null) {
                throw new RuntimeException("TelephonyDevController not yet created!?!");
            }
            return sTelephonyDevController;
        }
    
public HardwareConfiggetModem(int index)
get modem at index 'index'.

        synchronized (mLock) {
            if (mModems.isEmpty()) {
                loge("getModem: no registered modem device?!?");
                return null;
            }

            if (index > getModemCount()) {
                loge("getModem: out-of-bounds access for modem device " + index + " max: " + getModemCount());
                return null;
            }

            if (DBG) logd("getModem: " + index);
            return mModems.get(index);
        }
    
public static intgetModemCount()
get total number of registered modem.

        synchronized (mLock) {
            int count = mModems.size();
            if (DBG) logd("getModemCount: " + count);
            return count;
        }
    
public HardwareConfiggetModemForSim(int simIndex)
get modem associated with sim index 'simIndex'.

        synchronized (mLock) {
            if (mModems.isEmpty() || mSims.isEmpty()) {
                loge("getModemForSim: no registered modem/sim device?!?");
                return null;
            }

            if (simIndex > getSimCount()) {
                loge("getModemForSim: out-of-bounds access for sim device " + simIndex + " max: " + getSimCount());
                return null;
            }

            if (DBG) logd("getModemForSim " + simIndex);

            HardwareConfig sim = getSim(simIndex);
            for (HardwareConfig modem: mModems) {
                if (modem.uuid.equals(sim.modemUuid)) {
                    return modem;
                }
            }

            return null;
        }
    
public HardwareConfiggetSim(int index)
get sim at index 'index'.

        synchronized (mLock) {
            if (mSims.isEmpty()) {
                loge("getSim: no registered sim device?!?");
                return null;
            }

            if (index > getSimCount()) {
                loge("getSim: out-of-bounds access for sim device " + index + " max: " + getSimCount());
                return null;
            }

            if (DBG) logd("getSim: " + index);
            return mSims.get(index);
        }
    
public intgetSimCount()
get total number of registered sims.

        synchronized (mLock) {
            int count = mSims.size();
            if (DBG) logd("getSimCount: " + count);
            return count;
        }
    
private static voidhandleGetHardwareConfigChanged(android.os.AsyncResult ar)
hardware configuration changed.

        if ((ar.exception == null) && (ar.result != null)) {
            List hwcfg = (List)ar.result;
            for (int i = 0 ; i < hwcfg.size() ; i++) {
                HardwareConfig hw = null;

                hw = (HardwareConfig) hwcfg.get(i);
                if (hw != null) {
                    if (hw.type == HardwareConfig.DEV_HARDWARE_TYPE_MODEM) {
                        updateOrInsert(hw, mModems);
                    } else if (hw.type == HardwareConfig.DEV_HARDWARE_TYPE_SIM) {
                        updateOrInsert(hw, mSims);
                    }
                }
            }
        } else {
            /* error detected, ignore.  are we missing some real time configutation
             * at this point?  what to do...
             */
            loge("handleGetHardwareConfigChanged - returned an error.");
        }
    
public voidhandleMessage(android.os.Message msg)
handle callbacks from RIL.

        AsyncResult ar;
        switch (msg.what) {
            case EVENT_HARDWARE_CONFIG_CHANGED:
                if (DBG) logd("handleMessage: received EVENT_HARDWARE_CONFIG_CHANGED");
                ar = (AsyncResult) msg.obj;
                handleGetHardwareConfigChanged(ar);
            break;
            default:
                loge("handleMessage: Unknown Event " + msg.what);
        }
    
private voidinitFromResource()

        Resources resource = Resources.getSystem();
        String[] hwStrings = resource.getStringArray(
            com.android.internal.R.array.config_telephonyHardware);
        if (hwStrings != null) {
            for (String hwString : hwStrings) {
                HardwareConfig hw = new HardwareConfig(hwString);
                if (hw != null) {
                    if (hw.type == HardwareConfig.DEV_HARDWARE_TYPE_MODEM) {
                        updateOrInsert(hw, mModems);
                    } else if (hw.type == HardwareConfig.DEV_HARDWARE_TYPE_SIM) {
                        updateOrInsert(hw, mSims);
                    }
                }
            }
        }
    
private static voidlogd(java.lang.String s)


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

        Rlog.e(LOG_TAG, s);
    
public static voidregisterRIL(CommandsInterface cmdsIf)
each RIL call this interface to register/unregister the unsolicited hardware configuration callback data it can provide.

        /* get the current configuration from this ril... */
        cmdsIf.getHardwareConfig(sRilHardwareConfig);
        /* ... process it ... */
        if (sRilHardwareConfig != null) {
            AsyncResult ar = (AsyncResult) sRilHardwareConfig.obj;
            if (ar.exception == null) {
                handleGetHardwareConfigChanged(ar);
            }
        }
        /* and register for async device configuration change. */
        cmdsIf.registerForHardwareConfigChanged(sTelephonyDevController, EVENT_HARDWARE_CONFIG_CHANGED, null);
    
public static voidunregisterRIL(CommandsInterface cmdsIf)

        cmdsIf.unregisterForHardwareConfigChanged(sTelephonyDevController);
    
private static voidupdateOrInsert(HardwareConfig hw, java.util.ArrayList list)
hardware configuration update or insert.

        int size;
        HardwareConfig item;
        synchronized (mLock) {
            size = list.size();
            for (int i = 0 ; i < size ; i++) {
                item = list.get(i);
                if (item.uuid.compareTo(hw.uuid) == 0) {
                    if (DBG) logd("updateOrInsert: removing: " + item);
                    list.remove(i);
                }
            }
            if (DBG) logd("updateOrInsert: inserting: " + hw);
            list.add(hw);
        }