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