blob: 566d837a2ba31006b34d3c51158b63ff6859fe88 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
chen xu896e3d42018-12-11 18:09:41 -080037import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020038import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080039import android.telephony.LocationAccessPolicy;
Malcolm Chen5ee5c142018-08-08 20:27:45 -070040import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070041import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080042import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020043import android.telephony.PreciseCallState;
44import android.telephony.PreciseDataConnectionState;
45import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070046import android.telephony.Rlog;
47import android.telephony.ServiceState;
48import android.telephony.SignalStrength;
49import android.telephony.SubscriptionManager;
50import android.telephony.TelephonyManager;
chen xu896e3d42018-12-11 18:09:41 -080051import android.telephony.data.ApnSetting;
sqianbf165bc2018-12-07 17:09:39 -080052import android.telephony.emergency.EmergencyNumber;
Jack Yud19b6ae2017-04-05 14:12:09 -070053import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070054import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
Malcolm Chen800a7d62018-08-27 20:38:29 -070056import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080058import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070060import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080061import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070062import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080064import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060065import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070066import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import com.android.server.am.BatteryStatsService;
68
Jack Yud19b6ae2017-04-05 14:12:09 -070069import java.io.FileDescriptor;
70import java.io.PrintWriter;
71import java.util.ArrayList;
sqian46c0c302018-12-27 14:12:11 -080072import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070073import java.util.List;
sqian46c0c302018-12-27 14:12:11 -080074import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080075import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077/**
Wink Savillee9b06d72009-05-18 21:47:50 -070078 * Since phone process can be restarted, this class provides a centralized place
79 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070080 *
81 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
82 * and 15973975 by saving the phoneId of the registrant and then using the
83 * phoneId when deciding to to make a callback. This is necessary because
84 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070085 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070086 * the dummy value conversion we properly do the callbacks.
87 *
88 * Eventually we may want to remove the notion of dummy value but for now this
89 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 */
Malcolm Chen800a7d62018-08-27 20:38:29 -070091@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
92public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070094 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070095 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070096 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097
98 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080099 Context context;
100
Svet Ganov16a16892015-04-16 10:32:04 -0700101 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -0700102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700104
Malcolm Chenabbfac22018-02-12 19:15:59 -0800105 TelephonyRegistryDeathRecipient deathRecipient;
106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800108 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen27829e22018-09-04 22:12:31 -0700109 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700110
Hall Liu5fb337f2017-11-22 17:38:15 -0800111 int callerUid;
112 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700115
Wink Savilled09c4ca2014-11-22 10:08:16 -0800116 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700117
Wink Savilled09c4ca2014-11-22 10:08:16 -0800118 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800119
120 boolean matchPhoneStateListenerEvent(int events) {
121 return (callback != null) && ((events & this.events) != 0);
122 }
123
Wink Savilled09c4ca2014-11-22 10:08:16 -0800124 boolean matchOnSubscriptionsChangedListener() {
125 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800126 }
Wink Savillee380b982014-07-26 18:24:22 -0700127
Malcolm Chen27829e22018-09-04 22:12:31 -0700128 boolean matchOnOpportunisticSubscriptionsChangedListener() {
129 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
130 }
131
Tyler Gunnf955e562018-04-26 14:43:31 -0700132 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800133 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700134 return TelephonyPermissions.checkReadCallLog(
135 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800136 } catch (SecurityException e) {
137 return false;
138 }
139 }
140
Wink Savillea12a7b32012-09-20 10:09:45 -0700141 @Override
142 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700143 return "{callingPackage=" + callingPackage + " binder=" + binder
144 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800145 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen27829e22018-09-04 22:12:31 -0700146 + onSubscriptionsChangedListenerCallback
147 + " onOpportunisticSubscriptionsChangedListenererCallback="
148 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800149 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800150 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 }
153
154 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Joe Onorato163d8d92010-10-21 13:21:20 -0400156 // access should be inside synchronized (mRecords) for these two fields
157 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
158 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 private final IBatteryStats mBatteryStats;
161
Svet Ganov16a16892015-04-16 10:32:04 -0700162 private final AppOpsManager mAppOps;
163
Malcolm Chen27829e22018-09-04 22:12:31 -0700164 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
165
166 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700175
fionaxu12312f62016-11-14 13:32:14 -0800176 private int[] mVoiceActivationState;
177
178 private int[] mDataActivationState;
179
zxuan35a47022018-01-04 11:24:04 -0800180 private boolean[] mUserMobileDataState;
181
Wink Savillefb40dd42014-06-12 17:02:31 -0700182 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700183
Wink Savillefb40dd42014-06-12 17:02:31 -0700184 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
Jack Yub1bac542018-03-14 16:23:38 -0700190 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700192
Wink Savillefb40dd42014-06-12 17:02:31 -0700193 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700196
Nathan Harold016e9c62016-12-14 11:24:48 -0800197 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private ArrayList<List<CellInfo>> mCellInfo = null;
200
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800201 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
202
sqian46c0c302018-12-27 14:12:11 -0800203 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
204
Brad Ebingerefed9822018-10-26 10:25:57 -0700205 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700206
Wink Savilled09c4ca2014-11-22 10:08:16 -0800207 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700208
Wink Savilled09c4ca2014-11-22 10:08:16 -0800209 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700210
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200211 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
212
213 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
214
215 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
216
217 private PreciseCallState mPreciseCallState = new PreciseCallState();
218
chen xu970d7792018-12-12 19:59:30 -0800219 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
220
221 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
222
Andrew Flynn1f452642015-04-14 22:16:04 -0400223 private boolean mCarrierNetworkChangeState = false;
224
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700225 private PhoneCapability mPhoneCapability = null;
226
chen xu760729c2018-10-11 13:18:26 -0700227 @TelephonyManager.RadioPowerState
228 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
229
Malcolm Chenc1873af2018-09-24 20:01:32 -0700230 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
231
Jack Yud19b6ae2017-04-05 14:12:09 -0700232 private final LocalLog mLocalLog = new LocalLog(100);
233
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200234 private PreciseDataConnectionState mPreciseDataConnectionState =
235 new PreciseDataConnectionState();
236
Hall Liu70bbc162018-03-02 17:44:46 -0800237 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
238 PhoneStateListener.LISTEN_CELL_LOCATION
239 | PhoneStateListener.LISTEN_CELL_INFO;
240
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700241 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian46c0c302018-12-27 14:12:11 -0800242 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
243 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
244 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700245
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200246 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
247 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
248 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
249
Wink Savillea12a7b32012-09-20 10:09:45 -0700250 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700251 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700252
253 private final Handler mHandler = new Handler() {
254 @Override
255 public void handleMessage(Message msg) {
256 switch (msg.what) {
257 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700258 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700259 int numPhones = TelephonyManager.getDefault().getPhoneCount();
260 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700261 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700262 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700263 }
264 break;
265 }
xinhee9f16402014-09-25 16:39:28 -0700266 case MSG_UPDATE_DEFAULT_SUB: {
267 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700268 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700269 if (VDBG) {
270 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
271 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
272 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
273 }
274
275 //Due to possible risk condition,(notify call back using the new
276 //defaultSubId comes before new defaultSubId update) we need to recall all
277 //possible missed notify callback
278 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700279 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800280 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700281 checkPossibleMissNotify(r, newDefaultPhoneId);
282 }
283 }
284 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700285 }
286 mDefaultSubId = newDefaultSubId;
287 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700288 }
289 }
290 }
291 };
292
Malcolm Chenabbfac22018-02-12 19:15:59 -0800293 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
294
295 private final IBinder binder;
296
297 TelephonyRegistryDeathRecipient(IBinder binder) {
298 this.binder = binder;
299 }
300
301 @Override
302 public void binderDied() {
303 if (DBG) log("binderDied " + binder);
304 remove(binder);
305 }
306 }
307
Wink Savillea12a7b32012-09-20 10:09:45 -0700308 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
309 @Override
310 public void onReceive(Context context, Intent intent) {
311 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700312 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700313 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700314 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700315 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700316 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700317 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700318 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800319 PhoneConstants.SUBSCRIPTION_KEY,
320 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700321 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
322 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700323 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700324 log("onReceive:current mDefaultSubId=" + mDefaultSubId
325 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
326 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700327 }
xinhee9f16402014-09-25 16:39:28 -0700328
Junda Liu985f52c2015-02-23 16:06:51 -0800329 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700330 || (newDefaultPhoneId != mDefaultPhoneId))) {
331 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
332 newDefaultPhoneId, 0, newDefaultSubIdObj));
333 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700334 }
335 }
336 };
337
Wink Savillee9b06d72009-05-18 21:47:50 -0700338 // we keep a copy of all of the state so we can send it out when folks
339 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700341 // In these calls we call with the lock held. This is safe becasuse remote
342 // calls go through a oneway interface and local calls going through a
343 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
Malcolm Chen800a7d62018-08-27 20:38:29 -0700345 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
346 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700347 CellLocation location = CellLocation.getEmpty();
348
Wink Savillefb40dd42014-06-12 17:02:31 -0700349 mContext = context;
350 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700351
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700353 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 mNumPhones = numPhones;
355 mCallState = new int[numPhones];
356 mDataActivity = new int[numPhones];
357 mDataConnectionState = new int[numPhones];
358 mDataConnectionNetworkType = new int[numPhones];
359 mCallIncomingNumber = new String[numPhones];
360 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800361 mVoiceActivationState = new int[numPhones];
362 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800363 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700364 mSignalStrength = new SignalStrength[numPhones];
365 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 mCallForwarding = new boolean[numPhones];
367 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700368 mCellInfo = new ArrayList<List<CellInfo>>();
Brad Ebingerefed9822018-10-26 10:25:57 -0700369 mSrvccState = new int[numPhones];
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800370 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
sqian46c0c302018-12-27 14:12:11 -0800371 mEmergencyNumberList = new HashMap<>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700372 for (int i = 0; i < numPhones; i++) {
373 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
374 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
375 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800376 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
377 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700378 mCallIncomingNumber[i] = "";
379 mServiceState[i] = new ServiceState();
380 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800381 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700382 mMessageWaiting[i] = false;
383 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700384 mCellLocation[i] = new Bundle();
385 mCellInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700386 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700387 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700388 }
389
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700390 // Note that location can be null for non-phone builds like
391 // like the generic one.
392 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700393 for (int i = 0; i < numPhones; i++) {
394 location.fillInNotifierBundle(mCellLocation[i]);
395 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700396 }
Svet Ganov16a16892015-04-16 10:32:04 -0700397
398 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 }
400
Svetoslav Ganova0027152013-06-25 14:59:53 -0700401 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700402 // Watch for interesting updates
403 final IntentFilter filter = new IntentFilter();
404 filter.addAction(Intent.ACTION_USER_SWITCHED);
405 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700406 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700407 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700408 mContext.registerReceiver(mBroadcastReceiver, filter);
409 }
410
411 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700412 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800413 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700414 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800416 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700417 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
418 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 + " callback.asBinder=" + callback.asBinder());
420 }
421
Wink Savilled09c4ca2014-11-22 10:08:16 -0800422 synchronized (mRecords) {
423 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800424 IBinder b = callback.asBinder();
425 Record r = add(b);
426
427 if (r == null) {
428 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800429 }
430
Jeff Davidson29da89f2018-02-28 17:50:16 -0800431 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800432 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700433 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800434 r.callerUid = Binder.getCallingUid();
435 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800436 r.events = 0;
437 if (DBG) {
438 log("listen oscl: Register r=" + r);
439 }
440 // Always notify when registration occurs if there has been a notification.
Malcolm Chen27829e22018-09-04 22:12:31 -0700441 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800442 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800443 if (VDBG) log("listen oscl: send to r=" + r);
444 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
445 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800446 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800447 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800448 remove(r.binder);
449 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800450 } else {
Malcolm Chen27829e22018-09-04 22:12:31 -0700451 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800452 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800453 }
454 }
455
456 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800457 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800458 IOnSubscriptionsChangedListener callback) {
459 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800460 remove(callback.asBinder());
461 }
462
Malcolm Chen27829e22018-09-04 22:12:31 -0700463
464 @Override
465 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
466 IOnSubscriptionsChangedListener callback) {
467 int callerUserId = UserHandle.getCallingUserId();
468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
469 if (VDBG) {
470 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
471 + " callerUserId=" + callerUserId + " callback=" + callback
472 + " callback.asBinder=" + callback.asBinder());
473 }
474
475 synchronized (mRecords) {
476 // register
477 IBinder b = callback.asBinder();
478 Record r = add(b);
479
480 if (r == null) {
481 return;
482 }
483
484 r.context = mContext;
485 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
486 r.callingPackage = callingPackage;
487 r.callerUid = Binder.getCallingUid();
488 r.callerPid = Binder.getCallingPid();
489 r.events = 0;
490 if (DBG) {
491 log("listen ooscl: Register r=" + r);
492 }
493 // Always notify when registration occurs if there has been a notification.
494 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
495 try {
496 if (VDBG) log("listen ooscl: send to r=" + r);
497 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
498 if (VDBG) log("listen ooscl: sent to r=" + r);
499 } catch (RemoteException e) {
500 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
501 remove(r.binder);
502 }
503 } else {
504 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
505 }
506 }
507 }
508
Wink Savillea374c3d2014-11-11 11:48:04 -0800509 @Override
510 public void notifySubscriptionInfoChanged() {
511 if (VDBG) log("notifySubscriptionInfoChanged:");
512 synchronized (mRecords) {
Malcolm Chen27829e22018-09-04 22:12:31 -0700513 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800514 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
515 + mRecords.size());
516 }
Malcolm Chen27829e22018-09-04 22:12:31 -0700517 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800518 mRemoveList.clear();
519 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800520 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800521 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800522 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
523 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
524 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800525 } catch (RemoteException ex) {
526 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
527 mRemoveList.add(r.binder);
528 }
529 }
530 }
531 handleRemoveListLocked();
532 }
533 }
534
535 @Override
Malcolm Chen27829e22018-09-04 22:12:31 -0700536 public void notifyOpportunisticSubscriptionInfoChanged() {
537 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
538 synchronized (mRecords) {
539 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
540 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
541 + mRecords.size());
542 }
543 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
544 mRemoveList.clear();
545 for (Record r : mRecords) {
546 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
547 try {
548 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
549 r.onOpportunisticSubscriptionsChangedListenerCallback
550 .onSubscriptionsChanged();
551 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
552 } catch (RemoteException ex) {
553 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
554 mRemoveList.add(r.binder);
555 }
556 }
557 }
558 handleRemoveListLocked();
559 }
560 }
561
562 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
564 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800565 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
566 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700567 }
568
569 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700570 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700571 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700572 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700573 }
574
Svet Ganov16a16892015-04-16 10:32:04 -0700575 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700576 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700577 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700579 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700580 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700581 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
582 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700583 }
xinhe75c2c152014-10-16 11:49:45 -0700584
585 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800586 // Checks permission and throws SecurityException for disallowed operations. For pre-M
587 // apps whose runtime permission has been revoked, we return immediately to skip sending
588 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800589 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800590 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700591 }
592
yifan.baie620ce72017-12-22 14:59:57 +0800593 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 synchronized (mRecords) {
595 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800596 IBinder b = callback.asBinder();
597 Record r = add(b);
598
599 if (r == null) {
600 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 }
xinhe43c50292014-09-18 17:56:48 -0700602
Jeff Davidson29da89f2018-02-28 17:50:16 -0800603 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700604 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700605 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800606 r.callerUid = Binder.getCallingUid();
607 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700608 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
609 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800611 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700612 } else {//APP specify subID
613 r.subId = subId;
614 }
yifan.baie620ce72017-12-22 14:59:57 +0800615 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700617 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700618 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700619 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700620 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400622 try {
Wink Savillee380b982014-07-26 18:24:22 -0700623 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700624 r.callback.onServiceStateChanged(
625 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400626 } catch (RemoteException ex) {
627 remove(r.binder);
628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 }
630 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
631 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700632 int gsmSignalStrength = mSignalStrength[phoneId]
633 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700634 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
635 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 } catch (RemoteException ex) {
637 remove(r.binder);
638 }
639 }
640 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
641 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700642 r.callback.onMessageWaitingIndicatorChanged(
643 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 } catch (RemoteException ex) {
645 remove(r.binder);
646 }
647 }
648 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
649 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700650 r.callback.onCallForwardingIndicatorChanged(
651 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 } catch (RemoteException ex) {
653 remove(r.binder);
654 }
655 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700656 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400657 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700658 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700659 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800660 if (checkLocationAccess(r)) {
661 r.callback.onCellLocationChanged(
662 new Bundle(mCellLocation[phoneId]));
663 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400664 } catch (RemoteException ex) {
665 remove(r.binder);
666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 }
668 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
669 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700670 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700671 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 } catch (RemoteException ex) {
673 remove(r.binder);
674 }
675 }
676 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
677 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700678 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
679 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 } catch (RemoteException ex) {
681 remove(r.binder);
682 }
683 }
684 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
685 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700686 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 } catch (RemoteException ex) {
688 remove(r.binder);
689 }
690 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700691 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
692 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700693 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700694 } catch (RemoteException ex) {
695 remove(r.binder);
696 }
697 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700698 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
699 try {
700 r.callback.onOtaspChanged(mOtaspMode);
701 } catch (RemoteException ex) {
702 remove(r.binder);
703 }
704 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700705 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700706 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700707 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700708 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800709 if (checkLocationAccess(r)) {
710 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
711 }
John Wang963db55d2012-03-30 16:04:06 -0700712 } catch (RemoteException ex) {
713 remove(r.binder);
714 }
715 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200716 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
717 try {
718 r.callback.onPreciseCallStateChanged(mPreciseCallState);
719 } catch (RemoteException ex) {
720 remove(r.binder);
721 }
722 }
chen xu970d7792018-12-12 19:59:30 -0800723 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
724 try {
725 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
726 mCallPreciseDisconnectCause);
727 } catch (RemoteException ex) {
728 remove(r.binder);
729 }
730 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200731 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
732 try {
733 r.callback.onPreciseDataConnectionStateChanged(
734 mPreciseDataConnectionState);
735 } catch (RemoteException ex) {
736 remove(r.binder);
737 }
738 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400739 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
740 try {
741 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
742 } catch (RemoteException ex) {
743 remove(r.binder);
744 }
745 }
fionaxu12312f62016-11-14 13:32:14 -0800746 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
747 try {
748 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
749 } catch (RemoteException ex) {
750 remove(r.binder);
751 }
752 }
753 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
754 try {
755 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
756 } catch (RemoteException ex) {
757 remove(r.binder);
758 }
759 }
zxuan35a47022018-01-04 11:24:04 -0800760 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
761 try {
762 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
763 } catch (RemoteException ex) {
764 remove(r.binder);
765 }
766 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800767 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
768 try {
769 r.callback.onPhysicalChannelConfigurationChanged(
770 mPhysicalChannelConfigs.get(phoneId));
771 } catch (RemoteException ex) {
772 remove(r.binder);
773 }
774 }
sqian46c0c302018-12-27 14:12:11 -0800775 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
776 try {
777 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
778 } catch (RemoteException ex) {
779 remove(r.binder);
780 }
781 }
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700782 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
783 try {
784 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
785 } catch (RemoteException ex) {
786 remove(r.binder);
787 }
788 }
Malcolm Chenc1873af2018-09-24 20:01:32 -0700789 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
790 try {
791 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
792 } catch (RemoteException ex) {
793 remove(r.binder);
794 }
795 }
chen xu760729c2018-10-11 13:18:26 -0700796 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
797 try {
798 r.callback.onRadioPowerStateChanged(mRadioPowerState);
799 } catch (RemoteException ex) {
800 remove(r.binder);
801 }
802 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700803 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
804 try {
805 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
806 } catch (RemoteException ex) {
807 remove(r.binder);
808 }
809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 }
811 }
812 } else {
xinhe75c2c152014-10-16 11:49:45 -0700813 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 remove(callback.asBinder());
815 }
816 }
817
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700818 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700819 // Only reveal the incoming number if the record has read call log permission.
820 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700821 }
822
Malcolm Chenabbfac22018-02-12 19:15:59 -0800823 private Record add(IBinder binder) {
824 Record r;
825
826 synchronized (mRecords) {
827 final int N = mRecords.size();
828 for (int i = 0; i < N; i++) {
829 r = mRecords.get(i);
830 if (binder == r.binder) {
831 // Already existed.
832 return r;
833 }
834 }
835 r = new Record();
836 r.binder = binder;
837 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
838
839 try {
840 binder.linkToDeath(r.deathRecipient, 0);
841 } catch (RemoteException e) {
842 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
843 // Binder already died. Return null.
844 return null;
845 }
846
847 mRecords.add(r);
848 if (DBG) log("add new record");
849 }
850
851 return r;
852 }
853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 private void remove(IBinder binder) {
855 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700856 final int recordCount = mRecords.size();
857 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800858 Record r = mRecords.get(i);
859 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800860 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800861 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
862 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800863 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800864
865 if (r.deathRecipient != null) {
866 try {
867 binder.unlinkToDeath(r.deathRecipient, 0);
868 } catch (NoSuchElementException e) {
869 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
870 + r + " e=" + e);
871 }
872 }
873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 mRecords.remove(i);
875 return;
876 }
877 }
878 }
879 }
880
Tyler Gunnf955e562018-04-26 14:43:31 -0700881 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700882 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700883 return;
884 }
xinhe43c50292014-09-18 17:56:48 -0700885
886 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700887 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700888 }
889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700891 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800892 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800893 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700895 // Ensure the listener has read call log permission; if they do not return
896 // an empty phone number.
897 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
898 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400900 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 }
902 }
903 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400904 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700906
907 // Called only by Telecomm to communicate call state across different phone accounts. So
908 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700909 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700910 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700911 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 }
913
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700914 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
915 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700916 if (!checkNotifyPermission("notifyCallState()")) {
917 return;
918 }
Wink Savillee380b982014-07-26 18:24:22 -0700919 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700920 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700921 + " state=" + state + " incomingNumber=" + incomingNumber);
922 }
923 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700924 if (validatePhoneId(phoneId)) {
925 mCallState[phoneId] = state;
926 mCallIncomingNumber[phoneId] = incomingNumber;
927 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800928 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700929 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800930 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700931 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700932 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
933 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700934 } catch (RemoteException ex) {
935 mRemoveList.add(r.binder);
936 }
937 }
938 }
939 }
940 handleRemoveListLocked();
941 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700942 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700943 }
944
Wink Saville63f03dd2014-10-23 10:44:45 -0700945 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700946 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700947 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700948 }
xinhe43c50292014-09-18 17:56:48 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700951 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
952 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700953 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700954 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700955 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700956 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700957 if (validatePhoneId(phoneId)) {
958 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700959
Wink Savillefb40dd42014-06-12 17:02:31 -0700960 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700961 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700962 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700963 + " phoneId=" + phoneId + " state=" + state);
964 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800965 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800966 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700967 try {
Wink Savillee380b982014-07-26 18:24:22 -0700968 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700969 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700970 + " subId=" + subId + " phoneId=" + phoneId
971 + " state=" + state);
972 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700973 r.callback.onServiceStateChanged(new ServiceState(state));
974 } catch (RemoteException ex) {
975 mRemoveList.add(r.binder);
976 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700979 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700980 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400982 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700984 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 }
986
fionaxu12312f62016-11-14 13:32:14 -0800987 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
988 int activationType, int activationState) {
989 if (!checkNotifyPermission("notifySimActivationState()")){
990 return;
991 }
992 if (VDBG) {
993 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
994 + "type=" + activationType + " state=" + activationState);
995 }
996 synchronized (mRecords) {
997 if (validatePhoneId(phoneId)) {
998 switch (activationType) {
999 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
1000 mVoiceActivationState[phoneId] = activationState;
1001 break;
1002 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
1003 mDataActivationState[phoneId] = activationState;
1004 break;
1005 default:
1006 return;
1007 }
1008 for (Record r : mRecords) {
1009 if (VDBG) {
1010 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1011 + " phoneId=" + phoneId + "type=" + activationType
1012 + " state=" + activationState);
1013 }
1014 try {
1015 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1016 r.matchPhoneStateListenerEvent(
1017 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1018 idMatch(r.subId, subId, phoneId)) {
1019 if (DBG) {
1020 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1021 + " subId=" + subId + " phoneId=" + phoneId
1022 + " state=" + activationState);
1023 }
1024 r.callback.onVoiceActivationStateChanged(activationState);
1025 }
1026 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1027 r.matchPhoneStateListenerEvent(
1028 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1029 idMatch(r.subId, subId, phoneId)) {
1030 if (DBG) {
1031 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1032 + " subId=" + subId + " phoneId=" + phoneId
1033 + " state=" + activationState);
1034 }
1035 r.callback.onDataActivationStateChanged(activationState);
1036 }
1037 } catch (RemoteException ex) {
1038 mRemoveList.add(r.binder);
1039 }
1040 }
1041 } else {
1042 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1043 }
1044 handleRemoveListLocked();
1045 }
1046 }
1047
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001048 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1049 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001050 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001051 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001052 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001053 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001054 log("notifySignalStrengthForPhoneId: subId=" + subId
1055 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001056 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001059 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001060 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001061 mSignalStrength[phoneId] = signalStrength;
1062 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001063 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001064 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001065 + " phoneId=" + phoneId + " ss=" + signalStrength);
1066 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001067 if (r.matchPhoneStateListenerEvent(
1068 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001069 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001070 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001071 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001072 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001073 + " subId=" + subId + " phoneId=" + phoneId
1074 + " ss=" + signalStrength);
1075 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001076 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1077 } catch (RemoteException ex) {
1078 mRemoveList.add(r.binder);
1079 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001080 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001081 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001082 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001083 try {
1084 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001085 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001086 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001087 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001088 + " subId=" + subId + " phoneId=" + phoneId
1089 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1090 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001091 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001092 } catch (RemoteException ex) {
1093 mRemoveList.add(r.binder);
1094 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001097 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001098 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001100 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001102 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 }
1104
Andrew Flynn1f452642015-04-14 22:16:04 -04001105 @Override
1106 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001107 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1108
Andrew Flynn1f452642015-04-14 22:16:04 -04001109 if (VDBG) {
1110 log("notifyCarrierNetworkChange: active=" + active);
1111 }
1112
1113 synchronized (mRecords) {
1114 mCarrierNetworkChangeState = active;
1115 for (Record r : mRecords) {
1116 if (r.matchPhoneStateListenerEvent(
1117 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1118 try {
1119 r.callback.onCarrierNetworkChange(active);
1120 } catch (RemoteException ex) {
1121 mRemoveList.add(r.binder);
1122 }
1123 }
1124 }
1125 handleRemoveListLocked();
1126 }
1127 }
1128
Wink Savilleb208a242012-07-25 14:08:09 -07001129 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001130 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001131 }
1132
Wink Saville63f03dd2014-10-23 10:44:45 -07001133 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001134 if (!checkNotifyPermission("notifyCellInfo()")) {
1135 return;
1136 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001137 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001138 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001139 + " cellInfo=" + cellInfo);
1140 }
yifan.baie620ce72017-12-22 14:59:57 +08001141 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001142 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001143 if (validatePhoneId(phoneId)) {
1144 mCellInfo.set(phoneId, cellInfo);
1145 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001146 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001147 idMatch(r.subId, subId, phoneId) &&
1148 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001149 try {
1150 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001151 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001152 }
1153 r.callback.onCellInfoChanged(cellInfo);
1154 } catch (RemoteException ex) {
1155 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001156 }
John Wang963db55d2012-03-30 16:04:06 -07001157 }
1158 }
1159 }
1160 handleRemoveListLocked();
1161 }
1162 }
1163
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001164 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1165 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1166 configs);
1167 }
1168
1169 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1170 List<PhysicalChannelConfig> configs) {
1171 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1172 return;
1173 }
1174
1175 if (VDBG) {
1176 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1177 }
1178
1179 synchronized (mRecords) {
1180 int phoneId = SubscriptionManager.getPhoneId(subId);
1181 if (validatePhoneId(phoneId)) {
1182 mPhysicalChannelConfigs.set(phoneId, configs);
1183 for (Record r : mRecords) {
1184 if (r.matchPhoneStateListenerEvent(
1185 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1186 && idMatch(r.subId, subId, phoneId)) {
1187 try {
1188 if (DBG_LOC) {
1189 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1190 + configs + " r=" + r);
1191 }
1192 r.callback.onPhysicalChannelConfigurationChanged(configs);
1193 } catch (RemoteException ex) {
1194 mRemoveList.add(r.binder);
1195 }
1196 }
1197 }
1198 }
1199 handleRemoveListLocked();
1200 }
1201 }
1202
xinhe43c50292014-09-18 17:56:48 -07001203 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001204 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001205 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001206 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001207 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001208 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001209 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001210 + " mwi=" + mwi);
1211 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001213 if (validatePhoneId(phoneId)) {
1214 mMessageWaiting[phoneId] = mwi;
1215 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001216 if (r.matchPhoneStateListenerEvent(
1217 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001218 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001219 try {
1220 r.callback.onMessageWaitingIndicatorChanged(mwi);
1221 } catch (RemoteException ex) {
1222 mRemoveList.add(r.binder);
1223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 }
1225 }
1226 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001227 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 }
1229 }
1230
zxuan35a47022018-01-04 11:24:04 -08001231 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1232 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1233 return;
1234 }
1235 if (VDBG) {
1236 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1237 + " state=" + state);
1238 }
1239 synchronized (mRecords) {
1240 if (validatePhoneId(phoneId)) {
1241 mMessageWaiting[phoneId] = state;
1242 for (Record r : mRecords) {
1243 if (r.matchPhoneStateListenerEvent(
1244 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1245 idMatch(r.subId, subId, phoneId)) {
1246 try {
1247 r.callback.onUserMobileDataStateChanged(state);
1248 } catch (RemoteException ex) {
1249 mRemoveList.add(r.binder);
1250 }
1251 }
1252 }
1253 }
1254 handleRemoveListLocked();
1255 }
1256 }
1257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001259 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001260 }
1261
Wink Saville63f03dd2014-10-23 10:44:45 -07001262 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001263 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001264 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001265 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001266 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001267 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001268 + " cfi=" + cfi);
1269 }
yifan.baie620ce72017-12-22 14:59:57 +08001270 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001272 if (validatePhoneId(phoneId)) {
1273 mCallForwarding[phoneId] = cfi;
1274 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001275 if (r.matchPhoneStateListenerEvent(
1276 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001277 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001278 try {
1279 r.callback.onCallForwardingIndicatorChanged(cfi);
1280 } catch (RemoteException ex) {
1281 mRemoveList.add(r.binder);
1282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 }
1284 }
1285 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001286 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 }
1288 }
1289
1290 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001291 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001292 }
1293
Wink Saville63f03dd2014-10-23 10:44:45 -07001294 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001295 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001296 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001297 }
yifan.baie620ce72017-12-22 14:59:57 +08001298 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001300 if (validatePhoneId(phoneId)) {
1301 mDataActivity[phoneId] = state;
1302 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001303 // Notify by correct subId.
1304 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1305 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001306 try {
1307 r.callback.onDataActivity(state);
1308 } catch (RemoteException ex) {
1309 mRemoveList.add(r.binder);
1310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 }
1312 }
1313 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001314 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 }
1316 }
1317
Jack Yuf05919a2019-01-02 16:51:08 -08001318 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1319 LinkProperties linkProperties,
1320 NetworkCapabilities networkCapabilities, int networkType,
1321 boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001322 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yuf05919a2019-01-02 16:51:08 -08001323 isDataAllowed, apn, apnType, linkProperties,
1324 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001325 }
1326
Jack Yuf05919a2019-01-02 16:51:08 -08001327 public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataAllowed,
1328 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001329 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1330 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001331 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001332 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001333 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001334 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001335 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001336 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001337 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001338 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001339 }
yifan.baie620ce72017-12-22 14:59:57 +08001340 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001342 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001343 // We only call the callback when the change is for default APN type.
1344 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1345 && (mDataConnectionState[phoneId] != state
1346 || mDataConnectionNetworkType[phoneId] != networkType)) {
1347 String str = "onDataConnectionStateChanged(" + state
1348 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001349 log(str);
1350 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001351 for (Record r : mRecords) {
1352 if (r.matchPhoneStateListenerEvent(
1353 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1354 idMatch(r.subId, subId, phoneId)) {
1355 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001356 if (DBG) {
1357 log("Notify data connection state changed on sub: " + subId);
1358 }
Jack Yub1bac542018-03-14 16:23:38 -07001359 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001360 } catch (RemoteException ex) {
1361 mRemoveList.add(r.binder);
1362 }
1363 }
1364 }
1365 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001366
1367 mDataConnectionState[phoneId] = state;
1368 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001369 }
1370 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
chen xu896e3d42018-12-11 18:09:41 -08001371 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1372 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001373 for (Record r : mRecords) {
1374 if (r.matchPhoneStateListenerEvent(
1375 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1376 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001377 r.callback.onPreciseDataConnectionStateChanged(
1378 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001379 } catch (RemoteException ex) {
1380 mRemoveList.add(r.binder);
1381 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001382 }
1383 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001384 }
1385 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 }
Jack Yuf05919a2019-01-02 16:51:08 -08001387 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1388 networkCapabilities, roaming, subId);
1389 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu896e3d42018-12-11 18:09:41 -08001390 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 }
1392
Jack Yuf05919a2019-01-02 16:51:08 -08001393 public void notifyDataConnectionFailed(String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001394 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yuf05919a2019-01-02 16:51:08 -08001395 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001396 }
1397
Jack Yuf05919a2019-01-02 16:51:08 -08001398 public void notifyDataConnectionFailedForSubscriber(int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001399 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001400 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001401 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001402 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001403 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yuf05919a2019-01-02 16:51:08 -08001404 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001407 mPreciseDataConnectionState = new PreciseDataConnectionState(
1408 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001409 ApnSetting.getApnTypesBitmaskFromString(apnType), "", null,
1410 DataFailCause.NONE);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001411 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001412 if (r.matchPhoneStateListenerEvent(
1413 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001414 try {
1415 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1416 } catch (RemoteException ex) {
1417 mRemoveList.add(r.binder);
1418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 }
1420 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001421 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 }
Jack Yuf05919a2019-01-02 16:51:08 -08001423 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001424 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001425 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", null,
1426 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 }
1428
1429 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001430 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001431 }
1432
Wink Saville63f03dd2014-10-23 10:44:45 -07001433 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001434 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001435 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001436 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001437 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001438 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001439 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001440 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001441 + " cellLocation=" + cellLocation);
1442 }
yifan.baie620ce72017-12-22 14:59:57 +08001443 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001445 if (validatePhoneId(phoneId)) {
1446 mCellLocation[phoneId] = cellLocation;
1447 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001448 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001449 idMatch(r.subId, subId, phoneId) &&
1450 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001451 try {
1452 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001453 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001454 + " r=" + r);
1455 }
1456 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1457 } catch (RemoteException ex) {
1458 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001459 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 }
1462 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001463 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001464 }
1465 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466
Wink Savillefd2d0132010-10-28 14:22:26 -07001467 public void notifyOtaspChanged(int otaspMode) {
1468 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1469 return;
1470 }
1471 synchronized (mRecords) {
1472 mOtaspMode = otaspMode;
1473 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001474 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001475 try {
1476 r.callback.onOtaspChanged(otaspMode);
1477 } catch (RemoteException ex) {
1478 mRemoveList.add(r.binder);
1479 }
1480 }
1481 }
1482 handleRemoveListLocked();
1483 }
1484 }
1485
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001486 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1487 int backgroundCallState) {
1488 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1489 return;
1490 }
1491 synchronized (mRecords) {
1492 mRingingCallState = ringingCallState;
1493 mForegroundCallState = foregroundCallState;
1494 mBackgroundCallState = backgroundCallState;
1495 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1496 backgroundCallState,
1497 DisconnectCause.NOT_VALID,
1498 PreciseDisconnectCause.NOT_VALID);
1499 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001500 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001501 try {
1502 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1503 } catch (RemoteException ex) {
1504 mRemoveList.add(r.binder);
1505 }
1506 }
1507 }
1508 handleRemoveListLocked();
1509 }
chen xu970d7792018-12-12 19:59:30 -08001510 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1511 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001512 }
1513
1514 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1515 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1516 return;
1517 }
1518 synchronized (mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001519 mCallDisconnectCause = disconnectCause;
1520 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001521 for (Record r : mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001522 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1523 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001524 try {
chen xu970d7792018-12-12 19:59:30 -08001525 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1526 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001527 } catch (RemoteException ex) {
1528 mRemoveList.add(r.binder);
1529 }
1530 }
1531 }
1532 handleRemoveListLocked();
1533 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001534 }
1535
chen xu896e3d42018-12-11 18:09:41 -08001536 public void notifyPreciseDataConnectionFailed(String apnType,
1537 String apn, @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001538 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1539 return;
1540 }
1541 synchronized (mRecords) {
1542 mPreciseDataConnectionState = new PreciseDataConnectionState(
1543 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001544 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001545 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001546 if (r.matchPhoneStateListenerEvent(
1547 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001548 try {
1549 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1550 } catch (RemoteException ex) {
1551 mRemoveList.add(r.binder);
1552 }
1553 }
1554 }
1555 handleRemoveListLocked();
1556 }
1557 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yuf05919a2019-01-02 16:51:08 -08001558 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001559 }
1560
Brad Ebingerefed9822018-10-26 10:25:57 -07001561 @Override
1562 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1563 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001564 return;
1565 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001566 if (VDBG) {
1567 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1568 }
1569 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001570 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001571 if (validatePhoneId(phoneId)) {
1572 mSrvccState[phoneId] = state;
1573 for (Record r : mRecords) {
1574 if (r.matchPhoneStateListenerEvent(
1575 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1576 idMatch(r.subId, subId, phoneId)) {
1577 try {
1578 if (DBG_LOC) {
1579 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1580 }
1581 r.callback.onSrvccStateChanged(state);
1582 } catch (RemoteException ex) {
1583 mRemoveList.add(r.binder);
1584 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001585 }
1586 }
1587 }
1588 handleRemoveListLocked();
1589 }
1590 }
1591
Shuo Qian066e8652018-04-25 21:02:35 +00001592 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1593 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1594 return;
1595 }
1596
1597 synchronized (mRecords) {
1598 for (Record r : mRecords) {
1599 if (VDBG) {
1600 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1601 }
1602 if ((r.matchPhoneStateListenerEvent(
1603 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1604 ((r.subId == subId) ||
1605 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1606 try {
1607 r.callback.onOemHookRawEvent(rawData);
1608 } catch (RemoteException ex) {
1609 mRemoveList.add(r.binder);
1610 }
1611 }
1612 }
1613 handleRemoveListLocked();
1614 }
1615 }
1616
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001617 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1618 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1619 return;
1620 }
1621
1622 if (VDBG) {
1623 log("notifyPhoneCapabilityChanged: capability=" + capability);
1624 }
1625
1626 synchronized (mRecords) {
1627 mPhoneCapability = capability;
1628
1629 for (Record r : mRecords) {
1630 if (r.matchPhoneStateListenerEvent(
1631 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1632 try {
1633 r.callback.onPhoneCapabilityChanged(capability);
1634 } catch (RemoteException ex) {
1635 mRemoveList.add(r.binder);
1636 }
1637 }
1638 }
1639 handleRemoveListLocked();
1640 }
1641 }
1642
Malcolm Chenc1873af2018-09-24 20:01:32 -07001643 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1644 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1645 return;
1646 }
1647
1648 if (VDBG) {
1649 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1650 }
1651
1652 synchronized (mRecords) {
1653 mPreferredDataSubId = preferredSubId;
1654
1655 for (Record r : mRecords) {
1656 if (r.matchPhoneStateListenerEvent(
1657 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1658 try {
1659 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1660 } catch (RemoteException ex) {
1661 mRemoveList.add(r.binder);
1662 }
1663 }
1664 }
1665 handleRemoveListLocked();
1666 }
1667 }
1668
chen xu760729c2018-10-11 13:18:26 -07001669 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1670 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1671 return;
1672 }
1673
1674 if (VDBG) {
1675 log("notifyRadioPowerStateChanged: state= " + state);
1676 }
1677
1678 synchronized (mRecords) {
1679 mRadioPowerState = state;
1680
1681 for (Record r : mRecords) {
1682 if (r.matchPhoneStateListenerEvent(
1683 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1684 try {
1685 r.callback.onRadioPowerStateChanged(state);
1686 } catch (RemoteException ex) {
1687 mRemoveList.add(r.binder);
1688 }
1689 }
1690 }
1691 handleRemoveListLocked();
1692 }
1693 }
1694
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696 @Override
sqian46c0c302018-12-27 14:12:11 -08001697 public void notifyEmergencyNumberList() {
1698 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1699 return;
1700 }
1701
1702 synchronized (mRecords) {
sqian3e8647c2018-12-14 21:47:49 -08001703 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1704 Context.TELEPHONY_SERVICE);
1705 mEmergencyNumberList = tm.getCurrentEmergencyNumberList();
sqian46c0c302018-12-27 14:12:11 -08001706
1707 for (Record r : mRecords) {
1708 if (r.matchPhoneStateListenerEvent(
1709 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)) {
1710 try {
1711 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1712 if (VDBG) {
1713 log("notifyEmergencyNumberList: emergencyNumberList= "
1714 + mEmergencyNumberList);
1715 }
1716 } catch (RemoteException ex) {
1717 mRemoveList.add(r.binder);
1718 }
1719 }
1720 }
1721 handleRemoveListLocked();
1722 }
sqianbf165bc2018-12-07 17:09:39 -08001723 }
1724
1725
1726 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001727 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1728 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1729
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001730 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001732 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001733 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001734 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001735 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301736 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001737 pw.println("Phone Id=" + i);
1738 pw.increaseIndent();
1739 pw.println("mCallState=" + mCallState[i]);
1740 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1741 pw.println("mServiceState=" + mServiceState[i]);
1742 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1743 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001744 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001745 pw.println("mSignalStrength=" + mSignalStrength[i]);
1746 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1747 pw.println("mCallForwarding=" + mCallForwarding[i]);
1748 pw.println("mDataActivity=" + mDataActivity[i]);
1749 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001750 pw.println("mCellLocation=" + mCellLocation[i]);
1751 pw.println("mCellInfo=" + mCellInfo.get(i));
1752 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301753 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001754 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1755 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu970d7792018-12-12 19:59:30 -08001756 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1757 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001758 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1759 pw.println("mRingingCallState=" + mRingingCallState);
1760 pw.println("mForegroundCallState=" + mForegroundCallState);
1761 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001762 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001763 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chenc1873af2018-09-24 20:01:32 -07001764 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
chen xu760729c2018-10-11 13:18:26 -07001765 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian46c0c302018-12-27 14:12:11 -08001766 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
Jack Yud19b6ae2017-04-05 14:12:09 -07001767
1768 pw.decreaseIndent();
1769
1770 pw.println("local logs:");
1771 pw.increaseIndent();
1772 mLocalLog.dump(fd, pw, args);
1773 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001774 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001775 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001776 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001777 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001778 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001779 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 }
1781 }
1782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 //
1784 // the legacy intent broadcasting
1785 //
1786
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001787 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001788 long ident = Binder.clearCallingIdentity();
1789 try {
1790 mBatteryStats.notePhoneState(state.getState());
1791 } catch (RemoteException re) {
1792 // Can't do much
1793 } finally {
1794 Binder.restoreCallingIdentity(ident);
1795 }
1796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001798 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 Bundle data = new Bundle();
1800 state.fillInNotifierBundle(data);
1801 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001802 // Pass the subscription along with the intent.
1803 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001804 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001805 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001806 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 }
1808
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001809 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1810 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001811 long ident = Binder.clearCallingIdentity();
1812 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001813 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001814 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001815 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001816 } finally {
1817 Binder.restoreCallingIdentity(ident);
1818 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001821 Bundle data = new Bundle();
1822 signalStrength.fillInNotifierBundle(data);
1823 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001824 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001825 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001826 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001827 }
1828
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001829 /**
1830 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1831 * a valid subId, in which case this function fires a subId-specific intent, or it
1832 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1833 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1834 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001835 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1836 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 long ident = Binder.clearCallingIdentity();
1838 try {
1839 if (state == TelephonyManager.CALL_STATE_IDLE) {
1840 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001841 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1842 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 } else {
1844 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001845 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1846 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 }
1848 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001849 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 } finally {
1851 Binder.restoreCallingIdentity(ident);
1852 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001855 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001856 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001857
1858 // If a valid subId was specified, we should fire off a subId-specific state
1859 // change intent and include the subId.
1860 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1861 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1862 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001863 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001864 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001865 // If the phoneId is invalid, the broadcast is for overall call state.
1866 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1867 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1868 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001869
Brad Ebinger51de96a2017-04-21 17:05:18 -07001870 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1871 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1872
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001873 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001874 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001875 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1876
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001877 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1878 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001879 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001880 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001881 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001882 android.Manifest.permission.READ_PHONE_STATE,
1883 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001884 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1885 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1886 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 }
1888
Jack Yuf05919a2019-01-02 16:51:08 -08001889 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
1890 String apnType, LinkProperties linkProperties,
1891 NetworkCapabilities networkCapabilities,
1892 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001893 // Note: not reporting to the battery stats service here, because the
1894 // status bar takes care of that after taking into account all of the
1895 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001897 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001898 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001899 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001900 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001901 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001902 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001903 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001904 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001905 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001906 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001907 }
1908 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001909 if (networkCapabilities != null) {
1910 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001911 }
Wink Savillea639b312012-07-10 12:37:54 -07001912 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001913
Wink Savillea639b312012-07-10 12:37:54 -07001914 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1915 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001916 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001917 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 }
1919
Jack Yuf05919a2019-01-02 16:51:08 -08001920 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001922 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001923 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001924 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001926
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001927 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yuf05919a2019-01-02 16:51:08 -08001928 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001929 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1930 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1931 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1932 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001933 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1934 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1935 }
1936
1937 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu896e3d42018-12-11 18:09:41 -08001938 String apnType, String apn, LinkProperties linkProperties,
1939 @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001940 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1941 intent.putExtra(PhoneConstants.STATE_KEY, state);
1942 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001943 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1944 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001945 if (linkProperties != null) {
Jack Yuf05919a2019-01-02 16:51:08 -08001946 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001947 }
chen xu896e3d42018-12-11 18:09:41 -08001948 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001949
1950 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1951 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1952 }
1953
Andrew Flynnceaed682015-06-09 12:36:58 +00001954 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001955 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001956 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001957 }
1958
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001959 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1960 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001961 }
1962
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001963 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001964 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001965 return true;
1966 }
1967 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001968 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001969 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001970 return false;
1971 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001972
Andrew Flynn1f452642015-04-14 22:16:04 -04001973 private boolean checkNotifyPermission() {
1974 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1975 == PackageManager.PERMISSION_GRANTED;
1976 }
1977
Jeff Davidson29da89f2018-02-28 17:50:16 -08001978 private boolean checkListenerPermission(
1979 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001980 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001981 mContext.enforceCallingOrSelfPermission(
1982 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001983 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1984 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1985 return false;
1986 }
John Wang963db55d2012-03-30 16:04:06 -07001987 }
1988
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001989 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1991 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001992 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001993 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001994 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001995
1996 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1997 mContext.enforceCallingOrSelfPermission(
1998 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001999 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002000
Shuo Qian066e8652018-04-25 21:02:35 +00002001 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2002 mContext.enforceCallingOrSelfPermission(
2003 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2004 }
2005
Brad Ebingerefed9822018-10-26 10:25:57 -07002006 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2007 mContext.enforceCallingOrSelfPermission(
2008 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2009 }
2010
2011
chen xu970d7792018-12-12 19:59:30 -08002012 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2013 mContext.enforceCallingOrSelfPermission(
2014 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2015 }
2016
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002017 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002018 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002019
2020 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002021 int size = mRemoveList.size();
2022 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2023 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002024 for (IBinder b: mRemoveList) {
2025 remove(b);
2026 }
2027 mRemoveList.clear();
2028 }
2029 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002030
2031 private boolean validateEventsAndUserLocked(Record r, int events) {
2032 int foregroundUser;
2033 long callingIdentity = Binder.clearCallingIdentity();
2034 boolean valid = false;
2035 try {
2036 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002037 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2038 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002039 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002040 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002041 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002042 + " r.events=" + r.events + " events=" + events);
2043 }
2044 } finally {
2045 Binder.restoreCallingIdentity(callingIdentity);
2046 }
2047 return valid;
2048 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002049
2050 private boolean validatePhoneId(int phoneId) {
2051 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002052 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002053 return valid;
2054 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002055
2056 private static void log(String s) {
2057 Rlog.d(TAG, s);
2058 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002059
xinhe8b79fb62014-11-05 14:55:03 -08002060 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002061
2062 if(subId < 0) {
2063 // Invalid case, we need compare phoneId with default one.
2064 return (mDefaultPhoneId == phoneId);
2065 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002066 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002067 return (subId == mDefaultSubId);
2068 } else {
2069 return (rSubId == subId);
2070 }
2071 }
2072
Hall Liu5fb337f2017-11-22 17:38:15 -08002073 private boolean checkLocationAccess(Record r) {
2074 long token = Binder.clearCallingIdentity();
2075 try {
2076 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08002077 r.callingPackage, r.callerUid, r.callerPid,
2078 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08002079 } finally {
2080 Binder.restoreCallingIdentity(token);
2081 }
2082 }
2083
xinhee9f16402014-09-25 16:39:28 -07002084 private void checkPossibleMissNotify(Record r, int phoneId) {
2085 int events = r.events;
2086
2087 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2088 try {
2089 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2090 mServiceState[phoneId]);
2091 r.callback.onServiceStateChanged(
2092 new ServiceState(mServiceState[phoneId]));
2093 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002094 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002095 }
2096 }
2097
2098 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2099 try {
2100 SignalStrength signalStrength = mSignalStrength[phoneId];
2101 if (DBG) {
2102 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2103 }
2104 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2105 } catch (RemoteException ex) {
2106 mRemoveList.add(r.binder);
2107 }
2108 }
2109
2110 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2111 try {
2112 int gsmSignalStrength = mSignalStrength[phoneId]
2113 .getGsmSignalStrength();
2114 if (DBG) {
2115 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2116 gsmSignalStrength);
2117 }
2118 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2119 : gsmSignalStrength));
2120 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002121 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002122 }
2123 }
2124
2125 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2126 try {
2127 if (DBG_LOC) {
2128 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2129 + mCellInfo.get(phoneId));
2130 }
Hall Liu5fb337f2017-11-22 17:38:15 -08002131 if (checkLocationAccess(r)) {
2132 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2133 }
xinhee9f16402014-09-25 16:39:28 -07002134 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002135 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002136 }
2137 }
2138
zxuan35a47022018-01-04 11:24:04 -08002139 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2140 try {
2141 if (VDBG) {
2142 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2143 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2144 }
2145 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2146 } catch (RemoteException ex) {
2147 mRemoveList.add(r.binder);
2148 }
2149 }
2150
xinhee9f16402014-09-25 16:39:28 -07002151 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2152 try {
2153 if (VDBG) {
2154 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2155 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2156 }
2157 r.callback.onMessageWaitingIndicatorChanged(
2158 mMessageWaiting[phoneId]);
2159 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002160 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002161 }
2162 }
2163
2164 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2165 try {
2166 if (VDBG) {
2167 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2168 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2169 }
2170 r.callback.onCallForwardingIndicatorChanged(
2171 mCallForwarding[phoneId]);
2172 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002173 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002174 }
2175 }
2176
2177 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2178 try {
2179 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2180 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002181 if (checkLocationAccess(r)) {
2182 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2183 }
xinhee9f16402014-09-25 16:39:28 -07002184 } catch (RemoteException ex) {
2185 mRemoveList.add(r.binder);
2186 }
2187 }
2188
2189 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2190 try {
2191 if (DBG) {
2192 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2193 + "=" + mDataConnectionState[phoneId]
2194 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2195 + ")");
2196 }
2197 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2198 mDataConnectionNetworkType[phoneId]);
2199 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002200 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002201 }
2202 }
2203 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204}