blob: 8b8b3a9252e77ad60cdbbd3166a380b8024b7ff3 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.telephony;
18
Brad Ebingerefed9822018-10-26 10:25:57 -070019import android.Manifest;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -070020import android.annotation.NonNull;
Brad Ebingerefed9822018-10-26 10:25:57 -070021import android.annotation.RequiresPermission;
chen xu760729c2018-10-11 13:18:26 -070022import android.annotation.SystemApi;
Shuo Qian134334b2019-09-12 17:00:31 -070023import android.annotation.TestApi;
Hall Liued6d6e62020-03-26 19:09:30 -070024import android.compat.annotation.ChangeId;
Artur Satayevdf439592019-12-10 17:47:53 +000025import android.compat.annotation.UnsupportedAppUsage;
Nathan Harold7581efd2018-10-25 10:32:10 -070026import android.os.Binder;
chen xuf4c5c6e2018-11-18 18:56:00 -080027import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Handler;
Nathan Harold7581efd2018-10-25 10:32:10 -070029import android.os.HandlerExecutor;
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -070030import android.os.Looper;
Chen Xuc9d4ee12019-09-26 16:11:59 -070031import android.telephony.Annotation.CallState;
32import android.telephony.Annotation.RadioPowerState;
33import android.telephony.Annotation.SimActivationState;
34import android.telephony.Annotation.SrvccState;
sqian46c0c302018-12-27 14:12:11 -080035import android.telephony.emergency.EmergencyNumber;
chen xu0f494682019-01-24 14:14:13 -080036import android.telephony.ims.ImsReasonInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Chen Xu1f6cfa52019-10-13 17:30:32 -070038import com.android.internal.annotations.VisibleForTesting;
Nathan Harold4d340f12019-12-05 17:27:56 -080039import com.android.internal.telephony.IPhoneStateListener;
fionaxu64eebba2016-11-14 13:32:14 -080040
Malcolm Chenf028c3b2019-09-04 16:10:34 -070041import dalvik.system.VMRuntime;
42
fionaxuf5d7c582016-03-22 15:09:55 -070043import java.lang.ref.WeakReference;
Malcolm Chen5ee5c142018-08-08 20:27:45 -070044import java.util.List;
sqian46c0c302018-12-27 14:12:11 -080045import java.util.Map;
Nathan Harold7581efd2018-10-25 10:32:10 -070046import java.util.concurrent.Executor;
Wink Savilleb208a242012-07-25 14:08:09 -070047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048/**
49 * A listener class for monitoring changes in specific telephony states
Wink Saville767a6622009-04-02 01:37:02 -070050 * on the device, including service state, signal strength, message
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 * waiting indicator (voicemail), and others.
52 * <p>
Wink Saville767a6622009-04-02 01:37:02 -070053 * Override the methods for the state that you wish to receive updates for, and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 * pass your PhoneStateListener object, along with bitwise-or of the LISTEN_
Jordan Liu91b2555e2019-02-11 11:36:49 -080055 * flags to {@link TelephonyManager#listen TelephonyManager.listen()}. Methods are
Jordan Liu45da5052019-02-12 10:29:24 -080056 * called when the state changes, as well as once on initial registration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 * <p>
58 * Note that access to some telephony information is
Wink Saville767a6622009-04-02 01:37:02 -070059 * permission-protected. Your application won't receive updates for protected
60 * information unless it has the appropriate permissions declared in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 * its manifest file. Where permissions apply, they are noted in the
Wink Saville767a6622009-04-02 01:37:02 -070062 * appropriate LISTEN_ flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 */
64public class PhoneStateListener {
Wink Saville6d13bc82014-08-01 11:13:40 -070065 private static final String LOG_TAG = "PhoneStateListener";
66 private static final boolean DBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
68 /**
Hall Liued6d6e62020-03-26 19:09:30 -070069 * Experiment flag to set the per-pid registration limit for PhoneStateListeners
70 *
Hall Liu2da50cf2020-03-18 16:24:04 -070071 * Limit on registrations of {@link PhoneStateListener}s on a per-pid
72 * basis. When this limit is exceeded, any calls to {@link TelephonyManager#listen} will fail
73 * with an {@link IllegalStateException}.
74 *
75 * {@link android.os.Process#PHONE_UID}, {@link android.os.Process#SYSTEM_UID}, and the uid that
76 * TelephonyRegistry runs under are exempt from this limit.
Hall Liued6d6e62020-03-26 19:09:30 -070077 *
78 * If the value of the flag is less than 1, enforcement of the limit will be disabled.
Hall Liu2da50cf2020-03-18 16:24:04 -070079 * @hide
80 */
Hall Liued6d6e62020-03-26 19:09:30 -070081 public static final String FLAG_PER_PID_REGISTRATION_LIMIT =
82 "phone_state_listener_per_pid_registration_limit";
83
84 /**
85 * Default value for the per-pid registation limit.
86 * See {@link #FLAG_PER_PID_REGISTRATION_LIMIT}.
87 * @hide
88 */
89 public static final int DEFAULT_PER_PID_REGISTRATION_LIMIT = 50;
90
91 /**
92 * This change enables a limit on the number of {@link PhoneStateListener} objects any process
93 * may register via {@link TelephonyManager#listen}. The default limit is 50, which may change
94 * via remote device config updates.
95 *
96 * This limit is enforced via an {@link IllegalStateException} thrown from
97 * {@link TelephonyManager#listen} when the offending process attempts to register one too many
98 * listeners.
99 *
100 * @hide
101 */
102 @ChangeId
103 public static final long PHONE_STATE_LISTENER_LIMIT_CHANGE_ID = 150880553L;
Hall Liu2da50cf2020-03-18 16:24:04 -0700104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 /**
106 * Stop listening for updates.
chen xud5deeb12019-04-29 13:57:42 -0700107 *
108 * The PhoneStateListener is not tied to any subscription and unregistered for any update.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 */
110 public static final int LISTEN_NONE = 0;
111
112 /**
113 * Listen for changes to the network service state (cellular).
114 *
115 * @see #onServiceStateChanged
116 * @see ServiceState
117 */
118 public static final int LISTEN_SERVICE_STATE = 0x00000001;
119
120 /**
121 * Listen for changes to the network signal strength (cellular).
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700122 * {@more}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 *
124 * @see #onSignalStrengthChanged
Wink Savillee9b06d72009-05-18 21:47:50 -0700125 *
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800126 * @deprecated by {@link #LISTEN_SIGNAL_STRENGTHS}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 */
Wink Savillecc6ff2b2009-12-02 09:46:38 -0800128 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 public static final int LISTEN_SIGNAL_STRENGTH = 0x00000002;
130
131 /**
132 * Listen for changes to the message-waiting indicator.
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700133 * {@more}
134 * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
Jeff Davidson01efe5e2018-02-28 17:50:16 -0800135 * READ_PHONE_STATE} or that the calling app has carrier privileges (see
136 * {@link TelephonyManager#hasCarrierPrivileges}).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 * <p>
138 * Example: The status bar uses this to determine when to display the
139 * voicemail icon.
140 *
141 * @see #onMessageWaitingIndicatorChanged
142 */
143 public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 0x00000004;
144
145 /**
146 * Listen for changes to the call-forwarding indicator.
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700147 * {@more}
148 * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
Jeff Davidson01efe5e2018-02-28 17:50:16 -0800149 * READ_PHONE_STATE} or that the calling app has carrier privileges (see
150 * {@link TelephonyManager#hasCarrierPrivileges}).
151 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 * @see #onCallForwardingIndicatorChanged
153 */
154 public static final int LISTEN_CALL_FORWARDING_INDICATOR = 0x00000008;
155
156 /**
Wink Saville767a6622009-04-02 01:37:02 -0700157 * Listen for changes to the device's cell location. Note that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 * this will result in frequent callbacks to the listener.
159 * {@more}
Hall Liuba2884a2020-06-08 17:40:12 -0700160 * Requires Permission: {@link android.Manifest.permission#ACCESS_FINE_LOCATION
161 * ACCESS_FINE_LOCATION}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 * <p>
Wink Saville767a6622009-04-02 01:37:02 -0700163 * If you need regular location updates but want more control over
164 * the update interval or location precision, you can set up a listener
165 * through the {@link android.location.LocationManager location manager}
166 * instead.
167 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 * @see #onCellLocationChanged
169 */
170 public static final int LISTEN_CELL_LOCATION = 0x00000010;
171
172 /**
173 * Listen for changes to the device call state.
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700174 * {@more}
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700175 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 * @see #onCallStateChanged
177 */
178 public static final int LISTEN_CALL_STATE = 0x00000020;
179
180 /**
181 * Listen for changes to the data connection state (cellular).
182 *
183 * @see #onDataConnectionStateChanged
184 */
185 public static final int LISTEN_DATA_CONNECTION_STATE = 0x00000040;
186
187 /**
188 * Listen for changes to the direction of data traffic on the data
189 * connection (cellular).
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700190 * {@more}
Wink Saville767a6622009-04-02 01:37:02 -0700191 * Example: The status bar uses this to display the appropriate
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 * data-traffic icon.
193 *
194 * @see #onDataActivity
195 */
196 public static final int LISTEN_DATA_ACTIVITY = 0x00000080;
197
Wink Savillee9b06d72009-05-18 21:47:50 -0700198 /**
199 * Listen for changes to the network signal strengths (cellular).
200 * <p>
201 * Example: The status bar uses this to control the signal-strength
202 * icon.
203 *
204 * @see #onSignalStrengthsChanged
Wink Savillee9b06d72009-05-18 21:47:50 -0700205 */
206 public static final int LISTEN_SIGNAL_STRENGTHS = 0x00000100;
207
Wink Savillefd2d0132010-10-28 14:22:26 -0700208 /**
sqiandfdee632020-01-30 14:14:43 -0800209 * Listen for changes of the network signal strengths (cellular) always reported from modem,
Shuo Qian93642d42020-01-16 20:57:02 -0800210 * even in some situations such as the screen of the device is off.
211 *
sqiandfdee632020-01-30 14:14:43 -0800212 * @see #onSignalStrengthsChanged
213 *
Shuo Qian93642d42020-01-16 20:57:02 -0800214 * @hide
215 */
216 @RequiresPermission(android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH)
Shuo Qian93642d42020-01-16 20:57:02 -0800217 public static final int LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH = 0x00000200;
218
219 /**
John Wang963db55d2012-03-30 16:04:06 -0700220 * Listen for changes to observed cell info.
221 *
222 * @see #onCellInfoChanged
John Wang963db55d2012-03-30 16:04:06 -0700223 */
224 public static final int LISTEN_CELL_INFO = 0x00000400;
225
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200226 /**
Chen Xuf85cf992019-10-02 00:20:43 -0700227 * Listen for {@link android.telephony.Annotation.PreciseCallStates} of ringing,
228 * background and foreground calls.
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200229 *
Rambo Wang82a46e22020-01-02 14:42:57 -0800230 * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
231 * or the calling app has carrier privileges
232 * (see {@link TelephonyManager#hasCarrierPrivileges}).
233 *
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200234 * @hide
235 */
chen xu7621ff22019-02-21 19:17:22 -0800236 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
chen xu970d7792018-12-12 19:59:30 -0800237 @SystemApi
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200238 public static final int LISTEN_PRECISE_CALL_STATE = 0x00000800;
239
240 /**
chen xu896e3d42018-12-11 18:09:41 -0800241 * Listen for {@link PreciseDataConnectionState} on the data connection (cellular).
242 *
Rambo Wang82a46e22020-01-02 14:42:57 -0800243 * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
Nathan Harold4d340f12019-12-05 17:27:56 -0800244 * or the calling app has carrier privileges
245 * (see {@link TelephonyManager#hasCarrierPrivileges}).
chen xu896e3d42018-12-11 18:09:41 -0800246 *
Nathan Harold4d340f12019-12-05 17:27:56 -0800247 * @see #onPreciseDataConnectionStateChanged
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200248 */
Rambo Wang82a46e22020-01-02 14:42:57 -0800249 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200250 public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE = 0x00001000;
251
Wink Saville070e0612014-04-15 22:04:10 -0700252 /**
253 * Listen for real time info for all data connections (cellular)).
254 * {@more}
255 * Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
256 * READ_PRECISE_PHONE_STATE}
Wink Saville070e0612014-04-15 22:04:10 -0700257 * @see #onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo)
Nathan Harold82162362016-01-21 12:20:26 -0800258 *
259 * @deprecated Use {@link TelephonyManager#getModemActivityInfo()}
Wink Saville070e0612014-04-15 22:04:10 -0700260 * @hide
261 */
Nathan Harold82162362016-01-21 12:20:26 -0800262 @Deprecated
Wink Saville070e0612014-04-15 22:04:10 -0700263 public static final int LISTEN_DATA_CONNECTION_REAL_TIME_INFO = 0x00002000;
264
Wink Savillefb40dd42014-06-12 17:02:31 -0700265 /**
Brad Ebingerefed9822018-10-26 10:25:57 -0700266 * Listen for changes to the SRVCC state of the active call.
Rambo Wangfeed16d2020-01-20 16:55:36 -0800267 *
268 * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE}
269 *
Brad Ebingerefed9822018-10-26 10:25:57 -0700270 * @see #onServiceStateChanged(ServiceState)
Wink Savillefb40dd42014-06-12 17:02:31 -0700271 * @hide
272 */
Brad Ebingerefed9822018-10-26 10:25:57 -0700273 @SystemApi
274 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
275 public static final int LISTEN_SRVCC_STATE_CHANGED = 0x00004000;
Wink Savillefb40dd42014-06-12 17:02:31 -0700276
New Author Steven Liu485f2092014-09-11 10:18:45 -0500277 /**
Shuo Qian066e8652018-04-25 21:02:35 +0000278 * Listen for OEM hook raw event
279 *
280 * @see #onOemHookRawEvent
281 * @hide
282 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead
283 */
284 @Deprecated
285 public static final int LISTEN_OEM_HOOK_RAW_EVENT = 0x00008000;
286
287 /**
Andrew Flynn1f452642015-04-14 22:16:04 -0400288 * Listen for carrier network changes indicated by a carrier app.
289 *
290 * @see #onCarrierNetworkRequest
291 * @see TelephonyManager#notifyCarrierNetworkChange(boolean)
292 * @hide
293 */
294 public static final int LISTEN_CARRIER_NETWORK_CHANGE = 0x00010000;
295
fionaxu64eebba2016-11-14 13:32:14 -0800296 /**
chen xu63b0a342018-11-10 11:31:49 -0800297 * Listen for changes to the sim voice activation state
Rambo Wangfeed16d2020-01-20 16:55:36 -0800298 *
299 * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE}
300 *
chen xu63b0a342018-11-10 11:31:49 -0800301 * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
302 * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
303 * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
304 * @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
305 * @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
306 * {@more}
307 * Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates voice service has been
308 * fully activated
fionaxu64eebba2016-11-14 13:32:14 -0800309 *
chen xu63b0a342018-11-10 11:31:49 -0800310 * @see #onVoiceActivationStateChanged
311 * @hide
fionaxu64eebba2016-11-14 13:32:14 -0800312 */
chen xu63b0a342018-11-10 11:31:49 -0800313 @SystemApi
Rambo Wangfeed16d2020-01-20 16:55:36 -0800314 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
fionaxu64eebba2016-11-14 13:32:14 -0800315 public static final int LISTEN_VOICE_ACTIVATION_STATE = 0x00020000;
316
317 /**
chen xu63b0a342018-11-10 11:31:49 -0800318 * Listen for changes to the sim data activation state
319 * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
320 * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
321 * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
322 * @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
323 * @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
324 * {@more}
325 * Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates data service has been
326 * fully activated
fionaxu64eebba2016-11-14 13:32:14 -0800327 *
chen xu63b0a342018-11-10 11:31:49 -0800328 * @see #onDataActivationStateChanged
329 * @hide
fionaxu64eebba2016-11-14 13:32:14 -0800330 */
331 public static final int LISTEN_DATA_ACTIVATION_STATE = 0x00040000;
332
zxuan35a47022018-01-04 11:24:04 -0800333 /**
334 * Listen for changes to the user mobile data state
335 *
336 * @see #onUserMobileDataStateChanged
337 */
338 public static final int LISTEN_USER_MOBILE_DATA_STATE = 0x00080000;
339
Eric Schwarzenbach5c6b3a32018-01-18 17:15:51 -0800340 /**
Jack Yu73036c42020-02-06 13:33:04 -0800341 * Listen for display info changed event.
342 *
343 * @see #onDisplayInfoChanged
344 */
345 public static final int LISTEN_DISPLAY_INFO_CHANGED = 0x00100000;
346
347 /**
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700348 * Listen for changes to the phone capability.
349 *
350 * @see #onPhoneCapabilityChanged
351 * @hide
352 */
353 public static final int LISTEN_PHONE_CAPABILITY_CHANGE = 0x00200000;
354
chen xu760729c2018-10-11 13:18:26 -0700355 /**
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800356 * Listen for changes to active data subId. Active data subscription is
357 * the current subscription used to setup Cellular Internet data. For example,
358 * it could be the current active opportunistic subscription in use, or the
359 * subscription user selected as default data subscription in DSDS mode.
Malcolm Chenc1873af2018-09-24 20:01:32 -0700360 *
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800361 * @see #onActiveDataSubscriptionIdChanged
Malcolm Chenc1873af2018-09-24 20:01:32 -0700362 */
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800363 public static final int LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE = 0x00400000;
Malcolm Chenc1873af2018-09-24 20:01:32 -0700364
365 /**
chen xu760729c2018-10-11 13:18:26 -0700366 * Listen for changes to the radio power state.
367 *
Rambo Wangfeed16d2020-01-20 16:55:36 -0800368 * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE}
369 *
chen xu760729c2018-10-11 13:18:26 -0700370 * @see #onRadioPowerStateChanged
371 * @hide
372 */
373 @SystemApi
Rambo Wangfeed16d2020-01-20 16:55:36 -0800374 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
chen xub591f9d2018-10-18 14:24:58 -0700375 public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 0x00800000;
chen xu760729c2018-10-11 13:18:26 -0700376
sqian5ac293f02018-10-17 16:31:31 -0700377 /**
378 * Listen for changes to emergency number list based on all active subscriptions.
379 *
380 * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling
381 * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
382 */
383 public static final int LISTEN_EMERGENCY_NUMBER_LIST = 0x01000000;
384
chen xu970d7792018-12-12 19:59:30 -0800385 /**
386 * Listen for call disconnect causes which contains {@link DisconnectCause} and
387 * {@link PreciseDisconnectCause}.
chen xu970d7792018-12-12 19:59:30 -0800388 *
Rambo Wang82a46e22020-01-02 14:42:57 -0800389 * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
390 * or the calling app has carrier privileges
391 * (see {@link TelephonyManager#hasCarrierPrivileges}).
392 *
chen xu970d7792018-12-12 19:59:30 -0800393 */
chen xu7621ff22019-02-21 19:17:22 -0800394 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
chen xu970d7792018-12-12 19:59:30 -0800395 public static final int LISTEN_CALL_DISCONNECT_CAUSES = 0x02000000;
396
Jordan Liufd59a812018-10-23 14:17:39 -0700397 /**
398 * Listen for changes to the call attributes of a currently active call.
Rambo Wang82a46e22020-01-02 14:42:57 -0800399 *
400 * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
401 * or the calling app has carrier privileges
402 * (see {@link TelephonyManager#hasCarrierPrivileges}).
Jordan Liufd59a812018-10-23 14:17:39 -0700403 *
404 * @see #onCallAttributesChanged
405 * @hide
406 */
407 @SystemApi
Rambo Wang82a46e22020-01-02 14:42:57 -0800408 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
Jordan Liufd59a812018-10-23 14:17:39 -0700409 public static final int LISTEN_CALL_ATTRIBUTES_CHANGED = 0x04000000;
410
chen xu0f494682019-01-24 14:14:13 -0800411 /**
412 * Listen for IMS call disconnect causes which contains
413 * {@link android.telephony.ims.ImsReasonInfo}
414 *
Rambo Wang82a46e22020-01-02 14:42:57 -0800415 * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
416 * or the calling app has carrier privileges
417 * (see {@link TelephonyManager#hasCarrierPrivileges}).
418 *
chen xu0f494682019-01-24 14:14:13 -0800419 * @see #onImsCallDisconnectCauseChanged(ImsReasonInfo)
chen xu0f494682019-01-24 14:14:13 -0800420 */
chen xu7621ff22019-02-21 19:17:22 -0800421 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
chen xu0f494682019-01-24 14:14:13 -0800422 public static final int LISTEN_IMS_CALL_DISCONNECT_CAUSES = 0x08000000;
423
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700424 /**
425 * Listen for the emergency number placed from an outgoing call.
426 *
427 * <p>Requires permission {@link android.Manifest.permission#READ_ACTIVE_EMERGENCY_SESSION}
428 *
429 * @see #onOutgoingEmergencyCall
430 * @hide
431 */
432 @SystemApi
Shuo Qian134334b2019-09-12 17:00:31 -0700433 @TestApi
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700434 @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION)
Shuo Qiand9663762019-10-04 13:20:45 -0700435 public static final int LISTEN_OUTGOING_EMERGENCY_CALL = 0x10000000;
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700436
437 /**
438 * Listen for the emergency number placed from an outgoing SMS.
439 *
440 * <p>Requires permission {@link android.Manifest.permission#READ_ACTIVE_EMERGENCY_SESSION}
441 *
442 * @see #onOutgoingEmergencySms
443 * @hide
444 */
445 @SystemApi
Shuo Qian134334b2019-09-12 17:00:31 -0700446 @TestApi
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700447 @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION)
Shuo Qiand9663762019-10-04 13:20:45 -0700448 public static final int LISTEN_OUTGOING_EMERGENCY_SMS = 0x20000000;
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700449
Nathan Harold5e6e9832019-12-17 13:06:54 -0800450 /**
451 * Listen for Registration Failures.
452 *
453 * Listen for indications that a registration procedure has failed in either the CS or PS
454 * domain. This indication does not necessarily indicate a change of service state, which should
455 * be tracked via {@link #LISTEN_SERVICE_STATE}.
456 *
Nathan Harold0d9a92b2020-02-06 20:59:18 -0800457 * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} or
458 * the calling app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
Nathan Harold5e6e9832019-12-17 13:06:54 -0800459 *
Andrew Sapperstein8fe35e52020-04-28 12:29:20 -0700460 * @see #onRegistrationFailed
Nathan Harold5e6e9832019-12-17 13:06:54 -0800461 */
Nathan Harold0d9a92b2020-02-06 20:59:18 -0800462 @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
Nathan Harold5e6e9832019-12-17 13:06:54 -0800463 public static final int LISTEN_REGISTRATION_FAILURE = 0x40000000;
464
Nathan Haroldc564b1d2019-12-26 17:10:15 -0800465 /**
466 * Listen for Barring Information for the current registered / camped cell.
467 *
Nathan Harold0d9a92b2020-02-06 20:59:18 -0800468 * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} or
469 * the calling app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
Nathan Haroldc564b1d2019-12-26 17:10:15 -0800470 *
Andrew Sapperstein8fe35e52020-04-28 12:29:20 -0700471 * @see #onBarringInfoChanged
Nathan Haroldc564b1d2019-12-26 17:10:15 -0800472 */
Nathan Harold0d9a92b2020-02-06 20:59:18 -0800473 @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
Nathan Haroldc564b1d2019-12-26 17:10:15 -0800474 public static final int LISTEN_BARRING_INFO = 0x80000000;
475
Eric Schwarzenbach5c6b3a32018-01-18 17:15:51 -0800476 /*
Wink Savillefb40dd42014-06-12 17:02:31 -0700477 * Subscription used to listen to the phone state changes
478 * @hide
479 */
480 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +0100481 @UnsupportedAppUsage
Ta-wei Yen05f91122016-11-10 12:11:56 -0800482 protected Integer mSubId;
Wink Savillefb40dd42014-06-12 17:02:31 -0700483
Nathan Harold7581efd2018-10-25 10:32:10 -0700484 /**
485 * @hide
486 */
487 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
488 @UnsupportedAppUsage
489 public final IPhoneStateListener callback;
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700490
Wink Saville2e40ba92014-09-03 15:28:12 -0700491 /**
492 * Create a PhoneStateListener for the Phone with the default subscription.
Karol Wrótniak69d3e552014-11-27 21:29:15 +0100493 * This class requires Looper.myLooper() not return null.
Wink Saville2e40ba92014-09-03 15:28:12 -0700494 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 public PhoneStateListener() {
Ta-wei Yen05f91122016-11-10 12:11:56 -0800496 this(null, Looper.myLooper());
Wink Savillefb40dd42014-06-12 17:02:31 -0700497 }
498
499 /**
Wink Saville2e40ba92014-09-03 15:28:12 -0700500 * Create a PhoneStateListener for the Phone with the default subscription
501 * using a particular non-null Looper.
502 * @hide
503 */
chen xuf4c5c6e2018-11-18 18:56:00 -0800504 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Wink Saville2e40ba92014-09-03 15:28:12 -0700505 public PhoneStateListener(Looper looper) {
Ta-wei Yen05f91122016-11-10 12:11:56 -0800506 this(null, looper);
Wink Saville2e40ba92014-09-03 15:28:12 -0700507 }
508
509 /**
510 * Create a PhoneStateListener for the Phone using the specified subscription.
511 * This class requires Looper.myLooper() not return null. To supply your
Wink Saville63f03dd2014-10-23 10:44:45 -0700512 * own non-null Looper use PhoneStateListener(int subId, Looper looper) below.
Wink Savillefb40dd42014-06-12 17:02:31 -0700513 * @hide
514 */
chen xuf4c5c6e2018-11-18 18:56:00 -0800515 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Ta-wei Yen05f91122016-11-10 12:11:56 -0800516 public PhoneStateListener(Integer subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700517 this(subId, Looper.myLooper());
chen xu84a90872019-03-28 15:44:12 -0700518 if (subId != null && VMRuntime.getRuntime().getTargetSdkVersion()
519 >= Build.VERSION_CODES.Q) {
520 throw new IllegalArgumentException("PhoneStateListener with subId: "
521 + subId + " is not supported, use default constructor");
522 }
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700523 }
Wink Saville2e40ba92014-09-03 15:28:12 -0700524 /**
525 * Create a PhoneStateListener for the Phone using the specified subscription
526 * and non-null Looper.
527 * @hide
528 */
chen xuf4c5c6e2018-11-18 18:56:00 -0800529 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Ta-wei Yen05f91122016-11-10 12:11:56 -0800530 public PhoneStateListener(Integer subId, Looper looper) {
Nathan Harold7581efd2018-10-25 10:32:10 -0700531 this(subId, new HandlerExecutor(new Handler(looper)));
chen xu84a90872019-03-28 15:44:12 -0700532 if (subId != null && VMRuntime.getRuntime().getTargetSdkVersion()
533 >= Build.VERSION_CODES.Q) {
534 throw new IllegalArgumentException("PhoneStateListener with subId: "
535 + subId + " is not supported, use default constructor");
536 }
Nathan Harold7581efd2018-10-25 10:32:10 -0700537 }
538
539 /**
540 * Create a PhoneStateListener for the Phone using the specified Executor
541 *
542 * <p>Create a PhoneStateListener with a specified Executor for handling necessary callbacks.
543 * The Executor must not be null.
544 *
545 * @param executor a non-null Executor that will execute callbacks for the PhoneStateListener.
546 */
547 public PhoneStateListener(@NonNull Executor executor) {
548 this(null, executor);
549 }
550
551 private PhoneStateListener(Integer subId, Executor e) {
552 if (e == null) {
553 throw new IllegalArgumentException("PhoneStateListener Executor must be non-null");
554 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700555 mSubId = subId;
Nathan Harold7581efd2018-10-25 10:32:10 -0700556 callback = new IPhoneStateListenerStub(this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 }
558
559 /**
chen xud5deeb12019-04-29 13:57:42 -0700560 * Callback invoked when device service state changes on the registered subscription.
561 * Note, the registration subId comes from {@link TelephonyManager} object which registers
562 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
563 * If this TelephonyManager object was created with
564 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
565 * subId. Otherwise, this callback applies to
566 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 *
568 * @see ServiceState#STATE_EMERGENCY_ONLY
569 * @see ServiceState#STATE_IN_SERVICE
570 * @see ServiceState#STATE_OUT_OF_SERVICE
571 * @see ServiceState#STATE_POWER_OFF
572 */
573 public void onServiceStateChanged(ServiceState serviceState) {
574 // default implementation empty
575 }
576
577 /**
chen xud5deeb12019-04-29 13:57:42 -0700578 * Callback invoked when network signal strength changes on the registered subscription.
579 * Note, the registration subId comes from {@link TelephonyManager} object which registers
580 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
581 * If this TelephonyManager object was created with
582 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
583 * subId. Otherwise, this callback applies to
584 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 *
586 * @see ServiceState#STATE_EMERGENCY_ONLY
587 * @see ServiceState#STATE_IN_SERVICE
588 * @see ServiceState#STATE_OUT_OF_SERVICE
589 * @see ServiceState#STATE_POWER_OFF
Scott Mainb149ee82009-12-15 10:47:31 -0800590 * @deprecated Use {@link #onSignalStrengthsChanged(SignalStrength)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700592 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 public void onSignalStrengthChanged(int asu) {
594 // default implementation empty
595 }
596
597 /**
chen xud5deeb12019-04-29 13:57:42 -0700598 * Callback invoked when the message-waiting indicator changes on the registered subscription.
599 * Note, the registration subId comes from {@link TelephonyManager} object which registers
600 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
601 * If this TelephonyManager object was created with
602 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
603 * subId. Otherwise, this callback applies to
604 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 */
606 public void onMessageWaitingIndicatorChanged(boolean mwi) {
607 // default implementation empty
608 }
609
610 /**
chen xud5deeb12019-04-29 13:57:42 -0700611 * Callback invoked when the call-forwarding indicator changes on the registered subscription.
612 * Note, the registration subId comes from {@link TelephonyManager} object which registers
613 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
614 * If this TelephonyManager object was created with
615 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
616 * subId. Otherwise, this callback applies to
617 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 */
619 public void onCallForwardingIndicatorChanged(boolean cfi) {
620 // default implementation empty
621 }
622
623 /**
chen xud5deeb12019-04-29 13:57:42 -0700624 * Callback invoked when device cell location changes on the registered subscription.
625 * Note, the registration subId comes from {@link TelephonyManager} object which registers
626 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
627 * If this TelephonyManager object was created with
628 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
629 * subId. Otherwise, this callback applies to
630 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 */
632 public void onCellLocationChanged(CellLocation location) {
633 // default implementation empty
634 }
635
636 /**
Wink Saville767a6622009-04-02 01:37:02 -0700637 * Callback invoked when device call state changes.
Tyler Gunn5f7265e2018-03-13 15:56:37 -0700638 * <p>
chen xud5deeb12019-04-29 13:57:42 -0700639 * Reports the state of Telephony (mobile) calls on the device for the registered subscription.
640 * <p>
641 * Note: the registration subId comes from {@link TelephonyManager} object which registers
642 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
643 * If this TelephonyManager object was created with
644 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
645 * subId. Otherwise, this callback applies to
646 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
Tyler Gunn5f7265e2018-03-13 15:56:37 -0700647 * <p>
648 * Note: The state returned here may differ from that returned by
649 * {@link TelephonyManager#getCallState()}. Receivers of this callback should be aware that
650 * calling {@link TelephonyManager#getCallState()} from within this callback may return a
651 * different state than the callback reports.
652 *
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700653 * @param state call state
Jeff Davidson3463ee12017-11-10 15:58:20 -0800654 * @param phoneNumber call phone number. If application does not have
Tyler Gunnf955e562018-04-26 14:43:31 -0700655 * {@link android.Manifest.permission#READ_CALL_LOG READ_CALL_LOG} permission or carrier
Jeff Davidson01efe5e2018-02-28 17:50:16 -0800656 * privileges (see {@link TelephonyManager#hasCarrierPrivileges}), an empty string will be
657 * passed as an argument.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 */
Chen Xuc9d4ee12019-09-26 16:11:59 -0700659 public void onCallStateChanged(@CallState int state, String phoneNumber) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 // default implementation empty
661 }
662
663 /**
chen xud5deeb12019-04-29 13:57:42 -0700664 * Callback invoked when connection state changes on the registered subscription.
665 * Note, the registration subId comes from {@link TelephonyManager} object which registers
666 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
667 * If this TelephonyManager object was created with
668 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
669 * subId. Otherwise, this callback applies to
670 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 *
672 * @see TelephonyManager#DATA_DISCONNECTED
673 * @see TelephonyManager#DATA_CONNECTING
674 * @see TelephonyManager#DATA_CONNECTED
675 * @see TelephonyManager#DATA_SUSPENDED
676 */
677 public void onDataConnectionStateChanged(int state) {
678 // default implementation empty
679 }
680
681 /**
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700682 * same as above, but with the network type. Both called.
683 */
684 public void onDataConnectionStateChanged(int state, int networkType) {
685 }
686
687 /**
chen xud5deeb12019-04-29 13:57:42 -0700688 * Callback invoked when data activity state changes on the registered subscription.
689 * Note, the registration subId comes from {@link TelephonyManager} object which registers
690 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
691 * If this TelephonyManager object was created with
692 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
693 * subId. Otherwise, this callback applies to
694 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 *
696 * @see TelephonyManager#DATA_ACTIVITY_NONE
697 * @see TelephonyManager#DATA_ACTIVITY_IN
698 * @see TelephonyManager#DATA_ACTIVITY_OUT
699 * @see TelephonyManager#DATA_ACTIVITY_INOUT
Wink Savillee9b06d72009-05-18 21:47:50 -0700700 * @see TelephonyManager#DATA_ACTIVITY_DORMANT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 */
702 public void onDataActivity(int direction) {
703 // default implementation empty
704 }
705
706 /**
chen xud5deeb12019-04-29 13:57:42 -0700707 * Callback invoked when network signal strengths changes on the registered subscription.
708 * Note, the registration subId comes from {@link TelephonyManager} object which registers
709 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
710 * If this TelephonyManager object was created with
711 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
712 * subId. Otherwise, this callback applies to
713 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
Wink Savillee9b06d72009-05-18 21:47:50 -0700714 */
715 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
716 // default implementation empty
717 }
718
719 /**
chen xud5deeb12019-04-29 13:57:42 -0700720 * Callback invoked when a observed cell info has changed or new cells have been added
721 * or removed on the registered subscription.
722 * Note, the registration subId s from {@link TelephonyManager} object which registers
723 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
724 * If this TelephonyManager object was created with
725 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
726 * subId. Otherwise, this callback applies to
727 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
728 *
Wink Savilleb208a242012-07-25 14:08:09 -0700729 * @param cellInfo is the list of currently visible cells.
John Wang963db55d2012-03-30 16:04:06 -0700730 */
Wink Savilleb208a242012-07-25 14:08:09 -0700731 public void onCellInfoChanged(List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700732 }
733
734 /**
chen xud5deeb12019-04-29 13:57:42 -0700735 * Callback invoked when precise device call state changes on the registered subscription.
736 * Note, the registration subId comes from {@link TelephonyManager} object which registers
737 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
738 * If this TelephonyManager object was created with
739 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
740 * subId. Otherwise, this callback applies to
741 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
chen xu970d7792018-12-12 19:59:30 -0800742 * @param callState {@link PreciseCallState}
743 * @hide
744 */
chen xu7621ff22019-02-21 19:17:22 -0800745 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
chen xu970d7792018-12-12 19:59:30 -0800746 @SystemApi
chen xu7621ff22019-02-21 19:17:22 -0800747 public void onPreciseCallStateChanged(@NonNull PreciseCallState callState) {
chen xu970d7792018-12-12 19:59:30 -0800748 // default implementation empty
749 }
750
751 /**
chen xud5deeb12019-04-29 13:57:42 -0700752 * Callback invoked when call disconnect cause changes on the registered subscription.
753 * Note, the registration subId comes from {@link TelephonyManager} object which registers
754 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
755 * If this TelephonyManager object was created with
756 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
757 * subId. Otherwise, this callback applies to
758 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
759 *
chen xu970d7792018-12-12 19:59:30 -0800760 * @param disconnectCause {@link DisconnectCause}.
761 * @param preciseDisconnectCause {@link PreciseDisconnectCause}.
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200762 *
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200763 */
chen xu7621ff22019-02-21 19:17:22 -0800764 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
chen xu970d7792018-12-12 19:59:30 -0800765 public void onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200766 // default implementation empty
767 }
768
769 /**
chen xud5deeb12019-04-29 13:57:42 -0700770 * Callback invoked when Ims call disconnect cause changes on the registered subscription.
771 * Note, the registration subId comes from {@link TelephonyManager} object which registers
772 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
773 * If this TelephonyManager object was created with
774 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
775 * subId. Otherwise, this callback applies to
776 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
777 *
chen xu0f494682019-01-24 14:14:13 -0800778 * @param imsReasonInfo {@link ImsReasonInfo} contains details on why IMS call failed.
779 *
chen xu0f494682019-01-24 14:14:13 -0800780 */
chen xu7621ff22019-02-21 19:17:22 -0800781 @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
chen xu0f494682019-01-24 14:14:13 -0800782 public void onImsCallDisconnectCauseChanged(@NonNull ImsReasonInfo imsReasonInfo) {
783 // default implementation empty
784 }
785
786 /**
Nathan Harold4d340f12019-12-05 17:27:56 -0800787 * Callback providing update about the default/internet data connection on the registered
788 * subscription.
789 *
chen xud5deeb12019-04-29 13:57:42 -0700790 * Note, the registration subId comes from {@link TelephonyManager} object which registers
791 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
792 * If this TelephonyManager object was created with
793 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
794 * subId. Otherwise, this callback applies to
795 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
796 *
Nathan Harold4d340f12019-12-05 17:27:56 -0800797 * <p>Requires permission {@link android.Manifest.permission#MODIFY_PHONE_STATE}
798 * or the calling app has carrier privileges
799 * (see {@link TelephonyManager#hasCarrierPrivileges}).
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200800 *
Nathan Harold4d340f12019-12-05 17:27:56 -0800801 * @param dataConnectionState {@link PreciseDataConnectionState}
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200802 */
Nathan Harold4d340f12019-12-05 17:27:56 -0800803 @RequiresPermission((android.Manifest.permission.MODIFY_PHONE_STATE))
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200804 public void onPreciseDataConnectionStateChanged(
chen xu81653862019-02-28 10:44:54 -0800805 @NonNull PreciseDataConnectionState dataConnectionState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200806 // default implementation empty
807 }
808
809 /**
chen xud5deeb12019-04-29 13:57:42 -0700810 * Callback invoked when data connection real time info changes on the registered subscription.
811 * Note, the registration subId comes from {@link TelephonyManager} object which registers
812 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
813 * If this TelephonyManager object was created with
814 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
815 * subId. Otherwise, this callback applies to
816 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
Wink Saville070e0612014-04-15 22:04:10 -0700817 *
818 * @hide
819 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100820 @UnsupportedAppUsage
Wink Saville070e0612014-04-15 22:04:10 -0700821 public void onDataConnectionRealTimeInfoChanged(
822 DataConnectionRealTimeInfo dcRtInfo) {
823 // default implementation empty
824 }
825
826 /**
Brad Ebingerefed9822018-10-26 10:25:57 -0700827 * Callback invoked when there has been a change in the Single Radio Voice Call Continuity
chen xud5deeb12019-04-29 13:57:42 -0700828 * (SRVCC) state for the currently active call on the registered subscription.
829 *
830 * Note, the registration subId comes from {@link TelephonyManager} object which registers
831 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
832 * If this TelephonyManager object was created with
833 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
834 * subId. Otherwise, this callback applies to
835 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
836 *
Wink Savillefb40dd42014-06-12 17:02:31 -0700837 * @hide
838 */
Brad Ebingerefed9822018-10-26 10:25:57 -0700839 @SystemApi
Chen Xuc9d4ee12019-09-26 16:11:59 -0700840 public void onSrvccStateChanged(@SrvccState int srvccState) {
Brad Ebingerefed9822018-10-26 10:25:57 -0700841
Wink Savillefb40dd42014-06-12 17:02:31 -0700842 }
843
844 /**
chen xud5deeb12019-04-29 13:57:42 -0700845 * Callback invoked when the SIM voice activation state has changed on the registered
846 * subscription.
847 * Note, the registration subId comes from {@link TelephonyManager} object which registers
848 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
849 * If this TelephonyManager object was created with
850 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
851 * subId. Otherwise, this callback applies to
852 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
853 *
fionaxu64eebba2016-11-14 13:32:14 -0800854 * @param state is the current SIM voice activation state
855 * @hide
856 */
chen xu63b0a342018-11-10 11:31:49 -0800857 @SystemApi
Chen Xuc9d4ee12019-09-26 16:11:59 -0700858 public void onVoiceActivationStateChanged(@SimActivationState int state) {
fionaxu64eebba2016-11-14 13:32:14 -0800859 }
860
861 /**
chen xud5deeb12019-04-29 13:57:42 -0700862 * Callback invoked when the SIM data activation state has changed on the registered
863 * subscription.
864 * Note, the registration subId comes from {@link TelephonyManager} object which registers
865 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
866 * If this TelephonyManager object was created with
867 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
868 * subId. Otherwise, this callback applies to
869 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
870 *
fionaxu64eebba2016-11-14 13:32:14 -0800871 * @param state is the current SIM data activation state
872 * @hide
873 */
Chen Xuc9d4ee12019-09-26 16:11:59 -0700874 public void onDataActivationStateChanged(@SimActivationState int state) {
fionaxu64eebba2016-11-14 13:32:14 -0800875 }
876
877 /**
chen xud5deeb12019-04-29 13:57:42 -0700878 * Callback invoked when the user mobile data state has changed on the registered subscription.
879 * Note, the registration subId comes from {@link TelephonyManager} object which registers
880 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
881 * If this TelephonyManager object was created with
882 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
883 * subId. Otherwise, this callback applies to
884 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
885 *
zxuan35a47022018-01-04 11:24:04 -0800886 * @param enabled indicates whether the current user mobile data state is enabled or disabled.
887 */
888 public void onUserMobileDataStateChanged(boolean enabled) {
889 // default implementation empty
890 }
891
892 /**
Jack Yu73036c42020-02-06 13:33:04 -0800893 * Callback invoked when the display info has changed on the registered subscription.
Jack Yuac3ca332020-03-18 14:53:32 -0700894 * <p> The {@link TelephonyDisplayInfo} contains status information shown to the user based on
Jack Yu73036c42020-02-06 13:33:04 -0800895 * carrier policy.
896 *
897 * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling
898 * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
899 *
Jack Yuac3ca332020-03-18 14:53:32 -0700900 * @param telephonyDisplayInfo The display information.
Jack Yu73036c42020-02-06 13:33:04 -0800901 */
902 @RequiresPermission((android.Manifest.permission.READ_PHONE_STATE))
Jack Yuac3ca332020-03-18 14:53:32 -0700903 public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo) {
Jack Yu73036c42020-02-06 13:33:04 -0800904 // default implementation empty
905 }
906
907 /**
chen xud5deeb12019-04-29 13:57:42 -0700908 * Callback invoked when the current emergency number list has changed on the registered
909 * subscription.
910 * Note, the registration subId comes from {@link TelephonyManager} object which registers
911 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
912 * If this TelephonyManager object was created with
913 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
914 * subId. Otherwise, this callback applies to
915 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
sqian46c0c302018-12-27 14:12:11 -0800916 *
917 * @param emergencyNumberList Map including the key as the active subscription ID
918 * (Note: if there is no active subscription, the key is
919 * {@link SubscriptionManager#getDefaultSubscriptionId})
920 * and the value as the list of {@link EmergencyNumber};
921 * null if this information is not available.
922 * @hide
923 */
924 public void onEmergencyNumberListChanged(
925 @NonNull Map<Integer, List<EmergencyNumber>> emergencyNumberList) {
926 // default implementation empty
927 }
928
929 /**
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700930 * Callback invoked when an outgoing call is placed to an emergency number.
931 *
932 * @param placedEmergencyNumber the emergency number {@link EmergencyNumber} the call is placed
933 * to.
934 * @hide
935 */
Shuo Qian134334b2019-09-12 17:00:31 -0700936 @SystemApi
Shuo Qian650ff642019-10-02 15:22:21 -0700937 @TestApi
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700938 public void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber) {
939 // default implementation empty
940 }
941
942 /**
943 * Callback invoked when an outgoing SMS is placed to an emergency number.
944 *
945 * @param sentEmergencyNumber the emergency number {@link EmergencyNumber} the SMS is sent to.
946 * @hide
947 */
Shuo Qian134334b2019-09-12 17:00:31 -0700948 @SystemApi
Shuo Qian650ff642019-10-02 15:22:21 -0700949 @TestApi
Shuo Qian7a1eb6d2019-09-04 16:21:10 -0700950 public void onOutgoingEmergencySms(@NonNull EmergencyNumber sentEmergencyNumber) {
951 // default implementation empty
952 }
953
954 /**
chen xud5deeb12019-04-29 13:57:42 -0700955 * Callback invoked when OEM hook raw event is received on the registered subscription.
956 * Note, the registration subId comes from {@link TelephonyManager} object which registers
957 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
958 * If this TelephonyManager object was created with
959 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
960 * subId. Otherwise, this callback applies to
961 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
962 *
963 * Requires the READ_PRIVILEGED_PHONE_STATE permission.
Shuo Qian066e8652018-04-25 21:02:35 +0000964 * @param rawData is the byte array of the OEM hook raw data.
965 * @hide
966 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100967 @UnsupportedAppUsage
Shuo Qian066e8652018-04-25 21:02:35 +0000968 public void onOemHookRawEvent(byte[] rawData) {
969 // default implementation empty
970 }
971
972 /**
chen xud5deeb12019-04-29 13:57:42 -0700973 * Callback invoked when phone capability changes.
974 * Note, this callback triggers regardless of registered subscription.
975 *
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700976 * @param capability the new phone capability
977 * @hide
978 */
979 public void onPhoneCapabilityChanged(PhoneCapability capability) {
980 // default implementation empty
981 }
982
983 /**
chen xud5deeb12019-04-29 13:57:42 -0700984 * Callback invoked when active data subId changes.
985 * Note, this callback triggers regardless of registered subscription.
986 *
987 * Requires the READ_PHONE_STATE permission.
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800988 * @param subId current subscription used to setup Cellular Internet data.
989 * For example, it could be the current active opportunistic subscription in use,
990 * or the subscription user selected as default data subscription in DSDS mode.
Malcolm Chenc1873af2018-09-24 20:01:32 -0700991 */
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800992 public void onActiveDataSubscriptionIdChanged(int subId) {
Malcolm Chenc1873af2018-09-24 20:01:32 -0700993 // default implementation empty
994 }
chen xu760729c2018-10-11 13:18:26 -0700995
996 /**
chen xud5deeb12019-04-29 13:57:42 -0700997 * Callback invoked when the call attributes changes on the registered subscription.
998 * Note, the registration subId comes from {@link TelephonyManager} object which registers
999 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
1000 * If this TelephonyManager object was created with
1001 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1002 * subId. Otherwise, this callback applies to
1003 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1004 *
Rambo Wangfeed16d2020-01-20 16:55:36 -08001005 * Requires the READ_PRECISE_PHONE_STATE permission.
Jordan Liufd59a812018-10-23 14:17:39 -07001006 * @param callAttributes the call attributes
1007 * @hide
1008 */
1009 @SystemApi
Jordan Liueae57b22019-01-22 16:17:35 -08001010 public void onCallAttributesChanged(@NonNull CallAttributes callAttributes) {
Jordan Liufd59a812018-10-23 14:17:39 -07001011 // default implementation empty
1012 }
1013
1014 /**
chen xud5deeb12019-04-29 13:57:42 -07001015 * Callback invoked when modem radio power state changes on the registered subscription.
1016 * Note, the registration subId comes from {@link TelephonyManager} object which registers
1017 * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
1018 * If this TelephonyManager object was created with
1019 * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1020 * subId. Otherwise, this callback applies to
1021 * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1022 *
Shi Lu12645d12019-11-21 17:51:07 +00001023 * @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE}
Malcolm Chen27de0e52018-11-12 19:34:38 -08001024 * @param state the modem radio power state
1025 * @hide
1026 */
1027 @SystemApi
Chen Xuc9d4ee12019-09-26 16:11:59 -07001028 public void onRadioPowerStateChanged(@RadioPowerState int state) {
Malcolm Chen27de0e52018-11-12 19:34:38 -08001029 // default implementation empty
1030 }
1031
1032 /**
Andrew Flynn1f452642015-04-14 22:16:04 -04001033 * Callback invoked when telephony has received notice from a carrier
1034 * app that a network action that could result in connectivity loss
1035 * has been requested by an app using
1036 * {@link android.telephony.TelephonyManager#notifyCarrierNetworkChange(boolean)}
1037 *
chen xud5deeb12019-04-29 13:57:42 -07001038 * Note, this callback is pinned to the registered subscription and will be invoked when
1039 * the notifying carrier app has carrier privilege rule on the registered
1040 * subscription. {@link android.telephony.TelephonyManager#hasCarrierPrivileges}
1041 *
Andrew Flynn1f452642015-04-14 22:16:04 -04001042 * @param active Whether the carrier network change is or shortly
1043 * will be active. This value is true to indicate
1044 * showing alternative UI and false to stop.
1045 *
1046 * @hide
1047 */
1048 public void onCarrierNetworkChange(boolean active) {
1049 // default implementation empty
1050 }
1051
1052 /**
Nathan Harold5e6e9832019-12-17 13:06:54 -08001053 * Report that Registration or a Location/Routing/Tracking Area update has failed.
1054 *
1055 * <p>Indicate whenever a registration procedure, including a location, routing, or tracking
1056 * area update fails. This includes procedures that do not necessarily result in a change of
1057 * the modem's registration status. If the modem's registration status changes, that is
1058 * reflected in the onNetworkStateChanged() and subsequent get{Voice/Data}RegistrationState().
1059 *
1060 * <p>Because registration failures are ephemeral, this callback is not sticky.
1061 * Registrants will not receive the most recent past value when registering.
1062 *
1063 * @param cellIdentity the CellIdentity, which must include the globally unique identifier
1064 * for the cell (for example, all components of the CGI or ECGI).
1065 * @param chosenPlmn a 5 or 6 digit alphanumeric PLMN (MCC|MNC) among those broadcast by the
1066 * cell that was chosen for the failed registration attempt.
1067 * @param domain DOMAIN_CS, DOMAIN_PS or both in case of a combined procedure.
1068 * @param causeCode the primary failure cause code of the procedure.
1069 * For GSM/UMTS (MM), values are in TS 24.008 Sec 10.5.95
1070 * For GSM/UMTS (GMM), values are in TS 24.008 Sec 10.5.147
1071 * For LTE (EMM), cause codes are TS 24.301 Sec 9.9.3.9
1072 * For NR (5GMM), cause codes are TS 24.501 Sec 9.11.3.2
1073 * Integer.MAX_VALUE if this value is unused.
1074 * @param additionalCauseCode the cause code of any secondary/combined procedure if appropriate.
1075 * For UMTS, if a combined attach succeeds for PS only, then the GMM cause code shall be
1076 * included as an additionalCauseCode. For LTE (ESM), cause codes are in
1077 * TS 24.301 9.9.4.4. Integer.MAX_VALUE if this value is unused.
1078 */
1079 public void onRegistrationFailed(@NonNull CellIdentity cellIdentity, @NonNull String chosenPlmn,
Chen Xu546ce5e2020-01-10 08:38:31 -08001080 int domain, int causeCode, int additionalCauseCode) {
Nathan Harold5e6e9832019-12-17 13:06:54 -08001081 // default implementation empty
1082 }
1083
1084 /**
Nathan Haroldc564b1d2019-12-26 17:10:15 -08001085 * Report updated barring information for the current camped/registered cell.
1086 *
1087 * <p>Barring info is provided for all services applicable to the current camped/registered
1088 * cell, for the registered PLMN and current access class/access category.
1089 *
1090 * @param barringInfo for all services on the current cell.
1091 *
1092 * @see android.telephony.BarringInfo
1093 */
1094 public void onBarringInfoChanged(@NonNull BarringInfo barringInfo) {
1095 // default implementation empty
1096 }
1097
1098 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 * The callback methods need to be called on the handler thread where
1100 * this object was created. If the binder did that for us it'd be nice.
fionaxuf5d7c582016-03-22 15:09:55 -07001101 *
1102 * Using a static class and weak reference here to avoid memory leak caused by the
1103 * IPhoneStateListener.Stub callback retaining references to the outside PhoneStateListeners:
1104 * even caller has been destroyed and "un-registered" the PhoneStateListener, it is still not
1105 * eligible for GC given the references coming from:
1106 * Native Stack --> PhoneStateListener --> Context (Activity).
1107 * memory of caller's context will be collected after GC from service side get triggered
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 */
fionaxuf5d7c582016-03-22 15:09:55 -07001109 private static class IPhoneStateListenerStub extends IPhoneStateListener.Stub {
1110 private WeakReference<PhoneStateListener> mPhoneStateListenerWeakRef;
Nathan Harold7581efd2018-10-25 10:32:10 -07001111 private Executor mExecutor;
fionaxuf5d7c582016-03-22 15:09:55 -07001112
Nathan Harold7581efd2018-10-25 10:32:10 -07001113 IPhoneStateListenerStub(PhoneStateListener phoneStateListener, Executor executor) {
fionaxuf5d7c582016-03-22 15:09:55 -07001114 mPhoneStateListenerWeakRef = new WeakReference<PhoneStateListener>(phoneStateListener);
Nathan Harold7581efd2018-10-25 10:32:10 -07001115 mExecutor = executor;
fionaxuf5d7c582016-03-22 15:09:55 -07001116 }
1117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 public void onServiceStateChanged(ServiceState serviceState) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001119 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1120 if (psl == null) return;
1121
1122 Binder.withCleanCallingIdentity(
1123 () -> mExecutor.execute(() -> psl.onServiceStateChanged(serviceState)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 }
1125
1126 public void onSignalStrengthChanged(int asu) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001127 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1128 if (psl == null) return;
1129
1130 Binder.withCleanCallingIdentity(
1131 () -> mExecutor.execute(() -> psl.onSignalStrengthChanged(asu)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133
1134 public void onMessageWaitingIndicatorChanged(boolean mwi) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001135 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1136 if (psl == null) return;
1137
1138 Binder.withCleanCallingIdentity(
1139 () -> mExecutor.execute(() -> psl.onMessageWaitingIndicatorChanged(mwi)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 }
1141
1142 public void onCallForwardingIndicatorChanged(boolean cfi) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001143 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1144 if (psl == null) return;
1145
1146 Binder.withCleanCallingIdentity(
1147 () -> mExecutor.execute(() -> psl.onCallForwardingIndicatorChanged(cfi)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 }
1149
Meng Wangd75f97d2019-12-06 18:27:38 -08001150 public void onCellLocationChanged(CellIdentity cellIdentity) {
1151 // There is no system/public API to create an CellIdentity in system server,
1152 // so the server pass a null to indicate an empty initial location.
1153 CellLocation location =
1154 cellIdentity == null ? CellLocation.getEmpty() : cellIdentity.asCellLocation();
Nathan Harold7581efd2018-10-25 10:32:10 -07001155 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1156 if (psl == null) return;
1157
1158 Binder.withCleanCallingIdentity(
1159 () -> mExecutor.execute(() -> psl.onCellLocationChanged(location)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 }
1161
1162 public void onCallStateChanged(int state, String incomingNumber) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001163 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1164 if (psl == null) return;
1165
1166 Binder.withCleanCallingIdentity(
1167 () -> mExecutor.execute(() -> psl.onCallStateChanged(state, incomingNumber)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 }
1169
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001170 public void onDataConnectionStateChanged(int state, int networkType) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001171 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1172 if (psl == null) return;
1173
Nathan Harold4d340f12019-12-05 17:27:56 -08001174 if (state == TelephonyManager.DATA_DISCONNECTING
1175 && VMRuntime.getRuntime().getTargetSdkVersion() < Build.VERSION_CODES.R) {
1176 Binder.withCleanCallingIdentity(() -> mExecutor.execute(
1177 () -> {
1178 psl.onDataConnectionStateChanged(
1179 TelephonyManager.DATA_CONNECTED, networkType);
1180 psl.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED);
1181 }));
1182 } else {
1183 Binder.withCleanCallingIdentity(() -> mExecutor.execute(
1184 () -> {
1185 psl.onDataConnectionStateChanged(state, networkType);
1186 psl.onDataConnectionStateChanged(state);
1187 }));
1188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 }
1190
1191 public void onDataActivity(int direction) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001192 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1193 if (psl == null) return;
1194
1195 Binder.withCleanCallingIdentity(
1196 () -> mExecutor.execute(() -> psl.onDataActivity(direction)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 }
Wink Savillefd2d0132010-10-28 14:22:26 -07001198
Wink Savillee9b06d72009-05-18 21:47:50 -07001199 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001200 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1201 if (psl == null) return;
1202
1203 Binder.withCleanCallingIdentity(
1204 () -> mExecutor.execute(() -> psl.onSignalStrengthsChanged(signalStrength)));
Wink Savillee9b06d72009-05-18 21:47:50 -07001205 }
Wink Savillefd2d0132010-10-28 14:22:26 -07001206
Wink Savilleb208a242012-07-25 14:08:09 -07001207 public void onCellInfoChanged(List<CellInfo> cellInfo) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001208 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1209 if (psl == null) return;
1210
1211 Binder.withCleanCallingIdentity(
1212 () -> mExecutor.execute(() -> psl.onCellInfoChanged(cellInfo)));
John Wang963db55d2012-03-30 16:04:06 -07001213 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001214
1215 public void onPreciseCallStateChanged(PreciseCallState callState) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001216 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1217 if (psl == null) return;
1218
1219 Binder.withCleanCallingIdentity(
1220 () -> mExecutor.execute(() -> psl.onPreciseCallStateChanged(callState)));
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001221 }
1222
chen xu970d7792018-12-12 19:59:30 -08001223 public void onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause) {
1224 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1225 if (psl == null) return;
1226
1227 Binder.withCleanCallingIdentity(
1228 () -> mExecutor.execute(() -> psl.onCallDisconnectCauseChanged(
1229 disconnectCause, preciseDisconnectCause)));
1230 }
1231
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001232 public void onPreciseDataConnectionStateChanged(
1233 PreciseDataConnectionState dataConnectionState) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001234 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1235 if (psl == null) return;
1236
1237 Binder.withCleanCallingIdentity(
1238 () -> mExecutor.execute(
1239 () -> psl.onPreciseDataConnectionStateChanged(dataConnectionState)));
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001240 }
Wink Saville070e0612014-04-15 22:04:10 -07001241
Nathan Harold7581efd2018-10-25 10:32:10 -07001242 public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo) {
1243 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1244 if (psl == null) return;
1245
1246 Binder.withCleanCallingIdentity(
1247 () -> mExecutor.execute(
1248 () -> psl.onDataConnectionRealTimeInfoChanged(dcRtInfo)));
Wink Saville070e0612014-04-15 22:04:10 -07001249 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001250
Brad Ebingerefed9822018-10-26 10:25:57 -07001251 public void onSrvccStateChanged(int state) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001252 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1253 if (psl == null) return;
1254
1255 Binder.withCleanCallingIdentity(
1256 () -> mExecutor.execute(() -> psl.onSrvccStateChanged(state)));
Wink Savillefb40dd42014-06-12 17:02:31 -07001257 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001258
fionaxu64eebba2016-11-14 13:32:14 -08001259 public void onVoiceActivationStateChanged(int activationState) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001260 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1261 if (psl == null) return;
1262
1263 Binder.withCleanCallingIdentity(
1264 () -> mExecutor.execute(
1265 () -> psl.onVoiceActivationStateChanged(activationState)));
fionaxu64eebba2016-11-14 13:32:14 -08001266 }
1267
1268 public void onDataActivationStateChanged(int activationState) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001269 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1270 if (psl == null) return;
1271
1272 Binder.withCleanCallingIdentity(
1273 () -> mExecutor.execute(
1274 () -> psl.onDataActivationStateChanged(activationState)));
fionaxu64eebba2016-11-14 13:32:14 -08001275 }
1276
zxuan35a47022018-01-04 11:24:04 -08001277 public void onUserMobileDataStateChanged(boolean enabled) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001278 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1279 if (psl == null) return;
1280
1281 Binder.withCleanCallingIdentity(
1282 () -> mExecutor.execute(
1283 () -> psl.onUserMobileDataStateChanged(enabled)));
zxuan35a47022018-01-04 11:24:04 -08001284 }
1285
Jack Yuac3ca332020-03-18 14:53:32 -07001286 public void onDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo) {
Jack Yu73036c42020-02-06 13:33:04 -08001287 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1288 if (psl == null) return;
1289
1290 Binder.withCleanCallingIdentity(
1291 () -> mExecutor.execute(
Jack Yuac3ca332020-03-18 14:53:32 -07001292 () -> psl.onDisplayInfoChanged(telephonyDisplayInfo)));
Jack Yu73036c42020-02-06 13:33:04 -08001293 }
1294
Shuo Qian066e8652018-04-25 21:02:35 +00001295 public void onOemHookRawEvent(byte[] rawData) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001296 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1297 if (psl == null) return;
1298
1299 Binder.withCleanCallingIdentity(
1300 () -> mExecutor.execute(() -> psl.onOemHookRawEvent(rawData)));
Shuo Qian066e8652018-04-25 21:02:35 +00001301 }
1302
Andrew Flynn1f452642015-04-14 22:16:04 -04001303 public void onCarrierNetworkChange(boolean active) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001304 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1305 if (psl == null) return;
1306
1307 Binder.withCleanCallingIdentity(
1308 () -> mExecutor.execute(() -> psl.onCarrierNetworkChange(active)));
Andrew Flynn1f452642015-04-14 22:16:04 -04001309 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001310
sqian46c0c302018-12-27 14:12:11 -08001311 public void onEmergencyNumberListChanged(Map emergencyNumberList) {
1312 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1313 if (psl == null) return;
1314
1315 Binder.withCleanCallingIdentity(
1316 () -> mExecutor.execute(
1317 () -> psl.onEmergencyNumberListChanged(emergencyNumberList)));
1318 }
1319
Shuo Qian7a1eb6d2019-09-04 16:21:10 -07001320 public void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber) {
1321 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1322 if (psl == null) return;
1323
1324 Binder.withCleanCallingIdentity(
1325 () -> mExecutor.execute(
1326 () -> psl.onOutgoingEmergencyCall(placedEmergencyNumber)));
1327 }
1328
1329 public void onOutgoingEmergencySms(@NonNull EmergencyNumber sentEmergencyNumber) {
1330 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1331 if (psl == null) return;
1332
1333 Binder.withCleanCallingIdentity(
1334 () -> mExecutor.execute(
1335 () -> psl.onOutgoingEmergencySms(sentEmergencyNumber)));
1336 }
1337
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001338 public void onPhoneCapabilityChanged(PhoneCapability capability) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001339 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1340 if (psl == null) return;
chen xu760729c2018-10-11 13:18:26 -07001341
Nathan Harold7581efd2018-10-25 10:32:10 -07001342 Binder.withCleanCallingIdentity(
1343 () -> mExecutor.execute(() -> psl.onPhoneCapabilityChanged(capability)));
Malcolm Chen27de0e52018-11-12 19:34:38 -08001344 }
1345
Chen Xuc9d4ee12019-09-26 16:11:59 -07001346 public void onRadioPowerStateChanged(@RadioPowerState int state) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001347 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1348 if (psl == null) return;
1349
1350 Binder.withCleanCallingIdentity(
1351 () -> mExecutor.execute(() -> psl.onRadioPowerStateChanged(state)));
chen xu760729c2018-10-11 13:18:26 -07001352 }
Malcolm Chenc1873af2018-09-24 20:01:32 -07001353
Jordan Liufd59a812018-10-23 14:17:39 -07001354 public void onCallAttributesChanged(CallAttributes callAttributes) {
1355 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1356 if (psl == null) return;
1357
1358 Binder.withCleanCallingIdentity(
1359 () -> mExecutor.execute(() -> psl.onCallAttributesChanged(callAttributes)));
1360 }
1361
Malcolm Chen026451d2019-02-14 19:50:19 -08001362 public void onActiveDataSubIdChanged(int subId) {
Nathan Harold7581efd2018-10-25 10:32:10 -07001363 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1364 if (psl == null) return;
1365
1366 Binder.withCleanCallingIdentity(
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -08001367 () -> mExecutor.execute(() -> psl.onActiveDataSubscriptionIdChanged(subId)));
Nathan Harold7581efd2018-10-25 10:32:10 -07001368 }
chen xu0f494682019-01-24 14:14:13 -08001369
1370 public void onImsCallDisconnectCauseChanged(ImsReasonInfo disconnectCause) {
1371 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1372 if (psl == null) return;
1373
1374 Binder.withCleanCallingIdentity(
1375 () -> mExecutor.execute(
1376 () -> psl.onImsCallDisconnectCauseChanged(disconnectCause)));
1377
1378 }
Nathan Harold5e6e9832019-12-17 13:06:54 -08001379
1380 public void onRegistrationFailed(@NonNull CellIdentity cellIdentity,
Chen Xu546ce5e2020-01-10 08:38:31 -08001381 @NonNull String chosenPlmn, int domain,
Nathan Harold5e6e9832019-12-17 13:06:54 -08001382 int causeCode, int additionalCauseCode) {
1383 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1384 if (psl == null) return;
1385
1386 Binder.withCleanCallingIdentity(
1387 () -> mExecutor.execute(() -> psl.onRegistrationFailed(
1388 cellIdentity, chosenPlmn, domain, causeCode, additionalCauseCode)));
1389 // default implementation empty
1390 }
Nathan Haroldc564b1d2019-12-26 17:10:15 -08001391
1392 public void onBarringInfoChanged(BarringInfo barringInfo) {
1393 PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1394 if (psl == null) return;
1395
1396 Binder.withCleanCallingIdentity(
1397 () -> mExecutor.execute(() -> psl.onBarringInfoChanged(barringInfo)));
1398 }
fionaxuf5d7c582016-03-22 15:09:55 -07001399 }
1400
Wink Saville6d13bc82014-08-01 11:13:40 -07001401
1402 private void log(String s) {
1403 Rlog.d(LOG_TAG, s);
1404 }
Nathan Harold7581efd2018-10-25 10:32:10 -07001405}