blob: 607db4efb63ea97d9d68b33a2cef8a42cc34eee7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080038import android.telephony.LocationAccessPolicy;
Jack Yud19b6ae2017-04-05 14:12:09 -070039import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080040import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020041import android.telephony.PreciseCallState;
42import android.telephony.PreciseDataConnectionState;
43import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070044import android.telephony.Rlog;
45import android.telephony.ServiceState;
46import android.telephony.SignalStrength;
47import android.telephony.SubscriptionManager;
48import android.telephony.TelephonyManager;
49import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080054import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070056import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080057import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070058import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080060import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060061import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070062import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.server.am.BatteryStatsService;
64
Jack Yud19b6ae2017-04-05 14:12:09 -070065import java.io.FileDescriptor;
66import java.io.PrintWriter;
67import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070068import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080069import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071/**
Wink Savillee9b06d72009-05-18 21:47:50 -070072 * Since phone process can be restarted, this class provides a centralized place
73 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070074 *
75 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
76 * and 15973975 by saving the phoneId of the registrant and then using the
77 * phoneId when deciding to to make a callback. This is necessary because
78 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070079 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070080 * the dummy value conversion we properly do the callbacks.
81 *
82 * Eventually we may want to remove the notion of dummy value but for now this
83 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 */
85class TelephonyRegistry extends ITelephonyRegistry.Stub {
86 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070087 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070088 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070089 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080092 Context context;
93
Svet Ganov16a16892015-04-16 10:32:04 -070094 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
Malcolm Chenabbfac22018-02-12 19:15:59 -080098 TelephonyRegistryDeathRecipient deathRecipient;
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800101 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700102
Hall Liu5fb337f2017-11-22 17:38:15 -0800103 int callerUid;
104 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700107
Wink Savilled09c4ca2014-11-22 10:08:16 -0800108 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700109
Wink Savilled09c4ca2014-11-22 10:08:16 -0800110 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800111
112 boolean matchPhoneStateListenerEvent(int events) {
113 return (callback != null) && ((events & this.events) != 0);
114 }
115
Wink Savilled09c4ca2014-11-22 10:08:16 -0800116 boolean matchOnSubscriptionsChangedListener() {
117 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800118 }
Wink Savillee380b982014-07-26 18:24:22 -0700119
Tyler Gunnf955e562018-04-26 14:43:31 -0700120 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800121 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700122 return TelephonyPermissions.checkReadCallLog(
123 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800124 } catch (SecurityException e) {
125 return false;
126 }
127 }
128
Wink Savillea12a7b32012-09-20 10:09:45 -0700129 @Override
130 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700131 return "{callingPackage=" + callingPackage + " binder=" + binder
132 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800133 + " onSubscriptionsChangedListenererCallback="
134 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800135 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800136 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
139
140 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Joe Onorato163d8d92010-10-21 13:21:20 -0400142 // access should be inside synchronized (mRecords) for these two fields
143 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
144 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 private final IBatteryStats mBatteryStats;
147
Svet Ganov16a16892015-04-16 10:32:04 -0700148 private final AppOpsManager mAppOps;
149
Wink Savilled09c4ca2014-11-22 10:08:16 -0800150 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
fionaxu12312f62016-11-14 13:32:14 -0800160 private int[] mVoiceActivationState;
161
162 private int[] mDataActivationState;
163
zxuan35a47022018-01-04 11:24:04 -0800164 private boolean[] mUserMobileDataState;
165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Jack Yub1bac542018-03-14 16:23:38 -0700174 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700180
Nathan Harold016e9c62016-12-14 11:24:48 -0800181 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700182
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 private ArrayList<List<CellInfo>> mCellInfo = null;
184
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800185 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
186
Wink Savillefb40dd42014-06-12 17:02:31 -0700187 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
188
Wink Savilled09c4ca2014-11-22 10:08:16 -0800189 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700190
Wink Savilled09c4ca2014-11-22 10:08:16 -0800191 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700192
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200193 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
194
195 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
196
197 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
198
199 private PreciseCallState mPreciseCallState = new PreciseCallState();
200
Andrew Flynn1f452642015-04-14 22:16:04 -0400201 private boolean mCarrierNetworkChangeState = false;
202
Jack Yud19b6ae2017-04-05 14:12:09 -0700203 private final LocalLog mLocalLog = new LocalLog(100);
204
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200205 private PreciseDataConnectionState mPreciseDataConnectionState =
206 new PreciseDataConnectionState();
207
Hall Liu70bbc162018-03-02 17:44:46 -0800208 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
209 PhoneStateListener.LISTEN_CELL_LOCATION
210 | PhoneStateListener.LISTEN_CELL_INFO;
211
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700212 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700213 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700214 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
215 PhoneStateListener.LISTEN_VOLTE_STATE;
216
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200217 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
218 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
219 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
220
Wink Savillea12a7b32012-09-20 10:09:45 -0700221 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700222 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700223
224 private final Handler mHandler = new Handler() {
225 @Override
226 public void handleMessage(Message msg) {
227 switch (msg.what) {
228 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700229 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700230 int numPhones = TelephonyManager.getDefault().getPhoneCount();
231 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700232 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700233 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700234 }
235 break;
236 }
xinhee9f16402014-09-25 16:39:28 -0700237 case MSG_UPDATE_DEFAULT_SUB: {
238 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700239 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700240 if (VDBG) {
241 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
242 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
243 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
244 }
245
246 //Due to possible risk condition,(notify call back using the new
247 //defaultSubId comes before new defaultSubId update) we need to recall all
248 //possible missed notify callback
249 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700250 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800251 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700252 checkPossibleMissNotify(r, newDefaultPhoneId);
253 }
254 }
255 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700256 }
257 mDefaultSubId = newDefaultSubId;
258 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700259 }
260 }
261 }
262 };
263
Malcolm Chenabbfac22018-02-12 19:15:59 -0800264 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
265
266 private final IBinder binder;
267
268 TelephonyRegistryDeathRecipient(IBinder binder) {
269 this.binder = binder;
270 }
271
272 @Override
273 public void binderDied() {
274 if (DBG) log("binderDied " + binder);
275 remove(binder);
276 }
277 }
278
Wink Savillea12a7b32012-09-20 10:09:45 -0700279 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
280 @Override
281 public void onReceive(Context context, Intent intent) {
282 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700283 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700284 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700285 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700286 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700287 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700288 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700289 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800290 PhoneConstants.SUBSCRIPTION_KEY,
291 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700292 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
293 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700294 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700295 log("onReceive:current mDefaultSubId=" + mDefaultSubId
296 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
297 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700298 }
xinhee9f16402014-09-25 16:39:28 -0700299
Junda Liu985f52c2015-02-23 16:06:51 -0800300 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700301 || (newDefaultPhoneId != mDefaultPhoneId))) {
302 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
303 newDefaultPhoneId, 0, newDefaultSubIdObj));
304 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700305 }
306 }
307 };
308
Wink Savillee9b06d72009-05-18 21:47:50 -0700309 // we keep a copy of all of the state so we can send it out when folks
310 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700312 // In these calls we call with the lock held. This is safe becasuse remote
313 // calls go through a oneway interface and local calls going through a
314 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315
316 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700317 CellLocation location = CellLocation.getEmpty();
318
Wink Savillefb40dd42014-06-12 17:02:31 -0700319 mContext = context;
320 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700321
Wink Savillefb40dd42014-06-12 17:02:31 -0700322 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700323 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700324 mNumPhones = numPhones;
325 mCallState = new int[numPhones];
326 mDataActivity = new int[numPhones];
327 mDataConnectionState = new int[numPhones];
328 mDataConnectionNetworkType = new int[numPhones];
329 mCallIncomingNumber = new String[numPhones];
330 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800331 mVoiceActivationState = new int[numPhones];
332 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800333 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700334 mSignalStrength = new SignalStrength[numPhones];
335 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700336 mCallForwarding = new boolean[numPhones];
337 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700338 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800339 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700340 for (int i = 0; i < numPhones; i++) {
341 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
342 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
343 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800344 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
345 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700346 mCallIncomingNumber[i] = "";
347 mServiceState[i] = new ServiceState();
348 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800349 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700350 mMessageWaiting[i] = false;
351 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 mCellLocation[i] = new Bundle();
353 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700354 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 }
356
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700357 // Note that location can be null for non-phone builds like
358 // like the generic one.
359 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700360 for (int i = 0; i < numPhones; i++) {
361 location.fillInNotifierBundle(mCellLocation[i]);
362 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700363 }
Svet Ganov16a16892015-04-16 10:32:04 -0700364
365 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367
Svetoslav Ganova0027152013-06-25 14:59:53 -0700368 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700369 // Watch for interesting updates
370 final IntentFilter filter = new IntentFilter();
371 filter.addAction(Intent.ACTION_USER_SWITCHED);
372 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700373 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700374 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700375 mContext.registerReceiver(mBroadcastReceiver, filter);
376 }
377
378 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700379 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800380 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700381 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800383 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700384 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
385 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800386 + " callback.asBinder=" + callback.asBinder());
387 }
388
Wink Savilled09c4ca2014-11-22 10:08:16 -0800389 synchronized (mRecords) {
390 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800391 IBinder b = callback.asBinder();
392 Record r = add(b);
393
394 if (r == null) {
395 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800396 }
397
Jeff Davidson29da89f2018-02-28 17:50:16 -0800398 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800399 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700400 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800401 r.callerUid = Binder.getCallingUid();
402 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 r.events = 0;
404 if (DBG) {
405 log("listen oscl: Register r=" + r);
406 }
407 // Always notify when registration occurs if there has been a notification.
408 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800409 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800410 if (VDBG) log("listen oscl: send to r=" + r);
411 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
412 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800413 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800415 remove(r.binder);
416 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800417 } else {
418 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 }
421 }
422
423 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800424 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800425 IOnSubscriptionsChangedListener callback) {
426 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800427 remove(callback.asBinder());
428 }
429
Wink Savillea374c3d2014-11-11 11:48:04 -0800430 @Override
431 public void notifySubscriptionInfoChanged() {
432 if (VDBG) log("notifySubscriptionInfoChanged:");
433 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800434 if (!hasNotifySubscriptionInfoChangedOccurred) {
435 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
436 + mRecords.size());
437 }
438 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800439 mRemoveList.clear();
440 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800441 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800442 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800443 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
444 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
445 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800446 } catch (RemoteException ex) {
447 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
448 mRemoveList.add(r.binder);
449 }
450 }
451 }
452 handleRemoveListLocked();
453 }
454 }
455
456 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
458 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800459 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
460 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700461 }
462
463 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700464 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700465 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700466 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700467 }
468
Svet Ganov16a16892015-04-16 10:32:04 -0700469 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700470 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700471 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700473 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700474 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700475 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
476 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700477 }
xinhe75c2c152014-10-16 11:49:45 -0700478
479 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800480 // Checks permission and throws SecurityException for disallowed operations. For pre-M
481 // apps whose runtime permission has been revoked, we return immediately to skip sending
482 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800483 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800484 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700485 }
486
yifan.baie620ce72017-12-22 14:59:57 +0800487 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 synchronized (mRecords) {
489 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800490 IBinder b = callback.asBinder();
491 Record r = add(b);
492
493 if (r == null) {
494 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 }
xinhe43c50292014-09-18 17:56:48 -0700496
Jeff Davidson29da89f2018-02-28 17:50:16 -0800497 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700498 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700499 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800500 r.callerUid = Binder.getCallingUid();
501 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700502 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
503 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800504 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800505 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700506 } else {//APP specify subID
507 r.subId = subId;
508 }
yifan.baie620ce72017-12-22 14:59:57 +0800509 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700511 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700512 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700513 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700514 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400516 try {
Wink Savillee380b982014-07-26 18:24:22 -0700517 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700518 r.callback.onServiceStateChanged(
519 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400520 } catch (RemoteException ex) {
521 remove(r.binder);
522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 }
524 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
525 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700526 int gsmSignalStrength = mSignalStrength[phoneId]
527 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700528 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
529 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 } catch (RemoteException ex) {
531 remove(r.binder);
532 }
533 }
534 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
535 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700536 r.callback.onMessageWaitingIndicatorChanged(
537 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 } catch (RemoteException ex) {
539 remove(r.binder);
540 }
541 }
542 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
543 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700544 r.callback.onCallForwardingIndicatorChanged(
545 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 } catch (RemoteException ex) {
547 remove(r.binder);
548 }
549 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700550 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400551 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700552 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700553 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800554 if (checkLocationAccess(r)) {
555 r.callback.onCellLocationChanged(
556 new Bundle(mCellLocation[phoneId]));
557 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400558 } catch (RemoteException ex) {
559 remove(r.binder);
560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 }
562 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
563 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700564 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700565 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 } catch (RemoteException ex) {
567 remove(r.binder);
568 }
569 }
570 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
571 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700572 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
573 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 } catch (RemoteException ex) {
575 remove(r.binder);
576 }
577 }
578 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
579 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700580 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 } catch (RemoteException ex) {
582 remove(r.binder);
583 }
584 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700585 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
586 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700588 } catch (RemoteException ex) {
589 remove(r.binder);
590 }
591 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700592 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
593 try {
594 r.callback.onOtaspChanged(mOtaspMode);
595 } catch (RemoteException ex) {
596 remove(r.binder);
597 }
598 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700599 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700600 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700601 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800603 if (checkLocationAccess(r)) {
604 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
605 }
John Wang963db55d2012-03-30 16:04:06 -0700606 } catch (RemoteException ex) {
607 remove(r.binder);
608 }
609 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200610 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
611 try {
612 r.callback.onPreciseCallStateChanged(mPreciseCallState);
613 } catch (RemoteException ex) {
614 remove(r.binder);
615 }
616 }
617 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
618 try {
619 r.callback.onPreciseDataConnectionStateChanged(
620 mPreciseDataConnectionState);
621 } catch (RemoteException ex) {
622 remove(r.binder);
623 }
624 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400625 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
626 try {
627 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
628 } catch (RemoteException ex) {
629 remove(r.binder);
630 }
631 }
fionaxu12312f62016-11-14 13:32:14 -0800632 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
633 try {
634 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
635 } catch (RemoteException ex) {
636 remove(r.binder);
637 }
638 }
639 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
640 try {
641 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
642 } catch (RemoteException ex) {
643 remove(r.binder);
644 }
645 }
zxuan35a47022018-01-04 11:24:04 -0800646 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
647 try {
648 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
649 } catch (RemoteException ex) {
650 remove(r.binder);
651 }
652 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800653 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
654 try {
655 r.callback.onPhysicalChannelConfigurationChanged(
656 mPhysicalChannelConfigs.get(phoneId));
657 } catch (RemoteException ex) {
658 remove(r.binder);
659 }
660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 }
662 }
663 } else {
xinhe75c2c152014-10-16 11:49:45 -0700664 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 remove(callback.asBinder());
666 }
667 }
668
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700669 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700670 // Only reveal the incoming number if the record has read call log permission.
671 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700672 }
673
Malcolm Chenabbfac22018-02-12 19:15:59 -0800674 private Record add(IBinder binder) {
675 Record r;
676
677 synchronized (mRecords) {
678 final int N = mRecords.size();
679 for (int i = 0; i < N; i++) {
680 r = mRecords.get(i);
681 if (binder == r.binder) {
682 // Already existed.
683 return r;
684 }
685 }
686 r = new Record();
687 r.binder = binder;
688 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
689
690 try {
691 binder.linkToDeath(r.deathRecipient, 0);
692 } catch (RemoteException e) {
693 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
694 // Binder already died. Return null.
695 return null;
696 }
697
698 mRecords.add(r);
699 if (DBG) log("add new record");
700 }
701
702 return r;
703 }
704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 private void remove(IBinder binder) {
706 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700707 final int recordCount = mRecords.size();
708 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800709 Record r = mRecords.get(i);
710 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800711 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800712 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
713 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800714 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800715
716 if (r.deathRecipient != null) {
717 try {
718 binder.unlinkToDeath(r.deathRecipient, 0);
719 } catch (NoSuchElementException e) {
720 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
721 + r + " e=" + e);
722 }
723 }
724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 mRecords.remove(i);
726 return;
727 }
728 }
729 }
730 }
731
Tyler Gunnf955e562018-04-26 14:43:31 -0700732 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700733 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700734 return;
735 }
xinhe43c50292014-09-18 17:56:48 -0700736
737 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700738 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700739 }
740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700742 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800743 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800744 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700746 // Ensure the listener has read call log permission; if they do not return
747 // an empty phone number.
748 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
749 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400751 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 }
753 }
754 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400755 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700757
758 // Called only by Telecomm to communicate call state across different phone accounts. So
759 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700760 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700761 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700762 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 }
764
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700765 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
766 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700767 if (!checkNotifyPermission("notifyCallState()")) {
768 return;
769 }
Wink Savillee380b982014-07-26 18:24:22 -0700770 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700771 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700772 + " state=" + state + " incomingNumber=" + incomingNumber);
773 }
774 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700775 if (validatePhoneId(phoneId)) {
776 mCallState[phoneId] = state;
777 mCallIncomingNumber[phoneId] = incomingNumber;
778 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800779 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700780 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800781 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700782 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700783 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
784 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700785 } catch (RemoteException ex) {
786 mRemoveList.add(r.binder);
787 }
788 }
789 }
790 }
791 handleRemoveListLocked();
792 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700793 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700794 }
795
Wink Saville63f03dd2014-10-23 10:44:45 -0700796 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700797 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700798 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700799 }
xinhe43c50292014-09-18 17:56:48 -0700800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700802 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
803 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700804 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700805 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700806 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700807 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700808 if (validatePhoneId(phoneId)) {
809 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700810
Wink Savillefb40dd42014-06-12 17:02:31 -0700811 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700812 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700813 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700814 + " phoneId=" + phoneId + " state=" + state);
815 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800816 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800817 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700818 try {
Wink Savillee380b982014-07-26 18:24:22 -0700819 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700820 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700821 + " subId=" + subId + " phoneId=" + phoneId
822 + " state=" + state);
823 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700824 r.callback.onServiceStateChanged(new ServiceState(state));
825 } catch (RemoteException ex) {
826 mRemoveList.add(r.binder);
827 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700830 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700831 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400833 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700835 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 }
837
fionaxu12312f62016-11-14 13:32:14 -0800838 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
839 int activationType, int activationState) {
840 if (!checkNotifyPermission("notifySimActivationState()")){
841 return;
842 }
843 if (VDBG) {
844 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
845 + "type=" + activationType + " state=" + activationState);
846 }
847 synchronized (mRecords) {
848 if (validatePhoneId(phoneId)) {
849 switch (activationType) {
850 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
851 mVoiceActivationState[phoneId] = activationState;
852 break;
853 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
854 mDataActivationState[phoneId] = activationState;
855 break;
856 default:
857 return;
858 }
859 for (Record r : mRecords) {
860 if (VDBG) {
861 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
862 + " phoneId=" + phoneId + "type=" + activationType
863 + " state=" + activationState);
864 }
865 try {
866 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
867 r.matchPhoneStateListenerEvent(
868 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
869 idMatch(r.subId, subId, phoneId)) {
870 if (DBG) {
871 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
872 + " subId=" + subId + " phoneId=" + phoneId
873 + " state=" + activationState);
874 }
875 r.callback.onVoiceActivationStateChanged(activationState);
876 }
877 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
878 r.matchPhoneStateListenerEvent(
879 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
880 idMatch(r.subId, subId, phoneId)) {
881 if (DBG) {
882 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
883 + " subId=" + subId + " phoneId=" + phoneId
884 + " state=" + activationState);
885 }
886 r.callback.onDataActivationStateChanged(activationState);
887 }
888 } catch (RemoteException ex) {
889 mRemoveList.add(r.binder);
890 }
891 }
892 } else {
893 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
894 }
895 handleRemoveListLocked();
896 }
897 }
898
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700899 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
900 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700901 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700902 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700903 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000904 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700905 log("notifySignalStrengthForPhoneId: subId=" + subId
906 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000907 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700910 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700911 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700912 mSignalStrength[phoneId] = signalStrength;
913 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000914 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700915 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000916 + " phoneId=" + phoneId + " ss=" + signalStrength);
917 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800918 if (r.matchPhoneStateListenerEvent(
919 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800920 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700921 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000922 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700923 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000924 + " subId=" + subId + " phoneId=" + phoneId
925 + " ss=" + signalStrength);
926 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700927 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
928 } catch (RemoteException ex) {
929 mRemoveList.add(r.binder);
930 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400931 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800932 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800933 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700934 try {
935 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700936 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000937 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700938 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000939 + " subId=" + subId + " phoneId=" + phoneId
940 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
941 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700942 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700943 } catch (RemoteException ex) {
944 mRemoveList.add(r.binder);
945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 }
947 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700948 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700949 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400951 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700953 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 }
955
Andrew Flynn1f452642015-04-14 22:16:04 -0400956 @Override
957 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000958 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
959
Andrew Flynn1f452642015-04-14 22:16:04 -0400960 if (VDBG) {
961 log("notifyCarrierNetworkChange: active=" + active);
962 }
963
964 synchronized (mRecords) {
965 mCarrierNetworkChangeState = active;
966 for (Record r : mRecords) {
967 if (r.matchPhoneStateListenerEvent(
968 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
969 try {
970 r.callback.onCarrierNetworkChange(active);
971 } catch (RemoteException ex) {
972 mRemoveList.add(r.binder);
973 }
974 }
975 }
976 handleRemoveListLocked();
977 }
978 }
979
Wink Savilleb208a242012-07-25 14:08:09 -0700980 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800981 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700982 }
983
Wink Saville63f03dd2014-10-23 10:44:45 -0700984 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700985 if (!checkNotifyPermission("notifyCellInfo()")) {
986 return;
987 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700988 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700989 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700990 + " cellInfo=" + cellInfo);
991 }
yifan.baie620ce72017-12-22 14:59:57 +0800992 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -0700993 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700994 if (validatePhoneId(phoneId)) {
995 mCellInfo.set(phoneId, cellInfo);
996 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700997 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -0800998 idMatch(r.subId, subId, phoneId) &&
999 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001000 try {
1001 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001002 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001003 }
1004 r.callback.onCellInfoChanged(cellInfo);
1005 } catch (RemoteException ex) {
1006 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001007 }
John Wang963db55d2012-03-30 16:04:06 -07001008 }
1009 }
1010 }
1011 handleRemoveListLocked();
1012 }
1013 }
1014
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001015 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1016 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1017 configs);
1018 }
1019
1020 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1021 List<PhysicalChannelConfig> configs) {
1022 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1023 return;
1024 }
1025
1026 if (VDBG) {
1027 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1028 }
1029
1030 synchronized (mRecords) {
1031 int phoneId = SubscriptionManager.getPhoneId(subId);
1032 if (validatePhoneId(phoneId)) {
1033 mPhysicalChannelConfigs.set(phoneId, configs);
1034 for (Record r : mRecords) {
1035 if (r.matchPhoneStateListenerEvent(
1036 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1037 && idMatch(r.subId, subId, phoneId)) {
1038 try {
1039 if (DBG_LOC) {
1040 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1041 + configs + " r=" + r);
1042 }
1043 r.callback.onPhysicalChannelConfigurationChanged(configs);
1044 } catch (RemoteException ex) {
1045 mRemoveList.add(r.binder);
1046 }
1047 }
1048 }
1049 }
1050 handleRemoveListLocked();
1051 }
1052 }
1053
xinhe43c50292014-09-18 17:56:48 -07001054 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001055 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001056 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001057 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001058 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001059 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001060 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001061 + " mwi=" + mwi);
1062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001064 if (validatePhoneId(phoneId)) {
1065 mMessageWaiting[phoneId] = mwi;
1066 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001067 if (r.matchPhoneStateListenerEvent(
1068 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001069 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001070 try {
1071 r.callback.onMessageWaitingIndicatorChanged(mwi);
1072 } catch (RemoteException ex) {
1073 mRemoveList.add(r.binder);
1074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 }
1076 }
1077 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001078 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 }
1080 }
1081
zxuan35a47022018-01-04 11:24:04 -08001082 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1083 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1084 return;
1085 }
1086 if (VDBG) {
1087 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1088 + " state=" + state);
1089 }
1090 synchronized (mRecords) {
1091 if (validatePhoneId(phoneId)) {
1092 mMessageWaiting[phoneId] = state;
1093 for (Record r : mRecords) {
1094 if (r.matchPhoneStateListenerEvent(
1095 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1096 idMatch(r.subId, subId, phoneId)) {
1097 try {
1098 r.callback.onUserMobileDataStateChanged(state);
1099 } catch (RemoteException ex) {
1100 mRemoveList.add(r.binder);
1101 }
1102 }
1103 }
1104 }
1105 handleRemoveListLocked();
1106 }
1107 }
1108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001110 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001111 }
1112
Wink Saville63f03dd2014-10-23 10:44:45 -07001113 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001114 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001115 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001116 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001117 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001118 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001119 + " cfi=" + cfi);
1120 }
yifan.baie620ce72017-12-22 14:59:57 +08001121 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001123 if (validatePhoneId(phoneId)) {
1124 mCallForwarding[phoneId] = cfi;
1125 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001126 if (r.matchPhoneStateListenerEvent(
1127 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001128 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001129 try {
1130 r.callback.onCallForwardingIndicatorChanged(cfi);
1131 } catch (RemoteException ex) {
1132 mRemoveList.add(r.binder);
1133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 }
1135 }
1136 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001137 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 }
1139 }
1140
1141 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001142 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001143 }
1144
Wink Saville63f03dd2014-10-23 10:44:45 -07001145 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001146 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001147 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001148 }
yifan.baie620ce72017-12-22 14:59:57 +08001149 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001151 if (validatePhoneId(phoneId)) {
1152 mDataActivity[phoneId] = state;
1153 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001154 // Notify by correct subId.
1155 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1156 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001157 try {
1158 r.callback.onDataActivity(state);
1159 } catch (RemoteException ex) {
1160 mRemoveList.add(r.binder);
1161 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 }
1163 }
1164 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001165 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 }
1167 }
1168
Jack Yubaeec622017-05-01 17:01:11 -07001169 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001170 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001171 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001172 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001173 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001174 networkCapabilities, networkType, roaming);
1175 }
1176
Wink Saville63f03dd2014-10-23 10:44:45 -07001177 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001178 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001179 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1180 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001181 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001182 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001183 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001185 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001186 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001187 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001188 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001189 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001190 }
yifan.baie620ce72017-12-22 14:59:57 +08001191 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001193 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001194 // We only call the callback when the change is for default APN type.
1195 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1196 && (mDataConnectionState[phoneId] != state
1197 || mDataConnectionNetworkType[phoneId] != networkType)) {
1198 String str = "onDataConnectionStateChanged(" + state
1199 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001200 log(str);
1201 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001202 for (Record r : mRecords) {
1203 if (r.matchPhoneStateListenerEvent(
1204 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1205 idMatch(r.subId, subId, phoneId)) {
1206 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001207 if (DBG) {
1208 log("Notify data connection state changed on sub: " + subId);
1209 }
Jack Yub1bac542018-03-14 16:23:38 -07001210 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001211 } catch (RemoteException ex) {
1212 mRemoveList.add(r.binder);
1213 }
1214 }
1215 }
1216 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001217
1218 mDataConnectionState[phoneId] = state;
1219 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001220 }
1221 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1222 apnType, apn, reason, linkProperties, "");
1223 for (Record r : mRecords) {
1224 if (r.matchPhoneStateListenerEvent(
1225 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1226 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001227 r.callback.onPreciseDataConnectionStateChanged(
1228 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001229 } catch (RemoteException ex) {
1230 mRemoveList.add(r.binder);
1231 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001232 }
1233 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001234 }
1235 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 }
Jack Yubaeec622017-05-01 17:01:11 -07001237 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001238 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001239 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1240 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 }
1242
Robert Greenwalt02648a42010-05-18 10:52:51 -07001243 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001244 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001245 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001246 }
1247
Wink Saville63f03dd2014-10-23 10:44:45 -07001248 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001249 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001250 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001251 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001252 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001253 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001254 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001255 + " reason=" + reason + " apnType=" + apnType);
1256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001258 mPreciseDataConnectionState = new PreciseDataConnectionState(
1259 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1260 apnType, "", reason, null, "");
1261 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001262 if (r.matchPhoneStateListenerEvent(
1263 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001264 try {
1265 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1266 } catch (RemoteException ex) {
1267 mRemoveList.add(r.binder);
1268 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 }
1270 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001271 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001273 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001274 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1275 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 }
1277
1278 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001279 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001280 }
1281
Wink Saville63f03dd2014-10-23 10:44:45 -07001282 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001283 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001284 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001285 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001286 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001287 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001288 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001289 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001290 + " cellLocation=" + cellLocation);
1291 }
yifan.baie620ce72017-12-22 14:59:57 +08001292 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001294 if (validatePhoneId(phoneId)) {
1295 mCellLocation[phoneId] = cellLocation;
1296 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001297 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001298 idMatch(r.subId, subId, phoneId) &&
1299 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001300 try {
1301 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001302 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001303 + " r=" + r);
1304 }
1305 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1306 } catch (RemoteException ex) {
1307 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001308 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001309 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 }
1311 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001312 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001313 }
1314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315
Wink Savillefd2d0132010-10-28 14:22:26 -07001316 public void notifyOtaspChanged(int otaspMode) {
1317 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1318 return;
1319 }
1320 synchronized (mRecords) {
1321 mOtaspMode = otaspMode;
1322 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001323 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001324 try {
1325 r.callback.onOtaspChanged(otaspMode);
1326 } catch (RemoteException ex) {
1327 mRemoveList.add(r.binder);
1328 }
1329 }
1330 }
1331 handleRemoveListLocked();
1332 }
1333 }
1334
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001335 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1336 int backgroundCallState) {
1337 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1338 return;
1339 }
1340 synchronized (mRecords) {
1341 mRingingCallState = ringingCallState;
1342 mForegroundCallState = foregroundCallState;
1343 mBackgroundCallState = backgroundCallState;
1344 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1345 backgroundCallState,
1346 DisconnectCause.NOT_VALID,
1347 PreciseDisconnectCause.NOT_VALID);
1348 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001349 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001350 try {
1351 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1352 } catch (RemoteException ex) {
1353 mRemoveList.add(r.binder);
1354 }
1355 }
1356 }
1357 handleRemoveListLocked();
1358 }
1359 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1360 DisconnectCause.NOT_VALID,
1361 PreciseDisconnectCause.NOT_VALID);
1362 }
1363
1364 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1365 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1366 return;
1367 }
1368 synchronized (mRecords) {
1369 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1370 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1371 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001372 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001373 try {
1374 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1375 } catch (RemoteException ex) {
1376 mRemoveList.add(r.binder);
1377 }
1378 }
1379 }
1380 handleRemoveListLocked();
1381 }
1382 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1383 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1384 }
1385
1386 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1387 String apn, String failCause) {
1388 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1389 return;
1390 }
1391 synchronized (mRecords) {
1392 mPreciseDataConnectionState = new PreciseDataConnectionState(
1393 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1394 apnType, apn, reason, null, failCause);
1395 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001396 if (r.matchPhoneStateListenerEvent(
1397 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001398 try {
1399 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1400 } catch (RemoteException ex) {
1401 mRemoveList.add(r.binder);
1402 }
1403 }
1404 }
1405 handleRemoveListLocked();
1406 }
1407 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1408 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1409 }
1410
Wink Savillefb40dd42014-06-12 17:02:31 -07001411 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1412 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1413 return;
1414 }
1415 synchronized (mRecords) {
1416 mVoLteServiceState = lteState;
1417 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001418 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001419 try {
1420 r.callback.onVoLteServiceStateChanged(
1421 new VoLteServiceState(mVoLteServiceState));
1422 } catch (RemoteException ex) {
1423 mRemoveList.add(r.binder);
1424 }
1425 }
1426 }
1427 handleRemoveListLocked();
1428 }
1429 }
1430
Shuo Qian066e8652018-04-25 21:02:35 +00001431 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1432 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1433 return;
1434 }
1435
1436 synchronized (mRecords) {
1437 for (Record r : mRecords) {
1438 if (VDBG) {
1439 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1440 }
1441 if ((r.matchPhoneStateListenerEvent(
1442 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1443 ((r.subId == subId) ||
1444 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1445 try {
1446 r.callback.onOemHookRawEvent(rawData);
1447 } catch (RemoteException ex) {
1448 mRemoveList.add(r.binder);
1449 }
1450 }
1451 }
1452 handleRemoveListLocked();
1453 }
1454 }
1455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001457 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1458 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1459
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001460 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001463 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001465 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301466 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001467 pw.println("Phone Id=" + i);
1468 pw.increaseIndent();
1469 pw.println("mCallState=" + mCallState[i]);
1470 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1471 pw.println("mServiceState=" + mServiceState[i]);
1472 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1473 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001474 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001475 pw.println("mSignalStrength=" + mSignalStrength[i]);
1476 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1477 pw.println("mCallForwarding=" + mCallForwarding[i]);
1478 pw.println("mDataActivity=" + mDataActivity[i]);
1479 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001480 pw.println("mCellLocation=" + mCellLocation[i]);
1481 pw.println("mCellInfo=" + mCellInfo.get(i));
1482 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301483 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001484 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1485 pw.println("mPreciseCallState=" + mPreciseCallState);
1486 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1487 pw.println("mRingingCallState=" + mRingingCallState);
1488 pw.println("mForegroundCallState=" + mForegroundCallState);
1489 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1490 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1491
1492 pw.decreaseIndent();
1493
1494 pw.println("local logs:");
1495 pw.increaseIndent();
1496 mLocalLog.dump(fd, pw, args);
1497 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001498 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001499 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001500 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001501 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001503 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 }
1505 }
1506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 //
1508 // the legacy intent broadcasting
1509 //
1510
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001511 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001512 long ident = Binder.clearCallingIdentity();
1513 try {
1514 mBatteryStats.notePhoneState(state.getState());
1515 } catch (RemoteException re) {
1516 // Can't do much
1517 } finally {
1518 Binder.restoreCallingIdentity(ident);
1519 }
1520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001522 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 Bundle data = new Bundle();
1524 state.fillInNotifierBundle(data);
1525 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001526 // Pass the subscription along with the intent.
1527 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001528 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001529 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 }
1531
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001532 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1533 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001534 long ident = Binder.clearCallingIdentity();
1535 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001536 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001537 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001538 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001539 } finally {
1540 Binder.restoreCallingIdentity(ident);
1541 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001544 Bundle data = new Bundle();
1545 signalStrength.fillInNotifierBundle(data);
1546 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001547 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001548 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001549 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 }
1551
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001552 /**
1553 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1554 * a valid subId, in which case this function fires a subId-specific intent, or it
1555 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1556 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1557 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001558 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1559 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 long ident = Binder.clearCallingIdentity();
1561 try {
1562 if (state == TelephonyManager.CALL_STATE_IDLE) {
1563 mBatteryStats.notePhoneOff();
1564 } else {
1565 mBatteryStats.notePhoneOn();
1566 }
1567 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001568 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 } finally {
1570 Binder.restoreCallingIdentity(ident);
1571 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001574 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001575 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001576
1577 // If a valid subId was specified, we should fire off a subId-specific state
1578 // change intent and include the subId.
1579 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1580 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1581 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1582 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001583 // If the phoneId is invalid, the broadcast is for overall call state.
1584 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1585 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1586 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001587
Brad Ebinger51de96a2017-04-21 17:05:18 -07001588 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1589 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1590
Tyler Gunnf955e562018-04-26 14:43:31 -07001591 Intent intentWithPhoneNumber = new Intent(intent);
1592 if (!TextUtils.isEmpty(incomingNumber)) {
1593 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1594 }
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001595 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1596 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001597 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001598 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001599 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001600 android.Manifest.permission.READ_PHONE_STATE,
1601 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001602 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1603 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1604 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 }
1606
Robert Greenwalt42acef32009-08-12 16:08:25 -07001607 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001608 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001609 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001610 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001611 // Note: not reporting to the battery stats service here, because the
1612 // status bar takes care of that after taking into account all of the
1613 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001615 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001616 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001617 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001618 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 }
1620 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001621 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001623 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001624 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001625 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001626 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001627 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001628 }
1629 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001630 if (networkCapabilities != null) {
1631 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001632 }
Wink Savillea639b312012-07-10 12:37:54 -07001633 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001634
Wink Savillea639b312012-07-10 12:37:54 -07001635 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1636 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001637 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001638 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 }
1640
Wink Savillefb40dd42014-06-12 17:02:31 -07001641 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001642 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001644 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1645 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001646 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001647 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001649
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001650 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1651 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1652 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1653 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1654 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1655 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1656 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1657 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1658 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1659 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1660 }
1661
1662 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001663 String apnType, String apn, String reason, LinkProperties linkProperties,
1664 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001665 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1666 intent.putExtra(PhoneConstants.STATE_KEY, state);
1667 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1668 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1669 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1670 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001671 if (linkProperties != null) {
1672 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1673 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001674 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1675
1676 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1677 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1678 }
1679
Andrew Flynnceaed682015-06-09 12:36:58 +00001680 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001681 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001682 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001683 }
1684
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001685 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1686 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001687 }
1688
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001689 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001690 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001691 return true;
1692 }
1693 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001694 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001695 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001696 return false;
1697 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001698
Andrew Flynn1f452642015-04-14 22:16:04 -04001699 private boolean checkNotifyPermission() {
1700 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1701 == PackageManager.PERMISSION_GRANTED;
1702 }
1703
Jeff Davidson29da89f2018-02-28 17:50:16 -08001704 private boolean checkListenerPermission(
1705 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001706 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001707 mContext.enforceCallingOrSelfPermission(
1708 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001709 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1710 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1711 return false;
1712 }
John Wang963db55d2012-03-30 16:04:06 -07001713 }
1714
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001715 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1717 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001718 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001719 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001720 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001721
1722 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1723 mContext.enforceCallingOrSelfPermission(
1724 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001725 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001726
Shuo Qian066e8652018-04-25 21:02:35 +00001727 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1728 mContext.enforceCallingOrSelfPermission(
1729 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1730 }
1731
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001732 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001733 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001734
1735 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001736 int size = mRemoveList.size();
1737 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1738 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001739 for (IBinder b: mRemoveList) {
1740 remove(b);
1741 }
1742 mRemoveList.clear();
1743 }
1744 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001745
1746 private boolean validateEventsAndUserLocked(Record r, int events) {
1747 int foregroundUser;
1748 long callingIdentity = Binder.clearCallingIdentity();
1749 boolean valid = false;
1750 try {
1751 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001752 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1753 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001754 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001755 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001756 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001757 + " r.events=" + r.events + " events=" + events);
1758 }
1759 } finally {
1760 Binder.restoreCallingIdentity(callingIdentity);
1761 }
1762 return valid;
1763 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001764
1765 private boolean validatePhoneId(int phoneId) {
1766 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001767 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001768 return valid;
1769 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001770
1771 private static void log(String s) {
1772 Rlog.d(TAG, s);
1773 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001774
xinhe8b79fb62014-11-05 14:55:03 -08001775 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001776
1777 if(subId < 0) {
1778 // Invalid case, we need compare phoneId with default one.
1779 return (mDefaultPhoneId == phoneId);
1780 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001781 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001782 return (subId == mDefaultSubId);
1783 } else {
1784 return (rSubId == subId);
1785 }
1786 }
1787
Hall Liu5fb337f2017-11-22 17:38:15 -08001788 private boolean checkLocationAccess(Record r) {
1789 long token = Binder.clearCallingIdentity();
1790 try {
1791 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001792 r.callingPackage, r.callerUid, r.callerPid,
1793 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001794 } finally {
1795 Binder.restoreCallingIdentity(token);
1796 }
1797 }
1798
xinhee9f16402014-09-25 16:39:28 -07001799 private void checkPossibleMissNotify(Record r, int phoneId) {
1800 int events = r.events;
1801
1802 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1803 try {
1804 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1805 mServiceState[phoneId]);
1806 r.callback.onServiceStateChanged(
1807 new ServiceState(mServiceState[phoneId]));
1808 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001809 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001810 }
1811 }
1812
1813 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1814 try {
1815 SignalStrength signalStrength = mSignalStrength[phoneId];
1816 if (DBG) {
1817 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1818 }
1819 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1820 } catch (RemoteException ex) {
1821 mRemoveList.add(r.binder);
1822 }
1823 }
1824
1825 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1826 try {
1827 int gsmSignalStrength = mSignalStrength[phoneId]
1828 .getGsmSignalStrength();
1829 if (DBG) {
1830 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1831 gsmSignalStrength);
1832 }
1833 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1834 : gsmSignalStrength));
1835 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001836 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001837 }
1838 }
1839
1840 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1841 try {
1842 if (DBG_LOC) {
1843 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1844 + mCellInfo.get(phoneId));
1845 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001846 if (checkLocationAccess(r)) {
1847 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1848 }
xinhee9f16402014-09-25 16:39:28 -07001849 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001850 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001851 }
1852 }
1853
zxuan35a47022018-01-04 11:24:04 -08001854 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1855 try {
1856 if (VDBG) {
1857 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1858 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1859 }
1860 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1861 } catch (RemoteException ex) {
1862 mRemoveList.add(r.binder);
1863 }
1864 }
1865
xinhee9f16402014-09-25 16:39:28 -07001866 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1867 try {
1868 if (VDBG) {
1869 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1870 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1871 }
1872 r.callback.onMessageWaitingIndicatorChanged(
1873 mMessageWaiting[phoneId]);
1874 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001875 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001876 }
1877 }
1878
1879 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1880 try {
1881 if (VDBG) {
1882 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1883 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1884 }
1885 r.callback.onCallForwardingIndicatorChanged(
1886 mCallForwarding[phoneId]);
1887 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001888 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001889 }
1890 }
1891
1892 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1893 try {
1894 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1895 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001896 if (checkLocationAccess(r)) {
1897 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1898 }
xinhee9f16402014-09-25 16:39:28 -07001899 } catch (RemoteException ex) {
1900 mRemoveList.add(r.binder);
1901 }
1902 }
1903
1904 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1905 try {
1906 if (DBG) {
1907 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1908 + "=" + mDataConnectionState[phoneId]
1909 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1910 + ")");
1911 }
1912 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1913 mDataConnectionNetworkType[phoneId]);
1914 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001915 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001916 }
1917 }
1918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919}