blob: 38968712f4c898b55bb48d9b69538ed36ca9b64d [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 {
Svet Ganov16a16892015-04-16 10:32:04 -070092 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
Malcolm Chenabbfac22018-02-12 19:15:59 -080096 TelephonyRegistryDeathRecipient deathRecipient;
97
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080099 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
Hall Liu5fb337f2017-11-22 17:38:15 -0800101 int callerUid;
102 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700105
Wink Savilled09c4ca2014-11-22 10:08:16 -0800106 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700107
Wink Savilled09c4ca2014-11-22 10:08:16 -0800108 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800109
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700110 boolean canReadPhoneState;
111
Wink Savillea374c3d2014-11-11 11:48:04 -0800112 boolean matchPhoneStateListenerEvent(int events) {
113 return (callback != null) && ((events & this.events) != 0);
114 }
115
Wink Savilled09c4ca2014-11-22 10:08:16 -0800116 boolean matchOnSubscriptionsChangedListener() {
117 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800118 }
Wink Savillee380b982014-07-26 18:24:22 -0700119
Wink Savillea12a7b32012-09-20 10:09:45 -0700120 @Override
121 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700122 return "{callingPackage=" + callingPackage + " binder=" + binder
123 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800124 + " onSubscriptionsChangedListenererCallback="
125 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800126 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700127 + " events=" + Integer.toHexString(events)
128 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 }
131
132 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700133
Joe Onorato163d8d92010-10-21 13:21:20 -0400134 // access should be inside synchronized (mRecords) for these two fields
135 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
136 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 private final IBatteryStats mBatteryStats;
139
Svet Ganov16a16892015-04-16 10:32:04 -0700140 private final AppOpsManager mAppOps;
141
Wink Savilled09c4ca2014-11-22 10:08:16 -0800142 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
Wink Savillefb40dd42014-06-12 17:02:31 -0700146 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
Wink Savillefb40dd42014-06-12 17:02:31 -0700148 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
fionaxu12312f62016-11-14 13:32:14 -0800152 private int[] mVoiceActivationState;
153
154 private int[] mDataActivationState;
155
zxuan35a47022018-01-04 11:24:04 -0800156 private boolean[] mUserMobileDataState;
157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700165
Jack Yub1bac542018-03-14 16:23:38 -0700166 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700168
Wink Savillefb40dd42014-06-12 17:02:31 -0700169 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170
Wink Savillefb40dd42014-06-12 17:02:31 -0700171 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700172
Nathan Harold016e9c62016-12-14 11:24:48 -0800173 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700174
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private ArrayList<List<CellInfo>> mCellInfo = null;
176
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800177 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
180
Wink Savilled09c4ca2014-11-22 10:08:16 -0800181 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700182
Wink Savilled09c4ca2014-11-22 10:08:16 -0800183 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700184
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200185 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
186
187 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
188
189 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
190
191 private PreciseCallState mPreciseCallState = new PreciseCallState();
192
Andrew Flynn1f452642015-04-14 22:16:04 -0400193 private boolean mCarrierNetworkChangeState = false;
194
Jack Yud19b6ae2017-04-05 14:12:09 -0700195 private final LocalLog mLocalLog = new LocalLog(100);
196
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200197 private PreciseDataConnectionState mPreciseDataConnectionState =
198 new PreciseDataConnectionState();
199
Hall Liu70bbc162018-03-02 17:44:46 -0800200 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
201 PhoneStateListener.LISTEN_CELL_LOCATION
202 | PhoneStateListener.LISTEN_CELL_INFO;
203
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700204 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700205 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700206 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
207 PhoneStateListener.LISTEN_VOLTE_STATE;
208
209 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700210 PhoneStateListener.LISTEN_CALL_STATE |
211 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700212 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700213
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200214 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
215 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
216 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
217
Wink Savillea12a7b32012-09-20 10:09:45 -0700218 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700219 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700220
221 private final Handler mHandler = new Handler() {
222 @Override
223 public void handleMessage(Message msg) {
224 switch (msg.what) {
225 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700226 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700227 int numPhones = TelephonyManager.getDefault().getPhoneCount();
228 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700229 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700230 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700231 }
232 break;
233 }
xinhee9f16402014-09-25 16:39:28 -0700234 case MSG_UPDATE_DEFAULT_SUB: {
235 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700236 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700237 if (VDBG) {
238 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
239 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
240 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
241 }
242
243 //Due to possible risk condition,(notify call back using the new
244 //defaultSubId comes before new defaultSubId update) we need to recall all
245 //possible missed notify callback
246 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700247 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800248 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700249 checkPossibleMissNotify(r, newDefaultPhoneId);
250 }
251 }
252 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700253 }
254 mDefaultSubId = newDefaultSubId;
255 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700256 }
257 }
258 }
259 };
260
Malcolm Chenabbfac22018-02-12 19:15:59 -0800261 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
262
263 private final IBinder binder;
264
265 TelephonyRegistryDeathRecipient(IBinder binder) {
266 this.binder = binder;
267 }
268
269 @Override
270 public void binderDied() {
271 if (DBG) log("binderDied " + binder);
272 remove(binder);
273 }
274 }
275
Wink Savillea12a7b32012-09-20 10:09:45 -0700276 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
277 @Override
278 public void onReceive(Context context, Intent intent) {
279 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700280 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700281 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700282 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700283 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700284 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700285 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700286 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800287 PhoneConstants.SUBSCRIPTION_KEY,
288 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700289 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
290 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700291 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700292 log("onReceive:current mDefaultSubId=" + mDefaultSubId
293 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
294 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700295 }
xinhee9f16402014-09-25 16:39:28 -0700296
Junda Liu985f52c2015-02-23 16:06:51 -0800297 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700298 || (newDefaultPhoneId != mDefaultPhoneId))) {
299 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
300 newDefaultPhoneId, 0, newDefaultSubIdObj));
301 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700302 }
303 }
304 };
305
Wink Savillee9b06d72009-05-18 21:47:50 -0700306 // we keep a copy of all of the state so we can send it out when folks
307 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700309 // In these calls we call with the lock held. This is safe becasuse remote
310 // calls go through a oneway interface and local calls going through a
311 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312
313 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700314 CellLocation location = CellLocation.getEmpty();
315
Wink Savillefb40dd42014-06-12 17:02:31 -0700316 mContext = context;
317 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700318
Wink Savillefb40dd42014-06-12 17:02:31 -0700319 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700320 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700321 mNumPhones = numPhones;
322 mCallState = new int[numPhones];
323 mDataActivity = new int[numPhones];
324 mDataConnectionState = new int[numPhones];
325 mDataConnectionNetworkType = new int[numPhones];
326 mCallIncomingNumber = new String[numPhones];
327 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800328 mVoiceActivationState = new int[numPhones];
329 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800330 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700331 mSignalStrength = new SignalStrength[numPhones];
332 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 mCallForwarding = new boolean[numPhones];
334 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800336 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700337 for (int i = 0; i < numPhones; i++) {
338 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
339 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
340 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800341 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
342 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700343 mCallIncomingNumber[i] = "";
344 mServiceState[i] = new ServiceState();
345 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800346 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700347 mMessageWaiting[i] = false;
348 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700349 mCellLocation[i] = new Bundle();
350 mCellInfo.add(i, null);
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800351 mPhysicalChannelConfigs.add(i, null);
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 }
353
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700354 // Note that location can be null for non-phone builds like
355 // like the generic one.
356 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700357 for (int i = 0; i < numPhones; i++) {
358 location.fillInNotifierBundle(mCellLocation[i]);
359 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700360 }
Svet Ganov16a16892015-04-16 10:32:04 -0700361
362 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364
Svetoslav Ganova0027152013-06-25 14:59:53 -0700365 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700366 // Watch for interesting updates
367 final IntentFilter filter = new IntentFilter();
368 filter.addAction(Intent.ACTION_USER_SWITCHED);
369 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700370 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700371 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700372 mContext.registerReceiver(mBroadcastReceiver, filter);
373 }
374
375 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700376 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800377 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700378 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800379 mContext.getSystemService(AppOpsManager.class)
380 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800381 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700382 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
383 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800384 + " callback.asBinder=" + callback.asBinder());
385 }
386
Jeff Davidson3c0415a2018-02-23 15:27:46 -0800387 // TODO(b/70041899): Find a way to make this work for carrier-privileged callers.
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson3c0415a2018-02-23 15:27:46 -0800389 mContext, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
390 "addOnSubscriptionsChangedListener")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800391 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700392 }
393
Wink Savillea374c3d2014-11-11 11:48:04 -0800394
Wink Savilled09c4ca2014-11-22 10:08:16 -0800395 synchronized (mRecords) {
396 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800397 IBinder b = callback.asBinder();
398 Record r = add(b);
399
400 if (r == null) {
401 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800402 }
403
Wink Savilled09c4ca2014-11-22 10:08:16 -0800404 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700405 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800406 r.callerUid = Binder.getCallingUid();
407 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800408 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700409 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800410 if (DBG) {
411 log("listen oscl: Register r=" + r);
412 }
413 // Always notify when registration occurs if there has been a notification.
414 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800415 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800416 if (VDBG) log("listen oscl: send to r=" + r);
417 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
418 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800420 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800421 remove(r.binder);
422 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800423 } else {
424 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800426 }
427 }
428
429 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800430 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800431 IOnSubscriptionsChangedListener callback) {
432 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800433 remove(callback.asBinder());
434 }
435
Wink Savillea374c3d2014-11-11 11:48:04 -0800436 @Override
437 public void notifySubscriptionInfoChanged() {
438 if (VDBG) log("notifySubscriptionInfoChanged:");
439 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800440 if (!hasNotifySubscriptionInfoChangedOccurred) {
441 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
442 + mRecords.size());
443 }
444 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800445 mRemoveList.clear();
446 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800447 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800448 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800449 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
450 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
451 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800452 } catch (RemoteException ex) {
453 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
454 mRemoveList.add(r.binder);
455 }
456 }
457 }
458 handleRemoveListLocked();
459 }
460 }
461
462 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
464 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800465 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
466 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700467 }
468
469 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700470 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700471 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700472 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700473 }
474
Svet Ganov16a16892015-04-16 10:32:04 -0700475 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700476 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700477 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800478 mContext.getSystemService(AppOpsManager.class)
479 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700480 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700481 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700482 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
483 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700484 }
xinhe75c2c152014-10-16 11:49:45 -0700485
486 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800487 // Checks permission and throws SecurityException for disallowed operations. For pre-M
488 // apps whose runtime permission has been revoked, we return immediately to skip sending
489 // events to the app without crashing it.
490 if (!checkListenerPermission(events, callingPackage, "listen")) {
491 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700492 }
493
yifan.baie620ce72017-12-22 14:59:57 +0800494 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 synchronized (mRecords) {
496 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800497 IBinder b = callback.asBinder();
498 Record r = add(b);
499
500 if (r == null) {
501 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 }
xinhe43c50292014-09-18 17:56:48 -0700503
xinhe75c2c152014-10-16 11:49:45 -0700504 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700505 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800506 r.callerUid = Binder.getCallingUid();
507 r.callerPid = Binder.getCallingPid();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700508 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
509 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800510 r.canReadPhoneState =
511 isPhoneStateEvent && canReadPhoneState(callingPackage, "listen");
xinhe75c2c152014-10-16 11:49:45 -0700512 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
513 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800514 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800515 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700516 } else {//APP specify subID
517 r.subId = subId;
518 }
yifan.baie620ce72017-12-22 14:59:57 +0800519 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700521 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700522 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700523 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700524 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400526 try {
Wink Savillee380b982014-07-26 18:24:22 -0700527 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700528 r.callback.onServiceStateChanged(
529 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400530 } catch (RemoteException ex) {
531 remove(r.binder);
532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 }
534 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
535 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700536 int gsmSignalStrength = mSignalStrength[phoneId]
537 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700538 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
539 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 } catch (RemoteException ex) {
541 remove(r.binder);
542 }
543 }
544 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
545 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700546 r.callback.onMessageWaitingIndicatorChanged(
547 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 } catch (RemoteException ex) {
549 remove(r.binder);
550 }
551 }
552 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
553 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700554 r.callback.onCallForwardingIndicatorChanged(
555 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 } catch (RemoteException ex) {
557 remove(r.binder);
558 }
559 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700560 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400561 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700562 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700563 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800564 if (checkLocationAccess(r)) {
565 r.callback.onCellLocationChanged(
566 new Bundle(mCellLocation[phoneId]));
567 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400568 } catch (RemoteException ex) {
569 remove(r.binder);
570 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 }
572 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
573 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700574 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700575 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 } catch (RemoteException ex) {
577 remove(r.binder);
578 }
579 }
580 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
581 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
583 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 } catch (RemoteException ex) {
585 remove(r.binder);
586 }
587 }
588 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
589 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700590 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 } catch (RemoteException ex) {
592 remove(r.binder);
593 }
594 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700595 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
596 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700597 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700598 } catch (RemoteException ex) {
599 remove(r.binder);
600 }
601 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700602 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
603 try {
604 r.callback.onOtaspChanged(mOtaspMode);
605 } catch (RemoteException ex) {
606 remove(r.binder);
607 }
608 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700609 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700610 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700611 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700612 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800613 if (checkLocationAccess(r)) {
614 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
615 }
John Wang963db55d2012-03-30 16:04:06 -0700616 } catch (RemoteException ex) {
617 remove(r.binder);
618 }
619 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200620 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
621 try {
622 r.callback.onPreciseCallStateChanged(mPreciseCallState);
623 } catch (RemoteException ex) {
624 remove(r.binder);
625 }
626 }
627 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
628 try {
629 r.callback.onPreciseDataConnectionStateChanged(
630 mPreciseDataConnectionState);
631 } catch (RemoteException ex) {
632 remove(r.binder);
633 }
634 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400635 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
636 try {
637 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
638 } catch (RemoteException ex) {
639 remove(r.binder);
640 }
641 }
fionaxu12312f62016-11-14 13:32:14 -0800642 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
643 try {
644 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
645 } catch (RemoteException ex) {
646 remove(r.binder);
647 }
648 }
649 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
650 try {
651 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
652 } catch (RemoteException ex) {
653 remove(r.binder);
654 }
655 }
zxuan35a47022018-01-04 11:24:04 -0800656 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
657 try {
658 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
659 } catch (RemoteException ex) {
660 remove(r.binder);
661 }
662 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800663 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
664 try {
665 r.callback.onPhysicalChannelConfigurationChanged(
666 mPhysicalChannelConfigs.get(phoneId));
667 } catch (RemoteException ex) {
668 remove(r.binder);
669 }
670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 }
672 }
673 } else {
xinhe75c2c152014-10-16 11:49:45 -0700674 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 remove(callback.asBinder());
676 }
677 }
678
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800679 private boolean canReadPhoneState(String callingPackage, String message) {
680 try {
Jeff Davidson3c0415a2018-02-23 15:27:46 -0800681 // TODO(b/70041899): Find a way to make this work for carrier-privileged callers.
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800682 return TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson3c0415a2018-02-23 15:27:46 -0800683 mContext, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, message);
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800684 } catch (SecurityException e) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700685 return false;
686 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700687 }
688
689 private String getCallIncomingNumber(Record record, int phoneId) {
690 // Hide the number if record's process has no READ_PHONE_STATE permission
691 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
692 }
693
Malcolm Chenabbfac22018-02-12 19:15:59 -0800694 private Record add(IBinder binder) {
695 Record r;
696
697 synchronized (mRecords) {
698 final int N = mRecords.size();
699 for (int i = 0; i < N; i++) {
700 r = mRecords.get(i);
701 if (binder == r.binder) {
702 // Already existed.
703 return r;
704 }
705 }
706 r = new Record();
707 r.binder = binder;
708 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
709
710 try {
711 binder.linkToDeath(r.deathRecipient, 0);
712 } catch (RemoteException e) {
713 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
714 // Binder already died. Return null.
715 return null;
716 }
717
718 mRecords.add(r);
719 if (DBG) log("add new record");
720 }
721
722 return r;
723 }
724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 private void remove(IBinder binder) {
726 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700727 final int recordCount = mRecords.size();
728 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800729 Record r = mRecords.get(i);
730 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800731 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800732 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
733 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800734 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800735
736 if (r.deathRecipient != null) {
737 try {
738 binder.unlinkToDeath(r.deathRecipient, 0);
739 } catch (NoSuchElementException e) {
740 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
741 + r + " e=" + e);
742 }
743 }
744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 mRecords.remove(i);
746 return;
747 }
748 }
749 }
750 }
751
752 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700753 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700754 return;
755 }
xinhe43c50292014-09-18 17:56:48 -0700756
757 if (VDBG) {
758 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
759 }
760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700762 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800763 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800764 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700766 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
767 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400769 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 }
771 }
772 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400773 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700775
776 // Called only by Telecomm to communicate call state across different phone accounts. So
777 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800778 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700779 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700780 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 }
782
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700783 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
784 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700785 if (!checkNotifyPermission("notifyCallState()")) {
786 return;
787 }
Wink Savillee380b982014-07-26 18:24:22 -0700788 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700789 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700790 + " state=" + state + " incomingNumber=" + incomingNumber);
791 }
792 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700793 if (validatePhoneId(phoneId)) {
794 mCallState[phoneId] = state;
795 mCallIncomingNumber[phoneId] = incomingNumber;
796 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800797 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700798 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800799 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700800 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700801 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
802 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700803 } catch (RemoteException ex) {
804 mRemoveList.add(r.binder);
805 }
806 }
807 }
808 }
809 handleRemoveListLocked();
810 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700811 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700812 }
813
Wink Saville63f03dd2014-10-23 10:44:45 -0700814 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700815 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700816 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700817 }
xinhe43c50292014-09-18 17:56:48 -0700818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700820 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
821 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700822 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700823 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700824 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700825 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700826 if (validatePhoneId(phoneId)) {
827 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700828
Wink Savillefb40dd42014-06-12 17:02:31 -0700829 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700830 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700831 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700832 + " phoneId=" + phoneId + " state=" + state);
833 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800834 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800835 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700836 try {
Wink Savillee380b982014-07-26 18:24:22 -0700837 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700838 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700839 + " subId=" + subId + " phoneId=" + phoneId
840 + " state=" + state);
841 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700842 r.callback.onServiceStateChanged(new ServiceState(state));
843 } catch (RemoteException ex) {
844 mRemoveList.add(r.binder);
845 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700848 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700849 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400851 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700853 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
855
fionaxu12312f62016-11-14 13:32:14 -0800856 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
857 int activationType, int activationState) {
858 if (!checkNotifyPermission("notifySimActivationState()")){
859 return;
860 }
861 if (VDBG) {
862 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
863 + "type=" + activationType + " state=" + activationState);
864 }
865 synchronized (mRecords) {
866 if (validatePhoneId(phoneId)) {
867 switch (activationType) {
868 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
869 mVoiceActivationState[phoneId] = activationState;
870 break;
871 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
872 mDataActivationState[phoneId] = activationState;
873 break;
874 default:
875 return;
876 }
877 for (Record r : mRecords) {
878 if (VDBG) {
879 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
880 + " phoneId=" + phoneId + "type=" + activationType
881 + " state=" + activationState);
882 }
883 try {
884 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
885 r.matchPhoneStateListenerEvent(
886 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
887 idMatch(r.subId, subId, phoneId)) {
888 if (DBG) {
889 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
890 + " subId=" + subId + " phoneId=" + phoneId
891 + " state=" + activationState);
892 }
893 r.callback.onVoiceActivationStateChanged(activationState);
894 }
895 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
896 r.matchPhoneStateListenerEvent(
897 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
898 idMatch(r.subId, subId, phoneId)) {
899 if (DBG) {
900 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
901 + " subId=" + subId + " phoneId=" + phoneId
902 + " state=" + activationState);
903 }
904 r.callback.onDataActivationStateChanged(activationState);
905 }
906 } catch (RemoteException ex) {
907 mRemoveList.add(r.binder);
908 }
909 }
910 } else {
911 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
912 }
913 handleRemoveListLocked();
914 }
915 }
916
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700917 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
918 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700919 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700920 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700921 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000922 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700923 log("notifySignalStrengthForPhoneId: subId=" + subId
924 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000925 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700928 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700929 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700930 mSignalStrength[phoneId] = signalStrength;
931 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000932 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700933 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000934 + " phoneId=" + phoneId + " ss=" + signalStrength);
935 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800936 if (r.matchPhoneStateListenerEvent(
937 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800938 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700939 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000940 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700941 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000942 + " subId=" + subId + " phoneId=" + phoneId
943 + " ss=" + signalStrength);
944 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700945 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
946 } catch (RemoteException ex) {
947 mRemoveList.add(r.binder);
948 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400949 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800950 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800951 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700952 try {
953 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700954 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000955 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700956 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000957 + " subId=" + subId + " phoneId=" + phoneId
958 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
959 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700960 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700961 } catch (RemoteException ex) {
962 mRemoveList.add(r.binder);
963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 }
965 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700966 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700967 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400969 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700971 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 }
973
Andrew Flynn1f452642015-04-14 22:16:04 -0400974 @Override
975 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000976 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
977
Andrew Flynn1f452642015-04-14 22:16:04 -0400978 if (VDBG) {
979 log("notifyCarrierNetworkChange: active=" + active);
980 }
981
982 synchronized (mRecords) {
983 mCarrierNetworkChangeState = active;
984 for (Record r : mRecords) {
985 if (r.matchPhoneStateListenerEvent(
986 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
987 try {
988 r.callback.onCarrierNetworkChange(active);
989 } catch (RemoteException ex) {
990 mRemoveList.add(r.binder);
991 }
992 }
993 }
994 handleRemoveListLocked();
995 }
996 }
997
Wink Savilleb208a242012-07-25 14:08:09 -0700998 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800999 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001000 }
1001
Wink Saville63f03dd2014-10-23 10:44:45 -07001002 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001003 if (!checkNotifyPermission("notifyCellInfo()")) {
1004 return;
1005 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001006 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001007 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001008 + " cellInfo=" + cellInfo);
1009 }
yifan.baie620ce72017-12-22 14:59:57 +08001010 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001011 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 if (validatePhoneId(phoneId)) {
1013 mCellInfo.set(phoneId, cellInfo);
1014 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001015 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001016 idMatch(r.subId, subId, phoneId) &&
1017 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001018 try {
1019 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001020 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001021 }
1022 r.callback.onCellInfoChanged(cellInfo);
1023 } catch (RemoteException ex) {
1024 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001025 }
John Wang963db55d2012-03-30 16:04:06 -07001026 }
1027 }
1028 }
1029 handleRemoveListLocked();
1030 }
1031 }
1032
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001033 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1034 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1035 configs);
1036 }
1037
1038 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1039 List<PhysicalChannelConfig> configs) {
1040 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1041 return;
1042 }
1043
1044 if (VDBG) {
1045 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1046 }
1047
1048 synchronized (mRecords) {
1049 int phoneId = SubscriptionManager.getPhoneId(subId);
1050 if (validatePhoneId(phoneId)) {
1051 mPhysicalChannelConfigs.set(phoneId, configs);
1052 for (Record r : mRecords) {
1053 if (r.matchPhoneStateListenerEvent(
1054 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1055 && idMatch(r.subId, subId, phoneId)) {
1056 try {
1057 if (DBG_LOC) {
1058 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1059 + configs + " r=" + r);
1060 }
1061 r.callback.onPhysicalChannelConfigurationChanged(configs);
1062 } catch (RemoteException ex) {
1063 mRemoveList.add(r.binder);
1064 }
1065 }
1066 }
1067 }
1068 handleRemoveListLocked();
1069 }
1070 }
1071
xinhe43c50292014-09-18 17:56:48 -07001072 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001073 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001074 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001075 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001076 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001077 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001078 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001079 + " mwi=" + mwi);
1080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001082 if (validatePhoneId(phoneId)) {
1083 mMessageWaiting[phoneId] = mwi;
1084 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001085 if (r.matchPhoneStateListenerEvent(
1086 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001087 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001088 try {
1089 r.callback.onMessageWaitingIndicatorChanged(mwi);
1090 } catch (RemoteException ex) {
1091 mRemoveList.add(r.binder);
1092 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 }
1094 }
1095 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001096 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
1098 }
1099
zxuan35a47022018-01-04 11:24:04 -08001100 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1101 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1102 return;
1103 }
1104 if (VDBG) {
1105 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1106 + " state=" + state);
1107 }
1108 synchronized (mRecords) {
1109 if (validatePhoneId(phoneId)) {
1110 mMessageWaiting[phoneId] = state;
1111 for (Record r : mRecords) {
1112 if (r.matchPhoneStateListenerEvent(
1113 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1114 idMatch(r.subId, subId, phoneId)) {
1115 try {
1116 r.callback.onUserMobileDataStateChanged(state);
1117 } catch (RemoteException ex) {
1118 mRemoveList.add(r.binder);
1119 }
1120 }
1121 }
1122 }
1123 handleRemoveListLocked();
1124 }
1125 }
1126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001128 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001129 }
1130
Wink Saville63f03dd2014-10-23 10:44:45 -07001131 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001132 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001133 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001134 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001135 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001136 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001137 + " cfi=" + cfi);
1138 }
yifan.baie620ce72017-12-22 14:59:57 +08001139 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001141 if (validatePhoneId(phoneId)) {
1142 mCallForwarding[phoneId] = cfi;
1143 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001144 if (r.matchPhoneStateListenerEvent(
1145 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001146 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001147 try {
1148 r.callback.onCallForwardingIndicatorChanged(cfi);
1149 } catch (RemoteException ex) {
1150 mRemoveList.add(r.binder);
1151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 }
1153 }
1154 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001155 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 }
1157 }
1158
1159 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001160 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001161 }
1162
Wink Saville63f03dd2014-10-23 10:44:45 -07001163 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001164 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001165 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001166 }
yifan.baie620ce72017-12-22 14:59:57 +08001167 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001169 if (validatePhoneId(phoneId)) {
1170 mDataActivity[phoneId] = state;
1171 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001172 // Notify by correct subId.
1173 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1174 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001175 try {
1176 r.callback.onDataActivity(state);
1177 } catch (RemoteException ex) {
1178 mRemoveList.add(r.binder);
1179 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 }
1181 }
1182 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001183 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 }
1185 }
1186
Jack Yubaeec622017-05-01 17:01:11 -07001187 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001188 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001189 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001190 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001191 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001192 networkCapabilities, networkType, roaming);
1193 }
1194
Wink Saville63f03dd2014-10-23 10:44:45 -07001195 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001196 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001197 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1198 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001199 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001200 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001201 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001202 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001203 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001204 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001205 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001206 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001207 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001208 }
yifan.baie620ce72017-12-22 14:59:57 +08001209 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001211 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001212 // We only call the callback when the change is for default APN type.
1213 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1214 && (mDataConnectionState[phoneId] != state
1215 || mDataConnectionNetworkType[phoneId] != networkType)) {
1216 String str = "onDataConnectionStateChanged(" + state
1217 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001218 log(str);
1219 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001220 for (Record r : mRecords) {
1221 if (r.matchPhoneStateListenerEvent(
1222 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1223 idMatch(r.subId, subId, phoneId)) {
1224 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001225 if (DBG) {
1226 log("Notify data connection state changed on sub: " + subId);
1227 }
Jack Yub1bac542018-03-14 16:23:38 -07001228 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001229 } catch (RemoteException ex) {
1230 mRemoveList.add(r.binder);
1231 }
1232 }
1233 }
1234 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001235
1236 mDataConnectionState[phoneId] = state;
1237 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001238 }
1239 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1240 apnType, apn, reason, linkProperties, "");
1241 for (Record r : mRecords) {
1242 if (r.matchPhoneStateListenerEvent(
1243 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1244 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001245 r.callback.onPreciseDataConnectionStateChanged(
1246 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001247 } catch (RemoteException ex) {
1248 mRemoveList.add(r.binder);
1249 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001250 }
1251 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001252 }
1253 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 }
Jack Yubaeec622017-05-01 17:01:11 -07001255 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001256 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001257 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1258 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 }
1260
Robert Greenwalt02648a42010-05-18 10:52:51 -07001261 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001262 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001263 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001264 }
1265
Wink Saville63f03dd2014-10-23 10:44:45 -07001266 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001267 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001268 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001269 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001270 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001271 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001272 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001273 + " reason=" + reason + " apnType=" + apnType);
1274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001276 mPreciseDataConnectionState = new PreciseDataConnectionState(
1277 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1278 apnType, "", reason, null, "");
1279 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001280 if (r.matchPhoneStateListenerEvent(
1281 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001282 try {
1283 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1284 } catch (RemoteException ex) {
1285 mRemoveList.add(r.binder);
1286 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 }
1288 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001289 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001291 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001292 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1293 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 }
1295
1296 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001297 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001298 }
1299
Wink Saville63f03dd2014-10-23 10:44:45 -07001300 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001301 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001302 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001303 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001304 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001305 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001306 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001307 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001308 + " cellLocation=" + cellLocation);
1309 }
yifan.baie620ce72017-12-22 14:59:57 +08001310 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001312 if (validatePhoneId(phoneId)) {
1313 mCellLocation[phoneId] = cellLocation;
1314 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001315 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001316 idMatch(r.subId, subId, phoneId) &&
1317 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001318 try {
1319 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001320 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001321 + " r=" + r);
1322 }
1323 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1324 } catch (RemoteException ex) {
1325 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001326 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001327 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 }
1329 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001330 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001331 }
1332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333
Wink Savillefd2d0132010-10-28 14:22:26 -07001334 public void notifyOtaspChanged(int otaspMode) {
1335 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1336 return;
1337 }
1338 synchronized (mRecords) {
1339 mOtaspMode = otaspMode;
1340 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001341 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001342 try {
1343 r.callback.onOtaspChanged(otaspMode);
1344 } catch (RemoteException ex) {
1345 mRemoveList.add(r.binder);
1346 }
1347 }
1348 }
1349 handleRemoveListLocked();
1350 }
1351 }
1352
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001353 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1354 int backgroundCallState) {
1355 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1356 return;
1357 }
1358 synchronized (mRecords) {
1359 mRingingCallState = ringingCallState;
1360 mForegroundCallState = foregroundCallState;
1361 mBackgroundCallState = backgroundCallState;
1362 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1363 backgroundCallState,
1364 DisconnectCause.NOT_VALID,
1365 PreciseDisconnectCause.NOT_VALID);
1366 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001367 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001368 try {
1369 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1370 } catch (RemoteException ex) {
1371 mRemoveList.add(r.binder);
1372 }
1373 }
1374 }
1375 handleRemoveListLocked();
1376 }
1377 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1378 DisconnectCause.NOT_VALID,
1379 PreciseDisconnectCause.NOT_VALID);
1380 }
1381
1382 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1383 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1384 return;
1385 }
1386 synchronized (mRecords) {
1387 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1388 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1389 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001390 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001391 try {
1392 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1393 } catch (RemoteException ex) {
1394 mRemoveList.add(r.binder);
1395 }
1396 }
1397 }
1398 handleRemoveListLocked();
1399 }
1400 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1401 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1402 }
1403
1404 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1405 String apn, String failCause) {
1406 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1407 return;
1408 }
1409 synchronized (mRecords) {
1410 mPreciseDataConnectionState = new PreciseDataConnectionState(
1411 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1412 apnType, apn, reason, null, failCause);
1413 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001414 if (r.matchPhoneStateListenerEvent(
1415 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001416 try {
1417 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1418 } catch (RemoteException ex) {
1419 mRemoveList.add(r.binder);
1420 }
1421 }
1422 }
1423 handleRemoveListLocked();
1424 }
1425 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1426 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1427 }
1428
Wink Savillefb40dd42014-06-12 17:02:31 -07001429 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1430 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1431 return;
1432 }
1433 synchronized (mRecords) {
1434 mVoLteServiceState = lteState;
1435 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001436 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001437 try {
1438 r.callback.onVoLteServiceStateChanged(
1439 new VoLteServiceState(mVoLteServiceState));
1440 } catch (RemoteException ex) {
1441 mRemoveList.add(r.binder);
1442 }
1443 }
1444 }
1445 handleRemoveListLocked();
1446 }
1447 }
1448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001450 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1451 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1452
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001453 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001456 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001458 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301459 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001460 pw.println("Phone Id=" + i);
1461 pw.increaseIndent();
1462 pw.println("mCallState=" + mCallState[i]);
1463 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1464 pw.println("mServiceState=" + mServiceState[i]);
1465 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1466 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001467 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001468 pw.println("mSignalStrength=" + mSignalStrength[i]);
1469 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1470 pw.println("mCallForwarding=" + mCallForwarding[i]);
1471 pw.println("mDataActivity=" + mDataActivity[i]);
1472 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001473 pw.println("mCellLocation=" + mCellLocation[i]);
1474 pw.println("mCellInfo=" + mCellInfo.get(i));
1475 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301476 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001477 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1478 pw.println("mPreciseCallState=" + mPreciseCallState);
1479 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1480 pw.println("mRingingCallState=" + mRingingCallState);
1481 pw.println("mForegroundCallState=" + mForegroundCallState);
1482 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1483 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1484
1485 pw.decreaseIndent();
1486
1487 pw.println("local logs:");
1488 pw.increaseIndent();
1489 mLocalLog.dump(fd, pw, args);
1490 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001491 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001492 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001493 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001494 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001496 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 }
1498 }
1499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 //
1501 // the legacy intent broadcasting
1502 //
1503
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001504 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001505 long ident = Binder.clearCallingIdentity();
1506 try {
1507 mBatteryStats.notePhoneState(state.getState());
1508 } catch (RemoteException re) {
1509 // Can't do much
1510 } finally {
1511 Binder.restoreCallingIdentity(ident);
1512 }
1513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001515 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 Bundle data = new Bundle();
1517 state.fillInNotifierBundle(data);
1518 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001519 // Pass the subscription along with the intent.
1520 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
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001525 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1526 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001527 long ident = Binder.clearCallingIdentity();
1528 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001529 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001530 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001531 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001532 } finally {
1533 Binder.restoreCallingIdentity(ident);
1534 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001537 Bundle data = new Bundle();
1538 signalStrength.fillInNotifierBundle(data);
1539 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001540 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001541 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001542 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 }
1544
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001545 /**
1546 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1547 * a valid subId, in which case this function fires a subId-specific intent, or it
1548 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1549 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1550 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001551 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1552 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 long ident = Binder.clearCallingIdentity();
1554 try {
1555 if (state == TelephonyManager.CALL_STATE_IDLE) {
1556 mBatteryStats.notePhoneOff();
1557 } else {
1558 mBatteryStats.notePhoneOn();
1559 }
1560 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001561 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 } finally {
1563 Binder.restoreCallingIdentity(ident);
1564 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001567 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001568 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 if (!TextUtils.isEmpty(incomingNumber)) {
1570 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1571 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001572
1573 // If a valid subId was specified, we should fire off a subId-specific state
1574 // change intent and include the subId.
1575 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1576 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1577 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1578 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001579 // If the phoneId is invalid, the broadcast is for overall call state.
1580 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1581 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1582 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001583
Brad Ebinger51de96a2017-04-21 17:05:18 -07001584 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1585 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1586
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001587 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1588 // that have the runtime one
1589 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1590 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001591 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001592 android.Manifest.permission.READ_PHONE_STATE,
1593 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 }
1595
Robert Greenwalt42acef32009-08-12 16:08:25 -07001596 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001597 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001598 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001599 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001600 // Note: not reporting to the battery stats service here, because the
1601 // status bar takes care of that after taking into account all of the
1602 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001604 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001605 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001606 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001607 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 }
1609 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001610 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001612 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001613 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001614 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001615 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001616 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001617 }
1618 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001619 if (networkCapabilities != null) {
1620 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001621 }
Wink Savillea639b312012-07-10 12:37:54 -07001622 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001623
Wink Savillea639b312012-07-10 12:37:54 -07001624 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1625 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001626 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001627 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
1629
Wink Savillefb40dd42014-06-12 17:02:31 -07001630 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001631 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001633 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1634 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001635 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001636 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001638
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001639 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1640 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1641 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1642 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1643 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1644 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1645 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1646 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1647 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1648 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1649 }
1650
1651 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001652 String apnType, String apn, String reason, LinkProperties linkProperties,
1653 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001654 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1655 intent.putExtra(PhoneConstants.STATE_KEY, state);
1656 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1657 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1658 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1659 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001660 if (linkProperties != null) {
1661 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1662 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001663 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1664
1665 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1666 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1667 }
1668
Andrew Flynnceaed682015-06-09 12:36:58 +00001669 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001670 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001671 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001672 }
1673
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001674 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1675 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001676 }
1677
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001678 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001679 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001680 return true;
1681 }
1682 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001683 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001684 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001685 return false;
1686 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001687
Andrew Flynn1f452642015-04-14 22:16:04 -04001688 private boolean checkNotifyPermission() {
1689 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1690 == PackageManager.PERMISSION_GRANTED;
1691 }
1692
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001693 private boolean checkListenerPermission(int events, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001694 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001695 mContext.enforceCallingOrSelfPermission(
1696 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001697 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1698 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1699 return false;
1700 }
John Wang963db55d2012-03-30 16:04:06 -07001701 }
1702
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001703 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson3c0415a2018-02-23 15:27:46 -08001704 // TODO(b/70041899): Find a way to make this work for carrier-privileged callers.
1705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext,
1706 SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001707 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001708 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001709 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001710
1711 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1712 mContext.enforceCallingOrSelfPermission(
1713 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001714 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001715
1716 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001717 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001718
1719 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001720 int size = mRemoveList.size();
1721 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1722 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001723 for (IBinder b: mRemoveList) {
1724 remove(b);
1725 }
1726 mRemoveList.clear();
1727 }
1728 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001729
1730 private boolean validateEventsAndUserLocked(Record r, int events) {
1731 int foregroundUser;
1732 long callingIdentity = Binder.clearCallingIdentity();
1733 boolean valid = false;
1734 try {
1735 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001736 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1737 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001738 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001739 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001740 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001741 + " r.events=" + r.events + " events=" + events);
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(callingIdentity);
1745 }
1746 return valid;
1747 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001748
1749 private boolean validatePhoneId(int phoneId) {
1750 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001751 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001752 return valid;
1753 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001754
1755 private static void log(String s) {
1756 Rlog.d(TAG, s);
1757 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001758
xinhe8b79fb62014-11-05 14:55:03 -08001759 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001760
1761 if(subId < 0) {
1762 // Invalid case, we need compare phoneId with default one.
1763 return (mDefaultPhoneId == phoneId);
1764 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001765 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001766 return (subId == mDefaultSubId);
1767 } else {
1768 return (rSubId == subId);
1769 }
1770 }
1771
Hall Liu5fb337f2017-11-22 17:38:15 -08001772 private boolean checkLocationAccess(Record r) {
1773 long token = Binder.clearCallingIdentity();
1774 try {
1775 return LocationAccessPolicy.canAccessCellLocation(mContext,
1776 r.callingPackage, r.callerUid, r.callerPid);
1777 } finally {
1778 Binder.restoreCallingIdentity(token);
1779 }
1780 }
1781
xinhee9f16402014-09-25 16:39:28 -07001782 private void checkPossibleMissNotify(Record r, int phoneId) {
1783 int events = r.events;
1784
1785 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1786 try {
1787 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1788 mServiceState[phoneId]);
1789 r.callback.onServiceStateChanged(
1790 new ServiceState(mServiceState[phoneId]));
1791 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001792 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001793 }
1794 }
1795
1796 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1797 try {
1798 SignalStrength signalStrength = mSignalStrength[phoneId];
1799 if (DBG) {
1800 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1801 }
1802 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1803 } catch (RemoteException ex) {
1804 mRemoveList.add(r.binder);
1805 }
1806 }
1807
1808 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1809 try {
1810 int gsmSignalStrength = mSignalStrength[phoneId]
1811 .getGsmSignalStrength();
1812 if (DBG) {
1813 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1814 gsmSignalStrength);
1815 }
1816 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1817 : gsmSignalStrength));
1818 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001819 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001820 }
1821 }
1822
1823 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1824 try {
1825 if (DBG_LOC) {
1826 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1827 + mCellInfo.get(phoneId));
1828 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001829 if (checkLocationAccess(r)) {
1830 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1831 }
xinhee9f16402014-09-25 16:39:28 -07001832 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001833 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001834 }
1835 }
1836
zxuan35a47022018-01-04 11:24:04 -08001837 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1838 try {
1839 if (VDBG) {
1840 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1841 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1842 }
1843 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1844 } catch (RemoteException ex) {
1845 mRemoveList.add(r.binder);
1846 }
1847 }
1848
xinhee9f16402014-09-25 16:39:28 -07001849 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1850 try {
1851 if (VDBG) {
1852 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1853 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1854 }
1855 r.callback.onMessageWaitingIndicatorChanged(
1856 mMessageWaiting[phoneId]);
1857 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001858 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001859 }
1860 }
1861
1862 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1863 try {
1864 if (VDBG) {
1865 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1866 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1867 }
1868 r.callback.onCallForwardingIndicatorChanged(
1869 mCallForwarding[phoneId]);
1870 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001871 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001872 }
1873 }
1874
1875 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1876 try {
1877 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1878 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001879 if (checkLocationAccess(r)) {
1880 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1881 }
xinhee9f16402014-09-25 16:39:28 -07001882 } catch (RemoteException ex) {
1883 mRemoveList.add(r.binder);
1884 }
1885 }
1886
1887 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1888 try {
1889 if (DBG) {
1890 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1891 + "=" + mDataConnectionState[phoneId]
1892 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1893 + ")");
1894 }
1895 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1896 mDataConnectionNetworkType[phoneId]);
1897 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001898 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001899 }
1900 }
1901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001902}