blob: 447ed59a775ef784dcdc498f51c79c88114227fe [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;
Chen Xu7631ff72019-09-26 16:11:59 -070036import android.telephony.Annotation.DataFailureCause;
37import android.telephony.Annotation.RadioPowerState;
38import android.telephony.Annotation.SrvccState;
Jordan Liu8218ddd2018-11-28 11:22:39 -080039import android.telephony.CallAttributes;
40import android.telephony.CallQuality;
John Wang963db55d2012-03-30 16:04:06 -070041import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070042import android.telephony.CellLocation;
chen xu16e24cd2018-12-11 18:09:41 -080043import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020044import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080045import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070046import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070047import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080048import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020049import android.telephony.PreciseCallState;
50import android.telephony.PreciseDataConnectionState;
51import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070052import android.telephony.Rlog;
53import android.telephony.ServiceState;
54import android.telephony.SignalStrength;
55import android.telephony.SubscriptionManager;
56import android.telephony.TelephonyManager;
chen xu16e24cd2018-12-11 18:09:41 -080057import android.telephony.data.ApnSetting;
sqianbdc5a732018-10-26 13:27:51 -070058import android.telephony.emergency.EmergencyNumber;
chen xu6ac5fc12019-01-24 14:14:13 -080059import android.telephony.ims.ImsReasonInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070060import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070061import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070063import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080065import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070067import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080068import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070069import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080071import com.android.internal.telephony.TelephonyPermissions;
chen xubadf2b02019-04-26 17:45:26 -070072import com.android.internal.util.ArrayUtils;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060073import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070074import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import com.android.server.am.BatteryStatsService;
76
Jack Yud19b6ae2017-04-05 14:12:09 -070077import java.io.FileDescriptor;
78import java.io.PrintWriter;
79import java.util.ArrayList;
chen xu5b98d402019-03-22 16:56:34 -070080import java.util.Arrays;
sqian9f93a122018-12-03 22:40:41 -080081import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070082import java.util.List;
sqian9f93a122018-12-03 22:40:41 -080083import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080084import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086/**
Wink Savillee9b06d72009-05-18 21:47:50 -070087 * Since phone process can be restarted, this class provides a centralized place
88 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070089 *
90 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
91 * and 15973975 by saving the phoneId of the registrant and then using the
92 * phoneId when deciding to to make a callback. This is necessary because
93 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070094 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070095 * the dummy value conversion we properly do the callbacks.
96 *
97 * Eventually we may want to remove the notion of dummy value but for now this
98 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700100@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
101public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -0700103 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -0700104 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -0700105 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106
107 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800108 Context context;
109
Svet Ganov16a16892015-04-16 10:32:04 -0700110 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -0700111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700113
Malcolm Chenabbfac22018-02-12 19:15:59 -0800114 TelephonyRegistryDeathRecipient deathRecipient;
115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800117 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700118 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700119
Hall Liu5fb337f2017-11-22 17:38:15 -0800120 int callerUid;
121 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700124
Wink Savilled09c4ca2014-11-22 10:08:16 -0800125 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700126
Wink Savilled09c4ca2014-11-22 10:08:16 -0800127 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800128
129 boolean matchPhoneStateListenerEvent(int events) {
130 return (callback != null) && ((events & this.events) != 0);
131 }
132
Wink Savilled09c4ca2014-11-22 10:08:16 -0800133 boolean matchOnSubscriptionsChangedListener() {
134 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800135 }
Wink Savillee380b982014-07-26 18:24:22 -0700136
Malcolm Chen13f31af2018-09-04 22:12:31 -0700137 boolean matchOnOpportunisticSubscriptionsChangedListener() {
138 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
139 }
140
Tyler Gunnf955e562018-04-26 14:43:31 -0700141 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800142 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700143 return TelephonyPermissions.checkReadCallLog(
144 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800145 } catch (SecurityException e) {
146 return false;
147 }
148 }
149
Wink Savillea12a7b32012-09-20 10:09:45 -0700150 @Override
151 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700152 return "{callingPackage=" + callingPackage + " binder=" + binder
153 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800154 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700155 + onSubscriptionsChangedListenerCallback
156 + " onOpportunisticSubscriptionsChangedListenererCallback="
157 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800158 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800159 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 }
162
163 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700164
Joe Onorato163d8d92010-10-21 13:21:20 -0400165 // access should be inside synchronized (mRecords) for these two fields
166 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
167 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 private final IBatteryStats mBatteryStats;
170
Svet Ganov16a16892015-04-16 10:32:04 -0700171 private final AppOpsManager mAppOps;
172
Malcolm Chen13f31af2018-09-04 22:12:31 -0700173 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
174
175 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700180
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700182
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700184
fionaxu12312f62016-11-14 13:32:14 -0800185 private int[] mVoiceActivationState;
186
187 private int[] mDataActivationState;
188
zxuan35a47022018-01-04 11:24:04 -0800189 private boolean[] mUserMobileDataState;
190
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700192
Wink Savillefb40dd42014-06-12 17:02:31 -0700193 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700194
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700196
Wink Savillefb40dd42014-06-12 17:02:31 -0700197 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700198
Jack Yub1bac542018-03-14 16:23:38 -0700199 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700200 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700201
Wink Savillefb40dd42014-06-12 17:02:31 -0700202 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203
Wink Savillefb40dd42014-06-12 17:02:31 -0700204 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700205
chen xud5deeb12019-04-29 13:57:42 -0700206 private int[] mOtaspMode;
Wink Savillefd2d0132010-10-28 14:22:26 -0700207
Wink Savillefb40dd42014-06-12 17:02:31 -0700208 private ArrayList<List<CellInfo>> mCellInfo = null;
209
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800210 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
211
sqian9f93a122018-12-03 22:40:41 -0800212 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
213
Shuo Qianb61230c2019-09-12 17:00:31 -0700214 private EmergencyNumber[] mOutgoingSmsEmergencyNumber;
215
216 private EmergencyNumber[] mOutgoingCallEmergencyNumber;
217
chen xud5deeb12019-04-29 13:57:42 -0700218 private CallQuality[] mCallQuality;
Jordan Liu8218ddd2018-11-28 11:22:39 -0800219
chen xud5deeb12019-04-29 13:57:42 -0700220 private CallAttributes[] mCallAttributes;
Jordan Liu8218ddd2018-11-28 11:22:39 -0800221
Jordan Liu65ed9d92019-02-19 14:42:07 -0800222 // network type of the call associated with the mCallAttributes and mCallQuality
chen xud5deeb12019-04-29 13:57:42 -0700223 private int[] mCallNetworkType;
Jordan Liu65ed9d92019-02-19 14:42:07 -0800224
Brad Ebingerefed9822018-10-26 10:25:57 -0700225 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700226
Wink Savilled09c4ca2014-11-22 10:08:16 -0800227 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700228
Wink Savilled09c4ca2014-11-22 10:08:16 -0800229 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700230
chen xud5deeb12019-04-29 13:57:42 -0700231 private int[] mRingingCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200232
chen xud5deeb12019-04-29 13:57:42 -0700233 private int[] mForegroundCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200234
chen xud5deeb12019-04-29 13:57:42 -0700235 private int[] mBackgroundCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200236
chen xud5deeb12019-04-29 13:57:42 -0700237 private PreciseCallState[] mPreciseCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200238
chen xud5deeb12019-04-29 13:57:42 -0700239 private int[] mCallDisconnectCause;
chen xu6a942d482018-12-12 19:59:30 -0800240
chen xu6ac5fc12019-01-24 14:14:13 -0800241 private List<ImsReasonInfo> mImsReasonInfo = null;
242
chen xud5deeb12019-04-29 13:57:42 -0700243 private int[] mCallPreciseDisconnectCause;
chen xu6a942d482018-12-12 19:59:30 -0800244
Andrew Flynn1f452642015-04-14 22:16:04 -0400245 private boolean mCarrierNetworkChangeState = false;
246
Malcolm Chene1623652018-08-08 20:27:45 -0700247 private PhoneCapability mPhoneCapability = null;
248
Malcolm Chen026451d2019-02-14 19:50:19 -0800249 private int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700250
Chen Xu7631ff72019-09-26 16:11:59 -0700251 @RadioPowerState
Chen Xu7395c632018-10-17 17:53:47 +0000252 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
253
Jack Yud19b6ae2017-04-05 14:12:09 -0700254 private final LocalLog mLocalLog = new LocalLog(100);
255
Jack Yu0c92c232019-04-04 15:10:17 -0700256 private final LocalLog mListenLog = new LocalLog(100);
257
chen xud5deeb12019-04-29 13:57:42 -0700258 private PreciseDataConnectionState[] mPreciseDataConnectionState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200259
Hall Liuee313732018-11-27 14:36:51 -0800260 // Nothing here yet, but putting it here in case we want to add more in the future.
261 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = 0;
262
263 static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK =
Hall Liu70bbc162018-03-02 17:44:46 -0800264 PhoneStateListener.LISTEN_CELL_LOCATION
265 | PhoneStateListener.LISTEN_CELL_INFO;
266
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700267 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian9f93a122018-12-03 22:40:41 -0800268 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
269 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
sqian9e9ed182019-03-20 16:17:09 -0700270 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700271
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200272 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
273 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
274 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
275
Shuo Qianb61230c2019-09-12 17:00:31 -0700276 static final int READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK =
Shuo Qiand9663762019-10-04 13:20:45 -0700277 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL
278 | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS;
Shuo Qianb61230c2019-09-12 17:00:31 -0700279
Wink Savillea12a7b32012-09-20 10:09:45 -0700280 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700281 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700282
283 private final Handler mHandler = new Handler() {
284 @Override
285 public void handleMessage(Message msg) {
286 switch (msg.what) {
287 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700288 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700289 int numPhones = TelephonyManager.getDefault().getPhoneCount();
290 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700291 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700292 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700293 }
294 break;
295 }
xinhee9f16402014-09-25 16:39:28 -0700296 case MSG_UPDATE_DEFAULT_SUB: {
297 int newDefaultPhoneId = msg.arg1;
Taesu Leec955cd92019-09-23 08:06:31 +0900298 int newDefaultSubId = msg.arg2;
xinhee9f16402014-09-25 16:39:28 -0700299 if (VDBG) {
300 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
Taesu Leec955cd92019-09-23 08:06:31 +0900301 + " current mDefaultPhoneId=" + mDefaultPhoneId
302 + " newDefaultSubId=" + newDefaultSubId
303 + " newDefaultPhoneId=" + newDefaultPhoneId);
xinhee9f16402014-09-25 16:39:28 -0700304 }
305
306 //Due to possible risk condition,(notify call back using the new
307 //defaultSubId comes before new defaultSubId update) we need to recall all
308 //possible missed notify callback
309 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700310 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800311 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700312 checkPossibleMissNotify(r, newDefaultPhoneId);
313 }
314 }
315 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700316 }
317 mDefaultSubId = newDefaultSubId;
318 mDefaultPhoneId = newDefaultPhoneId;
Jack Yu0c92c232019-04-04 15:10:17 -0700319 mLocalLog.log("Default subscription updated: mDefaultPhoneId="
Taesu Leec955cd92019-09-23 08:06:31 +0900320 + mDefaultPhoneId + ", mDefaultSubId=" + mDefaultSubId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700321 }
322 }
323 }
324 };
325
Malcolm Chenabbfac22018-02-12 19:15:59 -0800326 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
327
328 private final IBinder binder;
329
330 TelephonyRegistryDeathRecipient(IBinder binder) {
331 this.binder = binder;
332 }
333
334 @Override
335 public void binderDied() {
336 if (DBG) log("binderDied " + binder);
337 remove(binder);
338 }
339 }
340
Wink Savillea12a7b32012-09-20 10:09:45 -0700341 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
342 @Override
343 public void onReceive(Context context, Intent intent) {
344 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700345 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700346 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700347 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700348 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700349 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Taesu Leec955cd92019-09-23 08:06:31 +0900350 } else if (action.equals(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
351 int newDefaultSubId = intent.getIntExtra(
352 SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
353 SubscriptionManager.getDefaultSubscriptionId());
354 int newDefaultPhoneId = intent.getIntExtra(
355 PhoneConstants.PHONE_KEY,
356 SubscriptionManager.getPhoneId(newDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700357 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700358 log("onReceive:current mDefaultSubId=" + mDefaultSubId
Taesu Leec955cd92019-09-23 08:06:31 +0900359 + " current mDefaultPhoneId=" + mDefaultPhoneId
360 + " newDefaultSubId=" + newDefaultSubId
361 + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700362 }
xinhee9f16402014-09-25 16:39:28 -0700363
Taesu Leec955cd92019-09-23 08:06:31 +0900364 if (validatePhoneId(newDefaultPhoneId)
365 && (newDefaultSubId != mDefaultSubId
366 || newDefaultPhoneId != mDefaultPhoneId)) {
xinhee9f16402014-09-25 16:39:28 -0700367 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
Taesu Leec955cd92019-09-23 08:06:31 +0900368 newDefaultPhoneId, newDefaultSubId));
xinhee9f16402014-09-25 16:39:28 -0700369 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700370 }
371 }
372 };
373
Wink Savillee9b06d72009-05-18 21:47:50 -0700374 // we keep a copy of all of the state so we can send it out when folks
375 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700377 // In these calls we call with the lock held. This is safe becasuse remote
378 // calls go through a oneway interface and local calls going through a
379 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700381 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
382 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700383 CellLocation location = CellLocation.getEmpty();
384
Wink Savillefb40dd42014-06-12 17:02:31 -0700385 mContext = context;
386 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700387
Malcolm Chen387dc0e2019-10-08 18:11:22 -0700388 int numPhones = TelephonyManager.getDefault().getSupportedModemCount();
Jack Yub1bac542018-03-14 16:23:38 -0700389 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700390 mNumPhones = numPhones;
391 mCallState = new int[numPhones];
392 mDataActivity = new int[numPhones];
393 mDataConnectionState = new int[numPhones];
394 mDataConnectionNetworkType = new int[numPhones];
395 mCallIncomingNumber = new String[numPhones];
396 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800397 mVoiceActivationState = new int[numPhones];
398 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800399 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700400 mSignalStrength = new SignalStrength[numPhones];
401 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700402 mCallForwarding = new boolean[numPhones];
403 mCellLocation = new Bundle[numPhones];
Brad Ebingerefed9822018-10-26 10:25:57 -0700404 mSrvccState = new int[numPhones];
chen xud5deeb12019-04-29 13:57:42 -0700405 mOtaspMode = new int[numPhones];
406 mPreciseCallState = new PreciseCallState[numPhones];
407 mForegroundCallState = new int[numPhones];
408 mBackgroundCallState = new int[numPhones];
409 mRingingCallState = new int[numPhones];
410 mCallDisconnectCause = new int[numPhones];
411 mCallPreciseDisconnectCause = new int[numPhones];
412 mCallQuality = new CallQuality[numPhones];
413 mCallNetworkType = new int[numPhones];
414 mCallAttributes = new CallAttributes[numPhones];
415 mPreciseDataConnectionState = new PreciseDataConnectionState[numPhones];
416 mCellInfo = new ArrayList<>();
417 mImsReasonInfo = new ArrayList<>();
418 mPhysicalChannelConfigs = new ArrayList<>();
sqian9f93a122018-12-03 22:40:41 -0800419 mEmergencyNumberList = new HashMap<>();
Shuo Qianb61230c2019-09-12 17:00:31 -0700420 mOutgoingCallEmergencyNumber = new EmergencyNumber[numPhones];
421 mOutgoingSmsEmergencyNumber = new EmergencyNumber[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700422 for (int i = 0; i < numPhones; i++) {
423 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
424 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
425 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800426 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
427 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700428 mCallIncomingNumber[i] = "";
429 mServiceState[i] = new ServiceState();
430 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800431 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700432 mMessageWaiting[i] = false;
433 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700434 mCellLocation[i] = new Bundle();
435 mCellInfo.add(i, null);
chen xu6ac5fc12019-01-24 14:14:13 -0800436 mImsReasonInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700437 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
chen xud5deeb12019-04-29 13:57:42 -0700438 mPhysicalChannelConfigs.add(i, new ArrayList<>());
439 mOtaspMode[i] = TelephonyManager.OTASP_UNKNOWN;
440 mCallDisconnectCause[i] = DisconnectCause.NOT_VALID;
441 mCallPreciseDisconnectCause[i] = PreciseDisconnectCause.NOT_VALID;
442 mCallQuality[i] = new CallQuality();
443 mCallAttributes[i] = new CallAttributes(new PreciseCallState(),
444 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
445 mCallNetworkType[i] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
446 mPreciseCallState[i] = new PreciseCallState();
447 mRingingCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
448 mForegroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
449 mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
450 mPreciseDataConnectionState[i] = new PreciseDataConnectionState();
Wink Savillefb40dd42014-06-12 17:02:31 -0700451 }
452
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700453 // Note that location can be null for non-phone builds like
454 // like the generic one.
455 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700456 for (int i = 0; i < numPhones; i++) {
457 location.fillInNotifierBundle(mCellLocation[i]);
458 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700459 }
Svet Ganov16a16892015-04-16 10:32:04 -0700460
461 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463
Svetoslav Ganova0027152013-06-25 14:59:53 -0700464 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700465 // Watch for interesting updates
466 final IntentFilter filter = new IntentFilter();
467 filter.addAction(Intent.ACTION_USER_SWITCHED);
468 filter.addAction(Intent.ACTION_USER_REMOVED);
Taesu Leec955cd92019-09-23 08:06:31 +0900469 filter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700470 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700471 mContext.registerReceiver(mBroadcastReceiver, filter);
472 }
473
474 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700475 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800476 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700477 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800478 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800479 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700480 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
481 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800482 + " callback.asBinder=" + callback.asBinder());
483 }
484
Wink Savilled09c4ca2014-11-22 10:08:16 -0800485 synchronized (mRecords) {
486 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800487 IBinder b = callback.asBinder();
488 Record r = add(b);
489
490 if (r == null) {
491 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800492 }
493
Jeff Davidson29da89f2018-02-28 17:50:16 -0800494 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800495 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700496 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800497 r.callerUid = Binder.getCallingUid();
498 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800499 r.events = 0;
500 if (DBG) {
501 log("listen oscl: Register r=" + r);
502 }
503 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700504 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800505 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800506 if (VDBG) log("listen oscl: send to r=" + r);
507 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
508 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800509 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800510 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800511 remove(r.binder);
512 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800513 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700514 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800515 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800516 }
517 }
518
519 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800520 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800521 IOnSubscriptionsChangedListener callback) {
522 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800523 remove(callback.asBinder());
524 }
525
Malcolm Chen13f31af2018-09-04 22:12:31 -0700526
527 @Override
528 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
529 IOnSubscriptionsChangedListener callback) {
530 int callerUserId = UserHandle.getCallingUserId();
531 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
532 if (VDBG) {
533 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
534 + " callerUserId=" + callerUserId + " callback=" + callback
535 + " callback.asBinder=" + callback.asBinder());
536 }
537
538 synchronized (mRecords) {
539 // register
540 IBinder b = callback.asBinder();
541 Record r = add(b);
542
543 if (r == null) {
544 return;
545 }
546
547 r.context = mContext;
548 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
549 r.callingPackage = callingPackage;
550 r.callerUid = Binder.getCallingUid();
551 r.callerPid = Binder.getCallingPid();
552 r.events = 0;
553 if (DBG) {
554 log("listen ooscl: Register r=" + r);
555 }
556 // Always notify when registration occurs if there has been a notification.
557 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
558 try {
559 if (VDBG) log("listen ooscl: send to r=" + r);
560 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
561 if (VDBG) log("listen ooscl: sent to r=" + r);
562 } catch (RemoteException e) {
563 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
564 remove(r.binder);
565 }
566 } else {
567 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
568 }
569 }
570 }
571
Wink Savillea374c3d2014-11-11 11:48:04 -0800572 @Override
573 public void notifySubscriptionInfoChanged() {
574 if (VDBG) log("notifySubscriptionInfoChanged:");
575 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700576 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800577 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
578 + mRecords.size());
579 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700580 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800581 mRemoveList.clear();
582 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800583 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800584 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800585 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
586 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
587 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800588 } catch (RemoteException ex) {
589 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
590 mRemoveList.add(r.binder);
591 }
592 }
593 }
594 handleRemoveListLocked();
595 }
596 }
597
598 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700599 public void notifyOpportunisticSubscriptionInfoChanged() {
600 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
601 synchronized (mRecords) {
602 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
603 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
604 + mRecords.size());
605 }
606 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
607 mRemoveList.clear();
608 for (Record r : mRecords) {
609 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
610 try {
611 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
612 r.onOpportunisticSubscriptionsChangedListenerCallback
613 .onSubscriptionsChanged();
614 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
615 } catch (RemoteException ex) {
616 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
617 mRemoveList.add(r.binder);
618 }
619 }
620 }
621 handleRemoveListLocked();
622 }
623 }
624
625 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
627 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800628 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
629 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700630 }
631
632 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700633 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700634 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700635 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700636 }
637
Svet Ganov16a16892015-04-16 10:32:04 -0700638 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700639 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700640 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800641 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jack Yu0c92c232019-04-04 15:10:17 -0700642 String str = "listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700643 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
Jack Yu0c92c232019-04-04 15:10:17 -0700644 + UserHandle.myUserId() + " callerUserId=" + callerUserId;
645 mListenLog.log(str);
646 if (VDBG) {
647 log(str);
Wink Savillea12a7b32012-09-20 10:09:45 -0700648 }
xinhe75c2c152014-10-16 11:49:45 -0700649
650 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800651 // Checks permission and throws SecurityException for disallowed operations. For pre-M
652 // apps whose runtime permission has been revoked, we return immediately to skip sending
653 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800654 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800655 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700656 }
657
yifan.baie620ce72017-12-22 14:59:57 +0800658 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 synchronized (mRecords) {
660 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800661 IBinder b = callback.asBinder();
662 Record r = add(b);
663
664 if (r == null) {
665 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 }
xinhe43c50292014-09-18 17:56:48 -0700667
Jeff Davidson29da89f2018-02-28 17:50:16 -0800668 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700669 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700670 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800671 r.callerUid = Binder.getCallingUid();
672 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700673 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
674 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800676 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700677 } else {//APP specify subID
678 r.subId = subId;
679 }
yifan.baie620ce72017-12-22 14:59:57 +0800680 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700682 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700683 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700684 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700685 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400687 try {
Wink Savillee380b982014-07-26 18:24:22 -0700688 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800689 ServiceState rawSs = new ServiceState(mServiceState[phoneId]);
690 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
691 r.callback.onServiceStateChanged(rawSs);
692 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
693 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(false));
694 } else {
695 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(true));
696 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400697 } catch (RemoteException ex) {
698 remove(r.binder);
699 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 }
701 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
702 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700703 int gsmSignalStrength = mSignalStrength[phoneId]
704 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700705 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
706 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 } catch (RemoteException ex) {
708 remove(r.binder);
709 }
710 }
711 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
712 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700713 r.callback.onMessageWaitingIndicatorChanged(
714 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 } catch (RemoteException ex) {
716 remove(r.binder);
717 }
718 }
719 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
720 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700721 r.callback.onCallForwardingIndicatorChanged(
722 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 } catch (RemoteException ex) {
724 remove(r.binder);
725 }
726 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700727 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400728 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700729 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700730 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800731 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800732 r.callback.onCellLocationChanged(
733 new Bundle(mCellLocation[phoneId]));
734 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400735 } catch (RemoteException ex) {
736 remove(r.binder);
737 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 }
739 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
740 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700741 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700742 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 } catch (RemoteException ex) {
744 remove(r.binder);
745 }
746 }
747 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
748 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700749 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
750 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 } catch (RemoteException ex) {
752 remove(r.binder);
753 }
754 }
755 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
756 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700757 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 } catch (RemoteException ex) {
759 remove(r.binder);
760 }
761 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700762 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
763 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700764 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700765 } catch (RemoteException ex) {
766 remove(r.binder);
767 }
768 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700769 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
770 try {
chen xud5deeb12019-04-29 13:57:42 -0700771 r.callback.onOtaspChanged(mOtaspMode[phoneId]);
Wink Savillefd2d0132010-10-28 14:22:26 -0700772 } catch (RemoteException ex) {
773 remove(r.binder);
774 }
775 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700776 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700777 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700778 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700779 + mCellInfo.get(phoneId));
Hall Liuee313732018-11-27 14:36:51 -0800780 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800781 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
782 }
John Wang963db55d2012-03-30 16:04:06 -0700783 } catch (RemoteException ex) {
784 remove(r.binder);
785 }
786 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200787 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
788 try {
chen xud5deeb12019-04-29 13:57:42 -0700789 r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200790 } catch (RemoteException ex) {
791 remove(r.binder);
792 }
793 }
chen xu6a942d482018-12-12 19:59:30 -0800794 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
795 try {
chen xud5deeb12019-04-29 13:57:42 -0700796 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId],
797 mCallPreciseDisconnectCause[phoneId]);
chen xu6a942d482018-12-12 19:59:30 -0800798 } catch (RemoteException ex) {
799 remove(r.binder);
800 }
801 }
chen xu6ac5fc12019-01-24 14:14:13 -0800802 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
803 try {
804 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
805 } catch (RemoteException ex) {
806 remove(r.binder);
807 }
808 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200809 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
810 try {
811 r.callback.onPreciseDataConnectionStateChanged(
chen xud5deeb12019-04-29 13:57:42 -0700812 mPreciseDataConnectionState[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200813 } catch (RemoteException ex) {
814 remove(r.binder);
815 }
816 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400817 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
818 try {
819 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
820 } catch (RemoteException ex) {
821 remove(r.binder);
822 }
823 }
fionaxu12312f62016-11-14 13:32:14 -0800824 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
825 try {
826 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
827 } catch (RemoteException ex) {
828 remove(r.binder);
829 }
830 }
831 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
832 try {
833 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
834 } catch (RemoteException ex) {
835 remove(r.binder);
836 }
837 }
zxuan35a47022018-01-04 11:24:04 -0800838 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
839 try {
840 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
841 } catch (RemoteException ex) {
842 remove(r.binder);
843 }
844 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800845 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
846 try {
847 r.callback.onPhysicalChannelConfigurationChanged(
848 mPhysicalChannelConfigs.get(phoneId));
849 } catch (RemoteException ex) {
850 remove(r.binder);
851 }
852 }
sqian9f93a122018-12-03 22:40:41 -0800853 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
854 try {
855 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
856 } catch (RemoteException ex) {
857 remove(r.binder);
858 }
859 }
Malcolm Chene1623652018-08-08 20:27:45 -0700860 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
861 try {
862 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
863 } catch (RemoteException ex) {
864 remove(r.binder);
865 }
866 }
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800867 if ((events & PhoneStateListener
Malcolm Chen118b02f2019-09-04 16:10:34 -0700868 .LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700869 try {
Malcolm Chen026451d2019-02-14 19:50:19 -0800870 r.callback.onActiveDataSubIdChanged(mActiveDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700871 } catch (RemoteException ex) {
872 remove(r.binder);
873 }
874 }
Chen Xu7395c632018-10-17 17:53:47 +0000875 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
876 try {
877 r.callback.onRadioPowerStateChanged(mRadioPowerState);
878 } catch (RemoteException ex) {
879 remove(r.binder);
880 }
881 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700882 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
883 try {
884 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
885 } catch (RemoteException ex) {
886 remove(r.binder);
887 }
888 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800889 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
890 try {
chen xud5deeb12019-04-29 13:57:42 -0700891 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
Jordan Liu8218ddd2018-11-28 11:22:39 -0800892 } catch (RemoteException ex) {
893 remove(r.binder);
894 }
895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 }
897 }
898 } else {
xinhe75c2c152014-10-16 11:49:45 -0700899 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 remove(callback.asBinder());
901 }
902 }
903
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700904 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700905 // Only reveal the incoming number if the record has read call log permission.
906 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700907 }
908
Malcolm Chenabbfac22018-02-12 19:15:59 -0800909 private Record add(IBinder binder) {
910 Record r;
911
912 synchronized (mRecords) {
913 final int N = mRecords.size();
914 for (int i = 0; i < N; i++) {
915 r = mRecords.get(i);
916 if (binder == r.binder) {
917 // Already existed.
918 return r;
919 }
920 }
921 r = new Record();
922 r.binder = binder;
923 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
924
925 try {
926 binder.linkToDeath(r.deathRecipient, 0);
927 } catch (RemoteException e) {
928 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
929 // Binder already died. Return null.
930 return null;
931 }
932
933 mRecords.add(r);
934 if (DBG) log("add new record");
935 }
936
937 return r;
938 }
939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 private void remove(IBinder binder) {
941 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700942 final int recordCount = mRecords.size();
943 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800944 Record r = mRecords.get(i);
945 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800946 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800947 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
948 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800949 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800950
951 if (r.deathRecipient != null) {
952 try {
953 binder.unlinkToDeath(r.deathRecipient, 0);
954 } catch (NoSuchElementException e) {
955 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
956 + r + " e=" + e);
957 }
958 }
959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 mRecords.remove(i);
961 return;
962 }
963 }
964 }
965 }
966
Chen Xu1f1c25e2019-09-15 18:28:21 -0700967 public void notifyCallStateForAllSubs(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700968 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700969 return;
970 }
xinhe43c50292014-09-18 17:56:48 -0700971
972 if (VDBG) {
Chen Xu1f1c25e2019-09-15 18:28:21 -0700973 log("notifyCallStateForAllSubs: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700974 }
975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700977 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800978 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800979 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700981 // Ensure the listener has read call log permission; if they do not return
982 // an empty phone number.
983 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
984 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400986 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 }
988 }
989 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400990 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700992
993 // Called only by Telecomm to communicate call state across different phone accounts. So
994 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700995 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700996 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700997 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 }
999
Chen Xu1f1c25e2019-09-15 18:28:21 -07001000 public void notifyCallState(int phoneId, int subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001001 if (!checkNotifyPermission("notifyCallState()")) {
1002 return;
1003 }
Wink Savillee380b982014-07-26 18:24:22 -07001004 if (VDBG) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001005 log("notifyCallState: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001006 + " state=" + state + " incomingNumber=" + incomingNumber);
1007 }
1008 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001009 if (validatePhoneId(phoneId)) {
1010 mCallState[phoneId] = state;
1011 mCallIncomingNumber[phoneId] = incomingNumber;
1012 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001013 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -07001014 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -08001015 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001016 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001017 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
1018 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -07001019 } catch (RemoteException ex) {
1020 mRemoveList.add(r.binder);
1021 }
1022 }
1023 }
1024 }
1025 handleRemoveListLocked();
1026 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001027 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001028 }
1029
Wink Saville63f03dd2014-10-23 10:44:45 -07001030 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001031 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001032 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001033 }
xinhe43c50292014-09-18 17:56:48 -07001034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001036 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
1037 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -07001038 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001039 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -07001040 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001041 mLocalLog.log(str);
Jordan Liud2d614a2019-06-24 11:27:34 -07001042 // for service state updates, don't notify clients when subId is invalid. This prevents
1043 // us from sending incorrect notifications like b/133140128
1044 // In the future, we can remove this logic for every notification here and add a
1045 // callback so listeners know when their PhoneStateListener's subId becomes invalid, but
1046 // for now we use the simplest fix.
1047 if (validatePhoneId(phoneId) && SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001048 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001049
Wink Savillefb40dd42014-06-12 17:02:31 -07001050 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001051 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001052 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001053 + " phoneId=" + phoneId + " state=" + state);
1054 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001055 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001056 idMatch(r.subId, subId, phoneId)) {
Hall Liuee313732018-11-27 14:36:51 -08001057
Wink Savillefb40dd42014-06-12 17:02:31 -07001058 try {
Hall Liuee313732018-11-27 14:36:51 -08001059 ServiceState stateToSend;
1060 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
1061 stateToSend = new ServiceState(state);
1062 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
1063 stateToSend = state.sanitizeLocationInfo(false);
1064 } else {
1065 stateToSend = state.sanitizeLocationInfo(true);
1066 }
Wink Savillee380b982014-07-26 18:24:22 -07001067 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001068 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001069 + " subId=" + subId + " phoneId=" + phoneId
1070 + " state=" + state);
1071 }
Hall Liuee313732018-11-27 14:36:51 -08001072 r.callback.onServiceStateChanged(stateToSend);
Wink Savillefb40dd42014-06-12 17:02:31 -07001073 } catch (RemoteException ex) {
1074 mRemoveList.add(r.binder);
1075 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001078 } else {
Jordan Liud2d614a2019-06-24 11:27:34 -07001079 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId
1080 + " or subId=" + subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001082 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001084 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 }
1086
fionaxu12312f62016-11-14 13:32:14 -08001087 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1088 int activationType, int activationState) {
1089 if (!checkNotifyPermission("notifySimActivationState()")){
1090 return;
1091 }
1092 if (VDBG) {
1093 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1094 + "type=" + activationType + " state=" + activationState);
1095 }
1096 synchronized (mRecords) {
1097 if (validatePhoneId(phoneId)) {
1098 switch (activationType) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001099 case TelephonyManager.SIM_ACTIVATION_TYPE_VOICE:
fionaxu12312f62016-11-14 13:32:14 -08001100 mVoiceActivationState[phoneId] = activationState;
1101 break;
Chen Xu1f1c25e2019-09-15 18:28:21 -07001102 case TelephonyManager.SIM_ACTIVATION_TYPE_DATA:
fionaxu12312f62016-11-14 13:32:14 -08001103 mDataActivationState[phoneId] = activationState;
1104 break;
1105 default:
1106 return;
1107 }
1108 for (Record r : mRecords) {
1109 if (VDBG) {
1110 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1111 + " phoneId=" + phoneId + "type=" + activationType
1112 + " state=" + activationState);
1113 }
1114 try {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001115 if ((activationType == TelephonyManager.SIM_ACTIVATION_TYPE_VOICE) &&
fionaxu12312f62016-11-14 13:32:14 -08001116 r.matchPhoneStateListenerEvent(
1117 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1118 idMatch(r.subId, subId, phoneId)) {
1119 if (DBG) {
1120 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1121 + " subId=" + subId + " phoneId=" + phoneId
1122 + " state=" + activationState);
1123 }
1124 r.callback.onVoiceActivationStateChanged(activationState);
1125 }
Chen Xu1f1c25e2019-09-15 18:28:21 -07001126 if ((activationType == TelephonyManager.SIM_ACTIVATION_TYPE_DATA) &&
fionaxu12312f62016-11-14 13:32:14 -08001127 r.matchPhoneStateListenerEvent(
1128 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1129 idMatch(r.subId, subId, phoneId)) {
1130 if (DBG) {
1131 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1132 + " subId=" + subId + " phoneId=" + phoneId
1133 + " state=" + activationState);
1134 }
1135 r.callback.onDataActivationStateChanged(activationState);
1136 }
1137 } catch (RemoteException ex) {
1138 mRemoveList.add(r.binder);
1139 }
1140 }
1141 } else {
1142 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1143 }
1144 handleRemoveListLocked();
1145 }
1146 }
1147
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001148 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1149 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001150 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001151 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001152 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001153 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001154 log("notifySignalStrengthForPhoneId: subId=" + subId
1155 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001156 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001159 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001160 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001161 mSignalStrength[phoneId] = signalStrength;
1162 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001163 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001164 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001165 + " phoneId=" + phoneId + " ss=" + signalStrength);
1166 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001167 if (r.matchPhoneStateListenerEvent(
1168 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001169 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001170 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001171 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001172 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001173 + " subId=" + subId + " phoneId=" + phoneId
1174 + " ss=" + signalStrength);
1175 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001176 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1177 } catch (RemoteException ex) {
1178 mRemoveList.add(r.binder);
1179 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001180 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001181 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001182 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001183 try {
1184 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001185 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001186 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001187 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001188 + " subId=" + subId + " phoneId=" + phoneId
1189 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1190 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001191 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001192 } catch (RemoteException ex) {
1193 mRemoveList.add(r.binder);
1194 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 }
1196 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001197 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001198 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001200 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001202 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
1204
Andrew Flynn1f452642015-04-14 22:16:04 -04001205 @Override
1206 public void notifyCarrierNetworkChange(boolean active) {
chen xubadf2b02019-04-26 17:45:26 -07001207 // only CarrierService with carrier privilege rule should have the permission
1208 int[] subIds = Arrays.stream(SubscriptionManager.from(mContext)
Malcolm Chen1eb939c2019-09-25 14:02:14 -07001209 .getActiveSubscriptionIdList(false))
chen xubadf2b02019-04-26 17:45:26 -07001210 .filter(i -> TelephonyPermissions.checkCarrierPrivilegeForSubId(i)).toArray();
1211 if (ArrayUtils.isEmpty(subIds)) {
chen xu627d1b22019-04-11 02:16:19 -07001212 loge("notifyCarrierNetworkChange without carrier privilege");
chen xubadf2b02019-04-26 17:45:26 -07001213 // the active subId does not have carrier privilege.
chen xu627d1b22019-04-11 02:16:19 -07001214 throw new SecurityException("notifyCarrierNetworkChange without carrier privilege");
chen xu5b98d402019-03-22 16:56:34 -07001215 }
Andrew Flynn1f452642015-04-14 22:16:04 -04001216
1217 synchronized (mRecords) {
1218 mCarrierNetworkChangeState = active;
chen xubadf2b02019-04-26 17:45:26 -07001219 for (int subId : subIds) {
1220 int phoneId = SubscriptionManager.getPhoneId(subId);
1221
1222 if (VDBG) {
1223 log("notifyCarrierNetworkChange: active=" + active + "subId: " + subId);
1224 }
1225 for (Record r : mRecords) {
1226 if (r.matchPhoneStateListenerEvent(
1227 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) &&
1228 idMatch(r.subId, subId, phoneId)) {
1229 try {
1230 r.callback.onCarrierNetworkChange(active);
1231 } catch (RemoteException ex) {
1232 mRemoveList.add(r.binder);
1233 }
Andrew Flynn1f452642015-04-14 22:16:04 -04001234 }
1235 }
1236 }
1237 handleRemoveListLocked();
1238 }
1239 }
1240
Wink Savilleb208a242012-07-25 14:08:09 -07001241 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001242 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001243 }
1244
Wink Saville63f03dd2014-10-23 10:44:45 -07001245 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001246 if (!checkNotifyPermission("notifyCellInfoForSubscriber()")) {
John Wang963db55d2012-03-30 16:04:06 -07001247 return;
1248 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001249 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001250 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001251 + " cellInfo=" + cellInfo);
1252 }
yifan.baie620ce72017-12-22 14:59:57 +08001253 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001254 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001255 if (validatePhoneId(phoneId)) {
1256 mCellInfo.set(phoneId, cellInfo);
1257 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001258 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001259 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001260 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001261 try {
1262 if (DBG_LOC) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001263 log("notifyCellInfoForSubscriber: mCellInfo=" + cellInfo
1264 + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001265 }
1266 r.callback.onCellInfoChanged(cellInfo);
1267 } catch (RemoteException ex) {
1268 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001269 }
John Wang963db55d2012-03-30 16:04:06 -07001270 }
1271 }
1272 }
1273 handleRemoveListLocked();
1274 }
1275 }
1276
andychouce659222019-06-19 20:54:32 +08001277 /**
1278 * Notify physical channel configuration according to subscripton ID and phone ID
1279 */
1280 public void notifyPhysicalChannelConfigurationForSubscriber(int phoneId, int subId,
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001281 List<PhysicalChannelConfig> configs) {
1282 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1283 return;
1284 }
1285
1286 if (VDBG) {
andychouce659222019-06-19 20:54:32 +08001287 log("notifyPhysicalChannelConfiguration: subId=" + subId + " phoneId=" + phoneId
1288 + " configs=" + configs);
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001289 }
1290
1291 synchronized (mRecords) {
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001292 if (validatePhoneId(phoneId)) {
1293 mPhysicalChannelConfigs.set(phoneId, configs);
1294 for (Record r : mRecords) {
1295 if (r.matchPhoneStateListenerEvent(
1296 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1297 && idMatch(r.subId, subId, phoneId)) {
1298 try {
1299 if (DBG_LOC) {
1300 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1301 + configs + " r=" + r);
1302 }
1303 r.callback.onPhysicalChannelConfigurationChanged(configs);
1304 } catch (RemoteException ex) {
1305 mRemoveList.add(r.binder);
1306 }
1307 }
1308 }
1309 }
1310 handleRemoveListLocked();
1311 }
1312 }
1313
xinhe43c50292014-09-18 17:56:48 -07001314 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001315 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001316 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001317 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001318 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001319 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001320 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001321 + " mwi=" + mwi);
1322 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001324 if (validatePhoneId(phoneId)) {
1325 mMessageWaiting[phoneId] = mwi;
1326 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001327 if (r.matchPhoneStateListenerEvent(
1328 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001329 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001330 try {
1331 r.callback.onMessageWaitingIndicatorChanged(mwi);
1332 } catch (RemoteException ex) {
1333 mRemoveList.add(r.binder);
1334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 }
1336 }
1337 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001338 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 }
1340 }
1341
zxuan35a47022018-01-04 11:24:04 -08001342 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1343 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1344 return;
1345 }
1346 if (VDBG) {
SongFerngWang0b109f5f2019-04-09 17:29:29 +08001347 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: PhoneId=" + phoneId
1348 + " subId=" + subId + " state=" + state);
zxuan35a47022018-01-04 11:24:04 -08001349 }
1350 synchronized (mRecords) {
1351 if (validatePhoneId(phoneId)) {
SongFerngWang0b109f5f2019-04-09 17:29:29 +08001352 mUserMobileDataState[phoneId] = state;
zxuan35a47022018-01-04 11:24:04 -08001353 for (Record r : mRecords) {
1354 if (r.matchPhoneStateListenerEvent(
1355 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1356 idMatch(r.subId, subId, phoneId)) {
1357 try {
1358 r.callback.onUserMobileDataStateChanged(state);
1359 } catch (RemoteException ex) {
1360 mRemoveList.add(r.binder);
1361 }
1362 }
1363 }
1364 }
1365 handleRemoveListLocked();
1366 }
1367 }
1368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001370 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001371 }
1372
Wink Saville63f03dd2014-10-23 10:44:45 -07001373 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001374 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001375 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001376 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001377 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001378 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001379 + " cfi=" + cfi);
1380 }
yifan.baie620ce72017-12-22 14:59:57 +08001381 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001383 if (validatePhoneId(phoneId)) {
1384 mCallForwarding[phoneId] = cfi;
1385 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001386 if (r.matchPhoneStateListenerEvent(
1387 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001388 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001389 try {
1390 r.callback.onCallForwardingIndicatorChanged(cfi);
1391 } catch (RemoteException ex) {
1392 mRemoveList.add(r.binder);
1393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 }
1395 }
1396 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001397 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 }
1399 }
1400
1401 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001402 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001403 }
1404
Wink Saville63f03dd2014-10-23 10:44:45 -07001405 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001406 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001407 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001408 }
yifan.baie620ce72017-12-22 14:59:57 +08001409 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001411 if (validatePhoneId(phoneId)) {
1412 mDataActivity[phoneId] = state;
1413 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001414 // Notify by correct subId.
1415 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1416 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001417 try {
1418 r.callback.onDataActivity(state);
1419 } catch (RemoteException ex) {
1420 mRemoveList.add(r.binder);
1421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 }
1423 }
1424 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001425 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 }
1427 }
1428
Jack Yu4d1c9452019-01-02 16:51:08 -08001429 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1430 LinkProperties linkProperties,
1431 NetworkCapabilities networkCapabilities, int networkType,
1432 boolean roaming) {
chen xud5deeb12019-04-29 13:57:42 -07001433 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX,
1434 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yu4d1c9452019-01-02 16:51:08 -08001435 isDataAllowed, apn, apnType, linkProperties,
1436 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001437 }
1438
chen xud5deeb12019-04-29 13:57:42 -07001439 public void notifyDataConnectionForSubscriber(int phoneId, int subId, int state,
1440 boolean isDataAllowed,
Jack Yu4d1c9452019-01-02 16:51:08 -08001441 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001442 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1443 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001444 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001445 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001446 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001447 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001448 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001449 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001450 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001451 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001452 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001454 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001455 // We only call the callback when the change is for default APN type.
1456 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1457 && (mDataConnectionState[phoneId] != state
1458 || mDataConnectionNetworkType[phoneId] != networkType)) {
Jack Yu0c92c232019-04-04 15:10:17 -07001459 String str = "onDataConnectionStateChanged("
1460 + TelephonyManager.dataStateToString(state)
1461 + ", " + TelephonyManager.getNetworkTypeName(networkType)
1462 + ") subId=" + subId + ", phoneId=" + phoneId;
Jack Yud19b6ae2017-04-05 14:12:09 -07001463 log(str);
1464 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001465 for (Record r : mRecords) {
1466 if (r.matchPhoneStateListenerEvent(
chen xud5deeb12019-04-29 13:57:42 -07001467 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE)
1468 && idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001469 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001470 if (DBG) {
1471 log("Notify data connection state changed on sub: " + subId);
1472 }
Jack Yub1bac542018-03-14 16:23:38 -07001473 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001474 } catch (RemoteException ex) {
1475 mRemoveList.add(r.binder);
1476 }
1477 }
1478 }
1479 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001480
1481 mDataConnectionState[phoneId] = state;
1482 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001483 }
chen xud5deeb12019-04-29 13:57:42 -07001484 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1485 state, networkType,
chen xu16e24cd2018-12-11 18:09:41 -08001486 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1487 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001488 for (Record r : mRecords) {
1489 if (r.matchPhoneStateListenerEvent(
chen xud5deeb12019-04-29 13:57:42 -07001490 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1491 && idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001492 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001493 r.callback.onPreciseDataConnectionStateChanged(
chen xud5deeb12019-04-29 13:57:42 -07001494 mPreciseDataConnectionState[phoneId]);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001495 } catch (RemoteException ex) {
1496 mRemoveList.add(r.binder);
1497 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001498 }
1499 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001500 }
1501 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001503 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1504 networkCapabilities, roaming, subId);
1505 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu16e24cd2018-12-11 18:09:41 -08001506 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 }
1508
Jack Yu4d1c9452019-01-02 16:51:08 -08001509 public void notifyDataConnectionFailed(String apnType) {
chen xud5deeb12019-04-29 13:57:42 -07001510 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX,
1511 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yu4d1c9452019-01-02 16:51:08 -08001512 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001513 }
1514
chen xud5deeb12019-04-29 13:57:42 -07001515 public void notifyDataConnectionFailedForSubscriber(int phoneId, int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001516 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001517 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001518 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001519 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001520 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yu4d1c9452019-01-02 16:51:08 -08001521 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001524 if (validatePhoneId(phoneId)) {
1525 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1526 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1527 ApnSetting.getApnTypesBitmaskFromString(apnType), null, null,
1528 DataFailCause.NONE);
1529 for (Record r : mRecords) {
1530 if (r.matchPhoneStateListenerEvent(
1531 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1532 && idMatch(r.subId, subId, phoneId)) {
1533 try {
1534 r.callback.onPreciseDataConnectionStateChanged(
1535 mPreciseDataConnectionState[phoneId]);
1536 } catch (RemoteException ex) {
1537 mRemoveList.add(r.binder);
1538 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001539 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 }
1541 }
chen xud5deeb12019-04-29 13:57:42 -07001542
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001543 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001545 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001546 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu81653862019-02-28 10:44:54 -08001547 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, null, null,
chen xu16e24cd2018-12-11 18:09:41 -08001548 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 }
1550
1551 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001552 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001553 }
1554
Wink Saville63f03dd2014-10-23 10:44:45 -07001555 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001556 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001557 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001558 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001559 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001560 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001561 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001562 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001563 + " cellLocation=" + cellLocation);
1564 }
yifan.baie620ce72017-12-22 14:59:57 +08001565 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001567 if (validatePhoneId(phoneId)) {
1568 mCellLocation[phoneId] = cellLocation;
1569 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001570 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001571 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001572 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001573 try {
1574 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001575 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001576 + " r=" + r);
1577 }
1578 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1579 } catch (RemoteException ex) {
1580 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001581 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001582 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 }
1584 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001585 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001586 }
1587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588
chen xud5deeb12019-04-29 13:57:42 -07001589 public void notifyOtaspChanged(int subId, int otaspMode) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001590 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1591 return;
1592 }
chen xud5deeb12019-04-29 13:57:42 -07001593 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefd2d0132010-10-28 14:22:26 -07001594 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001595 if (validatePhoneId(phoneId)) {
1596 mOtaspMode[phoneId] = otaspMode;
1597 for (Record r : mRecords) {
1598 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)
1599 && idMatch(r.subId, subId, phoneId)) {
1600 try {
1601 r.callback.onOtaspChanged(otaspMode);
1602 } catch (RemoteException ex) {
1603 mRemoveList.add(r.binder);
1604 }
Wink Savillefd2d0132010-10-28 14:22:26 -07001605 }
1606 }
1607 }
1608 handleRemoveListLocked();
1609 }
1610 }
1611
chen xud5deeb12019-04-29 13:57:42 -07001612 public void notifyPreciseCallState(int phoneId, int subId, int ringingCallState,
1613 int foregroundCallState, int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001614 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1615 return;
1616 }
1617 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001618 if (validatePhoneId(phoneId)) {
1619 mRingingCallState[phoneId] = ringingCallState;
1620 mForegroundCallState[phoneId] = foregroundCallState;
1621 mBackgroundCallState[phoneId] = backgroundCallState;
1622 mPreciseCallState[phoneId] = new PreciseCallState(
1623 ringingCallState, foregroundCallState,
1624 backgroundCallState,
1625 DisconnectCause.NOT_VALID,
1626 PreciseDisconnectCause.NOT_VALID);
1627 boolean notifyCallAttributes = true;
1628 if (mCallQuality == null) {
1629 log("notifyPreciseCallState: mCallQuality is null, "
1630 + "skipping call attributes");
1631 notifyCallAttributes = false;
1632 } else {
1633 // If the precise call state is no longer active, reset the call network type
1634 // and call quality.
1635 if (mPreciseCallState[phoneId].getForegroundCallState()
1636 != PreciseCallState.PRECISE_CALL_STATE_ACTIVE) {
1637 mCallNetworkType[phoneId] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1638 mCallQuality[phoneId] = new CallQuality();
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001639 }
chen xud5deeb12019-04-29 13:57:42 -07001640 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
1641 mCallNetworkType[phoneId], mCallQuality[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001642 }
chen xud5deeb12019-04-29 13:57:42 -07001643
1644 for (Record r : mRecords) {
1645 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)
1646 && idMatch(r.subId, subId, phoneId)) {
1647 try {
1648 r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]);
1649 } catch (RemoteException ex) {
1650 mRemoveList.add(r.binder);
1651 }
1652 }
1653 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1654 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
1655 && idMatch(r.subId, subId, phoneId)) {
1656 try {
1657 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
1658 } catch (RemoteException ex) {
1659 mRemoveList.add(r.binder);
1660 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001661 }
1662 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001663 }
1664 handleRemoveListLocked();
1665 }
chen xu6a942d482018-12-12 19:59:30 -08001666 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1667 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001668 }
1669
chen xud5deeb12019-04-29 13:57:42 -07001670 public void notifyDisconnectCause(int phoneId, int subId, int disconnectCause,
1671 int preciseDisconnectCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001672 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1673 return;
1674 }
1675 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001676 if (validatePhoneId(phoneId)) {
1677 mCallDisconnectCause[phoneId] = disconnectCause;
1678 mCallPreciseDisconnectCause[phoneId] = preciseDisconnectCause;
1679 for (Record r : mRecords) {
1680 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1681 .LISTEN_CALL_DISCONNECT_CAUSES) && idMatch(r.subId, subId, phoneId)) {
1682 try {
1683 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId],
1684 mCallPreciseDisconnectCause[phoneId]);
1685 } catch (RemoteException ex) {
1686 mRemoveList.add(r.binder);
1687 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001688 }
1689 }
1690 }
1691 handleRemoveListLocked();
1692 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001693 }
1694
chen xu6ac5fc12019-01-24 14:14:13 -08001695 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1696 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1697 return;
1698 }
1699 int phoneId = SubscriptionManager.getPhoneId(subId);
1700 synchronized (mRecords) {
1701 if (validatePhoneId(phoneId)) {
1702 mImsReasonInfo.set(phoneId, imsReasonInfo);
1703 for (Record r : mRecords) {
1704 if (r.matchPhoneStateListenerEvent(
1705 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1706 && idMatch(r.subId, subId, phoneId)) {
1707 try {
1708 if (DBG_LOC) {
1709 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1710 + imsReasonInfo + " r=" + r);
1711 }
1712 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1713 } catch (RemoteException ex) {
1714 mRemoveList.add(r.binder);
1715 }
1716 }
1717 }
1718 }
1719 handleRemoveListLocked();
1720 }
1721 }
1722
chen xud5deeb12019-04-29 13:57:42 -07001723 public void notifyPreciseDataConnectionFailed(int phoneId, int subId, String apnType,
Chen Xu7631ff72019-09-26 16:11:59 -07001724 String apn, @DataFailureCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001725 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1726 return;
1727 }
1728 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001729 if (validatePhoneId(phoneId)) {
1730 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1731 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1732 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
1733 for (Record r : mRecords) {
1734 if (r.matchPhoneStateListenerEvent(
1735 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1736 && idMatch(r.subId, subId, phoneId)) {
1737 try {
1738 r.callback.onPreciseDataConnectionStateChanged(
1739 mPreciseDataConnectionState[phoneId]);
1740 } catch (RemoteException ex) {
1741 mRemoveList.add(r.binder);
1742 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001743 }
1744 }
1745 }
chen xud5deeb12019-04-29 13:57:42 -07001746
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001747 handleRemoveListLocked();
1748 }
1749 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yu4d1c9452019-01-02 16:51:08 -08001750 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001751 }
1752
Brad Ebingerefed9822018-10-26 10:25:57 -07001753 @Override
Chen Xu7631ff72019-09-26 16:11:59 -07001754 public void notifySrvccStateChanged(int subId, @SrvccState int state) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001755 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001756 return;
1757 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001758 if (VDBG) {
1759 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1760 }
1761 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001762 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001763 if (validatePhoneId(phoneId)) {
chen xu6ac5fc12019-01-24 14:14:13 -08001764 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001765 for (Record r : mRecords) {
1766 if (r.matchPhoneStateListenerEvent(
1767 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1768 idMatch(r.subId, subId, phoneId)) {
1769 try {
1770 if (DBG_LOC) {
1771 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1772 }
1773 r.callback.onSrvccStateChanged(state);
1774 } catch (RemoteException ex) {
1775 mRemoveList.add(r.binder);
1776 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001777 }
1778 }
1779 }
1780 handleRemoveListLocked();
1781 }
1782 }
1783
chen xud5deeb12019-04-29 13:57:42 -07001784 public void notifyOemHookRawEventForSubscriber(int phoneId, int subId, byte[] rawData) {
Shuo Qian066e8652018-04-25 21:02:35 +00001785 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1786 return;
1787 }
1788
1789 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001790 if (validatePhoneId(phoneId)) {
1791 for (Record r : mRecords) {
1792 if (VDBG) {
1793 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1794 }
1795 if ((r.matchPhoneStateListenerEvent(
1796 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT))
1797 && idMatch(r.subId, subId, phoneId)) {
1798 try {
1799 r.callback.onOemHookRawEvent(rawData);
1800 } catch (RemoteException ex) {
1801 mRemoveList.add(r.binder);
1802 }
Shuo Qian066e8652018-04-25 21:02:35 +00001803 }
1804 }
1805 }
1806 handleRemoveListLocked();
1807 }
1808 }
1809
Malcolm Chene1623652018-08-08 20:27:45 -07001810 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1811 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1812 return;
1813 }
1814
1815 if (VDBG) {
1816 log("notifyPhoneCapabilityChanged: capability=" + capability);
1817 }
1818
1819 synchronized (mRecords) {
1820 mPhoneCapability = capability;
1821
1822 for (Record r : mRecords) {
1823 if (r.matchPhoneStateListenerEvent(
1824 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1825 try {
1826 r.callback.onPhoneCapabilityChanged(capability);
1827 } catch (RemoteException ex) {
1828 mRemoveList.add(r.binder);
1829 }
1830 }
1831 }
1832 handleRemoveListLocked();
1833 }
1834 }
1835
Malcolm Chen026451d2019-02-14 19:50:19 -08001836 public void notifyActiveDataSubIdChanged(int activeDataSubId) {
1837 if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001838 return;
1839 }
1840
1841 if (VDBG) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001842 log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001843 }
1844
sqian9e9ed182019-03-20 16:17:09 -07001845 mActiveDataSubId = activeDataSubId;
sqian9e9ed182019-03-20 16:17:09 -07001846 synchronized (mRecords) {
Malcolm Chen118b02f2019-09-04 16:10:34 -07001847 for (Record r : mRecords) {
1848 if (r.matchPhoneStateListenerEvent(
1849 PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE)) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001850 try {
Malcolm Chen026451d2019-02-14 19:50:19 -08001851 r.callback.onActiveDataSubIdChanged(activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001852 } catch (RemoteException ex) {
1853 mRemoveList.add(r.binder);
1854 }
1855 }
1856 }
1857 handleRemoveListLocked();
1858 }
1859 }
Malcolm Chene1623652018-08-08 20:27:45 -07001860
Chen Xu7631ff72019-09-26 16:11:59 -07001861 public void notifyRadioPowerStateChanged(int phoneId, int subId, @RadioPowerState int state) {
Chen Xu7395c632018-10-17 17:53:47 +00001862 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1863 return;
1864 }
1865
1866 if (VDBG) {
chen xud5deeb12019-04-29 13:57:42 -07001867 log("notifyRadioPowerStateChanged: state= " + state + " subId=" + subId);
Chen Xu7395c632018-10-17 17:53:47 +00001868 }
1869
1870 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001871 if (validatePhoneId(phoneId)) {
1872 mRadioPowerState = state;
Chen Xu7395c632018-10-17 17:53:47 +00001873
chen xud5deeb12019-04-29 13:57:42 -07001874 for (Record r : mRecords) {
1875 if (r.matchPhoneStateListenerEvent(
1876 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)
1877 && idMatch(r.subId, subId, phoneId)) {
1878 try {
1879 r.callback.onRadioPowerStateChanged(state);
1880 } catch (RemoteException ex) {
1881 mRemoveList.add(r.binder);
1882 }
Chen Xu7395c632018-10-17 17:53:47 +00001883 }
1884 }
chen xud5deeb12019-04-29 13:57:42 -07001885
Chen Xu7395c632018-10-17 17:53:47 +00001886 }
1887 handleRemoveListLocked();
1888 }
1889 }
1890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 @Override
chen xud5deeb12019-04-29 13:57:42 -07001892 public void notifyEmergencyNumberList(int phoneId, int subId) {
sqian9f93a122018-12-03 22:40:41 -08001893 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1894 return;
1895 }
1896
1897 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001898 if (validatePhoneId(phoneId)) {
1899 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1900 Context.TELEPHONY_SERVICE);
1901 mEmergencyNumberList = tm.getEmergencyNumberList();
sqian9f93a122018-12-03 22:40:41 -08001902
chen xud5deeb12019-04-29 13:57:42 -07001903 for (Record r : mRecords) {
1904 if (r.matchPhoneStateListenerEvent(
1905 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)
1906 && idMatch(r.subId, subId, phoneId)) {
1907 try {
1908 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1909 if (VDBG) {
1910 log("notifyEmergencyNumberList: emergencyNumberList= "
1911 + mEmergencyNumberList);
1912 }
1913 } catch (RemoteException ex) {
1914 mRemoveList.add(r.binder);
sqian9f93a122018-12-03 22:40:41 -08001915 }
sqian9f93a122018-12-03 22:40:41 -08001916 }
1917 }
1918 }
chen xud5deeb12019-04-29 13:57:42 -07001919
sqian9f93a122018-12-03 22:40:41 -08001920 handleRemoveListLocked();
1921 }
sqianbdc5a732018-10-26 13:27:51 -07001922 }
1923
Jordan Liu8218ddd2018-11-28 11:22:39 -08001924 @Override
Shuo Qianb61230c2019-09-12 17:00:31 -07001925 public void notifyOutgoingEmergencyCall(int phoneId, int subId,
1926 EmergencyNumber emergencyNumber) {
1927 if (!checkNotifyPermission("notifyOutgoingEmergencyCall()")) {
1928 return;
1929 }
1930 synchronized (mRecords) {
1931 if (validatePhoneId(phoneId)) {
1932 mOutgoingCallEmergencyNumber[phoneId] = emergencyNumber;
1933 for (Record r : mRecords) {
1934 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07001935 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL)
Shuo Qianb61230c2019-09-12 17:00:31 -07001936 && idMatch(r.subId, subId, phoneId)) {
1937 try {
1938 r.callback.onOutgoingEmergencyCall(emergencyNumber);
1939 } catch (RemoteException ex) {
1940 mRemoveList.add(r.binder);
1941 }
1942 }
1943 }
1944 }
1945 handleRemoveListLocked();
1946 }
1947 }
1948
1949 @Override
1950 public void notifyOutgoingEmergencySms(int phoneId, int subId,
1951 EmergencyNumber emergencyNumber) {
1952 if (!checkNotifyPermission("notifyOutgoingEmergencySms()")) {
1953 return;
1954 }
1955 synchronized (mRecords) {
1956 if (validatePhoneId(phoneId)) {
1957 mOutgoingSmsEmergencyNumber[phoneId] = emergencyNumber;
1958 for (Record r : mRecords) {
1959 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07001960 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS)
Shuo Qianb61230c2019-09-12 17:00:31 -07001961 && idMatch(r.subId, subId, phoneId)) {
1962 try {
1963 r.callback.onOutgoingEmergencySms(emergencyNumber);
1964 } catch (RemoteException ex) {
1965 mRemoveList.add(r.binder);
1966 }
1967 }
1968 }
1969 }
1970 handleRemoveListLocked();
1971 }
1972 }
1973
1974 @Override
chen xud5deeb12019-04-29 13:57:42 -07001975 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId, int subId,
Jordan Liu65ed9d92019-02-19 14:42:07 -08001976 int callNetworkType) {
Jordan Liu8218ddd2018-11-28 11:22:39 -08001977 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
1978 return;
1979 }
1980
Jordan Liu8218ddd2018-11-28 11:22:39 -08001981 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001982 if (validatePhoneId(phoneId)) {
1983 // merge CallQuality with PreciseCallState and network type
1984 mCallQuality[phoneId] = callQuality;
1985 mCallNetworkType[phoneId] = callNetworkType;
1986 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
1987 callNetworkType, callQuality);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001988
chen xud5deeb12019-04-29 13:57:42 -07001989 for (Record r : mRecords) {
1990 if (r.matchPhoneStateListenerEvent(
1991 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
1992 && idMatch(r.subId, subId, phoneId)) {
1993 try {
1994 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
1995 } catch (RemoteException ex) {
1996 mRemoveList.add(r.binder);
1997 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001998 }
1999 }
2000 }
chen xud5deeb12019-04-29 13:57:42 -07002001
Jordan Liu8218ddd2018-11-28 11:22:39 -08002002 handleRemoveListLocked();
2003 }
2004 }
2005
sqianbdc5a732018-10-26 13:27:51 -07002006
2007 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07002008 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
2009 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
2010
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06002011 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07002012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002014 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07002016 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05302017 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002018 pw.println("Phone Id=" + i);
2019 pw.increaseIndent();
2020 pw.println("mCallState=" + mCallState[i]);
chen xud5deeb12019-04-29 13:57:42 -07002021 pw.println("mRingingCallState=" + mRingingCallState[i]);
2022 pw.println("mForegroundCallState=" + mForegroundCallState[i]);
2023 pw.println("mBackgroundCallState=" + mBackgroundCallState[i]);
2024 pw.println("mPreciseCallState=" + mPreciseCallState[i]);
2025 pw.println("mCallDisconnectCause=" + mCallDisconnectCause[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002026 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
2027 pw.println("mServiceState=" + mServiceState[i]);
2028 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
2029 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08002030 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002031 pw.println("mSignalStrength=" + mSignalStrength[i]);
2032 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
2033 pw.println("mCallForwarding=" + mCallForwarding[i]);
2034 pw.println("mDataActivity=" + mDataActivity[i]);
2035 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002036 pw.println("mCellLocation=" + mCellLocation[i]);
2037 pw.println("mCellInfo=" + mCellInfo.get(i));
Tyler Gunnf3f89d02019-03-25 07:26:33 -07002038 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i));
chen xud5deeb12019-04-29 13:57:42 -07002039 pw.println("mSrvccState=" + mSrvccState[i]);
2040 pw.println("mOtaspMode=" + mOtaspMode[i]);
2041 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause[i]);
2042 pw.println("mCallQuality=" + mCallQuality[i]);
2043 pw.println("mCallAttributes=" + mCallAttributes[i]);
2044 pw.println("mCallNetworkType=" + mCallNetworkType[i]);
2045 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState[i]);
Shuo Qianb61230c2019-09-12 17:00:31 -07002046 pw.println("mOutgoingCallEmergencyNumber=" + mOutgoingCallEmergencyNumber[i]);
2047 pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002048 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05302049 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002050 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
chen xud5deeb12019-04-29 13:57:42 -07002051
Malcolm Chene1623652018-08-08 20:27:45 -07002052 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen026451d2019-02-14 19:50:19 -08002053 pw.println("mActiveDataSubId=" + mActiveDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00002054 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian9f93a122018-12-03 22:40:41 -08002055 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
chen xuaddc2702019-05-07 16:25:12 -07002056 pw.println("mDefaultPhoneId=" + mDefaultPhoneId);
2057 pw.println("mDefaultSubId=" + mDefaultSubId);
Jack Yud19b6ae2017-04-05 14:12:09 -07002058
2059 pw.decreaseIndent();
2060
2061 pw.println("local logs:");
2062 pw.increaseIndent();
2063 mLocalLog.dump(fd, pw, args);
Jack Yu0c92c232019-04-04 15:10:17 -07002064 pw.println("listen logs:");
2065 mListenLog.dump(fd, pw, args);
Jack Yud19b6ae2017-04-05 14:12:09 -07002066 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07002067 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07002068 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07002069 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002070 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002072 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 }
2074 }
2075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 //
2077 // the legacy intent broadcasting
2078 //
2079
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002080 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07002081 long ident = Binder.clearCallingIdentity();
2082 try {
2083 mBatteryStats.notePhoneState(state.getState());
2084 } catch (RemoteException re) {
2085 // Can't do much
2086 } finally {
2087 Binder.restoreCallingIdentity(ident);
2088 }
2089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08002091 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 Bundle data = new Bundle();
2093 state.fillInNotifierBundle(data);
2094 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07002095 // Pass the subscription along with the intent.
2096 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002097 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002098 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002099 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 }
2101
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002102 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
2103 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002104 long ident = Binder.clearCallingIdentity();
2105 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07002106 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002107 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002108 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07002109 } finally {
2110 Binder.restoreCallingIdentity(ident);
2111 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07002114 Bundle data = new Bundle();
2115 signalStrength.fillInNotifierBundle(data);
2116 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07002117 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002118 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002119 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 }
2121
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002122 /**
2123 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
2124 * a valid subId, in which case this function fires a subId-specific intent, or it
2125 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
2126 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
2127 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002128 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
2129 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 long ident = Binder.clearCallingIdentity();
2131 try {
2132 if (state == TelephonyManager.CALL_STATE_IDLE) {
2133 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07002134 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2135 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 } else {
2137 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07002138 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2139 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 }
2141 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002142 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 } finally {
2144 Binder.restoreCallingIdentity(ident);
2145 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002148 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002149 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002150
2151 // If a valid subId was specified, we should fire off a subId-specific state
2152 // change intent and include the subId.
2153 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
2154 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
2155 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002156 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002157 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002158 // If the phoneId is invalid, the broadcast is for overall call state.
2159 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
2160 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
2161 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002162
Brad Ebinger51de96a2017-04-21 17:05:18 -07002163 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
2164 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
2165
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002166 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002167 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002168 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2169
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002170 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2171 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002172 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002173 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002174 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002175 android.Manifest.permission.READ_PHONE_STATE,
2176 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002177 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2178 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2179 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 }
2181
Jack Yu4d1c9452019-01-02 16:51:08 -08002182 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2183 String apnType, LinkProperties linkProperties,
2184 NetworkCapabilities networkCapabilities,
2185 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002186 // Note: not reporting to the battery stats service here, because the
2187 // status bar takes care of that after taking into account all of the
2188 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002190 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002191 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07002192 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002193 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002195 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002196 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002197 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002198 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002199 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002200 }
2201 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002202 if (networkCapabilities != null) {
2203 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002204 }
Wink Savillea639b312012-07-10 12:37:54 -07002205 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002206
Wink Savillea639b312012-07-10 12:37:54 -07002207 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2208 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002209 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002210 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 }
2212
Jack Yu4d1c9452019-01-02 16:51:08 -08002213 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002215 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002216 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002217 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002219
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002220 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yu4d1c9452019-01-02 16:51:08 -08002221 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002222 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2223 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2224 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2225 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002226 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2227 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2228 }
2229
2230 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu16e24cd2018-12-11 18:09:41 -08002231 String apnType, String apn, LinkProperties linkProperties,
Chen Xu7631ff72019-09-26 16:11:59 -07002232 @DataFailureCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002233 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2234 intent.putExtra(PhoneConstants.STATE_KEY, state);
2235 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002236 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2237 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002238 if (linkProperties != null) {
Jack Yu4d1c9452019-01-02 16:51:08 -08002239 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002240 }
chen xu16e24cd2018-12-11 18:09:41 -08002241 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002242
2243 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2244 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2245 }
2246
Andrew Flynnceaed682015-06-09 12:36:58 +00002247 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002248 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002249 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002250 }
2251
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002252 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2253 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002254 }
2255
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002256 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002257 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002258 return true;
2259 }
2260 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002261 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002262 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002263 return false;
2264 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002265
Andrew Flynn1f452642015-04-14 22:16:04 -04002266 private boolean checkNotifyPermission() {
2267 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2268 == PackageManager.PERMISSION_GRANTED;
2269 }
2270
Jeff Davidson29da89f2018-02-28 17:50:16 -08002271 private boolean checkListenerPermission(
2272 int events, int subId, String callingPackage, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002273 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2274 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2275 .setCallingPackage(callingPackage)
2276 .setMethod(message + " events: " + events)
2277 .setCallingPid(Binder.getCallingPid())
2278 .setCallingUid(Binder.getCallingUid());
2279
2280 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002281 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002282 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2283 shouldCheckLocationPermissions = true;
2284 }
2285
2286 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2287 // Everything that requires fine location started in Q. So far...
2288 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2289 shouldCheckLocationPermissions = true;
2290 }
2291
2292 if (shouldCheckLocationPermissions) {
2293 LocationAccessPolicy.LocationPermissionResult result =
2294 LocationAccessPolicy.checkLocationPermission(
2295 mContext, locationQueryBuilder.build());
2296 switch (result) {
2297 case DENIED_HARD:
2298 throw new SecurityException("Unable to listen for events " + events + " due to "
2299 + "insufficient location permissions.");
2300 case DENIED_SOFT:
2301 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002302 }
John Wang963db55d2012-03-30 16:04:06 -07002303 }
2304
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002305 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2307 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002308 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002309 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002310 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002311
2312 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2313 mContext.enforceCallingOrSelfPermission(
2314 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002315 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002316
Shuo Qianb61230c2019-09-12 17:00:31 -07002317 if ((events & READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK) != 0) {
2318 mContext.enforceCallingOrSelfPermission(
2319 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2320 }
2321
Shuo Qian066e8652018-04-25 21:02:35 +00002322 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2323 mContext.enforceCallingOrSelfPermission(
2324 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2325 }
2326
Brad Ebingerefed9822018-10-26 10:25:57 -07002327 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2328 mContext.enforceCallingOrSelfPermission(
2329 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2330 }
2331
chen xu6a942d482018-12-12 19:59:30 -08002332 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2333 mContext.enforceCallingOrSelfPermission(
2334 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2335 }
2336
Jordan Liu8218ddd2018-11-28 11:22:39 -08002337 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2338 mContext.enforceCallingOrSelfPermission(
2339 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2340 }
2341
chen xu52797b62019-01-18 13:16:31 -08002342 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2343 mContext.enforceCallingOrSelfPermission(
2344 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2345 }
2346
2347 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2348 mContext.enforceCallingOrSelfPermission(
2349 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2350 }
2351
chen xu6ac5fc12019-01-24 14:14:13 -08002352 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2353 mContext.enforceCallingOrSelfPermission(
2354 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2355 }
2356
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002357 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002358 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002359
2360 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002361 int size = mRemoveList.size();
2362 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2363 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002364 for (IBinder b: mRemoveList) {
2365 remove(b);
2366 }
2367 mRemoveList.clear();
2368 }
2369 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002370
2371 private boolean validateEventsAndUserLocked(Record r, int events) {
2372 int foregroundUser;
2373 long callingIdentity = Binder.clearCallingIdentity();
2374 boolean valid = false;
2375 try {
2376 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002377 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2378 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002379 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002380 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002381 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002382 + " r.events=" + r.events + " events=" + events);
2383 }
2384 } finally {
2385 Binder.restoreCallingIdentity(callingIdentity);
2386 }
2387 return valid;
2388 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002389
2390 private boolean validatePhoneId(int phoneId) {
2391 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002392 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002393 return valid;
2394 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002395
2396 private static void log(String s) {
2397 Rlog.d(TAG, s);
2398 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002399
chen xu627d1b22019-04-11 02:16:19 -07002400 private static void loge(String s) {
2401 Rlog.e(TAG, s);
2402 }
2403
xinhe8b79fb62014-11-05 14:55:03 -08002404 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002405
2406 if(subId < 0) {
2407 // Invalid case, we need compare phoneId with default one.
2408 return (mDefaultPhoneId == phoneId);
2409 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002410 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002411 return (subId == mDefaultSubId);
2412 } else {
2413 return (rSubId == subId);
2414 }
2415 }
2416
Hall Liuee313732018-11-27 14:36:51 -08002417 private boolean checkFineLocationAccess(Record r, int minSdk) {
2418 LocationAccessPolicy.LocationPermissionQuery query =
2419 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2420 .setCallingPackage(r.callingPackage)
2421 .setCallingPid(r.callerPid)
2422 .setCallingUid(r.callerUid)
2423 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002424 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002425 .setMinSdkVersionForFine(minSdk)
2426 .build();
2427
2428 return Binder.withCleanCallingIdentity(() -> {
2429 LocationAccessPolicy.LocationPermissionResult locationResult =
2430 LocationAccessPolicy.checkLocationPermission(mContext, query);
2431 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2432 });
2433 }
2434
2435 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2436 LocationAccessPolicy.LocationPermissionQuery query =
2437 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2438 .setCallingPackage(r.callingPackage)
2439 .setCallingPid(r.callerPid)
2440 .setCallingUid(r.callerUid)
2441 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002442 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002443 .setMinSdkVersionForCoarse(minSdk)
2444 .build();
2445
2446 return Binder.withCleanCallingIdentity(() -> {
2447 LocationAccessPolicy.LocationPermissionResult locationResult =
2448 LocationAccessPolicy.checkLocationPermission(mContext, query);
2449 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2450 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002451 }
2452
xinhee9f16402014-09-25 16:39:28 -07002453 private void checkPossibleMissNotify(Record r, int phoneId) {
2454 int events = r.events;
2455
2456 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2457 try {
2458 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2459 mServiceState[phoneId]);
2460 r.callback.onServiceStateChanged(
2461 new ServiceState(mServiceState[phoneId]));
2462 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002463 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002464 }
2465 }
2466
2467 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2468 try {
2469 SignalStrength signalStrength = mSignalStrength[phoneId];
2470 if (DBG) {
2471 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2472 }
2473 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2474 } catch (RemoteException ex) {
2475 mRemoveList.add(r.binder);
2476 }
2477 }
2478
2479 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2480 try {
2481 int gsmSignalStrength = mSignalStrength[phoneId]
2482 .getGsmSignalStrength();
2483 if (DBG) {
2484 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2485 gsmSignalStrength);
2486 }
2487 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2488 : gsmSignalStrength));
2489 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002490 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002491 }
2492 }
2493
2494 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2495 try {
2496 if (DBG_LOC) {
2497 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2498 + mCellInfo.get(phoneId));
2499 }
Hall Liuee313732018-11-27 14:36:51 -08002500 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002501 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2502 }
xinhee9f16402014-09-25 16:39:28 -07002503 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002504 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002505 }
2506 }
2507
zxuan35a47022018-01-04 11:24:04 -08002508 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2509 try {
2510 if (VDBG) {
2511 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2512 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2513 }
2514 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2515 } catch (RemoteException ex) {
2516 mRemoveList.add(r.binder);
2517 }
2518 }
2519
xinhee9f16402014-09-25 16:39:28 -07002520 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2521 try {
2522 if (VDBG) {
2523 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2524 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2525 }
2526 r.callback.onMessageWaitingIndicatorChanged(
2527 mMessageWaiting[phoneId]);
2528 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002529 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002530 }
2531 }
2532
2533 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2534 try {
2535 if (VDBG) {
2536 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2537 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2538 }
2539 r.callback.onCallForwardingIndicatorChanged(
2540 mCallForwarding[phoneId]);
2541 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002542 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002543 }
2544 }
2545
2546 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2547 try {
2548 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2549 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002550 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002551 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2552 }
xinhee9f16402014-09-25 16:39:28 -07002553 } catch (RemoteException ex) {
2554 mRemoveList.add(r.binder);
2555 }
2556 }
2557
2558 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2559 try {
2560 if (DBG) {
2561 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2562 + "=" + mDataConnectionState[phoneId]
2563 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2564 + ")");
2565 }
2566 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2567 mDataConnectionNetworkType[phoneId]);
2568 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002569 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002570 }
2571 }
2572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573}