blob: d6fdbe3fd4dcdb6d615ad3b987c492680ad1cc0e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
Hall Liuee313732018-11-27 14:36:51 -080029import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070031import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070033import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070035import android.os.UserHandle;
Jordan Liu8218ddd2018-11-28 11:22:39 -080036import android.telephony.CallAttributes;
37import android.telephony.CallQuality;
John Wang963db55d2012-03-30 16:04:06 -070038import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070039import android.telephony.CellLocation;
chen xu16e24cd2018-12-11 18:09:41 -080040import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020041import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080042import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070043import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070044import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080045import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020046import android.telephony.PreciseCallState;
47import android.telephony.PreciseDataConnectionState;
48import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070049import android.telephony.Rlog;
50import android.telephony.ServiceState;
51import android.telephony.SignalStrength;
52import android.telephony.SubscriptionManager;
53import android.telephony.TelephonyManager;
chen xu16e24cd2018-12-11 18:09:41 -080054import android.telephony.data.ApnSetting;
sqianbdc5a732018-10-26 13:27:51 -070055import android.telephony.emergency.EmergencyNumber;
chen xu6ac5fc12019-01-24 14:14:13 -080056import android.telephony.ims.ImsReasonInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070057import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070058import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070060import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080062import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070064import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080065import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070066import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080068import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060069import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070070import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import com.android.server.am.BatteryStatsService;
72
Jack Yud19b6ae2017-04-05 14:12:09 -070073import java.io.FileDescriptor;
74import java.io.PrintWriter;
75import java.util.ArrayList;
sqian9f93a122018-12-03 22:40:41 -080076import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070077import java.util.List;
sqian9f93a122018-12-03 22:40:41 -080078import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080079import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081/**
Wink Savillee9b06d72009-05-18 21:47:50 -070082 * Since phone process can be restarted, this class provides a centralized place
83 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070084 *
85 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
86 * and 15973975 by saving the phoneId of the registrant and then using the
87 * phoneId when deciding to to make a callback. This is necessary because
88 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070089 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070090 * the dummy value conversion we properly do the callbacks.
91 *
92 * Eventually we may want to remove the notion of dummy value but for now this
93 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070095@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
96public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070098 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070099 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -0700100 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
102 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800103 Context context;
104
Svet Ganov16a16892015-04-16 10:32:04 -0700105 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700108
Malcolm Chenabbfac22018-02-12 19:15:59 -0800109 TelephonyRegistryDeathRecipient deathRecipient;
110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800112 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700113 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700114
Hall Liu5fb337f2017-11-22 17:38:15 -0800115 int callerUid;
116 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700119
Wink Savilled09c4ca2014-11-22 10:08:16 -0800120 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700121
Wink Savilled09c4ca2014-11-22 10:08:16 -0800122 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800123
124 boolean matchPhoneStateListenerEvent(int events) {
125 return (callback != null) && ((events & this.events) != 0);
126 }
127
Wink Savilled09c4ca2014-11-22 10:08:16 -0800128 boolean matchOnSubscriptionsChangedListener() {
129 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800130 }
Wink Savillee380b982014-07-26 18:24:22 -0700131
Malcolm Chen13f31af2018-09-04 22:12:31 -0700132 boolean matchOnOpportunisticSubscriptionsChangedListener() {
133 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
134 }
135
Tyler Gunnf955e562018-04-26 14:43:31 -0700136 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800137 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700138 return TelephonyPermissions.checkReadCallLog(
139 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800140 } catch (SecurityException e) {
141 return false;
142 }
143 }
144
Wink Savillea12a7b32012-09-20 10:09:45 -0700145 @Override
146 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700147 return "{callingPackage=" + callingPackage + " binder=" + binder
148 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800149 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700150 + onSubscriptionsChangedListenerCallback
151 + " onOpportunisticSubscriptionsChangedListenererCallback="
152 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800153 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800154 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 }
157
158 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Joe Onorato163d8d92010-10-21 13:21:20 -0400160 // access should be inside synchronized (mRecords) for these two fields
161 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
162 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 private final IBatteryStats mBatteryStats;
165
Svet Ganov16a16892015-04-16 10:32:04 -0700166 private final AppOpsManager mAppOps;
167
Malcolm Chen13f31af2018-09-04 22:12:31 -0700168 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
169
170 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700175
Wink Savillefb40dd42014-06-12 17:02:31 -0700176 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700177
Wink Savillefb40dd42014-06-12 17:02:31 -0700178 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700179
fionaxu12312f62016-11-14 13:32:14 -0800180 private int[] mVoiceActivationState;
181
182 private int[] mDataActivationState;
183
zxuan35a47022018-01-04 11:24:04 -0800184 private boolean[] mUserMobileDataState;
185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700191
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700193
Jack Yub1bac542018-03-14 16:23:38 -0700194 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700196
Wink Savillefb40dd42014-06-12 17:02:31 -0700197 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700200
Nathan Harold016e9c62016-12-14 11:24:48 -0800201 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700202
Wink Savillefb40dd42014-06-12 17:02:31 -0700203 private ArrayList<List<CellInfo>> mCellInfo = null;
204
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800205 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
206
sqian9f93a122018-12-03 22:40:41 -0800207 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
208
Jordan Liueae57b22019-01-22 16:17:35 -0800209 private CallQuality mCallQuality = new CallQuality();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800210
Jordan Liueae57b22019-01-22 16:17:35 -0800211 private CallAttributes mCallAttributes = new CallAttributes(new PreciseCallState(),
212 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
Jordan Liu8218ddd2018-11-28 11:22:39 -0800213
Jordan Liu65ed9d92019-02-19 14:42:07 -0800214 // network type of the call associated with the mCallAttributes and mCallQuality
215 private int mCallNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
216
Brad Ebingerefed9822018-10-26 10:25:57 -0700217 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700218
Wink Savilled09c4ca2014-11-22 10:08:16 -0800219 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700220
Wink Savilled09c4ca2014-11-22 10:08:16 -0800221 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700222
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200223 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
224
225 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
226
227 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
228
229 private PreciseCallState mPreciseCallState = new PreciseCallState();
230
chen xu6a942d482018-12-12 19:59:30 -0800231 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
232
chen xu6ac5fc12019-01-24 14:14:13 -0800233 private List<ImsReasonInfo> mImsReasonInfo = null;
234
chen xu6a942d482018-12-12 19:59:30 -0800235 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
236
Andrew Flynn1f452642015-04-14 22:16:04 -0400237 private boolean mCarrierNetworkChangeState = false;
238
Malcolm Chene1623652018-08-08 20:27:45 -0700239 private PhoneCapability mPhoneCapability = null;
240
Malcolm Chen026451d2019-02-14 19:50:19 -0800241 private int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700242
Chen Xu7395c632018-10-17 17:53:47 +0000243 @TelephonyManager.RadioPowerState
244 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
245
Jack Yud19b6ae2017-04-05 14:12:09 -0700246 private final LocalLog mLocalLog = new LocalLog(100);
247
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200248 private PreciseDataConnectionState mPreciseDataConnectionState =
249 new PreciseDataConnectionState();
250
Hall Liuee313732018-11-27 14:36:51 -0800251 // Nothing here yet, but putting it here in case we want to add more in the future.
252 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = 0;
253
254 static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK =
Hall Liu70bbc162018-03-02 17:44:46 -0800255 PhoneStateListener.LISTEN_CELL_LOCATION
256 | PhoneStateListener.LISTEN_CELL_INFO;
257
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700258 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian9f93a122018-12-03 22:40:41 -0800259 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
260 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
Malcolm Chen026451d2019-02-14 19:50:19 -0800261 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800262 | PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700263
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200264 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
265 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
266 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
267
Wink Savillea12a7b32012-09-20 10:09:45 -0700268 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700269 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700270
271 private final Handler mHandler = new Handler() {
272 @Override
273 public void handleMessage(Message msg) {
274 switch (msg.what) {
275 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700276 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700277 int numPhones = TelephonyManager.getDefault().getPhoneCount();
278 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700279 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700280 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700281 }
282 break;
283 }
xinhee9f16402014-09-25 16:39:28 -0700284 case MSG_UPDATE_DEFAULT_SUB: {
285 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700286 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700287 if (VDBG) {
288 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
289 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
290 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
291 }
292
293 //Due to possible risk condition,(notify call back using the new
294 //defaultSubId comes before new defaultSubId update) we need to recall all
295 //possible missed notify callback
296 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700297 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800298 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700299 checkPossibleMissNotify(r, newDefaultPhoneId);
300 }
301 }
302 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700303 }
304 mDefaultSubId = newDefaultSubId;
305 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700306 }
307 }
308 }
309 };
310
Malcolm Chenabbfac22018-02-12 19:15:59 -0800311 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
312
313 private final IBinder binder;
314
315 TelephonyRegistryDeathRecipient(IBinder binder) {
316 this.binder = binder;
317 }
318
319 @Override
320 public void binderDied() {
321 if (DBG) log("binderDied " + binder);
322 remove(binder);
323 }
324 }
325
Wink Savillea12a7b32012-09-20 10:09:45 -0700326 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
327 @Override
328 public void onReceive(Context context, Intent intent) {
329 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700330 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700331 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700332 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700333 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700334 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700336 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800337 PhoneConstants.SUBSCRIPTION_KEY,
338 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700339 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
340 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700341 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700342 log("onReceive:current mDefaultSubId=" + mDefaultSubId
343 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
344 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700345 }
xinhee9f16402014-09-25 16:39:28 -0700346
Junda Liu985f52c2015-02-23 16:06:51 -0800347 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700348 || (newDefaultPhoneId != mDefaultPhoneId))) {
349 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
350 newDefaultPhoneId, 0, newDefaultSubIdObj));
351 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700352 }
353 }
354 };
355
Wink Savillee9b06d72009-05-18 21:47:50 -0700356 // we keep a copy of all of the state so we can send it out when folks
357 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700359 // In these calls we call with the lock held. This is safe becasuse remote
360 // calls go through a oneway interface and local calls going through a
361 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700363 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
364 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700365 CellLocation location = CellLocation.getEmpty();
366
Wink Savillefb40dd42014-06-12 17:02:31 -0700367 mContext = context;
368 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700369
Wink Savillefb40dd42014-06-12 17:02:31 -0700370 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700371 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700372 mNumPhones = numPhones;
373 mCallState = new int[numPhones];
374 mDataActivity = new int[numPhones];
375 mDataConnectionState = new int[numPhones];
376 mDataConnectionNetworkType = new int[numPhones];
377 mCallIncomingNumber = new String[numPhones];
378 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800379 mVoiceActivationState = new int[numPhones];
380 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800381 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700382 mSignalStrength = new SignalStrength[numPhones];
383 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700384 mCallForwarding = new boolean[numPhones];
385 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700386 mCellInfo = new ArrayList<List<CellInfo>>();
Brad Ebingerefed9822018-10-26 10:25:57 -0700387 mSrvccState = new int[numPhones];
chen xu6ac5fc12019-01-24 14:14:13 -0800388 mImsReasonInfo = new ArrayList<ImsReasonInfo>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800389 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
sqian9f93a122018-12-03 22:40:41 -0800390 mEmergencyNumberList = new HashMap<>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700391 for (int i = 0; i < numPhones; i++) {
392 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
393 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
394 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800395 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
396 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700397 mCallIncomingNumber[i] = "";
398 mServiceState[i] = new ServiceState();
399 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800400 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700401 mMessageWaiting[i] = false;
402 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700403 mCellLocation[i] = new Bundle();
404 mCellInfo.add(i, null);
chen xu6ac5fc12019-01-24 14:14:13 -0800405 mImsReasonInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700406 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700407 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700408 }
409
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700410 // Note that location can be null for non-phone builds like
411 // like the generic one.
412 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700413 for (int i = 0; i < numPhones; i++) {
414 location.fillInNotifierBundle(mCellLocation[i]);
415 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700416 }
Svet Ganov16a16892015-04-16 10:32:04 -0700417
418 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 }
420
Svetoslav Ganova0027152013-06-25 14:59:53 -0700421 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700422 // Watch for interesting updates
423 final IntentFilter filter = new IntentFilter();
424 filter.addAction(Intent.ACTION_USER_SWITCHED);
425 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700426 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700427 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700428 mContext.registerReceiver(mBroadcastReceiver, filter);
429 }
430
431 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700432 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800433 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700434 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800436 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700437 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
438 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800439 + " callback.asBinder=" + callback.asBinder());
440 }
441
Wink Savilled09c4ca2014-11-22 10:08:16 -0800442 synchronized (mRecords) {
443 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800444 IBinder b = callback.asBinder();
445 Record r = add(b);
446
447 if (r == null) {
448 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800449 }
450
Jeff Davidson29da89f2018-02-28 17:50:16 -0800451 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800452 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700453 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800454 r.callerUid = Binder.getCallingUid();
455 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800456 r.events = 0;
457 if (DBG) {
458 log("listen oscl: Register r=" + r);
459 }
460 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700461 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800462 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800463 if (VDBG) log("listen oscl: send to r=" + r);
464 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
465 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800466 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800467 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800468 remove(r.binder);
469 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800470 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700471 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800472 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800473 }
474 }
475
476 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800477 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800478 IOnSubscriptionsChangedListener callback) {
479 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800480 remove(callback.asBinder());
481 }
482
Malcolm Chen13f31af2018-09-04 22:12:31 -0700483
484 @Override
485 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
486 IOnSubscriptionsChangedListener callback) {
487 int callerUserId = UserHandle.getCallingUserId();
488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
489 if (VDBG) {
490 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
491 + " callerUserId=" + callerUserId + " callback=" + callback
492 + " callback.asBinder=" + callback.asBinder());
493 }
494
495 synchronized (mRecords) {
496 // register
497 IBinder b = callback.asBinder();
498 Record r = add(b);
499
500 if (r == null) {
501 return;
502 }
503
504 r.context = mContext;
505 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
506 r.callingPackage = callingPackage;
507 r.callerUid = Binder.getCallingUid();
508 r.callerPid = Binder.getCallingPid();
509 r.events = 0;
510 if (DBG) {
511 log("listen ooscl: Register r=" + r);
512 }
513 // Always notify when registration occurs if there has been a notification.
514 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
515 try {
516 if (VDBG) log("listen ooscl: send to r=" + r);
517 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
518 if (VDBG) log("listen ooscl: sent to r=" + r);
519 } catch (RemoteException e) {
520 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
521 remove(r.binder);
522 }
523 } else {
524 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
525 }
526 }
527 }
528
Wink Savillea374c3d2014-11-11 11:48:04 -0800529 @Override
530 public void notifySubscriptionInfoChanged() {
531 if (VDBG) log("notifySubscriptionInfoChanged:");
532 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700533 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800534 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
535 + mRecords.size());
536 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700537 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800538 mRemoveList.clear();
539 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800540 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800541 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800542 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
543 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
544 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800545 } catch (RemoteException ex) {
546 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
547 mRemoveList.add(r.binder);
548 }
549 }
550 }
551 handleRemoveListLocked();
552 }
553 }
554
555 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700556 public void notifyOpportunisticSubscriptionInfoChanged() {
557 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
558 synchronized (mRecords) {
559 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
560 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
561 + mRecords.size());
562 }
563 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
564 mRemoveList.clear();
565 for (Record r : mRecords) {
566 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
567 try {
568 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
569 r.onOpportunisticSubscriptionsChangedListenerCallback
570 .onSubscriptionsChanged();
571 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
572 } catch (RemoteException ex) {
573 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
574 mRemoveList.add(r.binder);
575 }
576 }
577 }
578 handleRemoveListLocked();
579 }
580 }
581
582 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
584 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800585 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
586 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 }
588
589 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700590 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700591 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700592 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700593 }
594
Svet Ganov16a16892015-04-16 10:32:04 -0700595 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700596 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700597 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700599 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700600 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700601 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
602 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700603 }
xinhe75c2c152014-10-16 11:49:45 -0700604
605 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800606 // Checks permission and throws SecurityException for disallowed operations. For pre-M
607 // apps whose runtime permission has been revoked, we return immediately to skip sending
608 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800609 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800610 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700611 }
612
yifan.baie620ce72017-12-22 14:59:57 +0800613 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 synchronized (mRecords) {
615 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800616 IBinder b = callback.asBinder();
617 Record r = add(b);
618
619 if (r == null) {
620 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 }
xinhe43c50292014-09-18 17:56:48 -0700622
Jeff Davidson29da89f2018-02-28 17:50:16 -0800623 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700624 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700625 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800626 r.callerUid = Binder.getCallingUid();
627 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700628 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
629 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800630 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800631 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700632 } else {//APP specify subID
633 r.subId = subId;
634 }
yifan.baie620ce72017-12-22 14:59:57 +0800635 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700637 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700638 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700639 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700640 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400642 try {
Wink Savillee380b982014-07-26 18:24:22 -0700643 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800644 ServiceState rawSs = new ServiceState(mServiceState[phoneId]);
645 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
646 r.callback.onServiceStateChanged(rawSs);
647 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
648 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(false));
649 } else {
650 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(true));
651 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400652 } catch (RemoteException ex) {
653 remove(r.binder);
654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 }
656 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
657 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700658 int gsmSignalStrength = mSignalStrength[phoneId]
659 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700660 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
661 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 } catch (RemoteException ex) {
663 remove(r.binder);
664 }
665 }
666 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
667 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700668 r.callback.onMessageWaitingIndicatorChanged(
669 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 } catch (RemoteException ex) {
671 remove(r.binder);
672 }
673 }
674 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
675 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700676 r.callback.onCallForwardingIndicatorChanged(
677 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 } catch (RemoteException ex) {
679 remove(r.binder);
680 }
681 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700682 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400683 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700684 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700685 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800686 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800687 r.callback.onCellLocationChanged(
688 new Bundle(mCellLocation[phoneId]));
689 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400690 } catch (RemoteException ex) {
691 remove(r.binder);
692 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 }
694 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
695 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700696 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700697 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 } catch (RemoteException ex) {
699 remove(r.binder);
700 }
701 }
702 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
703 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700704 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
705 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 } catch (RemoteException ex) {
707 remove(r.binder);
708 }
709 }
710 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
711 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700712 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 } catch (RemoteException ex) {
714 remove(r.binder);
715 }
716 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700717 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
718 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700719 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700720 } catch (RemoteException ex) {
721 remove(r.binder);
722 }
723 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700724 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
725 try {
726 r.callback.onOtaspChanged(mOtaspMode);
727 } catch (RemoteException ex) {
728 remove(r.binder);
729 }
730 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700731 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700732 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700733 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700734 + mCellInfo.get(phoneId));
Hall Liuee313732018-11-27 14:36:51 -0800735 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800736 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
737 }
John Wang963db55d2012-03-30 16:04:06 -0700738 } catch (RemoteException ex) {
739 remove(r.binder);
740 }
741 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200742 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
743 try {
744 r.callback.onPreciseCallStateChanged(mPreciseCallState);
745 } catch (RemoteException ex) {
746 remove(r.binder);
747 }
748 }
chen xu6a942d482018-12-12 19:59:30 -0800749 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
750 try {
751 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
752 mCallPreciseDisconnectCause);
753 } catch (RemoteException ex) {
754 remove(r.binder);
755 }
756 }
chen xu6ac5fc12019-01-24 14:14:13 -0800757 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
758 try {
759 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
760 } catch (RemoteException ex) {
761 remove(r.binder);
762 }
763 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200764 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
765 try {
766 r.callback.onPreciseDataConnectionStateChanged(
767 mPreciseDataConnectionState);
768 } catch (RemoteException ex) {
769 remove(r.binder);
770 }
771 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400772 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
773 try {
774 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
775 } catch (RemoteException ex) {
776 remove(r.binder);
777 }
778 }
fionaxu12312f62016-11-14 13:32:14 -0800779 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
780 try {
781 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
782 } catch (RemoteException ex) {
783 remove(r.binder);
784 }
785 }
786 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
787 try {
788 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
789 } catch (RemoteException ex) {
790 remove(r.binder);
791 }
792 }
zxuan35a47022018-01-04 11:24:04 -0800793 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
794 try {
795 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
796 } catch (RemoteException ex) {
797 remove(r.binder);
798 }
799 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800800 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
801 try {
802 r.callback.onPhysicalChannelConfigurationChanged(
803 mPhysicalChannelConfigs.get(phoneId));
804 } catch (RemoteException ex) {
805 remove(r.binder);
806 }
807 }
sqian9f93a122018-12-03 22:40:41 -0800808 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
809 try {
810 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
811 } catch (RemoteException ex) {
812 remove(r.binder);
813 }
814 }
Malcolm Chene1623652018-08-08 20:27:45 -0700815 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
816 try {
817 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
818 } catch (RemoteException ex) {
819 remove(r.binder);
820 }
821 }
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800822 if ((events & PhoneStateListener
823 .LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700824 try {
Malcolm Chen026451d2019-02-14 19:50:19 -0800825 r.callback.onActiveDataSubIdChanged(mActiveDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700826 } catch (RemoteException ex) {
827 remove(r.binder);
828 }
829 }
Chen Xu7395c632018-10-17 17:53:47 +0000830 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
831 try {
832 r.callback.onRadioPowerStateChanged(mRadioPowerState);
833 } catch (RemoteException ex) {
834 remove(r.binder);
835 }
836 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700837 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
838 try {
839 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
840 } catch (RemoteException ex) {
841 remove(r.binder);
842 }
843 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800844 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
845 try {
846 r.callback.onCallAttributesChanged(mCallAttributes);
847 } catch (RemoteException ex) {
848 remove(r.binder);
849 }
850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 }
852 }
853 } else {
xinhe75c2c152014-10-16 11:49:45 -0700854 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 remove(callback.asBinder());
856 }
857 }
858
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700859 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700860 // Only reveal the incoming number if the record has read call log permission.
861 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700862 }
863
Malcolm Chenabbfac22018-02-12 19:15:59 -0800864 private Record add(IBinder binder) {
865 Record r;
866
867 synchronized (mRecords) {
868 final int N = mRecords.size();
869 for (int i = 0; i < N; i++) {
870 r = mRecords.get(i);
871 if (binder == r.binder) {
872 // Already existed.
873 return r;
874 }
875 }
876 r = new Record();
877 r.binder = binder;
878 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
879
880 try {
881 binder.linkToDeath(r.deathRecipient, 0);
882 } catch (RemoteException e) {
883 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
884 // Binder already died. Return null.
885 return null;
886 }
887
888 mRecords.add(r);
889 if (DBG) log("add new record");
890 }
891
892 return r;
893 }
894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 private void remove(IBinder binder) {
896 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700897 final int recordCount = mRecords.size();
898 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800899 Record r = mRecords.get(i);
900 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800901 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800902 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
903 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800904 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800905
906 if (r.deathRecipient != null) {
907 try {
908 binder.unlinkToDeath(r.deathRecipient, 0);
909 } catch (NoSuchElementException e) {
910 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
911 + r + " e=" + e);
912 }
913 }
914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 mRecords.remove(i);
916 return;
917 }
918 }
919 }
920 }
921
Tyler Gunnf955e562018-04-26 14:43:31 -0700922 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700923 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700924 return;
925 }
xinhe43c50292014-09-18 17:56:48 -0700926
927 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700928 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700929 }
930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700932 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800933 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800934 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700936 // Ensure the listener has read call log permission; if they do not return
937 // an empty phone number.
938 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
939 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400941 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 }
943 }
944 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400945 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700947
948 // Called only by Telecomm to communicate call state across different phone accounts. So
949 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700950 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700951 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700952 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 }
954
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700955 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
956 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700957 if (!checkNotifyPermission("notifyCallState()")) {
958 return;
959 }
Wink Savillee380b982014-07-26 18:24:22 -0700960 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700961 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700962 + " state=" + state + " incomingNumber=" + incomingNumber);
963 }
964 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700965 if (validatePhoneId(phoneId)) {
966 mCallState[phoneId] = state;
967 mCallIncomingNumber[phoneId] = incomingNumber;
968 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800969 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700970 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800971 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700972 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700973 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
974 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700975 } catch (RemoteException ex) {
976 mRemoveList.add(r.binder);
977 }
978 }
979 }
980 }
981 handleRemoveListLocked();
982 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700983 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700984 }
985
Wink Saville63f03dd2014-10-23 10:44:45 -0700986 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700987 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700988 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700989 }
xinhe43c50292014-09-18 17:56:48 -0700990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700992 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
993 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700994 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700995 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700996 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700997 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700998 if (validatePhoneId(phoneId)) {
999 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001000
Wink Savillefb40dd42014-06-12 17:02:31 -07001001 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001002 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001003 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001004 + " phoneId=" + phoneId + " state=" + state);
1005 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001006 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001007 idMatch(r.subId, subId, phoneId)) {
Hall Liuee313732018-11-27 14:36:51 -08001008
Wink Savillefb40dd42014-06-12 17:02:31 -07001009 try {
Hall Liuee313732018-11-27 14:36:51 -08001010 ServiceState stateToSend;
1011 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
1012 stateToSend = new ServiceState(state);
1013 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
1014 stateToSend = state.sanitizeLocationInfo(false);
1015 } else {
1016 stateToSend = state.sanitizeLocationInfo(true);
1017 }
Wink Savillee380b982014-07-26 18:24:22 -07001018 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001019 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001020 + " subId=" + subId + " phoneId=" + phoneId
1021 + " state=" + state);
1022 }
Hall Liuee313732018-11-27 14:36:51 -08001023 r.callback.onServiceStateChanged(stateToSend);
Wink Savillefb40dd42014-06-12 17:02:31 -07001024 } catch (RemoteException ex) {
1025 mRemoveList.add(r.binder);
1026 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001029 } else {
Wink Savillebc027272014-09-08 14:50:58 -07001030 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001032 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001034 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 }
1036
fionaxu12312f62016-11-14 13:32:14 -08001037 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1038 int activationType, int activationState) {
1039 if (!checkNotifyPermission("notifySimActivationState()")){
1040 return;
1041 }
1042 if (VDBG) {
1043 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1044 + "type=" + activationType + " state=" + activationState);
1045 }
1046 synchronized (mRecords) {
1047 if (validatePhoneId(phoneId)) {
1048 switch (activationType) {
1049 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
1050 mVoiceActivationState[phoneId] = activationState;
1051 break;
1052 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
1053 mDataActivationState[phoneId] = activationState;
1054 break;
1055 default:
1056 return;
1057 }
1058 for (Record r : mRecords) {
1059 if (VDBG) {
1060 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1061 + " phoneId=" + phoneId + "type=" + activationType
1062 + " state=" + activationState);
1063 }
1064 try {
1065 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1066 r.matchPhoneStateListenerEvent(
1067 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1068 idMatch(r.subId, subId, phoneId)) {
1069 if (DBG) {
1070 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1071 + " subId=" + subId + " phoneId=" + phoneId
1072 + " state=" + activationState);
1073 }
1074 r.callback.onVoiceActivationStateChanged(activationState);
1075 }
1076 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1077 r.matchPhoneStateListenerEvent(
1078 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1079 idMatch(r.subId, subId, phoneId)) {
1080 if (DBG) {
1081 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1082 + " subId=" + subId + " phoneId=" + phoneId
1083 + " state=" + activationState);
1084 }
1085 r.callback.onDataActivationStateChanged(activationState);
1086 }
1087 } catch (RemoteException ex) {
1088 mRemoveList.add(r.binder);
1089 }
1090 }
1091 } else {
1092 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1093 }
1094 handleRemoveListLocked();
1095 }
1096 }
1097
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001098 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1099 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001100 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001101 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001102 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001103 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001104 log("notifySignalStrengthForPhoneId: subId=" + subId
1105 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001106 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001109 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001110 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001111 mSignalStrength[phoneId] = signalStrength;
1112 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001113 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001114 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001115 + " phoneId=" + phoneId + " ss=" + signalStrength);
1116 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001117 if (r.matchPhoneStateListenerEvent(
1118 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001119 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001120 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001121 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001122 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001123 + " subId=" + subId + " phoneId=" + phoneId
1124 + " ss=" + signalStrength);
1125 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001126 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1127 } catch (RemoteException ex) {
1128 mRemoveList.add(r.binder);
1129 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001130 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001131 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001132 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001133 try {
1134 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001135 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001136 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001137 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001138 + " subId=" + subId + " phoneId=" + phoneId
1139 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1140 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001141 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001142 } catch (RemoteException ex) {
1143 mRemoveList.add(r.binder);
1144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 }
1146 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001147 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001148 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001150 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001152 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 }
1154
Andrew Flynn1f452642015-04-14 22:16:04 -04001155 @Override
1156 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001157 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1158
Andrew Flynn1f452642015-04-14 22:16:04 -04001159 if (VDBG) {
1160 log("notifyCarrierNetworkChange: active=" + active);
1161 }
1162
1163 synchronized (mRecords) {
1164 mCarrierNetworkChangeState = active;
1165 for (Record r : mRecords) {
1166 if (r.matchPhoneStateListenerEvent(
1167 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1168 try {
1169 r.callback.onCarrierNetworkChange(active);
1170 } catch (RemoteException ex) {
1171 mRemoveList.add(r.binder);
1172 }
1173 }
1174 }
1175 handleRemoveListLocked();
1176 }
1177 }
1178
Wink Savilleb208a242012-07-25 14:08:09 -07001179 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001180 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001181 }
1182
Wink Saville63f03dd2014-10-23 10:44:45 -07001183 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001184 if (!checkNotifyPermission("notifyCellInfo()")) {
1185 return;
1186 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001187 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001188 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001189 + " cellInfo=" + cellInfo);
1190 }
yifan.baie620ce72017-12-22 14:59:57 +08001191 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001192 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001193 if (validatePhoneId(phoneId)) {
1194 mCellInfo.set(phoneId, cellInfo);
1195 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001196 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001197 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001198 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001199 try {
1200 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001201 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001202 }
1203 r.callback.onCellInfoChanged(cellInfo);
1204 } catch (RemoteException ex) {
1205 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001206 }
John Wang963db55d2012-03-30 16:04:06 -07001207 }
1208 }
1209 }
1210 handleRemoveListLocked();
1211 }
1212 }
1213
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001214 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1215 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1216 configs);
1217 }
1218
1219 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1220 List<PhysicalChannelConfig> configs) {
1221 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1222 return;
1223 }
1224
1225 if (VDBG) {
1226 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1227 }
1228
1229 synchronized (mRecords) {
1230 int phoneId = SubscriptionManager.getPhoneId(subId);
1231 if (validatePhoneId(phoneId)) {
1232 mPhysicalChannelConfigs.set(phoneId, configs);
1233 for (Record r : mRecords) {
1234 if (r.matchPhoneStateListenerEvent(
1235 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1236 && idMatch(r.subId, subId, phoneId)) {
1237 try {
1238 if (DBG_LOC) {
1239 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1240 + configs + " r=" + r);
1241 }
1242 r.callback.onPhysicalChannelConfigurationChanged(configs);
1243 } catch (RemoteException ex) {
1244 mRemoveList.add(r.binder);
1245 }
1246 }
1247 }
1248 }
1249 handleRemoveListLocked();
1250 }
1251 }
1252
xinhe43c50292014-09-18 17:56:48 -07001253 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001254 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001255 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001256 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001257 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001258 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001259 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001260 + " mwi=" + mwi);
1261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001263 if (validatePhoneId(phoneId)) {
1264 mMessageWaiting[phoneId] = mwi;
1265 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001266 if (r.matchPhoneStateListenerEvent(
1267 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001268 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001269 try {
1270 r.callback.onMessageWaitingIndicatorChanged(mwi);
1271 } catch (RemoteException ex) {
1272 mRemoveList.add(r.binder);
1273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 }
1275 }
1276 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001277 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 }
1279 }
1280
zxuan35a47022018-01-04 11:24:04 -08001281 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1282 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1283 return;
1284 }
1285 if (VDBG) {
1286 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1287 + " state=" + state);
1288 }
1289 synchronized (mRecords) {
1290 if (validatePhoneId(phoneId)) {
1291 mMessageWaiting[phoneId] = state;
1292 for (Record r : mRecords) {
1293 if (r.matchPhoneStateListenerEvent(
1294 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1295 idMatch(r.subId, subId, phoneId)) {
1296 try {
1297 r.callback.onUserMobileDataStateChanged(state);
1298 } catch (RemoteException ex) {
1299 mRemoveList.add(r.binder);
1300 }
1301 }
1302 }
1303 }
1304 handleRemoveListLocked();
1305 }
1306 }
1307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001309 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001310 }
1311
Wink Saville63f03dd2014-10-23 10:44:45 -07001312 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001313 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001314 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001315 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001316 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001317 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001318 + " cfi=" + cfi);
1319 }
yifan.baie620ce72017-12-22 14:59:57 +08001320 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001322 if (validatePhoneId(phoneId)) {
1323 mCallForwarding[phoneId] = cfi;
1324 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001325 if (r.matchPhoneStateListenerEvent(
1326 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001327 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001328 try {
1329 r.callback.onCallForwardingIndicatorChanged(cfi);
1330 } catch (RemoteException ex) {
1331 mRemoveList.add(r.binder);
1332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 }
1334 }
1335 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001336 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 }
1338 }
1339
1340 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001341 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001342 }
1343
Wink Saville63f03dd2014-10-23 10:44:45 -07001344 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001345 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001346 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001347 }
yifan.baie620ce72017-12-22 14:59:57 +08001348 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001350 if (validatePhoneId(phoneId)) {
1351 mDataActivity[phoneId] = state;
1352 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001353 // Notify by correct subId.
1354 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1355 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001356 try {
1357 r.callback.onDataActivity(state);
1358 } catch (RemoteException ex) {
1359 mRemoveList.add(r.binder);
1360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 }
1362 }
1363 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001364 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 }
1366 }
1367
Jack Yu4d1c9452019-01-02 16:51:08 -08001368 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1369 LinkProperties linkProperties,
1370 NetworkCapabilities networkCapabilities, int networkType,
1371 boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001372 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yu4d1c9452019-01-02 16:51:08 -08001373 isDataAllowed, apn, apnType, linkProperties,
1374 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001375 }
1376
Jack Yu4d1c9452019-01-02 16:51:08 -08001377 public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataAllowed,
1378 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001379 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1380 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001381 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001382 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001383 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001384 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001385 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001386 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001387 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001388 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001389 }
yifan.baie620ce72017-12-22 14:59:57 +08001390 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001392 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001393 // We only call the callback when the change is for default APN type.
1394 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1395 && (mDataConnectionState[phoneId] != state
1396 || mDataConnectionNetworkType[phoneId] != networkType)) {
1397 String str = "onDataConnectionStateChanged(" + state
1398 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001399 log(str);
1400 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001401 for (Record r : mRecords) {
1402 if (r.matchPhoneStateListenerEvent(
1403 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1404 idMatch(r.subId, subId, phoneId)) {
1405 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001406 if (DBG) {
1407 log("Notify data connection state changed on sub: " + subId);
1408 }
Jack Yub1bac542018-03-14 16:23:38 -07001409 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001410 } catch (RemoteException ex) {
1411 mRemoveList.add(r.binder);
1412 }
1413 }
1414 }
1415 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001416
1417 mDataConnectionState[phoneId] = state;
1418 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001419 }
1420 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
chen xu16e24cd2018-12-11 18:09:41 -08001421 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1422 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001423 for (Record r : mRecords) {
1424 if (r.matchPhoneStateListenerEvent(
1425 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1426 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001427 r.callback.onPreciseDataConnectionStateChanged(
1428 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001429 } catch (RemoteException ex) {
1430 mRemoveList.add(r.binder);
1431 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001432 }
1433 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001434 }
1435 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001437 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1438 networkCapabilities, roaming, subId);
1439 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu16e24cd2018-12-11 18:09:41 -08001440 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 }
1442
Jack Yu4d1c9452019-01-02 16:51:08 -08001443 public void notifyDataConnectionFailed(String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001444 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yu4d1c9452019-01-02 16:51:08 -08001445 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001446 }
1447
Jack Yu4d1c9452019-01-02 16:51:08 -08001448 public void notifyDataConnectionFailedForSubscriber(int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001449 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001450 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001451 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001452 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001453 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yu4d1c9452019-01-02 16:51:08 -08001454 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001455 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001457 mPreciseDataConnectionState = new PreciseDataConnectionState(
1458 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu81653862019-02-28 10:44:54 -08001459 ApnSetting.getApnTypesBitmaskFromString(apnType), null, null,
chen xu16e24cd2018-12-11 18:09:41 -08001460 DataFailCause.NONE);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001461 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001462 if (r.matchPhoneStateListenerEvent(
1463 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001464 try {
1465 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1466 } catch (RemoteException ex) {
1467 mRemoveList.add(r.binder);
1468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 }
1470 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001471 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001473 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001474 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu81653862019-02-28 10:44:54 -08001475 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, null, null,
chen xu16e24cd2018-12-11 18:09:41 -08001476 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 }
1478
1479 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001480 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001481 }
1482
Wink Saville63f03dd2014-10-23 10:44:45 -07001483 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001484 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001485 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001486 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001487 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001488 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001489 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001490 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001491 + " cellLocation=" + cellLocation);
1492 }
yifan.baie620ce72017-12-22 14:59:57 +08001493 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001495 if (validatePhoneId(phoneId)) {
1496 mCellLocation[phoneId] = cellLocation;
1497 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001498 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001499 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001500 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001501 try {
1502 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001503 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001504 + " r=" + r);
1505 }
1506 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1507 } catch (RemoteException ex) {
1508 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001509 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 }
1512 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001513 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001514 }
1515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516
Wink Savillefd2d0132010-10-28 14:22:26 -07001517 public void notifyOtaspChanged(int otaspMode) {
1518 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1519 return;
1520 }
1521 synchronized (mRecords) {
1522 mOtaspMode = otaspMode;
1523 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001524 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001525 try {
1526 r.callback.onOtaspChanged(otaspMode);
1527 } catch (RemoteException ex) {
1528 mRemoveList.add(r.binder);
1529 }
1530 }
1531 }
1532 handleRemoveListLocked();
1533 }
1534 }
1535
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001536 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001537 int backgroundCallState, int phoneId) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001538 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1539 return;
1540 }
1541 synchronized (mRecords) {
1542 mRingingCallState = ringingCallState;
1543 mForegroundCallState = foregroundCallState;
1544 mBackgroundCallState = backgroundCallState;
1545 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1546 backgroundCallState,
1547 DisconnectCause.NOT_VALID,
1548 PreciseDisconnectCause.NOT_VALID);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001549 boolean notifyCallAttributes = true;
1550 if (mCallQuality == null) {
1551 log("notifyPreciseCallState: mCallQuality is null, skipping call attributes");
1552 notifyCallAttributes = false;
1553 } else {
Jordan Liu83b870f2019-02-22 14:19:55 -08001554 // If the precise call state is no longer active, reset the call network type and
1555 // call quality.
1556 if (mPreciseCallState.getForegroundCallState()
1557 != PreciseCallState.PRECISE_CALL_STATE_ACTIVE) {
1558 mCallNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1559 mCallQuality = new CallQuality();
1560 }
Jordan Liu65ed9d92019-02-19 14:42:07 -08001561 mCallAttributes = new CallAttributes(mPreciseCallState, mCallNetworkType,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001562 mCallQuality);
1563 }
1564
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001565 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001566 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001567 try {
1568 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1569 } catch (RemoteException ex) {
1570 mRemoveList.add(r.binder);
1571 }
1572 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001573 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1574 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1575 try {
1576 r.callback.onCallAttributesChanged(mCallAttributes);
1577 } catch (RemoteException ex) {
1578 mRemoveList.add(r.binder);
1579 }
1580 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001581 }
1582 handleRemoveListLocked();
1583 }
chen xu6a942d482018-12-12 19:59:30 -08001584 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1585 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001586 }
1587
1588 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1589 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1590 return;
1591 }
1592 synchronized (mRecords) {
chen xu6a942d482018-12-12 19:59:30 -08001593 mCallDisconnectCause = disconnectCause;
1594 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001595 for (Record r : mRecords) {
chen xu6a942d482018-12-12 19:59:30 -08001596 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1597 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001598 try {
chen xu6a942d482018-12-12 19:59:30 -08001599 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1600 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001601 } catch (RemoteException ex) {
1602 mRemoveList.add(r.binder);
1603 }
1604 }
1605 }
1606 handleRemoveListLocked();
1607 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001608 }
1609
chen xu6ac5fc12019-01-24 14:14:13 -08001610 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1611 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1612 return;
1613 }
1614 int phoneId = SubscriptionManager.getPhoneId(subId);
1615 synchronized (mRecords) {
1616 if (validatePhoneId(phoneId)) {
1617 mImsReasonInfo.set(phoneId, imsReasonInfo);
1618 for (Record r : mRecords) {
1619 if (r.matchPhoneStateListenerEvent(
1620 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1621 && idMatch(r.subId, subId, phoneId)) {
1622 try {
1623 if (DBG_LOC) {
1624 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1625 + imsReasonInfo + " r=" + r);
1626 }
1627 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1628 } catch (RemoteException ex) {
1629 mRemoveList.add(r.binder);
1630 }
1631 }
1632 }
1633 }
1634 handleRemoveListLocked();
1635 }
1636 }
1637
chen xu16e24cd2018-12-11 18:09:41 -08001638 public void notifyPreciseDataConnectionFailed(String apnType,
1639 String apn, @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001640 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1641 return;
1642 }
1643 synchronized (mRecords) {
1644 mPreciseDataConnectionState = new PreciseDataConnectionState(
1645 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu16e24cd2018-12-11 18:09:41 -08001646 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001647 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001648 if (r.matchPhoneStateListenerEvent(
1649 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001650 try {
1651 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1652 } catch (RemoteException ex) {
1653 mRemoveList.add(r.binder);
1654 }
1655 }
1656 }
1657 handleRemoveListLocked();
1658 }
1659 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yu4d1c9452019-01-02 16:51:08 -08001660 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001661 }
1662
Brad Ebingerefed9822018-10-26 10:25:57 -07001663 @Override
1664 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1665 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001666 return;
1667 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001668 if (VDBG) {
1669 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1670 }
1671 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001672 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001673 if (validatePhoneId(phoneId)) {
chen xu6ac5fc12019-01-24 14:14:13 -08001674 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001675 for (Record r : mRecords) {
1676 if (r.matchPhoneStateListenerEvent(
1677 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1678 idMatch(r.subId, subId, phoneId)) {
1679 try {
1680 if (DBG_LOC) {
1681 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1682 }
1683 r.callback.onSrvccStateChanged(state);
1684 } catch (RemoteException ex) {
1685 mRemoveList.add(r.binder);
1686 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001687 }
1688 }
1689 }
1690 handleRemoveListLocked();
1691 }
1692 }
1693
Shuo Qian066e8652018-04-25 21:02:35 +00001694 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1695 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1696 return;
1697 }
1698
1699 synchronized (mRecords) {
1700 for (Record r : mRecords) {
1701 if (VDBG) {
1702 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1703 }
1704 if ((r.matchPhoneStateListenerEvent(
1705 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1706 ((r.subId == subId) ||
1707 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1708 try {
1709 r.callback.onOemHookRawEvent(rawData);
1710 } catch (RemoteException ex) {
1711 mRemoveList.add(r.binder);
1712 }
1713 }
1714 }
1715 handleRemoveListLocked();
1716 }
1717 }
1718
Malcolm Chene1623652018-08-08 20:27:45 -07001719 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1720 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1721 return;
1722 }
1723
1724 if (VDBG) {
1725 log("notifyPhoneCapabilityChanged: capability=" + capability);
1726 }
1727
1728 synchronized (mRecords) {
1729 mPhoneCapability = capability;
1730
1731 for (Record r : mRecords) {
1732 if (r.matchPhoneStateListenerEvent(
1733 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1734 try {
1735 r.callback.onPhoneCapabilityChanged(capability);
1736 } catch (RemoteException ex) {
1737 mRemoveList.add(r.binder);
1738 }
1739 }
1740 }
1741 handleRemoveListLocked();
1742 }
1743 }
1744
Malcolm Chen026451d2019-02-14 19:50:19 -08001745 public void notifyActiveDataSubIdChanged(int activeDataSubId) {
1746 if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001747 return;
1748 }
1749
1750 if (VDBG) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001751 log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001752 }
1753
1754 synchronized (mRecords) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001755 mActiveDataSubId = activeDataSubId;
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001756
1757 for (Record r : mRecords) {
1758 if (r.matchPhoneStateListenerEvent(
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -08001759 PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE)) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001760 try {
Malcolm Chen026451d2019-02-14 19:50:19 -08001761 r.callback.onActiveDataSubIdChanged(activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001762 } catch (RemoteException ex) {
1763 mRemoveList.add(r.binder);
1764 }
1765 }
1766 }
1767 handleRemoveListLocked();
1768 }
1769 }
Malcolm Chene1623652018-08-08 20:27:45 -07001770
Chen Xu7395c632018-10-17 17:53:47 +00001771 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1772 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1773 return;
1774 }
1775
1776 if (VDBG) {
1777 log("notifyRadioPowerStateChanged: state= " + state);
1778 }
1779
1780 synchronized (mRecords) {
1781 mRadioPowerState = state;
1782
1783 for (Record r : mRecords) {
1784 if (r.matchPhoneStateListenerEvent(
1785 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1786 try {
1787 r.callback.onRadioPowerStateChanged(state);
1788 } catch (RemoteException ex) {
1789 mRemoveList.add(r.binder);
1790 }
1791 }
1792 }
1793 handleRemoveListLocked();
1794 }
1795 }
1796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 @Override
sqian9f93a122018-12-03 22:40:41 -08001798 public void notifyEmergencyNumberList() {
1799 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1800 return;
1801 }
1802
1803 synchronized (mRecords) {
sqianb0ae02b2018-12-14 21:47:49 -08001804 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1805 Context.TELEPHONY_SERVICE);
sqian613c3d52019-02-22 15:54:47 -08001806 mEmergencyNumberList = tm.getEmergencyNumberList();
sqian9f93a122018-12-03 22:40:41 -08001807
1808 for (Record r : mRecords) {
1809 if (r.matchPhoneStateListenerEvent(
1810 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)) {
1811 try {
1812 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1813 if (VDBG) {
1814 log("notifyEmergencyNumberList: emergencyNumberList= "
1815 + mEmergencyNumberList);
1816 }
1817 } catch (RemoteException ex) {
1818 mRemoveList.add(r.binder);
1819 }
1820 }
1821 }
1822 handleRemoveListLocked();
1823 }
sqianbdc5a732018-10-26 13:27:51 -07001824 }
1825
Jordan Liu8218ddd2018-11-28 11:22:39 -08001826 @Override
Jordan Liu65ed9d92019-02-19 14:42:07 -08001827 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId,
1828 int callNetworkType) {
Jordan Liu8218ddd2018-11-28 11:22:39 -08001829 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
1830 return;
1831 }
1832
1833 // merge CallQuality with PreciseCallState and network type
1834 mCallQuality = callQuality;
Jordan Liu65ed9d92019-02-19 14:42:07 -08001835 mCallNetworkType = callNetworkType;
1836 mCallAttributes = new CallAttributes(mPreciseCallState, callNetworkType, callQuality);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001837
1838 synchronized (mRecords) {
1839 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1840 Context.TELEPHONY_SERVICE);
1841
1842 for (Record r : mRecords) {
1843 if (r.matchPhoneStateListenerEvent(
1844 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1845 try {
1846 r.callback.onCallAttributesChanged(mCallAttributes);
1847 } catch (RemoteException ex) {
1848 mRemoveList.add(r.binder);
1849 }
1850 }
1851 }
1852 handleRemoveListLocked();
1853 }
1854 }
1855
sqianbdc5a732018-10-26 13:27:51 -07001856
1857 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001858 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1859 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1860
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001861 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001864 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001866 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301867 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001868 pw.println("Phone Id=" + i);
1869 pw.increaseIndent();
1870 pw.println("mCallState=" + mCallState[i]);
1871 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1872 pw.println("mServiceState=" + mServiceState[i]);
1873 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1874 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001875 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001876 pw.println("mSignalStrength=" + mSignalStrength[i]);
1877 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1878 pw.println("mCallForwarding=" + mCallForwarding[i]);
1879 pw.println("mDataActivity=" + mDataActivity[i]);
1880 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001881 pw.println("mCellLocation=" + mCellLocation[i]);
1882 pw.println("mCellInfo=" + mCellInfo.get(i));
chen xu6ac5fc12019-01-24 14:14:13 -08001883 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i).toString());
Jack Yud19b6ae2017-04-05 14:12:09 -07001884 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301885 }
Jordan Liu65ed9d92019-02-19 14:42:07 -08001886 pw.println("mCallNetworkType=" + mCallNetworkType);
Jack Yud19b6ae2017-04-05 14:12:09 -07001887 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1888 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu6a942d482018-12-12 19:59:30 -08001889 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1890 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001891 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1892 pw.println("mRingingCallState=" + mRingingCallState);
1893 pw.println("mForegroundCallState=" + mForegroundCallState);
1894 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001895 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chene1623652018-08-08 20:27:45 -07001896 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen026451d2019-02-14 19:50:19 -08001897 pw.println("mActiveDataSubId=" + mActiveDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00001898 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian9f93a122018-12-03 22:40:41 -08001899 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001900 pw.println("mCallQuality=" + mCallQuality);
1901 pw.println("mCallAttributes=" + mCallAttributes);
Jack Yud19b6ae2017-04-05 14:12:09 -07001902
1903 pw.decreaseIndent();
1904
1905 pw.println("local logs:");
1906 pw.increaseIndent();
1907 mLocalLog.dump(fd, pw, args);
1908 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001909 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001910 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001911 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001912 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001914 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001915 }
1916 }
1917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 //
1919 // the legacy intent broadcasting
1920 //
1921
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001922 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001923 long ident = Binder.clearCallingIdentity();
1924 try {
1925 mBatteryStats.notePhoneState(state.getState());
1926 } catch (RemoteException re) {
1927 // Can't do much
1928 } finally {
1929 Binder.restoreCallingIdentity(ident);
1930 }
1931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001933 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 Bundle data = new Bundle();
1935 state.fillInNotifierBundle(data);
1936 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001937 // Pass the subscription along with the intent.
1938 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001939 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001940 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001941 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 }
1943
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001944 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1945 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001946 long ident = Binder.clearCallingIdentity();
1947 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001948 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001949 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001950 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001951 } finally {
1952 Binder.restoreCallingIdentity(ident);
1953 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001956 Bundle data = new Bundle();
1957 signalStrength.fillInNotifierBundle(data);
1958 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001959 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001960 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001961 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 }
1963
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001964 /**
1965 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1966 * a valid subId, in which case this function fires a subId-specific intent, or it
1967 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1968 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1969 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001970 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1971 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 long ident = Binder.clearCallingIdentity();
1973 try {
1974 if (state == TelephonyManager.CALL_STATE_IDLE) {
1975 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001976 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1977 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 } else {
1979 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001980 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1981 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 }
1983 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001984 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 } finally {
1986 Binder.restoreCallingIdentity(ident);
1987 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001990 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001991 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001992
1993 // If a valid subId was specified, we should fire off a subId-specific state
1994 // change intent and include the subId.
1995 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1996 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1997 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001998 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001999 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002000 // If the phoneId is invalid, the broadcast is for overall call state.
2001 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
2002 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
2003 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002004
Brad Ebinger51de96a2017-04-21 17:05:18 -07002005 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
2006 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
2007
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002008 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002009 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002010 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2011
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002012 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2013 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002014 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002015 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002016 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002017 android.Manifest.permission.READ_PHONE_STATE,
2018 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002019 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2020 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2021 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022 }
2023
Jack Yu4d1c9452019-01-02 16:51:08 -08002024 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2025 String apnType, LinkProperties linkProperties,
2026 NetworkCapabilities networkCapabilities,
2027 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002028 // Note: not reporting to the battery stats service here, because the
2029 // status bar takes care of that after taking into account all of the
2030 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002032 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002033 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07002034 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002035 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002037 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002038 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002039 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002040 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002041 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002042 }
2043 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002044 if (networkCapabilities != null) {
2045 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002046 }
Wink Savillea639b312012-07-10 12:37:54 -07002047 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002048
Wink Savillea639b312012-07-10 12:37:54 -07002049 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2050 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002051 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002052 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 }
2054
Jack Yu4d1c9452019-01-02 16:51:08 -08002055 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002057 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002058 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002059 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002061
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002062 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yu4d1c9452019-01-02 16:51:08 -08002063 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002064 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2065 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2066 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2067 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002068 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2069 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2070 }
2071
2072 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu16e24cd2018-12-11 18:09:41 -08002073 String apnType, String apn, LinkProperties linkProperties,
2074 @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002075 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2076 intent.putExtra(PhoneConstants.STATE_KEY, state);
2077 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002078 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2079 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002080 if (linkProperties != null) {
Jack Yu4d1c9452019-01-02 16:51:08 -08002081 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002082 }
chen xu16e24cd2018-12-11 18:09:41 -08002083 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002084
2085 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2086 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2087 }
2088
Andrew Flynnceaed682015-06-09 12:36:58 +00002089 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002090 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002091 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002092 }
2093
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002094 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2095 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002096 }
2097
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002098 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002099 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002100 return true;
2101 }
2102 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002103 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002104 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002105 return false;
2106 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002107
Andrew Flynn1f452642015-04-14 22:16:04 -04002108 private boolean checkNotifyPermission() {
2109 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2110 == PackageManager.PERMISSION_GRANTED;
2111 }
2112
Jeff Davidson29da89f2018-02-28 17:50:16 -08002113 private boolean checkListenerPermission(
2114 int events, int subId, String callingPackage, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002115 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2116 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2117 .setCallingPackage(callingPackage)
2118 .setMethod(message + " events: " + events)
2119 .setCallingPid(Binder.getCallingPid())
2120 .setCallingUid(Binder.getCallingUid());
2121
2122 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002123 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002124 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2125 shouldCheckLocationPermissions = true;
2126 }
2127
2128 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2129 // Everything that requires fine location started in Q. So far...
2130 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2131 shouldCheckLocationPermissions = true;
2132 }
2133
2134 if (shouldCheckLocationPermissions) {
2135 LocationAccessPolicy.LocationPermissionResult result =
2136 LocationAccessPolicy.checkLocationPermission(
2137 mContext, locationQueryBuilder.build());
2138 switch (result) {
2139 case DENIED_HARD:
2140 throw new SecurityException("Unable to listen for events " + events + " due to "
2141 + "insufficient location permissions.");
2142 case DENIED_SOFT:
2143 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002144 }
John Wang963db55d2012-03-30 16:04:06 -07002145 }
2146
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002147 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2149 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002150 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002151 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002152 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002153
2154 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2155 mContext.enforceCallingOrSelfPermission(
2156 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002157 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002158
Shuo Qian066e8652018-04-25 21:02:35 +00002159 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2160 mContext.enforceCallingOrSelfPermission(
2161 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2162 }
2163
Brad Ebingerefed9822018-10-26 10:25:57 -07002164 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2165 mContext.enforceCallingOrSelfPermission(
2166 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2167 }
2168
chen xu6a942d482018-12-12 19:59:30 -08002169 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2170 mContext.enforceCallingOrSelfPermission(
2171 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2172 }
2173
Jordan Liu8218ddd2018-11-28 11:22:39 -08002174 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2175 mContext.enforceCallingOrSelfPermission(
2176 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2177 }
2178
chen xu52797b62019-01-18 13:16:31 -08002179 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2180 mContext.enforceCallingOrSelfPermission(
2181 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2182 }
2183
2184 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2185 mContext.enforceCallingOrSelfPermission(
2186 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2187 }
2188
chen xu6ac5fc12019-01-24 14:14:13 -08002189 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2190 mContext.enforceCallingOrSelfPermission(
2191 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2192 }
2193
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002194 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002195 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002196
2197 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002198 int size = mRemoveList.size();
2199 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2200 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002201 for (IBinder b: mRemoveList) {
2202 remove(b);
2203 }
2204 mRemoveList.clear();
2205 }
2206 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002207
2208 private boolean validateEventsAndUserLocked(Record r, int events) {
2209 int foregroundUser;
2210 long callingIdentity = Binder.clearCallingIdentity();
2211 boolean valid = false;
2212 try {
2213 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002214 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2215 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002216 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002217 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002218 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002219 + " r.events=" + r.events + " events=" + events);
2220 }
2221 } finally {
2222 Binder.restoreCallingIdentity(callingIdentity);
2223 }
2224 return valid;
2225 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002226
2227 private boolean validatePhoneId(int phoneId) {
2228 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002229 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002230 return valid;
2231 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002232
2233 private static void log(String s) {
2234 Rlog.d(TAG, s);
2235 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002236
xinhe8b79fb62014-11-05 14:55:03 -08002237 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002238
2239 if(subId < 0) {
2240 // Invalid case, we need compare phoneId with default one.
2241 return (mDefaultPhoneId == phoneId);
2242 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002243 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002244 return (subId == mDefaultSubId);
2245 } else {
2246 return (rSubId == subId);
2247 }
2248 }
2249
Hall Liuee313732018-11-27 14:36:51 -08002250 private boolean checkFineLocationAccess(Record r, int minSdk) {
2251 LocationAccessPolicy.LocationPermissionQuery query =
2252 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2253 .setCallingPackage(r.callingPackage)
2254 .setCallingPid(r.callerPid)
2255 .setCallingUid(r.callerUid)
2256 .setMethod("TelephonyRegistry push")
2257 .setMinSdkVersionForFine(minSdk)
2258 .build();
2259
2260 return Binder.withCleanCallingIdentity(() -> {
2261 LocationAccessPolicy.LocationPermissionResult locationResult =
2262 LocationAccessPolicy.checkLocationPermission(mContext, query);
2263 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2264 });
2265 }
2266
2267 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2268 LocationAccessPolicy.LocationPermissionQuery query =
2269 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2270 .setCallingPackage(r.callingPackage)
2271 .setCallingPid(r.callerPid)
2272 .setCallingUid(r.callerUid)
2273 .setMethod("TelephonyRegistry push")
2274 .setMinSdkVersionForCoarse(minSdk)
2275 .build();
2276
2277 return Binder.withCleanCallingIdentity(() -> {
2278 LocationAccessPolicy.LocationPermissionResult locationResult =
2279 LocationAccessPolicy.checkLocationPermission(mContext, query);
2280 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2281 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002282 }
2283
xinhee9f16402014-09-25 16:39:28 -07002284 private void checkPossibleMissNotify(Record r, int phoneId) {
2285 int events = r.events;
2286
2287 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2288 try {
2289 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2290 mServiceState[phoneId]);
2291 r.callback.onServiceStateChanged(
2292 new ServiceState(mServiceState[phoneId]));
2293 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002294 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002295 }
2296 }
2297
2298 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2299 try {
2300 SignalStrength signalStrength = mSignalStrength[phoneId];
2301 if (DBG) {
2302 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2303 }
2304 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2305 } catch (RemoteException ex) {
2306 mRemoveList.add(r.binder);
2307 }
2308 }
2309
2310 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2311 try {
2312 int gsmSignalStrength = mSignalStrength[phoneId]
2313 .getGsmSignalStrength();
2314 if (DBG) {
2315 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2316 gsmSignalStrength);
2317 }
2318 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2319 : gsmSignalStrength));
2320 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002321 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002322 }
2323 }
2324
2325 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2326 try {
2327 if (DBG_LOC) {
2328 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2329 + mCellInfo.get(phoneId));
2330 }
Hall Liuee313732018-11-27 14:36:51 -08002331 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002332 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2333 }
xinhee9f16402014-09-25 16:39:28 -07002334 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002335 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002336 }
2337 }
2338
zxuan35a47022018-01-04 11:24:04 -08002339 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2340 try {
2341 if (VDBG) {
2342 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2343 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2344 }
2345 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2346 } catch (RemoteException ex) {
2347 mRemoveList.add(r.binder);
2348 }
2349 }
2350
xinhee9f16402014-09-25 16:39:28 -07002351 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2352 try {
2353 if (VDBG) {
2354 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2355 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2356 }
2357 r.callback.onMessageWaitingIndicatorChanged(
2358 mMessageWaiting[phoneId]);
2359 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002360 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002361 }
2362 }
2363
2364 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2365 try {
2366 if (VDBG) {
2367 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2368 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2369 }
2370 r.callback.onCallForwardingIndicatorChanged(
2371 mCallForwarding[phoneId]);
2372 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002373 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002374 }
2375 }
2376
2377 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2378 try {
2379 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2380 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002381 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002382 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2383 }
xinhee9f16402014-09-25 16:39:28 -07002384 } catch (RemoteException ex) {
2385 mRemoveList.add(r.binder);
2386 }
2387 }
2388
2389 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2390 try {
2391 if (DBG) {
2392 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2393 + "=" + mDataConnectionState[phoneId]
2394 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2395 + ")");
2396 }
2397 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2398 mDataConnectionNetworkType[phoneId]);
2399 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002400 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002401 }
2402 }
2403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404}