blob: 8b5176e2c8586dcd43a9fb53e755b5b12ad60c08 [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;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080038import android.telephony.LocationAccessPolicy;
Jack Yud19b6ae2017-04-05 14:12:09 -070039import android.telephony.PhoneStateListener;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020040import android.telephony.PreciseCallState;
41import android.telephony.PreciseDataConnectionState;
42import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070043import android.telephony.Rlog;
44import android.telephony.ServiceState;
45import android.telephony.SignalStrength;
46import android.telephony.SubscriptionManager;
47import android.telephony.TelephonyManager;
48import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070050import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080053import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070055import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080056import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070057import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080059import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060060import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070061import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import com.android.server.am.BatteryStatsService;
63
Jack Yud19b6ae2017-04-05 14:12:09 -070064import java.io.FileDescriptor;
65import java.io.PrintWriter;
66import java.util.ArrayList;
67import java.util.Arrays;
68import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080069import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071/**
Wink Savillee9b06d72009-05-18 21:47:50 -070072 * Since phone process can be restarted, this class provides a centralized place
73 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070074 *
75 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
76 * and 15973975 by saving the phoneId of the registrant and then using the
77 * phoneId when deciding to to make a callback. This is necessary because
78 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070079 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070080 * the dummy value conversion we properly do the callbacks.
81 *
82 * Eventually we may want to remove the notion of dummy value but for now this
83 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 */
85class TelephonyRegistry extends ITelephonyRegistry.Stub {
86 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070087 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070088 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070089 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070092 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
Malcolm Chenabbfac22018-02-12 19:15:59 -080096 TelephonyRegistryDeathRecipient deathRecipient;
97
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080099 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
Hall Liu5fb337f2017-11-22 17:38:15 -0800101 int callerUid;
102 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700105
Wink Savilled09c4ca2014-11-22 10:08:16 -0800106 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700107
Wink Savilled09c4ca2014-11-22 10:08:16 -0800108 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800109
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700110 boolean canReadPhoneState;
111
Wink Savillea374c3d2014-11-11 11:48:04 -0800112 boolean matchPhoneStateListenerEvent(int events) {
113 return (callback != null) && ((events & this.events) != 0);
114 }
115
Wink Savilled09c4ca2014-11-22 10:08:16 -0800116 boolean matchOnSubscriptionsChangedListener() {
117 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800118 }
Wink Savillee380b982014-07-26 18:24:22 -0700119
Wink Savillea12a7b32012-09-20 10:09:45 -0700120 @Override
121 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700122 return "{callingPackage=" + callingPackage + " binder=" + binder
123 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800124 + " onSubscriptionsChangedListenererCallback="
125 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800126 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700127 + " events=" + Integer.toHexString(events)
128 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 }
131
132 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700133
Joe Onorato163d8d92010-10-21 13:21:20 -0400134 // access should be inside synchronized (mRecords) for these two fields
135 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
136 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 private final IBatteryStats mBatteryStats;
139
Svet Ganov16a16892015-04-16 10:32:04 -0700140 private final AppOpsManager mAppOps;
141
Wink Savilled09c4ca2014-11-22 10:08:16 -0800142 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
Wink Savillefb40dd42014-06-12 17:02:31 -0700146 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
Wink Savillefb40dd42014-06-12 17:02:31 -0700148 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
fionaxu12312f62016-11-14 13:32:14 -0800152 private int[] mVoiceActivationState;
153
154 private int[] mDataActivationState;
155
zxuan35a47022018-01-04 11:24:04 -0800156 private boolean[] mUserMobileDataState;
157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Yifan Bai57b39e32016-04-01 16:24:33 +0800168 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175
Wink Savillefb40dd42014-06-12 17:02:31 -0700176 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700177
Nathan Harold016e9c62016-12-14 11:24:48 -0800178 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700179
Wink Savillefb40dd42014-06-12 17:02:31 -0700180 private ArrayList<List<CellInfo>> mCellInfo = null;
181
182 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
183
Wink Savilled09c4ca2014-11-22 10:08:16 -0800184 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700185
Wink Savilled09c4ca2014-11-22 10:08:16 -0800186 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700187
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200188 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
189
190 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
191
192 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
193
194 private PreciseCallState mPreciseCallState = new PreciseCallState();
195
Andrew Flynn1f452642015-04-14 22:16:04 -0400196 private boolean mCarrierNetworkChangeState = false;
197
Jack Yud19b6ae2017-04-05 14:12:09 -0700198 private final LocalLog mLocalLog = new LocalLog(100);
199
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200200 private PreciseDataConnectionState mPreciseDataConnectionState =
201 new PreciseDataConnectionState();
202
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700203 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700204 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700205 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
206 PhoneStateListener.LISTEN_VOLTE_STATE;
207
208 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700209 PhoneStateListener.LISTEN_CALL_STATE |
210 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700211 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700212
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200213 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
214 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
215 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
216
Wink Savillea12a7b32012-09-20 10:09:45 -0700217 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700218 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700219
220 private final Handler mHandler = new Handler() {
221 @Override
222 public void handleMessage(Message msg) {
223 switch (msg.what) {
224 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700225 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700226 int numPhones = TelephonyManager.getDefault().getPhoneCount();
227 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700228 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700229 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700230 }
231 break;
232 }
xinhee9f16402014-09-25 16:39:28 -0700233 case MSG_UPDATE_DEFAULT_SUB: {
234 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700235 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700236 if (VDBG) {
237 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
238 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
239 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
240 }
241
242 //Due to possible risk condition,(notify call back using the new
243 //defaultSubId comes before new defaultSubId update) we need to recall all
244 //possible missed notify callback
245 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700246 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800247 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700248 checkPossibleMissNotify(r, newDefaultPhoneId);
249 }
250 }
251 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700252 }
253 mDefaultSubId = newDefaultSubId;
254 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700255 }
256 }
257 }
258 };
259
Malcolm Chenabbfac22018-02-12 19:15:59 -0800260 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
261
262 private final IBinder binder;
263
264 TelephonyRegistryDeathRecipient(IBinder binder) {
265 this.binder = binder;
266 }
267
268 @Override
269 public void binderDied() {
270 if (DBG) log("binderDied " + binder);
271 remove(binder);
272 }
273 }
274
Wink Savillea12a7b32012-09-20 10:09:45 -0700275 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
276 @Override
277 public void onReceive(Context context, Intent intent) {
278 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700279 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700280 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700281 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700282 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700283 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700284 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700285 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800286 PhoneConstants.SUBSCRIPTION_KEY,
287 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700288 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
289 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700290 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700291 log("onReceive:current mDefaultSubId=" + mDefaultSubId
292 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
293 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700294 }
xinhee9f16402014-09-25 16:39:28 -0700295
Junda Liu985f52c2015-02-23 16:06:51 -0800296 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700297 || (newDefaultPhoneId != mDefaultPhoneId))) {
298 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
299 newDefaultPhoneId, 0, newDefaultSubIdObj));
300 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700301 }
302 }
303 };
304
Wink Savillee9b06d72009-05-18 21:47:50 -0700305 // we keep a copy of all of the state so we can send it out when folks
306 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700308 // In these calls we call with the lock held. This is safe becasuse remote
309 // calls go through a oneway interface and local calls going through a
310 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311
312 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700313 CellLocation location = CellLocation.getEmpty();
314
Wink Savillefb40dd42014-06-12 17:02:31 -0700315 mContext = context;
316 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700317
Wink Savillefb40dd42014-06-12 17:02:31 -0700318 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700319 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700320 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800321 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700322 mCallState = new int[numPhones];
323 mDataActivity = new int[numPhones];
324 mDataConnectionState = new int[numPhones];
325 mDataConnectionNetworkType = new int[numPhones];
326 mCallIncomingNumber = new String[numPhones];
327 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800328 mVoiceActivationState = new int[numPhones];
329 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800330 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700331 mSignalStrength = new SignalStrength[numPhones];
332 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 mCallForwarding = new boolean[numPhones];
334 mCellLocation = new Bundle[numPhones];
335 mDataConnectionLinkProperties = new LinkProperties[numPhones];
336 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
337 mCellInfo = new ArrayList<List<CellInfo>>();
338 for (int i = 0; i < numPhones; i++) {
339 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
340 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
341 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800342 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
343 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700344 mCallIncomingNumber[i] = "";
345 mServiceState[i] = new ServiceState();
346 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800347 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700348 mMessageWaiting[i] = false;
349 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700350 mCellLocation[i] = new Bundle();
351 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800352 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700353 }
354
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700355 // Note that location can be null for non-phone builds like
356 // like the generic one.
357 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700358 for (int i = 0; i < numPhones; i++) {
359 location.fillInNotifierBundle(mCellLocation[i]);
360 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700361 }
Svet Ganov16a16892015-04-16 10:32:04 -0700362
363 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 }
365
Svetoslav Ganova0027152013-06-25 14:59:53 -0700366 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700367 // Watch for interesting updates
368 final IntentFilter filter = new IntentFilter();
369 filter.addAction(Intent.ACTION_USER_SWITCHED);
370 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700371 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700372 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700373 mContext.registerReceiver(mBroadcastReceiver, filter);
374 }
375
376 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700377 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800378 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700379 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800380 mContext.getSystemService(AppOpsManager.class)
381 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800382 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700383 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
384 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800385 + " callback.asBinder=" + callback.asBinder());
386 }
387
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
389 mContext, callingPackage, "addOnSubscriptionsChangedListener")) {
390 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700391 }
392
Wink Savillea374c3d2014-11-11 11:48:04 -0800393
Wink Savilled09c4ca2014-11-22 10:08:16 -0800394 synchronized (mRecords) {
395 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800396 IBinder b = callback.asBinder();
397 Record r = add(b);
398
399 if (r == null) {
400 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800401 }
402
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700404 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800405 r.callerUid = Binder.getCallingUid();
406 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800407 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700408 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800409 if (DBG) {
410 log("listen oscl: Register r=" + r);
411 }
412 // Always notify when registration occurs if there has been a notification.
413 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800414 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800415 if (VDBG) log("listen oscl: send to r=" + r);
416 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
417 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800418 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 remove(r.binder);
421 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800422 } else {
423 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 }
426 }
427
428 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800429 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800430 IOnSubscriptionsChangedListener callback) {
431 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800432 remove(callback.asBinder());
433 }
434
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 @Override
436 public void notifySubscriptionInfoChanged() {
437 if (VDBG) log("notifySubscriptionInfoChanged:");
438 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 if (!hasNotifySubscriptionInfoChangedOccurred) {
440 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
441 + mRecords.size());
442 }
443 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 mRemoveList.clear();
445 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800446 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800447 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800448 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
449 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
450 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800451 } catch (RemoteException ex) {
452 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
453 mRemoveList.add(r.binder);
454 }
455 }
456 }
457 handleRemoveListLocked();
458 }
459 }
460
461 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
463 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800464 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
465 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700466 }
467
468 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700469 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700470 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700471 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700472 }
473
Svet Ganov16a16892015-04-16 10:32:04 -0700474 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700475 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700476 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800477 mContext.getSystemService(AppOpsManager.class)
478 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700479 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700480 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700481 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
482 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700483 }
xinhe75c2c152014-10-16 11:49:45 -0700484
485 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800486 // Checks permission and throws SecurityException for disallowed operations. For pre-M
487 // apps whose runtime permission has been revoked, we return immediately to skip sending
488 // events to the app without crashing it.
489 if (!checkListenerPermission(events, callingPackage, "listen")) {
490 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700491 }
492
yifan.baie620ce72017-12-22 14:59:57 +0800493 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 synchronized (mRecords) {
495 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800496 IBinder b = callback.asBinder();
497 Record r = add(b);
498
499 if (r == null) {
500 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
xinhe43c50292014-09-18 17:56:48 -0700502
xinhe75c2c152014-10-16 11:49:45 -0700503 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700504 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800505 r.callerUid = Binder.getCallingUid();
506 r.callerPid = Binder.getCallingPid();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700507 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
508 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800509 r.canReadPhoneState =
510 isPhoneStateEvent && canReadPhoneState(callingPackage, "listen");
xinhe75c2c152014-10-16 11:49:45 -0700511 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
512 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800514 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700515 } else {//APP specify subID
516 r.subId = subId;
517 }
yifan.baie620ce72017-12-22 14:59:57 +0800518 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700520 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700521 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700522 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700523 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400525 try {
Wink Savillee380b982014-07-26 18:24:22 -0700526 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700527 r.callback.onServiceStateChanged(
528 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400529 } catch (RemoteException ex) {
530 remove(r.binder);
531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 }
533 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
534 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700535 int gsmSignalStrength = mSignalStrength[phoneId]
536 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700537 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
538 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 } catch (RemoteException ex) {
540 remove(r.binder);
541 }
542 }
543 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
544 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700545 r.callback.onMessageWaitingIndicatorChanged(
546 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 } catch (RemoteException ex) {
548 remove(r.binder);
549 }
550 }
551 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
552 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700553 r.callback.onCallForwardingIndicatorChanged(
554 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 } catch (RemoteException ex) {
556 remove(r.binder);
557 }
558 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700559 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400560 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700561 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800563 if (checkLocationAccess(r)) {
564 r.callback.onCellLocationChanged(
565 new Bundle(mCellLocation[phoneId]));
566 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400567 } catch (RemoteException ex) {
568 remove(r.binder);
569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 }
571 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
572 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700573 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700574 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 } catch (RemoteException ex) {
576 remove(r.binder);
577 }
578 }
579 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
580 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700581 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
582 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 } catch (RemoteException ex) {
584 remove(r.binder);
585 }
586 }
587 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
588 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700589 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 } catch (RemoteException ex) {
591 remove(r.binder);
592 }
593 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700594 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
595 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700596 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700597 } catch (RemoteException ex) {
598 remove(r.binder);
599 }
600 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700601 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
602 try {
603 r.callback.onOtaspChanged(mOtaspMode);
604 } catch (RemoteException ex) {
605 remove(r.binder);
606 }
607 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700608 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700609 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700610 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700611 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800612 if (checkLocationAccess(r)) {
613 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
614 }
John Wang963db55d2012-03-30 16:04:06 -0700615 } catch (RemoteException ex) {
616 remove(r.binder);
617 }
618 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200619 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
620 try {
621 r.callback.onPreciseCallStateChanged(mPreciseCallState);
622 } catch (RemoteException ex) {
623 remove(r.binder);
624 }
625 }
626 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
627 try {
628 r.callback.onPreciseDataConnectionStateChanged(
629 mPreciseDataConnectionState);
630 } catch (RemoteException ex) {
631 remove(r.binder);
632 }
633 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400634 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
635 try {
636 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
637 } catch (RemoteException ex) {
638 remove(r.binder);
639 }
640 }
fionaxu12312f62016-11-14 13:32:14 -0800641 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
642 try {
643 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
644 } catch (RemoteException ex) {
645 remove(r.binder);
646 }
647 }
648 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
649 try {
650 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
651 } catch (RemoteException ex) {
652 remove(r.binder);
653 }
654 }
zxuan35a47022018-01-04 11:24:04 -0800655 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
656 try {
657 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
658 } catch (RemoteException ex) {
659 remove(r.binder);
660 }
661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 }
663 }
664 } else {
xinhe75c2c152014-10-16 11:49:45 -0700665 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 remove(callback.asBinder());
667 }
668 }
669
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800670 private boolean canReadPhoneState(String callingPackage, String message) {
671 try {
672 return TelephonyPermissions.checkCallingOrSelfReadPhoneState(
673 mContext, callingPackage, message);
674 } catch (SecurityException e) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700675 return false;
676 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700677 }
678
679 private String getCallIncomingNumber(Record record, int phoneId) {
680 // Hide the number if record's process has no READ_PHONE_STATE permission
681 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
682 }
683
Malcolm Chenabbfac22018-02-12 19:15:59 -0800684 private Record add(IBinder binder) {
685 Record r;
686
687 synchronized (mRecords) {
688 final int N = mRecords.size();
689 for (int i = 0; i < N; i++) {
690 r = mRecords.get(i);
691 if (binder == r.binder) {
692 // Already existed.
693 return r;
694 }
695 }
696 r = new Record();
697 r.binder = binder;
698 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
699
700 try {
701 binder.linkToDeath(r.deathRecipient, 0);
702 } catch (RemoteException e) {
703 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
704 // Binder already died. Return null.
705 return null;
706 }
707
708 mRecords.add(r);
709 if (DBG) log("add new record");
710 }
711
712 return r;
713 }
714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 private void remove(IBinder binder) {
716 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700717 final int recordCount = mRecords.size();
718 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800719 Record r = mRecords.get(i);
720 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800721 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800722 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
723 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800724 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800725
726 if (r.deathRecipient != null) {
727 try {
728 binder.unlinkToDeath(r.deathRecipient, 0);
729 } catch (NoSuchElementException e) {
730 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
731 + r + " e=" + e);
732 }
733 }
734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 mRecords.remove(i);
736 return;
737 }
738 }
739 }
740 }
741
742 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700743 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700744 return;
745 }
xinhe43c50292014-09-18 17:56:48 -0700746
747 if (VDBG) {
748 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
749 }
750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700752 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800753 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800754 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700756 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
757 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400759 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 }
761 }
762 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400763 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700765
766 // Called only by Telecomm to communicate call state across different phone accounts. So
767 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800768 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700769 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700770 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 }
772
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700773 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
774 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700775 if (!checkNotifyPermission("notifyCallState()")) {
776 return;
777 }
Wink Savillee380b982014-07-26 18:24:22 -0700778 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700779 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 + " state=" + state + " incomingNumber=" + incomingNumber);
781 }
782 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700783 if (validatePhoneId(phoneId)) {
784 mCallState[phoneId] = state;
785 mCallIncomingNumber[phoneId] = incomingNumber;
786 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800787 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700788 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800789 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700790 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700791 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
792 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700793 } catch (RemoteException ex) {
794 mRemoveList.add(r.binder);
795 }
796 }
797 }
798 }
799 handleRemoveListLocked();
800 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700801 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700802 }
803
Wink Saville63f03dd2014-10-23 10:44:45 -0700804 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700805 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700806 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700807 }
xinhe43c50292014-09-18 17:56:48 -0700808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700810 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
811 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700812 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700813 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700814 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700815 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700816 if (validatePhoneId(phoneId)) {
817 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700818
Wink Savillefb40dd42014-06-12 17:02:31 -0700819 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700820 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700821 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700822 + " phoneId=" + phoneId + " state=" + state);
823 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800824 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800825 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700826 try {
Wink Savillee380b982014-07-26 18:24:22 -0700827 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700828 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700829 + " subId=" + subId + " phoneId=" + phoneId
830 + " state=" + state);
831 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700832 r.callback.onServiceStateChanged(new ServiceState(state));
833 } catch (RemoteException ex) {
834 mRemoveList.add(r.binder);
835 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400836 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700838 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700839 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400841 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700843 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
845
fionaxu12312f62016-11-14 13:32:14 -0800846 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
847 int activationType, int activationState) {
848 if (!checkNotifyPermission("notifySimActivationState()")){
849 return;
850 }
851 if (VDBG) {
852 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
853 + "type=" + activationType + " state=" + activationState);
854 }
855 synchronized (mRecords) {
856 if (validatePhoneId(phoneId)) {
857 switch (activationType) {
858 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
859 mVoiceActivationState[phoneId] = activationState;
860 break;
861 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
862 mDataActivationState[phoneId] = activationState;
863 break;
864 default:
865 return;
866 }
867 for (Record r : mRecords) {
868 if (VDBG) {
869 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
870 + " phoneId=" + phoneId + "type=" + activationType
871 + " state=" + activationState);
872 }
873 try {
874 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
875 r.matchPhoneStateListenerEvent(
876 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
877 idMatch(r.subId, subId, phoneId)) {
878 if (DBG) {
879 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
880 + " subId=" + subId + " phoneId=" + phoneId
881 + " state=" + activationState);
882 }
883 r.callback.onVoiceActivationStateChanged(activationState);
884 }
885 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
886 r.matchPhoneStateListenerEvent(
887 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
888 idMatch(r.subId, subId, phoneId)) {
889 if (DBG) {
890 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
891 + " subId=" + subId + " phoneId=" + phoneId
892 + " state=" + activationState);
893 }
894 r.callback.onDataActivationStateChanged(activationState);
895 }
896 } catch (RemoteException ex) {
897 mRemoveList.add(r.binder);
898 }
899 }
900 } else {
901 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
902 }
903 handleRemoveListLocked();
904 }
905 }
906
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700907 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
908 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700909 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700910 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700911 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000912 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700913 log("notifySignalStrengthForPhoneId: subId=" + subId
914 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000915 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700918 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700919 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700920 mSignalStrength[phoneId] = signalStrength;
921 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000922 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700923 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000924 + " phoneId=" + phoneId + " ss=" + signalStrength);
925 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800926 if (r.matchPhoneStateListenerEvent(
927 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800928 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700929 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000930 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700931 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000932 + " subId=" + subId + " phoneId=" + phoneId
933 + " ss=" + signalStrength);
934 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700935 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
936 } catch (RemoteException ex) {
937 mRemoveList.add(r.binder);
938 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400939 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800940 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800941 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700942 try {
943 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700944 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000945 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700946 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000947 + " subId=" + subId + " phoneId=" + phoneId
948 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
949 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700950 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700951 } catch (RemoteException ex) {
952 mRemoveList.add(r.binder);
953 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 }
955 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700956 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700957 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400959 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700961 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 }
963
Andrew Flynn1f452642015-04-14 22:16:04 -0400964 @Override
965 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000966 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
967
Andrew Flynn1f452642015-04-14 22:16:04 -0400968 if (VDBG) {
969 log("notifyCarrierNetworkChange: active=" + active);
970 }
971
972 synchronized (mRecords) {
973 mCarrierNetworkChangeState = active;
974 for (Record r : mRecords) {
975 if (r.matchPhoneStateListenerEvent(
976 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
977 try {
978 r.callback.onCarrierNetworkChange(active);
979 } catch (RemoteException ex) {
980 mRemoveList.add(r.binder);
981 }
982 }
983 }
984 handleRemoveListLocked();
985 }
986 }
987
Wink Savilleb208a242012-07-25 14:08:09 -0700988 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800989 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700990 }
991
Wink Saville63f03dd2014-10-23 10:44:45 -0700992 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700993 if (!checkNotifyPermission("notifyCellInfo()")) {
994 return;
995 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700996 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700997 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700998 + " cellInfo=" + cellInfo);
999 }
yifan.baie620ce72017-12-22 14:59:57 +08001000 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001001 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001002 if (validatePhoneId(phoneId)) {
1003 mCellInfo.set(phoneId, cellInfo);
1004 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001005 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001006 idMatch(r.subId, subId, phoneId) &&
1007 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001008 try {
1009 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001010 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001011 }
1012 r.callback.onCellInfoChanged(cellInfo);
1013 } catch (RemoteException ex) {
1014 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001015 }
John Wang963db55d2012-03-30 16:04:06 -07001016 }
1017 }
1018 }
1019 handleRemoveListLocked();
1020 }
1021 }
1022
xinhe43c50292014-09-18 17:56:48 -07001023 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001024 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001025 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001026 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001027 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001028 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001029 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001030 + " mwi=" + mwi);
1031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001033 if (validatePhoneId(phoneId)) {
1034 mMessageWaiting[phoneId] = mwi;
1035 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001036 if (r.matchPhoneStateListenerEvent(
1037 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001038 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001039 try {
1040 r.callback.onMessageWaitingIndicatorChanged(mwi);
1041 } catch (RemoteException ex) {
1042 mRemoveList.add(r.binder);
1043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 }
1045 }
1046 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001047 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 }
1049 }
1050
zxuan35a47022018-01-04 11:24:04 -08001051 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1052 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1053 return;
1054 }
1055 if (VDBG) {
1056 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1057 + " state=" + state);
1058 }
1059 synchronized (mRecords) {
1060 if (validatePhoneId(phoneId)) {
1061 mMessageWaiting[phoneId] = state;
1062 for (Record r : mRecords) {
1063 if (r.matchPhoneStateListenerEvent(
1064 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1065 idMatch(r.subId, subId, phoneId)) {
1066 try {
1067 r.callback.onUserMobileDataStateChanged(state);
1068 } catch (RemoteException ex) {
1069 mRemoveList.add(r.binder);
1070 }
1071 }
1072 }
1073 }
1074 handleRemoveListLocked();
1075 }
1076 }
1077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001079 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001080 }
1081
Wink Saville63f03dd2014-10-23 10:44:45 -07001082 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001083 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001084 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001085 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001086 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001087 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001088 + " cfi=" + cfi);
1089 }
yifan.baie620ce72017-12-22 14:59:57 +08001090 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001092 if (validatePhoneId(phoneId)) {
1093 mCallForwarding[phoneId] = cfi;
1094 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001095 if (r.matchPhoneStateListenerEvent(
1096 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001097 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001098 try {
1099 r.callback.onCallForwardingIndicatorChanged(cfi);
1100 } catch (RemoteException ex) {
1101 mRemoveList.add(r.binder);
1102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 }
1104 }
1105 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001106 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 }
1108 }
1109
1110 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001111 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001112 }
1113
Wink Saville63f03dd2014-10-23 10:44:45 -07001114 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001115 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001116 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001117 }
yifan.baie620ce72017-12-22 14:59:57 +08001118 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001120 if (validatePhoneId(phoneId)) {
1121 mDataActivity[phoneId] = state;
1122 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001123 // Notify by correct subId.
1124 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1125 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001126 try {
1127 r.callback.onDataActivity(state);
1128 } catch (RemoteException ex) {
1129 mRemoveList.add(r.binder);
1130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 }
1132 }
1133 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001134 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 }
1136 }
1137
Jack Yubaeec622017-05-01 17:01:11 -07001138 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001139 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001140 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001141 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001142 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001143 networkCapabilities, networkType, roaming);
1144 }
1145
Wink Saville63f03dd2014-10-23 10:44:45 -07001146 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001147 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001148 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1149 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001150 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001151 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001152 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001153 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001154 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001155 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001156 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001157 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001158 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001159 }
yifan.baie620ce72017-12-22 14:59:57 +08001160 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001162 if (validatePhoneId(phoneId)) {
1163 boolean modified = false;
1164 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001165 if (!mConnectedApns[phoneId].contains(apnType)) {
1166 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001167 if (mDataConnectionState[phoneId] != state) {
1168 mDataConnectionState[phoneId] = state;
1169 modified = true;
1170 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001172 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001173 if (mConnectedApns[phoneId].remove(apnType)) {
1174 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001175 mDataConnectionState[phoneId] = state;
1176 modified = true;
1177 } else {
1178 // leave mDataConnectionState as is and
1179 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001180 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001181 }
1182 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001183 mDataConnectionLinkProperties[phoneId] = linkProperties;
1184 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1185 if (mDataConnectionNetworkType[phoneId] != networkType) {
1186 mDataConnectionNetworkType[phoneId] = networkType;
1187 // need to tell registered listeners about the new network type
1188 modified = true;
1189 }
1190 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001191 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1192 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1193 log(str);
1194 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001195 for (Record r : mRecords) {
1196 if (r.matchPhoneStateListenerEvent(
1197 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1198 idMatch(r.subId, subId, phoneId)) {
1199 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001200 if (DBG) {
1201 log("Notify data connection state changed on sub: " + subId);
1202 }
1203 r.callback.onDataConnectionStateChanged(
1204 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001205 mDataConnectionNetworkType[phoneId]);
1206 } catch (RemoteException ex) {
1207 mRemoveList.add(r.binder);
1208 }
1209 }
1210 }
1211 handleRemoveListLocked();
1212 }
1213 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1214 apnType, apn, reason, linkProperties, "");
1215 for (Record r : mRecords) {
1216 if (r.matchPhoneStateListenerEvent(
1217 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1218 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001219 r.callback.onPreciseDataConnectionStateChanged(
1220 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001221 } catch (RemoteException ex) {
1222 mRemoveList.add(r.binder);
1223 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001224 }
1225 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001226 }
1227 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 }
Jack Yubaeec622017-05-01 17:01:11 -07001229 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001230 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001231 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1232 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 }
1234
Robert Greenwalt02648a42010-05-18 10:52:51 -07001235 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001236 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001237 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001238 }
1239
Wink Saville63f03dd2014-10-23 10:44:45 -07001240 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001241 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001242 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001243 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001244 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001245 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001246 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001247 + " reason=" + reason + " apnType=" + apnType);
1248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001250 mPreciseDataConnectionState = new PreciseDataConnectionState(
1251 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1252 apnType, "", reason, null, "");
1253 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001254 if (r.matchPhoneStateListenerEvent(
1255 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001256 try {
1257 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1258 } catch (RemoteException ex) {
1259 mRemoveList.add(r.binder);
1260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 }
1262 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001263 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001265 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001266 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1267 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 }
1269
1270 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001271 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001272 }
1273
Wink Saville63f03dd2014-10-23 10:44:45 -07001274 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001275 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001276 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001277 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001278 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001279 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001280 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001281 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001282 + " cellLocation=" + cellLocation);
1283 }
yifan.baie620ce72017-12-22 14:59:57 +08001284 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001286 if (validatePhoneId(phoneId)) {
1287 mCellLocation[phoneId] = cellLocation;
1288 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001289 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001290 idMatch(r.subId, subId, phoneId) &&
1291 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001292 try {
1293 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001294 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001295 + " r=" + r);
1296 }
1297 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1298 } catch (RemoteException ex) {
1299 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001300 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001301 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 }
1303 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001304 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001305 }
1306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307
Wink Savillefd2d0132010-10-28 14:22:26 -07001308 public void notifyOtaspChanged(int otaspMode) {
1309 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1310 return;
1311 }
1312 synchronized (mRecords) {
1313 mOtaspMode = otaspMode;
1314 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001315 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001316 try {
1317 r.callback.onOtaspChanged(otaspMode);
1318 } catch (RemoteException ex) {
1319 mRemoveList.add(r.binder);
1320 }
1321 }
1322 }
1323 handleRemoveListLocked();
1324 }
1325 }
1326
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001327 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1328 int backgroundCallState) {
1329 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1330 return;
1331 }
1332 synchronized (mRecords) {
1333 mRingingCallState = ringingCallState;
1334 mForegroundCallState = foregroundCallState;
1335 mBackgroundCallState = backgroundCallState;
1336 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1337 backgroundCallState,
1338 DisconnectCause.NOT_VALID,
1339 PreciseDisconnectCause.NOT_VALID);
1340 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001341 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001342 try {
1343 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1344 } catch (RemoteException ex) {
1345 mRemoveList.add(r.binder);
1346 }
1347 }
1348 }
1349 handleRemoveListLocked();
1350 }
1351 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1352 DisconnectCause.NOT_VALID,
1353 PreciseDisconnectCause.NOT_VALID);
1354 }
1355
1356 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1357 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1358 return;
1359 }
1360 synchronized (mRecords) {
1361 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1362 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1363 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001364 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001365 try {
1366 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1367 } catch (RemoteException ex) {
1368 mRemoveList.add(r.binder);
1369 }
1370 }
1371 }
1372 handleRemoveListLocked();
1373 }
1374 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1375 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1376 }
1377
1378 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1379 String apn, String failCause) {
1380 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1381 return;
1382 }
1383 synchronized (mRecords) {
1384 mPreciseDataConnectionState = new PreciseDataConnectionState(
1385 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1386 apnType, apn, reason, null, failCause);
1387 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001388 if (r.matchPhoneStateListenerEvent(
1389 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001390 try {
1391 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1392 } catch (RemoteException ex) {
1393 mRemoveList.add(r.binder);
1394 }
1395 }
1396 }
1397 handleRemoveListLocked();
1398 }
1399 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1400 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1401 }
1402
Wink Savillefb40dd42014-06-12 17:02:31 -07001403 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1404 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1405 return;
1406 }
1407 synchronized (mRecords) {
1408 mVoLteServiceState = lteState;
1409 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001410 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001411 try {
1412 r.callback.onVoLteServiceStateChanged(
1413 new VoLteServiceState(mVoLteServiceState));
1414 } catch (RemoteException ex) {
1415 mRemoveList.add(r.binder);
1416 }
1417 }
1418 }
1419 handleRemoveListLocked();
1420 }
1421 }
1422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001424 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1425 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1426
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001427 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001430 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001432 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301433 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001434 pw.println("Phone Id=" + i);
1435 pw.increaseIndent();
1436 pw.println("mCallState=" + mCallState[i]);
1437 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1438 pw.println("mServiceState=" + mServiceState[i]);
1439 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1440 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001441 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001442 pw.println("mSignalStrength=" + mSignalStrength[i]);
1443 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1444 pw.println("mCallForwarding=" + mCallForwarding[i]);
1445 pw.println("mDataActivity=" + mDataActivity[i]);
1446 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001447 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1448 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301449 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001450 pw.println("mCellLocation=" + mCellLocation[i]);
1451 pw.println("mCellInfo=" + mCellInfo.get(i));
1452 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301453 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001454 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1455 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1456 pw.println("mPreciseCallState=" + mPreciseCallState);
1457 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1458 pw.println("mRingingCallState=" + mRingingCallState);
1459 pw.println("mForegroundCallState=" + mForegroundCallState);
1460 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1461 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1462
1463 pw.decreaseIndent();
1464
1465 pw.println("local logs:");
1466 pw.increaseIndent();
1467 mLocalLog.dump(fd, pw, args);
1468 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001469 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001470 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001471 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001472 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001474 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 }
1476 }
1477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 //
1479 // the legacy intent broadcasting
1480 //
1481
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001482 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001483 long ident = Binder.clearCallingIdentity();
1484 try {
1485 mBatteryStats.notePhoneState(state.getState());
1486 } catch (RemoteException re) {
1487 // Can't do much
1488 } finally {
1489 Binder.restoreCallingIdentity(ident);
1490 }
1491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001493 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 Bundle data = new Bundle();
1495 state.fillInNotifierBundle(data);
1496 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001497 // Pass the subscription along with the intent.
1498 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001499 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001500 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 }
1502
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001503 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1504 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001505 long ident = Binder.clearCallingIdentity();
1506 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001507 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001508 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001509 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001510 } finally {
1511 Binder.restoreCallingIdentity(ident);
1512 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001515 Bundle data = new Bundle();
1516 signalStrength.fillInNotifierBundle(data);
1517 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001518 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001519 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001520 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 }
1522
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001523 /**
1524 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1525 * a valid subId, in which case this function fires a subId-specific intent, or it
1526 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1527 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1528 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001529 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1530 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 long ident = Binder.clearCallingIdentity();
1532 try {
1533 if (state == TelephonyManager.CALL_STATE_IDLE) {
1534 mBatteryStats.notePhoneOff();
1535 } else {
1536 mBatteryStats.notePhoneOn();
1537 }
1538 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001539 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 } finally {
1541 Binder.restoreCallingIdentity(ident);
1542 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001545 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001546 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 if (!TextUtils.isEmpty(incomingNumber)) {
1548 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1549 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001550
1551 // If a valid subId was specified, we should fire off a subId-specific state
1552 // change intent and include the subId.
1553 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1554 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1555 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1556 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001557 // If the phoneId is invalid, the broadcast is for overall call state.
1558 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1559 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1560 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001561
Brad Ebinger51de96a2017-04-21 17:05:18 -07001562 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1563 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1564
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001565 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1566 // that have the runtime one
1567 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1568 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001569 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001570 android.Manifest.permission.READ_PHONE_STATE,
1571 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 }
1573
Robert Greenwalt42acef32009-08-12 16:08:25 -07001574 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001575 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001576 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001577 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001578 // Note: not reporting to the battery stats service here, because the
1579 // status bar takes care of that after taking into account all of the
1580 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001582 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001583 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001584 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001585 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 }
1587 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001588 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001590 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001591 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001592 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001593 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001594 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001595 }
1596 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001597 if (networkCapabilities != null) {
1598 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001599 }
Wink Savillea639b312012-07-10 12:37:54 -07001600 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001601
Wink Savillea639b312012-07-10 12:37:54 -07001602 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1603 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001604 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001605 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 }
1607
Wink Savillefb40dd42014-06-12 17:02:31 -07001608 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001609 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001611 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1612 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001613 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001614 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001616
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001617 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1618 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1619 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1620 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1621 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1622 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1623 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1624 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1625 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1626 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1627 }
1628
1629 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001630 String apnType, String apn, String reason, LinkProperties linkProperties,
1631 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001632 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1633 intent.putExtra(PhoneConstants.STATE_KEY, state);
1634 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1635 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1636 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1637 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001638 if (linkProperties != null) {
1639 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1640 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001641 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1642
1643 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1644 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1645 }
1646
Andrew Flynnceaed682015-06-09 12:36:58 +00001647 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001648 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001649 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001650 }
1651
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001652 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1653 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001654 }
1655
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001656 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001657 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001658 return true;
1659 }
1660 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001661 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001662 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001663 return false;
1664 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001665
Andrew Flynn1f452642015-04-14 22:16:04 -04001666 private boolean checkNotifyPermission() {
1667 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1668 == PackageManager.PERMISSION_GRANTED;
1669 }
1670
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001671 private boolean checkListenerPermission(int events, String callingPackage, String message) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001672 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1673 mContext.enforceCallingOrSelfPermission(
1674 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1675
1676 }
1677
John Wang963db55d2012-03-30 16:04:06 -07001678 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1679 mContext.enforceCallingOrSelfPermission(
1680 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1681
1682 }
1683
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001684 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1686 mContext, callingPackage, message)) {
1687 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001688 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001689 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001690
1691 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1692 mContext.enforceCallingOrSelfPermission(
1693 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001694 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001695
1696 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001697 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001698
1699 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001700 int size = mRemoveList.size();
1701 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1702 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001703 for (IBinder b: mRemoveList) {
1704 remove(b);
1705 }
1706 mRemoveList.clear();
1707 }
1708 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001709
1710 private boolean validateEventsAndUserLocked(Record r, int events) {
1711 int foregroundUser;
1712 long callingIdentity = Binder.clearCallingIdentity();
1713 boolean valid = false;
1714 try {
1715 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001716 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1717 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001718 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001719 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001720 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001721 + " r.events=" + r.events + " events=" + events);
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(callingIdentity);
1725 }
1726 return valid;
1727 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001728
1729 private boolean validatePhoneId(int phoneId) {
1730 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001731 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001732 return valid;
1733 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001734
1735 private static void log(String s) {
1736 Rlog.d(TAG, s);
1737 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001738
xinhe8b79fb62014-11-05 14:55:03 -08001739 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001740
1741 if(subId < 0) {
1742 // Invalid case, we need compare phoneId with default one.
1743 return (mDefaultPhoneId == phoneId);
1744 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001745 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001746 return (subId == mDefaultSubId);
1747 } else {
1748 return (rSubId == subId);
1749 }
1750 }
1751
Hall Liu5fb337f2017-11-22 17:38:15 -08001752 private boolean checkLocationAccess(Record r) {
1753 long token = Binder.clearCallingIdentity();
1754 try {
1755 return LocationAccessPolicy.canAccessCellLocation(mContext,
1756 r.callingPackage, r.callerUid, r.callerPid);
1757 } finally {
1758 Binder.restoreCallingIdentity(token);
1759 }
1760 }
1761
xinhee9f16402014-09-25 16:39:28 -07001762 private void checkPossibleMissNotify(Record r, int phoneId) {
1763 int events = r.events;
1764
1765 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1766 try {
1767 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1768 mServiceState[phoneId]);
1769 r.callback.onServiceStateChanged(
1770 new ServiceState(mServiceState[phoneId]));
1771 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001772 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001773 }
1774 }
1775
1776 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1777 try {
1778 SignalStrength signalStrength = mSignalStrength[phoneId];
1779 if (DBG) {
1780 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1781 }
1782 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1783 } catch (RemoteException ex) {
1784 mRemoveList.add(r.binder);
1785 }
1786 }
1787
1788 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1789 try {
1790 int gsmSignalStrength = mSignalStrength[phoneId]
1791 .getGsmSignalStrength();
1792 if (DBG) {
1793 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1794 gsmSignalStrength);
1795 }
1796 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1797 : gsmSignalStrength));
1798 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001799 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001800 }
1801 }
1802
1803 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1804 try {
1805 if (DBG_LOC) {
1806 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1807 + mCellInfo.get(phoneId));
1808 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001809 if (checkLocationAccess(r)) {
1810 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1811 }
xinhee9f16402014-09-25 16:39:28 -07001812 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001813 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001814 }
1815 }
1816
zxuan35a47022018-01-04 11:24:04 -08001817 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1818 try {
1819 if (VDBG) {
1820 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1821 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1822 }
1823 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1824 } catch (RemoteException ex) {
1825 mRemoveList.add(r.binder);
1826 }
1827 }
1828
xinhee9f16402014-09-25 16:39:28 -07001829 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1830 try {
1831 if (VDBG) {
1832 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1833 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1834 }
1835 r.callback.onMessageWaitingIndicatorChanged(
1836 mMessageWaiting[phoneId]);
1837 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001838 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001839 }
1840 }
1841
1842 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1843 try {
1844 if (VDBG) {
1845 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1846 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1847 }
1848 r.callback.onCallForwardingIndicatorChanged(
1849 mCallForwarding[phoneId]);
1850 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001851 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001852 }
1853 }
1854
1855 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1856 try {
1857 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1858 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001859 if (checkLocationAccess(r)) {
1860 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1861 }
xinhee9f16402014-09-25 16:39:28 -07001862 } catch (RemoteException ex) {
1863 mRemoveList.add(r.binder);
1864 }
1865 }
1866
1867 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1868 try {
1869 if (DBG) {
1870 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1871 + "=" + mDataConnectionState[phoneId]
1872 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1873 + ")");
1874 }
1875 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1876 mDataConnectionNetworkType[phoneId]);
1877 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001878 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001879 }
1880 }
1881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882}