blob: 2f1510e32311a15007295585f1aac5371d692230 [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;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
Jordan Liu8218ddd2018-11-28 11:22:39 -080035import android.telephony.CallAttributes;
36import android.telephony.CallQuality;
John Wang963db55d2012-03-30 16:04:06 -070037import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070038import android.telephony.CellLocation;
chen xu16e24cd2018-12-11 18:09:41 -080039import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020040import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080041import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070042import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070043import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080044import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020045import android.telephony.PreciseCallState;
46import android.telephony.PreciseDataConnectionState;
47import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070048import android.telephony.Rlog;
49import android.telephony.ServiceState;
50import android.telephony.SignalStrength;
51import android.telephony.SubscriptionManager;
52import android.telephony.TelephonyManager;
chen xu16e24cd2018-12-11 18:09:41 -080053import android.telephony.data.ApnSetting;
sqianbdc5a732018-10-26 13:27:51 -070054import android.telephony.emergency.EmergencyNumber;
chen xu6ac5fc12019-01-24 14:14:13 -080055import android.telephony.ims.ImsReasonInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070056import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070057import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070059import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080061import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070063import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080064import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070065import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080067import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060068import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070069import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070import com.android.server.am.BatteryStatsService;
71
Jack Yud19b6ae2017-04-05 14:12:09 -070072import java.io.FileDescriptor;
73import java.io.PrintWriter;
74import java.util.ArrayList;
sqian9f93a122018-12-03 22:40:41 -080075import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070076import java.util.List;
sqian9f93a122018-12-03 22:40:41 -080077import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080078import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080/**
Wink Savillee9b06d72009-05-18 21:47:50 -070081 * Since phone process can be restarted, this class provides a centralized place
82 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070083 *
84 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
85 * and 15973975 by saving the phoneId of the registrant and then using the
86 * phoneId when deciding to to make a callback. This is necessary because
87 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070088 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070089 * the dummy value conversion we properly do the callbacks.
90 *
91 * Eventually we may want to remove the notion of dummy value but for now this
92 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070094@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
95public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070097 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070098 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070099 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
101 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800102 Context context;
103
Svet Ganov16a16892015-04-16 10:32:04 -0700104 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -0700105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700107
Malcolm Chenabbfac22018-02-12 19:15:59 -0800108 TelephonyRegistryDeathRecipient deathRecipient;
109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800111 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700112 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700113
Hall Liu5fb337f2017-11-22 17:38:15 -0800114 int callerUid;
115 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700118
Wink Savilled09c4ca2014-11-22 10:08:16 -0800119 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700120
Wink Savilled09c4ca2014-11-22 10:08:16 -0800121 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800122
123 boolean matchPhoneStateListenerEvent(int events) {
124 return (callback != null) && ((events & this.events) != 0);
125 }
126
Wink Savilled09c4ca2014-11-22 10:08:16 -0800127 boolean matchOnSubscriptionsChangedListener() {
128 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800129 }
Wink Savillee380b982014-07-26 18:24:22 -0700130
Malcolm Chen13f31af2018-09-04 22:12:31 -0700131 boolean matchOnOpportunisticSubscriptionsChangedListener() {
132 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
133 }
134
Tyler Gunnf955e562018-04-26 14:43:31 -0700135 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800136 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700137 return TelephonyPermissions.checkReadCallLog(
138 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800139 } catch (SecurityException e) {
140 return false;
141 }
142 }
143
Wink Savillea12a7b32012-09-20 10:09:45 -0700144 @Override
145 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700146 return "{callingPackage=" + callingPackage + " binder=" + binder
147 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800148 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700149 + onSubscriptionsChangedListenerCallback
150 + " onOpportunisticSubscriptionsChangedListenererCallback="
151 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800152 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800153 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700154 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 }
156
157 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700158
Joe Onorato163d8d92010-10-21 13:21:20 -0400159 // access should be inside synchronized (mRecords) for these two fields
160 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
161 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 private final IBatteryStats mBatteryStats;
164
Svet Ganov16a16892015-04-16 10:32:04 -0700165 private final AppOpsManager mAppOps;
166
Malcolm Chen13f31af2018-09-04 22:12:31 -0700167 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
168
169 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800170
Wink Savillefb40dd42014-06-12 17:02:31 -0700171 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700172
Wink Savillefb40dd42014-06-12 17:02:31 -0700173 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700174
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700178
Jordan Liu8218ddd2018-11-28 11:22:39 -0800179 private int[] mNetworkType;
180
fionaxu12312f62016-11-14 13:32:14 -0800181 private int[] mVoiceActivationState;
182
183 private int[] mDataActivationState;
184
zxuan35a47022018-01-04 11:24:04 -0800185 private boolean[] mUserMobileDataState;
186
Wink Savillefb40dd42014-06-12 17:02:31 -0700187 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700188
Wink Savillefb40dd42014-06-12 17:02:31 -0700189 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700190
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700192
Wink Savillefb40dd42014-06-12 17:02:31 -0700193 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700194
Jack Yub1bac542018-03-14 16:23:38 -0700195 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700196 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700197
Wink Savillefb40dd42014-06-12 17:02:31 -0700198 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199
Wink Savillefb40dd42014-06-12 17:02:31 -0700200 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700201
Nathan Harold016e9c62016-12-14 11:24:48 -0800202 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700203
Wink Savillefb40dd42014-06-12 17:02:31 -0700204 private ArrayList<List<CellInfo>> mCellInfo = null;
205
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800206 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
207
sqian9f93a122018-12-03 22:40:41 -0800208 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
209
Jordan Liueae57b22019-01-22 16:17:35 -0800210 private CallQuality mCallQuality = new CallQuality();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800211
Jordan Liueae57b22019-01-22 16:17:35 -0800212 private CallAttributes mCallAttributes = new CallAttributes(new PreciseCallState(),
213 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
Jordan Liu8218ddd2018-11-28 11:22:39 -0800214
Brad Ebingerefed9822018-10-26 10:25:57 -0700215 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700216
Wink Savilled09c4ca2014-11-22 10:08:16 -0800217 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700218
Wink Savilled09c4ca2014-11-22 10:08:16 -0800219 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700220
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200221 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
222
223 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
224
225 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
226
227 private PreciseCallState mPreciseCallState = new PreciseCallState();
228
chen xu6a942d482018-12-12 19:59:30 -0800229 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
230
chen xu6ac5fc12019-01-24 14:14:13 -0800231 private List<ImsReasonInfo> mImsReasonInfo = null;
232
chen xu6a942d482018-12-12 19:59:30 -0800233 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
234
Andrew Flynn1f452642015-04-14 22:16:04 -0400235 private boolean mCarrierNetworkChangeState = false;
236
Malcolm Chene1623652018-08-08 20:27:45 -0700237 private PhoneCapability mPhoneCapability = null;
238
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700239 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
240
Chen Xu7395c632018-10-17 17:53:47 +0000241 @TelephonyManager.RadioPowerState
242 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
243
Jack Yud19b6ae2017-04-05 14:12:09 -0700244 private final LocalLog mLocalLog = new LocalLog(100);
245
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200246 private PreciseDataConnectionState mPreciseDataConnectionState =
247 new PreciseDataConnectionState();
248
Hall Liu70bbc162018-03-02 17:44:46 -0800249 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
250 PhoneStateListener.LISTEN_CELL_LOCATION
251 | PhoneStateListener.LISTEN_CELL_INFO;
252
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700253 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian9f93a122018-12-03 22:40:41 -0800254 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
255 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
256 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700257
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200258 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
259 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
260 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
261
Wink Savillea12a7b32012-09-20 10:09:45 -0700262 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700263 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700264
265 private final Handler mHandler = new Handler() {
266 @Override
267 public void handleMessage(Message msg) {
268 switch (msg.what) {
269 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700270 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700271 int numPhones = TelephonyManager.getDefault().getPhoneCount();
272 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700273 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700274 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700275 }
276 break;
277 }
xinhee9f16402014-09-25 16:39:28 -0700278 case MSG_UPDATE_DEFAULT_SUB: {
279 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700280 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700281 if (VDBG) {
282 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
283 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
284 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
285 }
286
287 //Due to possible risk condition,(notify call back using the new
288 //defaultSubId comes before new defaultSubId update) we need to recall all
289 //possible missed notify callback
290 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700291 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800292 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700293 checkPossibleMissNotify(r, newDefaultPhoneId);
294 }
295 }
296 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700297 }
298 mDefaultSubId = newDefaultSubId;
299 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700300 }
301 }
302 }
303 };
304
Malcolm Chenabbfac22018-02-12 19:15:59 -0800305 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
306
307 private final IBinder binder;
308
309 TelephonyRegistryDeathRecipient(IBinder binder) {
310 this.binder = binder;
311 }
312
313 @Override
314 public void binderDied() {
315 if (DBG) log("binderDied " + binder);
316 remove(binder);
317 }
318 }
319
Wink Savillea12a7b32012-09-20 10:09:45 -0700320 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
321 @Override
322 public void onReceive(Context context, Intent intent) {
323 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700324 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700325 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700326 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700327 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700328 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700329 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700330 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800331 PhoneConstants.SUBSCRIPTION_KEY,
332 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700333 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
334 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700335 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700336 log("onReceive:current mDefaultSubId=" + mDefaultSubId
337 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
338 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700339 }
xinhee9f16402014-09-25 16:39:28 -0700340
Junda Liu985f52c2015-02-23 16:06:51 -0800341 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700342 || (newDefaultPhoneId != mDefaultPhoneId))) {
343 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
344 newDefaultPhoneId, 0, newDefaultSubIdObj));
345 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700346 }
347 }
348 };
349
Wink Savillee9b06d72009-05-18 21:47:50 -0700350 // we keep a copy of all of the state so we can send it out when folks
351 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700353 // In these calls we call with the lock held. This is safe becasuse remote
354 // calls go through a oneway interface and local calls going through a
355 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700357 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
358 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700359 CellLocation location = CellLocation.getEmpty();
360
Wink Savillefb40dd42014-06-12 17:02:31 -0700361 mContext = context;
362 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700363
Wink Savillefb40dd42014-06-12 17:02:31 -0700364 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700365 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 mNumPhones = numPhones;
367 mCallState = new int[numPhones];
368 mDataActivity = new int[numPhones];
369 mDataConnectionState = new int[numPhones];
370 mDataConnectionNetworkType = new int[numPhones];
371 mCallIncomingNumber = new String[numPhones];
372 mServiceState = new ServiceState[numPhones];
Jordan Liu8218ddd2018-11-28 11:22:39 -0800373 mNetworkType = new int[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800374 mVoiceActivationState = new int[numPhones];
375 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800376 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700377 mSignalStrength = new SignalStrength[numPhones];
378 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700379 mCallForwarding = new boolean[numPhones];
380 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700381 mCellInfo = new ArrayList<List<CellInfo>>();
Brad Ebingerefed9822018-10-26 10:25:57 -0700382 mSrvccState = new int[numPhones];
chen xu6ac5fc12019-01-24 14:14:13 -0800383 mImsReasonInfo = new ArrayList<ImsReasonInfo>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800384 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
sqian9f93a122018-12-03 22:40:41 -0800385 mEmergencyNumberList = new HashMap<>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700386 for (int i = 0; i < numPhones; i++) {
387 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
388 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
389 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800390 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
391 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700392 mCallIncomingNumber[i] = "";
393 mServiceState[i] = new ServiceState();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800394 mNetworkType[i] = mServiceState[i].getVoiceNetworkType();
Wink Savillefb40dd42014-06-12 17:02:31 -0700395 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800396 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700397 mMessageWaiting[i] = false;
398 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700399 mCellLocation[i] = new Bundle();
400 mCellInfo.add(i, null);
chen xu6ac5fc12019-01-24 14:14:13 -0800401 mImsReasonInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700402 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700403 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700404 }
405
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700406 // Note that location can be null for non-phone builds like
407 // like the generic one.
408 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700409 for (int i = 0; i < numPhones; i++) {
410 location.fillInNotifierBundle(mCellLocation[i]);
411 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700412 }
Svet Ganov16a16892015-04-16 10:32:04 -0700413
414 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 }
416
Svetoslav Ganova0027152013-06-25 14:59:53 -0700417 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700418 // Watch for interesting updates
419 final IntentFilter filter = new IntentFilter();
420 filter.addAction(Intent.ACTION_USER_SWITCHED);
421 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700422 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700423 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700424 mContext.registerReceiver(mBroadcastReceiver, filter);
425 }
426
427 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700428 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800429 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700430 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800431 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800432 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700433 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
434 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 + " callback.asBinder=" + callback.asBinder());
436 }
437
Wink Savilled09c4ca2014-11-22 10:08:16 -0800438 synchronized (mRecords) {
439 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800440 IBinder b = callback.asBinder();
441 Record r = add(b);
442
443 if (r == null) {
444 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800445 }
446
Jeff Davidson29da89f2018-02-28 17:50:16 -0800447 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800448 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700449 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800450 r.callerUid = Binder.getCallingUid();
451 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800452 r.events = 0;
453 if (DBG) {
454 log("listen oscl: Register r=" + r);
455 }
456 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700457 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800458 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800459 if (VDBG) log("listen oscl: send to r=" + r);
460 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
461 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800462 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800463 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800464 remove(r.binder);
465 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800466 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700467 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800468 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800469 }
470 }
471
472 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800473 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800474 IOnSubscriptionsChangedListener callback) {
475 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800476 remove(callback.asBinder());
477 }
478
Malcolm Chen13f31af2018-09-04 22:12:31 -0700479
480 @Override
481 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
482 IOnSubscriptionsChangedListener callback) {
483 int callerUserId = UserHandle.getCallingUserId();
484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
485 if (VDBG) {
486 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
487 + " callerUserId=" + callerUserId + " callback=" + callback
488 + " callback.asBinder=" + callback.asBinder());
489 }
490
491 synchronized (mRecords) {
492 // register
493 IBinder b = callback.asBinder();
494 Record r = add(b);
495
496 if (r == null) {
497 return;
498 }
499
500 r.context = mContext;
501 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
502 r.callingPackage = callingPackage;
503 r.callerUid = Binder.getCallingUid();
504 r.callerPid = Binder.getCallingPid();
505 r.events = 0;
506 if (DBG) {
507 log("listen ooscl: Register r=" + r);
508 }
509 // Always notify when registration occurs if there has been a notification.
510 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
511 try {
512 if (VDBG) log("listen ooscl: send to r=" + r);
513 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
514 if (VDBG) log("listen ooscl: sent to r=" + r);
515 } catch (RemoteException e) {
516 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
517 remove(r.binder);
518 }
519 } else {
520 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
521 }
522 }
523 }
524
Wink Savillea374c3d2014-11-11 11:48:04 -0800525 @Override
526 public void notifySubscriptionInfoChanged() {
527 if (VDBG) log("notifySubscriptionInfoChanged:");
528 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700529 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800530 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
531 + mRecords.size());
532 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700533 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800534 mRemoveList.clear();
535 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800536 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800537 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800538 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
539 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
540 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800541 } catch (RemoteException ex) {
542 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
543 mRemoveList.add(r.binder);
544 }
545 }
546 }
547 handleRemoveListLocked();
548 }
549 }
550
551 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700552 public void notifyOpportunisticSubscriptionInfoChanged() {
553 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
554 synchronized (mRecords) {
555 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
556 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
557 + mRecords.size());
558 }
559 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
560 mRemoveList.clear();
561 for (Record r : mRecords) {
562 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
563 try {
564 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
565 r.onOpportunisticSubscriptionsChangedListenerCallback
566 .onSubscriptionsChanged();
567 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
568 } catch (RemoteException ex) {
569 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
570 mRemoveList.add(r.binder);
571 }
572 }
573 }
574 handleRemoveListLocked();
575 }
576 }
577
578 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
580 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800581 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
582 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700583 }
584
585 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700586 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700588 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700589 }
590
Svet Ganov16a16892015-04-16 10:32:04 -0700591 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700592 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700593 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700595 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700596 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700597 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
598 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700599 }
xinhe75c2c152014-10-16 11:49:45 -0700600
601 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800602 // Checks permission and throws SecurityException for disallowed operations. For pre-M
603 // apps whose runtime permission has been revoked, we return immediately to skip sending
604 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800605 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800606 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700607 }
608
yifan.baie620ce72017-12-22 14:59:57 +0800609 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 synchronized (mRecords) {
611 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800612 IBinder b = callback.asBinder();
613 Record r = add(b);
614
615 if (r == null) {
616 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 }
xinhe43c50292014-09-18 17:56:48 -0700618
Jeff Davidson29da89f2018-02-28 17:50:16 -0800619 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700620 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700621 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800622 r.callerUid = Binder.getCallingUid();
623 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700624 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
625 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800626 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800627 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700628 } else {//APP specify subID
629 r.subId = subId;
630 }
yifan.baie620ce72017-12-22 14:59:57 +0800631 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700633 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700634 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700635 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700636 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400638 try {
Wink Savillee380b982014-07-26 18:24:22 -0700639 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700640 r.callback.onServiceStateChanged(
641 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400642 } catch (RemoteException ex) {
643 remove(r.binder);
644 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 }
646 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
647 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700648 int gsmSignalStrength = mSignalStrength[phoneId]
649 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700650 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
651 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 } catch (RemoteException ex) {
653 remove(r.binder);
654 }
655 }
656 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
657 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700658 r.callback.onMessageWaitingIndicatorChanged(
659 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 } catch (RemoteException ex) {
661 remove(r.binder);
662 }
663 }
664 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
665 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700666 r.callback.onCallForwardingIndicatorChanged(
667 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 } catch (RemoteException ex) {
669 remove(r.binder);
670 }
671 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700672 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400673 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700674 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700675 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800676 if (checkLocationAccess(r)) {
677 r.callback.onCellLocationChanged(
678 new Bundle(mCellLocation[phoneId]));
679 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400680 } catch (RemoteException ex) {
681 remove(r.binder);
682 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 }
684 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
685 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700686 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700687 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 } catch (RemoteException ex) {
689 remove(r.binder);
690 }
691 }
692 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
693 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700694 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
695 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 } catch (RemoteException ex) {
697 remove(r.binder);
698 }
699 }
700 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
701 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700702 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 } catch (RemoteException ex) {
704 remove(r.binder);
705 }
706 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700707 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
708 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700709 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700710 } catch (RemoteException ex) {
711 remove(r.binder);
712 }
713 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700714 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
715 try {
716 r.callback.onOtaspChanged(mOtaspMode);
717 } catch (RemoteException ex) {
718 remove(r.binder);
719 }
720 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700721 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700722 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700723 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700724 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800725 if (checkLocationAccess(r)) {
726 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
727 }
John Wang963db55d2012-03-30 16:04:06 -0700728 } catch (RemoteException ex) {
729 remove(r.binder);
730 }
731 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200732 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
733 try {
734 r.callback.onPreciseCallStateChanged(mPreciseCallState);
735 } catch (RemoteException ex) {
736 remove(r.binder);
737 }
738 }
chen xu6a942d482018-12-12 19:59:30 -0800739 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
740 try {
741 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
742 mCallPreciseDisconnectCause);
743 } catch (RemoteException ex) {
744 remove(r.binder);
745 }
746 }
chen xu6ac5fc12019-01-24 14:14:13 -0800747 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
748 try {
749 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
750 } catch (RemoteException ex) {
751 remove(r.binder);
752 }
753 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200754 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
755 try {
756 r.callback.onPreciseDataConnectionStateChanged(
757 mPreciseDataConnectionState);
758 } catch (RemoteException ex) {
759 remove(r.binder);
760 }
761 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400762 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
763 try {
764 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
765 } catch (RemoteException ex) {
766 remove(r.binder);
767 }
768 }
fionaxu12312f62016-11-14 13:32:14 -0800769 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
770 try {
771 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
772 } catch (RemoteException ex) {
773 remove(r.binder);
774 }
775 }
776 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
777 try {
778 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
779 } catch (RemoteException ex) {
780 remove(r.binder);
781 }
782 }
zxuan35a47022018-01-04 11:24:04 -0800783 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
784 try {
785 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
786 } catch (RemoteException ex) {
787 remove(r.binder);
788 }
789 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800790 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
791 try {
792 r.callback.onPhysicalChannelConfigurationChanged(
793 mPhysicalChannelConfigs.get(phoneId));
794 } catch (RemoteException ex) {
795 remove(r.binder);
796 }
797 }
sqian9f93a122018-12-03 22:40:41 -0800798 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
799 try {
800 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
801 } catch (RemoteException ex) {
802 remove(r.binder);
803 }
804 }
Malcolm Chene1623652018-08-08 20:27:45 -0700805 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
806 try {
807 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
808 } catch (RemoteException ex) {
809 remove(r.binder);
810 }
811 }
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700812 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
813 try {
814 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
815 } catch (RemoteException ex) {
816 remove(r.binder);
817 }
818 }
Chen Xu7395c632018-10-17 17:53:47 +0000819 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
820 try {
821 r.callback.onRadioPowerStateChanged(mRadioPowerState);
822 } catch (RemoteException ex) {
823 remove(r.binder);
824 }
825 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700826 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
827 try {
828 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
829 } catch (RemoteException ex) {
830 remove(r.binder);
831 }
832 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800833 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
834 try {
835 r.callback.onCallAttributesChanged(mCallAttributes);
836 } catch (RemoteException ex) {
837 remove(r.binder);
838 }
839 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
841 }
842 } else {
xinhe75c2c152014-10-16 11:49:45 -0700843 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 remove(callback.asBinder());
845 }
846 }
847
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700848 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700849 // Only reveal the incoming number if the record has read call log permission.
850 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700851 }
852
Malcolm Chenabbfac22018-02-12 19:15:59 -0800853 private Record add(IBinder binder) {
854 Record r;
855
856 synchronized (mRecords) {
857 final int N = mRecords.size();
858 for (int i = 0; i < N; i++) {
859 r = mRecords.get(i);
860 if (binder == r.binder) {
861 // Already existed.
862 return r;
863 }
864 }
865 r = new Record();
866 r.binder = binder;
867 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
868
869 try {
870 binder.linkToDeath(r.deathRecipient, 0);
871 } catch (RemoteException e) {
872 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
873 // Binder already died. Return null.
874 return null;
875 }
876
877 mRecords.add(r);
878 if (DBG) log("add new record");
879 }
880
881 return r;
882 }
883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 private void remove(IBinder binder) {
885 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700886 final int recordCount = mRecords.size();
887 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800888 Record r = mRecords.get(i);
889 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800890 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800891 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
892 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800893 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800894
895 if (r.deathRecipient != null) {
896 try {
897 binder.unlinkToDeath(r.deathRecipient, 0);
898 } catch (NoSuchElementException e) {
899 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
900 + r + " e=" + e);
901 }
902 }
903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 mRecords.remove(i);
905 return;
906 }
907 }
908 }
909 }
910
Tyler Gunnf955e562018-04-26 14:43:31 -0700911 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700912 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700913 return;
914 }
xinhe43c50292014-09-18 17:56:48 -0700915
916 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700917 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700918 }
919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700921 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800922 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800923 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700925 // Ensure the listener has read call log permission; if they do not return
926 // an empty phone number.
927 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
928 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400930 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 }
932 }
933 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400934 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700936
937 // Called only by Telecomm to communicate call state across different phone accounts. So
938 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700939 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700940 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700941 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 }
943
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700944 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
945 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700946 if (!checkNotifyPermission("notifyCallState()")) {
947 return;
948 }
Wink Savillee380b982014-07-26 18:24:22 -0700949 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700950 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700951 + " state=" + state + " incomingNumber=" + incomingNumber);
952 }
953 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700954 if (validatePhoneId(phoneId)) {
955 mCallState[phoneId] = state;
956 mCallIncomingNumber[phoneId] = incomingNumber;
957 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800958 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700959 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800960 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700961 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700962 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
963 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700964 } catch (RemoteException ex) {
965 mRemoveList.add(r.binder);
966 }
967 }
968 }
969 }
970 handleRemoveListLocked();
971 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700972 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700973 }
974
Wink Saville63f03dd2014-10-23 10:44:45 -0700975 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700976 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700977 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700978 }
xinhe43c50292014-09-18 17:56:48 -0700979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700981 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
982 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700983 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700984 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700985 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700986 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700987 if (validatePhoneId(phoneId)) {
988 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700989
Jordan Liu8218ddd2018-11-28 11:22:39 -0800990 boolean notifyCallAttributes = true;
991 if (mNetworkType[phoneId] != mServiceState[phoneId].getVoiceNetworkType()) {
992 mNetworkType[phoneId] = state.getVoiceNetworkType();
993 mCallAttributes = new CallAttributes(mPreciseCallState, mNetworkType[phoneId],
994 mCallQuality);
995 } else {
996 // No change to network type, so no need to notify call attributes
997 notifyCallAttributes = false;
998 }
999
1000 if (mCallQuality == null) {
1001 // No call quality reported yet, so no need to notify call attributes
1002 notifyCallAttributes = false;
1003 }
1004
Wink Savillefb40dd42014-06-12 17:02:31 -07001005 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001006 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001007 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001008 + " phoneId=" + phoneId + " state=" + state);
1009 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001010 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001011 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 try {
Wink Savillee380b982014-07-26 18:24:22 -07001013 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001014 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001015 + " subId=" + subId + " phoneId=" + phoneId
1016 + " state=" + state);
1017 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001018 r.callback.onServiceStateChanged(new ServiceState(state));
1019 } catch (RemoteException ex) {
1020 mRemoveList.add(r.binder);
1021 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001022 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001023 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1024 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1025 try {
1026 r.callback.onCallAttributesChanged(mCallAttributes);
1027 } catch (RemoteException ex) {
1028 mRemoveList.add(r.binder);
1029 }
1030 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001032 } else {
Wink Savillebc027272014-09-08 14:50:58 -07001033 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001035 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001037 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 }
1039
fionaxu12312f62016-11-14 13:32:14 -08001040 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1041 int activationType, int activationState) {
1042 if (!checkNotifyPermission("notifySimActivationState()")){
1043 return;
1044 }
1045 if (VDBG) {
1046 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1047 + "type=" + activationType + " state=" + activationState);
1048 }
1049 synchronized (mRecords) {
1050 if (validatePhoneId(phoneId)) {
1051 switch (activationType) {
1052 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
1053 mVoiceActivationState[phoneId] = activationState;
1054 break;
1055 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
1056 mDataActivationState[phoneId] = activationState;
1057 break;
1058 default:
1059 return;
1060 }
1061 for (Record r : mRecords) {
1062 if (VDBG) {
1063 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1064 + " phoneId=" + phoneId + "type=" + activationType
1065 + " state=" + activationState);
1066 }
1067 try {
1068 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1069 r.matchPhoneStateListenerEvent(
1070 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1071 idMatch(r.subId, subId, phoneId)) {
1072 if (DBG) {
1073 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1074 + " subId=" + subId + " phoneId=" + phoneId
1075 + " state=" + activationState);
1076 }
1077 r.callback.onVoiceActivationStateChanged(activationState);
1078 }
1079 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1080 r.matchPhoneStateListenerEvent(
1081 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1082 idMatch(r.subId, subId, phoneId)) {
1083 if (DBG) {
1084 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1085 + " subId=" + subId + " phoneId=" + phoneId
1086 + " state=" + activationState);
1087 }
1088 r.callback.onDataActivationStateChanged(activationState);
1089 }
1090 } catch (RemoteException ex) {
1091 mRemoveList.add(r.binder);
1092 }
1093 }
1094 } else {
1095 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1096 }
1097 handleRemoveListLocked();
1098 }
1099 }
1100
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001101 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1102 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001103 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001104 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001105 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001106 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001107 log("notifySignalStrengthForPhoneId: subId=" + subId
1108 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001109 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001112 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001113 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001114 mSignalStrength[phoneId] = signalStrength;
1115 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001116 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001117 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001118 + " phoneId=" + phoneId + " ss=" + signalStrength);
1119 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001120 if (r.matchPhoneStateListenerEvent(
1121 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001122 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001123 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001124 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001125 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001126 + " subId=" + subId + " phoneId=" + phoneId
1127 + " ss=" + signalStrength);
1128 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001129 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1130 } catch (RemoteException ex) {
1131 mRemoveList.add(r.binder);
1132 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001133 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001134 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001135 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001136 try {
1137 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001138 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001139 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001140 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001141 + " subId=" + subId + " phoneId=" + phoneId
1142 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1143 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001144 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001145 } catch (RemoteException ex) {
1146 mRemoveList.add(r.binder);
1147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 }
1149 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001150 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001151 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001153 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001155 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 }
1157
Andrew Flynn1f452642015-04-14 22:16:04 -04001158 @Override
1159 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001160 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1161
Andrew Flynn1f452642015-04-14 22:16:04 -04001162 if (VDBG) {
1163 log("notifyCarrierNetworkChange: active=" + active);
1164 }
1165
1166 synchronized (mRecords) {
1167 mCarrierNetworkChangeState = active;
1168 for (Record r : mRecords) {
1169 if (r.matchPhoneStateListenerEvent(
1170 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1171 try {
1172 r.callback.onCarrierNetworkChange(active);
1173 } catch (RemoteException ex) {
1174 mRemoveList.add(r.binder);
1175 }
1176 }
1177 }
1178 handleRemoveListLocked();
1179 }
1180 }
1181
Wink Savilleb208a242012-07-25 14:08:09 -07001182 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001183 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 }
1185
Wink Saville63f03dd2014-10-23 10:44:45 -07001186 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001187 if (!checkNotifyPermission("notifyCellInfo()")) {
1188 return;
1189 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001190 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001191 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001192 + " cellInfo=" + cellInfo);
1193 }
yifan.baie620ce72017-12-22 14:59:57 +08001194 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001195 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001196 if (validatePhoneId(phoneId)) {
1197 mCellInfo.set(phoneId, cellInfo);
1198 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001199 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001200 idMatch(r.subId, subId, phoneId) &&
1201 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001202 try {
1203 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001204 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001205 }
1206 r.callback.onCellInfoChanged(cellInfo);
1207 } catch (RemoteException ex) {
1208 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001209 }
John Wang963db55d2012-03-30 16:04:06 -07001210 }
1211 }
1212 }
1213 handleRemoveListLocked();
1214 }
1215 }
1216
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001217 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1218 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1219 configs);
1220 }
1221
1222 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1223 List<PhysicalChannelConfig> configs) {
1224 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1225 return;
1226 }
1227
1228 if (VDBG) {
1229 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1230 }
1231
1232 synchronized (mRecords) {
1233 int phoneId = SubscriptionManager.getPhoneId(subId);
1234 if (validatePhoneId(phoneId)) {
1235 mPhysicalChannelConfigs.set(phoneId, configs);
1236 for (Record r : mRecords) {
1237 if (r.matchPhoneStateListenerEvent(
1238 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1239 && idMatch(r.subId, subId, phoneId)) {
1240 try {
1241 if (DBG_LOC) {
1242 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1243 + configs + " r=" + r);
1244 }
1245 r.callback.onPhysicalChannelConfigurationChanged(configs);
1246 } catch (RemoteException ex) {
1247 mRemoveList.add(r.binder);
1248 }
1249 }
1250 }
1251 }
1252 handleRemoveListLocked();
1253 }
1254 }
1255
xinhe43c50292014-09-18 17:56:48 -07001256 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001257 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001258 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001259 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001260 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001261 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001262 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001263 + " mwi=" + mwi);
1264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001266 if (validatePhoneId(phoneId)) {
1267 mMessageWaiting[phoneId] = mwi;
1268 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001269 if (r.matchPhoneStateListenerEvent(
1270 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001271 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001272 try {
1273 r.callback.onMessageWaitingIndicatorChanged(mwi);
1274 } catch (RemoteException ex) {
1275 mRemoveList.add(r.binder);
1276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 }
1278 }
1279 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001280 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 }
1282 }
1283
zxuan35a47022018-01-04 11:24:04 -08001284 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1285 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1286 return;
1287 }
1288 if (VDBG) {
1289 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1290 + " state=" + state);
1291 }
1292 synchronized (mRecords) {
1293 if (validatePhoneId(phoneId)) {
1294 mMessageWaiting[phoneId] = state;
1295 for (Record r : mRecords) {
1296 if (r.matchPhoneStateListenerEvent(
1297 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1298 idMatch(r.subId, subId, phoneId)) {
1299 try {
1300 r.callback.onUserMobileDataStateChanged(state);
1301 } catch (RemoteException ex) {
1302 mRemoveList.add(r.binder);
1303 }
1304 }
1305 }
1306 }
1307 handleRemoveListLocked();
1308 }
1309 }
1310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001312 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001313 }
1314
Wink Saville63f03dd2014-10-23 10:44:45 -07001315 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001316 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
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) {
Wink Savillebc027272014-09-08 14:50:58 -07001320 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001321 + " cfi=" + cfi);
1322 }
yifan.baie620ce72017-12-22 14:59:57 +08001323 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001325 if (validatePhoneId(phoneId)) {
1326 mCallForwarding[phoneId] = cfi;
1327 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001328 if (r.matchPhoneStateListenerEvent(
1329 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001330 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001331 try {
1332 r.callback.onCallForwardingIndicatorChanged(cfi);
1333 } catch (RemoteException ex) {
1334 mRemoveList.add(r.binder);
1335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 }
1337 }
1338 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001339 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 }
1341 }
1342
1343 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001344 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001345 }
1346
Wink Saville63f03dd2014-10-23 10:44:45 -07001347 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001348 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001349 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001350 }
yifan.baie620ce72017-12-22 14:59:57 +08001351 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001353 if (validatePhoneId(phoneId)) {
1354 mDataActivity[phoneId] = state;
1355 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001356 // Notify by correct subId.
1357 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1358 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001359 try {
1360 r.callback.onDataActivity(state);
1361 } catch (RemoteException ex) {
1362 mRemoveList.add(r.binder);
1363 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 }
1365 }
1366 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001367 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 }
1369 }
1370
Jack Yu4d1c9452019-01-02 16:51:08 -08001371 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1372 LinkProperties linkProperties,
1373 NetworkCapabilities networkCapabilities, int networkType,
1374 boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001375 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yu4d1c9452019-01-02 16:51:08 -08001376 isDataAllowed, apn, apnType, linkProperties,
1377 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001378 }
1379
Jack Yu4d1c9452019-01-02 16:51:08 -08001380 public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataAllowed,
1381 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001382 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1383 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001384 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001385 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001386 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001387 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001388 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001389 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001390 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001391 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001392 }
yifan.baie620ce72017-12-22 14:59:57 +08001393 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001395 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001396 // We only call the callback when the change is for default APN type.
1397 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1398 && (mDataConnectionState[phoneId] != state
1399 || mDataConnectionNetworkType[phoneId] != networkType)) {
1400 String str = "onDataConnectionStateChanged(" + state
1401 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001402 log(str);
1403 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001404 for (Record r : mRecords) {
1405 if (r.matchPhoneStateListenerEvent(
1406 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1407 idMatch(r.subId, subId, phoneId)) {
1408 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001409 if (DBG) {
1410 log("Notify data connection state changed on sub: " + subId);
1411 }
Jack Yub1bac542018-03-14 16:23:38 -07001412 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001413 } catch (RemoteException ex) {
1414 mRemoveList.add(r.binder);
1415 }
1416 }
1417 }
1418 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001419
1420 mDataConnectionState[phoneId] = state;
1421 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001422 }
1423 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
chen xu16e24cd2018-12-11 18:09:41 -08001424 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1425 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001426 for (Record r : mRecords) {
1427 if (r.matchPhoneStateListenerEvent(
1428 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1429 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001430 r.callback.onPreciseDataConnectionStateChanged(
1431 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001432 } catch (RemoteException ex) {
1433 mRemoveList.add(r.binder);
1434 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001435 }
1436 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001437 }
1438 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001440 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1441 networkCapabilities, roaming, subId);
1442 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu16e24cd2018-12-11 18:09:41 -08001443 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 }
1445
Jack Yu4d1c9452019-01-02 16:51:08 -08001446 public void notifyDataConnectionFailed(String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001447 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yu4d1c9452019-01-02 16:51:08 -08001448 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001449 }
1450
Jack Yu4d1c9452019-01-02 16:51:08 -08001451 public void notifyDataConnectionFailedForSubscriber(int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001452 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001453 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001454 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001455 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001456 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yu4d1c9452019-01-02 16:51:08 -08001457 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001458 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001460 mPreciseDataConnectionState = new PreciseDataConnectionState(
1461 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu16e24cd2018-12-11 18:09:41 -08001462 ApnSetting.getApnTypesBitmaskFromString(apnType), "", null,
1463 DataFailCause.NONE);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001464 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001465 if (r.matchPhoneStateListenerEvent(
1466 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001467 try {
1468 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1469 } catch (RemoteException ex) {
1470 mRemoveList.add(r.binder);
1471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 }
1473 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001474 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001476 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001477 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu16e24cd2018-12-11 18:09:41 -08001478 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", null,
1479 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 }
1481
1482 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001483 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001484 }
1485
Wink Saville63f03dd2014-10-23 10:44:45 -07001486 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001487 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001488 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001489 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001490 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001491 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001492 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001493 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001494 + " cellLocation=" + cellLocation);
1495 }
yifan.baie620ce72017-12-22 14:59:57 +08001496 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001498 if (validatePhoneId(phoneId)) {
1499 mCellLocation[phoneId] = cellLocation;
1500 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001501 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001502 idMatch(r.subId, subId, phoneId) &&
1503 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001504 try {
1505 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001506 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001507 + " r=" + r);
1508 }
1509 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1510 } catch (RemoteException ex) {
1511 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001512 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 }
1515 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001516 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001517 }
1518 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519
Wink Savillefd2d0132010-10-28 14:22:26 -07001520 public void notifyOtaspChanged(int otaspMode) {
1521 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1522 return;
1523 }
1524 synchronized (mRecords) {
1525 mOtaspMode = otaspMode;
1526 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001527 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001528 try {
1529 r.callback.onOtaspChanged(otaspMode);
1530 } catch (RemoteException ex) {
1531 mRemoveList.add(r.binder);
1532 }
1533 }
1534 }
1535 handleRemoveListLocked();
1536 }
1537 }
1538
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001539 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001540 int backgroundCallState, int phoneId) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001541 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1542 return;
1543 }
1544 synchronized (mRecords) {
1545 mRingingCallState = ringingCallState;
1546 mForegroundCallState = foregroundCallState;
1547 mBackgroundCallState = backgroundCallState;
1548 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1549 backgroundCallState,
1550 DisconnectCause.NOT_VALID,
1551 PreciseDisconnectCause.NOT_VALID);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001552 boolean notifyCallAttributes = true;
1553 if (mCallQuality == null) {
1554 log("notifyPreciseCallState: mCallQuality is null, skipping call attributes");
1555 notifyCallAttributes = false;
1556 } else {
1557 mCallAttributes = new CallAttributes(mPreciseCallState, mNetworkType[phoneId],
1558 mCallQuality);
1559 }
1560
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001561 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001562 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001563 try {
1564 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1565 } catch (RemoteException ex) {
1566 mRemoveList.add(r.binder);
1567 }
1568 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001569 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1570 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1571 try {
1572 r.callback.onCallAttributesChanged(mCallAttributes);
1573 } catch (RemoteException ex) {
1574 mRemoveList.add(r.binder);
1575 }
1576 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001577 }
1578 handleRemoveListLocked();
1579 }
chen xu6a942d482018-12-12 19:59:30 -08001580 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1581 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001582 }
1583
1584 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1585 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1586 return;
1587 }
1588 synchronized (mRecords) {
chen xu6a942d482018-12-12 19:59:30 -08001589 mCallDisconnectCause = disconnectCause;
1590 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001591 for (Record r : mRecords) {
chen xu6a942d482018-12-12 19:59:30 -08001592 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1593 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001594 try {
chen xu6a942d482018-12-12 19:59:30 -08001595 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1596 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001597 } catch (RemoteException ex) {
1598 mRemoveList.add(r.binder);
1599 }
1600 }
1601 }
1602 handleRemoveListLocked();
1603 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001604 }
1605
chen xu6ac5fc12019-01-24 14:14:13 -08001606 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1607 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1608 return;
1609 }
1610 int phoneId = SubscriptionManager.getPhoneId(subId);
1611 synchronized (mRecords) {
1612 if (validatePhoneId(phoneId)) {
1613 mImsReasonInfo.set(phoneId, imsReasonInfo);
1614 for (Record r : mRecords) {
1615 if (r.matchPhoneStateListenerEvent(
1616 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1617 && idMatch(r.subId, subId, phoneId)) {
1618 try {
1619 if (DBG_LOC) {
1620 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1621 + imsReasonInfo + " r=" + r);
1622 }
1623 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1624 } catch (RemoteException ex) {
1625 mRemoveList.add(r.binder);
1626 }
1627 }
1628 }
1629 }
1630 handleRemoveListLocked();
1631 }
1632 }
1633
chen xu16e24cd2018-12-11 18:09:41 -08001634 public void notifyPreciseDataConnectionFailed(String apnType,
1635 String apn, @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001636 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1637 return;
1638 }
1639 synchronized (mRecords) {
1640 mPreciseDataConnectionState = new PreciseDataConnectionState(
1641 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu16e24cd2018-12-11 18:09:41 -08001642 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001643 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001644 if (r.matchPhoneStateListenerEvent(
1645 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001646 try {
1647 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1648 } catch (RemoteException ex) {
1649 mRemoveList.add(r.binder);
1650 }
1651 }
1652 }
1653 handleRemoveListLocked();
1654 }
1655 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yu4d1c9452019-01-02 16:51:08 -08001656 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001657 }
1658
Brad Ebingerefed9822018-10-26 10:25:57 -07001659 @Override
1660 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1661 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001662 return;
1663 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001664 if (VDBG) {
1665 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1666 }
1667 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001668 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001669 if (validatePhoneId(phoneId)) {
chen xu6ac5fc12019-01-24 14:14:13 -08001670 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001671 for (Record r : mRecords) {
1672 if (r.matchPhoneStateListenerEvent(
1673 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1674 idMatch(r.subId, subId, phoneId)) {
1675 try {
1676 if (DBG_LOC) {
1677 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1678 }
1679 r.callback.onSrvccStateChanged(state);
1680 } catch (RemoteException ex) {
1681 mRemoveList.add(r.binder);
1682 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001683 }
1684 }
1685 }
1686 handleRemoveListLocked();
1687 }
1688 }
1689
Shuo Qian066e8652018-04-25 21:02:35 +00001690 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1691 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1692 return;
1693 }
1694
1695 synchronized (mRecords) {
1696 for (Record r : mRecords) {
1697 if (VDBG) {
1698 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1699 }
1700 if ((r.matchPhoneStateListenerEvent(
1701 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1702 ((r.subId == subId) ||
1703 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1704 try {
1705 r.callback.onOemHookRawEvent(rawData);
1706 } catch (RemoteException ex) {
1707 mRemoveList.add(r.binder);
1708 }
1709 }
1710 }
1711 handleRemoveListLocked();
1712 }
1713 }
1714
Malcolm Chene1623652018-08-08 20:27:45 -07001715 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1716 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1717 return;
1718 }
1719
1720 if (VDBG) {
1721 log("notifyPhoneCapabilityChanged: capability=" + capability);
1722 }
1723
1724 synchronized (mRecords) {
1725 mPhoneCapability = capability;
1726
1727 for (Record r : mRecords) {
1728 if (r.matchPhoneStateListenerEvent(
1729 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1730 try {
1731 r.callback.onPhoneCapabilityChanged(capability);
1732 } catch (RemoteException ex) {
1733 mRemoveList.add(r.binder);
1734 }
1735 }
1736 }
1737 handleRemoveListLocked();
1738 }
1739 }
1740
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001741 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1742 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1743 return;
1744 }
1745
1746 if (VDBG) {
1747 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1748 }
1749
1750 synchronized (mRecords) {
1751 mPreferredDataSubId = preferredSubId;
1752
1753 for (Record r : mRecords) {
1754 if (r.matchPhoneStateListenerEvent(
1755 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1756 try {
1757 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1758 } catch (RemoteException ex) {
1759 mRemoveList.add(r.binder);
1760 }
1761 }
1762 }
1763 handleRemoveListLocked();
1764 }
1765 }
Malcolm Chene1623652018-08-08 20:27:45 -07001766
Chen Xu7395c632018-10-17 17:53:47 +00001767 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1768 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1769 return;
1770 }
1771
1772 if (VDBG) {
1773 log("notifyRadioPowerStateChanged: state= " + state);
1774 }
1775
1776 synchronized (mRecords) {
1777 mRadioPowerState = state;
1778
1779 for (Record r : mRecords) {
1780 if (r.matchPhoneStateListenerEvent(
1781 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1782 try {
1783 r.callback.onRadioPowerStateChanged(state);
1784 } catch (RemoteException ex) {
1785 mRemoveList.add(r.binder);
1786 }
1787 }
1788 }
1789 handleRemoveListLocked();
1790 }
1791 }
1792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 @Override
sqian9f93a122018-12-03 22:40:41 -08001794 public void notifyEmergencyNumberList() {
1795 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1796 return;
1797 }
1798
1799 synchronized (mRecords) {
sqianb0ae02b2018-12-14 21:47:49 -08001800 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1801 Context.TELEPHONY_SERVICE);
1802 mEmergencyNumberList = tm.getCurrentEmergencyNumberList();
sqian9f93a122018-12-03 22:40:41 -08001803
1804 for (Record r : mRecords) {
1805 if (r.matchPhoneStateListenerEvent(
1806 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)) {
1807 try {
1808 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1809 if (VDBG) {
1810 log("notifyEmergencyNumberList: emergencyNumberList= "
1811 + mEmergencyNumberList);
1812 }
1813 } catch (RemoteException ex) {
1814 mRemoveList.add(r.binder);
1815 }
1816 }
1817 }
1818 handleRemoveListLocked();
1819 }
sqianbdc5a732018-10-26 13:27:51 -07001820 }
1821
Jordan Liu8218ddd2018-11-28 11:22:39 -08001822 @Override
1823 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId) {
1824 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
1825 return;
1826 }
1827
1828 // merge CallQuality with PreciseCallState and network type
1829 mCallQuality = callQuality;
1830 mCallAttributes = new CallAttributes(mPreciseCallState,
1831 mNetworkType[phoneId],
1832 callQuality);
1833
1834 synchronized (mRecords) {
1835 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1836 Context.TELEPHONY_SERVICE);
1837
1838 for (Record r : mRecords) {
1839 if (r.matchPhoneStateListenerEvent(
1840 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1841 try {
1842 r.callback.onCallAttributesChanged(mCallAttributes);
1843 } catch (RemoteException ex) {
1844 mRemoveList.add(r.binder);
1845 }
1846 }
1847 }
1848 handleRemoveListLocked();
1849 }
1850 }
1851
sqianbdc5a732018-10-26 13:27:51 -07001852
1853 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001854 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1855 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1856
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001857 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001859 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001860 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001862 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301863 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001864 pw.println("Phone Id=" + i);
1865 pw.increaseIndent();
1866 pw.println("mCallState=" + mCallState[i]);
1867 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1868 pw.println("mServiceState=" + mServiceState[i]);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001869 pw.println("mNetworkType=" + mNetworkType[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001870 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1871 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001872 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001873 pw.println("mSignalStrength=" + mSignalStrength[i]);
1874 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1875 pw.println("mCallForwarding=" + mCallForwarding[i]);
1876 pw.println("mDataActivity=" + mDataActivity[i]);
1877 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001878 pw.println("mCellLocation=" + mCellLocation[i]);
1879 pw.println("mCellInfo=" + mCellInfo.get(i));
chen xu6ac5fc12019-01-24 14:14:13 -08001880 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i).toString());
Jack Yud19b6ae2017-04-05 14:12:09 -07001881 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301882 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001883 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1884 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu6a942d482018-12-12 19:59:30 -08001885 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1886 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001887 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1888 pw.println("mRingingCallState=" + mRingingCallState);
1889 pw.println("mForegroundCallState=" + mForegroundCallState);
1890 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001891 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chene1623652018-08-08 20:27:45 -07001892 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001893 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00001894 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian9f93a122018-12-03 22:40:41 -08001895 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001896 pw.println("mCallQuality=" + mCallQuality);
1897 pw.println("mCallAttributes=" + mCallAttributes);
Jack Yud19b6ae2017-04-05 14:12:09 -07001898
1899 pw.decreaseIndent();
1900
1901 pw.println("local logs:");
1902 pw.increaseIndent();
1903 mLocalLog.dump(fd, pw, args);
1904 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001905 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001906 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001907 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001908 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001910 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 }
1912 }
1913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001914 //
1915 // the legacy intent broadcasting
1916 //
1917
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001918 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001919 long ident = Binder.clearCallingIdentity();
1920 try {
1921 mBatteryStats.notePhoneState(state.getState());
1922 } catch (RemoteException re) {
1923 // Can't do much
1924 } finally {
1925 Binder.restoreCallingIdentity(ident);
1926 }
1927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001929 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 Bundle data = new Bundle();
1931 state.fillInNotifierBundle(data);
1932 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001933 // Pass the subscription along with the intent.
1934 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001935 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001936 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001937 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 }
1939
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001940 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1941 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001942 long ident = Binder.clearCallingIdentity();
1943 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001944 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001945 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001946 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001947 } finally {
1948 Binder.restoreCallingIdentity(ident);
1949 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001952 Bundle data = new Bundle();
1953 signalStrength.fillInNotifierBundle(data);
1954 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001955 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001956 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001957 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 }
1959
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001960 /**
1961 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1962 * a valid subId, in which case this function fires a subId-specific intent, or it
1963 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1964 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1965 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001966 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1967 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 long ident = Binder.clearCallingIdentity();
1969 try {
1970 if (state == TelephonyManager.CALL_STATE_IDLE) {
1971 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001972 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1973 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 } else {
1975 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001976 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1977 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 }
1979 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001980 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 } finally {
1982 Binder.restoreCallingIdentity(ident);
1983 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001986 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001987 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001988
1989 // If a valid subId was specified, we should fire off a subId-specific state
1990 // change intent and include the subId.
1991 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1992 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1993 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001994 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001995 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001996 // If the phoneId is invalid, the broadcast is for overall call state.
1997 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1998 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1999 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002000
Brad Ebinger51de96a2017-04-21 17:05:18 -07002001 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
2002 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
2003
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002004 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002005 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002006 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2007
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002008 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2009 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002010 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002011 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002012 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002013 android.Manifest.permission.READ_PHONE_STATE,
2014 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002015 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2016 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2017 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 }
2019
Jack Yu4d1c9452019-01-02 16:51:08 -08002020 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2021 String apnType, LinkProperties linkProperties,
2022 NetworkCapabilities networkCapabilities,
2023 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002024 // Note: not reporting to the battery stats service here, because the
2025 // status bar takes care of that after taking into account all of the
2026 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002028 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002029 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07002030 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002031 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002033 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002034 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002035 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002036 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002037 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002038 }
2039 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002040 if (networkCapabilities != null) {
2041 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002042 }
Wink Savillea639b312012-07-10 12:37:54 -07002043 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002044
Wink Savillea639b312012-07-10 12:37:54 -07002045 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2046 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002047 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002048 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002049 }
2050
Jack Yu4d1c9452019-01-02 16:51:08 -08002051 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002053 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002054 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002055 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002057
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002058 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yu4d1c9452019-01-02 16:51:08 -08002059 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002060 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2061 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2062 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2063 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002064 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2065 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2066 }
2067
2068 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu16e24cd2018-12-11 18:09:41 -08002069 String apnType, String apn, LinkProperties linkProperties,
2070 @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002071 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2072 intent.putExtra(PhoneConstants.STATE_KEY, state);
2073 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002074 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2075 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002076 if (linkProperties != null) {
Jack Yu4d1c9452019-01-02 16:51:08 -08002077 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002078 }
chen xu16e24cd2018-12-11 18:09:41 -08002079 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002080
2081 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2082 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2083 }
2084
Andrew Flynnceaed682015-06-09 12:36:58 +00002085 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002086 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002087 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002088 }
2089
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002090 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2091 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002092 }
2093
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002094 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002095 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002096 return true;
2097 }
2098 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002099 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002100 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002101 return false;
2102 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002103
Andrew Flynn1f452642015-04-14 22:16:04 -04002104 private boolean checkNotifyPermission() {
2105 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2106 == PackageManager.PERMISSION_GRANTED;
2107 }
2108
Jeff Davidson29da89f2018-02-28 17:50:16 -08002109 private boolean checkListenerPermission(
2110 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08002111 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002112 mContext.enforceCallingOrSelfPermission(
2113 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08002114 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
2115 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2116 return false;
2117 }
John Wang963db55d2012-03-30 16:04:06 -07002118 }
2119
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002120 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2122 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002123 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002124 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002125 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002126
2127 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2128 mContext.enforceCallingOrSelfPermission(
2129 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002130 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002131
Shuo Qian066e8652018-04-25 21:02:35 +00002132 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2133 mContext.enforceCallingOrSelfPermission(
2134 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2135 }
2136
Brad Ebingerefed9822018-10-26 10:25:57 -07002137 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2138 mContext.enforceCallingOrSelfPermission(
2139 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2140 }
2141
Malcolm Chen7e22ba62018-12-11 13:56:53 -08002142 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
2143 // It can have either READ_PHONE_STATE or READ_PRIVILEGED_PHONE_STATE.
2144 TelephonyPermissions.checkReadPhoneState(mContext,
2145 SubscriptionManager.INVALID_SUBSCRIPTION_ID, Binder.getCallingPid(),
2146 Binder.getCallingUid(), callingPackage, "listen to "
2147 + "LISTEN_PREFERRED_DATA_SUBID_CHANGE");
2148 }
Brad Ebingerefed9822018-10-26 10:25:57 -07002149
chen xu6a942d482018-12-12 19:59:30 -08002150 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2151 mContext.enforceCallingOrSelfPermission(
2152 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2153 }
2154
Jordan Liu8218ddd2018-11-28 11:22:39 -08002155 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2156 mContext.enforceCallingOrSelfPermission(
2157 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2158 }
2159
chen xu52797b62019-01-18 13:16:31 -08002160 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2161 mContext.enforceCallingOrSelfPermission(
2162 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2163 }
2164
2165 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2166 mContext.enforceCallingOrSelfPermission(
2167 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2168 }
2169
chen xu6ac5fc12019-01-24 14:14:13 -08002170 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2171 mContext.enforceCallingOrSelfPermission(
2172 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2173 }
2174
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002175 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002176 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002177
2178 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002179 int size = mRemoveList.size();
2180 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2181 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002182 for (IBinder b: mRemoveList) {
2183 remove(b);
2184 }
2185 mRemoveList.clear();
2186 }
2187 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002188
2189 private boolean validateEventsAndUserLocked(Record r, int events) {
2190 int foregroundUser;
2191 long callingIdentity = Binder.clearCallingIdentity();
2192 boolean valid = false;
2193 try {
2194 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002195 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2196 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002197 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002198 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002199 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002200 + " r.events=" + r.events + " events=" + events);
2201 }
2202 } finally {
2203 Binder.restoreCallingIdentity(callingIdentity);
2204 }
2205 return valid;
2206 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002207
2208 private boolean validatePhoneId(int phoneId) {
2209 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002210 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002211 return valid;
2212 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002213
2214 private static void log(String s) {
2215 Rlog.d(TAG, s);
2216 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002217
xinhe8b79fb62014-11-05 14:55:03 -08002218 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002219
2220 if(subId < 0) {
2221 // Invalid case, we need compare phoneId with default one.
2222 return (mDefaultPhoneId == phoneId);
2223 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002224 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002225 return (subId == mDefaultSubId);
2226 } else {
2227 return (rSubId == subId);
2228 }
2229 }
2230
Hall Liu5fb337f2017-11-22 17:38:15 -08002231 private boolean checkLocationAccess(Record r) {
2232 long token = Binder.clearCallingIdentity();
2233 try {
2234 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08002235 r.callingPackage, r.callerUid, r.callerPid,
2236 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08002237 } finally {
2238 Binder.restoreCallingIdentity(token);
2239 }
2240 }
2241
xinhee9f16402014-09-25 16:39:28 -07002242 private void checkPossibleMissNotify(Record r, int phoneId) {
2243 int events = r.events;
2244
2245 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2246 try {
2247 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2248 mServiceState[phoneId]);
2249 r.callback.onServiceStateChanged(
2250 new ServiceState(mServiceState[phoneId]));
2251 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002252 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002253 }
2254 }
2255
2256 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2257 try {
2258 SignalStrength signalStrength = mSignalStrength[phoneId];
2259 if (DBG) {
2260 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2261 }
2262 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2263 } catch (RemoteException ex) {
2264 mRemoveList.add(r.binder);
2265 }
2266 }
2267
2268 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2269 try {
2270 int gsmSignalStrength = mSignalStrength[phoneId]
2271 .getGsmSignalStrength();
2272 if (DBG) {
2273 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2274 gsmSignalStrength);
2275 }
2276 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2277 : gsmSignalStrength));
2278 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002279 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002280 }
2281 }
2282
2283 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2284 try {
2285 if (DBG_LOC) {
2286 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2287 + mCellInfo.get(phoneId));
2288 }
Hall Liu5fb337f2017-11-22 17:38:15 -08002289 if (checkLocationAccess(r)) {
2290 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2291 }
xinhee9f16402014-09-25 16:39:28 -07002292 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002293 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002294 }
2295 }
2296
zxuan35a47022018-01-04 11:24:04 -08002297 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2298 try {
2299 if (VDBG) {
2300 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2301 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2302 }
2303 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2304 } catch (RemoteException ex) {
2305 mRemoveList.add(r.binder);
2306 }
2307 }
2308
xinhee9f16402014-09-25 16:39:28 -07002309 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2310 try {
2311 if (VDBG) {
2312 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2313 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2314 }
2315 r.callback.onMessageWaitingIndicatorChanged(
2316 mMessageWaiting[phoneId]);
2317 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002318 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002319 }
2320 }
2321
2322 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2323 try {
2324 if (VDBG) {
2325 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2326 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2327 }
2328 r.callback.onCallForwardingIndicatorChanged(
2329 mCallForwarding[phoneId]);
2330 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002331 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002332 }
2333 }
2334
2335 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2336 try {
2337 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2338 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002339 if (checkLocationAccess(r)) {
2340 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2341 }
xinhee9f16402014-09-25 16:39:28 -07002342 } catch (RemoteException ex) {
2343 mRemoveList.add(r.binder);
2344 }
2345 }
2346
2347 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2348 try {
2349 if (DBG) {
2350 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2351 + "=" + mDataConnectionState[phoneId]
2352 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2353 + ")");
2354 }
2355 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2356 mDataConnectionNetworkType[phoneId]);
2357 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002358 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002359 }
2360 }
2361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362}