blob: 83fe97697194f25eade6f430220fbf3e8e7a0478 [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;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080040import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020041import android.telephony.PreciseCallState;
42import android.telephony.PreciseDataConnectionState;
43import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070044import android.telephony.Rlog;
45import android.telephony.ServiceState;
46import android.telephony.SignalStrength;
47import android.telephony.SubscriptionManager;
48import android.telephony.TelephonyManager;
49import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080054import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070056import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080057import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070058import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080060import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060061import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070062import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.server.am.BatteryStatsService;
64
Jack Yud19b6ae2017-04-05 14:12:09 -070065import java.io.FileDescriptor;
66import java.io.PrintWriter;
67import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070068import 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 {
Jeff Davidson29da89f2018-02-28 17:50:16 -080092 Context context;
93
Svet Ganov16a16892015-04-16 10:32:04 -070094 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
Malcolm Chenabbfac22018-02-12 19:15:59 -080098 TelephonyRegistryDeathRecipient deathRecipient;
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800101 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700102
Hall Liu5fb337f2017-11-22 17:38:15 -0800103 int callerUid;
104 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700107
Wink Savilled09c4ca2014-11-22 10:08:16 -0800108 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700109
Wink Savilled09c4ca2014-11-22 10:08:16 -0800110 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800111
112 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
Jeff Davidson29da89f2018-02-28 17:50:16 -0800120 boolean canReadPhoneState() {
121 try {
122 return TelephonyPermissions.checkReadPhoneState(
123 context, subId, callerPid, callerUid, callingPackage, "listen");
124 } catch (SecurityException e) {
125 return false;
126 }
127 }
128
Wink Savillea12a7b32012-09-20 10:09:45 -0700129 @Override
130 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700131 return "{callingPackage=" + callingPackage + " binder=" + binder
132 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800133 + " onSubscriptionsChangedListenererCallback="
134 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800135 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800136 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
139
140 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Joe Onorato163d8d92010-10-21 13:21:20 -0400142 // access should be inside synchronized (mRecords) for these two fields
143 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
144 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 private final IBatteryStats mBatteryStats;
147
Svet Ganov16a16892015-04-16 10:32:04 -0700148 private final AppOpsManager mAppOps;
149
Wink Savilled09c4ca2014-11-22 10:08:16 -0800150 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
fionaxu12312f62016-11-14 13:32:14 -0800160 private int[] mVoiceActivationState;
161
162 private int[] mDataActivationState;
163
zxuan35a47022018-01-04 11:24:04 -0800164 private boolean[] mUserMobileDataState;
165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Jack Yub1bac542018-03-14 16:23:38 -0700174 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700180
Nathan Harold016e9c62016-12-14 11:24:48 -0800181 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700182
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 private ArrayList<List<CellInfo>> mCellInfo = null;
184
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800185 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
186
Wink Savillefb40dd42014-06-12 17:02:31 -0700187 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
188
Wink Savilled09c4ca2014-11-22 10:08:16 -0800189 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700190
Wink Savilled09c4ca2014-11-22 10:08:16 -0800191 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700192
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200193 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
194
195 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
196
197 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
198
199 private PreciseCallState mPreciseCallState = new PreciseCallState();
200
Andrew Flynn1f452642015-04-14 22:16:04 -0400201 private boolean mCarrierNetworkChangeState = false;
202
Jack Yud19b6ae2017-04-05 14:12:09 -0700203 private final LocalLog mLocalLog = new LocalLog(100);
204
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200205 private PreciseDataConnectionState mPreciseDataConnectionState =
206 new PreciseDataConnectionState();
207
Hall Liu70bbc162018-03-02 17:44:46 -0800208 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
209 PhoneStateListener.LISTEN_CELL_LOCATION
210 | PhoneStateListener.LISTEN_CELL_INFO;
211
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700212 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700213 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700214 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
215 PhoneStateListener.LISTEN_VOLTE_STATE;
216
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200217 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
218 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
219 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
220
Wink Savillea12a7b32012-09-20 10:09:45 -0700221 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700222 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700223
224 private final Handler mHandler = new Handler() {
225 @Override
226 public void handleMessage(Message msg) {
227 switch (msg.what) {
228 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700229 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700230 int numPhones = TelephonyManager.getDefault().getPhoneCount();
231 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700232 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700233 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700234 }
235 break;
236 }
xinhee9f16402014-09-25 16:39:28 -0700237 case MSG_UPDATE_DEFAULT_SUB: {
238 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700239 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700240 if (VDBG) {
241 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
242 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
243 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
244 }
245
246 //Due to possible risk condition,(notify call back using the new
247 //defaultSubId comes before new defaultSubId update) we need to recall all
248 //possible missed notify callback
249 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700250 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800251 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700252 checkPossibleMissNotify(r, newDefaultPhoneId);
253 }
254 }
255 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700256 }
257 mDefaultSubId = newDefaultSubId;
258 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700259 }
260 }
261 }
262 };
263
Malcolm Chenabbfac22018-02-12 19:15:59 -0800264 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
265
266 private final IBinder binder;
267
268 TelephonyRegistryDeathRecipient(IBinder binder) {
269 this.binder = binder;
270 }
271
272 @Override
273 public void binderDied() {
274 if (DBG) log("binderDied " + binder);
275 remove(binder);
276 }
277 }
278
Wink Savillea12a7b32012-09-20 10:09:45 -0700279 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
280 @Override
281 public void onReceive(Context context, Intent intent) {
282 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700283 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700284 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700285 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700286 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700287 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700288 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700289 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800290 PhoneConstants.SUBSCRIPTION_KEY,
291 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700292 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
293 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700294 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700295 log("onReceive:current mDefaultSubId=" + mDefaultSubId
296 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
297 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700298 }
xinhee9f16402014-09-25 16:39:28 -0700299
Junda Liu985f52c2015-02-23 16:06:51 -0800300 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700301 || (newDefaultPhoneId != mDefaultPhoneId))) {
302 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
303 newDefaultPhoneId, 0, newDefaultSubIdObj));
304 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700305 }
306 }
307 };
308
Wink Savillee9b06d72009-05-18 21:47:50 -0700309 // we keep a copy of all of the state so we can send it out when folks
310 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700312 // In these calls we call with the lock held. This is safe becasuse remote
313 // calls go through a oneway interface and local calls going through a
314 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315
316 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700317 CellLocation location = CellLocation.getEmpty();
318
Wink Savillefb40dd42014-06-12 17:02:31 -0700319 mContext = context;
320 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700321
Wink Savillefb40dd42014-06-12 17:02:31 -0700322 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700323 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700324 mNumPhones = numPhones;
325 mCallState = new int[numPhones];
326 mDataActivity = new int[numPhones];
327 mDataConnectionState = new int[numPhones];
328 mDataConnectionNetworkType = new int[numPhones];
329 mCallIncomingNumber = new String[numPhones];
330 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800331 mVoiceActivationState = new int[numPhones];
332 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800333 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700334 mSignalStrength = new SignalStrength[numPhones];
335 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700336 mCallForwarding = new boolean[numPhones];
337 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700338 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800339 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700340 for (int i = 0; i < numPhones; i++) {
341 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
342 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
343 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800344 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
345 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700346 mCallIncomingNumber[i] = "";
347 mServiceState[i] = new ServiceState();
348 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800349 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700350 mMessageWaiting[i] = false;
351 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 mCellLocation[i] = new Bundle();
353 mCellInfo.add(i, null);
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800354 mPhysicalChannelConfigs.add(i, null);
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 }
356
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700357 // Note that location can be null for non-phone builds like
358 // like the generic one.
359 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700360 for (int i = 0; i < numPhones; i++) {
361 location.fillInNotifierBundle(mCellLocation[i]);
362 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700363 }
Svet Ganov16a16892015-04-16 10:32:04 -0700364
365 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367
Svetoslav Ganova0027152013-06-25 14:59:53 -0700368 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700369 // Watch for interesting updates
370 final IntentFilter filter = new IntentFilter();
371 filter.addAction(Intent.ACTION_USER_SWITCHED);
372 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700373 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700374 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700375 mContext.registerReceiver(mBroadcastReceiver, filter);
376 }
377
378 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700379 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800380 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700381 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800383 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700384 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
385 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800386 + " callback.asBinder=" + callback.asBinder());
387 }
388
Wink Savilled09c4ca2014-11-22 10:08:16 -0800389 synchronized (mRecords) {
390 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800391 IBinder b = callback.asBinder();
392 Record r = add(b);
393
394 if (r == null) {
395 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800396 }
397
Jeff Davidson29da89f2018-02-28 17:50:16 -0800398 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800399 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700400 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800401 r.callerUid = Binder.getCallingUid();
402 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 r.events = 0;
404 if (DBG) {
405 log("listen oscl: Register r=" + r);
406 }
407 // Always notify when registration occurs if there has been a notification.
408 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800409 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800410 if (VDBG) log("listen oscl: send to r=" + r);
411 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
412 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800413 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800415 remove(r.binder);
416 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800417 } else {
418 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 }
421 }
422
423 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800424 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800425 IOnSubscriptionsChangedListener callback) {
426 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800427 remove(callback.asBinder());
428 }
429
Wink Savillea374c3d2014-11-11 11:48:04 -0800430 @Override
431 public void notifySubscriptionInfoChanged() {
432 if (VDBG) log("notifySubscriptionInfoChanged:");
433 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800434 if (!hasNotifySubscriptionInfoChangedOccurred) {
435 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
436 + mRecords.size());
437 }
438 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800439 mRemoveList.clear();
440 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800441 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800442 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800443 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
444 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
445 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800446 } catch (RemoteException ex) {
447 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
448 mRemoveList.add(r.binder);
449 }
450 }
451 }
452 handleRemoveListLocked();
453 }
454 }
455
456 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
458 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800459 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
460 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700461 }
462
463 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700464 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700465 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700466 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700467 }
468
Svet Ganov16a16892015-04-16 10:32:04 -0700469 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700470 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700471 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700473 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700474 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700475 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
476 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700477 }
xinhe75c2c152014-10-16 11:49:45 -0700478
479 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800480 // Checks permission and throws SecurityException for disallowed operations. For pre-M
481 // apps whose runtime permission has been revoked, we return immediately to skip sending
482 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800483 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800484 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700485 }
486
yifan.baie620ce72017-12-22 14:59:57 +0800487 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 synchronized (mRecords) {
489 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800490 IBinder b = callback.asBinder();
491 Record r = add(b);
492
493 if (r == null) {
494 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 }
xinhe43c50292014-09-18 17:56:48 -0700496
Jeff Davidson29da89f2018-02-28 17:50:16 -0800497 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700498 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700499 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800500 r.callerUid = Binder.getCallingUid();
501 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700502 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
503 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800504 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800505 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700506 } else {//APP specify subID
507 r.subId = subId;
508 }
yifan.baie620ce72017-12-22 14:59:57 +0800509 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700511 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700512 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700513 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700514 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400516 try {
Wink Savillee380b982014-07-26 18:24:22 -0700517 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700518 r.callback.onServiceStateChanged(
519 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400520 } catch (RemoteException ex) {
521 remove(r.binder);
522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 }
524 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
525 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700526 int gsmSignalStrength = mSignalStrength[phoneId]
527 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700528 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
529 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 } catch (RemoteException ex) {
531 remove(r.binder);
532 }
533 }
534 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
535 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700536 r.callback.onMessageWaitingIndicatorChanged(
537 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 } catch (RemoteException ex) {
539 remove(r.binder);
540 }
541 }
542 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
543 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700544 r.callback.onCallForwardingIndicatorChanged(
545 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 } catch (RemoteException ex) {
547 remove(r.binder);
548 }
549 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700550 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400551 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700552 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700553 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800554 if (checkLocationAccess(r)) {
555 r.callback.onCellLocationChanged(
556 new Bundle(mCellLocation[phoneId]));
557 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400558 } catch (RemoteException ex) {
559 remove(r.binder);
560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 }
562 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
563 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700564 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700565 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 } catch (RemoteException ex) {
567 remove(r.binder);
568 }
569 }
570 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
571 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700572 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
573 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 } catch (RemoteException ex) {
575 remove(r.binder);
576 }
577 }
578 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
579 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700580 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 } catch (RemoteException ex) {
582 remove(r.binder);
583 }
584 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700585 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
586 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700588 } catch (RemoteException ex) {
589 remove(r.binder);
590 }
591 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700592 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
593 try {
594 r.callback.onOtaspChanged(mOtaspMode);
595 } catch (RemoteException ex) {
596 remove(r.binder);
597 }
598 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700599 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700600 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700601 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800603 if (checkLocationAccess(r)) {
604 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
605 }
John Wang963db55d2012-03-30 16:04:06 -0700606 } catch (RemoteException ex) {
607 remove(r.binder);
608 }
609 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200610 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
611 try {
612 r.callback.onPreciseCallStateChanged(mPreciseCallState);
613 } catch (RemoteException ex) {
614 remove(r.binder);
615 }
616 }
617 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
618 try {
619 r.callback.onPreciseDataConnectionStateChanged(
620 mPreciseDataConnectionState);
621 } catch (RemoteException ex) {
622 remove(r.binder);
623 }
624 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400625 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
626 try {
627 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
628 } catch (RemoteException ex) {
629 remove(r.binder);
630 }
631 }
fionaxu12312f62016-11-14 13:32:14 -0800632 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
633 try {
634 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
635 } catch (RemoteException ex) {
636 remove(r.binder);
637 }
638 }
639 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
640 try {
641 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
642 } catch (RemoteException ex) {
643 remove(r.binder);
644 }
645 }
zxuan35a47022018-01-04 11:24:04 -0800646 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
647 try {
648 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
649 } catch (RemoteException ex) {
650 remove(r.binder);
651 }
652 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800653 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
654 try {
655 r.callback.onPhysicalChannelConfigurationChanged(
656 mPhysicalChannelConfigs.get(phoneId));
657 } catch (RemoteException ex) {
658 remove(r.binder);
659 }
660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 }
662 }
663 } else {
xinhe75c2c152014-10-16 11:49:45 -0700664 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 remove(callback.asBinder());
666 }
667 }
668
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700669 private String getCallIncomingNumber(Record record, int phoneId) {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800670 // Hide the number if record's process can't currently read phone state.
671 return record.canReadPhoneState() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700672 }
673
Malcolm Chenabbfac22018-02-12 19:15:59 -0800674 private Record add(IBinder binder) {
675 Record r;
676
677 synchronized (mRecords) {
678 final int N = mRecords.size();
679 for (int i = 0; i < N; i++) {
680 r = mRecords.get(i);
681 if (binder == r.binder) {
682 // Already existed.
683 return r;
684 }
685 }
686 r = new Record();
687 r.binder = binder;
688 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
689
690 try {
691 binder.linkToDeath(r.deathRecipient, 0);
692 } catch (RemoteException e) {
693 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
694 // Binder already died. Return null.
695 return null;
696 }
697
698 mRecords.add(r);
699 if (DBG) log("add new record");
700 }
701
702 return r;
703 }
704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 private void remove(IBinder binder) {
706 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700707 final int recordCount = mRecords.size();
708 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800709 Record r = mRecords.get(i);
710 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800711 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800712 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
713 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800714 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800715
716 if (r.deathRecipient != null) {
717 try {
718 binder.unlinkToDeath(r.deathRecipient, 0);
719 } catch (NoSuchElementException e) {
720 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
721 + r + " e=" + e);
722 }
723 }
724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 mRecords.remove(i);
726 return;
727 }
728 }
729 }
730 }
731
732 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700733 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700734 return;
735 }
xinhe43c50292014-09-18 17:56:48 -0700736
737 if (VDBG) {
738 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
739 }
740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700742 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800743 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800744 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 try {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800746 String incomingNumberOrEmpty = r.canReadPhoneState() ? incomingNumber : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700747 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400749 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
751 }
752 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400753 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700755
756 // Called only by Telecomm to communicate call state across different phone accounts. So
757 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800758 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700759 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700760 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700763 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
764 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700765 if (!checkNotifyPermission("notifyCallState()")) {
766 return;
767 }
Wink Savillee380b982014-07-26 18:24:22 -0700768 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700769 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700770 + " state=" + state + " incomingNumber=" + incomingNumber);
771 }
772 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700773 if (validatePhoneId(phoneId)) {
774 mCallState[phoneId] = state;
775 mCallIncomingNumber[phoneId] = incomingNumber;
776 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800777 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700778 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800779 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700781 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
782 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700783 } catch (RemoteException ex) {
784 mRemoveList.add(r.binder);
785 }
786 }
787 }
788 }
789 handleRemoveListLocked();
790 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700791 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700792 }
793
Wink Saville63f03dd2014-10-23 10:44:45 -0700794 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700795 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700796 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700797 }
xinhe43c50292014-09-18 17:56:48 -0700798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700800 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
801 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700802 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700803 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700804 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700805 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700806 if (validatePhoneId(phoneId)) {
807 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700808
Wink Savillefb40dd42014-06-12 17:02:31 -0700809 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700810 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700811 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700812 + " phoneId=" + phoneId + " state=" + state);
813 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800814 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800815 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700816 try {
Wink Savillee380b982014-07-26 18:24:22 -0700817 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700818 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700819 + " subId=" + subId + " phoneId=" + phoneId
820 + " state=" + state);
821 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700822 r.callback.onServiceStateChanged(new ServiceState(state));
823 } catch (RemoteException ex) {
824 mRemoveList.add(r.binder);
825 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700828 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700829 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400831 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700833 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
835
fionaxu12312f62016-11-14 13:32:14 -0800836 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
837 int activationType, int activationState) {
838 if (!checkNotifyPermission("notifySimActivationState()")){
839 return;
840 }
841 if (VDBG) {
842 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
843 + "type=" + activationType + " state=" + activationState);
844 }
845 synchronized (mRecords) {
846 if (validatePhoneId(phoneId)) {
847 switch (activationType) {
848 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
849 mVoiceActivationState[phoneId] = activationState;
850 break;
851 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
852 mDataActivationState[phoneId] = activationState;
853 break;
854 default:
855 return;
856 }
857 for (Record r : mRecords) {
858 if (VDBG) {
859 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
860 + " phoneId=" + phoneId + "type=" + activationType
861 + " state=" + activationState);
862 }
863 try {
864 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
865 r.matchPhoneStateListenerEvent(
866 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
867 idMatch(r.subId, subId, phoneId)) {
868 if (DBG) {
869 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
870 + " subId=" + subId + " phoneId=" + phoneId
871 + " state=" + activationState);
872 }
873 r.callback.onVoiceActivationStateChanged(activationState);
874 }
875 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
876 r.matchPhoneStateListenerEvent(
877 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
878 idMatch(r.subId, subId, phoneId)) {
879 if (DBG) {
880 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
881 + " subId=" + subId + " phoneId=" + phoneId
882 + " state=" + activationState);
883 }
884 r.callback.onDataActivationStateChanged(activationState);
885 }
886 } catch (RemoteException ex) {
887 mRemoveList.add(r.binder);
888 }
889 }
890 } else {
891 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
892 }
893 handleRemoveListLocked();
894 }
895 }
896
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700897 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
898 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700899 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700900 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700901 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000902 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700903 log("notifySignalStrengthForPhoneId: subId=" + subId
904 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000905 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700908 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700909 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700910 mSignalStrength[phoneId] = signalStrength;
911 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000912 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700913 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000914 + " phoneId=" + phoneId + " ss=" + signalStrength);
915 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800916 if (r.matchPhoneStateListenerEvent(
917 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800918 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700919 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000920 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700921 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000922 + " subId=" + subId + " phoneId=" + phoneId
923 + " ss=" + signalStrength);
924 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
926 } catch (RemoteException ex) {
927 mRemoveList.add(r.binder);
928 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400929 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800930 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800931 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700932 try {
933 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700934 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000935 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700936 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000937 + " subId=" + subId + " phoneId=" + phoneId
938 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
939 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700940 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700941 } catch (RemoteException ex) {
942 mRemoveList.add(r.binder);
943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 }
945 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700946 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700947 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400949 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700951 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 }
953
Andrew Flynn1f452642015-04-14 22:16:04 -0400954 @Override
955 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000956 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
957
Andrew Flynn1f452642015-04-14 22:16:04 -0400958 if (VDBG) {
959 log("notifyCarrierNetworkChange: active=" + active);
960 }
961
962 synchronized (mRecords) {
963 mCarrierNetworkChangeState = active;
964 for (Record r : mRecords) {
965 if (r.matchPhoneStateListenerEvent(
966 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
967 try {
968 r.callback.onCarrierNetworkChange(active);
969 } catch (RemoteException ex) {
970 mRemoveList.add(r.binder);
971 }
972 }
973 }
974 handleRemoveListLocked();
975 }
976 }
977
Wink Savilleb208a242012-07-25 14:08:09 -0700978 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800979 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700980 }
981
Wink Saville63f03dd2014-10-23 10:44:45 -0700982 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700983 if (!checkNotifyPermission("notifyCellInfo()")) {
984 return;
985 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700986 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700987 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700988 + " cellInfo=" + cellInfo);
989 }
yifan.baie620ce72017-12-22 14:59:57 +0800990 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -0700991 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700992 if (validatePhoneId(phoneId)) {
993 mCellInfo.set(phoneId, cellInfo);
994 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700995 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -0800996 idMatch(r.subId, subId, phoneId) &&
997 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700998 try {
999 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001000 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001001 }
1002 r.callback.onCellInfoChanged(cellInfo);
1003 } catch (RemoteException ex) {
1004 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001005 }
John Wang963db55d2012-03-30 16:04:06 -07001006 }
1007 }
1008 }
1009 handleRemoveListLocked();
1010 }
1011 }
1012
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001013 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1014 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1015 configs);
1016 }
1017
1018 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1019 List<PhysicalChannelConfig> configs) {
1020 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1021 return;
1022 }
1023
1024 if (VDBG) {
1025 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1026 }
1027
1028 synchronized (mRecords) {
1029 int phoneId = SubscriptionManager.getPhoneId(subId);
1030 if (validatePhoneId(phoneId)) {
1031 mPhysicalChannelConfigs.set(phoneId, configs);
1032 for (Record r : mRecords) {
1033 if (r.matchPhoneStateListenerEvent(
1034 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1035 && idMatch(r.subId, subId, phoneId)) {
1036 try {
1037 if (DBG_LOC) {
1038 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1039 + configs + " r=" + r);
1040 }
1041 r.callback.onPhysicalChannelConfigurationChanged(configs);
1042 } catch (RemoteException ex) {
1043 mRemoveList.add(r.binder);
1044 }
1045 }
1046 }
1047 }
1048 handleRemoveListLocked();
1049 }
1050 }
1051
xinhe43c50292014-09-18 17:56:48 -07001052 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001053 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001054 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001055 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001056 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001057 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001058 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001059 + " mwi=" + mwi);
1060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001062 if (validatePhoneId(phoneId)) {
1063 mMessageWaiting[phoneId] = mwi;
1064 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001065 if (r.matchPhoneStateListenerEvent(
1066 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001067 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001068 try {
1069 r.callback.onMessageWaitingIndicatorChanged(mwi);
1070 } catch (RemoteException ex) {
1071 mRemoveList.add(r.binder);
1072 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 }
1074 }
1075 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001076 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 }
1078 }
1079
zxuan35a47022018-01-04 11:24:04 -08001080 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1081 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1082 return;
1083 }
1084 if (VDBG) {
1085 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1086 + " state=" + state);
1087 }
1088 synchronized (mRecords) {
1089 if (validatePhoneId(phoneId)) {
1090 mMessageWaiting[phoneId] = state;
1091 for (Record r : mRecords) {
1092 if (r.matchPhoneStateListenerEvent(
1093 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1094 idMatch(r.subId, subId, phoneId)) {
1095 try {
1096 r.callback.onUserMobileDataStateChanged(state);
1097 } catch (RemoteException ex) {
1098 mRemoveList.add(r.binder);
1099 }
1100 }
1101 }
1102 }
1103 handleRemoveListLocked();
1104 }
1105 }
1106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001108 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001109 }
1110
Wink Saville63f03dd2014-10-23 10:44:45 -07001111 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001112 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001113 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001114 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001115 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001116 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001117 + " cfi=" + cfi);
1118 }
yifan.baie620ce72017-12-22 14:59:57 +08001119 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001121 if (validatePhoneId(phoneId)) {
1122 mCallForwarding[phoneId] = cfi;
1123 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001124 if (r.matchPhoneStateListenerEvent(
1125 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001126 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001127 try {
1128 r.callback.onCallForwardingIndicatorChanged(cfi);
1129 } catch (RemoteException ex) {
1130 mRemoveList.add(r.binder);
1131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133 }
1134 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001135 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 }
1137 }
1138
1139 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001140 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001141 }
1142
Wink Saville63f03dd2014-10-23 10:44:45 -07001143 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001144 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001145 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001146 }
yifan.baie620ce72017-12-22 14:59:57 +08001147 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001149 if (validatePhoneId(phoneId)) {
1150 mDataActivity[phoneId] = state;
1151 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001152 // Notify by correct subId.
1153 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1154 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001155 try {
1156 r.callback.onDataActivity(state);
1157 } catch (RemoteException ex) {
1158 mRemoveList.add(r.binder);
1159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 }
1161 }
1162 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001163 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 }
1165 }
1166
Jack Yubaeec622017-05-01 17:01:11 -07001167 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001168 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001169 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001170 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001171 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001172 networkCapabilities, networkType, roaming);
1173 }
1174
Wink Saville63f03dd2014-10-23 10:44:45 -07001175 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001176 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001177 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1178 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001179 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001180 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001181 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001182 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001183 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001184 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001185 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001186 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001187 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001188 }
yifan.baie620ce72017-12-22 14:59:57 +08001189 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001191 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001192 // We only call the callback when the change is for default APN type.
1193 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1194 && (mDataConnectionState[phoneId] != state
1195 || mDataConnectionNetworkType[phoneId] != networkType)) {
1196 String str = "onDataConnectionStateChanged(" + state
1197 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001198 log(str);
1199 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001200 for (Record r : mRecords) {
1201 if (r.matchPhoneStateListenerEvent(
1202 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1203 idMatch(r.subId, subId, phoneId)) {
1204 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001205 if (DBG) {
1206 log("Notify data connection state changed on sub: " + subId);
1207 }
Jack Yub1bac542018-03-14 16:23:38 -07001208 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001209 } catch (RemoteException ex) {
1210 mRemoveList.add(r.binder);
1211 }
1212 }
1213 }
1214 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001215
1216 mDataConnectionState[phoneId] = state;
1217 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001218 }
1219 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1220 apnType, apn, reason, linkProperties, "");
1221 for (Record r : mRecords) {
1222 if (r.matchPhoneStateListenerEvent(
1223 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1224 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001225 r.callback.onPreciseDataConnectionStateChanged(
1226 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001227 } catch (RemoteException ex) {
1228 mRemoveList.add(r.binder);
1229 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001230 }
1231 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001232 }
1233 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 }
Jack Yubaeec622017-05-01 17:01:11 -07001235 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001236 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001237 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1238 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 }
1240
Robert Greenwalt02648a42010-05-18 10:52:51 -07001241 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001242 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001243 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001244 }
1245
Wink Saville63f03dd2014-10-23 10:44:45 -07001246 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001247 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001248 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001249 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001250 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001251 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001252 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001253 + " reason=" + reason + " apnType=" + apnType);
1254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001256 mPreciseDataConnectionState = new PreciseDataConnectionState(
1257 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1258 apnType, "", reason, null, "");
1259 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001260 if (r.matchPhoneStateListenerEvent(
1261 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001262 try {
1263 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1264 } catch (RemoteException ex) {
1265 mRemoveList.add(r.binder);
1266 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 }
1268 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001269 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001271 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001272 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1273 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 }
1275
1276 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001277 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001278 }
1279
Wink Saville63f03dd2014-10-23 10:44:45 -07001280 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001281 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001282 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001283 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001284 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001285 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001286 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001287 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001288 + " cellLocation=" + cellLocation);
1289 }
yifan.baie620ce72017-12-22 14:59:57 +08001290 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001292 if (validatePhoneId(phoneId)) {
1293 mCellLocation[phoneId] = cellLocation;
1294 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001295 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001296 idMatch(r.subId, subId, phoneId) &&
1297 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001298 try {
1299 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001300 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001301 + " r=" + r);
1302 }
1303 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1304 } catch (RemoteException ex) {
1305 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001306 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 }
1309 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001310 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001311 }
1312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313
Wink Savillefd2d0132010-10-28 14:22:26 -07001314 public void notifyOtaspChanged(int otaspMode) {
1315 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1316 return;
1317 }
1318 synchronized (mRecords) {
1319 mOtaspMode = otaspMode;
1320 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001321 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001322 try {
1323 r.callback.onOtaspChanged(otaspMode);
1324 } catch (RemoteException ex) {
1325 mRemoveList.add(r.binder);
1326 }
1327 }
1328 }
1329 handleRemoveListLocked();
1330 }
1331 }
1332
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001333 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1334 int backgroundCallState) {
1335 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1336 return;
1337 }
1338 synchronized (mRecords) {
1339 mRingingCallState = ringingCallState;
1340 mForegroundCallState = foregroundCallState;
1341 mBackgroundCallState = backgroundCallState;
1342 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1343 backgroundCallState,
1344 DisconnectCause.NOT_VALID,
1345 PreciseDisconnectCause.NOT_VALID);
1346 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001347 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001348 try {
1349 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1350 } catch (RemoteException ex) {
1351 mRemoveList.add(r.binder);
1352 }
1353 }
1354 }
1355 handleRemoveListLocked();
1356 }
1357 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1358 DisconnectCause.NOT_VALID,
1359 PreciseDisconnectCause.NOT_VALID);
1360 }
1361
1362 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1363 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1364 return;
1365 }
1366 synchronized (mRecords) {
1367 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1368 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1369 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001370 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001371 try {
1372 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1373 } catch (RemoteException ex) {
1374 mRemoveList.add(r.binder);
1375 }
1376 }
1377 }
1378 handleRemoveListLocked();
1379 }
1380 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1381 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1382 }
1383
1384 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1385 String apn, String failCause) {
1386 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1387 return;
1388 }
1389 synchronized (mRecords) {
1390 mPreciseDataConnectionState = new PreciseDataConnectionState(
1391 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1392 apnType, apn, reason, null, failCause);
1393 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001394 if (r.matchPhoneStateListenerEvent(
1395 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001396 try {
1397 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1398 } catch (RemoteException ex) {
1399 mRemoveList.add(r.binder);
1400 }
1401 }
1402 }
1403 handleRemoveListLocked();
1404 }
1405 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1406 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1407 }
1408
Wink Savillefb40dd42014-06-12 17:02:31 -07001409 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1410 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1411 return;
1412 }
1413 synchronized (mRecords) {
1414 mVoLteServiceState = lteState;
1415 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001416 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001417 try {
1418 r.callback.onVoLteServiceStateChanged(
1419 new VoLteServiceState(mVoLteServiceState));
1420 } catch (RemoteException ex) {
1421 mRemoveList.add(r.binder);
1422 }
1423 }
1424 }
1425 handleRemoveListLocked();
1426 }
1427 }
1428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001430 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1431 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1432
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001433 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001436 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001438 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301439 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001440 pw.println("Phone Id=" + i);
1441 pw.increaseIndent();
1442 pw.println("mCallState=" + mCallState[i]);
1443 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1444 pw.println("mServiceState=" + mServiceState[i]);
1445 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1446 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001447 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001448 pw.println("mSignalStrength=" + mSignalStrength[i]);
1449 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1450 pw.println("mCallForwarding=" + mCallForwarding[i]);
1451 pw.println("mDataActivity=" + mDataActivity[i]);
1452 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001453 pw.println("mCellLocation=" + mCellLocation[i]);
1454 pw.println("mCellInfo=" + mCellInfo.get(i));
1455 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301456 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001457 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1458 pw.println("mPreciseCallState=" + mPreciseCallState);
1459 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1460 pw.println("mRingingCallState=" + mRingingCallState);
1461 pw.println("mForegroundCallState=" + mForegroundCallState);
1462 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1463 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1464
1465 pw.decreaseIndent();
1466
1467 pw.println("local logs:");
1468 pw.increaseIndent();
1469 mLocalLog.dump(fd, pw, args);
1470 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001471 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001472 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001473 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001474 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001476 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 }
1478 }
1479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 //
1481 // the legacy intent broadcasting
1482 //
1483
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001484 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001485 long ident = Binder.clearCallingIdentity();
1486 try {
1487 mBatteryStats.notePhoneState(state.getState());
1488 } catch (RemoteException re) {
1489 // Can't do much
1490 } finally {
1491 Binder.restoreCallingIdentity(ident);
1492 }
1493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001495 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 Bundle data = new Bundle();
1497 state.fillInNotifierBundle(data);
1498 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001499 // Pass the subscription along with the intent.
1500 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001501 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001502 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 }
1504
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001505 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1506 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001507 long ident = Binder.clearCallingIdentity();
1508 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001509 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001510 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001511 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001512 } finally {
1513 Binder.restoreCallingIdentity(ident);
1514 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001517 Bundle data = new Bundle();
1518 signalStrength.fillInNotifierBundle(data);
1519 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001520 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001521 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001522 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 }
1524
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001525 /**
1526 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1527 * a valid subId, in which case this function fires a subId-specific intent, or it
1528 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1529 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1530 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001531 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1532 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 long ident = Binder.clearCallingIdentity();
1534 try {
1535 if (state == TelephonyManager.CALL_STATE_IDLE) {
1536 mBatteryStats.notePhoneOff();
1537 } else {
1538 mBatteryStats.notePhoneOn();
1539 }
1540 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001541 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 } finally {
1543 Binder.restoreCallingIdentity(ident);
1544 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001547 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001548 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 if (!TextUtils.isEmpty(incomingNumber)) {
1550 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1551 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001552
1553 // If a valid subId was specified, we should fire off a subId-specific state
1554 // change intent and include the subId.
1555 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1556 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1557 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1558 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001559 // If the phoneId is invalid, the broadcast is for overall call state.
1560 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1561 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1562 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001563
Brad Ebinger51de96a2017-04-21 17:05:18 -07001564 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1565 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1566
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001567 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1568 // that have the runtime one
1569 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1570 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001571 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001572 android.Manifest.permission.READ_PHONE_STATE,
1573 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 }
1575
Robert Greenwalt42acef32009-08-12 16:08:25 -07001576 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001577 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001578 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001579 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001580 // Note: not reporting to the battery stats service here, because the
1581 // status bar takes care of that after taking into account all of the
1582 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001584 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001585 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001586 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001587 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 }
1589 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001590 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001592 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001593 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001594 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001595 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001596 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001597 }
1598 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001599 if (networkCapabilities != null) {
1600 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001601 }
Wink Savillea639b312012-07-10 12:37:54 -07001602 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001603
Wink Savillea639b312012-07-10 12:37:54 -07001604 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1605 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001606 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001607 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 }
1609
Wink Savillefb40dd42014-06-12 17:02:31 -07001610 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001611 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001613 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1614 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001615 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001616 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001618
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001619 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1620 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1621 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1622 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1623 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1624 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1625 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1626 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1627 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1628 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1629 }
1630
1631 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001632 String apnType, String apn, String reason, LinkProperties linkProperties,
1633 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001634 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1635 intent.putExtra(PhoneConstants.STATE_KEY, state);
1636 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1637 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1638 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1639 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001640 if (linkProperties != null) {
1641 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1642 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001643 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1644
1645 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1646 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1647 }
1648
Andrew Flynnceaed682015-06-09 12:36:58 +00001649 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001650 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001651 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001652 }
1653
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001654 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1655 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001656 }
1657
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001658 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001659 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001660 return true;
1661 }
1662 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001663 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001664 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001665 return false;
1666 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001667
Andrew Flynn1f452642015-04-14 22:16:04 -04001668 private boolean checkNotifyPermission() {
1669 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1670 == PackageManager.PERMISSION_GRANTED;
1671 }
1672
Jeff Davidson29da89f2018-02-28 17:50:16 -08001673 private boolean checkListenerPermission(
1674 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001675 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001676 mContext.enforceCallingOrSelfPermission(
1677 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001678 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1679 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1680 return false;
1681 }
John Wang963db55d2012-03-30 16:04:06 -07001682 }
1683
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001684 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1686 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001687 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,
Svet Ganov33b15092018-03-07 19:53:43 -08001756 r.callingPackage, r.callerUid, r.callerPid,
1757 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001758 } finally {
1759 Binder.restoreCallingIdentity(token);
1760 }
1761 }
1762
xinhee9f16402014-09-25 16:39:28 -07001763 private void checkPossibleMissNotify(Record r, int phoneId) {
1764 int events = r.events;
1765
1766 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1767 try {
1768 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1769 mServiceState[phoneId]);
1770 r.callback.onServiceStateChanged(
1771 new ServiceState(mServiceState[phoneId]));
1772 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001773 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001774 }
1775 }
1776
1777 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1778 try {
1779 SignalStrength signalStrength = mSignalStrength[phoneId];
1780 if (DBG) {
1781 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1782 }
1783 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1784 } catch (RemoteException ex) {
1785 mRemoveList.add(r.binder);
1786 }
1787 }
1788
1789 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1790 try {
1791 int gsmSignalStrength = mSignalStrength[phoneId]
1792 .getGsmSignalStrength();
1793 if (DBG) {
1794 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1795 gsmSignalStrength);
1796 }
1797 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1798 : gsmSignalStrength));
1799 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001800 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001801 }
1802 }
1803
1804 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1805 try {
1806 if (DBG_LOC) {
1807 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1808 + mCellInfo.get(phoneId));
1809 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001810 if (checkLocationAccess(r)) {
1811 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1812 }
xinhee9f16402014-09-25 16:39:28 -07001813 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001814 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001815 }
1816 }
1817
zxuan35a47022018-01-04 11:24:04 -08001818 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1819 try {
1820 if (VDBG) {
1821 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1822 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1823 }
1824 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1825 } catch (RemoteException ex) {
1826 mRemoveList.add(r.binder);
1827 }
1828 }
1829
xinhee9f16402014-09-25 16:39:28 -07001830 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1831 try {
1832 if (VDBG) {
1833 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1834 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1835 }
1836 r.callback.onMessageWaitingIndicatorChanged(
1837 mMessageWaiting[phoneId]);
1838 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001839 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001840 }
1841 }
1842
1843 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1844 try {
1845 if (VDBG) {
1846 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1847 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1848 }
1849 r.callback.onCallForwardingIndicatorChanged(
1850 mCallForwarding[phoneId]);
1851 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001852 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001853 }
1854 }
1855
1856 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1857 try {
1858 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1859 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001860 if (checkLocationAccess(r)) {
1861 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1862 }
xinhee9f16402014-09-25 16:39:28 -07001863 } catch (RemoteException ex) {
1864 mRemoveList.add(r.binder);
1865 }
1866 }
1867
1868 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1869 try {
1870 if (DBG) {
1871 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1872 + "=" + mDataConnectionState[phoneId]
1873 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1874 + ")");
1875 }
1876 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1877 mDataConnectionNetworkType[phoneId]);
1878 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001879 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001880 }
1881 }
1882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883}