1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.telephony;
18 
19 import android.os.Bundle;
20 import android.os.Handler;
21 import android.os.Looper;
22 import android.os.Message;
23 
24 import com.android.internal.telephony.IPhoneStateListener;
25 
26 import java.util.List;
27 import java.lang.ref.WeakReference;
28 
29 /**
30  * A listener class for monitoring changes in specific telephony states
31  * on the device, including service state, signal strength, message
32  * waiting indicator (voicemail), and others.
33  * <p>
34  * Override the methods for the state that you wish to receive updates for, and
35  * pass your PhoneStateListener object, along with bitwise-or of the LISTEN_
36  * flags to {@link TelephonyManager#listen TelephonyManager.listen()}.
37  * <p>
38  * Note that access to some telephony information is
39  * permission-protected. Your application won't receive updates for protected
40  * information unless it has the appropriate permissions declared in
41  * its manifest file. Where permissions apply, they are noted in the
42  * appropriate LISTEN_ flags.
43  */
44 public class PhoneStateListener {
45     private static final String LOG_TAG = "PhoneStateListener";
46     private static final boolean DBG = false; // STOPSHIP if true
47 
48     /**
49      * Stop listening for updates.
50      */
51     public static final int LISTEN_NONE = 0;
52 
53     /**
54      *  Listen for changes to the network service state (cellular).
55      *
56      *  @see #onServiceStateChanged
57      *  @see ServiceState
58      */
59     public static final int LISTEN_SERVICE_STATE                            = 0x00000001;
60 
61     /**
62      * Listen for changes to the network signal strength (cellular).
63      * {@more}
64      * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
65      * READ_PHONE_STATE}
66      * <p>
67      *
68      * @see #onSignalStrengthChanged
69      *
70      * @deprecated by {@link #LISTEN_SIGNAL_STRENGTHS}
71      */
72     @Deprecated
73     public static final int LISTEN_SIGNAL_STRENGTH                          = 0x00000002;
74 
75     /**
76      * Listen for changes to the message-waiting indicator.
77      * {@more}
78      * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
79      * READ_PHONE_STATE}
80      * <p>
81      * Example: The status bar uses this to determine when to display the
82      * voicemail icon.
83      *
84      * @see #onMessageWaitingIndicatorChanged
85      */
86     public static final int LISTEN_MESSAGE_WAITING_INDICATOR                = 0x00000004;
87 
88     /**
89      * Listen for changes to the call-forwarding indicator.
90      * {@more}
91      * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
92      * READ_PHONE_STATE}
93      * @see #onCallForwardingIndicatorChanged
94      */
95     public static final int LISTEN_CALL_FORWARDING_INDICATOR                = 0x00000008;
96 
97     /**
98      * Listen for changes to the device's cell location. Note that
99      * this will result in frequent callbacks to the listener.
100      * {@more}
101      * Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION
102      * ACCESS_COARSE_LOCATION}
103      * <p>
104      * If you need regular location updates but want more control over
105      * the update interval or location precision, you can set up a listener
106      * through the {@link android.location.LocationManager location manager}
107      * instead.
108      *
109      * @see #onCellLocationChanged
110      */
111     public static final int LISTEN_CELL_LOCATION                            = 0x00000010;
112 
113     /**
114      * Listen for changes to the device call state.
115      * {@more}
116      *
117      * @see #onCallStateChanged
118      */
119     public static final int LISTEN_CALL_STATE                               = 0x00000020;
120 
121     /**
122      * Listen for changes to the data connection state (cellular).
123      *
124      * @see #onDataConnectionStateChanged
125      */
126     public static final int LISTEN_DATA_CONNECTION_STATE                    = 0x00000040;
127 
128     /**
129      * Listen for changes to the direction of data traffic on the data
130      * connection (cellular).
131      * {@more}
132      * Example: The status bar uses this to display the appropriate
133      * data-traffic icon.
134      *
135      * @see #onDataActivity
136      */
137     public static final int LISTEN_DATA_ACTIVITY                            = 0x00000080;
138 
139     /**
140      * Listen for changes to the network signal strengths (cellular).
141      * <p>
142      * Example: The status bar uses this to control the signal-strength
143      * icon.
144      *
145      * @see #onSignalStrengthsChanged
146      */
147     public static final int LISTEN_SIGNAL_STRENGTHS                         = 0x00000100;
148 
149     /**
150      * Listen for changes to OTASP mode.
151      *
152      * @see #onOtaspChanged
153      * @hide
154      */
155     public static final int LISTEN_OTASP_CHANGED                            = 0x00000200;
156 
157     /**
158      * Listen for changes to observed cell info.
159      *
160      * @see #onCellInfoChanged
161      */
162     public static final int LISTEN_CELL_INFO = 0x00000400;
163 
164     /**
165      * Listen for precise changes and fails to the device calls (cellular).
166      * {@more}
167      * Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
168      * READ_PRECISE_PHONE_STATE}
169      *
170      * @hide
171      */
172     public static final int LISTEN_PRECISE_CALL_STATE                       = 0x00000800;
173 
174     /**
175      * Listen for precise changes and fails on the data connection (cellular).
176      * {@more}
177      * Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
178      * READ_PRECISE_PHONE_STATE}
179      *
180      * @see #onPreciseDataConnectionStateChanged
181      * @hide
182      */
183     public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE            = 0x00001000;
184 
185     /**
186      * Listen for real time info for all data connections (cellular)).
187      * {@more}
188      * Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
189      * READ_PRECISE_PHONE_STATE}
190      * @see #onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo)
191      *
192      * @deprecated Use {@link TelephonyManager#getModemActivityInfo()}
193      * @hide
194      */
195     @Deprecated
196     public static final int LISTEN_DATA_CONNECTION_REAL_TIME_INFO           = 0x00002000;
197 
198     /**
199      * Listen for changes to LTE network state
200      *
201      * @see #onLteNetworkStateChanged
202      * @hide
203      */
204     public static final int LISTEN_VOLTE_STATE                              = 0x00004000;
205 
206     /**
207      * Listen for OEM hook raw event
208      *
209      * @see #onOemHookRawEvent
210      * @hide
211      * @deprecated OEM needs a vendor-extension hal and their apps should use that instead
212      */
213     @Deprecated
214     public static final int LISTEN_OEM_HOOK_RAW_EVENT                       = 0x00008000;
215 
216     /**
217      * Listen for carrier network changes indicated by a carrier app.
218      *
219      * @see #onCarrierNetworkRequest
220      * @see TelephonyManager#notifyCarrierNetworkChange(boolean)
221      * @hide
222      */
223     public static final int LISTEN_CARRIER_NETWORK_CHANGE                   = 0x00010000;
224 
225     /**
226      *  Listen for changes to the sim voice activation state
227      *  @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
228      *  @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
229      *  @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
230      *  @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
231      *  @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
232      *  {@more}
233      *  Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates voice service has been
234      *  fully activated
235      *
236      *  @see #onVoiceActivationStateChanged
237      *  @hide
238      */
239     public static final int LISTEN_VOICE_ACTIVATION_STATE                   = 0x00020000;
240 
241     /**
242      *  Listen for changes to the sim data activation state
243      *  @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
244      *  @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
245      *  @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
246      *  @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
247      *  @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
248      *  {@more}
249      *  Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates data service has been
250      *  fully activated
251      *
252      *  @see #onDataActivationStateChanged
253      *  @hide
254      */
255     public static final int LISTEN_DATA_ACTIVATION_STATE                   = 0x00040000;
256 
257      /*
258      * Subscription used to listen to the phone state changes
259      * @hide
260      */
261     /** @hide */
262     protected Integer mSubId;
263 
264     private final Handler mHandler;
265 
266     /**
267      * Create a PhoneStateListener for the Phone with the default subscription.
268      * This class requires Looper.myLooper() not return null.
269      */
PhoneStateListener()270     public PhoneStateListener() {
271         this(null, Looper.myLooper());
272     }
273 
274     /**
275      * Create a PhoneStateListener for the Phone with the default subscription
276      * using a particular non-null Looper.
277      * @hide
278      */
PhoneStateListener(Looper looper)279     public PhoneStateListener(Looper looper) {
280         this(null, looper);
281     }
282 
283     /**
284      * Create a PhoneStateListener for the Phone using the specified subscription.
285      * This class requires Looper.myLooper() not return null. To supply your
286      * own non-null Looper use PhoneStateListener(int subId, Looper looper) below.
287      * @hide
288      */
PhoneStateListener(Integer subId)289     public PhoneStateListener(Integer subId) {
290         this(subId, Looper.myLooper());
291     }
292 
293     /**
294      * Create a PhoneStateListener for the Phone using the specified subscription
295      * and non-null Looper.
296      * @hide
297      */
PhoneStateListener(Integer subId, Looper looper)298     public PhoneStateListener(Integer subId, Looper looper) {
299         if (DBG) log("ctor: subId=" + subId + " looper=" + looper);
300         mSubId = subId;
301         mHandler = new Handler(looper) {
302             public void handleMessage(Message msg) {
303                 if (DBG) {
304                     log("mSubId=" + mSubId + " what=0x" + Integer.toHexString(msg.what)
305                             + " msg=" + msg);
306                 }
307                 switch (msg.what) {
308                     case LISTEN_SERVICE_STATE:
309                         PhoneStateListener.this.onServiceStateChanged((ServiceState)msg.obj);
310                         break;
311                     case LISTEN_SIGNAL_STRENGTH:
312                         PhoneStateListener.this.onSignalStrengthChanged(msg.arg1);
313                         break;
314                     case LISTEN_MESSAGE_WAITING_INDICATOR:
315                         PhoneStateListener.this.onMessageWaitingIndicatorChanged(msg.arg1 != 0);
316                         break;
317                     case LISTEN_CALL_FORWARDING_INDICATOR:
318                         PhoneStateListener.this.onCallForwardingIndicatorChanged(msg.arg1 != 0);
319                         break;
320                     case LISTEN_CELL_LOCATION:
321                         PhoneStateListener.this.onCellLocationChanged((CellLocation)msg.obj);
322                         break;
323                     case LISTEN_CALL_STATE:
324                         PhoneStateListener.this.onCallStateChanged(msg.arg1, (String)msg.obj);
325                         break;
326                     case LISTEN_DATA_CONNECTION_STATE:
327                         PhoneStateListener.this.onDataConnectionStateChanged(msg.arg1, msg.arg2);
328                         PhoneStateListener.this.onDataConnectionStateChanged(msg.arg1);
329                         break;
330                     case LISTEN_DATA_ACTIVITY:
331                         PhoneStateListener.this.onDataActivity(msg.arg1);
332                         break;
333                     case LISTEN_SIGNAL_STRENGTHS:
334                         PhoneStateListener.this.onSignalStrengthsChanged((SignalStrength)msg.obj);
335                         break;
336                     case LISTEN_OTASP_CHANGED:
337                         PhoneStateListener.this.onOtaspChanged(msg.arg1);
338                         break;
339                     case LISTEN_CELL_INFO:
340                         PhoneStateListener.this.onCellInfoChanged((List<CellInfo>)msg.obj);
341                         break;
342                     case LISTEN_PRECISE_CALL_STATE:
343                         PhoneStateListener.this.onPreciseCallStateChanged((PreciseCallState)msg.obj);
344                         break;
345                     case LISTEN_PRECISE_DATA_CONNECTION_STATE:
346                         PhoneStateListener.this.onPreciseDataConnectionStateChanged(
347                                 (PreciseDataConnectionState)msg.obj);
348                         break;
349                     case LISTEN_DATA_CONNECTION_REAL_TIME_INFO:
350                         PhoneStateListener.this.onDataConnectionRealTimeInfoChanged(
351                                 (DataConnectionRealTimeInfo)msg.obj);
352                         break;
353                     case LISTEN_VOLTE_STATE:
354                         PhoneStateListener.this.onVoLteServiceStateChanged((VoLteServiceState)msg.obj);
355                         break;
356                     case LISTEN_VOICE_ACTIVATION_STATE:
357                         PhoneStateListener.this.onVoiceActivationStateChanged((int)msg.obj);
358                         break;
359                     case LISTEN_DATA_ACTIVATION_STATE:
360                         PhoneStateListener.this.onDataActivationStateChanged((int)msg.obj);
361                         break;
362                     case LISTEN_OEM_HOOK_RAW_EVENT:
363                         PhoneStateListener.this.onOemHookRawEvent((byte[])msg.obj);
364                         break;
365                     case LISTEN_CARRIER_NETWORK_CHANGE:
366                         PhoneStateListener.this.onCarrierNetworkChange((boolean)msg.obj);
367                         break;
368 
369                 }
370             }
371         };
372     }
373 
374     /**
375      * Callback invoked when device service state changes.
376      *
377      * @see ServiceState#STATE_EMERGENCY_ONLY
378      * @see ServiceState#STATE_IN_SERVICE
379      * @see ServiceState#STATE_OUT_OF_SERVICE
380      * @see ServiceState#STATE_POWER_OFF
381      */
onServiceStateChanged(ServiceState serviceState)382     public void onServiceStateChanged(ServiceState serviceState) {
383         // default implementation empty
384     }
385 
386     /**
387      * Callback invoked when network signal strength changes.
388      *
389      * @see ServiceState#STATE_EMERGENCY_ONLY
390      * @see ServiceState#STATE_IN_SERVICE
391      * @see ServiceState#STATE_OUT_OF_SERVICE
392      * @see ServiceState#STATE_POWER_OFF
393      * @deprecated Use {@link #onSignalStrengthsChanged(SignalStrength)}
394      */
395     @Deprecated
onSignalStrengthChanged(int asu)396     public void onSignalStrengthChanged(int asu) {
397         // default implementation empty
398     }
399 
400     /**
401      * Callback invoked when the message-waiting indicator changes.
402      */
onMessageWaitingIndicatorChanged(boolean mwi)403     public void onMessageWaitingIndicatorChanged(boolean mwi) {
404         // default implementation empty
405     }
406 
407     /**
408      * Callback invoked when the call-forwarding indicator changes.
409      */
onCallForwardingIndicatorChanged(boolean cfi)410     public void onCallForwardingIndicatorChanged(boolean cfi) {
411         // default implementation empty
412     }
413 
414     /**
415      * Callback invoked when device cell location changes.
416      */
onCellLocationChanged(CellLocation location)417     public void onCellLocationChanged(CellLocation location) {
418         // default implementation empty
419     }
420 
421     /**
422      * Callback invoked when device call state changes.
423      * @param state call state
424      * @param incomingNumber incoming call phone number. If application does not have
425      * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} permission, an empty
426      * string will be passed as an argument.
427      *
428      * @see TelephonyManager#CALL_STATE_IDLE
429      * @see TelephonyManager#CALL_STATE_RINGING
430      * @see TelephonyManager#CALL_STATE_OFFHOOK
431      */
onCallStateChanged(int state, String incomingNumber)432     public void onCallStateChanged(int state, String incomingNumber) {
433         // default implementation empty
434     }
435 
436     /**
437      * Callback invoked when connection state changes.
438      *
439      * @see TelephonyManager#DATA_DISCONNECTED
440      * @see TelephonyManager#DATA_CONNECTING
441      * @see TelephonyManager#DATA_CONNECTED
442      * @see TelephonyManager#DATA_SUSPENDED
443      */
onDataConnectionStateChanged(int state)444     public void onDataConnectionStateChanged(int state) {
445         // default implementation empty
446     }
447 
448     /**
449      * same as above, but with the network type.  Both called.
450      */
onDataConnectionStateChanged(int state, int networkType)451     public void onDataConnectionStateChanged(int state, int networkType) {
452     }
453 
454     /**
455      * Callback invoked when data activity state changes.
456      *
457      * @see TelephonyManager#DATA_ACTIVITY_NONE
458      * @see TelephonyManager#DATA_ACTIVITY_IN
459      * @see TelephonyManager#DATA_ACTIVITY_OUT
460      * @see TelephonyManager#DATA_ACTIVITY_INOUT
461      * @see TelephonyManager#DATA_ACTIVITY_DORMANT
462      */
onDataActivity(int direction)463     public void onDataActivity(int direction) {
464         // default implementation empty
465     }
466 
467     /**
468      * Callback invoked when network signal strengths changes.
469      *
470      * @see ServiceState#STATE_EMERGENCY_ONLY
471      * @see ServiceState#STATE_IN_SERVICE
472      * @see ServiceState#STATE_OUT_OF_SERVICE
473      * @see ServiceState#STATE_POWER_OFF
474      */
onSignalStrengthsChanged(SignalStrength signalStrength)475     public void onSignalStrengthsChanged(SignalStrength signalStrength) {
476         // default implementation empty
477     }
478 
479 
480     /**
481      * The Over The Air Service Provisioning (OTASP) has changed. Requires
482      * the READ_PHONE_STATE permission.
483      * @param otaspMode is integer <code>OTASP_UNKNOWN=1<code>
484      *   means the value is currently unknown and the system should wait until
485      *   <code>OTASP_NEEDED=2<code> or <code>OTASP_NOT_NEEDED=3<code> is received before
486      *   making the decision to perform OTASP or not.
487      *
488      * @hide
489      */
onOtaspChanged(int otaspMode)490     public void onOtaspChanged(int otaspMode) {
491         // default implementation empty
492     }
493 
494     /**
495      * Callback invoked when a observed cell info has changed,
496      * or new cells have been added or removed.
497      * @param cellInfo is the list of currently visible cells.
498      */
onCellInfoChanged(List<CellInfo> cellInfo)499     public void onCellInfoChanged(List<CellInfo> cellInfo) {
500     }
501 
502     /**
503      * Callback invoked when precise device call state changes.
504      *
505      * @hide
506      */
onPreciseCallStateChanged(PreciseCallState callState)507     public void onPreciseCallStateChanged(PreciseCallState callState) {
508         // default implementation empty
509     }
510 
511     /**
512      * Callback invoked when data connection state changes with precise information.
513      *
514      * @hide
515      */
onPreciseDataConnectionStateChanged( PreciseDataConnectionState dataConnectionState)516     public void onPreciseDataConnectionStateChanged(
517             PreciseDataConnectionState dataConnectionState) {
518         // default implementation empty
519     }
520 
521     /**
522      * Callback invoked when data connection state changes with precise information.
523      *
524      * @hide
525      */
onDataConnectionRealTimeInfoChanged( DataConnectionRealTimeInfo dcRtInfo)526     public void onDataConnectionRealTimeInfoChanged(
527             DataConnectionRealTimeInfo dcRtInfo) {
528         // default implementation empty
529     }
530 
531     /**
532      * Callback invoked when the service state of LTE network
533      * related to the VoLTE service has changed.
534      * @param stateInfo is the current LTE network information
535      * @hide
536      */
onVoLteServiceStateChanged(VoLteServiceState stateInfo)537     public void onVoLteServiceStateChanged(VoLteServiceState stateInfo) {
538     }
539 
540     /**
541      * Callback invoked when the SIM voice activation state has changed
542      * @param state is the current SIM voice activation state
543      * @hide
544      */
onVoiceActivationStateChanged(int state)545     public void onVoiceActivationStateChanged(int state) {
546 
547     }
548 
549     /**
550      * Callback invoked when the SIM data activation state has changed
551      * @param state is the current SIM data activation state
552      * @hide
553      */
onDataActivationStateChanged(int state)554     public void onDataActivationStateChanged(int state) {
555 
556     }
557 
558     /**
559      * Callback invoked when OEM hook raw event is received. Requires
560      * the READ_PRIVILEGED_PHONE_STATE permission.
561      * @param rawData is the byte array of the OEM hook raw data.
562      * @hide
563      */
onOemHookRawEvent(byte[] rawData)564     public void onOemHookRawEvent(byte[] rawData) {
565         // default implementation empty
566     }
567 
568     /**
569      * Callback invoked when telephony has received notice from a carrier
570      * app that a network action that could result in connectivity loss
571      * has been requested by an app using
572      * {@link android.telephony.TelephonyManager#notifyCarrierNetworkChange(boolean)}
573      *
574      * @param active Whether the carrier network change is or shortly
575      *               will be active. This value is true to indicate
576      *               showing alternative UI and false to stop.
577      *
578      * @hide
579      */
onCarrierNetworkChange(boolean active)580     public void onCarrierNetworkChange(boolean active) {
581         // default implementation empty
582     }
583 
584     /**
585      * The callback methods need to be called on the handler thread where
586      * this object was created.  If the binder did that for us it'd be nice.
587      *
588      * Using a static class and weak reference here to avoid memory leak caused by the
589      * IPhoneStateListener.Stub callback retaining references to the outside PhoneStateListeners:
590      * even caller has been destroyed and "un-registered" the PhoneStateListener, it is still not
591      * eligible for GC given the references coming from:
592      * Native Stack --> PhoneStateListener --> Context (Activity).
593      * memory of caller's context will be collected after GC from service side get triggered
594      */
595     private static class IPhoneStateListenerStub extends IPhoneStateListener.Stub {
596         private WeakReference<PhoneStateListener> mPhoneStateListenerWeakRef;
597 
IPhoneStateListenerStub(PhoneStateListener phoneStateListener)598         public IPhoneStateListenerStub(PhoneStateListener phoneStateListener) {
599             mPhoneStateListenerWeakRef = new WeakReference<PhoneStateListener>(phoneStateListener);
600         }
601 
send(int what, int arg1, int arg2, Object obj)602         private void send(int what, int arg1, int arg2, Object obj) {
603             PhoneStateListener listener = mPhoneStateListenerWeakRef.get();
604             if (listener != null) {
605                 Message.obtain(listener.mHandler, what, arg1, arg2, obj).sendToTarget();
606             }
607         }
608 
onServiceStateChanged(ServiceState serviceState)609         public void onServiceStateChanged(ServiceState serviceState) {
610             send(LISTEN_SERVICE_STATE, 0, 0, serviceState);
611         }
612 
onSignalStrengthChanged(int asu)613         public void onSignalStrengthChanged(int asu) {
614             send(LISTEN_SIGNAL_STRENGTH, asu, 0, null);
615         }
616 
onMessageWaitingIndicatorChanged(boolean mwi)617         public void onMessageWaitingIndicatorChanged(boolean mwi) {
618             send(LISTEN_MESSAGE_WAITING_INDICATOR, mwi ? 1 : 0, 0, null);
619         }
620 
onCallForwardingIndicatorChanged(boolean cfi)621         public void onCallForwardingIndicatorChanged(boolean cfi) {
622             send(LISTEN_CALL_FORWARDING_INDICATOR, cfi ? 1 : 0, 0, null);
623         }
624 
onCellLocationChanged(Bundle bundle)625         public void onCellLocationChanged(Bundle bundle) {
626             CellLocation location = CellLocation.newFromBundle(bundle);
627             send(LISTEN_CELL_LOCATION, 0, 0, location);
628         }
629 
onCallStateChanged(int state, String incomingNumber)630         public void onCallStateChanged(int state, String incomingNumber) {
631             send(LISTEN_CALL_STATE, state, 0, incomingNumber);
632         }
633 
onDataConnectionStateChanged(int state, int networkType)634         public void onDataConnectionStateChanged(int state, int networkType) {
635             send(LISTEN_DATA_CONNECTION_STATE, state, networkType, null);
636         }
637 
onDataActivity(int direction)638         public void onDataActivity(int direction) {
639             send(LISTEN_DATA_ACTIVITY, direction, 0, null);
640         }
641 
onSignalStrengthsChanged(SignalStrength signalStrength)642         public void onSignalStrengthsChanged(SignalStrength signalStrength) {
643             send(LISTEN_SIGNAL_STRENGTHS, 0, 0, signalStrength);
644         }
645 
onOtaspChanged(int otaspMode)646         public void onOtaspChanged(int otaspMode) {
647             send(LISTEN_OTASP_CHANGED, otaspMode, 0, null);
648         }
649 
onCellInfoChanged(List<CellInfo> cellInfo)650         public void onCellInfoChanged(List<CellInfo> cellInfo) {
651             send(LISTEN_CELL_INFO, 0, 0, cellInfo);
652         }
653 
onPreciseCallStateChanged(PreciseCallState callState)654         public void onPreciseCallStateChanged(PreciseCallState callState) {
655             send(LISTEN_PRECISE_CALL_STATE, 0, 0, callState);
656         }
657 
onPreciseDataConnectionStateChanged( PreciseDataConnectionState dataConnectionState)658         public void onPreciseDataConnectionStateChanged(
659                 PreciseDataConnectionState dataConnectionState) {
660             send(LISTEN_PRECISE_DATA_CONNECTION_STATE, 0, 0, dataConnectionState);
661         }
662 
onDataConnectionRealTimeInfoChanged( DataConnectionRealTimeInfo dcRtInfo)663         public void onDataConnectionRealTimeInfoChanged(
664                 DataConnectionRealTimeInfo dcRtInfo) {
665             send(LISTEN_DATA_CONNECTION_REAL_TIME_INFO, 0, 0, dcRtInfo);
666         }
667 
onVoLteServiceStateChanged(VoLteServiceState lteState)668         public void onVoLteServiceStateChanged(VoLteServiceState lteState) {
669             send(LISTEN_VOLTE_STATE, 0, 0, lteState);
670         }
671 
onVoiceActivationStateChanged(int activationState)672         public void onVoiceActivationStateChanged(int activationState) {
673             send(LISTEN_VOICE_ACTIVATION_STATE, 0, 0, activationState);
674         }
675 
onDataActivationStateChanged(int activationState)676         public void onDataActivationStateChanged(int activationState) {
677             send(LISTEN_DATA_ACTIVATION_STATE, 0, 0, activationState);
678         }
679 
onOemHookRawEvent(byte[] rawData)680         public void onOemHookRawEvent(byte[] rawData) {
681             send(LISTEN_OEM_HOOK_RAW_EVENT, 0, 0, rawData);
682         }
683 
onCarrierNetworkChange(boolean active)684         public void onCarrierNetworkChange(boolean active) {
685             send(LISTEN_CARRIER_NETWORK_CHANGE, 0, 0, active);
686         }
687     }
688 
689     IPhoneStateListener callback = new IPhoneStateListenerStub(this);
690 
log(String s)691     private void log(String s) {
692         Rlog.d(LOG_TAG, s);
693     }
694 }
695