Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.internal.telephony;
     19 
     20 
     21 import android.content.Context;
     22 import android.os.RegistrantList;
     23 import android.os.Registrant;
     24 import android.os.Handler;
     25 import android.os.AsyncResult;
     26 import android.telephony.TelephonyManager;
     27 
     28 /**
     29  * {@hide}
     30  */
     31 public abstract class BaseCommands implements CommandsInterface {
     32     //***** Instance Variables
     33     protected Context mContext;
     34     protected RadioState mState = RadioState.RADIO_UNAVAILABLE;
     35     protected Object mStateMonitor = new Object();
     36 
     37     protected RegistrantList mRadioStateChangedRegistrants = new RegistrantList();
     38     protected RegistrantList mOnRegistrants = new RegistrantList();
     39     protected RegistrantList mAvailRegistrants = new RegistrantList();
     40     protected RegistrantList mOffOrNotAvailRegistrants = new RegistrantList();
     41     protected RegistrantList mNotAvailRegistrants = new RegistrantList();
     42     protected RegistrantList mCallStateRegistrants = new RegistrantList();
     43     protected RegistrantList mVoiceNetworkStateRegistrants = new RegistrantList();
     44     protected RegistrantList mDataNetworkStateRegistrants = new RegistrantList();
     45     protected RegistrantList mVoiceRadioTechChangedRegistrants = new RegistrantList();
     46     protected RegistrantList mImsNetworkStateChangedRegistrants = new RegistrantList();
     47     protected RegistrantList mIccStatusChangedRegistrants = new RegistrantList();
     48     protected RegistrantList mVoicePrivacyOnRegistrants = new RegistrantList();
     49     protected RegistrantList mVoicePrivacyOffRegistrants = new RegistrantList();
     50     protected Registrant mUnsolOemHookRawRegistrant;
     51     protected RegistrantList mOtaProvisionRegistrants = new RegistrantList();
     52     protected RegistrantList mCallWaitingInfoRegistrants = new RegistrantList();
     53     protected RegistrantList mDisplayInfoRegistrants = new RegistrantList();
     54     protected RegistrantList mSignalInfoRegistrants = new RegistrantList();
     55     protected RegistrantList mNumberInfoRegistrants = new RegistrantList();
     56     protected RegistrantList mRedirNumInfoRegistrants = new RegistrantList();
     57     protected RegistrantList mLineControlInfoRegistrants = new RegistrantList();
     58     protected RegistrantList mT53ClirInfoRegistrants = new RegistrantList();
     59     protected RegistrantList mT53AudCntrlInfoRegistrants = new RegistrantList();
     60     protected RegistrantList mRingbackToneRegistrants = new RegistrantList();
     61     protected RegistrantList mResendIncallMuteRegistrants = new RegistrantList();
     62     protected RegistrantList mCdmaSubscriptionChangedRegistrants = new RegistrantList();
     63     protected RegistrantList mCdmaPrlChangedRegistrants = new RegistrantList();
     64     protected RegistrantList mExitEmergencyCallbackModeRegistrants = new RegistrantList();
     65     protected RegistrantList mRilConnectedRegistrants = new RegistrantList();
     66     protected RegistrantList mIccRefreshRegistrants = new RegistrantList();
     67     protected RegistrantList mRilCellInfoListRegistrants = new RegistrantList();
     68 
     69     protected Registrant mGsmSmsRegistrant;
     70     protected Registrant mCdmaSmsRegistrant;
     71     protected Registrant mNITZTimeRegistrant;
     72     protected Registrant mSignalStrengthRegistrant;
     73     protected Registrant mUSSDRegistrant;
     74     protected Registrant mSmsOnSimRegistrant;
     75     protected Registrant mSmsStatusRegistrant;
     76     protected Registrant mSsnRegistrant;
     77     protected Registrant mCatSessionEndRegistrant;
     78     protected Registrant mCatProCmdRegistrant;
     79     protected Registrant mCatEventRegistrant;
     80     protected Registrant mCatCallSetUpRegistrant;
     81     protected Registrant mIccSmsFullRegistrant;
     82     protected Registrant mEmergencyCallbackModeRegistrant;
     83     protected Registrant mRingRegistrant;
     84     protected Registrant mRestrictedStateRegistrant;
     85     protected Registrant mGsmBroadcastSmsRegistrant;
     86 
     87     // Preferred network type received from PhoneFactory.
     88     // This is used when establishing a connection to the
     89     // vendor ril so it starts up in the correct mode.
     90     protected int mPreferredNetworkType;
     91     // CDMA subscription received from PhoneFactory
     92     protected int mCdmaSubscription;
     93     // Type of Phone, GSM or CDMA. Set by CDMAPhone or GSMPhone.
     94     protected int mPhoneType;
     95     // RIL Version
     96     protected int mRilVersion = -1;
     97 
     98     public BaseCommands(Context context) {
     99         mContext = context;  // May be null (if so we won't log statistics)
    100     }
    101 
    102     //***** CommandsInterface implementation
    103 
    104     @Override
    105     public RadioState getRadioState() {
    106         return mState;
    107     }
    108 
    109     @Override
    110     public void registerForRadioStateChanged(Handler h, int what, Object obj) {
    111         Registrant r = new Registrant (h, what, obj);
    112 
    113         synchronized (mStateMonitor) {
    114             mRadioStateChangedRegistrants.add(r);
    115             r.notifyRegistrant();
    116         }
    117     }
    118 
    119     @Override
    120     public void unregisterForRadioStateChanged(Handler h) {
    121         synchronized (mStateMonitor) {
    122             mRadioStateChangedRegistrants.remove(h);
    123         }
    124     }
    125 
    126     public void registerForImsNetworkStateChanged(Handler h, int what, Object obj) {
    127         Registrant r = new Registrant (h, what, obj);
    128         mImsNetworkStateChangedRegistrants.add(r);
    129     }
    130 
    131     public void unregisterForImsNetworkStateChanged(Handler h) {
    132         mImsNetworkStateChangedRegistrants.remove(h);
    133     }
    134 
    135     @Override
    136     public void registerForOn(Handler h, int what, Object obj) {
    137         Registrant r = new Registrant (h, what, obj);
    138 
    139         synchronized (mStateMonitor) {
    140             mOnRegistrants.add(r);
    141 
    142             if (mState.isOn()) {
    143                 r.notifyRegistrant(new AsyncResult(null, null, null));
    144             }
    145         }
    146     }
    147     @Override
    148     public void unregisterForOn(Handler h) {
    149         synchronized (mStateMonitor) {
    150             mOnRegistrants.remove(h);
    151         }
    152     }
    153 
    154 
    155     @Override
    156     public void registerForAvailable(Handler h, int what, Object obj) {
    157         Registrant r = new Registrant (h, what, obj);
    158 
    159         synchronized (mStateMonitor) {
    160             mAvailRegistrants.add(r);
    161 
    162             if (mState.isAvailable()) {
    163                 r.notifyRegistrant(new AsyncResult(null, null, null));
    164             }
    165         }
    166     }
    167 
    168     @Override
    169     public void unregisterForAvailable(Handler h) {
    170         synchronized(mStateMonitor) {
    171             mAvailRegistrants.remove(h);
    172         }
    173     }
    174 
    175     @Override
    176     public void registerForNotAvailable(Handler h, int what, Object obj) {
    177         Registrant r = new Registrant (h, what, obj);
    178 
    179         synchronized (mStateMonitor) {
    180             mNotAvailRegistrants.add(r);
    181 
    182             if (!mState.isAvailable()) {
    183                 r.notifyRegistrant(new AsyncResult(null, null, null));
    184             }
    185         }
    186     }
    187 
    188     @Override
    189     public void unregisterForNotAvailable(Handler h) {
    190         synchronized (mStateMonitor) {
    191             mNotAvailRegistrants.remove(h);
    192         }
    193     }
    194 
    195     @Override
    196     public void registerForOffOrNotAvailable(Handler h, int what, Object obj) {
    197         Registrant r = new Registrant (h, what, obj);
    198 
    199         synchronized (mStateMonitor) {
    200             mOffOrNotAvailRegistrants.add(r);
    201 
    202             if (mState == RadioState.RADIO_OFF || !mState.isAvailable()) {
    203                 r.notifyRegistrant(new AsyncResult(null, null, null));
    204             }
    205         }
    206     }
    207     @Override
    208     public void unregisterForOffOrNotAvailable(Handler h) {
    209         synchronized(mStateMonitor) {
    210             mOffOrNotAvailRegistrants.remove(h);
    211         }
    212     }
    213 
    214     @Override
    215     public void registerForCallStateChanged(Handler h, int what, Object obj) {
    216         Registrant r = new Registrant (h, what, obj);
    217 
    218         mCallStateRegistrants.add(r);
    219     }
    220 
    221     @Override
    222     public void unregisterForCallStateChanged(Handler h) {
    223         mCallStateRegistrants.remove(h);
    224     }
    225 
    226     @Override
    227     public void registerForVoiceNetworkStateChanged(Handler h, int what, Object obj) {
    228         Registrant r = new Registrant (h, what, obj);
    229 
    230         mVoiceNetworkStateRegistrants.add(r);
    231     }
    232 
    233     @Override
    234     public void unregisterForVoiceNetworkStateChanged(Handler h) {
    235         mVoiceNetworkStateRegistrants.remove(h);
    236     }
    237 
    238     @Override
    239     public void registerForDataNetworkStateChanged(Handler h, int what, Object obj) {
    240         Registrant r = new Registrant (h, what, obj);
    241 
    242         mDataNetworkStateRegistrants.add(r);
    243     }
    244 
    245     @Override
    246     public void unregisterForDataNetworkStateChanged(Handler h) {
    247         mDataNetworkStateRegistrants.remove(h);
    248     }
    249 
    250     @Override
    251     public void registerForVoiceRadioTechChanged(Handler h, int what, Object obj) {
    252         Registrant r = new Registrant (h, what, obj);
    253         mVoiceRadioTechChangedRegistrants.add(r);
    254     }
    255 
    256     @Override
    257     public void unregisterForVoiceRadioTechChanged(Handler h) {
    258         mVoiceRadioTechChangedRegistrants.remove(h);
    259     }
    260 
    261     @Override
    262     public void registerForIccStatusChanged(Handler h, int what, Object obj) {
    263         Registrant r = new Registrant (h, what, obj);
    264         mIccStatusChangedRegistrants.add(r);
    265     }
    266 
    267     @Override
    268     public void unregisterForIccStatusChanged(Handler h) {
    269         mIccStatusChangedRegistrants.remove(h);
    270     }
    271 
    272     @Override
    273     public void setOnNewGsmSms(Handler h, int what, Object obj) {
    274         mGsmSmsRegistrant = new Registrant (h, what, obj);
    275     }
    276 
    277     @Override
    278     public void unSetOnNewGsmSms(Handler h) {
    279         mGsmSmsRegistrant.clear();
    280     }
    281 
    282     @Override
    283     public void setOnNewCdmaSms(Handler h, int what, Object obj) {
    284         mCdmaSmsRegistrant = new Registrant (h, what, obj);
    285     }
    286 
    287     @Override
    288     public void unSetOnNewCdmaSms(Handler h) {
    289         mCdmaSmsRegistrant.clear();
    290     }
    291 
    292     @Override
    293     public void setOnNewGsmBroadcastSms(Handler h, int what, Object obj) {
    294         mGsmBroadcastSmsRegistrant = new Registrant (h, what, obj);
    295     }
    296 
    297     @Override
    298     public void unSetOnNewGsmBroadcastSms(Handler h) {
    299         mGsmBroadcastSmsRegistrant.clear();
    300     }
    301 
    302     @Override
    303     public void setOnSmsOnSim(Handler h, int what, Object obj) {
    304         mSmsOnSimRegistrant = new Registrant (h, what, obj);
    305     }
    306 
    307     @Override
    308     public void unSetOnSmsOnSim(Handler h) {
    309         mSmsOnSimRegistrant.clear();
    310     }
    311 
    312     @Override
    313     public void setOnSmsStatus(Handler h, int what, Object obj) {
    314         mSmsStatusRegistrant = new Registrant (h, what, obj);
    315     }
    316 
    317     @Override
    318     public void unSetOnSmsStatus(Handler h) {
    319         mSmsStatusRegistrant.clear();
    320     }
    321 
    322     @Override
    323     public void setOnSignalStrengthUpdate(Handler h, int what, Object obj) {
    324         mSignalStrengthRegistrant = new Registrant (h, what, obj);
    325     }
    326 
    327     @Override
    328     public void unSetOnSignalStrengthUpdate(Handler h) {
    329         mSignalStrengthRegistrant.clear();
    330     }
    331 
    332     @Override
    333     public void setOnNITZTime(Handler h, int what, Object obj) {
    334         mNITZTimeRegistrant = new Registrant (h, what, obj);
    335     }
    336 
    337     @Override
    338     public void unSetOnNITZTime(Handler h) {
    339         mNITZTimeRegistrant.clear();
    340     }
    341 
    342     @Override
    343     public void setOnUSSD(Handler h, int what, Object obj) {
    344         mUSSDRegistrant = new Registrant (h, what, obj);
    345     }
    346 
    347     @Override
    348     public void unSetOnUSSD(Handler h) {
    349         mUSSDRegistrant.clear();
    350     }
    351 
    352     @Override
    353     public void setOnSuppServiceNotification(Handler h, int what, Object obj) {
    354         mSsnRegistrant = new Registrant (h, what, obj);
    355     }
    356 
    357     @Override
    358     public void unSetOnSuppServiceNotification(Handler h) {
    359         mSsnRegistrant.clear();
    360     }
    361 
    362     @Override
    363     public void setOnCatSessionEnd(Handler h, int what, Object obj) {
    364         mCatSessionEndRegistrant = new Registrant (h, what, obj);
    365     }
    366 
    367     @Override
    368     public void unSetOnCatSessionEnd(Handler h) {
    369         mCatSessionEndRegistrant.clear();
    370     }
    371 
    372     @Override
    373     public void setOnCatProactiveCmd(Handler h, int what, Object obj) {
    374         mCatProCmdRegistrant = new Registrant (h, what, obj);
    375     }
    376 
    377     @Override
    378     public void unSetOnCatProactiveCmd(Handler h) {
    379         mCatProCmdRegistrant.clear();
    380     }
    381 
    382     @Override
    383     public void setOnCatEvent(Handler h, int what, Object obj) {
    384         mCatEventRegistrant = new Registrant (h, what, obj);
    385     }
    386 
    387     @Override
    388     public void unSetOnCatEvent(Handler h) {
    389         mCatEventRegistrant.clear();
    390     }
    391 
    392     @Override
    393     public void setOnCatCallSetUp(Handler h, int what, Object obj) {
    394         mCatCallSetUpRegistrant = new Registrant (h, what, obj);
    395     }
    396 
    397     @Override
    398     public void unSetOnCatCallSetUp(Handler h) {
    399         mCatCallSetUpRegistrant.clear();
    400     }
    401 
    402     @Override
    403     public void setOnIccSmsFull(Handler h, int what, Object obj) {
    404         mIccSmsFullRegistrant = new Registrant (h, what, obj);
    405     }
    406 
    407     @Override
    408     public void unSetOnIccSmsFull(Handler h) {
    409         mIccSmsFullRegistrant.clear();
    410     }
    411 
    412     @Override
    413     public void registerForIccRefresh(Handler h, int what, Object obj) {
    414         Registrant r = new Registrant (h, what, obj);
    415         mIccRefreshRegistrants.add(r);
    416     }
    417     @Override
    418     public void setOnIccRefresh(Handler h, int what, Object obj) {
    419         registerForIccRefresh(h, what, obj);
    420     }
    421 
    422     @Override
    423     public void setEmergencyCallbackMode(Handler h, int what, Object obj) {
    424         mEmergencyCallbackModeRegistrant = new Registrant (h, what, obj);
    425     }
    426 
    427     @Override
    428     public void unregisterForIccRefresh(Handler h) {
    429         mIccRefreshRegistrants.remove(h);
    430     }
    431     @Override
    432     public void unsetOnIccRefresh(Handler h) {
    433         unregisterForIccRefresh(h);
    434     }
    435 
    436     @Override
    437     public void setOnCallRing(Handler h, int what, Object obj) {
    438         mRingRegistrant = new Registrant (h, what, obj);
    439     }
    440 
    441     @Override
    442     public void unSetOnCallRing(Handler h) {
    443         mRingRegistrant.clear();
    444     }
    445 
    446     @Override
    447     public void registerForInCallVoicePrivacyOn(Handler h, int what, Object obj) {
    448         Registrant r = new Registrant (h, what, obj);
    449         mVoicePrivacyOnRegistrants.add(r);
    450     }
    451 
    452     @Override
    453     public void unregisterForInCallVoicePrivacyOn(Handler h){
    454         mVoicePrivacyOnRegistrants.remove(h);
    455     }
    456 
    457     @Override
    458     public void registerForInCallVoicePrivacyOff(Handler h, int what, Object obj) {
    459         Registrant r = new Registrant (h, what, obj);
    460         mVoicePrivacyOffRegistrants.add(r);
    461     }
    462 
    463     @Override
    464     public void unregisterForInCallVoicePrivacyOff(Handler h){
    465         mVoicePrivacyOffRegistrants.remove(h);
    466     }
    467 
    468     @Override
    469     public void setOnRestrictedStateChanged(Handler h, int what, Object obj) {
    470         mRestrictedStateRegistrant = new Registrant (h, what, obj);
    471     }
    472 
    473     @Override
    474     public void unSetOnRestrictedStateChanged(Handler h) {
    475         mRestrictedStateRegistrant.clear();
    476     }
    477 
    478     @Override
    479     public void registerForDisplayInfo(Handler h, int what, Object obj) {
    480         Registrant r = new Registrant (h, what, obj);
    481         mDisplayInfoRegistrants.add(r);
    482     }
    483 
    484     @Override
    485     public void unregisterForDisplayInfo(Handler h) {
    486         mDisplayInfoRegistrants.remove(h);
    487     }
    488 
    489     @Override
    490     public void registerForCallWaitingInfo(Handler h, int what, Object obj) {
    491         Registrant r = new Registrant (h, what, obj);
    492         mCallWaitingInfoRegistrants.add(r);
    493     }
    494 
    495     @Override
    496     public void unregisterForCallWaitingInfo(Handler h) {
    497         mCallWaitingInfoRegistrants.remove(h);
    498     }
    499 
    500     @Override
    501     public void registerForSignalInfo(Handler h, int what, Object obj) {
    502         Registrant r = new Registrant (h, what, obj);
    503         mSignalInfoRegistrants.add(r);
    504     }
    505 
    506     public void setOnUnsolOemHookRaw(Handler h, int what, Object obj) {
    507         mUnsolOemHookRawRegistrant = new Registrant (h, what, obj);
    508     }
    509 
    510     public void unSetOnUnsolOemHookRaw(Handler h) {
    511         mUnsolOemHookRawRegistrant.clear();
    512     }
    513 
    514     @Override
    515     public void unregisterForSignalInfo(Handler h) {
    516         mSignalInfoRegistrants.remove(h);
    517     }
    518 
    519     @Override
    520     public void registerForCdmaOtaProvision(Handler h,int what, Object obj){
    521         Registrant r = new Registrant (h, what, obj);
    522         mOtaProvisionRegistrants.add(r);
    523     }
    524 
    525     @Override
    526     public void unregisterForCdmaOtaProvision(Handler h){
    527         mOtaProvisionRegistrants.remove(h);
    528     }
    529 
    530     @Override
    531     public void registerForNumberInfo(Handler h,int what, Object obj) {
    532         Registrant r = new Registrant (h, what, obj);
    533         mNumberInfoRegistrants.add(r);
    534     }
    535 
    536     @Override
    537     public void unregisterForNumberInfo(Handler h){
    538         mNumberInfoRegistrants.remove(h);
    539     }
    540 
    541      @Override
    542     public void registerForRedirectedNumberInfo(Handler h,int what, Object obj) {
    543         Registrant r = new Registrant (h, what, obj);
    544         mRedirNumInfoRegistrants.add(r);
    545     }
    546 
    547     @Override
    548     public void unregisterForRedirectedNumberInfo(Handler h) {
    549         mRedirNumInfoRegistrants.remove(h);
    550     }
    551 
    552     @Override
    553     public void registerForLineControlInfo(Handler h, int what, Object obj) {
    554         Registrant r = new Registrant (h, what, obj);
    555         mLineControlInfoRegistrants.add(r);
    556     }
    557 
    558     @Override
    559     public void unregisterForLineControlInfo(Handler h) {
    560         mLineControlInfoRegistrants.remove(h);
    561     }
    562 
    563     @Override
    564     public void registerFoT53ClirlInfo(Handler h,int what, Object obj) {
    565         Registrant r = new Registrant (h, what, obj);
    566         mT53ClirInfoRegistrants.add(r);
    567     }
    568 
    569     @Override
    570     public void unregisterForT53ClirInfo(Handler h) {
    571         mT53ClirInfoRegistrants.remove(h);
    572     }
    573 
    574     @Override
    575     public void registerForT53AudioControlInfo(Handler h,int what, Object obj) {
    576         Registrant r = new Registrant (h, what, obj);
    577         mT53AudCntrlInfoRegistrants.add(r);
    578     }
    579 
    580     @Override
    581     public void unregisterForT53AudioControlInfo(Handler h) {
    582         mT53AudCntrlInfoRegistrants.remove(h);
    583     }
    584 
    585     @Override
    586     public void registerForRingbackTone(Handler h, int what, Object obj) {
    587         Registrant r = new Registrant (h, what, obj);
    588         mRingbackToneRegistrants.add(r);
    589     }
    590 
    591     @Override
    592     public void unregisterForRingbackTone(Handler h) {
    593         mRingbackToneRegistrants.remove(h);
    594     }
    595 
    596     @Override
    597     public void registerForResendIncallMute(Handler h, int what, Object obj) {
    598         Registrant r = new Registrant (h, what, obj);
    599         mResendIncallMuteRegistrants.add(r);
    600     }
    601 
    602     @Override
    603     public void unregisterForResendIncallMute(Handler h) {
    604         mResendIncallMuteRegistrants.remove(h);
    605     }
    606 
    607     @Override
    608     public void registerForCdmaSubscriptionChanged(Handler h, int what, Object obj) {
    609         Registrant r = new Registrant (h, what, obj);
    610         mCdmaSubscriptionChangedRegistrants.add(r);
    611     }
    612 
    613     @Override
    614     public void unregisterForCdmaSubscriptionChanged(Handler h) {
    615         mCdmaSubscriptionChangedRegistrants.remove(h);
    616     }
    617 
    618     @Override
    619     public void registerForCdmaPrlChanged(Handler h, int what, Object obj) {
    620         Registrant r = new Registrant (h, what, obj);
    621         mCdmaPrlChangedRegistrants.add(r);
    622     }
    623 
    624     @Override
    625     public void unregisterForCdmaPrlChanged(Handler h) {
    626         mCdmaPrlChangedRegistrants.remove(h);
    627     }
    628 
    629     @Override
    630     public void registerForExitEmergencyCallbackMode(Handler h, int what, Object obj) {
    631         Registrant r = new Registrant (h, what, obj);
    632         mExitEmergencyCallbackModeRegistrants.add(r);
    633     }
    634 
    635     @Override
    636     public void unregisterForExitEmergencyCallbackMode(Handler h) {
    637         mExitEmergencyCallbackModeRegistrants.remove(h);
    638     }
    639 
    640     /**
    641      * {@inheritDoc}
    642      */
    643     @Override
    644     public void registerForRilConnected(Handler h, int what, Object obj) {
    645         Registrant r = new Registrant (h, what, obj);
    646         mRilConnectedRegistrants.add(r);
    647         if (mRilVersion != -1) {
    648             r.notifyRegistrant(new AsyncResult(null, new Integer(mRilVersion), null));
    649         }
    650     }
    651 
    652     @Override
    653     public void unregisterForRilConnected(Handler h) {
    654         mRilConnectedRegistrants.remove(h);
    655     }
    656 
    657     /**
    658      * {@inheritDoc}
    659      */
    660     @Override
    661     public void setCurrentPreferredNetworkType() {
    662     }
    663 
    664     //***** Protected Methods
    665     /**
    666      * Store new RadioState and send notification based on the changes
    667      *
    668      * This function is called only by RIL.java when receiving unsolicited
    669      * RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED
    670      *
    671      * RadioState has 3 values : RADIO_OFF, RADIO_UNAVAILABLE, RADIO_ON.
    672      *
    673      * @param newState new RadioState decoded from RIL_UNSOL_RADIO_STATE_CHANGED
    674      */
    675     protected void setRadioState(RadioState newState) {
    676         RadioState oldState;
    677 
    678         synchronized (mStateMonitor) {
    679             oldState = mState;
    680             mState = newState;
    681 
    682             if (oldState == mState) {
    683                 // no state transition
    684                 return;
    685             }
    686 
    687             mRadioStateChangedRegistrants.notifyRegistrants();
    688 
    689             if (mState.isAvailable() && !oldState.isAvailable()) {
    690                 mAvailRegistrants.notifyRegistrants();
    691                 onRadioAvailable();
    692             }
    693 
    694             if (!mState.isAvailable() && oldState.isAvailable()) {
    695                 mNotAvailRegistrants.notifyRegistrants();
    696             }
    697 
    698             if (mState.isOn() && !oldState.isOn()) {
    699                 mOnRegistrants.notifyRegistrants();
    700             }
    701 
    702             if ((!mState.isOn() || !mState.isAvailable())
    703                 && !((!oldState.isOn() || !oldState.isAvailable()))
    704             ) {
    705                 mOffOrNotAvailRegistrants.notifyRegistrants();
    706             }
    707         }
    708     }
    709 
    710     protected void onRadioAvailable() {
    711     }
    712 
    713     /**
    714      * {@inheritDoc}
    715      */
    716     @Override
    717     public int getLteOnCdmaMode() {
    718         return TelephonyManager.getLteOnCdmaModeStatic();
    719     }
    720 
    721     /**
    722      * {@inheritDoc}
    723      */
    724     @Override
    725     public void registerForCellInfoList(Handler h, int what, Object obj) {
    726         Registrant r = new Registrant (h, what, obj);
    727         mRilCellInfoListRegistrants.add(r);
    728     }
    729     @Override
    730     public void unregisterForCellInfoList(Handler h) {
    731         mRilCellInfoListRegistrants.remove(h);
    732     }
    733 
    734     @Override
    735     public void testingEmergencyCall() {}
    736 
    737     @Override
    738     public int getRilVersion() {
    739         return mRilVersion;
    740     }
    741 }
    742