blob: 3b5c9f53d9a15f1e3cb20a323c7ed0d0fde1b6e9 [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 xu896e3d42018-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 Chen5ee5c142018-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 xu896e3d42018-12-11 18:09:41 -080054import android.telephony.data.ApnSetting;
sqianbf165bc2018-12-07 17:09:39 -080055import android.telephony.emergency.EmergencyNumber;
chen xu0f494682019-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 Chen800a7d62018-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;
sqian46c0c302018-12-27 14:12:11 -080076import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070077import java.util.List;
sqian46c0c302018-12-27 14:12:11 -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 Chen800a7d62018-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 Chen27829e22018-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 Chen27829e22018-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 Chen27829e22018-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 Chen27829e22018-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
Jordan Liu8218ddd2018-11-28 11:22:39 -0800180 private int[] mNetworkType;
181
fionaxu12312f62016-11-14 13:32:14 -0800182 private int[] mVoiceActivationState;
183
184 private int[] mDataActivationState;
185
zxuan35a47022018-01-04 11:24:04 -0800186 private boolean[] mUserMobileDataState;
187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700191
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700193
Wink Savillefb40dd42014-06-12 17:02:31 -0700194 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700195
Jack Yub1bac542018-03-14 16:23:38 -0700196 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700197 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200
Wink Savillefb40dd42014-06-12 17:02:31 -0700201 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700202
Nathan Harold016e9c62016-12-14 11:24:48 -0800203 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700204
Wink Savillefb40dd42014-06-12 17:02:31 -0700205 private ArrayList<List<CellInfo>> mCellInfo = null;
206
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800207 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
208
sqian46c0c302018-12-27 14:12:11 -0800209 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
210
Jordan Liueae57b22019-01-22 16:17:35 -0800211 private CallQuality mCallQuality = new CallQuality();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800212
Jordan Liueae57b22019-01-22 16:17:35 -0800213 private CallAttributes mCallAttributes = new CallAttributes(new PreciseCallState(),
214 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
Jordan Liu8218ddd2018-11-28 11:22:39 -0800215
Brad Ebingerefed9822018-10-26 10:25:57 -0700216 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700217
Wink Savilled09c4ca2014-11-22 10:08:16 -0800218 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700219
Wink Savilled09c4ca2014-11-22 10:08:16 -0800220 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700221
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200222 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
223
224 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
225
226 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
227
228 private PreciseCallState mPreciseCallState = new PreciseCallState();
229
chen xu970d7792018-12-12 19:59:30 -0800230 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
231
chen xu0f494682019-01-24 14:14:13 -0800232 private List<ImsReasonInfo> mImsReasonInfo = null;
233
chen xu970d7792018-12-12 19:59:30 -0800234 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
235
Andrew Flynn1f452642015-04-14 22:16:04 -0400236 private boolean mCarrierNetworkChangeState = false;
237
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700238 private PhoneCapability mPhoneCapability = null;
239
chen xu760729c2018-10-11 13:18:26 -0700240 @TelephonyManager.RadioPowerState
241 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
242
Malcolm Chenc1873af2018-09-24 20:01:32 -0700243 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
244
Jack Yud19b6ae2017-04-05 14:12:09 -0700245 private final LocalLog mLocalLog = new LocalLog(100);
246
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200247 private PreciseDataConnectionState mPreciseDataConnectionState =
248 new PreciseDataConnectionState();
249
Hall Liuee313732018-11-27 14:36:51 -0800250 // Nothing here yet, but putting it here in case we want to add more in the future.
251 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = 0;
252
253 static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK =
Hall Liu70bbc162018-03-02 17:44:46 -0800254 PhoneStateListener.LISTEN_CELL_LOCATION
255 | PhoneStateListener.LISTEN_CELL_INFO;
256
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700257 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian46c0c302018-12-27 14:12:11 -0800258 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
259 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
260 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700261
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200262 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
263 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
264 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
265
Wink Savillea12a7b32012-09-20 10:09:45 -0700266 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700267 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700268
269 private final Handler mHandler = new Handler() {
270 @Override
271 public void handleMessage(Message msg) {
272 switch (msg.what) {
273 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700274 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700275 int numPhones = TelephonyManager.getDefault().getPhoneCount();
276 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700277 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700278 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700279 }
280 break;
281 }
xinhee9f16402014-09-25 16:39:28 -0700282 case MSG_UPDATE_DEFAULT_SUB: {
283 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700284 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700285 if (VDBG) {
286 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
287 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
288 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
289 }
290
291 //Due to possible risk condition,(notify call back using the new
292 //defaultSubId comes before new defaultSubId update) we need to recall all
293 //possible missed notify callback
294 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700295 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800296 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700297 checkPossibleMissNotify(r, newDefaultPhoneId);
298 }
299 }
300 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700301 }
302 mDefaultSubId = newDefaultSubId;
303 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700304 }
305 }
306 }
307 };
308
Malcolm Chenabbfac22018-02-12 19:15:59 -0800309 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
310
311 private final IBinder binder;
312
313 TelephonyRegistryDeathRecipient(IBinder binder) {
314 this.binder = binder;
315 }
316
317 @Override
318 public void binderDied() {
319 if (DBG) log("binderDied " + binder);
320 remove(binder);
321 }
322 }
323
Wink Savillea12a7b32012-09-20 10:09:45 -0700324 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
325 @Override
326 public void onReceive(Context context, Intent intent) {
327 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700328 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700329 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700330 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700331 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700332 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700334 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800335 PhoneConstants.SUBSCRIPTION_KEY,
336 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700337 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
338 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700339 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700340 log("onReceive:current mDefaultSubId=" + mDefaultSubId
341 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
342 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700343 }
xinhee9f16402014-09-25 16:39:28 -0700344
Junda Liu985f52c2015-02-23 16:06:51 -0800345 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700346 || (newDefaultPhoneId != mDefaultPhoneId))) {
347 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
348 newDefaultPhoneId, 0, newDefaultSubIdObj));
349 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700350 }
351 }
352 };
353
Wink Savillee9b06d72009-05-18 21:47:50 -0700354 // we keep a copy of all of the state so we can send it out when folks
355 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700357 // In these calls we call with the lock held. This is safe becasuse remote
358 // calls go through a oneway interface and local calls going through a
359 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360
Malcolm Chen800a7d62018-08-27 20:38:29 -0700361 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
362 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700363 CellLocation location = CellLocation.getEmpty();
364
Wink Savillefb40dd42014-06-12 17:02:31 -0700365 mContext = context;
366 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700367
Wink Savillefb40dd42014-06-12 17:02:31 -0700368 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700369 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700370 mNumPhones = numPhones;
371 mCallState = new int[numPhones];
372 mDataActivity = new int[numPhones];
373 mDataConnectionState = new int[numPhones];
374 mDataConnectionNetworkType = new int[numPhones];
375 mCallIncomingNumber = new String[numPhones];
376 mServiceState = new ServiceState[numPhones];
Jordan Liu8218ddd2018-11-28 11:22:39 -0800377 mNetworkType = new int[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800378 mVoiceActivationState = new int[numPhones];
379 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800380 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700381 mSignalStrength = new SignalStrength[numPhones];
382 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700383 mCallForwarding = new boolean[numPhones];
384 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700385 mCellInfo = new ArrayList<List<CellInfo>>();
Brad Ebingerefed9822018-10-26 10:25:57 -0700386 mSrvccState = new int[numPhones];
chen xu0f494682019-01-24 14:14:13 -0800387 mImsReasonInfo = new ArrayList<ImsReasonInfo>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800388 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
sqian46c0c302018-12-27 14:12:11 -0800389 mEmergencyNumberList = new HashMap<>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700390 for (int i = 0; i < numPhones; i++) {
391 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
392 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
393 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800394 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
395 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700396 mCallIncomingNumber[i] = "";
397 mServiceState[i] = new ServiceState();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800398 mNetworkType[i] = mServiceState[i].getVoiceNetworkType();
Wink Savillefb40dd42014-06-12 17:02:31 -0700399 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 xu0f494682019-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 Chen27829e22018-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 Chen27829e22018-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 Chen27829e22018-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 Chen27829e22018-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 Chen27829e22018-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 Chen27829e22018-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 xu970d7792018-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 xu0f494682019-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 }
sqian46c0c302018-12-27 14:12:11 -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 Chen5ee5c142018-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 Chenc1873af2018-09-24 20:01:32 -0700822 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
823 try {
824 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
825 } catch (RemoteException ex) {
826 remove(r.binder);
827 }
828 }
chen xu760729c2018-10-11 13:18:26 -0700829 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
Jordan Liu8218ddd2018-11-28 11:22:39 -08001000 boolean notifyCallAttributes = true;
1001 if (mNetworkType[phoneId] != mServiceState[phoneId].getVoiceNetworkType()) {
1002 mNetworkType[phoneId] = state.getVoiceNetworkType();
1003 mCallAttributes = new CallAttributes(mPreciseCallState, mNetworkType[phoneId],
1004 mCallQuality);
1005 } else {
1006 // No change to network type, so no need to notify call attributes
1007 notifyCallAttributes = false;
1008 }
1009
1010 if (mCallQuality == null) {
1011 // No call quality reported yet, so no need to notify call attributes
1012 notifyCallAttributes = false;
1013 }
1014
Wink Savillefb40dd42014-06-12 17:02:31 -07001015 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001016 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001017 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001018 + " phoneId=" + phoneId + " state=" + state);
1019 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001020 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001021 idMatch(r.subId, subId, phoneId)) {
Hall Liuee313732018-11-27 14:36:51 -08001022
Wink Savillefb40dd42014-06-12 17:02:31 -07001023 try {
Hall Liuee313732018-11-27 14:36:51 -08001024 ServiceState stateToSend;
1025 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
1026 stateToSend = new ServiceState(state);
1027 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
1028 stateToSend = state.sanitizeLocationInfo(false);
1029 } else {
1030 stateToSend = state.sanitizeLocationInfo(true);
1031 }
Wink Savillee380b982014-07-26 18:24:22 -07001032 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001033 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001034 + " subId=" + subId + " phoneId=" + phoneId
1035 + " state=" + state);
1036 }
Hall Liuee313732018-11-27 14:36:51 -08001037 r.callback.onServiceStateChanged(stateToSend);
Wink Savillefb40dd42014-06-12 17:02:31 -07001038 } catch (RemoteException ex) {
1039 mRemoveList.add(r.binder);
1040 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001041 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001042 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1043 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1044 try {
1045 r.callback.onCallAttributesChanged(mCallAttributes);
1046 } catch (RemoteException ex) {
1047 mRemoveList.add(r.binder);
1048 }
1049 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001051 } else {
Wink Savillebc027272014-09-08 14:50:58 -07001052 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001054 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001056 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 }
1058
fionaxu12312f62016-11-14 13:32:14 -08001059 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1060 int activationType, int activationState) {
1061 if (!checkNotifyPermission("notifySimActivationState()")){
1062 return;
1063 }
1064 if (VDBG) {
1065 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1066 + "type=" + activationType + " state=" + activationState);
1067 }
1068 synchronized (mRecords) {
1069 if (validatePhoneId(phoneId)) {
1070 switch (activationType) {
1071 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
1072 mVoiceActivationState[phoneId] = activationState;
1073 break;
1074 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
1075 mDataActivationState[phoneId] = activationState;
1076 break;
1077 default:
1078 return;
1079 }
1080 for (Record r : mRecords) {
1081 if (VDBG) {
1082 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1083 + " phoneId=" + phoneId + "type=" + activationType
1084 + " state=" + activationState);
1085 }
1086 try {
1087 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1088 r.matchPhoneStateListenerEvent(
1089 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1090 idMatch(r.subId, subId, phoneId)) {
1091 if (DBG) {
1092 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1093 + " subId=" + subId + " phoneId=" + phoneId
1094 + " state=" + activationState);
1095 }
1096 r.callback.onVoiceActivationStateChanged(activationState);
1097 }
1098 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1099 r.matchPhoneStateListenerEvent(
1100 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1101 idMatch(r.subId, subId, phoneId)) {
1102 if (DBG) {
1103 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1104 + " subId=" + subId + " phoneId=" + phoneId
1105 + " state=" + activationState);
1106 }
1107 r.callback.onDataActivationStateChanged(activationState);
1108 }
1109 } catch (RemoteException ex) {
1110 mRemoveList.add(r.binder);
1111 }
1112 }
1113 } else {
1114 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1115 }
1116 handleRemoveListLocked();
1117 }
1118 }
1119
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001120 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1121 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001122 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001123 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001124 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001125 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001126 log("notifySignalStrengthForPhoneId: subId=" + subId
1127 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001128 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001131 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001132 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001133 mSignalStrength[phoneId] = signalStrength;
1134 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001135 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001136 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001137 + " phoneId=" + phoneId + " ss=" + signalStrength);
1138 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001139 if (r.matchPhoneStateListenerEvent(
1140 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001141 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001142 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001143 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001144 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001145 + " subId=" + subId + " phoneId=" + phoneId
1146 + " ss=" + signalStrength);
1147 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001148 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1149 } catch (RemoteException ex) {
1150 mRemoveList.add(r.binder);
1151 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001152 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001153 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001154 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001155 try {
1156 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001157 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001158 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001159 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001160 + " subId=" + subId + " phoneId=" + phoneId
1161 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1162 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001163 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001164 } catch (RemoteException ex) {
1165 mRemoveList.add(r.binder);
1166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 }
1168 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001169 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001170 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001172 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001174 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176
Andrew Flynn1f452642015-04-14 22:16:04 -04001177 @Override
1178 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001179 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1180
Andrew Flynn1f452642015-04-14 22:16:04 -04001181 if (VDBG) {
1182 log("notifyCarrierNetworkChange: active=" + active);
1183 }
1184
1185 synchronized (mRecords) {
1186 mCarrierNetworkChangeState = active;
1187 for (Record r : mRecords) {
1188 if (r.matchPhoneStateListenerEvent(
1189 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1190 try {
1191 r.callback.onCarrierNetworkChange(active);
1192 } catch (RemoteException ex) {
1193 mRemoveList.add(r.binder);
1194 }
1195 }
1196 }
1197 handleRemoveListLocked();
1198 }
1199 }
1200
Wink Savilleb208a242012-07-25 14:08:09 -07001201 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001202 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001203 }
1204
Wink Saville63f03dd2014-10-23 10:44:45 -07001205 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001206 if (!checkNotifyPermission("notifyCellInfo()")) {
1207 return;
1208 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001209 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001210 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001211 + " cellInfo=" + cellInfo);
1212 }
yifan.baie620ce72017-12-22 14:59:57 +08001213 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001214 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001215 if (validatePhoneId(phoneId)) {
1216 mCellInfo.set(phoneId, cellInfo);
1217 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001218 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001219 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001220 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001221 try {
1222 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001223 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001224 }
1225 r.callback.onCellInfoChanged(cellInfo);
1226 } catch (RemoteException ex) {
1227 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001228 }
John Wang963db55d2012-03-30 16:04:06 -07001229 }
1230 }
1231 }
1232 handleRemoveListLocked();
1233 }
1234 }
1235
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001236 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1237 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1238 configs);
1239 }
1240
1241 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1242 List<PhysicalChannelConfig> configs) {
1243 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1244 return;
1245 }
1246
1247 if (VDBG) {
1248 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1249 }
1250
1251 synchronized (mRecords) {
1252 int phoneId = SubscriptionManager.getPhoneId(subId);
1253 if (validatePhoneId(phoneId)) {
1254 mPhysicalChannelConfigs.set(phoneId, configs);
1255 for (Record r : mRecords) {
1256 if (r.matchPhoneStateListenerEvent(
1257 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1258 && idMatch(r.subId, subId, phoneId)) {
1259 try {
1260 if (DBG_LOC) {
1261 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1262 + configs + " r=" + r);
1263 }
1264 r.callback.onPhysicalChannelConfigurationChanged(configs);
1265 } catch (RemoteException ex) {
1266 mRemoveList.add(r.binder);
1267 }
1268 }
1269 }
1270 }
1271 handleRemoveListLocked();
1272 }
1273 }
1274
xinhe43c50292014-09-18 17:56:48 -07001275 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001276 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001277 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001278 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001279 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001280 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001281 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001282 + " mwi=" + mwi);
1283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001285 if (validatePhoneId(phoneId)) {
1286 mMessageWaiting[phoneId] = mwi;
1287 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001288 if (r.matchPhoneStateListenerEvent(
1289 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001290 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001291 try {
1292 r.callback.onMessageWaitingIndicatorChanged(mwi);
1293 } catch (RemoteException ex) {
1294 mRemoveList.add(r.binder);
1295 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 }
1297 }
1298 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001299 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 }
1301 }
1302
zxuan35a47022018-01-04 11:24:04 -08001303 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1304 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1305 return;
1306 }
1307 if (VDBG) {
1308 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1309 + " state=" + state);
1310 }
1311 synchronized (mRecords) {
1312 if (validatePhoneId(phoneId)) {
1313 mMessageWaiting[phoneId] = state;
1314 for (Record r : mRecords) {
1315 if (r.matchPhoneStateListenerEvent(
1316 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1317 idMatch(r.subId, subId, phoneId)) {
1318 try {
1319 r.callback.onUserMobileDataStateChanged(state);
1320 } catch (RemoteException ex) {
1321 mRemoveList.add(r.binder);
1322 }
1323 }
1324 }
1325 }
1326 handleRemoveListLocked();
1327 }
1328 }
1329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001331 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001332 }
1333
Wink Saville63f03dd2014-10-23 10:44:45 -07001334 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001335 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001336 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001337 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001338 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001339 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001340 + " cfi=" + cfi);
1341 }
yifan.baie620ce72017-12-22 14:59:57 +08001342 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001344 if (validatePhoneId(phoneId)) {
1345 mCallForwarding[phoneId] = cfi;
1346 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001347 if (r.matchPhoneStateListenerEvent(
1348 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001349 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001350 try {
1351 r.callback.onCallForwardingIndicatorChanged(cfi);
1352 } catch (RemoteException ex) {
1353 mRemoveList.add(r.binder);
1354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 }
1356 }
1357 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001358 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 }
1360 }
1361
1362 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001363 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001364 }
1365
Wink Saville63f03dd2014-10-23 10:44:45 -07001366 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001367 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001368 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001369 }
yifan.baie620ce72017-12-22 14:59:57 +08001370 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001372 if (validatePhoneId(phoneId)) {
1373 mDataActivity[phoneId] = state;
1374 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001375 // Notify by correct subId.
1376 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1377 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001378 try {
1379 r.callback.onDataActivity(state);
1380 } catch (RemoteException ex) {
1381 mRemoveList.add(r.binder);
1382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 }
1384 }
1385 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001386 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001387 }
1388 }
1389
Jack Yuf05919a2019-01-02 16:51:08 -08001390 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1391 LinkProperties linkProperties,
1392 NetworkCapabilities networkCapabilities, int networkType,
1393 boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001394 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yuf05919a2019-01-02 16:51:08 -08001395 isDataAllowed, apn, apnType, linkProperties,
1396 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001397 }
1398
Jack Yuf05919a2019-01-02 16:51:08 -08001399 public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataAllowed,
1400 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001401 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1402 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001403 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001404 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001405 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001406 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001407 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001408 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001409 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001410 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001411 }
yifan.baie620ce72017-12-22 14:59:57 +08001412 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001414 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001415 // We only call the callback when the change is for default APN type.
1416 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1417 && (mDataConnectionState[phoneId] != state
1418 || mDataConnectionNetworkType[phoneId] != networkType)) {
1419 String str = "onDataConnectionStateChanged(" + state
1420 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001421 log(str);
1422 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001423 for (Record r : mRecords) {
1424 if (r.matchPhoneStateListenerEvent(
1425 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1426 idMatch(r.subId, subId, phoneId)) {
1427 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001428 if (DBG) {
1429 log("Notify data connection state changed on sub: " + subId);
1430 }
Jack Yub1bac542018-03-14 16:23:38 -07001431 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001432 } catch (RemoteException ex) {
1433 mRemoveList.add(r.binder);
1434 }
1435 }
1436 }
1437 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001438
1439 mDataConnectionState[phoneId] = state;
1440 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001441 }
1442 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
chen xu896e3d42018-12-11 18:09:41 -08001443 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1444 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001445 for (Record r : mRecords) {
1446 if (r.matchPhoneStateListenerEvent(
1447 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1448 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001449 r.callback.onPreciseDataConnectionStateChanged(
1450 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001451 } catch (RemoteException ex) {
1452 mRemoveList.add(r.binder);
1453 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001454 }
1455 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001456 }
1457 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 }
Jack Yuf05919a2019-01-02 16:51:08 -08001459 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1460 networkCapabilities, roaming, subId);
1461 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu896e3d42018-12-11 18:09:41 -08001462 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 }
1464
Jack Yuf05919a2019-01-02 16:51:08 -08001465 public void notifyDataConnectionFailed(String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001466 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yuf05919a2019-01-02 16:51:08 -08001467 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001468 }
1469
Jack Yuf05919a2019-01-02 16:51:08 -08001470 public void notifyDataConnectionFailedForSubscriber(int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001471 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001472 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001473 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001474 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001475 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yuf05919a2019-01-02 16:51:08 -08001476 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001477 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001479 mPreciseDataConnectionState = new PreciseDataConnectionState(
1480 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001481 ApnSetting.getApnTypesBitmaskFromString(apnType), "", null,
1482 DataFailCause.NONE);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001483 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001484 if (r.matchPhoneStateListenerEvent(
1485 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001486 try {
1487 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1488 } catch (RemoteException ex) {
1489 mRemoveList.add(r.binder);
1490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 }
1492 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001493 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 }
Jack Yuf05919a2019-01-02 16:51:08 -08001495 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001496 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001497 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", null,
1498 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 }
1500
1501 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001502 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001503 }
1504
Wink Saville63f03dd2014-10-23 10:44:45 -07001505 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001506 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001507 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001508 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001509 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001510 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001511 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001512 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001513 + " cellLocation=" + cellLocation);
1514 }
yifan.baie620ce72017-12-22 14:59:57 +08001515 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001517 if (validatePhoneId(phoneId)) {
1518 mCellLocation[phoneId] = cellLocation;
1519 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001520 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001521 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001522 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001523 try {
1524 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001525 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001526 + " r=" + r);
1527 }
1528 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1529 } catch (RemoteException ex) {
1530 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001531 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 }
1534 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001535 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001536 }
1537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538
Wink Savillefd2d0132010-10-28 14:22:26 -07001539 public void notifyOtaspChanged(int otaspMode) {
1540 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1541 return;
1542 }
1543 synchronized (mRecords) {
1544 mOtaspMode = otaspMode;
1545 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001546 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001547 try {
1548 r.callback.onOtaspChanged(otaspMode);
1549 } catch (RemoteException ex) {
1550 mRemoveList.add(r.binder);
1551 }
1552 }
1553 }
1554 handleRemoveListLocked();
1555 }
1556 }
1557
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001558 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001559 int backgroundCallState, int phoneId) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001560 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1561 return;
1562 }
1563 synchronized (mRecords) {
1564 mRingingCallState = ringingCallState;
1565 mForegroundCallState = foregroundCallState;
1566 mBackgroundCallState = backgroundCallState;
1567 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1568 backgroundCallState,
1569 DisconnectCause.NOT_VALID,
1570 PreciseDisconnectCause.NOT_VALID);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001571 boolean notifyCallAttributes = true;
1572 if (mCallQuality == null) {
1573 log("notifyPreciseCallState: mCallQuality is null, skipping call attributes");
1574 notifyCallAttributes = false;
1575 } else {
1576 mCallAttributes = new CallAttributes(mPreciseCallState, mNetworkType[phoneId],
1577 mCallQuality);
1578 }
1579
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001580 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001581 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001582 try {
1583 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1584 } catch (RemoteException ex) {
1585 mRemoveList.add(r.binder);
1586 }
1587 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001588 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1589 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1590 try {
1591 r.callback.onCallAttributesChanged(mCallAttributes);
1592 } catch (RemoteException ex) {
1593 mRemoveList.add(r.binder);
1594 }
1595 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001596 }
1597 handleRemoveListLocked();
1598 }
chen xu970d7792018-12-12 19:59:30 -08001599 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1600 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001601 }
1602
1603 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1604 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1605 return;
1606 }
1607 synchronized (mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001608 mCallDisconnectCause = disconnectCause;
1609 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001610 for (Record r : mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001611 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1612 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001613 try {
chen xu970d7792018-12-12 19:59:30 -08001614 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1615 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001616 } catch (RemoteException ex) {
1617 mRemoveList.add(r.binder);
1618 }
1619 }
1620 }
1621 handleRemoveListLocked();
1622 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001623 }
1624
chen xu0f494682019-01-24 14:14:13 -08001625 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1626 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1627 return;
1628 }
1629 int phoneId = SubscriptionManager.getPhoneId(subId);
1630 synchronized (mRecords) {
1631 if (validatePhoneId(phoneId)) {
1632 mImsReasonInfo.set(phoneId, imsReasonInfo);
1633 for (Record r : mRecords) {
1634 if (r.matchPhoneStateListenerEvent(
1635 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1636 && idMatch(r.subId, subId, phoneId)) {
1637 try {
1638 if (DBG_LOC) {
1639 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1640 + imsReasonInfo + " r=" + r);
1641 }
1642 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1643 } catch (RemoteException ex) {
1644 mRemoveList.add(r.binder);
1645 }
1646 }
1647 }
1648 }
1649 handleRemoveListLocked();
1650 }
1651 }
1652
chen xu896e3d42018-12-11 18:09:41 -08001653 public void notifyPreciseDataConnectionFailed(String apnType,
1654 String apn, @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001655 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1656 return;
1657 }
1658 synchronized (mRecords) {
1659 mPreciseDataConnectionState = new PreciseDataConnectionState(
1660 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001661 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001662 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001663 if (r.matchPhoneStateListenerEvent(
1664 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001665 try {
1666 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1667 } catch (RemoteException ex) {
1668 mRemoveList.add(r.binder);
1669 }
1670 }
1671 }
1672 handleRemoveListLocked();
1673 }
1674 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yuf05919a2019-01-02 16:51:08 -08001675 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001676 }
1677
Brad Ebingerefed9822018-10-26 10:25:57 -07001678 @Override
1679 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1680 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001681 return;
1682 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001683 if (VDBG) {
1684 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1685 }
1686 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001687 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001688 if (validatePhoneId(phoneId)) {
chen xu0f494682019-01-24 14:14:13 -08001689 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001690 for (Record r : mRecords) {
1691 if (r.matchPhoneStateListenerEvent(
1692 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1693 idMatch(r.subId, subId, phoneId)) {
1694 try {
1695 if (DBG_LOC) {
1696 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1697 }
1698 r.callback.onSrvccStateChanged(state);
1699 } catch (RemoteException ex) {
1700 mRemoveList.add(r.binder);
1701 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001702 }
1703 }
1704 }
1705 handleRemoveListLocked();
1706 }
1707 }
1708
Shuo Qian066e8652018-04-25 21:02:35 +00001709 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1710 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1711 return;
1712 }
1713
1714 synchronized (mRecords) {
1715 for (Record r : mRecords) {
1716 if (VDBG) {
1717 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1718 }
1719 if ((r.matchPhoneStateListenerEvent(
1720 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1721 ((r.subId == subId) ||
1722 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1723 try {
1724 r.callback.onOemHookRawEvent(rawData);
1725 } catch (RemoteException ex) {
1726 mRemoveList.add(r.binder);
1727 }
1728 }
1729 }
1730 handleRemoveListLocked();
1731 }
1732 }
1733
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001734 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1735 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1736 return;
1737 }
1738
1739 if (VDBG) {
1740 log("notifyPhoneCapabilityChanged: capability=" + capability);
1741 }
1742
1743 synchronized (mRecords) {
1744 mPhoneCapability = capability;
1745
1746 for (Record r : mRecords) {
1747 if (r.matchPhoneStateListenerEvent(
1748 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1749 try {
1750 r.callback.onPhoneCapabilityChanged(capability);
1751 } catch (RemoteException ex) {
1752 mRemoveList.add(r.binder);
1753 }
1754 }
1755 }
1756 handleRemoveListLocked();
1757 }
1758 }
1759
Malcolm Chenc1873af2018-09-24 20:01:32 -07001760 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1761 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1762 return;
1763 }
1764
1765 if (VDBG) {
1766 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1767 }
1768
1769 synchronized (mRecords) {
1770 mPreferredDataSubId = preferredSubId;
1771
1772 for (Record r : mRecords) {
1773 if (r.matchPhoneStateListenerEvent(
1774 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1775 try {
1776 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1777 } catch (RemoteException ex) {
1778 mRemoveList.add(r.binder);
1779 }
1780 }
1781 }
1782 handleRemoveListLocked();
1783 }
1784 }
1785
chen xu760729c2018-10-11 13:18:26 -07001786 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1787 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1788 return;
1789 }
1790
1791 if (VDBG) {
1792 log("notifyRadioPowerStateChanged: state= " + state);
1793 }
1794
1795 synchronized (mRecords) {
1796 mRadioPowerState = state;
1797
1798 for (Record r : mRecords) {
1799 if (r.matchPhoneStateListenerEvent(
1800 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1801 try {
1802 r.callback.onRadioPowerStateChanged(state);
1803 } catch (RemoteException ex) {
1804 mRemoveList.add(r.binder);
1805 }
1806 }
1807 }
1808 handleRemoveListLocked();
1809 }
1810 }
1811
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 @Override
sqian46c0c302018-12-27 14:12:11 -08001814 public void notifyEmergencyNumberList() {
1815 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1816 return;
1817 }
1818
1819 synchronized (mRecords) {
sqian3e8647c2018-12-14 21:47:49 -08001820 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1821 Context.TELEPHONY_SERVICE);
1822 mEmergencyNumberList = tm.getCurrentEmergencyNumberList();
sqian46c0c302018-12-27 14:12:11 -08001823
1824 for (Record r : mRecords) {
1825 if (r.matchPhoneStateListenerEvent(
1826 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)) {
1827 try {
1828 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1829 if (VDBG) {
1830 log("notifyEmergencyNumberList: emergencyNumberList= "
1831 + mEmergencyNumberList);
1832 }
1833 } catch (RemoteException ex) {
1834 mRemoveList.add(r.binder);
1835 }
1836 }
1837 }
1838 handleRemoveListLocked();
1839 }
sqianbf165bc2018-12-07 17:09:39 -08001840 }
1841
Jordan Liu8218ddd2018-11-28 11:22:39 -08001842 @Override
1843 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId) {
1844 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
1845 return;
1846 }
1847
1848 // merge CallQuality with PreciseCallState and network type
1849 mCallQuality = callQuality;
1850 mCallAttributes = new CallAttributes(mPreciseCallState,
1851 mNetworkType[phoneId],
1852 callQuality);
1853
1854 synchronized (mRecords) {
1855 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1856 Context.TELEPHONY_SERVICE);
1857
1858 for (Record r : mRecords) {
1859 if (r.matchPhoneStateListenerEvent(
1860 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1861 try {
1862 r.callback.onCallAttributesChanged(mCallAttributes);
1863 } catch (RemoteException ex) {
1864 mRemoveList.add(r.binder);
1865 }
1866 }
1867 }
1868 handleRemoveListLocked();
1869 }
1870 }
1871
sqianbf165bc2018-12-07 17:09:39 -08001872
1873 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001874 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1875 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1876
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001877 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001880 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001882 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301883 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001884 pw.println("Phone Id=" + i);
1885 pw.increaseIndent();
1886 pw.println("mCallState=" + mCallState[i]);
1887 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1888 pw.println("mServiceState=" + mServiceState[i]);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001889 pw.println("mNetworkType=" + mNetworkType[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001890 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1891 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001892 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001893 pw.println("mSignalStrength=" + mSignalStrength[i]);
1894 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1895 pw.println("mCallForwarding=" + mCallForwarding[i]);
1896 pw.println("mDataActivity=" + mDataActivity[i]);
1897 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001898 pw.println("mCellLocation=" + mCellLocation[i]);
1899 pw.println("mCellInfo=" + mCellInfo.get(i));
chen xu0f494682019-01-24 14:14:13 -08001900 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i).toString());
Jack Yud19b6ae2017-04-05 14:12:09 -07001901 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301902 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001903 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1904 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu970d7792018-12-12 19:59:30 -08001905 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1906 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001907 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1908 pw.println("mRingingCallState=" + mRingingCallState);
1909 pw.println("mForegroundCallState=" + mForegroundCallState);
1910 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001911 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001912 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chenc1873af2018-09-24 20:01:32 -07001913 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
chen xu760729c2018-10-11 13:18:26 -07001914 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian46c0c302018-12-27 14:12:11 -08001915 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001916 pw.println("mCallQuality=" + mCallQuality);
1917 pw.println("mCallAttributes=" + mCallAttributes);
Jack Yud19b6ae2017-04-05 14:12:09 -07001918
1919 pw.decreaseIndent();
1920
1921 pw.println("local logs:");
1922 pw.increaseIndent();
1923 mLocalLog.dump(fd, pw, args);
1924 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001925 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001926 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001927 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001928 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001930 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 }
1932 }
1933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 //
1935 // the legacy intent broadcasting
1936 //
1937
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001938 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001939 long ident = Binder.clearCallingIdentity();
1940 try {
1941 mBatteryStats.notePhoneState(state.getState());
1942 } catch (RemoteException re) {
1943 // Can't do much
1944 } finally {
1945 Binder.restoreCallingIdentity(ident);
1946 }
1947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001949 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 Bundle data = new Bundle();
1951 state.fillInNotifierBundle(data);
1952 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001953 // Pass the subscription along with the intent.
1954 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001955 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001956 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001957 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 }
1959
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001960 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1961 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001962 long ident = Binder.clearCallingIdentity();
1963 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001964 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001965 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001966 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001967 } finally {
1968 Binder.restoreCallingIdentity(ident);
1969 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001972 Bundle data = new Bundle();
1973 signalStrength.fillInNotifierBundle(data);
1974 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001975 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001976 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001977 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 }
1979
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001980 /**
1981 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1982 * a valid subId, in which case this function fires a subId-specific intent, or it
1983 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1984 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1985 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001986 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1987 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 long ident = Binder.clearCallingIdentity();
1989 try {
1990 if (state == TelephonyManager.CALL_STATE_IDLE) {
1991 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001992 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1993 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 } else {
1995 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001996 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1997 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 }
1999 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002000 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 } finally {
2002 Binder.restoreCallingIdentity(ident);
2003 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002006 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002007 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002008
2009 // If a valid subId was specified, we should fire off a subId-specific state
2010 // change intent and include the subId.
2011 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
2012 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
2013 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002014 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002015 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002016 // If the phoneId is invalid, the broadcast is for overall call state.
2017 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
2018 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
2019 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002020
Brad Ebinger51de96a2017-04-21 17:05:18 -07002021 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
2022 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
2023
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07002024 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002025 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07002026 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2027
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002028 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2029 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002030 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002031 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002032 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002033 android.Manifest.permission.READ_PHONE_STATE,
2034 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002035 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2036 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2037 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 }
2039
Jack Yuf05919a2019-01-02 16:51:08 -08002040 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2041 String apnType, LinkProperties linkProperties,
2042 NetworkCapabilities networkCapabilities,
2043 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002044 // Note: not reporting to the battery stats service here, because the
2045 // status bar takes care of that after taking into account all of the
2046 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002048 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002049 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07002050 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002051 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002053 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002054 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002055 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002056 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002057 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002058 }
2059 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002060 if (networkCapabilities != null) {
2061 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002062 }
Wink Savillea639b312012-07-10 12:37:54 -07002063 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002064
Wink Savillea639b312012-07-10 12:37:54 -07002065 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2066 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002067 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002068 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 }
2070
Jack Yuf05919a2019-01-02 16:51:08 -08002071 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002072 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002073 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002074 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002075 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002077
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002078 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yuf05919a2019-01-02 16:51:08 -08002079 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002080 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2081 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2082 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2083 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002084 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2085 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2086 }
2087
2088 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu896e3d42018-12-11 18:09:41 -08002089 String apnType, String apn, LinkProperties linkProperties,
2090 @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002091 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2092 intent.putExtra(PhoneConstants.STATE_KEY, state);
2093 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002094 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2095 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002096 if (linkProperties != null) {
Jack Yuf05919a2019-01-02 16:51:08 -08002097 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002098 }
chen xu896e3d42018-12-11 18:09:41 -08002099 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002100
2101 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2102 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2103 }
2104
Andrew Flynnceaed682015-06-09 12:36:58 +00002105 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002106 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002107 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002108 }
2109
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002110 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2111 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002112 }
2113
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002114 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002115 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002116 return true;
2117 }
2118 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002119 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002120 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002121 return false;
2122 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002123
Andrew Flynn1f452642015-04-14 22:16:04 -04002124 private boolean checkNotifyPermission() {
2125 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2126 == PackageManager.PERMISSION_GRANTED;
2127 }
2128
Jeff Davidson29da89f2018-02-28 17:50:16 -08002129 private boolean checkListenerPermission(
2130 int events, int subId, String callingPackage, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002131 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2132 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2133 .setCallingPackage(callingPackage)
2134 .setMethod(message + " events: " + events)
2135 .setCallingPid(Binder.getCallingPid())
2136 .setCallingUid(Binder.getCallingUid());
2137
2138 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002139 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002140 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2141 shouldCheckLocationPermissions = true;
2142 }
2143
2144 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2145 // Everything that requires fine location started in Q. So far...
2146 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2147 shouldCheckLocationPermissions = true;
2148 }
2149
2150 if (shouldCheckLocationPermissions) {
2151 LocationAccessPolicy.LocationPermissionResult result =
2152 LocationAccessPolicy.checkLocationPermission(
2153 mContext, locationQueryBuilder.build());
2154 switch (result) {
2155 case DENIED_HARD:
2156 throw new SecurityException("Unable to listen for events " + events + " due to "
2157 + "insufficient location permissions.");
2158 case DENIED_SOFT:
2159 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002160 }
John Wang963db55d2012-03-30 16:04:06 -07002161 }
2162
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002163 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2165 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002166 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002167 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002168 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002169
2170 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2171 mContext.enforceCallingOrSelfPermission(
2172 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002173 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002174
Shuo Qian066e8652018-04-25 21:02:35 +00002175 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2176 mContext.enforceCallingOrSelfPermission(
2177 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2178 }
2179
Brad Ebingerefed9822018-10-26 10:25:57 -07002180 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2181 mContext.enforceCallingOrSelfPermission(
2182 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2183 }
2184
Malcolm Chend4dc4ee2018-12-11 13:56:53 -08002185 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
2186 // It can have either READ_PHONE_STATE or READ_PRIVILEGED_PHONE_STATE.
2187 TelephonyPermissions.checkReadPhoneState(mContext,
2188 SubscriptionManager.INVALID_SUBSCRIPTION_ID, Binder.getCallingPid(),
2189 Binder.getCallingUid(), callingPackage, "listen to "
2190 + "LISTEN_PREFERRED_DATA_SUBID_CHANGE");
2191 }
Brad Ebingerefed9822018-10-26 10:25:57 -07002192
chen xu970d7792018-12-12 19:59:30 -08002193 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2194 mContext.enforceCallingOrSelfPermission(
2195 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2196 }
2197
Jordan Liu8218ddd2018-11-28 11:22:39 -08002198 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2199 mContext.enforceCallingOrSelfPermission(
2200 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2201 }
2202
chen xu52797b62019-01-18 13:16:31 -08002203 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2204 mContext.enforceCallingOrSelfPermission(
2205 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2206 }
2207
2208 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2209 mContext.enforceCallingOrSelfPermission(
2210 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2211 }
2212
chen xu0f494682019-01-24 14:14:13 -08002213 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2214 mContext.enforceCallingOrSelfPermission(
2215 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2216 }
2217
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002218 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002219 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002220
2221 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002222 int size = mRemoveList.size();
2223 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2224 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002225 for (IBinder b: mRemoveList) {
2226 remove(b);
2227 }
2228 mRemoveList.clear();
2229 }
2230 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002231
2232 private boolean validateEventsAndUserLocked(Record r, int events) {
2233 int foregroundUser;
2234 long callingIdentity = Binder.clearCallingIdentity();
2235 boolean valid = false;
2236 try {
2237 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002238 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2239 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002240 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002241 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002242 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002243 + " r.events=" + r.events + " events=" + events);
2244 }
2245 } finally {
2246 Binder.restoreCallingIdentity(callingIdentity);
2247 }
2248 return valid;
2249 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002250
2251 private boolean validatePhoneId(int phoneId) {
2252 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002253 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002254 return valid;
2255 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002256
2257 private static void log(String s) {
2258 Rlog.d(TAG, s);
2259 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002260
xinhe8b79fb62014-11-05 14:55:03 -08002261 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002262
2263 if(subId < 0) {
2264 // Invalid case, we need compare phoneId with default one.
2265 return (mDefaultPhoneId == phoneId);
2266 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002267 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002268 return (subId == mDefaultSubId);
2269 } else {
2270 return (rSubId == subId);
2271 }
2272 }
2273
Hall Liuee313732018-11-27 14:36:51 -08002274 private boolean checkFineLocationAccess(Record r, int minSdk) {
2275 LocationAccessPolicy.LocationPermissionQuery query =
2276 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2277 .setCallingPackage(r.callingPackage)
2278 .setCallingPid(r.callerPid)
2279 .setCallingUid(r.callerUid)
2280 .setMethod("TelephonyRegistry push")
2281 .setMinSdkVersionForFine(minSdk)
2282 .build();
2283
2284 return Binder.withCleanCallingIdentity(() -> {
2285 LocationAccessPolicy.LocationPermissionResult locationResult =
2286 LocationAccessPolicy.checkLocationPermission(mContext, query);
2287 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2288 });
2289 }
2290
2291 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2292 LocationAccessPolicy.LocationPermissionQuery query =
2293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2294 .setCallingPackage(r.callingPackage)
2295 .setCallingPid(r.callerPid)
2296 .setCallingUid(r.callerUid)
2297 .setMethod("TelephonyRegistry push")
2298 .setMinSdkVersionForCoarse(minSdk)
2299 .build();
2300
2301 return Binder.withCleanCallingIdentity(() -> {
2302 LocationAccessPolicy.LocationPermissionResult locationResult =
2303 LocationAccessPolicy.checkLocationPermission(mContext, query);
2304 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2305 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002306 }
2307
xinhee9f16402014-09-25 16:39:28 -07002308 private void checkPossibleMissNotify(Record r, int phoneId) {
2309 int events = r.events;
2310
2311 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2312 try {
2313 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2314 mServiceState[phoneId]);
2315 r.callback.onServiceStateChanged(
2316 new ServiceState(mServiceState[phoneId]));
2317 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002318 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002319 }
2320 }
2321
2322 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2323 try {
2324 SignalStrength signalStrength = mSignalStrength[phoneId];
2325 if (DBG) {
2326 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2327 }
2328 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2329 } catch (RemoteException ex) {
2330 mRemoveList.add(r.binder);
2331 }
2332 }
2333
2334 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2335 try {
2336 int gsmSignalStrength = mSignalStrength[phoneId]
2337 .getGsmSignalStrength();
2338 if (DBG) {
2339 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2340 gsmSignalStrength);
2341 }
2342 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2343 : gsmSignalStrength));
2344 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002345 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002346 }
2347 }
2348
2349 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2350 try {
2351 if (DBG_LOC) {
2352 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2353 + mCellInfo.get(phoneId));
2354 }
Hall Liuee313732018-11-27 14:36:51 -08002355 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002356 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2357 }
xinhee9f16402014-09-25 16:39:28 -07002358 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002359 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002360 }
2361 }
2362
zxuan35a47022018-01-04 11:24:04 -08002363 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2364 try {
2365 if (VDBG) {
2366 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2367 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2368 }
2369 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2370 } catch (RemoteException ex) {
2371 mRemoveList.add(r.binder);
2372 }
2373 }
2374
xinhee9f16402014-09-25 16:39:28 -07002375 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2376 try {
2377 if (VDBG) {
2378 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2379 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2380 }
2381 r.callback.onMessageWaitingIndicatorChanged(
2382 mMessageWaiting[phoneId]);
2383 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002384 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002385 }
2386 }
2387
2388 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2389 try {
2390 if (VDBG) {
2391 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2392 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2393 }
2394 r.callback.onCallForwardingIndicatorChanged(
2395 mCallForwarding[phoneId]);
2396 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002397 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002398 }
2399 }
2400
2401 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2402 try {
2403 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2404 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002405 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002406 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2407 }
xinhee9f16402014-09-25 16:39:28 -07002408 } catch (RemoteException ex) {
2409 mRemoveList.add(r.binder);
2410 }
2411 }
2412
2413 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2414 try {
2415 if (DBG) {
2416 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2417 + "=" + mDataConnectionState[phoneId]
2418 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2419 + ")");
2420 }
2421 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2422 mDataConnectionNetworkType[phoneId]);
2423 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002424 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002425 }
2426 }
2427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428}