1 
2 /*
3  * Copyright (C) 2006 The Android Open Source Project
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 import android.content.Context;
21 import android.os.AsyncResult;
22 import android.os.Handler;
23 import android.os.Message;
24 import android.os.Registrant;
25 import android.os.RegistrantList;
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 mNetworkStateRegistrants = new RegistrantList();
44     protected RegistrantList mDataCallListChangedRegistrants = 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     protected RegistrantList mSubscriptionStatusRegistrants = new RegistrantList();
69     protected RegistrantList mSrvccStateRegistrants = new RegistrantList();
70     protected RegistrantList mHardwareConfigChangeRegistrants = new RegistrantList();
71     protected RegistrantList mPhoneRadioCapabilityChangedRegistrants =
72             new RegistrantList();
73     protected RegistrantList mPcoDataRegistrants = new RegistrantList();
74 
75 
76     protected Registrant mGsmSmsRegistrant;
77     protected Registrant mCdmaSmsRegistrant;
78     protected Registrant mNITZTimeRegistrant;
79     protected Registrant mSignalStrengthRegistrant;
80     protected Registrant mUSSDRegistrant;
81     protected Registrant mSmsOnSimRegistrant;
82     protected Registrant mSmsStatusRegistrant;
83     protected Registrant mSsnRegistrant;
84     protected Registrant mCatSessionEndRegistrant;
85     protected Registrant mCatProCmdRegistrant;
86     protected Registrant mCatEventRegistrant;
87     protected Registrant mCatCallSetUpRegistrant;
88     protected Registrant mIccSmsFullRegistrant;
89     protected Registrant mEmergencyCallbackModeRegistrant;
90     protected Registrant mRingRegistrant;
91     protected Registrant mRestrictedStateRegistrant;
92     protected Registrant mGsmBroadcastSmsRegistrant;
93     protected Registrant mCatCcAlphaRegistrant;
94     protected Registrant mSsRegistrant;
95     protected Registrant mLceInfoRegistrant;
96 
97     // Preferred network type received from PhoneFactory.
98     // This is used when establishing a connection to the
99     // vendor ril so it starts up in the correct mode.
100     protected int mPreferredNetworkType;
101     // CDMA subscription received from PhoneFactory
102     protected int mCdmaSubscription;
103     // Type of Phone, GSM or CDMA. Set by GsmCdmaPhone.
104     protected int mPhoneType;
105     // RIL Version
106     protected int mRilVersion = -1;
107 
BaseCommands(Context context)108     public BaseCommands(Context context) {
109         mContext = context;  // May be null (if so we won't log statistics)
110     }
111 
112     //***** CommandsInterface implementation
113 
114     @Override
getRadioState()115     public RadioState getRadioState() {
116         return mState;
117     }
118 
119     @Override
registerForRadioStateChanged(Handler h, int what, Object obj)120     public void registerForRadioStateChanged(Handler h, int what, Object obj) {
121         Registrant r = new Registrant (h, what, obj);
122 
123         synchronized (mStateMonitor) {
124             mRadioStateChangedRegistrants.add(r);
125             r.notifyRegistrant();
126         }
127     }
128 
129     @Override
unregisterForRadioStateChanged(Handler h)130     public void unregisterForRadioStateChanged(Handler h) {
131         synchronized (mStateMonitor) {
132             mRadioStateChangedRegistrants.remove(h);
133         }
134     }
135 
registerForImsNetworkStateChanged(Handler h, int what, Object obj)136     public void registerForImsNetworkStateChanged(Handler h, int what, Object obj) {
137         Registrant r = new Registrant (h, what, obj);
138         mImsNetworkStateChangedRegistrants.add(r);
139     }
140 
unregisterForImsNetworkStateChanged(Handler h)141     public void unregisterForImsNetworkStateChanged(Handler h) {
142         mImsNetworkStateChangedRegistrants.remove(h);
143     }
144 
145     @Override
registerForOn(Handler h, int what, Object obj)146     public void registerForOn(Handler h, int what, Object obj) {
147         Registrant r = new Registrant (h, what, obj);
148 
149         synchronized (mStateMonitor) {
150             mOnRegistrants.add(r);
151 
152             if (mState.isOn()) {
153                 r.notifyRegistrant(new AsyncResult(null, null, null));
154             }
155         }
156     }
157     @Override
unregisterForOn(Handler h)158     public void unregisterForOn(Handler h) {
159         synchronized (mStateMonitor) {
160             mOnRegistrants.remove(h);
161         }
162     }
163 
164 
165     @Override
registerForAvailable(Handler h, int what, Object obj)166     public void registerForAvailable(Handler h, int what, Object obj) {
167         Registrant r = new Registrant (h, what, obj);
168 
169         synchronized (mStateMonitor) {
170             mAvailRegistrants.add(r);
171 
172             if (mState.isAvailable()) {
173                 r.notifyRegistrant(new AsyncResult(null, null, null));
174             }
175         }
176     }
177 
178     @Override
unregisterForAvailable(Handler h)179     public void unregisterForAvailable(Handler h) {
180         synchronized(mStateMonitor) {
181             mAvailRegistrants.remove(h);
182         }
183     }
184 
185     @Override
registerForNotAvailable(Handler h, int what, Object obj)186     public void registerForNotAvailable(Handler h, int what, Object obj) {
187         Registrant r = new Registrant (h, what, obj);
188 
189         synchronized (mStateMonitor) {
190             mNotAvailRegistrants.add(r);
191 
192             if (!mState.isAvailable()) {
193                 r.notifyRegistrant(new AsyncResult(null, null, null));
194             }
195         }
196     }
197 
198     @Override
unregisterForNotAvailable(Handler h)199     public void unregisterForNotAvailable(Handler h) {
200         synchronized (mStateMonitor) {
201             mNotAvailRegistrants.remove(h);
202         }
203     }
204 
205     @Override
registerForOffOrNotAvailable(Handler h, int what, Object obj)206     public void registerForOffOrNotAvailable(Handler h, int what, Object obj) {
207         Registrant r = new Registrant (h, what, obj);
208 
209         synchronized (mStateMonitor) {
210             mOffOrNotAvailRegistrants.add(r);
211 
212             if (mState == RadioState.RADIO_OFF || !mState.isAvailable()) {
213                 r.notifyRegistrant(new AsyncResult(null, null, null));
214             }
215         }
216     }
217     @Override
unregisterForOffOrNotAvailable(Handler h)218     public void unregisterForOffOrNotAvailable(Handler h) {
219         synchronized(mStateMonitor) {
220             mOffOrNotAvailRegistrants.remove(h);
221         }
222     }
223 
224     @Override
registerForCallStateChanged(Handler h, int what, Object obj)225     public void registerForCallStateChanged(Handler h, int what, Object obj) {
226         Registrant r = new Registrant (h, what, obj);
227 
228         mCallStateRegistrants.add(r);
229     }
230 
231     @Override
unregisterForCallStateChanged(Handler h)232     public void unregisterForCallStateChanged(Handler h) {
233         mCallStateRegistrants.remove(h);
234     }
235 
236     @Override
registerForNetworkStateChanged(Handler h, int what, Object obj)237     public void registerForNetworkStateChanged(Handler h, int what, Object obj) {
238         Registrant r = new Registrant (h, what, obj);
239 
240         mNetworkStateRegistrants.add(r);
241     }
242 
243     @Override
unregisterForNetworkStateChanged(Handler h)244     public void unregisterForNetworkStateChanged(Handler h) {
245         mNetworkStateRegistrants.remove(h);
246     }
247 
248     @Override
registerForDataCallListChanged(Handler h, int what, Object obj)249     public void registerForDataCallListChanged(Handler h, int what, Object obj) {
250         Registrant r = new Registrant (h, what, obj);
251 
252         mDataCallListChangedRegistrants.add(r);
253     }
254 
255     @Override
unregisterForDataCallListChanged(Handler h)256     public void unregisterForDataCallListChanged(Handler h) {
257         mDataCallListChangedRegistrants.remove(h);
258     }
259 
260     @Override
registerForVoiceRadioTechChanged(Handler h, int what, Object obj)261     public void registerForVoiceRadioTechChanged(Handler h, int what, Object obj) {
262         Registrant r = new Registrant (h, what, obj);
263         mVoiceRadioTechChangedRegistrants.add(r);
264     }
265 
266     @Override
unregisterForVoiceRadioTechChanged(Handler h)267     public void unregisterForVoiceRadioTechChanged(Handler h) {
268         mVoiceRadioTechChangedRegistrants.remove(h);
269     }
270 
271     @Override
registerForIccStatusChanged(Handler h, int what, Object obj)272     public void registerForIccStatusChanged(Handler h, int what, Object obj) {
273         Registrant r = new Registrant (h, what, obj);
274         mIccStatusChangedRegistrants.add(r);
275     }
276 
277     @Override
unregisterForIccStatusChanged(Handler h)278     public void unregisterForIccStatusChanged(Handler h) {
279         mIccStatusChangedRegistrants.remove(h);
280     }
281 
282     @Override
setOnNewGsmSms(Handler h, int what, Object obj)283     public void setOnNewGsmSms(Handler h, int what, Object obj) {
284         mGsmSmsRegistrant = new Registrant (h, what, obj);
285     }
286 
287     @Override
unSetOnNewGsmSms(Handler h)288     public void unSetOnNewGsmSms(Handler h) {
289         if (mGsmSmsRegistrant != null && mGsmSmsRegistrant.getHandler() == h) {
290             mGsmSmsRegistrant.clear();
291             mGsmSmsRegistrant = null;
292         }
293     }
294 
295     @Override
setOnNewCdmaSms(Handler h, int what, Object obj)296     public void setOnNewCdmaSms(Handler h, int what, Object obj) {
297         mCdmaSmsRegistrant = new Registrant (h, what, obj);
298     }
299 
300     @Override
unSetOnNewCdmaSms(Handler h)301     public void unSetOnNewCdmaSms(Handler h) {
302         if (mCdmaSmsRegistrant != null && mCdmaSmsRegistrant.getHandler() == h) {
303             mCdmaSmsRegistrant.clear();
304             mCdmaSmsRegistrant = null;
305         }
306     }
307 
308     @Override
setOnNewGsmBroadcastSms(Handler h, int what, Object obj)309     public void setOnNewGsmBroadcastSms(Handler h, int what, Object obj) {
310         mGsmBroadcastSmsRegistrant = new Registrant (h, what, obj);
311     }
312 
313     @Override
unSetOnNewGsmBroadcastSms(Handler h)314     public void unSetOnNewGsmBroadcastSms(Handler h) {
315         if (mGsmBroadcastSmsRegistrant != null && mGsmBroadcastSmsRegistrant.getHandler() == h) {
316             mGsmBroadcastSmsRegistrant.clear();
317             mGsmBroadcastSmsRegistrant = null;
318         }
319     }
320 
321     @Override
setOnSmsOnSim(Handler h, int what, Object obj)322     public void setOnSmsOnSim(Handler h, int what, Object obj) {
323         mSmsOnSimRegistrant = new Registrant (h, what, obj);
324     }
325 
326     @Override
unSetOnSmsOnSim(Handler h)327     public void unSetOnSmsOnSim(Handler h) {
328         if (mSmsOnSimRegistrant != null && mSmsOnSimRegistrant.getHandler() == h) {
329             mSmsOnSimRegistrant.clear();
330             mSmsOnSimRegistrant = null;
331         }
332     }
333 
334     @Override
setOnSmsStatus(Handler h, int what, Object obj)335     public void setOnSmsStatus(Handler h, int what, Object obj) {
336         mSmsStatusRegistrant = new Registrant (h, what, obj);
337     }
338 
339     @Override
unSetOnSmsStatus(Handler h)340     public void unSetOnSmsStatus(Handler h) {
341         if (mSmsStatusRegistrant != null && mSmsStatusRegistrant.getHandler() == h) {
342             mSmsStatusRegistrant.clear();
343             mSmsStatusRegistrant = null;
344         }
345     }
346 
347     @Override
setOnSignalStrengthUpdate(Handler h, int what, Object obj)348     public void setOnSignalStrengthUpdate(Handler h, int what, Object obj) {
349         mSignalStrengthRegistrant = new Registrant (h, what, obj);
350     }
351 
352     @Override
unSetOnSignalStrengthUpdate(Handler h)353     public void unSetOnSignalStrengthUpdate(Handler h) {
354         if (mSignalStrengthRegistrant != null && mSignalStrengthRegistrant.getHandler() == h) {
355             mSignalStrengthRegistrant.clear();
356             mSignalStrengthRegistrant = null;
357         }
358     }
359 
360     @Override
setOnNITZTime(Handler h, int what, Object obj)361     public void setOnNITZTime(Handler h, int what, Object obj) {
362         mNITZTimeRegistrant = new Registrant (h, what, obj);
363     }
364 
365     @Override
unSetOnNITZTime(Handler h)366     public void unSetOnNITZTime(Handler h) {
367         if (mNITZTimeRegistrant != null && mNITZTimeRegistrant.getHandler() == h) {
368             mNITZTimeRegistrant.clear();
369             mNITZTimeRegistrant = null;
370         }
371     }
372 
373     @Override
setOnUSSD(Handler h, int what, Object obj)374     public void setOnUSSD(Handler h, int what, Object obj) {
375         mUSSDRegistrant = new Registrant (h, what, obj);
376     }
377 
378     @Override
unSetOnUSSD(Handler h)379     public void unSetOnUSSD(Handler h) {
380         if (mUSSDRegistrant != null && mUSSDRegistrant.getHandler() == h) {
381             mUSSDRegistrant.clear();
382             mUSSDRegistrant = null;
383         }
384     }
385 
386     @Override
setOnSuppServiceNotification(Handler h, int what, Object obj)387     public void setOnSuppServiceNotification(Handler h, int what, Object obj) {
388         mSsnRegistrant = new Registrant (h, what, obj);
389     }
390 
391     @Override
unSetOnSuppServiceNotification(Handler h)392     public void unSetOnSuppServiceNotification(Handler h) {
393         if (mSsnRegistrant != null && mSsnRegistrant.getHandler() == h) {
394             mSsnRegistrant.clear();
395             mSsnRegistrant = null;
396         }
397     }
398 
399     @Override
setOnCatSessionEnd(Handler h, int what, Object obj)400     public void setOnCatSessionEnd(Handler h, int what, Object obj) {
401         mCatSessionEndRegistrant = new Registrant (h, what, obj);
402     }
403 
404     @Override
unSetOnCatSessionEnd(Handler h)405     public void unSetOnCatSessionEnd(Handler h) {
406         if (mCatSessionEndRegistrant != null && mCatSessionEndRegistrant.getHandler() == h) {
407             mCatSessionEndRegistrant.clear();
408             mCatSessionEndRegistrant = null;
409         }
410     }
411 
412     @Override
setOnCatProactiveCmd(Handler h, int what, Object obj)413     public void setOnCatProactiveCmd(Handler h, int what, Object obj) {
414         mCatProCmdRegistrant = new Registrant (h, what, obj);
415     }
416 
417     @Override
unSetOnCatProactiveCmd(Handler h)418     public void unSetOnCatProactiveCmd(Handler h) {
419         if (mCatProCmdRegistrant != null && mCatProCmdRegistrant.getHandler() == h) {
420             mCatProCmdRegistrant.clear();
421             mCatProCmdRegistrant = null;
422         }
423     }
424 
425     @Override
setOnCatEvent(Handler h, int what, Object obj)426     public void setOnCatEvent(Handler h, int what, Object obj) {
427         mCatEventRegistrant = new Registrant (h, what, obj);
428     }
429 
430     @Override
unSetOnCatEvent(Handler h)431     public void unSetOnCatEvent(Handler h) {
432         if (mCatEventRegistrant != null && mCatEventRegistrant.getHandler() == h) {
433             mCatEventRegistrant.clear();
434             mCatEventRegistrant = null;
435         }
436     }
437 
438     @Override
setOnCatCallSetUp(Handler h, int what, Object obj)439     public void setOnCatCallSetUp(Handler h, int what, Object obj) {
440         mCatCallSetUpRegistrant = new Registrant (h, what, obj);
441     }
442 
443     @Override
unSetOnCatCallSetUp(Handler h)444     public void unSetOnCatCallSetUp(Handler h) {
445         if (mCatCallSetUpRegistrant != null && mCatCallSetUpRegistrant.getHandler() == h) {
446             mCatCallSetUpRegistrant.clear();
447             mCatCallSetUpRegistrant = null;
448         }
449     }
450 
451     @Override
setOnIccSmsFull(Handler h, int what, Object obj)452     public void setOnIccSmsFull(Handler h, int what, Object obj) {
453         mIccSmsFullRegistrant = new Registrant (h, what, obj);
454     }
455 
456     @Override
unSetOnIccSmsFull(Handler h)457     public void unSetOnIccSmsFull(Handler h) {
458         if (mIccSmsFullRegistrant != null && mIccSmsFullRegistrant.getHandler() == h) {
459             mIccSmsFullRegistrant.clear();
460             mIccSmsFullRegistrant = null;
461         }
462     }
463 
464     @Override
registerForIccRefresh(Handler h, int what, Object obj)465     public void registerForIccRefresh(Handler h, int what, Object obj) {
466         Registrant r = new Registrant (h, what, obj);
467         mIccRefreshRegistrants.add(r);
468     }
469     @Override
setOnIccRefresh(Handler h, int what, Object obj)470     public void setOnIccRefresh(Handler h, int what, Object obj) {
471         registerForIccRefresh(h, what, obj);
472     }
473 
474     @Override
setEmergencyCallbackMode(Handler h, int what, Object obj)475     public void setEmergencyCallbackMode(Handler h, int what, Object obj) {
476         mEmergencyCallbackModeRegistrant = new Registrant (h, what, obj);
477     }
478 
479     @Override
unregisterForIccRefresh(Handler h)480     public void unregisterForIccRefresh(Handler h) {
481         mIccRefreshRegistrants.remove(h);
482     }
483     @Override
unsetOnIccRefresh(Handler h)484     public void unsetOnIccRefresh(Handler h) {
485         unregisterForIccRefresh(h);
486     }
487 
488     @Override
setOnCallRing(Handler h, int what, Object obj)489     public void setOnCallRing(Handler h, int what, Object obj) {
490         mRingRegistrant = new Registrant (h, what, obj);
491     }
492 
493     @Override
unSetOnCallRing(Handler h)494     public void unSetOnCallRing(Handler h) {
495         if (mRingRegistrant != null && mRingRegistrant.getHandler() == h) {
496             mRingRegistrant.clear();
497             mRingRegistrant = null;
498         }
499     }
500 
501     @Override
setOnSs(Handler h, int what, Object obj)502     public void setOnSs(Handler h, int what, Object obj) {
503         mSsRegistrant = new Registrant (h, what, obj);
504     }
505 
506     @Override
unSetOnSs(Handler h)507     public void unSetOnSs(Handler h) {
508         mSsRegistrant.clear();
509     }
510 
511     @Override
setOnCatCcAlphaNotify(Handler h, int what, Object obj)512     public void setOnCatCcAlphaNotify(Handler h, int what, Object obj) {
513         mCatCcAlphaRegistrant = new Registrant (h, what, obj);
514     }
515 
516     @Override
unSetOnCatCcAlphaNotify(Handler h)517     public void unSetOnCatCcAlphaNotify(Handler h) {
518         mCatCcAlphaRegistrant.clear();
519     }
520 
521     @Override
registerForInCallVoicePrivacyOn(Handler h, int what, Object obj)522     public void registerForInCallVoicePrivacyOn(Handler h, int what, Object obj) {
523         Registrant r = new Registrant (h, what, obj);
524         mVoicePrivacyOnRegistrants.add(r);
525     }
526 
527     @Override
unregisterForInCallVoicePrivacyOn(Handler h)528     public void unregisterForInCallVoicePrivacyOn(Handler h){
529         mVoicePrivacyOnRegistrants.remove(h);
530     }
531 
532     @Override
registerForInCallVoicePrivacyOff(Handler h, int what, Object obj)533     public void registerForInCallVoicePrivacyOff(Handler h, int what, Object obj) {
534         Registrant r = new Registrant (h, what, obj);
535         mVoicePrivacyOffRegistrants.add(r);
536     }
537 
538     @Override
unregisterForInCallVoicePrivacyOff(Handler h)539     public void unregisterForInCallVoicePrivacyOff(Handler h){
540         mVoicePrivacyOffRegistrants.remove(h);
541     }
542 
543     @Override
setOnRestrictedStateChanged(Handler h, int what, Object obj)544     public void setOnRestrictedStateChanged(Handler h, int what, Object obj) {
545         mRestrictedStateRegistrant = new Registrant (h, what, obj);
546     }
547 
548     @Override
unSetOnRestrictedStateChanged(Handler h)549     public void unSetOnRestrictedStateChanged(Handler h) {
550         if (mRestrictedStateRegistrant != null && mRestrictedStateRegistrant.getHandler() == h) {
551             mRestrictedStateRegistrant.clear();
552             mRestrictedStateRegistrant = null;
553         }
554     }
555 
556     @Override
registerForDisplayInfo(Handler h, int what, Object obj)557     public void registerForDisplayInfo(Handler h, int what, Object obj) {
558         Registrant r = new Registrant (h, what, obj);
559         mDisplayInfoRegistrants.add(r);
560     }
561 
562     @Override
unregisterForDisplayInfo(Handler h)563     public void unregisterForDisplayInfo(Handler h) {
564         mDisplayInfoRegistrants.remove(h);
565     }
566 
567     @Override
registerForCallWaitingInfo(Handler h, int what, Object obj)568     public void registerForCallWaitingInfo(Handler h, int what, Object obj) {
569         Registrant r = new Registrant (h, what, obj);
570         mCallWaitingInfoRegistrants.add(r);
571     }
572 
573     @Override
unregisterForCallWaitingInfo(Handler h)574     public void unregisterForCallWaitingInfo(Handler h) {
575         mCallWaitingInfoRegistrants.remove(h);
576     }
577 
578     @Override
registerForSignalInfo(Handler h, int what, Object obj)579     public void registerForSignalInfo(Handler h, int what, Object obj) {
580         Registrant r = new Registrant (h, what, obj);
581         mSignalInfoRegistrants.add(r);
582     }
583 
setOnUnsolOemHookRaw(Handler h, int what, Object obj)584     public void setOnUnsolOemHookRaw(Handler h, int what, Object obj) {
585         mUnsolOemHookRawRegistrant = new Registrant (h, what, obj);
586     }
587 
unSetOnUnsolOemHookRaw(Handler h)588     public void unSetOnUnsolOemHookRaw(Handler h) {
589         if (mUnsolOemHookRawRegistrant != null && mUnsolOemHookRawRegistrant.getHandler() == h) {
590             mUnsolOemHookRawRegistrant.clear();
591             mUnsolOemHookRawRegistrant = null;
592         }
593     }
594 
595     @Override
unregisterForSignalInfo(Handler h)596     public void unregisterForSignalInfo(Handler h) {
597         mSignalInfoRegistrants.remove(h);
598     }
599 
600     @Override
registerForCdmaOtaProvision(Handler h,int what, Object obj)601     public void registerForCdmaOtaProvision(Handler h,int what, Object obj){
602         Registrant r = new Registrant (h, what, obj);
603         mOtaProvisionRegistrants.add(r);
604     }
605 
606     @Override
unregisterForCdmaOtaProvision(Handler h)607     public void unregisterForCdmaOtaProvision(Handler h){
608         mOtaProvisionRegistrants.remove(h);
609     }
610 
611     @Override
registerForNumberInfo(Handler h,int what, Object obj)612     public void registerForNumberInfo(Handler h,int what, Object obj) {
613         Registrant r = new Registrant (h, what, obj);
614         mNumberInfoRegistrants.add(r);
615     }
616 
617     @Override
unregisterForNumberInfo(Handler h)618     public void unregisterForNumberInfo(Handler h){
619         mNumberInfoRegistrants.remove(h);
620     }
621 
622      @Override
registerForRedirectedNumberInfo(Handler h,int what, Object obj)623     public void registerForRedirectedNumberInfo(Handler h,int what, Object obj) {
624         Registrant r = new Registrant (h, what, obj);
625         mRedirNumInfoRegistrants.add(r);
626     }
627 
628     @Override
unregisterForRedirectedNumberInfo(Handler h)629     public void unregisterForRedirectedNumberInfo(Handler h) {
630         mRedirNumInfoRegistrants.remove(h);
631     }
632 
633     @Override
registerForLineControlInfo(Handler h, int what, Object obj)634     public void registerForLineControlInfo(Handler h, int what, Object obj) {
635         Registrant r = new Registrant (h, what, obj);
636         mLineControlInfoRegistrants.add(r);
637     }
638 
639     @Override
unregisterForLineControlInfo(Handler h)640     public void unregisterForLineControlInfo(Handler h) {
641         mLineControlInfoRegistrants.remove(h);
642     }
643 
644     @Override
registerFoT53ClirlInfo(Handler h,int what, Object obj)645     public void registerFoT53ClirlInfo(Handler h,int what, Object obj) {
646         Registrant r = new Registrant (h, what, obj);
647         mT53ClirInfoRegistrants.add(r);
648     }
649 
650     @Override
unregisterForT53ClirInfo(Handler h)651     public void unregisterForT53ClirInfo(Handler h) {
652         mT53ClirInfoRegistrants.remove(h);
653     }
654 
655     @Override
registerForT53AudioControlInfo(Handler h,int what, Object obj)656     public void registerForT53AudioControlInfo(Handler h,int what, Object obj) {
657         Registrant r = new Registrant (h, what, obj);
658         mT53AudCntrlInfoRegistrants.add(r);
659     }
660 
661     @Override
unregisterForT53AudioControlInfo(Handler h)662     public void unregisterForT53AudioControlInfo(Handler h) {
663         mT53AudCntrlInfoRegistrants.remove(h);
664     }
665 
666     @Override
registerForRingbackTone(Handler h, int what, Object obj)667     public void registerForRingbackTone(Handler h, int what, Object obj) {
668         Registrant r = new Registrant (h, what, obj);
669         mRingbackToneRegistrants.add(r);
670     }
671 
672     @Override
unregisterForRingbackTone(Handler h)673     public void unregisterForRingbackTone(Handler h) {
674         mRingbackToneRegistrants.remove(h);
675     }
676 
677     @Override
registerForResendIncallMute(Handler h, int what, Object obj)678     public void registerForResendIncallMute(Handler h, int what, Object obj) {
679         Registrant r = new Registrant (h, what, obj);
680         mResendIncallMuteRegistrants.add(r);
681     }
682 
683     @Override
unregisterForResendIncallMute(Handler h)684     public void unregisterForResendIncallMute(Handler h) {
685         mResendIncallMuteRegistrants.remove(h);
686     }
687 
688     @Override
registerForCdmaSubscriptionChanged(Handler h, int what, Object obj)689     public void registerForCdmaSubscriptionChanged(Handler h, int what, Object obj) {
690         Registrant r = new Registrant (h, what, obj);
691         mCdmaSubscriptionChangedRegistrants.add(r);
692     }
693 
694     @Override
unregisterForCdmaSubscriptionChanged(Handler h)695     public void unregisterForCdmaSubscriptionChanged(Handler h) {
696         mCdmaSubscriptionChangedRegistrants.remove(h);
697     }
698 
699     @Override
registerForCdmaPrlChanged(Handler h, int what, Object obj)700     public void registerForCdmaPrlChanged(Handler h, int what, Object obj) {
701         Registrant r = new Registrant (h, what, obj);
702         mCdmaPrlChangedRegistrants.add(r);
703     }
704 
705     @Override
unregisterForCdmaPrlChanged(Handler h)706     public void unregisterForCdmaPrlChanged(Handler h) {
707         mCdmaPrlChangedRegistrants.remove(h);
708     }
709 
710     @Override
registerForExitEmergencyCallbackMode(Handler h, int what, Object obj)711     public void registerForExitEmergencyCallbackMode(Handler h, int what, Object obj) {
712         Registrant r = new Registrant (h, what, obj);
713         mExitEmergencyCallbackModeRegistrants.add(r);
714     }
715 
716     @Override
unregisterForExitEmergencyCallbackMode(Handler h)717     public void unregisterForExitEmergencyCallbackMode(Handler h) {
718         mExitEmergencyCallbackModeRegistrants.remove(h);
719     }
720 
721     @Override
registerForHardwareConfigChanged(Handler h, int what, Object obj)722     public void registerForHardwareConfigChanged(Handler h, int what, Object obj) {
723         Registrant r = new Registrant (h, what, obj);
724         mHardwareConfigChangeRegistrants.add(r);
725     }
726 
727     @Override
unregisterForHardwareConfigChanged(Handler h)728     public void unregisterForHardwareConfigChanged(Handler h) {
729         mHardwareConfigChangeRegistrants.remove(h);
730     }
731 
732     /**
733      * {@inheritDoc}
734      */
735     @Override
registerForRilConnected(Handler h, int what, Object obj)736     public void registerForRilConnected(Handler h, int what, Object obj) {
737         Registrant r = new Registrant (h, what, obj);
738         mRilConnectedRegistrants.add(r);
739         if (mRilVersion != -1) {
740             r.notifyRegistrant(new AsyncResult(null, new Integer(mRilVersion), null));
741         }
742     }
743 
744     @Override
unregisterForRilConnected(Handler h)745     public void unregisterForRilConnected(Handler h) {
746         mRilConnectedRegistrants.remove(h);
747     }
748 
registerForSubscriptionStatusChanged(Handler h, int what, Object obj)749     public void registerForSubscriptionStatusChanged(Handler h, int what, Object obj) {
750         Registrant r = new Registrant (h, what, obj);
751         mSubscriptionStatusRegistrants.add(r);
752     }
753 
unregisterForSubscriptionStatusChanged(Handler h)754     public void unregisterForSubscriptionStatusChanged(Handler h) {
755         mSubscriptionStatusRegistrants.remove(h);
756     }
757 
758     //***** Protected Methods
759     /**
760      * Store new RadioState and send notification based on the changes
761      *
762      * This function is called only by RIL.java when receiving unsolicited
763      * RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED
764      *
765      * RadioState has 3 values : RADIO_OFF, RADIO_UNAVAILABLE, RADIO_ON.
766      *
767      * @param newState new RadioState decoded from RIL_UNSOL_RADIO_STATE_CHANGED
768      */
setRadioState(RadioState newState)769     protected void setRadioState(RadioState newState) {
770         RadioState oldState;
771 
772         synchronized (mStateMonitor) {
773             oldState = mState;
774             mState = newState;
775 
776             if (oldState == mState) {
777                 // no state transition
778                 return;
779             }
780 
781             mRadioStateChangedRegistrants.notifyRegistrants();
782 
783             if (mState.isAvailable() && !oldState.isAvailable()) {
784                 mAvailRegistrants.notifyRegistrants();
785             }
786 
787             if (!mState.isAvailable() && oldState.isAvailable()) {
788                 mNotAvailRegistrants.notifyRegistrants();
789             }
790 
791             if (mState.isOn() && !oldState.isOn()) {
792                 mOnRegistrants.notifyRegistrants();
793             }
794 
795             if ((!mState.isOn() || !mState.isAvailable())
796                 && !((!oldState.isOn() || !oldState.isAvailable()))
797             ) {
798                 mOffOrNotAvailRegistrants.notifyRegistrants();
799             }
800         }
801     }
802 
803     /**
804      * {@inheritDoc}
805      */
806     @Override
getLteOnCdmaMode()807     public int getLteOnCdmaMode() {
808         return TelephonyManager.getLteOnCdmaModeStatic();
809     }
810 
811     /**
812      * {@inheritDoc}
813      */
814     @Override
registerForCellInfoList(Handler h, int what, Object obj)815     public void registerForCellInfoList(Handler h, int what, Object obj) {
816         Registrant r = new Registrant (h, what, obj);
817         mRilCellInfoListRegistrants.add(r);
818     }
819     @Override
unregisterForCellInfoList(Handler h)820     public void unregisterForCellInfoList(Handler h) {
821         mRilCellInfoListRegistrants.remove(h);
822     }
823 
824     @Override
registerForSrvccStateChanged(Handler h, int what, Object obj)825     public void registerForSrvccStateChanged(Handler h, int what, Object obj) {
826         Registrant r = new Registrant (h, what, obj);
827 
828         mSrvccStateRegistrants.add(r);
829     }
830 
831     @Override
unregisterForSrvccStateChanged(Handler h)832     public void unregisterForSrvccStateChanged(Handler h) {
833         mSrvccStateRegistrants.remove(h);
834     }
835 
836     @Override
testingEmergencyCall()837     public void testingEmergencyCall() {}
838 
839     @Override
getRilVersion()840     public int getRilVersion() {
841         return mRilVersion;
842     }
843 
setUiccSubscription(int slotId, int appIndex, int subId, int subStatus, Message response)844     public void setUiccSubscription(int slotId, int appIndex, int subId, int subStatus,
845             Message response) {
846     }
847 
setDataAllowed(boolean allowed, Message response)848     public void setDataAllowed(boolean allowed, Message response) {
849     }
850 
851     @Override
requestShutdown(Message result)852     public void requestShutdown(Message result) {
853     }
854 
855     @Override
getRadioCapability(Message result)856     public void getRadioCapability(Message result) {
857     }
858 
859     @Override
setRadioCapability(RadioCapability rc, Message response)860     public void setRadioCapability(RadioCapability rc, Message response) {
861     }
862 
863     @Override
registerForRadioCapabilityChanged(Handler h, int what, Object obj)864     public void registerForRadioCapabilityChanged(Handler h, int what, Object obj) {
865         Registrant r = new Registrant(h, what, obj);
866         mPhoneRadioCapabilityChangedRegistrants.add(r);
867     }
868 
869     @Override
unregisterForRadioCapabilityChanged(Handler h)870     public void unregisterForRadioCapabilityChanged(Handler h) {
871         mPhoneRadioCapabilityChangedRegistrants.remove(h);
872     }
873 
874     @Override
startLceService(int reportIntervalMs, boolean pullMode, Message result)875     public void startLceService(int reportIntervalMs, boolean pullMode, Message result) {
876     }
877 
878     @Override
stopLceService(Message result)879     public void stopLceService(Message result) {
880     }
881 
882     @Override
pullLceData(Message result)883     public void pullLceData(Message result) {
884     }
885 
886     @Override
registerForLceInfo(Handler h, int what, Object obj)887     public void registerForLceInfo(Handler h, int what, Object obj) {
888       mLceInfoRegistrant = new Registrant(h, what, obj);
889     }
890 
891     @Override
unregisterForLceInfo(Handler h)892     public void unregisterForLceInfo(Handler h) {
893       if (mLceInfoRegistrant != null && mLceInfoRegistrant.getHandler() == h) {
894           mLceInfoRegistrant.clear();
895           mLceInfoRegistrant = null;
896       }
897     }
898 
899     @Override
registerForPcoData(Handler h, int what, Object obj)900     public void registerForPcoData(Handler h, int what, Object obj) {
901         mPcoDataRegistrants.add(new Registrant(h, what, obj));
902     }
903 
904     @Override
unregisterForPcoData(Handler h)905     public void unregisterForPcoData(Handler h) {
906         mPcoDataRegistrants.remove(h);
907     }
908 }
909