blob: 98b88cb557af13ef5b4dc4e42f851f8080e2ffa2 [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;
Malcolm Chene1623652018-08-08 20:27:45 -070039import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070040import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080041import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020042import android.telephony.PreciseCallState;
43import android.telephony.PreciseDataConnectionState;
44import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070045import android.telephony.Rlog;
46import android.telephony.ServiceState;
47import android.telephony.SignalStrength;
48import android.telephony.SubscriptionManager;
49import android.telephony.TelephonyManager;
50import android.telephony.VoLteServiceState;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070053import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080055import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070057import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080058import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070059import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080061import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060062import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070063import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import com.android.server.am.BatteryStatsService;
65
Jack Yud19b6ae2017-04-05 14:12:09 -070066import java.io.FileDescriptor;
67import java.io.PrintWriter;
68import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070069import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080070import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072/**
Wink Savillee9b06d72009-05-18 21:47:50 -070073 * Since phone process can be restarted, this class provides a centralized place
74 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070075 *
76 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
77 * and 15973975 by saving the phoneId of the registrant and then using the
78 * phoneId when deciding to to make a callback. This is necessary because
79 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070080 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070081 * the dummy value conversion we properly do the callbacks.
82 *
83 * Eventually we may want to remove the notion of dummy value but for now this
84 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070086@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
87public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070089 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070090 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070091 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080094 Context context;
95
Svet Ganov16a16892015-04-16 10:32:04 -070096 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070099
Malcolm Chenabbfac22018-02-12 19:15:59 -0800100 TelephonyRegistryDeathRecipient deathRecipient;
101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800103 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700104 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700105
Hall Liu5fb337f2017-11-22 17:38:15 -0800106 int callerUid;
107 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700110
Wink Savilled09c4ca2014-11-22 10:08:16 -0800111 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700112
Wink Savilled09c4ca2014-11-22 10:08:16 -0800113 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800114
115 boolean matchPhoneStateListenerEvent(int events) {
116 return (callback != null) && ((events & this.events) != 0);
117 }
118
Wink Savilled09c4ca2014-11-22 10:08:16 -0800119 boolean matchOnSubscriptionsChangedListener() {
120 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800121 }
Wink Savillee380b982014-07-26 18:24:22 -0700122
Malcolm Chen13f31af2018-09-04 22:12:31 -0700123 boolean matchOnOpportunisticSubscriptionsChangedListener() {
124 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
125 }
126
Tyler Gunnf955e562018-04-26 14:43:31 -0700127 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800128 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700129 return TelephonyPermissions.checkReadCallLog(
130 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800131 } catch (SecurityException e) {
132 return false;
133 }
134 }
135
Wink Savillea12a7b32012-09-20 10:09:45 -0700136 @Override
137 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700138 return "{callingPackage=" + callingPackage + " binder=" + binder
139 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800140 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700141 + onSubscriptionsChangedListenerCallback
142 + " onOpportunisticSubscriptionsChangedListenererCallback="
143 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800144 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800145 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 }
148
149 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700150
Joe Onorato163d8d92010-10-21 13:21:20 -0400151 // access should be inside synchronized (mRecords) for these two fields
152 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
153 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 private final IBatteryStats mBatteryStats;
156
Svet Ganov16a16892015-04-16 10:32:04 -0700157 private final AppOpsManager mAppOps;
158
Malcolm Chen13f31af2018-09-04 22:12:31 -0700159 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
160
161 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800162
Wink Savillefb40dd42014-06-12 17:02:31 -0700163 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700164
Wink Savillefb40dd42014-06-12 17:02:31 -0700165 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700166
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700168
Wink Savillefb40dd42014-06-12 17:02:31 -0700169 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700170
fionaxu12312f62016-11-14 13:32:14 -0800171 private int[] mVoiceActivationState;
172
173 private int[] mDataActivationState;
174
zxuan35a47022018-01-04 11:24:04 -0800175 private boolean[] mUserMobileDataState;
176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700180
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700182
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700184
Jack Yub1bac542018-03-14 16:23:38 -0700185 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700191
Nathan Harold016e9c62016-12-14 11:24:48 -0800192 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700193
Wink Savillefb40dd42014-06-12 17:02:31 -0700194 private ArrayList<List<CellInfo>> mCellInfo = null;
195
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800196 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
197
Wink Savillefb40dd42014-06-12 17:02:31 -0700198 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
199
Wink Savilled09c4ca2014-11-22 10:08:16 -0800200 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700201
Wink Savilled09c4ca2014-11-22 10:08:16 -0800202 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700203
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200204 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
205
206 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
207
208 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
209
210 private PreciseCallState mPreciseCallState = new PreciseCallState();
211
Andrew Flynn1f452642015-04-14 22:16:04 -0400212 private boolean mCarrierNetworkChangeState = false;
213
Malcolm Chene1623652018-08-08 20:27:45 -0700214 private PhoneCapability mPhoneCapability = null;
215
Jack Yud19b6ae2017-04-05 14:12:09 -0700216 private final LocalLog mLocalLog = new LocalLog(100);
217
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200218 private PreciseDataConnectionState mPreciseDataConnectionState =
219 new PreciseDataConnectionState();
220
Hall Liu70bbc162018-03-02 17:44:46 -0800221 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
222 PhoneStateListener.LISTEN_CELL_LOCATION
223 | PhoneStateListener.LISTEN_CELL_INFO;
224
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700225 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700226 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700227 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
228 PhoneStateListener.LISTEN_VOLTE_STATE;
229
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200230 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
231 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
232 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
233
Wink Savillea12a7b32012-09-20 10:09:45 -0700234 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700235 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700236
237 private final Handler mHandler = new Handler() {
238 @Override
239 public void handleMessage(Message msg) {
240 switch (msg.what) {
241 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700242 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700243 int numPhones = TelephonyManager.getDefault().getPhoneCount();
244 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700245 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700246 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700247 }
248 break;
249 }
xinhee9f16402014-09-25 16:39:28 -0700250 case MSG_UPDATE_DEFAULT_SUB: {
251 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700252 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700253 if (VDBG) {
254 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
255 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
256 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
257 }
258
259 //Due to possible risk condition,(notify call back using the new
260 //defaultSubId comes before new defaultSubId update) we need to recall all
261 //possible missed notify callback
262 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700263 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800264 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700265 checkPossibleMissNotify(r, newDefaultPhoneId);
266 }
267 }
268 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700269 }
270 mDefaultSubId = newDefaultSubId;
271 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700272 }
273 }
274 }
275 };
276
Malcolm Chenabbfac22018-02-12 19:15:59 -0800277 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
278
279 private final IBinder binder;
280
281 TelephonyRegistryDeathRecipient(IBinder binder) {
282 this.binder = binder;
283 }
284
285 @Override
286 public void binderDied() {
287 if (DBG) log("binderDied " + binder);
288 remove(binder);
289 }
290 }
291
Wink Savillea12a7b32012-09-20 10:09:45 -0700292 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
293 @Override
294 public void onReceive(Context context, Intent intent) {
295 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700296 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700297 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700298 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700299 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700300 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700301 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700302 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800303 PhoneConstants.SUBSCRIPTION_KEY,
304 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700305 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
306 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700307 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700308 log("onReceive:current mDefaultSubId=" + mDefaultSubId
309 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
310 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700311 }
xinhee9f16402014-09-25 16:39:28 -0700312
Junda Liu985f52c2015-02-23 16:06:51 -0800313 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700314 || (newDefaultPhoneId != mDefaultPhoneId))) {
315 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
316 newDefaultPhoneId, 0, newDefaultSubIdObj));
317 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700318 }
319 }
320 };
321
Wink Savillee9b06d72009-05-18 21:47:50 -0700322 // we keep a copy of all of the state so we can send it out when folks
323 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700325 // In these calls we call with the lock held. This is safe becasuse remote
326 // calls go through a oneway interface and local calls going through a
327 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700329 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
330 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700331 CellLocation location = CellLocation.getEmpty();
332
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 mContext = context;
334 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700335
Wink Savillefb40dd42014-06-12 17:02:31 -0700336 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700337 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700338 mNumPhones = numPhones;
339 mCallState = new int[numPhones];
340 mDataActivity = new int[numPhones];
341 mDataConnectionState = new int[numPhones];
342 mDataConnectionNetworkType = new int[numPhones];
343 mCallIncomingNumber = new String[numPhones];
344 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800345 mVoiceActivationState = new int[numPhones];
346 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800347 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700348 mSignalStrength = new SignalStrength[numPhones];
349 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700350 mCallForwarding = new boolean[numPhones];
351 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800353 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 for (int i = 0; i < numPhones; i++) {
355 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
356 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
357 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800358 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
359 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700360 mCallIncomingNumber[i] = "";
361 mServiceState[i] = new ServiceState();
362 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800363 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700364 mMessageWaiting[i] = false;
365 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 mCellLocation[i] = new Bundle();
367 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700368 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700369 }
370
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700371 // Note that location can be null for non-phone builds like
372 // like the generic one.
373 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700374 for (int i = 0; i < numPhones; i++) {
375 location.fillInNotifierBundle(mCellLocation[i]);
376 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700377 }
Svet Ganov16a16892015-04-16 10:32:04 -0700378
379 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 }
381
Svetoslav Ganova0027152013-06-25 14:59:53 -0700382 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700383 // Watch for interesting updates
384 final IntentFilter filter = new IntentFilter();
385 filter.addAction(Intent.ACTION_USER_SWITCHED);
386 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700387 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700388 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700389 mContext.registerReceiver(mBroadcastReceiver, filter);
390 }
391
392 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700393 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800394 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700395 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800397 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700398 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
399 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800400 + " callback.asBinder=" + callback.asBinder());
401 }
402
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 synchronized (mRecords) {
404 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800405 IBinder b = callback.asBinder();
406 Record r = add(b);
407
408 if (r == null) {
409 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800410 }
411
Jeff Davidson29da89f2018-02-28 17:50:16 -0800412 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800413 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700414 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800415 r.callerUid = Binder.getCallingUid();
416 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800417 r.events = 0;
418 if (DBG) {
419 log("listen oscl: Register r=" + r);
420 }
421 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700422 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800423 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800424 if (VDBG) log("listen oscl: send to r=" + r);
425 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
426 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800427 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800428 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800429 remove(r.binder);
430 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800431 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700432 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800433 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800434 }
435 }
436
437 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800438 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 IOnSubscriptionsChangedListener callback) {
440 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800441 remove(callback.asBinder());
442 }
443
Malcolm Chen13f31af2018-09-04 22:12:31 -0700444
445 @Override
446 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
447 IOnSubscriptionsChangedListener callback) {
448 int callerUserId = UserHandle.getCallingUserId();
449 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
450 if (VDBG) {
451 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
452 + " callerUserId=" + callerUserId + " callback=" + callback
453 + " callback.asBinder=" + callback.asBinder());
454 }
455
456 synchronized (mRecords) {
457 // register
458 IBinder b = callback.asBinder();
459 Record r = add(b);
460
461 if (r == null) {
462 return;
463 }
464
465 r.context = mContext;
466 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
467 r.callingPackage = callingPackage;
468 r.callerUid = Binder.getCallingUid();
469 r.callerPid = Binder.getCallingPid();
470 r.events = 0;
471 if (DBG) {
472 log("listen ooscl: Register r=" + r);
473 }
474 // Always notify when registration occurs if there has been a notification.
475 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
476 try {
477 if (VDBG) log("listen ooscl: send to r=" + r);
478 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
479 if (VDBG) log("listen ooscl: sent to r=" + r);
480 } catch (RemoteException e) {
481 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
482 remove(r.binder);
483 }
484 } else {
485 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
486 }
487 }
488 }
489
Wink Savillea374c3d2014-11-11 11:48:04 -0800490 @Override
491 public void notifySubscriptionInfoChanged() {
492 if (VDBG) log("notifySubscriptionInfoChanged:");
493 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700494 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800495 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
496 + mRecords.size());
497 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700498 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800499 mRemoveList.clear();
500 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800501 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800502 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800503 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
504 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
505 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800506 } catch (RemoteException ex) {
507 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
508 mRemoveList.add(r.binder);
509 }
510 }
511 }
512 handleRemoveListLocked();
513 }
514 }
515
516 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700517 public void notifyOpportunisticSubscriptionInfoChanged() {
518 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
519 synchronized (mRecords) {
520 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
521 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
522 + mRecords.size());
523 }
524 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
525 mRemoveList.clear();
526 for (Record r : mRecords) {
527 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
528 try {
529 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
530 r.onOpportunisticSubscriptionsChangedListenerCallback
531 .onSubscriptionsChanged();
532 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
533 } catch (RemoteException ex) {
534 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
535 mRemoveList.add(r.binder);
536 }
537 }
538 }
539 handleRemoveListLocked();
540 }
541 }
542
543 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
545 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800546 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
547 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700548 }
549
550 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700551 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700552 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700553 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700554 }
555
Svet Ganov16a16892015-04-16 10:32:04 -0700556 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700557 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700558 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700560 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700561 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700562 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
563 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700564 }
xinhe75c2c152014-10-16 11:49:45 -0700565
566 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800567 // Checks permission and throws SecurityException for disallowed operations. For pre-M
568 // apps whose runtime permission has been revoked, we return immediately to skip sending
569 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800570 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800571 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700572 }
573
yifan.baie620ce72017-12-22 14:59:57 +0800574 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 synchronized (mRecords) {
576 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800577 IBinder b = callback.asBinder();
578 Record r = add(b);
579
580 if (r == null) {
581 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 }
xinhe43c50292014-09-18 17:56:48 -0700583
Jeff Davidson29da89f2018-02-28 17:50:16 -0800584 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700585 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700586 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800587 r.callerUid = Binder.getCallingUid();
588 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700589 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
590 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800592 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700593 } else {//APP specify subID
594 r.subId = subId;
595 }
yifan.baie620ce72017-12-22 14:59:57 +0800596 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700598 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700599 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700600 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700601 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400603 try {
Wink Savillee380b982014-07-26 18:24:22 -0700604 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700605 r.callback.onServiceStateChanged(
606 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400607 } catch (RemoteException ex) {
608 remove(r.binder);
609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 }
611 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
612 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700613 int gsmSignalStrength = mSignalStrength[phoneId]
614 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700615 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
616 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 } catch (RemoteException ex) {
618 remove(r.binder);
619 }
620 }
621 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
622 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700623 r.callback.onMessageWaitingIndicatorChanged(
624 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 } catch (RemoteException ex) {
626 remove(r.binder);
627 }
628 }
629 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
630 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700631 r.callback.onCallForwardingIndicatorChanged(
632 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 } catch (RemoteException ex) {
634 remove(r.binder);
635 }
636 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700637 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400638 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700639 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700640 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800641 if (checkLocationAccess(r)) {
642 r.callback.onCellLocationChanged(
643 new Bundle(mCellLocation[phoneId]));
644 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400645 } catch (RemoteException ex) {
646 remove(r.binder);
647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 }
649 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
650 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700651 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700652 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 } catch (RemoteException ex) {
654 remove(r.binder);
655 }
656 }
657 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
658 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700659 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
660 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 } catch (RemoteException ex) {
662 remove(r.binder);
663 }
664 }
665 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
666 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700667 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 } catch (RemoteException ex) {
669 remove(r.binder);
670 }
671 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700672 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
673 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700674 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700675 } catch (RemoteException ex) {
676 remove(r.binder);
677 }
678 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700679 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
680 try {
681 r.callback.onOtaspChanged(mOtaspMode);
682 } catch (RemoteException ex) {
683 remove(r.binder);
684 }
685 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700686 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700687 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700688 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700689 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800690 if (checkLocationAccess(r)) {
691 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
692 }
John Wang963db55d2012-03-30 16:04:06 -0700693 } catch (RemoteException ex) {
694 remove(r.binder);
695 }
696 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200697 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
698 try {
699 r.callback.onPreciseCallStateChanged(mPreciseCallState);
700 } catch (RemoteException ex) {
701 remove(r.binder);
702 }
703 }
704 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
705 try {
706 r.callback.onPreciseDataConnectionStateChanged(
707 mPreciseDataConnectionState);
708 } catch (RemoteException ex) {
709 remove(r.binder);
710 }
711 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400712 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
713 try {
714 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
715 } catch (RemoteException ex) {
716 remove(r.binder);
717 }
718 }
fionaxu12312f62016-11-14 13:32:14 -0800719 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
720 try {
721 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
722 } catch (RemoteException ex) {
723 remove(r.binder);
724 }
725 }
726 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
727 try {
728 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
729 } catch (RemoteException ex) {
730 remove(r.binder);
731 }
732 }
zxuan35a47022018-01-04 11:24:04 -0800733 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
734 try {
735 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
736 } catch (RemoteException ex) {
737 remove(r.binder);
738 }
739 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800740 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
741 try {
742 r.callback.onPhysicalChannelConfigurationChanged(
743 mPhysicalChannelConfigs.get(phoneId));
744 } catch (RemoteException ex) {
745 remove(r.binder);
746 }
747 }
Malcolm Chene1623652018-08-08 20:27:45 -0700748 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
749 try {
750 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
751 } catch (RemoteException ex) {
752 remove(r.binder);
753 }
754 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 }
756 }
757 } else {
xinhe75c2c152014-10-16 11:49:45 -0700758 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 remove(callback.asBinder());
760 }
761 }
762
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700763 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700764 // Only reveal the incoming number if the record has read call log permission.
765 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700766 }
767
Malcolm Chenabbfac22018-02-12 19:15:59 -0800768 private Record add(IBinder binder) {
769 Record r;
770
771 synchronized (mRecords) {
772 final int N = mRecords.size();
773 for (int i = 0; i < N; i++) {
774 r = mRecords.get(i);
775 if (binder == r.binder) {
776 // Already existed.
777 return r;
778 }
779 }
780 r = new Record();
781 r.binder = binder;
782 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
783
784 try {
785 binder.linkToDeath(r.deathRecipient, 0);
786 } catch (RemoteException e) {
787 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
788 // Binder already died. Return null.
789 return null;
790 }
791
792 mRecords.add(r);
793 if (DBG) log("add new record");
794 }
795
796 return r;
797 }
798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 private void remove(IBinder binder) {
800 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700801 final int recordCount = mRecords.size();
802 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800803 Record r = mRecords.get(i);
804 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800805 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800806 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
807 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800808 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800809
810 if (r.deathRecipient != null) {
811 try {
812 binder.unlinkToDeath(r.deathRecipient, 0);
813 } catch (NoSuchElementException e) {
814 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
815 + r + " e=" + e);
816 }
817 }
818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 mRecords.remove(i);
820 return;
821 }
822 }
823 }
824 }
825
Tyler Gunnf955e562018-04-26 14:43:31 -0700826 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700827 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700828 return;
829 }
xinhe43c50292014-09-18 17:56:48 -0700830
831 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700832 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700833 }
834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700836 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800837 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800838 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700840 // Ensure the listener has read call log permission; if they do not return
841 // an empty phone number.
842 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
843 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400845 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 }
847 }
848 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400849 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700851
852 // Called only by Telecomm to communicate call state across different phone accounts. So
853 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700854 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700855 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700856 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 }
858
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700859 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
860 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700861 if (!checkNotifyPermission("notifyCallState()")) {
862 return;
863 }
Wink Savillee380b982014-07-26 18:24:22 -0700864 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700865 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700866 + " state=" + state + " incomingNumber=" + incomingNumber);
867 }
868 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700869 if (validatePhoneId(phoneId)) {
870 mCallState[phoneId] = state;
871 mCallIncomingNumber[phoneId] = incomingNumber;
872 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800873 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700874 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800875 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700876 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700877 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
878 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700879 } catch (RemoteException ex) {
880 mRemoveList.add(r.binder);
881 }
882 }
883 }
884 }
885 handleRemoveListLocked();
886 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700887 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700888 }
889
Wink Saville63f03dd2014-10-23 10:44:45 -0700890 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700891 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700892 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700893 }
xinhe43c50292014-09-18 17:56:48 -0700894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700896 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
897 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700898 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700899 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700900 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700901 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700902 if (validatePhoneId(phoneId)) {
903 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700904
Wink Savillefb40dd42014-06-12 17:02:31 -0700905 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700906 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700907 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700908 + " phoneId=" + phoneId + " state=" + state);
909 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800910 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800911 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700912 try {
Wink Savillee380b982014-07-26 18:24:22 -0700913 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700914 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700915 + " subId=" + subId + " phoneId=" + phoneId
916 + " state=" + state);
917 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700918 r.callback.onServiceStateChanged(new ServiceState(state));
919 } catch (RemoteException ex) {
920 mRemoveList.add(r.binder);
921 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400922 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700924 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700925 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400927 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700929 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
931
fionaxu12312f62016-11-14 13:32:14 -0800932 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
933 int activationType, int activationState) {
934 if (!checkNotifyPermission("notifySimActivationState()")){
935 return;
936 }
937 if (VDBG) {
938 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
939 + "type=" + activationType + " state=" + activationState);
940 }
941 synchronized (mRecords) {
942 if (validatePhoneId(phoneId)) {
943 switch (activationType) {
944 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
945 mVoiceActivationState[phoneId] = activationState;
946 break;
947 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
948 mDataActivationState[phoneId] = activationState;
949 break;
950 default:
951 return;
952 }
953 for (Record r : mRecords) {
954 if (VDBG) {
955 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
956 + " phoneId=" + phoneId + "type=" + activationType
957 + " state=" + activationState);
958 }
959 try {
960 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
961 r.matchPhoneStateListenerEvent(
962 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
963 idMatch(r.subId, subId, phoneId)) {
964 if (DBG) {
965 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
966 + " subId=" + subId + " phoneId=" + phoneId
967 + " state=" + activationState);
968 }
969 r.callback.onVoiceActivationStateChanged(activationState);
970 }
971 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
972 r.matchPhoneStateListenerEvent(
973 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
974 idMatch(r.subId, subId, phoneId)) {
975 if (DBG) {
976 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
977 + " subId=" + subId + " phoneId=" + phoneId
978 + " state=" + activationState);
979 }
980 r.callback.onDataActivationStateChanged(activationState);
981 }
982 } catch (RemoteException ex) {
983 mRemoveList.add(r.binder);
984 }
985 }
986 } else {
987 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
988 }
989 handleRemoveListLocked();
990 }
991 }
992
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700993 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
994 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700995 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700996 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700997 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000998 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700999 log("notifySignalStrengthForPhoneId: subId=" + subId
1000 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001001 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001004 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001005 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001006 mSignalStrength[phoneId] = signalStrength;
1007 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001008 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001009 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001010 + " phoneId=" + phoneId + " ss=" + signalStrength);
1011 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001012 if (r.matchPhoneStateListenerEvent(
1013 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001014 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001015 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001016 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001017 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001018 + " subId=" + subId + " phoneId=" + phoneId
1019 + " ss=" + signalStrength);
1020 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001021 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1022 } catch (RemoteException ex) {
1023 mRemoveList.add(r.binder);
1024 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001025 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001026 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001027 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001028 try {
1029 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001030 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001031 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001032 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001033 + " subId=" + subId + " phoneId=" + phoneId
1034 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1035 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001036 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001037 } catch (RemoteException ex) {
1038 mRemoveList.add(r.binder);
1039 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 }
1041 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001042 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001043 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001045 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001047 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 }
1049
Andrew Flynn1f452642015-04-14 22:16:04 -04001050 @Override
1051 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001052 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1053
Andrew Flynn1f452642015-04-14 22:16:04 -04001054 if (VDBG) {
1055 log("notifyCarrierNetworkChange: active=" + active);
1056 }
1057
1058 synchronized (mRecords) {
1059 mCarrierNetworkChangeState = active;
1060 for (Record r : mRecords) {
1061 if (r.matchPhoneStateListenerEvent(
1062 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1063 try {
1064 r.callback.onCarrierNetworkChange(active);
1065 } catch (RemoteException ex) {
1066 mRemoveList.add(r.binder);
1067 }
1068 }
1069 }
1070 handleRemoveListLocked();
1071 }
1072 }
1073
Wink Savilleb208a242012-07-25 14:08:09 -07001074 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001075 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001076 }
1077
Wink Saville63f03dd2014-10-23 10:44:45 -07001078 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001079 if (!checkNotifyPermission("notifyCellInfo()")) {
1080 return;
1081 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001082 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001083 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001084 + " cellInfo=" + cellInfo);
1085 }
yifan.baie620ce72017-12-22 14:59:57 +08001086 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001087 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001088 if (validatePhoneId(phoneId)) {
1089 mCellInfo.set(phoneId, cellInfo);
1090 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001091 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001092 idMatch(r.subId, subId, phoneId) &&
1093 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001094 try {
1095 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001096 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001097 }
1098 r.callback.onCellInfoChanged(cellInfo);
1099 } catch (RemoteException ex) {
1100 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001101 }
John Wang963db55d2012-03-30 16:04:06 -07001102 }
1103 }
1104 }
1105 handleRemoveListLocked();
1106 }
1107 }
1108
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001109 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1110 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1111 configs);
1112 }
1113
1114 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1115 List<PhysicalChannelConfig> configs) {
1116 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1117 return;
1118 }
1119
1120 if (VDBG) {
1121 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1122 }
1123
1124 synchronized (mRecords) {
1125 int phoneId = SubscriptionManager.getPhoneId(subId);
1126 if (validatePhoneId(phoneId)) {
1127 mPhysicalChannelConfigs.set(phoneId, configs);
1128 for (Record r : mRecords) {
1129 if (r.matchPhoneStateListenerEvent(
1130 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1131 && idMatch(r.subId, subId, phoneId)) {
1132 try {
1133 if (DBG_LOC) {
1134 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1135 + configs + " r=" + r);
1136 }
1137 r.callback.onPhysicalChannelConfigurationChanged(configs);
1138 } catch (RemoteException ex) {
1139 mRemoveList.add(r.binder);
1140 }
1141 }
1142 }
1143 }
1144 handleRemoveListLocked();
1145 }
1146 }
1147
xinhe43c50292014-09-18 17:56:48 -07001148 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001149 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001150 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001151 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001152 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001153 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001154 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001155 + " mwi=" + mwi);
1156 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001158 if (validatePhoneId(phoneId)) {
1159 mMessageWaiting[phoneId] = mwi;
1160 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001161 if (r.matchPhoneStateListenerEvent(
1162 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001163 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001164 try {
1165 r.callback.onMessageWaitingIndicatorChanged(mwi);
1166 } catch (RemoteException ex) {
1167 mRemoveList.add(r.binder);
1168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 }
1170 }
1171 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001172 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
1174 }
1175
zxuan35a47022018-01-04 11:24:04 -08001176 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1177 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1178 return;
1179 }
1180 if (VDBG) {
1181 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1182 + " state=" + state);
1183 }
1184 synchronized (mRecords) {
1185 if (validatePhoneId(phoneId)) {
1186 mMessageWaiting[phoneId] = state;
1187 for (Record r : mRecords) {
1188 if (r.matchPhoneStateListenerEvent(
1189 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1190 idMatch(r.subId, subId, phoneId)) {
1191 try {
1192 r.callback.onUserMobileDataStateChanged(state);
1193 } catch (RemoteException ex) {
1194 mRemoveList.add(r.binder);
1195 }
1196 }
1197 }
1198 }
1199 handleRemoveListLocked();
1200 }
1201 }
1202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001204 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001205 }
1206
Wink Saville63f03dd2014-10-23 10:44:45 -07001207 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001208 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001209 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001210 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001211 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001212 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001213 + " cfi=" + cfi);
1214 }
yifan.baie620ce72017-12-22 14:59:57 +08001215 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001217 if (validatePhoneId(phoneId)) {
1218 mCallForwarding[phoneId] = cfi;
1219 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001220 if (r.matchPhoneStateListenerEvent(
1221 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001222 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001223 try {
1224 r.callback.onCallForwardingIndicatorChanged(cfi);
1225 } catch (RemoteException ex) {
1226 mRemoveList.add(r.binder);
1227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 }
1229 }
1230 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001231 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 }
1233 }
1234
1235 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001236 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001237 }
1238
Wink Saville63f03dd2014-10-23 10:44:45 -07001239 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001240 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001241 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001242 }
yifan.baie620ce72017-12-22 14:59:57 +08001243 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001245 if (validatePhoneId(phoneId)) {
1246 mDataActivity[phoneId] = state;
1247 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001248 // Notify by correct subId.
1249 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1250 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001251 try {
1252 r.callback.onDataActivity(state);
1253 } catch (RemoteException ex) {
1254 mRemoveList.add(r.binder);
1255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 }
1257 }
1258 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001259 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 }
1261 }
1262
Jack Yubaeec622017-05-01 17:01:11 -07001263 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001264 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001265 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001266 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001267 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001268 networkCapabilities, networkType, roaming);
1269 }
1270
Wink Saville63f03dd2014-10-23 10:44:45 -07001271 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001272 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001273 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1274 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001275 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001276 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001277 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001278 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001279 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001280 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001281 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001282 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001283 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001284 }
yifan.baie620ce72017-12-22 14:59:57 +08001285 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001287 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001288 // We only call the callback when the change is for default APN type.
1289 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1290 && (mDataConnectionState[phoneId] != state
1291 || mDataConnectionNetworkType[phoneId] != networkType)) {
1292 String str = "onDataConnectionStateChanged(" + state
1293 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001294 log(str);
1295 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001296 for (Record r : mRecords) {
1297 if (r.matchPhoneStateListenerEvent(
1298 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1299 idMatch(r.subId, subId, phoneId)) {
1300 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001301 if (DBG) {
1302 log("Notify data connection state changed on sub: " + subId);
1303 }
Jack Yub1bac542018-03-14 16:23:38 -07001304 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001305 } catch (RemoteException ex) {
1306 mRemoveList.add(r.binder);
1307 }
1308 }
1309 }
1310 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001311
1312 mDataConnectionState[phoneId] = state;
1313 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001314 }
1315 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1316 apnType, apn, reason, linkProperties, "");
1317 for (Record r : mRecords) {
1318 if (r.matchPhoneStateListenerEvent(
1319 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1320 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001321 r.callback.onPreciseDataConnectionStateChanged(
1322 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001323 } catch (RemoteException ex) {
1324 mRemoveList.add(r.binder);
1325 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001326 }
1327 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001328 }
1329 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 }
Jack Yubaeec622017-05-01 17:01:11 -07001331 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001332 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001333 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1334 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 }
1336
Robert Greenwalt02648a42010-05-18 10:52:51 -07001337 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001338 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001339 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001340 }
1341
Wink Saville63f03dd2014-10-23 10:44:45 -07001342 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001343 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001344 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001345 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001346 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001347 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001348 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001349 + " reason=" + reason + " apnType=" + apnType);
1350 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001352 mPreciseDataConnectionState = new PreciseDataConnectionState(
1353 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1354 apnType, "", reason, null, "");
1355 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001356 if (r.matchPhoneStateListenerEvent(
1357 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001358 try {
1359 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1360 } catch (RemoteException ex) {
1361 mRemoveList.add(r.binder);
1362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 }
1364 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001365 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001367 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001368 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1369 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 }
1371
1372 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001373 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001374 }
1375
Wink Saville63f03dd2014-10-23 10:44:45 -07001376 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001377 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001378 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001379 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001380 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001381 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001382 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001383 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001384 + " cellLocation=" + cellLocation);
1385 }
yifan.baie620ce72017-12-22 14:59:57 +08001386 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001387 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001388 if (validatePhoneId(phoneId)) {
1389 mCellLocation[phoneId] = cellLocation;
1390 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001391 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001392 idMatch(r.subId, subId, phoneId) &&
1393 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001394 try {
1395 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001396 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001397 + " r=" + r);
1398 }
1399 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1400 } catch (RemoteException ex) {
1401 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001402 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 }
1405 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001406 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001407 }
1408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409
Wink Savillefd2d0132010-10-28 14:22:26 -07001410 public void notifyOtaspChanged(int otaspMode) {
1411 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1412 return;
1413 }
1414 synchronized (mRecords) {
1415 mOtaspMode = otaspMode;
1416 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001417 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001418 try {
1419 r.callback.onOtaspChanged(otaspMode);
1420 } catch (RemoteException ex) {
1421 mRemoveList.add(r.binder);
1422 }
1423 }
1424 }
1425 handleRemoveListLocked();
1426 }
1427 }
1428
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001429 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1430 int backgroundCallState) {
1431 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1432 return;
1433 }
1434 synchronized (mRecords) {
1435 mRingingCallState = ringingCallState;
1436 mForegroundCallState = foregroundCallState;
1437 mBackgroundCallState = backgroundCallState;
1438 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1439 backgroundCallState,
1440 DisconnectCause.NOT_VALID,
1441 PreciseDisconnectCause.NOT_VALID);
1442 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001443 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001444 try {
1445 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1446 } catch (RemoteException ex) {
1447 mRemoveList.add(r.binder);
1448 }
1449 }
1450 }
1451 handleRemoveListLocked();
1452 }
1453 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1454 DisconnectCause.NOT_VALID,
1455 PreciseDisconnectCause.NOT_VALID);
1456 }
1457
1458 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1459 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1460 return;
1461 }
1462 synchronized (mRecords) {
1463 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1464 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1465 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001466 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001467 try {
1468 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1469 } catch (RemoteException ex) {
1470 mRemoveList.add(r.binder);
1471 }
1472 }
1473 }
1474 handleRemoveListLocked();
1475 }
1476 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1477 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1478 }
1479
1480 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1481 String apn, String failCause) {
1482 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1483 return;
1484 }
1485 synchronized (mRecords) {
1486 mPreciseDataConnectionState = new PreciseDataConnectionState(
1487 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1488 apnType, apn, reason, null, failCause);
1489 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001490 if (r.matchPhoneStateListenerEvent(
1491 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001492 try {
1493 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1494 } catch (RemoteException ex) {
1495 mRemoveList.add(r.binder);
1496 }
1497 }
1498 }
1499 handleRemoveListLocked();
1500 }
1501 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1502 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1503 }
1504
Wink Savillefb40dd42014-06-12 17:02:31 -07001505 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1506 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1507 return;
1508 }
1509 synchronized (mRecords) {
1510 mVoLteServiceState = lteState;
1511 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001512 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001513 try {
1514 r.callback.onVoLteServiceStateChanged(
1515 new VoLteServiceState(mVoLteServiceState));
1516 } catch (RemoteException ex) {
1517 mRemoveList.add(r.binder);
1518 }
1519 }
1520 }
1521 handleRemoveListLocked();
1522 }
1523 }
1524
Shuo Qian066e8652018-04-25 21:02:35 +00001525 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1526 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1527 return;
1528 }
1529
1530 synchronized (mRecords) {
1531 for (Record r : mRecords) {
1532 if (VDBG) {
1533 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1534 }
1535 if ((r.matchPhoneStateListenerEvent(
1536 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1537 ((r.subId == subId) ||
1538 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1539 try {
1540 r.callback.onOemHookRawEvent(rawData);
1541 } catch (RemoteException ex) {
1542 mRemoveList.add(r.binder);
1543 }
1544 }
1545 }
1546 handleRemoveListLocked();
1547 }
1548 }
1549
Malcolm Chene1623652018-08-08 20:27:45 -07001550 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1551 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1552 return;
1553 }
1554
1555 if (VDBG) {
1556 log("notifyPhoneCapabilityChanged: capability=" + capability);
1557 }
1558
1559 synchronized (mRecords) {
1560 mPhoneCapability = capability;
1561
1562 for (Record r : mRecords) {
1563 if (r.matchPhoneStateListenerEvent(
1564 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1565 try {
1566 r.callback.onPhoneCapabilityChanged(capability);
1567 } catch (RemoteException ex) {
1568 mRemoveList.add(r.binder);
1569 }
1570 }
1571 }
1572 handleRemoveListLocked();
1573 }
1574 }
1575
1576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001578 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1579 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1580
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001581 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001584 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001586 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301587 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001588 pw.println("Phone Id=" + i);
1589 pw.increaseIndent();
1590 pw.println("mCallState=" + mCallState[i]);
1591 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1592 pw.println("mServiceState=" + mServiceState[i]);
1593 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1594 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001595 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001596 pw.println("mSignalStrength=" + mSignalStrength[i]);
1597 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1598 pw.println("mCallForwarding=" + mCallForwarding[i]);
1599 pw.println("mDataActivity=" + mDataActivity[i]);
1600 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001601 pw.println("mCellLocation=" + mCellLocation[i]);
1602 pw.println("mCellInfo=" + mCellInfo.get(i));
1603 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301604 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001605 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1606 pw.println("mPreciseCallState=" + mPreciseCallState);
1607 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1608 pw.println("mRingingCallState=" + mRingingCallState);
1609 pw.println("mForegroundCallState=" + mForegroundCallState);
1610 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1611 pw.println("mVoLteServiceState=" + mVoLteServiceState);
Malcolm Chene1623652018-08-08 20:27:45 -07001612 pw.println("mPhoneCapability=" + mPhoneCapability);
Jack Yud19b6ae2017-04-05 14:12:09 -07001613
1614 pw.decreaseIndent();
1615
1616 pw.println("local logs:");
1617 pw.increaseIndent();
1618 mLocalLog.dump(fd, pw, args);
1619 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001620 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001621 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001622 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001623 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001625 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 }
1627 }
1628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 //
1630 // the legacy intent broadcasting
1631 //
1632
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001633 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001634 long ident = Binder.clearCallingIdentity();
1635 try {
1636 mBatteryStats.notePhoneState(state.getState());
1637 } catch (RemoteException re) {
1638 // Can't do much
1639 } finally {
1640 Binder.restoreCallingIdentity(ident);
1641 }
1642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001644 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 Bundle data = new Bundle();
1646 state.fillInNotifierBundle(data);
1647 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001648 // Pass the subscription along with the intent.
1649 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001650 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001651 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 }
1653
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001654 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1655 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001656 long ident = Binder.clearCallingIdentity();
1657 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001658 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001659 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001660 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001661 } finally {
1662 Binder.restoreCallingIdentity(ident);
1663 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001666 Bundle data = new Bundle();
1667 signalStrength.fillInNotifierBundle(data);
1668 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001669 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001670 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001671 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 }
1673
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001674 /**
1675 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1676 * a valid subId, in which case this function fires a subId-specific intent, or it
1677 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1678 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1679 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001680 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1681 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 long ident = Binder.clearCallingIdentity();
1683 try {
1684 if (state == TelephonyManager.CALL_STATE_IDLE) {
1685 mBatteryStats.notePhoneOff();
1686 } else {
1687 mBatteryStats.notePhoneOn();
1688 }
1689 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001690 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 } finally {
1692 Binder.restoreCallingIdentity(ident);
1693 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001696 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001697 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001698
1699 // If a valid subId was specified, we should fire off a subId-specific state
1700 // change intent and include the subId.
1701 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1702 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1703 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1704 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001705 // If the phoneId is invalid, the broadcast is for overall call state.
1706 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1707 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1708 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001709
Brad Ebinger51de96a2017-04-21 17:05:18 -07001710 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1711 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1712
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001713 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001714 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001715 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1716
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001717 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1718 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001719 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001720 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001721 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001722 android.Manifest.permission.READ_PHONE_STATE,
1723 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001724 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1725 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1726 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001727 }
1728
Robert Greenwalt42acef32009-08-12 16:08:25 -07001729 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001730 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001731 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001732 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001733 // Note: not reporting to the battery stats service here, because the
1734 // status bar takes care of that after taking into account all of the
1735 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001737 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001738 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001739 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001740 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001741 }
1742 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001743 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001744 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001745 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001746 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001747 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001748 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001749 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001750 }
1751 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001752 if (networkCapabilities != null) {
1753 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001754 }
Wink Savillea639b312012-07-10 12:37:54 -07001755 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001756
Wink Savillea639b312012-07-10 12:37:54 -07001757 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1758 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001759 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001760 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761 }
1762
Wink Savillefb40dd42014-06-12 17:02:31 -07001763 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001764 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001765 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001766 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1767 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001768 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001769 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001771
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001772 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1773 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1774 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1775 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1776 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1777 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1778 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1779 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1780 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1781 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1782 }
1783
1784 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001785 String apnType, String apn, String reason, LinkProperties linkProperties,
1786 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001787 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1788 intent.putExtra(PhoneConstants.STATE_KEY, state);
1789 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1790 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1791 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1792 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001793 if (linkProperties != null) {
1794 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1795 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001796 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1797
1798 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1799 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1800 }
1801
Andrew Flynnceaed682015-06-09 12:36:58 +00001802 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001803 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001804 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001805 }
1806
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001807 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1808 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001809 }
1810
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001811 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001812 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001813 return true;
1814 }
1815 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001816 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001817 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001818 return false;
1819 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001820
Andrew Flynn1f452642015-04-14 22:16:04 -04001821 private boolean checkNotifyPermission() {
1822 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1823 == PackageManager.PERMISSION_GRANTED;
1824 }
1825
Jeff Davidson29da89f2018-02-28 17:50:16 -08001826 private boolean checkListenerPermission(
1827 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001828 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001829 mContext.enforceCallingOrSelfPermission(
1830 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001831 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1832 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1833 return false;
1834 }
John Wang963db55d2012-03-30 16:04:06 -07001835 }
1836
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001837 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1839 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001840 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001841 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001842 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001843
1844 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1845 mContext.enforceCallingOrSelfPermission(
1846 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001847 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001848
Shuo Qian066e8652018-04-25 21:02:35 +00001849 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1850 mContext.enforceCallingOrSelfPermission(
1851 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1852 }
1853
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001854 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001855 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001856
1857 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001858 int size = mRemoveList.size();
1859 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1860 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001861 for (IBinder b: mRemoveList) {
1862 remove(b);
1863 }
1864 mRemoveList.clear();
1865 }
1866 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001867
1868 private boolean validateEventsAndUserLocked(Record r, int events) {
1869 int foregroundUser;
1870 long callingIdentity = Binder.clearCallingIdentity();
1871 boolean valid = false;
1872 try {
1873 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001874 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1875 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001876 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001877 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001878 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001879 + " r.events=" + r.events + " events=" + events);
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(callingIdentity);
1883 }
1884 return valid;
1885 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001886
1887 private boolean validatePhoneId(int phoneId) {
1888 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001889 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001890 return valid;
1891 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001892
1893 private static void log(String s) {
1894 Rlog.d(TAG, s);
1895 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001896
xinhe8b79fb62014-11-05 14:55:03 -08001897 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001898
1899 if(subId < 0) {
1900 // Invalid case, we need compare phoneId with default one.
1901 return (mDefaultPhoneId == phoneId);
1902 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001903 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001904 return (subId == mDefaultSubId);
1905 } else {
1906 return (rSubId == subId);
1907 }
1908 }
1909
Hall Liu5fb337f2017-11-22 17:38:15 -08001910 private boolean checkLocationAccess(Record r) {
1911 long token = Binder.clearCallingIdentity();
1912 try {
1913 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001914 r.callingPackage, r.callerUid, r.callerPid,
1915 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001916 } finally {
1917 Binder.restoreCallingIdentity(token);
1918 }
1919 }
1920
xinhee9f16402014-09-25 16:39:28 -07001921 private void checkPossibleMissNotify(Record r, int phoneId) {
1922 int events = r.events;
1923
1924 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1925 try {
1926 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1927 mServiceState[phoneId]);
1928 r.callback.onServiceStateChanged(
1929 new ServiceState(mServiceState[phoneId]));
1930 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001931 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001932 }
1933 }
1934
1935 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1936 try {
1937 SignalStrength signalStrength = mSignalStrength[phoneId];
1938 if (DBG) {
1939 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1940 }
1941 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1942 } catch (RemoteException ex) {
1943 mRemoveList.add(r.binder);
1944 }
1945 }
1946
1947 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1948 try {
1949 int gsmSignalStrength = mSignalStrength[phoneId]
1950 .getGsmSignalStrength();
1951 if (DBG) {
1952 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1953 gsmSignalStrength);
1954 }
1955 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1956 : gsmSignalStrength));
1957 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001958 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001959 }
1960 }
1961
1962 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1963 try {
1964 if (DBG_LOC) {
1965 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1966 + mCellInfo.get(phoneId));
1967 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001968 if (checkLocationAccess(r)) {
1969 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1970 }
xinhee9f16402014-09-25 16:39:28 -07001971 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001972 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001973 }
1974 }
1975
zxuan35a47022018-01-04 11:24:04 -08001976 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1977 try {
1978 if (VDBG) {
1979 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1980 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1981 }
1982 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1983 } catch (RemoteException ex) {
1984 mRemoveList.add(r.binder);
1985 }
1986 }
1987
xinhee9f16402014-09-25 16:39:28 -07001988 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1989 try {
1990 if (VDBG) {
1991 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1992 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1993 }
1994 r.callback.onMessageWaitingIndicatorChanged(
1995 mMessageWaiting[phoneId]);
1996 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001997 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001998 }
1999 }
2000
2001 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2002 try {
2003 if (VDBG) {
2004 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2005 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2006 }
2007 r.callback.onCallForwardingIndicatorChanged(
2008 mCallForwarding[phoneId]);
2009 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002010 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002011 }
2012 }
2013
2014 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2015 try {
2016 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2017 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002018 if (checkLocationAccess(r)) {
2019 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2020 }
xinhee9f16402014-09-25 16:39:28 -07002021 } catch (RemoteException ex) {
2022 mRemoveList.add(r.binder);
2023 }
2024 }
2025
2026 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2027 try {
2028 if (DBG) {
2029 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2030 + "=" + mDataConnectionState[phoneId]
2031 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2032 + ")");
2033 }
2034 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2035 mDataConnectionNetworkType[phoneId]);
2036 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002037 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002038 }
2039 }
2040 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041}