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