blob: b4d45d475917c6c8910bfac1172e65ea249f666d [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
fionaxu12312f62016-11-14 13:32:14 -0800180 private int[] mVoiceActivationState;
181
182 private int[] mDataActivationState;
183
zxuan35a47022018-01-04 11:24:04 -0800184 private boolean[] mUserMobileDataState;
185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700191
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700193
Jack Yub1bac542018-03-14 16:23:38 -0700194 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700196
Wink Savillefb40dd42014-06-12 17:02:31 -0700197 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700200
Nathan Harold016e9c62016-12-14 11:24:48 -0800201 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700202
Wink Savillefb40dd42014-06-12 17:02:31 -0700203 private ArrayList<List<CellInfo>> mCellInfo = null;
204
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800205 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
206
sqian46c0c302018-12-27 14:12:11 -0800207 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
208
Jordan Liueae57b22019-01-22 16:17:35 -0800209 private CallQuality mCallQuality = new CallQuality();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800210
Jordan Liueae57b22019-01-22 16:17:35 -0800211 private CallAttributes mCallAttributes = new CallAttributes(new PreciseCallState(),
212 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
Jordan Liu8218ddd2018-11-28 11:22:39 -0800213
Jordan Liu65ed9d92019-02-19 14:42:07 -0800214 // network type of the call associated with the mCallAttributes and mCallQuality
215 private int mCallNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
216
Brad Ebingerefed9822018-10-26 10:25:57 -0700217 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700218
Wink Savilled09c4ca2014-11-22 10:08:16 -0800219 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700220
Wink Savilled09c4ca2014-11-22 10:08:16 -0800221 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700222
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200223 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
224
225 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
226
227 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
228
229 private PreciseCallState mPreciseCallState = new PreciseCallState();
230
chen xu970d7792018-12-12 19:59:30 -0800231 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
232
chen xu0f494682019-01-24 14:14:13 -0800233 private List<ImsReasonInfo> mImsReasonInfo = null;
234
chen xu970d7792018-12-12 19:59:30 -0800235 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
236
Andrew Flynn1f452642015-04-14 22:16:04 -0400237 private boolean mCarrierNetworkChangeState = false;
238
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700239 private PhoneCapability mPhoneCapability = null;
240
chen xu760729c2018-10-11 13:18:26 -0700241 @TelephonyManager.RadioPowerState
242 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
243
Malcolm Chenc1873af2018-09-24 20:01:32 -0700244 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
245
Jack Yud19b6ae2017-04-05 14:12:09 -0700246 private final LocalLog mLocalLog = new LocalLog(100);
247
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200248 private PreciseDataConnectionState mPreciseDataConnectionState =
249 new PreciseDataConnectionState();
250
Hall Liuee313732018-11-27 14:36:51 -0800251 // Nothing here yet, but putting it here in case we want to add more in the future.
252 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = 0;
253
254 static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK =
Hall Liu70bbc162018-03-02 17:44:46 -0800255 PhoneStateListener.LISTEN_CELL_LOCATION
256 | PhoneStateListener.LISTEN_CELL_INFO;
257
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700258 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian46c0c302018-12-27 14:12:11 -0800259 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
260 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
261 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700262
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200263 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
264 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
265 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
266
Wink Savillea12a7b32012-09-20 10:09:45 -0700267 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700268 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700269
270 private final Handler mHandler = new Handler() {
271 @Override
272 public void handleMessage(Message msg) {
273 switch (msg.what) {
274 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700275 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700276 int numPhones = TelephonyManager.getDefault().getPhoneCount();
277 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700278 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700279 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700280 }
281 break;
282 }
xinhee9f16402014-09-25 16:39:28 -0700283 case MSG_UPDATE_DEFAULT_SUB: {
284 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700285 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700286 if (VDBG) {
287 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
288 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
289 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
290 }
291
292 //Due to possible risk condition,(notify call back using the new
293 //defaultSubId comes before new defaultSubId update) we need to recall all
294 //possible missed notify callback
295 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700296 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800297 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700298 checkPossibleMissNotify(r, newDefaultPhoneId);
299 }
300 }
301 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700302 }
303 mDefaultSubId = newDefaultSubId;
304 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700305 }
306 }
307 }
308 };
309
Malcolm Chenabbfac22018-02-12 19:15:59 -0800310 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
311
312 private final IBinder binder;
313
314 TelephonyRegistryDeathRecipient(IBinder binder) {
315 this.binder = binder;
316 }
317
318 @Override
319 public void binderDied() {
320 if (DBG) log("binderDied " + binder);
321 remove(binder);
322 }
323 }
324
Wink Savillea12a7b32012-09-20 10:09:45 -0700325 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
326 @Override
327 public void onReceive(Context context, Intent intent) {
328 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700329 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700330 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700331 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700332 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700333 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700334 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700335 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800336 PhoneConstants.SUBSCRIPTION_KEY,
337 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700338 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
339 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700340 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700341 log("onReceive:current mDefaultSubId=" + mDefaultSubId
342 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
343 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700344 }
xinhee9f16402014-09-25 16:39:28 -0700345
Junda Liu985f52c2015-02-23 16:06:51 -0800346 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700347 || (newDefaultPhoneId != mDefaultPhoneId))) {
348 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
349 newDefaultPhoneId, 0, newDefaultSubIdObj));
350 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700351 }
352 }
353 };
354
Wink Savillee9b06d72009-05-18 21:47:50 -0700355 // we keep a copy of all of the state so we can send it out when folks
356 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700358 // In these calls we call with the lock held. This is safe becasuse remote
359 // calls go through a oneway interface and local calls going through a
360 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361
Malcolm Chen800a7d62018-08-27 20:38:29 -0700362 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
363 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700364 CellLocation location = CellLocation.getEmpty();
365
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 mContext = context;
367 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700368
Wink Savillefb40dd42014-06-12 17:02:31 -0700369 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700370 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700371 mNumPhones = numPhones;
372 mCallState = new int[numPhones];
373 mDataActivity = new int[numPhones];
374 mDataConnectionState = new int[numPhones];
375 mDataConnectionNetworkType = new int[numPhones];
376 mCallIncomingNumber = new String[numPhones];
377 mServiceState = new ServiceState[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();
398 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800399 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700400 mMessageWaiting[i] = false;
401 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700402 mCellLocation[i] = new Bundle();
403 mCellInfo.add(i, null);
chen xu0f494682019-01-24 14:14:13 -0800404 mImsReasonInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700405 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700406 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700407 }
408
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700409 // Note that location can be null for non-phone builds like
410 // like the generic one.
411 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700412 for (int i = 0; i < numPhones; i++) {
413 location.fillInNotifierBundle(mCellLocation[i]);
414 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700415 }
Svet Ganov16a16892015-04-16 10:32:04 -0700416
417 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 }
419
Svetoslav Ganova0027152013-06-25 14:59:53 -0700420 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700421 // Watch for interesting updates
422 final IntentFilter filter = new IntentFilter();
423 filter.addAction(Intent.ACTION_USER_SWITCHED);
424 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700425 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700426 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700427 mContext.registerReceiver(mBroadcastReceiver, filter);
428 }
429
430 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700431 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800432 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700433 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700436 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
437 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800438 + " callback.asBinder=" + callback.asBinder());
439 }
440
Wink Savilled09c4ca2014-11-22 10:08:16 -0800441 synchronized (mRecords) {
442 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800443 IBinder b = callback.asBinder();
444 Record r = add(b);
445
446 if (r == null) {
447 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800448 }
449
Jeff Davidson29da89f2018-02-28 17:50:16 -0800450 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800451 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700452 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800453 r.callerUid = Binder.getCallingUid();
454 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800455 r.events = 0;
456 if (DBG) {
457 log("listen oscl: Register r=" + r);
458 }
459 // Always notify when registration occurs if there has been a notification.
Malcolm Chen27829e22018-09-04 22:12:31 -0700460 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800461 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800462 if (VDBG) log("listen oscl: send to r=" + r);
463 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
464 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800465 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800466 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800467 remove(r.binder);
468 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800469 } else {
Malcolm Chen27829e22018-09-04 22:12:31 -0700470 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800471 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800472 }
473 }
474
475 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800476 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800477 IOnSubscriptionsChangedListener callback) {
478 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800479 remove(callback.asBinder());
480 }
481
Malcolm Chen27829e22018-09-04 22:12:31 -0700482
483 @Override
484 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
485 IOnSubscriptionsChangedListener callback) {
486 int callerUserId = UserHandle.getCallingUserId();
487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
488 if (VDBG) {
489 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
490 + " callerUserId=" + callerUserId + " callback=" + callback
491 + " callback.asBinder=" + callback.asBinder());
492 }
493
494 synchronized (mRecords) {
495 // register
496 IBinder b = callback.asBinder();
497 Record r = add(b);
498
499 if (r == null) {
500 return;
501 }
502
503 r.context = mContext;
504 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
505 r.callingPackage = callingPackage;
506 r.callerUid = Binder.getCallingUid();
507 r.callerPid = Binder.getCallingPid();
508 r.events = 0;
509 if (DBG) {
510 log("listen ooscl: Register r=" + r);
511 }
512 // Always notify when registration occurs if there has been a notification.
513 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
514 try {
515 if (VDBG) log("listen ooscl: send to r=" + r);
516 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
517 if (VDBG) log("listen ooscl: sent to r=" + r);
518 } catch (RemoteException e) {
519 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
520 remove(r.binder);
521 }
522 } else {
523 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
524 }
525 }
526 }
527
Wink Savillea374c3d2014-11-11 11:48:04 -0800528 @Override
529 public void notifySubscriptionInfoChanged() {
530 if (VDBG) log("notifySubscriptionInfoChanged:");
531 synchronized (mRecords) {
Malcolm Chen27829e22018-09-04 22:12:31 -0700532 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800533 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
534 + mRecords.size());
535 }
Malcolm Chen27829e22018-09-04 22:12:31 -0700536 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800537 mRemoveList.clear();
538 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800539 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800540 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800541 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
542 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
543 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800544 } catch (RemoteException ex) {
545 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
546 mRemoveList.add(r.binder);
547 }
548 }
549 }
550 handleRemoveListLocked();
551 }
552 }
553
554 @Override
Malcolm Chen27829e22018-09-04 22:12:31 -0700555 public void notifyOpportunisticSubscriptionInfoChanged() {
556 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
557 synchronized (mRecords) {
558 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
559 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
560 + mRecords.size());
561 }
562 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
563 mRemoveList.clear();
564 for (Record r : mRecords) {
565 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
566 try {
567 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
568 r.onOpportunisticSubscriptionsChangedListenerCallback
569 .onSubscriptionsChanged();
570 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
571 } catch (RemoteException ex) {
572 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
573 mRemoveList.add(r.binder);
574 }
575 }
576 }
577 handleRemoveListLocked();
578 }
579 }
580
581 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
583 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800584 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
585 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700586 }
587
588 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700589 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700590 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700591 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700592 }
593
Svet Ganov16a16892015-04-16 10:32:04 -0700594 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700595 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700596 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700598 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700599 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700600 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
601 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700602 }
xinhe75c2c152014-10-16 11:49:45 -0700603
604 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800605 // Checks permission and throws SecurityException for disallowed operations. For pre-M
606 // apps whose runtime permission has been revoked, we return immediately to skip sending
607 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800608 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800609 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700610 }
611
yifan.baie620ce72017-12-22 14:59:57 +0800612 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 synchronized (mRecords) {
614 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800615 IBinder b = callback.asBinder();
616 Record r = add(b);
617
618 if (r == null) {
619 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 }
xinhe43c50292014-09-18 17:56:48 -0700621
Jeff Davidson29da89f2018-02-28 17:50:16 -0800622 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700623 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700624 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800625 r.callerUid = Binder.getCallingUid();
626 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700627 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
628 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800630 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700631 } else {//APP specify subID
632 r.subId = subId;
633 }
yifan.baie620ce72017-12-22 14:59:57 +0800634 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700636 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700637 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700638 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700639 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400641 try {
Wink Savillee380b982014-07-26 18:24:22 -0700642 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800643 ServiceState rawSs = new ServiceState(mServiceState[phoneId]);
644 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
645 r.callback.onServiceStateChanged(rawSs);
646 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
647 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(false));
648 } else {
649 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(true));
650 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400651 } catch (RemoteException ex) {
652 remove(r.binder);
653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
656 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700657 int gsmSignalStrength = mSignalStrength[phoneId]
658 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700659 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
660 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 } catch (RemoteException ex) {
662 remove(r.binder);
663 }
664 }
665 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
666 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700667 r.callback.onMessageWaitingIndicatorChanged(
668 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 } catch (RemoteException ex) {
670 remove(r.binder);
671 }
672 }
673 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
674 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700675 r.callback.onCallForwardingIndicatorChanged(
676 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 } catch (RemoteException ex) {
678 remove(r.binder);
679 }
680 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700681 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400682 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700683 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700684 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800685 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800686 r.callback.onCellLocationChanged(
687 new Bundle(mCellLocation[phoneId]));
688 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400689 } catch (RemoteException ex) {
690 remove(r.binder);
691 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
694 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700695 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700696 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 } catch (RemoteException ex) {
698 remove(r.binder);
699 }
700 }
701 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
702 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700703 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
704 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 } catch (RemoteException ex) {
706 remove(r.binder);
707 }
708 }
709 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
710 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700711 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 } catch (RemoteException ex) {
713 remove(r.binder);
714 }
715 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700716 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
717 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700718 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700719 } catch (RemoteException ex) {
720 remove(r.binder);
721 }
722 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700723 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
724 try {
725 r.callback.onOtaspChanged(mOtaspMode);
726 } catch (RemoteException ex) {
727 remove(r.binder);
728 }
729 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700730 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700731 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700732 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700733 + mCellInfo.get(phoneId));
Hall Liuee313732018-11-27 14:36:51 -0800734 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800735 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
736 }
John Wang963db55d2012-03-30 16:04:06 -0700737 } catch (RemoteException ex) {
738 remove(r.binder);
739 }
740 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200741 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
742 try {
743 r.callback.onPreciseCallStateChanged(mPreciseCallState);
744 } catch (RemoteException ex) {
745 remove(r.binder);
746 }
747 }
chen xu970d7792018-12-12 19:59:30 -0800748 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
749 try {
750 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
751 mCallPreciseDisconnectCause);
752 } catch (RemoteException ex) {
753 remove(r.binder);
754 }
755 }
chen xu0f494682019-01-24 14:14:13 -0800756 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
757 try {
758 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
759 } catch (RemoteException ex) {
760 remove(r.binder);
761 }
762 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200763 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
764 try {
765 r.callback.onPreciseDataConnectionStateChanged(
766 mPreciseDataConnectionState);
767 } catch (RemoteException ex) {
768 remove(r.binder);
769 }
770 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400771 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
772 try {
773 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
774 } catch (RemoteException ex) {
775 remove(r.binder);
776 }
777 }
fionaxu12312f62016-11-14 13:32:14 -0800778 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
779 try {
780 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
781 } catch (RemoteException ex) {
782 remove(r.binder);
783 }
784 }
785 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
786 try {
787 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
788 } catch (RemoteException ex) {
789 remove(r.binder);
790 }
791 }
zxuan35a47022018-01-04 11:24:04 -0800792 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
793 try {
794 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
795 } catch (RemoteException ex) {
796 remove(r.binder);
797 }
798 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800799 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
800 try {
801 r.callback.onPhysicalChannelConfigurationChanged(
802 mPhysicalChannelConfigs.get(phoneId));
803 } catch (RemoteException ex) {
804 remove(r.binder);
805 }
806 }
sqian46c0c302018-12-27 14:12:11 -0800807 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
808 try {
809 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
810 } catch (RemoteException ex) {
811 remove(r.binder);
812 }
813 }
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700814 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
815 try {
816 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
817 } catch (RemoteException ex) {
818 remove(r.binder);
819 }
820 }
Malcolm Chenc1873af2018-09-24 20:01:32 -0700821 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
822 try {
823 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
824 } catch (RemoteException ex) {
825 remove(r.binder);
826 }
827 }
chen xu760729c2018-10-11 13:18:26 -0700828 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
829 try {
830 r.callback.onRadioPowerStateChanged(mRadioPowerState);
831 } catch (RemoteException ex) {
832 remove(r.binder);
833 }
834 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700835 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
836 try {
837 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
838 } catch (RemoteException ex) {
839 remove(r.binder);
840 }
841 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800842 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
843 try {
844 r.callback.onCallAttributesChanged(mCallAttributes);
845 } catch (RemoteException ex) {
846 remove(r.binder);
847 }
848 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 }
850 }
851 } else {
xinhe75c2c152014-10-16 11:49:45 -0700852 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 remove(callback.asBinder());
854 }
855 }
856
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700857 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700858 // Only reveal the incoming number if the record has read call log permission.
859 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700860 }
861
Malcolm Chenabbfac22018-02-12 19:15:59 -0800862 private Record add(IBinder binder) {
863 Record r;
864
865 synchronized (mRecords) {
866 final int N = mRecords.size();
867 for (int i = 0; i < N; i++) {
868 r = mRecords.get(i);
869 if (binder == r.binder) {
870 // Already existed.
871 return r;
872 }
873 }
874 r = new Record();
875 r.binder = binder;
876 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
877
878 try {
879 binder.linkToDeath(r.deathRecipient, 0);
880 } catch (RemoteException e) {
881 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
882 // Binder already died. Return null.
883 return null;
884 }
885
886 mRecords.add(r);
887 if (DBG) log("add new record");
888 }
889
890 return r;
891 }
892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 private void remove(IBinder binder) {
894 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700895 final int recordCount = mRecords.size();
896 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800897 Record r = mRecords.get(i);
898 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800899 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800900 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
901 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800902 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800903
904 if (r.deathRecipient != null) {
905 try {
906 binder.unlinkToDeath(r.deathRecipient, 0);
907 } catch (NoSuchElementException e) {
908 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
909 + r + " e=" + e);
910 }
911 }
912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 mRecords.remove(i);
914 return;
915 }
916 }
917 }
918 }
919
Tyler Gunnf955e562018-04-26 14:43:31 -0700920 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700921 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700922 return;
923 }
xinhe43c50292014-09-18 17:56:48 -0700924
925 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700926 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700927 }
928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700930 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800931 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800932 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700934 // Ensure the listener has read call log permission; if they do not return
935 // an empty phone number.
936 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
937 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400939 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 }
941 }
942 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400943 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700945
946 // Called only by Telecomm to communicate call state across different phone accounts. So
947 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700948 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700949 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700950 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 }
952
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700953 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
954 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700955 if (!checkNotifyPermission("notifyCallState()")) {
956 return;
957 }
Wink Savillee380b982014-07-26 18:24:22 -0700958 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700959 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700960 + " state=" + state + " incomingNumber=" + incomingNumber);
961 }
962 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700963 if (validatePhoneId(phoneId)) {
964 mCallState[phoneId] = state;
965 mCallIncomingNumber[phoneId] = incomingNumber;
966 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800967 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700968 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800969 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700970 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700971 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
972 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700973 } catch (RemoteException ex) {
974 mRemoveList.add(r.binder);
975 }
976 }
977 }
978 }
979 handleRemoveListLocked();
980 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700981 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700982 }
983
Wink Saville63f03dd2014-10-23 10:44:45 -0700984 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700985 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700986 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700987 }
xinhe43c50292014-09-18 17:56:48 -0700988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700990 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
991 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700992 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700993 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700994 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700995 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700996 if (validatePhoneId(phoneId)) {
997 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700998
Wink Savillefb40dd42014-06-12 17:02:31 -0700999 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001000 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001001 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001002 + " phoneId=" + phoneId + " state=" + state);
1003 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001004 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001005 idMatch(r.subId, subId, phoneId)) {
Hall Liuee313732018-11-27 14:36:51 -08001006
Wink Savillefb40dd42014-06-12 17:02:31 -07001007 try {
Hall Liuee313732018-11-27 14:36:51 -08001008 ServiceState stateToSend;
1009 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
1010 stateToSend = new ServiceState(state);
1011 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
1012 stateToSend = state.sanitizeLocationInfo(false);
1013 } else {
1014 stateToSend = state.sanitizeLocationInfo(true);
1015 }
Wink Savillee380b982014-07-26 18:24:22 -07001016 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001017 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001018 + " subId=" + subId + " phoneId=" + phoneId
1019 + " state=" + state);
1020 }
Hall Liuee313732018-11-27 14:36:51 -08001021 r.callback.onServiceStateChanged(stateToSend);
Wink Savillefb40dd42014-06-12 17:02:31 -07001022 } catch (RemoteException ex) {
1023 mRemoveList.add(r.binder);
1024 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001025 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001027 } else {
Wink Savillebc027272014-09-08 14:50:58 -07001028 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001030 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001032 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 }
1034
fionaxu12312f62016-11-14 13:32:14 -08001035 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1036 int activationType, int activationState) {
1037 if (!checkNotifyPermission("notifySimActivationState()")){
1038 return;
1039 }
1040 if (VDBG) {
1041 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1042 + "type=" + activationType + " state=" + activationState);
1043 }
1044 synchronized (mRecords) {
1045 if (validatePhoneId(phoneId)) {
1046 switch (activationType) {
1047 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
1048 mVoiceActivationState[phoneId] = activationState;
1049 break;
1050 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
1051 mDataActivationState[phoneId] = activationState;
1052 break;
1053 default:
1054 return;
1055 }
1056 for (Record r : mRecords) {
1057 if (VDBG) {
1058 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1059 + " phoneId=" + phoneId + "type=" + activationType
1060 + " state=" + activationState);
1061 }
1062 try {
1063 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1064 r.matchPhoneStateListenerEvent(
1065 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1066 idMatch(r.subId, subId, phoneId)) {
1067 if (DBG) {
1068 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1069 + " subId=" + subId + " phoneId=" + phoneId
1070 + " state=" + activationState);
1071 }
1072 r.callback.onVoiceActivationStateChanged(activationState);
1073 }
1074 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1075 r.matchPhoneStateListenerEvent(
1076 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1077 idMatch(r.subId, subId, phoneId)) {
1078 if (DBG) {
1079 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1080 + " subId=" + subId + " phoneId=" + phoneId
1081 + " state=" + activationState);
1082 }
1083 r.callback.onDataActivationStateChanged(activationState);
1084 }
1085 } catch (RemoteException ex) {
1086 mRemoveList.add(r.binder);
1087 }
1088 }
1089 } else {
1090 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1091 }
1092 handleRemoveListLocked();
1093 }
1094 }
1095
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001096 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1097 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001098 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001099 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001100 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001101 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001102 log("notifySignalStrengthForPhoneId: subId=" + subId
1103 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001104 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001107 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001108 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001109 mSignalStrength[phoneId] = signalStrength;
1110 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001111 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001112 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001113 + " phoneId=" + phoneId + " ss=" + signalStrength);
1114 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001115 if (r.matchPhoneStateListenerEvent(
1116 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001117 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001118 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001119 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001120 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001121 + " subId=" + subId + " phoneId=" + phoneId
1122 + " ss=" + signalStrength);
1123 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001124 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1125 } catch (RemoteException ex) {
1126 mRemoveList.add(r.binder);
1127 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001128 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001129 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001130 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001131 try {
1132 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001133 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001134 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001135 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001136 + " subId=" + subId + " phoneId=" + phoneId
1137 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1138 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001139 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001140 } catch (RemoteException ex) {
1141 mRemoveList.add(r.binder);
1142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 }
1144 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001145 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001146 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001148 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001150 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
1152
Andrew Flynn1f452642015-04-14 22:16:04 -04001153 @Override
1154 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001155 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1156
Andrew Flynn1f452642015-04-14 22:16:04 -04001157 if (VDBG) {
1158 log("notifyCarrierNetworkChange: active=" + active);
1159 }
1160
1161 synchronized (mRecords) {
1162 mCarrierNetworkChangeState = active;
1163 for (Record r : mRecords) {
1164 if (r.matchPhoneStateListenerEvent(
1165 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1166 try {
1167 r.callback.onCarrierNetworkChange(active);
1168 } catch (RemoteException ex) {
1169 mRemoveList.add(r.binder);
1170 }
1171 }
1172 }
1173 handleRemoveListLocked();
1174 }
1175 }
1176
Wink Savilleb208a242012-07-25 14:08:09 -07001177 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001178 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001179 }
1180
Wink Saville63f03dd2014-10-23 10:44:45 -07001181 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001182 if (!checkNotifyPermission("notifyCellInfo()")) {
1183 return;
1184 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001185 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001186 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001187 + " cellInfo=" + cellInfo);
1188 }
yifan.baie620ce72017-12-22 14:59:57 +08001189 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001190 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001191 if (validatePhoneId(phoneId)) {
1192 mCellInfo.set(phoneId, cellInfo);
1193 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001194 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001195 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001196 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001197 try {
1198 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001199 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001200 }
1201 r.callback.onCellInfoChanged(cellInfo);
1202 } catch (RemoteException ex) {
1203 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001204 }
John Wang963db55d2012-03-30 16:04:06 -07001205 }
1206 }
1207 }
1208 handleRemoveListLocked();
1209 }
1210 }
1211
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001212 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1213 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1214 configs);
1215 }
1216
1217 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1218 List<PhysicalChannelConfig> configs) {
1219 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1220 return;
1221 }
1222
1223 if (VDBG) {
1224 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1225 }
1226
1227 synchronized (mRecords) {
1228 int phoneId = SubscriptionManager.getPhoneId(subId);
1229 if (validatePhoneId(phoneId)) {
1230 mPhysicalChannelConfigs.set(phoneId, configs);
1231 for (Record r : mRecords) {
1232 if (r.matchPhoneStateListenerEvent(
1233 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1234 && idMatch(r.subId, subId, phoneId)) {
1235 try {
1236 if (DBG_LOC) {
1237 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1238 + configs + " r=" + r);
1239 }
1240 r.callback.onPhysicalChannelConfigurationChanged(configs);
1241 } catch (RemoteException ex) {
1242 mRemoveList.add(r.binder);
1243 }
1244 }
1245 }
1246 }
1247 handleRemoveListLocked();
1248 }
1249 }
1250
xinhe43c50292014-09-18 17:56:48 -07001251 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001252 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001253 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001254 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001255 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001256 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001257 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001258 + " mwi=" + mwi);
1259 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001261 if (validatePhoneId(phoneId)) {
1262 mMessageWaiting[phoneId] = mwi;
1263 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001264 if (r.matchPhoneStateListenerEvent(
1265 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001266 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001267 try {
1268 r.callback.onMessageWaitingIndicatorChanged(mwi);
1269 } catch (RemoteException ex) {
1270 mRemoveList.add(r.binder);
1271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 }
1273 }
1274 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001275 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 }
1277 }
1278
zxuan35a47022018-01-04 11:24:04 -08001279 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1280 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1281 return;
1282 }
1283 if (VDBG) {
1284 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1285 + " state=" + state);
1286 }
1287 synchronized (mRecords) {
1288 if (validatePhoneId(phoneId)) {
1289 mMessageWaiting[phoneId] = state;
1290 for (Record r : mRecords) {
1291 if (r.matchPhoneStateListenerEvent(
1292 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1293 idMatch(r.subId, subId, phoneId)) {
1294 try {
1295 r.callback.onUserMobileDataStateChanged(state);
1296 } catch (RemoteException ex) {
1297 mRemoveList.add(r.binder);
1298 }
1299 }
1300 }
1301 }
1302 handleRemoveListLocked();
1303 }
1304 }
1305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001307 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001308 }
1309
Wink Saville63f03dd2014-10-23 10:44:45 -07001310 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001311 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001312 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001313 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001314 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001315 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001316 + " cfi=" + cfi);
1317 }
yifan.baie620ce72017-12-22 14:59:57 +08001318 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001320 if (validatePhoneId(phoneId)) {
1321 mCallForwarding[phoneId] = cfi;
1322 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001323 if (r.matchPhoneStateListenerEvent(
1324 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001325 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001326 try {
1327 r.callback.onCallForwardingIndicatorChanged(cfi);
1328 } catch (RemoteException ex) {
1329 mRemoveList.add(r.binder);
1330 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 }
1332 }
1333 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001334 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 }
1336 }
1337
1338 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001339 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001340 }
1341
Wink Saville63f03dd2014-10-23 10:44:45 -07001342 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001343 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001344 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001345 }
yifan.baie620ce72017-12-22 14:59:57 +08001346 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001348 if (validatePhoneId(phoneId)) {
1349 mDataActivity[phoneId] = state;
1350 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001351 // Notify by correct subId.
1352 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1353 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001354 try {
1355 r.callback.onDataActivity(state);
1356 } catch (RemoteException ex) {
1357 mRemoveList.add(r.binder);
1358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 }
1360 }
1361 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001362 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 }
1364 }
1365
Jack Yuf05919a2019-01-02 16:51:08 -08001366 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1367 LinkProperties linkProperties,
1368 NetworkCapabilities networkCapabilities, int networkType,
1369 boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001370 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yuf05919a2019-01-02 16:51:08 -08001371 isDataAllowed, apn, apnType, linkProperties,
1372 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001373 }
1374
Jack Yuf05919a2019-01-02 16:51:08 -08001375 public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataAllowed,
1376 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001377 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1378 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001379 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001380 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001381 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001382 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001383 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001384 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001385 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001386 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001387 }
yifan.baie620ce72017-12-22 14:59:57 +08001388 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001390 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001391 // We only call the callback when the change is for default APN type.
1392 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1393 && (mDataConnectionState[phoneId] != state
1394 || mDataConnectionNetworkType[phoneId] != networkType)) {
1395 String str = "onDataConnectionStateChanged(" + state
1396 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001397 log(str);
1398 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001399 for (Record r : mRecords) {
1400 if (r.matchPhoneStateListenerEvent(
1401 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1402 idMatch(r.subId, subId, phoneId)) {
1403 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001404 if (DBG) {
1405 log("Notify data connection state changed on sub: " + subId);
1406 }
Jack Yub1bac542018-03-14 16:23:38 -07001407 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001408 } catch (RemoteException ex) {
1409 mRemoveList.add(r.binder);
1410 }
1411 }
1412 }
1413 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001414
1415 mDataConnectionState[phoneId] = state;
1416 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001417 }
1418 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
chen xu896e3d42018-12-11 18:09:41 -08001419 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1420 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001421 for (Record r : mRecords) {
1422 if (r.matchPhoneStateListenerEvent(
1423 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1424 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001425 r.callback.onPreciseDataConnectionStateChanged(
1426 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001427 } catch (RemoteException ex) {
1428 mRemoveList.add(r.binder);
1429 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001430 }
1431 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001432 }
1433 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 }
Jack Yuf05919a2019-01-02 16:51:08 -08001435 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1436 networkCapabilities, roaming, subId);
1437 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu896e3d42018-12-11 18:09:41 -08001438 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 }
1440
Jack Yuf05919a2019-01-02 16:51:08 -08001441 public void notifyDataConnectionFailed(String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001442 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yuf05919a2019-01-02 16:51:08 -08001443 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001444 }
1445
Jack Yuf05919a2019-01-02 16:51:08 -08001446 public void notifyDataConnectionFailedForSubscriber(int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001447 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001448 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001449 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001450 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001451 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yuf05919a2019-01-02 16:51:08 -08001452 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001455 mPreciseDataConnectionState = new PreciseDataConnectionState(
1456 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001457 ApnSetting.getApnTypesBitmaskFromString(apnType), "", null,
1458 DataFailCause.NONE);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001459 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001460 if (r.matchPhoneStateListenerEvent(
1461 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001462 try {
1463 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1464 } catch (RemoteException ex) {
1465 mRemoveList.add(r.binder);
1466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 }
1468 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001469 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 }
Jack Yuf05919a2019-01-02 16:51:08 -08001471 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001472 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001473 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", null,
1474 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 }
1476
1477 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001478 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001479 }
1480
Wink Saville63f03dd2014-10-23 10:44:45 -07001481 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001482 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001483 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001484 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001485 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001486 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001487 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001488 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001489 + " cellLocation=" + cellLocation);
1490 }
yifan.baie620ce72017-12-22 14:59:57 +08001491 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001493 if (validatePhoneId(phoneId)) {
1494 mCellLocation[phoneId] = cellLocation;
1495 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001496 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001497 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001498 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001499 try {
1500 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001501 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001502 + " r=" + r);
1503 }
1504 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1505 } catch (RemoteException ex) {
1506 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001507 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 }
1510 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001511 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001512 }
1513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514
Wink Savillefd2d0132010-10-28 14:22:26 -07001515 public void notifyOtaspChanged(int otaspMode) {
1516 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1517 return;
1518 }
1519 synchronized (mRecords) {
1520 mOtaspMode = otaspMode;
1521 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001522 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001523 try {
1524 r.callback.onOtaspChanged(otaspMode);
1525 } catch (RemoteException ex) {
1526 mRemoveList.add(r.binder);
1527 }
1528 }
1529 }
1530 handleRemoveListLocked();
1531 }
1532 }
1533
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001534 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001535 int backgroundCallState, int phoneId) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001536 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1537 return;
1538 }
1539 synchronized (mRecords) {
1540 mRingingCallState = ringingCallState;
1541 mForegroundCallState = foregroundCallState;
1542 mBackgroundCallState = backgroundCallState;
1543 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1544 backgroundCallState,
1545 DisconnectCause.NOT_VALID,
1546 PreciseDisconnectCause.NOT_VALID);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001547 boolean notifyCallAttributes = true;
1548 if (mCallQuality == null) {
1549 log("notifyPreciseCallState: mCallQuality is null, skipping call attributes");
1550 notifyCallAttributes = false;
1551 } else {
Jordan Liu65ed9d92019-02-19 14:42:07 -08001552 mCallAttributes = new CallAttributes(mPreciseCallState, mCallNetworkType,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001553 mCallQuality);
1554 }
1555
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001556 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001557 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001558 try {
1559 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1560 } catch (RemoteException ex) {
1561 mRemoveList.add(r.binder);
1562 }
1563 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001564 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1565 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1566 try {
1567 r.callback.onCallAttributesChanged(mCallAttributes);
1568 } catch (RemoteException ex) {
1569 mRemoveList.add(r.binder);
1570 }
1571 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001572 }
1573 handleRemoveListLocked();
1574 }
chen xu970d7792018-12-12 19:59:30 -08001575 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1576 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001577 }
1578
1579 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1580 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1581 return;
1582 }
1583 synchronized (mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001584 mCallDisconnectCause = disconnectCause;
1585 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001586 for (Record r : mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001587 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1588 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001589 try {
chen xu970d7792018-12-12 19:59:30 -08001590 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1591 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001592 } catch (RemoteException ex) {
1593 mRemoveList.add(r.binder);
1594 }
1595 }
1596 }
1597 handleRemoveListLocked();
1598 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001599 }
1600
chen xu0f494682019-01-24 14:14:13 -08001601 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1602 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1603 return;
1604 }
1605 int phoneId = SubscriptionManager.getPhoneId(subId);
1606 synchronized (mRecords) {
1607 if (validatePhoneId(phoneId)) {
1608 mImsReasonInfo.set(phoneId, imsReasonInfo);
1609 for (Record r : mRecords) {
1610 if (r.matchPhoneStateListenerEvent(
1611 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1612 && idMatch(r.subId, subId, phoneId)) {
1613 try {
1614 if (DBG_LOC) {
1615 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1616 + imsReasonInfo + " r=" + r);
1617 }
1618 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1619 } catch (RemoteException ex) {
1620 mRemoveList.add(r.binder);
1621 }
1622 }
1623 }
1624 }
1625 handleRemoveListLocked();
1626 }
1627 }
1628
chen xu896e3d42018-12-11 18:09:41 -08001629 public void notifyPreciseDataConnectionFailed(String apnType,
1630 String apn, @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001631 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1632 return;
1633 }
1634 synchronized (mRecords) {
1635 mPreciseDataConnectionState = new PreciseDataConnectionState(
1636 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001637 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001638 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001639 if (r.matchPhoneStateListenerEvent(
1640 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001641 try {
1642 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1643 } catch (RemoteException ex) {
1644 mRemoveList.add(r.binder);
1645 }
1646 }
1647 }
1648 handleRemoveListLocked();
1649 }
1650 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yuf05919a2019-01-02 16:51:08 -08001651 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001652 }
1653
Brad Ebingerefed9822018-10-26 10:25:57 -07001654 @Override
1655 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1656 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001657 return;
1658 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001659 if (VDBG) {
1660 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1661 }
1662 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001663 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001664 if (validatePhoneId(phoneId)) {
chen xu0f494682019-01-24 14:14:13 -08001665 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001666 for (Record r : mRecords) {
1667 if (r.matchPhoneStateListenerEvent(
1668 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1669 idMatch(r.subId, subId, phoneId)) {
1670 try {
1671 if (DBG_LOC) {
1672 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1673 }
1674 r.callback.onSrvccStateChanged(state);
1675 } catch (RemoteException ex) {
1676 mRemoveList.add(r.binder);
1677 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001678 }
1679 }
1680 }
1681 handleRemoveListLocked();
1682 }
1683 }
1684
Shuo Qian066e8652018-04-25 21:02:35 +00001685 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1686 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1687 return;
1688 }
1689
1690 synchronized (mRecords) {
1691 for (Record r : mRecords) {
1692 if (VDBG) {
1693 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1694 }
1695 if ((r.matchPhoneStateListenerEvent(
1696 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1697 ((r.subId == subId) ||
1698 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1699 try {
1700 r.callback.onOemHookRawEvent(rawData);
1701 } catch (RemoteException ex) {
1702 mRemoveList.add(r.binder);
1703 }
1704 }
1705 }
1706 handleRemoveListLocked();
1707 }
1708 }
1709
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001710 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1711 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1712 return;
1713 }
1714
1715 if (VDBG) {
1716 log("notifyPhoneCapabilityChanged: capability=" + capability);
1717 }
1718
1719 synchronized (mRecords) {
1720 mPhoneCapability = capability;
1721
1722 for (Record r : mRecords) {
1723 if (r.matchPhoneStateListenerEvent(
1724 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1725 try {
1726 r.callback.onPhoneCapabilityChanged(capability);
1727 } catch (RemoteException ex) {
1728 mRemoveList.add(r.binder);
1729 }
1730 }
1731 }
1732 handleRemoveListLocked();
1733 }
1734 }
1735
Malcolm Chenc1873af2018-09-24 20:01:32 -07001736 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1737 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1738 return;
1739 }
1740
1741 if (VDBG) {
1742 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1743 }
1744
1745 synchronized (mRecords) {
1746 mPreferredDataSubId = preferredSubId;
1747
1748 for (Record r : mRecords) {
1749 if (r.matchPhoneStateListenerEvent(
1750 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1751 try {
1752 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1753 } catch (RemoteException ex) {
1754 mRemoveList.add(r.binder);
1755 }
1756 }
1757 }
1758 handleRemoveListLocked();
1759 }
1760 }
1761
chen xu760729c2018-10-11 13:18:26 -07001762 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1763 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1764 return;
1765 }
1766
1767 if (VDBG) {
1768 log("notifyRadioPowerStateChanged: state= " + state);
1769 }
1770
1771 synchronized (mRecords) {
1772 mRadioPowerState = state;
1773
1774 for (Record r : mRecords) {
1775 if (r.matchPhoneStateListenerEvent(
1776 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1777 try {
1778 r.callback.onRadioPowerStateChanged(state);
1779 } catch (RemoteException ex) {
1780 mRemoveList.add(r.binder);
1781 }
1782 }
1783 }
1784 handleRemoveListLocked();
1785 }
1786 }
1787
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 @Override
sqian46c0c302018-12-27 14:12:11 -08001790 public void notifyEmergencyNumberList() {
1791 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1792 return;
1793 }
1794
1795 synchronized (mRecords) {
sqian3e8647c2018-12-14 21:47:49 -08001796 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1797 Context.TELEPHONY_SERVICE);
1798 mEmergencyNumberList = tm.getCurrentEmergencyNumberList();
sqian46c0c302018-12-27 14:12:11 -08001799
1800 for (Record r : mRecords) {
1801 if (r.matchPhoneStateListenerEvent(
1802 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)) {
1803 try {
1804 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1805 if (VDBG) {
1806 log("notifyEmergencyNumberList: emergencyNumberList= "
1807 + mEmergencyNumberList);
1808 }
1809 } catch (RemoteException ex) {
1810 mRemoveList.add(r.binder);
1811 }
1812 }
1813 }
1814 handleRemoveListLocked();
1815 }
sqianbf165bc2018-12-07 17:09:39 -08001816 }
1817
Jordan Liu8218ddd2018-11-28 11:22:39 -08001818 @Override
Jordan Liu65ed9d92019-02-19 14:42:07 -08001819 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId,
1820 int callNetworkType) {
Jordan Liu8218ddd2018-11-28 11:22:39 -08001821 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
1822 return;
1823 }
1824
1825 // merge CallQuality with PreciseCallState and network type
1826 mCallQuality = callQuality;
Jordan Liu65ed9d92019-02-19 14:42:07 -08001827 mCallNetworkType = callNetworkType;
1828 mCallAttributes = new CallAttributes(mPreciseCallState, callNetworkType, callQuality);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001829
1830 synchronized (mRecords) {
1831 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1832 Context.TELEPHONY_SERVICE);
1833
1834 for (Record r : mRecords) {
1835 if (r.matchPhoneStateListenerEvent(
1836 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1837 try {
1838 r.callback.onCallAttributesChanged(mCallAttributes);
1839 } catch (RemoteException ex) {
1840 mRemoveList.add(r.binder);
1841 }
1842 }
1843 }
1844 handleRemoveListLocked();
1845 }
1846 }
1847
sqianbf165bc2018-12-07 17:09:39 -08001848
1849 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001850 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1851 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1852
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001853 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001856 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001858 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301859 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001860 pw.println("Phone Id=" + i);
1861 pw.increaseIndent();
1862 pw.println("mCallState=" + mCallState[i]);
1863 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1864 pw.println("mServiceState=" + mServiceState[i]);
1865 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1866 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001867 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001868 pw.println("mSignalStrength=" + mSignalStrength[i]);
1869 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1870 pw.println("mCallForwarding=" + mCallForwarding[i]);
1871 pw.println("mDataActivity=" + mDataActivity[i]);
1872 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001873 pw.println("mCellLocation=" + mCellLocation[i]);
1874 pw.println("mCellInfo=" + mCellInfo.get(i));
chen xu0f494682019-01-24 14:14:13 -08001875 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i).toString());
Jack Yud19b6ae2017-04-05 14:12:09 -07001876 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301877 }
Jordan Liu65ed9d92019-02-19 14:42:07 -08001878 pw.println("mCallNetworkType=" + mCallNetworkType);
Jack Yud19b6ae2017-04-05 14:12:09 -07001879 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1880 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu970d7792018-12-12 19:59:30 -08001881 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1882 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001883 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1884 pw.println("mRingingCallState=" + mRingingCallState);
1885 pw.println("mForegroundCallState=" + mForegroundCallState);
1886 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001887 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001888 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chenc1873af2018-09-24 20:01:32 -07001889 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
chen xu760729c2018-10-11 13:18:26 -07001890 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian46c0c302018-12-27 14:12:11 -08001891 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001892 pw.println("mCallQuality=" + mCallQuality);
1893 pw.println("mCallAttributes=" + mCallAttributes);
Jack Yud19b6ae2017-04-05 14:12:09 -07001894
1895 pw.decreaseIndent();
1896
1897 pw.println("local logs:");
1898 pw.increaseIndent();
1899 mLocalLog.dump(fd, pw, args);
1900 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001901 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001902 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001903 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001904 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001906 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001907 }
1908 }
1909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 //
1911 // the legacy intent broadcasting
1912 //
1913
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001914 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001915 long ident = Binder.clearCallingIdentity();
1916 try {
1917 mBatteryStats.notePhoneState(state.getState());
1918 } catch (RemoteException re) {
1919 // Can't do much
1920 } finally {
1921 Binder.restoreCallingIdentity(ident);
1922 }
1923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001925 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 Bundle data = new Bundle();
1927 state.fillInNotifierBundle(data);
1928 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001929 // Pass the subscription along with the intent.
1930 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001931 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001932 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001933 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 }
1935
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001936 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1937 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001938 long ident = Binder.clearCallingIdentity();
1939 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001940 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001941 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001942 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001943 } finally {
1944 Binder.restoreCallingIdentity(ident);
1945 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001948 Bundle data = new Bundle();
1949 signalStrength.fillInNotifierBundle(data);
1950 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001951 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001952 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001953 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 }
1955
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001956 /**
1957 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1958 * a valid subId, in which case this function fires a subId-specific intent, or it
1959 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1960 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1961 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001962 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1963 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 long ident = Binder.clearCallingIdentity();
1965 try {
1966 if (state == TelephonyManager.CALL_STATE_IDLE) {
1967 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001968 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1969 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 } else {
1971 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001972 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1973 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 }
1975 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001976 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 } finally {
1978 Binder.restoreCallingIdentity(ident);
1979 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001982 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001983 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001984
1985 // If a valid subId was specified, we should fire off a subId-specific state
1986 // change intent and include the subId.
1987 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1988 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1989 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001990 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001991 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001992 // If the phoneId is invalid, the broadcast is for overall call state.
1993 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1994 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1995 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001996
Brad Ebinger51de96a2017-04-21 17:05:18 -07001997 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1998 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1999
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07002000 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002001 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07002002 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2003
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002004 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2005 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002006 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002007 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002008 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002009 android.Manifest.permission.READ_PHONE_STATE,
2010 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002011 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2012 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2013 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 }
2015
Jack Yuf05919a2019-01-02 16:51:08 -08002016 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2017 String apnType, LinkProperties linkProperties,
2018 NetworkCapabilities networkCapabilities,
2019 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002020 // Note: not reporting to the battery stats service here, because the
2021 // status bar takes care of that after taking into account all of the
2022 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002024 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002025 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07002026 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002027 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002029 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002030 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002031 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002032 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002033 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002034 }
2035 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002036 if (networkCapabilities != null) {
2037 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002038 }
Wink Savillea639b312012-07-10 12:37:54 -07002039 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002040
Wink Savillea639b312012-07-10 12:37:54 -07002041 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2042 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002043 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002044 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 }
2046
Jack Yuf05919a2019-01-02 16:51:08 -08002047 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002049 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002050 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002051 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002053
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002054 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yuf05919a2019-01-02 16:51:08 -08002055 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002056 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2057 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2058 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2059 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002060 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2061 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2062 }
2063
2064 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu896e3d42018-12-11 18:09:41 -08002065 String apnType, String apn, LinkProperties linkProperties,
2066 @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002067 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2068 intent.putExtra(PhoneConstants.STATE_KEY, state);
2069 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002070 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2071 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002072 if (linkProperties != null) {
Jack Yuf05919a2019-01-02 16:51:08 -08002073 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002074 }
chen xu896e3d42018-12-11 18:09:41 -08002075 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002076
2077 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2078 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2079 }
2080
Andrew Flynnceaed682015-06-09 12:36:58 +00002081 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002082 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002083 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002084 }
2085
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002086 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2087 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002088 }
2089
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002090 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002091 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002092 return true;
2093 }
2094 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002095 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002096 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002097 return false;
2098 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002099
Andrew Flynn1f452642015-04-14 22:16:04 -04002100 private boolean checkNotifyPermission() {
2101 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2102 == PackageManager.PERMISSION_GRANTED;
2103 }
2104
Jeff Davidson29da89f2018-02-28 17:50:16 -08002105 private boolean checkListenerPermission(
2106 int events, int subId, String callingPackage, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002107 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2108 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2109 .setCallingPackage(callingPackage)
2110 .setMethod(message + " events: " + events)
2111 .setCallingPid(Binder.getCallingPid())
2112 .setCallingUid(Binder.getCallingUid());
2113
2114 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002115 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002116 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2117 shouldCheckLocationPermissions = true;
2118 }
2119
2120 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2121 // Everything that requires fine location started in Q. So far...
2122 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2123 shouldCheckLocationPermissions = true;
2124 }
2125
2126 if (shouldCheckLocationPermissions) {
2127 LocationAccessPolicy.LocationPermissionResult result =
2128 LocationAccessPolicy.checkLocationPermission(
2129 mContext, locationQueryBuilder.build());
2130 switch (result) {
2131 case DENIED_HARD:
2132 throw new SecurityException("Unable to listen for events " + events + " due to "
2133 + "insufficient location permissions.");
2134 case DENIED_SOFT:
2135 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002136 }
John Wang963db55d2012-03-30 16:04:06 -07002137 }
2138
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002139 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2141 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002142 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002143 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002144 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002145
2146 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2147 mContext.enforceCallingOrSelfPermission(
2148 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002149 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002150
Shuo Qian066e8652018-04-25 21:02:35 +00002151 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2152 mContext.enforceCallingOrSelfPermission(
2153 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2154 }
2155
Brad Ebingerefed9822018-10-26 10:25:57 -07002156 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2157 mContext.enforceCallingOrSelfPermission(
2158 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2159 }
2160
Malcolm Chend4dc4ee2018-12-11 13:56:53 -08002161 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
2162 // It can have either READ_PHONE_STATE or READ_PRIVILEGED_PHONE_STATE.
2163 TelephonyPermissions.checkReadPhoneState(mContext,
2164 SubscriptionManager.INVALID_SUBSCRIPTION_ID, Binder.getCallingPid(),
2165 Binder.getCallingUid(), callingPackage, "listen to "
2166 + "LISTEN_PREFERRED_DATA_SUBID_CHANGE");
2167 }
Brad Ebingerefed9822018-10-26 10:25:57 -07002168
chen xu970d7792018-12-12 19:59:30 -08002169 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2170 mContext.enforceCallingOrSelfPermission(
2171 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2172 }
2173
Jordan Liu8218ddd2018-11-28 11:22:39 -08002174 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2175 mContext.enforceCallingOrSelfPermission(
2176 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2177 }
2178
chen xu52797b62019-01-18 13:16:31 -08002179 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2180 mContext.enforceCallingOrSelfPermission(
2181 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2182 }
2183
2184 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2185 mContext.enforceCallingOrSelfPermission(
2186 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2187 }
2188
chen xu0f494682019-01-24 14:14:13 -08002189 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2190 mContext.enforceCallingOrSelfPermission(
2191 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2192 }
2193
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002194 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002195 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002196
2197 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002198 int size = mRemoveList.size();
2199 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2200 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002201 for (IBinder b: mRemoveList) {
2202 remove(b);
2203 }
2204 mRemoveList.clear();
2205 }
2206 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002207
2208 private boolean validateEventsAndUserLocked(Record r, int events) {
2209 int foregroundUser;
2210 long callingIdentity = Binder.clearCallingIdentity();
2211 boolean valid = false;
2212 try {
2213 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002214 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2215 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002216 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002217 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002218 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002219 + " r.events=" + r.events + " events=" + events);
2220 }
2221 } finally {
2222 Binder.restoreCallingIdentity(callingIdentity);
2223 }
2224 return valid;
2225 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002226
2227 private boolean validatePhoneId(int phoneId) {
2228 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002229 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002230 return valid;
2231 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002232
2233 private static void log(String s) {
2234 Rlog.d(TAG, s);
2235 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002236
xinhe8b79fb62014-11-05 14:55:03 -08002237 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002238
2239 if(subId < 0) {
2240 // Invalid case, we need compare phoneId with default one.
2241 return (mDefaultPhoneId == phoneId);
2242 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002243 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002244 return (subId == mDefaultSubId);
2245 } else {
2246 return (rSubId == subId);
2247 }
2248 }
2249
Hall Liuee313732018-11-27 14:36:51 -08002250 private boolean checkFineLocationAccess(Record r, int minSdk) {
2251 LocationAccessPolicy.LocationPermissionQuery query =
2252 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2253 .setCallingPackage(r.callingPackage)
2254 .setCallingPid(r.callerPid)
2255 .setCallingUid(r.callerUid)
2256 .setMethod("TelephonyRegistry push")
2257 .setMinSdkVersionForFine(minSdk)
2258 .build();
2259
2260 return Binder.withCleanCallingIdentity(() -> {
2261 LocationAccessPolicy.LocationPermissionResult locationResult =
2262 LocationAccessPolicy.checkLocationPermission(mContext, query);
2263 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2264 });
2265 }
2266
2267 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2268 LocationAccessPolicy.LocationPermissionQuery query =
2269 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2270 .setCallingPackage(r.callingPackage)
2271 .setCallingPid(r.callerPid)
2272 .setCallingUid(r.callerUid)
2273 .setMethod("TelephonyRegistry push")
2274 .setMinSdkVersionForCoarse(minSdk)
2275 .build();
2276
2277 return Binder.withCleanCallingIdentity(() -> {
2278 LocationAccessPolicy.LocationPermissionResult locationResult =
2279 LocationAccessPolicy.checkLocationPermission(mContext, query);
2280 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2281 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002282 }
2283
xinhee9f16402014-09-25 16:39:28 -07002284 private void checkPossibleMissNotify(Record r, int phoneId) {
2285 int events = r.events;
2286
2287 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2288 try {
2289 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2290 mServiceState[phoneId]);
2291 r.callback.onServiceStateChanged(
2292 new ServiceState(mServiceState[phoneId]));
2293 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002294 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002295 }
2296 }
2297
2298 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2299 try {
2300 SignalStrength signalStrength = mSignalStrength[phoneId];
2301 if (DBG) {
2302 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2303 }
2304 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2305 } catch (RemoteException ex) {
2306 mRemoveList.add(r.binder);
2307 }
2308 }
2309
2310 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2311 try {
2312 int gsmSignalStrength = mSignalStrength[phoneId]
2313 .getGsmSignalStrength();
2314 if (DBG) {
2315 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2316 gsmSignalStrength);
2317 }
2318 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2319 : gsmSignalStrength));
2320 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002321 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002322 }
2323 }
2324
2325 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2326 try {
2327 if (DBG_LOC) {
2328 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2329 + mCellInfo.get(phoneId));
2330 }
Hall Liuee313732018-11-27 14:36:51 -08002331 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002332 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2333 }
xinhee9f16402014-09-25 16:39:28 -07002334 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002335 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002336 }
2337 }
2338
zxuan35a47022018-01-04 11:24:04 -08002339 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2340 try {
2341 if (VDBG) {
2342 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2343 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2344 }
2345 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2346 } catch (RemoteException ex) {
2347 mRemoveList.add(r.binder);
2348 }
2349 }
2350
xinhee9f16402014-09-25 16:39:28 -07002351 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2352 try {
2353 if (VDBG) {
2354 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2355 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2356 }
2357 r.callback.onMessageWaitingIndicatorChanged(
2358 mMessageWaiting[phoneId]);
2359 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002360 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002361 }
2362 }
2363
2364 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2365 try {
2366 if (VDBG) {
2367 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2368 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2369 }
2370 r.callback.onCallForwardingIndicatorChanged(
2371 mCallForwarding[phoneId]);
2372 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002373 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002374 }
2375 }
2376
2377 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2378 try {
2379 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2380 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002381 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002382 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2383 }
xinhee9f16402014-09-25 16:39:28 -07002384 } catch (RemoteException ex) {
2385 mRemoveList.add(r.binder);
2386 }
2387 }
2388
2389 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2390 try {
2391 if (DBG) {
2392 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2393 + "=" + mDataConnectionState[phoneId]
2394 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2395 + ")");
2396 }
2397 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2398 mDataConnectionNetworkType[phoneId]);
2399 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002400 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002401 }
2402 }
2403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404}