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