blob: 5633082ce4b3a974a2af52f465ace4f174d7bb17 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
Hall Liuee313732018-11-27 14:36:51 -080029import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070031import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070033import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070035import android.os.UserHandle;
Jordan Liu8218ddd2018-11-28 11:22:39 -080036import android.telephony.CallAttributes;
37import android.telephony.CallQuality;
John Wang963db55d2012-03-30 16:04:06 -070038import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070039import android.telephony.CellLocation;
chen xu16e24cd2018-12-11 18:09:41 -080040import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020041import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080042import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070043import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070044import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080045import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020046import android.telephony.PreciseCallState;
47import android.telephony.PreciseDataConnectionState;
48import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070049import android.telephony.Rlog;
50import android.telephony.ServiceState;
51import android.telephony.SignalStrength;
52import android.telephony.SubscriptionManager;
53import android.telephony.TelephonyManager;
chen xu16e24cd2018-12-11 18:09:41 -080054import android.telephony.data.ApnSetting;
sqianbdc5a732018-10-26 13:27:51 -070055import android.telephony.emergency.EmergencyNumber;
chen xu6ac5fc12019-01-24 14:14:13 -080056import android.telephony.ims.ImsReasonInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070057import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070058import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070060import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080062import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070064import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080065import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070066import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080068import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060069import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070070import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import com.android.server.am.BatteryStatsService;
72
Jack Yud19b6ae2017-04-05 14:12:09 -070073import java.io.FileDescriptor;
74import java.io.PrintWriter;
75import java.util.ArrayList;
sqian9f93a122018-12-03 22:40:41 -080076import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070077import java.util.List;
sqian9f93a122018-12-03 22:40:41 -080078import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080079import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081/**
Wink Savillee9b06d72009-05-18 21:47:50 -070082 * Since phone process can be restarted, this class provides a centralized place
83 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070084 *
85 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
86 * and 15973975 by saving the phoneId of the registrant and then using the
87 * phoneId when deciding to to make a callback. This is necessary because
88 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070089 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070090 * the dummy value conversion we properly do the callbacks.
91 *
92 * Eventually we may want to remove the notion of dummy value but for now this
93 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070095@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
96public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070098 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070099 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -0700100 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
102 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800103 Context context;
104
Svet Ganov16a16892015-04-16 10:32:04 -0700105 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700108
Malcolm Chenabbfac22018-02-12 19:15:59 -0800109 TelephonyRegistryDeathRecipient deathRecipient;
110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800112 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700113 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700114
Hall Liu5fb337f2017-11-22 17:38:15 -0800115 int callerUid;
116 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700119
Wink Savilled09c4ca2014-11-22 10:08:16 -0800120 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700121
Wink Savilled09c4ca2014-11-22 10:08:16 -0800122 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800123
124 boolean matchPhoneStateListenerEvent(int events) {
125 return (callback != null) && ((events & this.events) != 0);
126 }
127
Wink Savilled09c4ca2014-11-22 10:08:16 -0800128 boolean matchOnSubscriptionsChangedListener() {
129 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800130 }
Wink Savillee380b982014-07-26 18:24:22 -0700131
Malcolm Chen13f31af2018-09-04 22:12:31 -0700132 boolean matchOnOpportunisticSubscriptionsChangedListener() {
133 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
134 }
135
Tyler Gunnf955e562018-04-26 14:43:31 -0700136 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800137 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700138 return TelephonyPermissions.checkReadCallLog(
139 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800140 } catch (SecurityException e) {
141 return false;
142 }
143 }
144
Wink Savillea12a7b32012-09-20 10:09:45 -0700145 @Override
146 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700147 return "{callingPackage=" + callingPackage + " binder=" + binder
148 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800149 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700150 + onSubscriptionsChangedListenerCallback
151 + " onOpportunisticSubscriptionsChangedListenererCallback="
152 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800153 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800154 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 }
157
158 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Joe Onorato163d8d92010-10-21 13:21:20 -0400160 // access should be inside synchronized (mRecords) for these two fields
161 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
162 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 private final IBatteryStats mBatteryStats;
165
Svet Ganov16a16892015-04-16 10:32:04 -0700166 private final AppOpsManager mAppOps;
167
Malcolm Chen13f31af2018-09-04 22:12:31 -0700168 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
169
170 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700175
Wink Savillefb40dd42014-06-12 17:02:31 -0700176 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700177
Wink Savillefb40dd42014-06-12 17:02:31 -0700178 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700179
fionaxu12312f62016-11-14 13:32:14 -0800180 private int[] mVoiceActivationState;
181
182 private int[] mDataActivationState;
183
zxuan35a47022018-01-04 11:24:04 -0800184 private boolean[] mUserMobileDataState;
185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700191
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700193
Jack Yub1bac542018-03-14 16:23:38 -0700194 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700196
Wink Savillefb40dd42014-06-12 17:02:31 -0700197 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700200
Nathan Harold016e9c62016-12-14 11:24:48 -0800201 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700202
Wink Savillefb40dd42014-06-12 17:02:31 -0700203 private ArrayList<List<CellInfo>> mCellInfo = null;
204
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800205 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
206
sqian9f93a122018-12-03 22:40:41 -0800207 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
208
Jordan Liueae57b22019-01-22 16:17:35 -0800209 private CallQuality mCallQuality = new CallQuality();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800210
Jordan Liueae57b22019-01-22 16:17:35 -0800211 private CallAttributes mCallAttributes = new CallAttributes(new PreciseCallState(),
212 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
Jordan Liu8218ddd2018-11-28 11:22:39 -0800213
Jordan Liu65ed9d92019-02-19 14:42:07 -0800214 // network type of the call associated with the mCallAttributes and mCallQuality
215 private int mCallNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
216
Brad Ebingerefed9822018-10-26 10:25:57 -0700217 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700218
Wink Savilled09c4ca2014-11-22 10:08:16 -0800219 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700220
Wink Savilled09c4ca2014-11-22 10:08:16 -0800221 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700222
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200223 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
224
225 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
226
227 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
228
229 private PreciseCallState mPreciseCallState = new PreciseCallState();
230
chen xu6a942d482018-12-12 19:59:30 -0800231 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
232
chen xu6ac5fc12019-01-24 14:14:13 -0800233 private List<ImsReasonInfo> mImsReasonInfo = null;
234
chen xu6a942d482018-12-12 19:59:30 -0800235 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
236
Andrew Flynn1f452642015-04-14 22:16:04 -0400237 private boolean mCarrierNetworkChangeState = false;
238
Malcolm Chene1623652018-08-08 20:27:45 -0700239 private PhoneCapability mPhoneCapability = null;
240
Malcolm Chen026451d2019-02-14 19:50:19 -0800241 private int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700242
Chen Xu7395c632018-10-17 17:53:47 +0000243 @TelephonyManager.RadioPowerState
244 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
245
Jack Yud19b6ae2017-04-05 14:12:09 -0700246 private final LocalLog mLocalLog = new LocalLog(100);
247
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200248 private PreciseDataConnectionState mPreciseDataConnectionState =
249 new PreciseDataConnectionState();
250
Hall Liuee313732018-11-27 14:36:51 -0800251 // Nothing here yet, but putting it here in case we want to add more in the future.
252 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = 0;
253
254 static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK =
Hall Liu70bbc162018-03-02 17:44:46 -0800255 PhoneStateListener.LISTEN_CELL_LOCATION
256 | PhoneStateListener.LISTEN_CELL_INFO;
257
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700258 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian9f93a122018-12-03 22:40:41 -0800259 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
260 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
Malcolm Chen026451d2019-02-14 19:50:19 -0800261 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST
262 | PhoneStateListener.LISTEN_ACTIVE_DATA_SUBID_CHANGE;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700263
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200264 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
265 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
266 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
267
Wink Savillea12a7b32012-09-20 10:09:45 -0700268 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700269 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700270
271 private final Handler mHandler = new Handler() {
272 @Override
273 public void handleMessage(Message msg) {
274 switch (msg.what) {
275 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700276 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700277 int numPhones = TelephonyManager.getDefault().getPhoneCount();
278 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700279 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700280 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700281 }
282 break;
283 }
xinhee9f16402014-09-25 16:39:28 -0700284 case MSG_UPDATE_DEFAULT_SUB: {
285 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700286 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700287 if (VDBG) {
288 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
289 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
290 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
291 }
292
293 //Due to possible risk condition,(notify call back using the new
294 //defaultSubId comes before new defaultSubId update) we need to recall all
295 //possible missed notify callback
296 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700297 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800298 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700299 checkPossibleMissNotify(r, newDefaultPhoneId);
300 }
301 }
302 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700303 }
304 mDefaultSubId = newDefaultSubId;
305 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700306 }
307 }
308 }
309 };
310
Malcolm Chenabbfac22018-02-12 19:15:59 -0800311 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
312
313 private final IBinder binder;
314
315 TelephonyRegistryDeathRecipient(IBinder binder) {
316 this.binder = binder;
317 }
318
319 @Override
320 public void binderDied() {
321 if (DBG) log("binderDied " + binder);
322 remove(binder);
323 }
324 }
325
Wink Savillea12a7b32012-09-20 10:09:45 -0700326 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
327 @Override
328 public void onReceive(Context context, Intent intent) {
329 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700330 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700331 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700332 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700333 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700334 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700336 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800337 PhoneConstants.SUBSCRIPTION_KEY,
338 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700339 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
340 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700341 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700342 log("onReceive:current mDefaultSubId=" + mDefaultSubId
343 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
344 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700345 }
xinhee9f16402014-09-25 16:39:28 -0700346
Junda Liu985f52c2015-02-23 16:06:51 -0800347 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700348 || (newDefaultPhoneId != mDefaultPhoneId))) {
349 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
350 newDefaultPhoneId, 0, newDefaultSubIdObj));
351 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700352 }
353 }
354 };
355
Wink Savillee9b06d72009-05-18 21:47:50 -0700356 // we keep a copy of all of the state so we can send it out when folks
357 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700359 // In these calls we call with the lock held. This is safe becasuse remote
360 // calls go through a oneway interface and local calls going through a
361 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700363 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
364 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700365 CellLocation location = CellLocation.getEmpty();
366
Wink Savillefb40dd42014-06-12 17:02:31 -0700367 mContext = context;
368 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700369
Wink Savillefb40dd42014-06-12 17:02:31 -0700370 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700371 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700372 mNumPhones = numPhones;
373 mCallState = new int[numPhones];
374 mDataActivity = new int[numPhones];
375 mDataConnectionState = new int[numPhones];
376 mDataConnectionNetworkType = new int[numPhones];
377 mCallIncomingNumber = new String[numPhones];
378 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800379 mVoiceActivationState = new int[numPhones];
380 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800381 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700382 mSignalStrength = new SignalStrength[numPhones];
383 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700384 mCallForwarding = new boolean[numPhones];
385 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700386 mCellInfo = new ArrayList<List<CellInfo>>();
Brad Ebingerefed9822018-10-26 10:25:57 -0700387 mSrvccState = new int[numPhones];
chen xu6ac5fc12019-01-24 14:14:13 -0800388 mImsReasonInfo = new ArrayList<ImsReasonInfo>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800389 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
sqian9f93a122018-12-03 22:40:41 -0800390 mEmergencyNumberList = new HashMap<>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700391 for (int i = 0; i < numPhones; i++) {
392 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
393 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
394 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800395 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
396 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700397 mCallIncomingNumber[i] = "";
398 mServiceState[i] = new ServiceState();
399 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800400 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700401 mMessageWaiting[i] = false;
402 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700403 mCellLocation[i] = new Bundle();
404 mCellInfo.add(i, null);
chen xu6ac5fc12019-01-24 14:14:13 -0800405 mImsReasonInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700406 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700407 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700408 }
409
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700410 // Note that location can be null for non-phone builds like
411 // like the generic one.
412 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700413 for (int i = 0; i < numPhones; i++) {
414 location.fillInNotifierBundle(mCellLocation[i]);
415 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700416 }
Svet Ganov16a16892015-04-16 10:32:04 -0700417
418 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 }
420
Svetoslav Ganova0027152013-06-25 14:59:53 -0700421 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700422 // Watch for interesting updates
423 final IntentFilter filter = new IntentFilter();
424 filter.addAction(Intent.ACTION_USER_SWITCHED);
425 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700426 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700427 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700428 mContext.registerReceiver(mBroadcastReceiver, filter);
429 }
430
431 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700432 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800433 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700434 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800436 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700437 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
438 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800439 + " callback.asBinder=" + callback.asBinder());
440 }
441
Wink Savilled09c4ca2014-11-22 10:08:16 -0800442 synchronized (mRecords) {
443 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800444 IBinder b = callback.asBinder();
445 Record r = add(b);
446
447 if (r == null) {
448 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800449 }
450
Jeff Davidson29da89f2018-02-28 17:50:16 -0800451 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800452 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700453 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800454 r.callerUid = Binder.getCallingUid();
455 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800456 r.events = 0;
457 if (DBG) {
458 log("listen oscl: Register r=" + r);
459 }
460 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700461 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800462 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800463 if (VDBG) log("listen oscl: send to r=" + r);
464 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
465 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800466 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800467 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800468 remove(r.binder);
469 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800470 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700471 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800472 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800473 }
474 }
475
476 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800477 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800478 IOnSubscriptionsChangedListener callback) {
479 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800480 remove(callback.asBinder());
481 }
482
Malcolm Chen13f31af2018-09-04 22:12:31 -0700483
484 @Override
485 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
486 IOnSubscriptionsChangedListener callback) {
487 int callerUserId = UserHandle.getCallingUserId();
488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
489 if (VDBG) {
490 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
491 + " callerUserId=" + callerUserId + " callback=" + callback
492 + " callback.asBinder=" + callback.asBinder());
493 }
494
495 synchronized (mRecords) {
496 // register
497 IBinder b = callback.asBinder();
498 Record r = add(b);
499
500 if (r == null) {
501 return;
502 }
503
504 r.context = mContext;
505 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
506 r.callingPackage = callingPackage;
507 r.callerUid = Binder.getCallingUid();
508 r.callerPid = Binder.getCallingPid();
509 r.events = 0;
510 if (DBG) {
511 log("listen ooscl: Register r=" + r);
512 }
513 // Always notify when registration occurs if there has been a notification.
514 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
515 try {
516 if (VDBG) log("listen ooscl: send to r=" + r);
517 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
518 if (VDBG) log("listen ooscl: sent to r=" + r);
519 } catch (RemoteException e) {
520 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
521 remove(r.binder);
522 }
523 } else {
524 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
525 }
526 }
527 }
528
Wink Savillea374c3d2014-11-11 11:48:04 -0800529 @Override
530 public void notifySubscriptionInfoChanged() {
531 if (VDBG) log("notifySubscriptionInfoChanged:");
532 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700533 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800534 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
535 + mRecords.size());
536 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700537 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800538 mRemoveList.clear();
539 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800540 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800541 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800542 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
543 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
544 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800545 } catch (RemoteException ex) {
546 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
547 mRemoveList.add(r.binder);
548 }
549 }
550 }
551 handleRemoveListLocked();
552 }
553 }
554
555 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700556 public void notifyOpportunisticSubscriptionInfoChanged() {
557 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
558 synchronized (mRecords) {
559 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
560 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
561 + mRecords.size());
562 }
563 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
564 mRemoveList.clear();
565 for (Record r : mRecords) {
566 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
567 try {
568 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
569 r.onOpportunisticSubscriptionsChangedListenerCallback
570 .onSubscriptionsChanged();
571 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
572 } catch (RemoteException ex) {
573 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
574 mRemoveList.add(r.binder);
575 }
576 }
577 }
578 handleRemoveListLocked();
579 }
580 }
581
582 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
584 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800585 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
586 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 }
588
589 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700590 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700591 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700592 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700593 }
594
Svet Ganov16a16892015-04-16 10:32:04 -0700595 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700596 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700597 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700599 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700600 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700601 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
602 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700603 }
xinhe75c2c152014-10-16 11:49:45 -0700604
605 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800606 // Checks permission and throws SecurityException for disallowed operations. For pre-M
607 // apps whose runtime permission has been revoked, we return immediately to skip sending
608 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800609 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800610 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700611 }
612
yifan.baie620ce72017-12-22 14:59:57 +0800613 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 synchronized (mRecords) {
615 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800616 IBinder b = callback.asBinder();
617 Record r = add(b);
618
619 if (r == null) {
620 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 }
xinhe43c50292014-09-18 17:56:48 -0700622
Jeff Davidson29da89f2018-02-28 17:50:16 -0800623 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700624 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700625 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800626 r.callerUid = Binder.getCallingUid();
627 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700628 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
629 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800630 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800631 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700632 } else {//APP specify subID
633 r.subId = subId;
634 }
yifan.baie620ce72017-12-22 14:59:57 +0800635 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700637 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700638 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700639 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700640 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400642 try {
Wink Savillee380b982014-07-26 18:24:22 -0700643 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800644 ServiceState rawSs = new ServiceState(mServiceState[phoneId]);
645 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
646 r.callback.onServiceStateChanged(rawSs);
647 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
648 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(false));
649 } else {
650 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(true));
651 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400652 } catch (RemoteException ex) {
653 remove(r.binder);
654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 }
656 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
657 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700658 int gsmSignalStrength = mSignalStrength[phoneId]
659 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700660 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
661 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 } catch (RemoteException ex) {
663 remove(r.binder);
664 }
665 }
666 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
667 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700668 r.callback.onMessageWaitingIndicatorChanged(
669 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 } catch (RemoteException ex) {
671 remove(r.binder);
672 }
673 }
674 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
675 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700676 r.callback.onCallForwardingIndicatorChanged(
677 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 } catch (RemoteException ex) {
679 remove(r.binder);
680 }
681 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700682 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400683 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700684 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700685 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800686 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800687 r.callback.onCellLocationChanged(
688 new Bundle(mCellLocation[phoneId]));
689 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400690 } catch (RemoteException ex) {
691 remove(r.binder);
692 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 }
694 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
695 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700696 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700697 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 } catch (RemoteException ex) {
699 remove(r.binder);
700 }
701 }
702 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
703 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700704 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
705 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 } catch (RemoteException ex) {
707 remove(r.binder);
708 }
709 }
710 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
711 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700712 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 } catch (RemoteException ex) {
714 remove(r.binder);
715 }
716 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700717 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
718 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700719 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700720 } catch (RemoteException ex) {
721 remove(r.binder);
722 }
723 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700724 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
725 try {
726 r.callback.onOtaspChanged(mOtaspMode);
727 } catch (RemoteException ex) {
728 remove(r.binder);
729 }
730 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700731 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700732 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700733 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700734 + mCellInfo.get(phoneId));
Hall Liuee313732018-11-27 14:36:51 -0800735 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800736 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
737 }
John Wang963db55d2012-03-30 16:04:06 -0700738 } catch (RemoteException ex) {
739 remove(r.binder);
740 }
741 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200742 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
743 try {
744 r.callback.onPreciseCallStateChanged(mPreciseCallState);
745 } catch (RemoteException ex) {
746 remove(r.binder);
747 }
748 }
chen xu6a942d482018-12-12 19:59:30 -0800749 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
750 try {
751 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
752 mCallPreciseDisconnectCause);
753 } catch (RemoteException ex) {
754 remove(r.binder);
755 }
756 }
chen xu6ac5fc12019-01-24 14:14:13 -0800757 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
758 try {
759 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
760 } catch (RemoteException ex) {
761 remove(r.binder);
762 }
763 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200764 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
765 try {
766 r.callback.onPreciseDataConnectionStateChanged(
767 mPreciseDataConnectionState);
768 } catch (RemoteException ex) {
769 remove(r.binder);
770 }
771 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400772 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
773 try {
774 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
775 } catch (RemoteException ex) {
776 remove(r.binder);
777 }
778 }
fionaxu12312f62016-11-14 13:32:14 -0800779 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
780 try {
781 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
782 } catch (RemoteException ex) {
783 remove(r.binder);
784 }
785 }
786 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
787 try {
788 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
789 } catch (RemoteException ex) {
790 remove(r.binder);
791 }
792 }
zxuan35a47022018-01-04 11:24:04 -0800793 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
794 try {
795 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
796 } catch (RemoteException ex) {
797 remove(r.binder);
798 }
799 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800800 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
801 try {
802 r.callback.onPhysicalChannelConfigurationChanged(
803 mPhysicalChannelConfigs.get(phoneId));
804 } catch (RemoteException ex) {
805 remove(r.binder);
806 }
807 }
sqian9f93a122018-12-03 22:40:41 -0800808 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
809 try {
810 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
811 } catch (RemoteException ex) {
812 remove(r.binder);
813 }
814 }
Malcolm Chene1623652018-08-08 20:27:45 -0700815 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
816 try {
817 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
818 } catch (RemoteException ex) {
819 remove(r.binder);
820 }
821 }
Malcolm Chen026451d2019-02-14 19:50:19 -0800822 if ((events & PhoneStateListener.LISTEN_ACTIVE_DATA_SUBID_CHANGE) != 0) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700823 try {
Malcolm Chen026451d2019-02-14 19:50:19 -0800824 r.callback.onActiveDataSubIdChanged(mActiveDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700825 } catch (RemoteException ex) {
826 remove(r.binder);
827 }
828 }
Chen Xu7395c632018-10-17 17:53:47 +0000829 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
830 try {
831 r.callback.onRadioPowerStateChanged(mRadioPowerState);
832 } catch (RemoteException ex) {
833 remove(r.binder);
834 }
835 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700836 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
837 try {
838 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
839 } catch (RemoteException ex) {
840 remove(r.binder);
841 }
842 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800843 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
844 try {
845 r.callback.onCallAttributesChanged(mCallAttributes);
846 } catch (RemoteException ex) {
847 remove(r.binder);
848 }
849 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
851 }
852 } else {
xinhe75c2c152014-10-16 11:49:45 -0700853 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 remove(callback.asBinder());
855 }
856 }
857
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700858 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700859 // Only reveal the incoming number if the record has read call log permission.
860 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700861 }
862
Malcolm Chenabbfac22018-02-12 19:15:59 -0800863 private Record add(IBinder binder) {
864 Record r;
865
866 synchronized (mRecords) {
867 final int N = mRecords.size();
868 for (int i = 0; i < N; i++) {
869 r = mRecords.get(i);
870 if (binder == r.binder) {
871 // Already existed.
872 return r;
873 }
874 }
875 r = new Record();
876 r.binder = binder;
877 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
878
879 try {
880 binder.linkToDeath(r.deathRecipient, 0);
881 } catch (RemoteException e) {
882 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
883 // Binder already died. Return null.
884 return null;
885 }
886
887 mRecords.add(r);
888 if (DBG) log("add new record");
889 }
890
891 return r;
892 }
893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 private void remove(IBinder binder) {
895 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700896 final int recordCount = mRecords.size();
897 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800898 Record r = mRecords.get(i);
899 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800900 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800901 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
902 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800903 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800904
905 if (r.deathRecipient != null) {
906 try {
907 binder.unlinkToDeath(r.deathRecipient, 0);
908 } catch (NoSuchElementException e) {
909 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
910 + r + " e=" + e);
911 }
912 }
913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 mRecords.remove(i);
915 return;
916 }
917 }
918 }
919 }
920
Tyler Gunnf955e562018-04-26 14:43:31 -0700921 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700922 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700923 return;
924 }
xinhe43c50292014-09-18 17:56:48 -0700925
926 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700927 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700928 }
929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700931 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800932 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800933 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700935 // Ensure the listener has read call log permission; if they do not return
936 // an empty phone number.
937 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
938 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400940 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 }
942 }
943 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400944 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700946
947 // Called only by Telecomm to communicate call state across different phone accounts. So
948 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700949 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700950 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700951 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 }
953
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700954 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
955 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700956 if (!checkNotifyPermission("notifyCallState()")) {
957 return;
958 }
Wink Savillee380b982014-07-26 18:24:22 -0700959 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700960 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700961 + " state=" + state + " incomingNumber=" + incomingNumber);
962 }
963 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700964 if (validatePhoneId(phoneId)) {
965 mCallState[phoneId] = state;
966 mCallIncomingNumber[phoneId] = incomingNumber;
967 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800968 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700969 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800970 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700971 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700972 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
973 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700974 } catch (RemoteException ex) {
975 mRemoveList.add(r.binder);
976 }
977 }
978 }
979 }
980 handleRemoveListLocked();
981 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700982 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700983 }
984
Wink Saville63f03dd2014-10-23 10:44:45 -0700985 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700986 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700987 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700988 }
xinhe43c50292014-09-18 17:56:48 -0700989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700991 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
992 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700993 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700994 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700995 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700996 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700997 if (validatePhoneId(phoneId)) {
998 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700999
Wink Savillefb40dd42014-06-12 17:02:31 -07001000 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001001 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001002 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001003 + " phoneId=" + phoneId + " state=" + state);
1004 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001005 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001006 idMatch(r.subId, subId, phoneId)) {
Hall Liuee313732018-11-27 14:36:51 -08001007
Wink Savillefb40dd42014-06-12 17:02:31 -07001008 try {
Hall Liuee313732018-11-27 14:36:51 -08001009 ServiceState stateToSend;
1010 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
1011 stateToSend = new ServiceState(state);
1012 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
1013 stateToSend = state.sanitizeLocationInfo(false);
1014 } else {
1015 stateToSend = state.sanitizeLocationInfo(true);
1016 }
Wink Savillee380b982014-07-26 18:24:22 -07001017 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001018 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001019 + " subId=" + subId + " phoneId=" + phoneId
1020 + " state=" + state);
1021 }
Hall Liuee313732018-11-27 14:36:51 -08001022 r.callback.onServiceStateChanged(stateToSend);
Wink Savillefb40dd42014-06-12 17:02:31 -07001023 } catch (RemoteException ex) {
1024 mRemoveList.add(r.binder);
1025 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001028 } else {
Wink Savillebc027272014-09-08 14:50:58 -07001029 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001031 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001033 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 }
1035
fionaxu12312f62016-11-14 13:32:14 -08001036 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1037 int activationType, int activationState) {
1038 if (!checkNotifyPermission("notifySimActivationState()")){
1039 return;
1040 }
1041 if (VDBG) {
1042 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1043 + "type=" + activationType + " state=" + activationState);
1044 }
1045 synchronized (mRecords) {
1046 if (validatePhoneId(phoneId)) {
1047 switch (activationType) {
1048 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
1049 mVoiceActivationState[phoneId] = activationState;
1050 break;
1051 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
1052 mDataActivationState[phoneId] = activationState;
1053 break;
1054 default:
1055 return;
1056 }
1057 for (Record r : mRecords) {
1058 if (VDBG) {
1059 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1060 + " phoneId=" + phoneId + "type=" + activationType
1061 + " state=" + activationState);
1062 }
1063 try {
1064 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1065 r.matchPhoneStateListenerEvent(
1066 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1067 idMatch(r.subId, subId, phoneId)) {
1068 if (DBG) {
1069 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1070 + " subId=" + subId + " phoneId=" + phoneId
1071 + " state=" + activationState);
1072 }
1073 r.callback.onVoiceActivationStateChanged(activationState);
1074 }
1075 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1076 r.matchPhoneStateListenerEvent(
1077 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1078 idMatch(r.subId, subId, phoneId)) {
1079 if (DBG) {
1080 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1081 + " subId=" + subId + " phoneId=" + phoneId
1082 + " state=" + activationState);
1083 }
1084 r.callback.onDataActivationStateChanged(activationState);
1085 }
1086 } catch (RemoteException ex) {
1087 mRemoveList.add(r.binder);
1088 }
1089 }
1090 } else {
1091 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1092 }
1093 handleRemoveListLocked();
1094 }
1095 }
1096
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001097 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1098 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001099 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001100 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001101 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001102 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001103 log("notifySignalStrengthForPhoneId: subId=" + subId
1104 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001105 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001108 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001109 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001110 mSignalStrength[phoneId] = signalStrength;
1111 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001112 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001113 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001114 + " phoneId=" + phoneId + " ss=" + signalStrength);
1115 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001116 if (r.matchPhoneStateListenerEvent(
1117 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001118 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001119 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001120 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001121 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001122 + " subId=" + subId + " phoneId=" + phoneId
1123 + " ss=" + signalStrength);
1124 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001125 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1126 } catch (RemoteException ex) {
1127 mRemoveList.add(r.binder);
1128 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001129 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001130 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001131 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001132 try {
1133 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001134 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001135 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001136 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001137 + " subId=" + subId + " phoneId=" + phoneId
1138 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1139 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001140 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001141 } catch (RemoteException ex) {
1142 mRemoveList.add(r.binder);
1143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 }
1145 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001146 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001147 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001149 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001151 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 }
1153
Andrew Flynn1f452642015-04-14 22:16:04 -04001154 @Override
1155 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001156 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1157
Andrew Flynn1f452642015-04-14 22:16:04 -04001158 if (VDBG) {
1159 log("notifyCarrierNetworkChange: active=" + active);
1160 }
1161
1162 synchronized (mRecords) {
1163 mCarrierNetworkChangeState = active;
1164 for (Record r : mRecords) {
1165 if (r.matchPhoneStateListenerEvent(
1166 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1167 try {
1168 r.callback.onCarrierNetworkChange(active);
1169 } catch (RemoteException ex) {
1170 mRemoveList.add(r.binder);
1171 }
1172 }
1173 }
1174 handleRemoveListLocked();
1175 }
1176 }
1177
Wink Savilleb208a242012-07-25 14:08:09 -07001178 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001179 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001180 }
1181
Wink Saville63f03dd2014-10-23 10:44:45 -07001182 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001183 if (!checkNotifyPermission("notifyCellInfo()")) {
1184 return;
1185 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001186 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001187 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001188 + " cellInfo=" + cellInfo);
1189 }
yifan.baie620ce72017-12-22 14:59:57 +08001190 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001191 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001192 if (validatePhoneId(phoneId)) {
1193 mCellInfo.set(phoneId, cellInfo);
1194 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001195 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001196 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001197 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001198 try {
1199 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001200 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001201 }
1202 r.callback.onCellInfoChanged(cellInfo);
1203 } catch (RemoteException ex) {
1204 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001205 }
John Wang963db55d2012-03-30 16:04:06 -07001206 }
1207 }
1208 }
1209 handleRemoveListLocked();
1210 }
1211 }
1212
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001213 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1214 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1215 configs);
1216 }
1217
1218 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1219 List<PhysicalChannelConfig> configs) {
1220 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1221 return;
1222 }
1223
1224 if (VDBG) {
1225 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1226 }
1227
1228 synchronized (mRecords) {
1229 int phoneId = SubscriptionManager.getPhoneId(subId);
1230 if (validatePhoneId(phoneId)) {
1231 mPhysicalChannelConfigs.set(phoneId, configs);
1232 for (Record r : mRecords) {
1233 if (r.matchPhoneStateListenerEvent(
1234 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1235 && idMatch(r.subId, subId, phoneId)) {
1236 try {
1237 if (DBG_LOC) {
1238 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1239 + configs + " r=" + r);
1240 }
1241 r.callback.onPhysicalChannelConfigurationChanged(configs);
1242 } catch (RemoteException ex) {
1243 mRemoveList.add(r.binder);
1244 }
1245 }
1246 }
1247 }
1248 handleRemoveListLocked();
1249 }
1250 }
1251
xinhe43c50292014-09-18 17:56:48 -07001252 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001253 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001254 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001255 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001256 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001257 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001258 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001259 + " mwi=" + mwi);
1260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001262 if (validatePhoneId(phoneId)) {
1263 mMessageWaiting[phoneId] = mwi;
1264 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001265 if (r.matchPhoneStateListenerEvent(
1266 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001267 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001268 try {
1269 r.callback.onMessageWaitingIndicatorChanged(mwi);
1270 } catch (RemoteException ex) {
1271 mRemoveList.add(r.binder);
1272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 }
1274 }
1275 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001276 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 }
1278 }
1279
zxuan35a47022018-01-04 11:24:04 -08001280 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1281 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1282 return;
1283 }
1284 if (VDBG) {
1285 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1286 + " state=" + state);
1287 }
1288 synchronized (mRecords) {
1289 if (validatePhoneId(phoneId)) {
1290 mMessageWaiting[phoneId] = state;
1291 for (Record r : mRecords) {
1292 if (r.matchPhoneStateListenerEvent(
1293 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1294 idMatch(r.subId, subId, phoneId)) {
1295 try {
1296 r.callback.onUserMobileDataStateChanged(state);
1297 } catch (RemoteException ex) {
1298 mRemoveList.add(r.binder);
1299 }
1300 }
1301 }
1302 }
1303 handleRemoveListLocked();
1304 }
1305 }
1306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001308 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001309 }
1310
Wink Saville63f03dd2014-10-23 10:44:45 -07001311 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001312 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001313 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001314 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001315 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001316 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001317 + " cfi=" + cfi);
1318 }
yifan.baie620ce72017-12-22 14:59:57 +08001319 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001321 if (validatePhoneId(phoneId)) {
1322 mCallForwarding[phoneId] = cfi;
1323 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001324 if (r.matchPhoneStateListenerEvent(
1325 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001326 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001327 try {
1328 r.callback.onCallForwardingIndicatorChanged(cfi);
1329 } catch (RemoteException ex) {
1330 mRemoveList.add(r.binder);
1331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 }
1333 }
1334 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001335 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 }
1337 }
1338
1339 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001340 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001341 }
1342
Wink Saville63f03dd2014-10-23 10:44:45 -07001343 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001344 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001345 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001346 }
yifan.baie620ce72017-12-22 14:59:57 +08001347 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001349 if (validatePhoneId(phoneId)) {
1350 mDataActivity[phoneId] = state;
1351 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001352 // Notify by correct subId.
1353 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1354 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001355 try {
1356 r.callback.onDataActivity(state);
1357 } catch (RemoteException ex) {
1358 mRemoveList.add(r.binder);
1359 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 }
1361 }
1362 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001363 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 }
1365 }
1366
Jack Yu4d1c9452019-01-02 16:51:08 -08001367 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1368 LinkProperties linkProperties,
1369 NetworkCapabilities networkCapabilities, int networkType,
1370 boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001371 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yu4d1c9452019-01-02 16:51:08 -08001372 isDataAllowed, apn, apnType, linkProperties,
1373 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001374 }
1375
Jack Yu4d1c9452019-01-02 16:51:08 -08001376 public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataAllowed,
1377 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001378 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1379 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001380 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001381 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001382 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001383 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001384 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001385 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001386 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001387 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001388 }
yifan.baie620ce72017-12-22 14:59:57 +08001389 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001391 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001392 // We only call the callback when the change is for default APN type.
1393 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1394 && (mDataConnectionState[phoneId] != state
1395 || mDataConnectionNetworkType[phoneId] != networkType)) {
1396 String str = "onDataConnectionStateChanged(" + state
1397 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001398 log(str);
1399 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001400 for (Record r : mRecords) {
1401 if (r.matchPhoneStateListenerEvent(
1402 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1403 idMatch(r.subId, subId, phoneId)) {
1404 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001405 if (DBG) {
1406 log("Notify data connection state changed on sub: " + subId);
1407 }
Jack Yub1bac542018-03-14 16:23:38 -07001408 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001409 } catch (RemoteException ex) {
1410 mRemoveList.add(r.binder);
1411 }
1412 }
1413 }
1414 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001415
1416 mDataConnectionState[phoneId] = state;
1417 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001418 }
1419 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
chen xu16e24cd2018-12-11 18:09:41 -08001420 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1421 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001422 for (Record r : mRecords) {
1423 if (r.matchPhoneStateListenerEvent(
1424 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1425 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001426 r.callback.onPreciseDataConnectionStateChanged(
1427 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001428 } catch (RemoteException ex) {
1429 mRemoveList.add(r.binder);
1430 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001431 }
1432 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001433 }
1434 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001436 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1437 networkCapabilities, roaming, subId);
1438 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu16e24cd2018-12-11 18:09:41 -08001439 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 }
1441
Jack Yu4d1c9452019-01-02 16:51:08 -08001442 public void notifyDataConnectionFailed(String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001443 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yu4d1c9452019-01-02 16:51:08 -08001444 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001445 }
1446
Jack Yu4d1c9452019-01-02 16:51:08 -08001447 public void notifyDataConnectionFailedForSubscriber(int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001448 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001449 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001450 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001451 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001452 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yu4d1c9452019-01-02 16:51:08 -08001453 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001456 mPreciseDataConnectionState = new PreciseDataConnectionState(
1457 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu16e24cd2018-12-11 18:09:41 -08001458 ApnSetting.getApnTypesBitmaskFromString(apnType), "", null,
1459 DataFailCause.NONE);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001460 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001461 if (r.matchPhoneStateListenerEvent(
1462 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001463 try {
1464 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1465 } catch (RemoteException ex) {
1466 mRemoveList.add(r.binder);
1467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 }
1469 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001470 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001472 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001473 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu16e24cd2018-12-11 18:09:41 -08001474 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", null,
1475 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 }
1477
1478 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001479 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001480 }
1481
Wink Saville63f03dd2014-10-23 10:44:45 -07001482 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001483 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001484 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001485 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001486 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001487 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001488 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001489 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001490 + " cellLocation=" + cellLocation);
1491 }
yifan.baie620ce72017-12-22 14:59:57 +08001492 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001494 if (validatePhoneId(phoneId)) {
1495 mCellLocation[phoneId] = cellLocation;
1496 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001497 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001498 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001499 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001500 try {
1501 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001502 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001503 + " r=" + r);
1504 }
1505 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1506 } catch (RemoteException ex) {
1507 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001508 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001509 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 }
1511 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001512 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001513 }
1514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515
Wink Savillefd2d0132010-10-28 14:22:26 -07001516 public void notifyOtaspChanged(int otaspMode) {
1517 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1518 return;
1519 }
1520 synchronized (mRecords) {
1521 mOtaspMode = otaspMode;
1522 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001523 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001524 try {
1525 r.callback.onOtaspChanged(otaspMode);
1526 } catch (RemoteException ex) {
1527 mRemoveList.add(r.binder);
1528 }
1529 }
1530 }
1531 handleRemoveListLocked();
1532 }
1533 }
1534
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001535 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001536 int backgroundCallState, int phoneId) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001537 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1538 return;
1539 }
1540 synchronized (mRecords) {
1541 mRingingCallState = ringingCallState;
1542 mForegroundCallState = foregroundCallState;
1543 mBackgroundCallState = backgroundCallState;
1544 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1545 backgroundCallState,
1546 DisconnectCause.NOT_VALID,
1547 PreciseDisconnectCause.NOT_VALID);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001548 boolean notifyCallAttributes = true;
1549 if (mCallQuality == null) {
1550 log("notifyPreciseCallState: mCallQuality is null, skipping call attributes");
1551 notifyCallAttributes = false;
1552 } else {
Jordan Liu65ed9d92019-02-19 14:42:07 -08001553 mCallAttributes = new CallAttributes(mPreciseCallState, mCallNetworkType,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001554 mCallQuality);
1555 }
1556
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001557 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001558 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001559 try {
1560 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1561 } catch (RemoteException ex) {
1562 mRemoveList.add(r.binder);
1563 }
1564 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001565 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1566 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1567 try {
1568 r.callback.onCallAttributesChanged(mCallAttributes);
1569 } catch (RemoteException ex) {
1570 mRemoveList.add(r.binder);
1571 }
1572 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001573 }
1574 handleRemoveListLocked();
1575 }
chen xu6a942d482018-12-12 19:59:30 -08001576 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1577 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001578 }
1579
1580 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1581 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1582 return;
1583 }
1584 synchronized (mRecords) {
chen xu6a942d482018-12-12 19:59:30 -08001585 mCallDisconnectCause = disconnectCause;
1586 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001587 for (Record r : mRecords) {
chen xu6a942d482018-12-12 19:59:30 -08001588 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1589 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001590 try {
chen xu6a942d482018-12-12 19:59:30 -08001591 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1592 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001593 } catch (RemoteException ex) {
1594 mRemoveList.add(r.binder);
1595 }
1596 }
1597 }
1598 handleRemoveListLocked();
1599 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001600 }
1601
chen xu6ac5fc12019-01-24 14:14:13 -08001602 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1603 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1604 return;
1605 }
1606 int phoneId = SubscriptionManager.getPhoneId(subId);
1607 synchronized (mRecords) {
1608 if (validatePhoneId(phoneId)) {
1609 mImsReasonInfo.set(phoneId, imsReasonInfo);
1610 for (Record r : mRecords) {
1611 if (r.matchPhoneStateListenerEvent(
1612 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1613 && idMatch(r.subId, subId, phoneId)) {
1614 try {
1615 if (DBG_LOC) {
1616 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1617 + imsReasonInfo + " r=" + r);
1618 }
1619 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1620 } catch (RemoteException ex) {
1621 mRemoveList.add(r.binder);
1622 }
1623 }
1624 }
1625 }
1626 handleRemoveListLocked();
1627 }
1628 }
1629
chen xu16e24cd2018-12-11 18:09:41 -08001630 public void notifyPreciseDataConnectionFailed(String apnType,
1631 String apn, @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001632 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1633 return;
1634 }
1635 synchronized (mRecords) {
1636 mPreciseDataConnectionState = new PreciseDataConnectionState(
1637 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu16e24cd2018-12-11 18:09:41 -08001638 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001639 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001640 if (r.matchPhoneStateListenerEvent(
1641 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001642 try {
1643 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1644 } catch (RemoteException ex) {
1645 mRemoveList.add(r.binder);
1646 }
1647 }
1648 }
1649 handleRemoveListLocked();
1650 }
1651 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yu4d1c9452019-01-02 16:51:08 -08001652 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001653 }
1654
Brad Ebingerefed9822018-10-26 10:25:57 -07001655 @Override
1656 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1657 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001658 return;
1659 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001660 if (VDBG) {
1661 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1662 }
1663 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001664 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001665 if (validatePhoneId(phoneId)) {
chen xu6ac5fc12019-01-24 14:14:13 -08001666 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001667 for (Record r : mRecords) {
1668 if (r.matchPhoneStateListenerEvent(
1669 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1670 idMatch(r.subId, subId, phoneId)) {
1671 try {
1672 if (DBG_LOC) {
1673 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1674 }
1675 r.callback.onSrvccStateChanged(state);
1676 } catch (RemoteException ex) {
1677 mRemoveList.add(r.binder);
1678 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001679 }
1680 }
1681 }
1682 handleRemoveListLocked();
1683 }
1684 }
1685
Shuo Qian066e8652018-04-25 21:02:35 +00001686 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1687 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1688 return;
1689 }
1690
1691 synchronized (mRecords) {
1692 for (Record r : mRecords) {
1693 if (VDBG) {
1694 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1695 }
1696 if ((r.matchPhoneStateListenerEvent(
1697 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1698 ((r.subId == subId) ||
1699 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1700 try {
1701 r.callback.onOemHookRawEvent(rawData);
1702 } catch (RemoteException ex) {
1703 mRemoveList.add(r.binder);
1704 }
1705 }
1706 }
1707 handleRemoveListLocked();
1708 }
1709 }
1710
Malcolm Chene1623652018-08-08 20:27:45 -07001711 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1712 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1713 return;
1714 }
1715
1716 if (VDBG) {
1717 log("notifyPhoneCapabilityChanged: capability=" + capability);
1718 }
1719
1720 synchronized (mRecords) {
1721 mPhoneCapability = capability;
1722
1723 for (Record r : mRecords) {
1724 if (r.matchPhoneStateListenerEvent(
1725 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1726 try {
1727 r.callback.onPhoneCapabilityChanged(capability);
1728 } catch (RemoteException ex) {
1729 mRemoveList.add(r.binder);
1730 }
1731 }
1732 }
1733 handleRemoveListLocked();
1734 }
1735 }
1736
Malcolm Chen026451d2019-02-14 19:50:19 -08001737 public void notifyActiveDataSubIdChanged(int activeDataSubId) {
1738 if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001739 return;
1740 }
1741
1742 if (VDBG) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001743 log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001744 }
1745
1746 synchronized (mRecords) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001747 mActiveDataSubId = activeDataSubId;
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001748
1749 for (Record r : mRecords) {
1750 if (r.matchPhoneStateListenerEvent(
Malcolm Chen026451d2019-02-14 19:50:19 -08001751 PhoneStateListener.LISTEN_ACTIVE_DATA_SUBID_CHANGE)) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001752 try {
Malcolm Chen026451d2019-02-14 19:50:19 -08001753 r.callback.onActiveDataSubIdChanged(activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001754 } catch (RemoteException ex) {
1755 mRemoveList.add(r.binder);
1756 }
1757 }
1758 }
1759 handleRemoveListLocked();
1760 }
1761 }
Malcolm Chene1623652018-08-08 20:27:45 -07001762
Chen Xu7395c632018-10-17 17:53:47 +00001763 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1764 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1765 return;
1766 }
1767
1768 if (VDBG) {
1769 log("notifyRadioPowerStateChanged: state= " + state);
1770 }
1771
1772 synchronized (mRecords) {
1773 mRadioPowerState = state;
1774
1775 for (Record r : mRecords) {
1776 if (r.matchPhoneStateListenerEvent(
1777 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1778 try {
1779 r.callback.onRadioPowerStateChanged(state);
1780 } catch (RemoteException ex) {
1781 mRemoveList.add(r.binder);
1782 }
1783 }
1784 }
1785 handleRemoveListLocked();
1786 }
1787 }
1788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 @Override
sqian9f93a122018-12-03 22:40:41 -08001790 public void notifyEmergencyNumberList() {
1791 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1792 return;
1793 }
1794
1795 synchronized (mRecords) {
sqianb0ae02b2018-12-14 21:47:49 -08001796 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1797 Context.TELEPHONY_SERVICE);
1798 mEmergencyNumberList = tm.getCurrentEmergencyNumberList();
sqian9f93a122018-12-03 22:40:41 -08001799
1800 for (Record r : mRecords) {
1801 if (r.matchPhoneStateListenerEvent(
1802 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)) {
1803 try {
1804 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1805 if (VDBG) {
1806 log("notifyEmergencyNumberList: emergencyNumberList= "
1807 + mEmergencyNumberList);
1808 }
1809 } catch (RemoteException ex) {
1810 mRemoveList.add(r.binder);
1811 }
1812 }
1813 }
1814 handleRemoveListLocked();
1815 }
sqianbdc5a732018-10-26 13:27:51 -07001816 }
1817
Jordan Liu8218ddd2018-11-28 11:22:39 -08001818 @Override
Jordan Liu65ed9d92019-02-19 14:42:07 -08001819 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId,
1820 int callNetworkType) {
Jordan Liu8218ddd2018-11-28 11:22:39 -08001821 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
1822 return;
1823 }
1824
1825 // merge CallQuality with PreciseCallState and network type
1826 mCallQuality = callQuality;
Jordan Liu65ed9d92019-02-19 14:42:07 -08001827 mCallNetworkType = callNetworkType;
1828 mCallAttributes = new CallAttributes(mPreciseCallState, callNetworkType, callQuality);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001829
1830 synchronized (mRecords) {
1831 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1832 Context.TELEPHONY_SERVICE);
1833
1834 for (Record r : mRecords) {
1835 if (r.matchPhoneStateListenerEvent(
1836 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1837 try {
1838 r.callback.onCallAttributesChanged(mCallAttributes);
1839 } catch (RemoteException ex) {
1840 mRemoveList.add(r.binder);
1841 }
1842 }
1843 }
1844 handleRemoveListLocked();
1845 }
1846 }
1847
sqianbdc5a732018-10-26 13:27:51 -07001848
1849 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001850 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1851 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1852
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001853 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001856 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001858 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301859 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001860 pw.println("Phone Id=" + i);
1861 pw.increaseIndent();
1862 pw.println("mCallState=" + mCallState[i]);
1863 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1864 pw.println("mServiceState=" + mServiceState[i]);
1865 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1866 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001867 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001868 pw.println("mSignalStrength=" + mSignalStrength[i]);
1869 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1870 pw.println("mCallForwarding=" + mCallForwarding[i]);
1871 pw.println("mDataActivity=" + mDataActivity[i]);
1872 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001873 pw.println("mCellLocation=" + mCellLocation[i]);
1874 pw.println("mCellInfo=" + mCellInfo.get(i));
chen xu6ac5fc12019-01-24 14:14:13 -08001875 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i).toString());
Jack Yud19b6ae2017-04-05 14:12:09 -07001876 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301877 }
Jordan Liu65ed9d92019-02-19 14:42:07 -08001878 pw.println("mCallNetworkType=" + mCallNetworkType);
Jack Yud19b6ae2017-04-05 14:12:09 -07001879 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1880 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu6a942d482018-12-12 19:59:30 -08001881 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1882 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001883 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1884 pw.println("mRingingCallState=" + mRingingCallState);
1885 pw.println("mForegroundCallState=" + mForegroundCallState);
1886 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001887 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chene1623652018-08-08 20:27:45 -07001888 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen026451d2019-02-14 19:50:19 -08001889 pw.println("mActiveDataSubId=" + mActiveDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00001890 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian9f93a122018-12-03 22:40:41 -08001891 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001892 pw.println("mCallQuality=" + mCallQuality);
1893 pw.println("mCallAttributes=" + mCallAttributes);
Jack Yud19b6ae2017-04-05 14:12:09 -07001894
1895 pw.decreaseIndent();
1896
1897 pw.println("local logs:");
1898 pw.increaseIndent();
1899 mLocalLog.dump(fd, pw, args);
1900 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001901 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001902 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001903 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001904 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001906 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001907 }
1908 }
1909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 //
1911 // the legacy intent broadcasting
1912 //
1913
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001914 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001915 long ident = Binder.clearCallingIdentity();
1916 try {
1917 mBatteryStats.notePhoneState(state.getState());
1918 } catch (RemoteException re) {
1919 // Can't do much
1920 } finally {
1921 Binder.restoreCallingIdentity(ident);
1922 }
1923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001925 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 Bundle data = new Bundle();
1927 state.fillInNotifierBundle(data);
1928 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001929 // Pass the subscription along with the intent.
1930 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001931 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001932 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001933 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 }
1935
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001936 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1937 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001938 long ident = Binder.clearCallingIdentity();
1939 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001940 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001941 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001942 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001943 } finally {
1944 Binder.restoreCallingIdentity(ident);
1945 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001948 Bundle data = new Bundle();
1949 signalStrength.fillInNotifierBundle(data);
1950 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001951 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001952 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001953 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 }
1955
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001956 /**
1957 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1958 * a valid subId, in which case this function fires a subId-specific intent, or it
1959 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1960 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1961 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001962 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1963 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 long ident = Binder.clearCallingIdentity();
1965 try {
1966 if (state == TelephonyManager.CALL_STATE_IDLE) {
1967 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001968 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1969 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 } else {
1971 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001972 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1973 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 }
1975 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001976 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 } finally {
1978 Binder.restoreCallingIdentity(ident);
1979 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001982 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001983 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001984
1985 // If a valid subId was specified, we should fire off a subId-specific state
1986 // change intent and include the subId.
1987 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1988 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1989 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001990 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001991 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001992 // If the phoneId is invalid, the broadcast is for overall call state.
1993 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1994 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1995 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001996
Brad Ebinger51de96a2017-04-21 17:05:18 -07001997 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1998 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1999
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002000 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002001 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002002 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2003
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002004 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2005 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002006 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002007 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002008 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002009 android.Manifest.permission.READ_PHONE_STATE,
2010 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002011 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2012 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2013 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 }
2015
Jack Yu4d1c9452019-01-02 16:51:08 -08002016 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2017 String apnType, LinkProperties linkProperties,
2018 NetworkCapabilities networkCapabilities,
2019 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002020 // Note: not reporting to the battery stats service here, because the
2021 // status bar takes care of that after taking into account all of the
2022 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002024 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002025 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07002026 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002027 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002029 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002030 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002031 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002032 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002033 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002034 }
2035 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002036 if (networkCapabilities != null) {
2037 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002038 }
Wink Savillea639b312012-07-10 12:37:54 -07002039 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002040
Wink Savillea639b312012-07-10 12:37:54 -07002041 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2042 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002043 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002044 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 }
2046
Jack Yu4d1c9452019-01-02 16:51:08 -08002047 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002049 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002050 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002051 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002053
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002054 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yu4d1c9452019-01-02 16:51:08 -08002055 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002056 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2057 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2058 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2059 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002060 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2061 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2062 }
2063
2064 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu16e24cd2018-12-11 18:09:41 -08002065 String apnType, String apn, LinkProperties linkProperties,
2066 @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002067 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2068 intent.putExtra(PhoneConstants.STATE_KEY, state);
2069 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002070 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2071 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002072 if (linkProperties != null) {
Jack Yu4d1c9452019-01-02 16:51:08 -08002073 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002074 }
chen xu16e24cd2018-12-11 18:09:41 -08002075 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002076
2077 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2078 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2079 }
2080
Andrew Flynnceaed682015-06-09 12:36:58 +00002081 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002082 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002083 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002084 }
2085
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002086 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2087 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002088 }
2089
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002090 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002091 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002092 return true;
2093 }
2094 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002095 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002096 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002097 return false;
2098 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002099
Andrew Flynn1f452642015-04-14 22:16:04 -04002100 private boolean checkNotifyPermission() {
2101 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2102 == PackageManager.PERMISSION_GRANTED;
2103 }
2104
Jeff Davidson29da89f2018-02-28 17:50:16 -08002105 private boolean checkListenerPermission(
2106 int events, int subId, String callingPackage, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002107 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2108 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2109 .setCallingPackage(callingPackage)
2110 .setMethod(message + " events: " + events)
2111 .setCallingPid(Binder.getCallingPid())
2112 .setCallingUid(Binder.getCallingUid());
2113
2114 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002115 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002116 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2117 shouldCheckLocationPermissions = true;
2118 }
2119
2120 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2121 // Everything that requires fine location started in Q. So far...
2122 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2123 shouldCheckLocationPermissions = true;
2124 }
2125
2126 if (shouldCheckLocationPermissions) {
2127 LocationAccessPolicy.LocationPermissionResult result =
2128 LocationAccessPolicy.checkLocationPermission(
2129 mContext, locationQueryBuilder.build());
2130 switch (result) {
2131 case DENIED_HARD:
2132 throw new SecurityException("Unable to listen for events " + events + " due to "
2133 + "insufficient location permissions.");
2134 case DENIED_SOFT:
2135 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002136 }
John Wang963db55d2012-03-30 16:04:06 -07002137 }
2138
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002139 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2141 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002142 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002143 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002144 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002145
2146 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2147 mContext.enforceCallingOrSelfPermission(
2148 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002149 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002150
Shuo Qian066e8652018-04-25 21:02:35 +00002151 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2152 mContext.enforceCallingOrSelfPermission(
2153 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2154 }
2155
Brad Ebingerefed9822018-10-26 10:25:57 -07002156 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2157 mContext.enforceCallingOrSelfPermission(
2158 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2159 }
2160
chen xu6a942d482018-12-12 19:59:30 -08002161 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2162 mContext.enforceCallingOrSelfPermission(
2163 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2164 }
2165
Jordan Liu8218ddd2018-11-28 11:22:39 -08002166 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2167 mContext.enforceCallingOrSelfPermission(
2168 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2169 }
2170
chen xu52797b62019-01-18 13:16:31 -08002171 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2172 mContext.enforceCallingOrSelfPermission(
2173 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2174 }
2175
2176 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2177 mContext.enforceCallingOrSelfPermission(
2178 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2179 }
2180
chen xu6ac5fc12019-01-24 14:14:13 -08002181 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2182 mContext.enforceCallingOrSelfPermission(
2183 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2184 }
2185
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002186 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002187 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002188
2189 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002190 int size = mRemoveList.size();
2191 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2192 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002193 for (IBinder b: mRemoveList) {
2194 remove(b);
2195 }
2196 mRemoveList.clear();
2197 }
2198 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002199
2200 private boolean validateEventsAndUserLocked(Record r, int events) {
2201 int foregroundUser;
2202 long callingIdentity = Binder.clearCallingIdentity();
2203 boolean valid = false;
2204 try {
2205 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002206 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2207 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002208 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002209 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002210 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002211 + " r.events=" + r.events + " events=" + events);
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(callingIdentity);
2215 }
2216 return valid;
2217 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002218
2219 private boolean validatePhoneId(int phoneId) {
2220 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002221 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002222 return valid;
2223 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002224
2225 private static void log(String s) {
2226 Rlog.d(TAG, s);
2227 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002228
xinhe8b79fb62014-11-05 14:55:03 -08002229 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002230
2231 if(subId < 0) {
2232 // Invalid case, we need compare phoneId with default one.
2233 return (mDefaultPhoneId == phoneId);
2234 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002235 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002236 return (subId == mDefaultSubId);
2237 } else {
2238 return (rSubId == subId);
2239 }
2240 }
2241
Hall Liuee313732018-11-27 14:36:51 -08002242 private boolean checkFineLocationAccess(Record r, int minSdk) {
2243 LocationAccessPolicy.LocationPermissionQuery query =
2244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2245 .setCallingPackage(r.callingPackage)
2246 .setCallingPid(r.callerPid)
2247 .setCallingUid(r.callerUid)
2248 .setMethod("TelephonyRegistry push")
2249 .setMinSdkVersionForFine(minSdk)
2250 .build();
2251
2252 return Binder.withCleanCallingIdentity(() -> {
2253 LocationAccessPolicy.LocationPermissionResult locationResult =
2254 LocationAccessPolicy.checkLocationPermission(mContext, query);
2255 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2256 });
2257 }
2258
2259 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2260 LocationAccessPolicy.LocationPermissionQuery query =
2261 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2262 .setCallingPackage(r.callingPackage)
2263 .setCallingPid(r.callerPid)
2264 .setCallingUid(r.callerUid)
2265 .setMethod("TelephonyRegistry push")
2266 .setMinSdkVersionForCoarse(minSdk)
2267 .build();
2268
2269 return Binder.withCleanCallingIdentity(() -> {
2270 LocationAccessPolicy.LocationPermissionResult locationResult =
2271 LocationAccessPolicy.checkLocationPermission(mContext, query);
2272 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2273 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002274 }
2275
xinhee9f16402014-09-25 16:39:28 -07002276 private void checkPossibleMissNotify(Record r, int phoneId) {
2277 int events = r.events;
2278
2279 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2280 try {
2281 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2282 mServiceState[phoneId]);
2283 r.callback.onServiceStateChanged(
2284 new ServiceState(mServiceState[phoneId]));
2285 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002286 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002287 }
2288 }
2289
2290 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2291 try {
2292 SignalStrength signalStrength = mSignalStrength[phoneId];
2293 if (DBG) {
2294 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2295 }
2296 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2297 } catch (RemoteException ex) {
2298 mRemoveList.add(r.binder);
2299 }
2300 }
2301
2302 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2303 try {
2304 int gsmSignalStrength = mSignalStrength[phoneId]
2305 .getGsmSignalStrength();
2306 if (DBG) {
2307 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2308 gsmSignalStrength);
2309 }
2310 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2311 : gsmSignalStrength));
2312 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002313 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002314 }
2315 }
2316
2317 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2318 try {
2319 if (DBG_LOC) {
2320 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2321 + mCellInfo.get(phoneId));
2322 }
Hall Liuee313732018-11-27 14:36:51 -08002323 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002324 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2325 }
xinhee9f16402014-09-25 16:39:28 -07002326 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002327 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002328 }
2329 }
2330
zxuan35a47022018-01-04 11:24:04 -08002331 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2332 try {
2333 if (VDBG) {
2334 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2335 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2336 }
2337 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2338 } catch (RemoteException ex) {
2339 mRemoveList.add(r.binder);
2340 }
2341 }
2342
xinhee9f16402014-09-25 16:39:28 -07002343 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2344 try {
2345 if (VDBG) {
2346 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2347 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2348 }
2349 r.callback.onMessageWaitingIndicatorChanged(
2350 mMessageWaiting[phoneId]);
2351 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002352 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002353 }
2354 }
2355
2356 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2357 try {
2358 if (VDBG) {
2359 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2360 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2361 }
2362 r.callback.onCallForwardingIndicatorChanged(
2363 mCallForwarding[phoneId]);
2364 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002365 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002366 }
2367 }
2368
2369 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2370 try {
2371 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2372 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002373 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002374 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2375 }
xinhee9f16402014-09-25 16:39:28 -07002376 } catch (RemoteException ex) {
2377 mRemoveList.add(r.binder);
2378 }
2379 }
2380
2381 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2382 try {
2383 if (DBG) {
2384 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2385 + "=" + mDataConnectionState[phoneId]
2386 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2387 + ")");
2388 }
2389 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2390 mDataConnectionNetworkType[phoneId]);
2391 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002392 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002393 }
2394 }
2395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396}