blob: 7b29fe5b1c4ea9f42401eed624d6c7127458d915 [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 Chen5ee5c142018-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;
sqianbf165bc2018-12-07 17:09:39 -080050import android.telephony.emergency.EmergencyNumber;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070052import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
Malcolm Chen800a7d62018-08-27 20:38:29 -070054import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080056import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070058import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080059import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070060import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080062import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060063import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070064import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import com.android.server.am.BatteryStatsService;
66
Jack Yud19b6ae2017-04-05 14:12:09 -070067import java.io.FileDescriptor;
68import java.io.PrintWriter;
69import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070070import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080071import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073/**
Wink Savillee9b06d72009-05-18 21:47:50 -070074 * Since phone process can be restarted, this class provides a centralized place
75 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070076 *
77 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
78 * and 15973975 by saving the phoneId of the registrant and then using the
79 * phoneId when deciding to to make a callback. This is necessary because
80 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070081 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070082 * the dummy value conversion we properly do the callbacks.
83 *
84 * Eventually we may want to remove the notion of dummy value but for now this
85 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 */
Malcolm Chen800a7d62018-08-27 20:38:29 -070087@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
88public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070090 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070091 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070092 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
94 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080095 Context context;
96
Svet Ganov16a16892015-04-16 10:32:04 -070097 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
Malcolm Chenabbfac22018-02-12 19:15:59 -0800101 TelephonyRegistryDeathRecipient deathRecipient;
102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800104 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen27829e22018-09-04 22:12:31 -0700105 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
Hall Liu5fb337f2017-11-22 17:38:15 -0800107 int callerUid;
108 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700111
Wink Savilled09c4ca2014-11-22 10:08:16 -0800112 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700113
Wink Savilled09c4ca2014-11-22 10:08:16 -0800114 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800115
116 boolean matchPhoneStateListenerEvent(int events) {
117 return (callback != null) && ((events & this.events) != 0);
118 }
119
Wink Savilled09c4ca2014-11-22 10:08:16 -0800120 boolean matchOnSubscriptionsChangedListener() {
121 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800122 }
Wink Savillee380b982014-07-26 18:24:22 -0700123
Malcolm Chen27829e22018-09-04 22:12:31 -0700124 boolean matchOnOpportunisticSubscriptionsChangedListener() {
125 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
126 }
127
Tyler Gunnf955e562018-04-26 14:43:31 -0700128 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800129 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700130 return TelephonyPermissions.checkReadCallLog(
131 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800132 } catch (SecurityException e) {
133 return false;
134 }
135 }
136
Wink Savillea12a7b32012-09-20 10:09:45 -0700137 @Override
138 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700139 return "{callingPackage=" + callingPackage + " binder=" + binder
140 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800141 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen27829e22018-09-04 22:12:31 -0700142 + onSubscriptionsChangedListenerCallback
143 + " onOpportunisticSubscriptionsChangedListenererCallback="
144 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800145 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800146 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
149
150 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
Joe Onorato163d8d92010-10-21 13:21:20 -0400152 // access should be inside synchronized (mRecords) for these two fields
153 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
154 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 private final IBatteryStats mBatteryStats;
157
Svet Ganov16a16892015-04-16 10:32:04 -0700158 private final AppOpsManager mAppOps;
159
Malcolm Chen27829e22018-09-04 22:12:31 -0700160 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
161
162 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
fionaxu12312f62016-11-14 13:32:14 -0800172 private int[] mVoiceActivationState;
173
174 private int[] mDataActivationState;
175
zxuan35a47022018-01-04 11:24:04 -0800176 private boolean[] mUserMobileDataState;
177
Wink Savillefb40dd42014-06-12 17:02:31 -0700178 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700179
Wink Savillefb40dd42014-06-12 17:02:31 -0700180 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700181
Wink Savillefb40dd42014-06-12 17:02:31 -0700182 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700183
Wink Savillefb40dd42014-06-12 17:02:31 -0700184 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700185
Jack Yub1bac542018-03-14 16:23:38 -0700186 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700187 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700188
Wink Savillefb40dd42014-06-12 17:02:31 -0700189 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700192
Nathan Harold016e9c62016-12-14 11:24:48 -0800193 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700194
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private ArrayList<List<CellInfo>> mCellInfo = null;
196
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800197 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
198
Brad Ebingerefed9822018-10-26 10:25:57 -0700199 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700200
Wink Savilled09c4ca2014-11-22 10:08:16 -0800201 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700202
Wink Savilled09c4ca2014-11-22 10:08:16 -0800203 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700204
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200205 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
206
207 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
208
209 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
210
211 private PreciseCallState mPreciseCallState = new PreciseCallState();
212
chen xu970d7792018-12-12 19:59:30 -0800213 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
214
215 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
216
Andrew Flynn1f452642015-04-14 22:16:04 -0400217 private boolean mCarrierNetworkChangeState = false;
218
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700219 private PhoneCapability mPhoneCapability = null;
220
chen xu760729c2018-10-11 13:18:26 -0700221 @TelephonyManager.RadioPowerState
222 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
223
Malcolm Chenc1873af2018-09-24 20:01:32 -0700224 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
225
Jack Yud19b6ae2017-04-05 14:12:09 -0700226 private final LocalLog mLocalLog = new LocalLog(100);
227
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200228 private PreciseDataConnectionState mPreciseDataConnectionState =
229 new PreciseDataConnectionState();
230
Hall Liu70bbc162018-03-02 17:44:46 -0800231 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
232 PhoneStateListener.LISTEN_CELL_LOCATION
233 | PhoneStateListener.LISTEN_CELL_INFO;
234
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700235 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700236 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Brad Ebingerefed9822018-10-26 10:25:57 -0700237 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700238
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200239 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
240 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
241 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
242
Wink Savillea12a7b32012-09-20 10:09:45 -0700243 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700244 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700245
246 private final Handler mHandler = new Handler() {
247 @Override
248 public void handleMessage(Message msg) {
249 switch (msg.what) {
250 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700251 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700252 int numPhones = TelephonyManager.getDefault().getPhoneCount();
253 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700254 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700255 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700256 }
257 break;
258 }
xinhee9f16402014-09-25 16:39:28 -0700259 case MSG_UPDATE_DEFAULT_SUB: {
260 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700261 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700262 if (VDBG) {
263 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
264 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
265 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
266 }
267
268 //Due to possible risk condition,(notify call back using the new
269 //defaultSubId comes before new defaultSubId update) we need to recall all
270 //possible missed notify callback
271 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700272 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800273 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700274 checkPossibleMissNotify(r, newDefaultPhoneId);
275 }
276 }
277 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700278 }
279 mDefaultSubId = newDefaultSubId;
280 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700281 }
282 }
283 }
284 };
285
Malcolm Chenabbfac22018-02-12 19:15:59 -0800286 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
287
288 private final IBinder binder;
289
290 TelephonyRegistryDeathRecipient(IBinder binder) {
291 this.binder = binder;
292 }
293
294 @Override
295 public void binderDied() {
296 if (DBG) log("binderDied " + binder);
297 remove(binder);
298 }
299 }
300
Wink Savillea12a7b32012-09-20 10:09:45 -0700301 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
302 @Override
303 public void onReceive(Context context, Intent intent) {
304 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700305 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700306 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700307 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700308 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700309 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700310 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700311 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800312 PhoneConstants.SUBSCRIPTION_KEY,
313 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700314 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
315 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700316 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700317 log("onReceive:current mDefaultSubId=" + mDefaultSubId
318 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
319 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700320 }
xinhee9f16402014-09-25 16:39:28 -0700321
Junda Liu985f52c2015-02-23 16:06:51 -0800322 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700323 || (newDefaultPhoneId != mDefaultPhoneId))) {
324 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
325 newDefaultPhoneId, 0, newDefaultSubIdObj));
326 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700327 }
328 }
329 };
330
Wink Savillee9b06d72009-05-18 21:47:50 -0700331 // we keep a copy of all of the state so we can send it out when folks
332 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700334 // In these calls we call with the lock held. This is safe becasuse remote
335 // calls go through a oneway interface and local calls going through a
336 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337
Malcolm Chen800a7d62018-08-27 20:38:29 -0700338 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
339 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700340 CellLocation location = CellLocation.getEmpty();
341
Wink Savillefb40dd42014-06-12 17:02:31 -0700342 mContext = context;
343 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700344
Wink Savillefb40dd42014-06-12 17:02:31 -0700345 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700346 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700347 mNumPhones = numPhones;
348 mCallState = new int[numPhones];
349 mDataActivity = new int[numPhones];
350 mDataConnectionState = new int[numPhones];
351 mDataConnectionNetworkType = new int[numPhones];
352 mCallIncomingNumber = new String[numPhones];
353 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800354 mVoiceActivationState = new int[numPhones];
355 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800356 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700357 mSignalStrength = new SignalStrength[numPhones];
358 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700359 mCallForwarding = new boolean[numPhones];
360 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700361 mCellInfo = new ArrayList<List<CellInfo>>();
Brad Ebingerefed9822018-10-26 10:25:57 -0700362 mSrvccState = new int[numPhones];
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800363 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700364 for (int i = 0; i < numPhones; i++) {
365 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
366 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
367 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800368 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
369 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700370 mCallIncomingNumber[i] = "";
371 mServiceState[i] = new ServiceState();
372 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800373 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700374 mMessageWaiting[i] = false;
375 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700376 mCellLocation[i] = new Bundle();
377 mCellInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700378 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700379 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700380 }
381
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700382 // Note that location can be null for non-phone builds like
383 // like the generic one.
384 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700385 for (int i = 0; i < numPhones; i++) {
386 location.fillInNotifierBundle(mCellLocation[i]);
387 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700388 }
Svet Ganov16a16892015-04-16 10:32:04 -0700389
390 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 }
392
Svetoslav Ganova0027152013-06-25 14:59:53 -0700393 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700394 // Watch for interesting updates
395 final IntentFilter filter = new IntentFilter();
396 filter.addAction(Intent.ACTION_USER_SWITCHED);
397 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700398 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700399 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700400 mContext.registerReceiver(mBroadcastReceiver, filter);
401 }
402
403 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700404 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800405 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700406 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800407 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800408 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700409 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
410 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800411 + " callback.asBinder=" + callback.asBinder());
412 }
413
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 synchronized (mRecords) {
415 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800416 IBinder b = callback.asBinder();
417 Record r = add(b);
418
419 if (r == null) {
420 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800421 }
422
Jeff Davidson29da89f2018-02-28 17:50:16 -0800423 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800424 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700425 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800426 r.callerUid = Binder.getCallingUid();
427 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800428 r.events = 0;
429 if (DBG) {
430 log("listen oscl: Register r=" + r);
431 }
432 // Always notify when registration occurs if there has been a notification.
Malcolm Chen27829e22018-09-04 22:12:31 -0700433 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800434 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800435 if (VDBG) log("listen oscl: send to r=" + r);
436 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
437 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800438 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800440 remove(r.binder);
441 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800442 } else {
Malcolm Chen27829e22018-09-04 22:12:31 -0700443 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800445 }
446 }
447
448 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800449 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800450 IOnSubscriptionsChangedListener callback) {
451 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800452 remove(callback.asBinder());
453 }
454
Malcolm Chen27829e22018-09-04 22:12:31 -0700455
456 @Override
457 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
458 IOnSubscriptionsChangedListener callback) {
459 int callerUserId = UserHandle.getCallingUserId();
460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
461 if (VDBG) {
462 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
463 + " callerUserId=" + callerUserId + " callback=" + callback
464 + " callback.asBinder=" + callback.asBinder());
465 }
466
467 synchronized (mRecords) {
468 // register
469 IBinder b = callback.asBinder();
470 Record r = add(b);
471
472 if (r == null) {
473 return;
474 }
475
476 r.context = mContext;
477 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
478 r.callingPackage = callingPackage;
479 r.callerUid = Binder.getCallingUid();
480 r.callerPid = Binder.getCallingPid();
481 r.events = 0;
482 if (DBG) {
483 log("listen ooscl: Register r=" + r);
484 }
485 // Always notify when registration occurs if there has been a notification.
486 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
487 try {
488 if (VDBG) log("listen ooscl: send to r=" + r);
489 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
490 if (VDBG) log("listen ooscl: sent to r=" + r);
491 } catch (RemoteException e) {
492 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
493 remove(r.binder);
494 }
495 } else {
496 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
497 }
498 }
499 }
500
Wink Savillea374c3d2014-11-11 11:48:04 -0800501 @Override
502 public void notifySubscriptionInfoChanged() {
503 if (VDBG) log("notifySubscriptionInfoChanged:");
504 synchronized (mRecords) {
Malcolm Chen27829e22018-09-04 22:12:31 -0700505 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800506 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
507 + mRecords.size());
508 }
Malcolm Chen27829e22018-09-04 22:12:31 -0700509 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800510 mRemoveList.clear();
511 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800512 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800513 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800514 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
515 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
516 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800517 } catch (RemoteException ex) {
518 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
519 mRemoveList.add(r.binder);
520 }
521 }
522 }
523 handleRemoveListLocked();
524 }
525 }
526
527 @Override
Malcolm Chen27829e22018-09-04 22:12:31 -0700528 public void notifyOpportunisticSubscriptionInfoChanged() {
529 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
530 synchronized (mRecords) {
531 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
532 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
533 + mRecords.size());
534 }
535 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
536 mRemoveList.clear();
537 for (Record r : mRecords) {
538 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
539 try {
540 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
541 r.onOpportunisticSubscriptionsChangedListenerCallback
542 .onSubscriptionsChanged();
543 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
544 } catch (RemoteException ex) {
545 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
546 mRemoveList.add(r.binder);
547 }
548 }
549 }
550 handleRemoveListLocked();
551 }
552 }
553
554 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
556 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800557 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
558 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700559 }
560
561 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700562 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700563 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700564 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700565 }
566
Svet Ganov16a16892015-04-16 10:32:04 -0700567 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700568 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700569 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700571 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700572 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700573 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
574 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700575 }
xinhe75c2c152014-10-16 11:49:45 -0700576
577 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800578 // Checks permission and throws SecurityException for disallowed operations. For pre-M
579 // apps whose runtime permission has been revoked, we return immediately to skip sending
580 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800581 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800582 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700583 }
584
yifan.baie620ce72017-12-22 14:59:57 +0800585 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 synchronized (mRecords) {
587 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800588 IBinder b = callback.asBinder();
589 Record r = add(b);
590
591 if (r == null) {
592 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 }
xinhe43c50292014-09-18 17:56:48 -0700594
Jeff Davidson29da89f2018-02-28 17:50:16 -0800595 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700596 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700597 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800598 r.callerUid = Binder.getCallingUid();
599 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700600 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
601 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800603 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700604 } else {//APP specify subID
605 r.subId = subId;
606 }
yifan.baie620ce72017-12-22 14:59:57 +0800607 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700609 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700610 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700611 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700612 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400614 try {
Wink Savillee380b982014-07-26 18:24:22 -0700615 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700616 r.callback.onServiceStateChanged(
617 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400618 } catch (RemoteException ex) {
619 remove(r.binder);
620 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 }
622 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
623 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700624 int gsmSignalStrength = mSignalStrength[phoneId]
625 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700626 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
627 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 } catch (RemoteException ex) {
629 remove(r.binder);
630 }
631 }
632 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
633 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700634 r.callback.onMessageWaitingIndicatorChanged(
635 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 } catch (RemoteException ex) {
637 remove(r.binder);
638 }
639 }
640 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
641 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700642 r.callback.onCallForwardingIndicatorChanged(
643 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 } catch (RemoteException ex) {
645 remove(r.binder);
646 }
647 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700648 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400649 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700650 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700651 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800652 if (checkLocationAccess(r)) {
653 r.callback.onCellLocationChanged(
654 new Bundle(mCellLocation[phoneId]));
655 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400656 } catch (RemoteException ex) {
657 remove(r.binder);
658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
661 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700662 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700663 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 } catch (RemoteException ex) {
665 remove(r.binder);
666 }
667 }
668 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
669 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700670 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
671 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 } catch (RemoteException ex) {
673 remove(r.binder);
674 }
675 }
676 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
677 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700678 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 } catch (RemoteException ex) {
680 remove(r.binder);
681 }
682 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700683 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
684 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700685 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700686 } catch (RemoteException ex) {
687 remove(r.binder);
688 }
689 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700690 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
691 try {
692 r.callback.onOtaspChanged(mOtaspMode);
693 } catch (RemoteException ex) {
694 remove(r.binder);
695 }
696 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700697 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700698 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700699 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700700 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800701 if (checkLocationAccess(r)) {
702 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
703 }
John Wang963db55d2012-03-30 16:04:06 -0700704 } catch (RemoteException ex) {
705 remove(r.binder);
706 }
707 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200708 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
709 try {
710 r.callback.onPreciseCallStateChanged(mPreciseCallState);
711 } catch (RemoteException ex) {
712 remove(r.binder);
713 }
714 }
chen xu970d7792018-12-12 19:59:30 -0800715 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
716 try {
717 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
718 mCallPreciseDisconnectCause);
719 } catch (RemoteException ex) {
720 remove(r.binder);
721 }
722 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200723 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
724 try {
725 r.callback.onPreciseDataConnectionStateChanged(
726 mPreciseDataConnectionState);
727 } catch (RemoteException ex) {
728 remove(r.binder);
729 }
730 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400731 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
732 try {
733 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
734 } catch (RemoteException ex) {
735 remove(r.binder);
736 }
737 }
fionaxu12312f62016-11-14 13:32:14 -0800738 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
739 try {
740 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
741 } catch (RemoteException ex) {
742 remove(r.binder);
743 }
744 }
745 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
746 try {
747 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
748 } catch (RemoteException ex) {
749 remove(r.binder);
750 }
751 }
zxuan35a47022018-01-04 11:24:04 -0800752 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
753 try {
754 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
755 } catch (RemoteException ex) {
756 remove(r.binder);
757 }
758 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800759 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
760 try {
761 r.callback.onPhysicalChannelConfigurationChanged(
762 mPhysicalChannelConfigs.get(phoneId));
763 } catch (RemoteException ex) {
764 remove(r.binder);
765 }
766 }
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700767 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
768 try {
769 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
770 } catch (RemoteException ex) {
771 remove(r.binder);
772 }
773 }
Malcolm Chenc1873af2018-09-24 20:01:32 -0700774 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
775 try {
776 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
777 } catch (RemoteException ex) {
778 remove(r.binder);
779 }
780 }
chen xu760729c2018-10-11 13:18:26 -0700781 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
782 try {
783 r.callback.onRadioPowerStateChanged(mRadioPowerState);
784 } catch (RemoteException ex) {
785 remove(r.binder);
786 }
787 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700788 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
789 try {
790 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
791 } catch (RemoteException ex) {
792 remove(r.binder);
793 }
794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 }
796 }
797 } else {
xinhe75c2c152014-10-16 11:49:45 -0700798 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 remove(callback.asBinder());
800 }
801 }
802
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700803 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700804 // Only reveal the incoming number if the record has read call log permission.
805 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700806 }
807
Malcolm Chenabbfac22018-02-12 19:15:59 -0800808 private Record add(IBinder binder) {
809 Record r;
810
811 synchronized (mRecords) {
812 final int N = mRecords.size();
813 for (int i = 0; i < N; i++) {
814 r = mRecords.get(i);
815 if (binder == r.binder) {
816 // Already existed.
817 return r;
818 }
819 }
820 r = new Record();
821 r.binder = binder;
822 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
823
824 try {
825 binder.linkToDeath(r.deathRecipient, 0);
826 } catch (RemoteException e) {
827 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
828 // Binder already died. Return null.
829 return null;
830 }
831
832 mRecords.add(r);
833 if (DBG) log("add new record");
834 }
835
836 return r;
837 }
838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 private void remove(IBinder binder) {
840 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700841 final int recordCount = mRecords.size();
842 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800843 Record r = mRecords.get(i);
844 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800845 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800846 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
847 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800848 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800849
850 if (r.deathRecipient != null) {
851 try {
852 binder.unlinkToDeath(r.deathRecipient, 0);
853 } catch (NoSuchElementException e) {
854 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
855 + r + " e=" + e);
856 }
857 }
858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 mRecords.remove(i);
860 return;
861 }
862 }
863 }
864 }
865
Tyler Gunnf955e562018-04-26 14:43:31 -0700866 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700867 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700868 return;
869 }
xinhe43c50292014-09-18 17:56:48 -0700870
871 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700872 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700873 }
874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700876 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800877 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800878 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700880 // Ensure the listener has read call log permission; if they do not return
881 // an empty phone number.
882 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
883 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400885 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 }
887 }
888 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400889 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700891
892 // Called only by Telecomm to communicate call state across different phone accounts. So
893 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700894 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700895 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700896 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 }
898
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700899 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
900 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700901 if (!checkNotifyPermission("notifyCallState()")) {
902 return;
903 }
Wink Savillee380b982014-07-26 18:24:22 -0700904 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700905 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700906 + " state=" + state + " incomingNumber=" + incomingNumber);
907 }
908 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700909 if (validatePhoneId(phoneId)) {
910 mCallState[phoneId] = state;
911 mCallIncomingNumber[phoneId] = incomingNumber;
912 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800913 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700914 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800915 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700916 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700917 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
918 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700919 } catch (RemoteException ex) {
920 mRemoveList.add(r.binder);
921 }
922 }
923 }
924 }
925 handleRemoveListLocked();
926 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700927 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700928 }
929
Wink Saville63f03dd2014-10-23 10:44:45 -0700930 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700931 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700932 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700933 }
xinhe43c50292014-09-18 17:56:48 -0700934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700936 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
937 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700938 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700939 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700940 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700941 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700942 if (validatePhoneId(phoneId)) {
943 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700944
Wink Savillefb40dd42014-06-12 17:02:31 -0700945 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700946 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700947 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700948 + " phoneId=" + phoneId + " state=" + state);
949 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800950 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800951 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700952 try {
Wink Savillee380b982014-07-26 18:24:22 -0700953 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700954 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700955 + " subId=" + subId + " phoneId=" + phoneId
956 + " state=" + state);
957 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700958 r.callback.onServiceStateChanged(new ServiceState(state));
959 } catch (RemoteException ex) {
960 mRemoveList.add(r.binder);
961 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700964 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700965 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400967 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700969 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
971
fionaxu12312f62016-11-14 13:32:14 -0800972 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
973 int activationType, int activationState) {
974 if (!checkNotifyPermission("notifySimActivationState()")){
975 return;
976 }
977 if (VDBG) {
978 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
979 + "type=" + activationType + " state=" + activationState);
980 }
981 synchronized (mRecords) {
982 if (validatePhoneId(phoneId)) {
983 switch (activationType) {
984 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
985 mVoiceActivationState[phoneId] = activationState;
986 break;
987 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
988 mDataActivationState[phoneId] = activationState;
989 break;
990 default:
991 return;
992 }
993 for (Record r : mRecords) {
994 if (VDBG) {
995 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
996 + " phoneId=" + phoneId + "type=" + activationType
997 + " state=" + activationState);
998 }
999 try {
1000 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1001 r.matchPhoneStateListenerEvent(
1002 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1003 idMatch(r.subId, subId, phoneId)) {
1004 if (DBG) {
1005 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1006 + " subId=" + subId + " phoneId=" + phoneId
1007 + " state=" + activationState);
1008 }
1009 r.callback.onVoiceActivationStateChanged(activationState);
1010 }
1011 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1012 r.matchPhoneStateListenerEvent(
1013 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1014 idMatch(r.subId, subId, phoneId)) {
1015 if (DBG) {
1016 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1017 + " subId=" + subId + " phoneId=" + phoneId
1018 + " state=" + activationState);
1019 }
1020 r.callback.onDataActivationStateChanged(activationState);
1021 }
1022 } catch (RemoteException ex) {
1023 mRemoveList.add(r.binder);
1024 }
1025 }
1026 } else {
1027 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1028 }
1029 handleRemoveListLocked();
1030 }
1031 }
1032
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001033 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1034 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001035 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001036 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001037 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001038 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001039 log("notifySignalStrengthForPhoneId: subId=" + subId
1040 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001041 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001044 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001045 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001046 mSignalStrength[phoneId] = signalStrength;
1047 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001048 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001049 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001050 + " phoneId=" + phoneId + " ss=" + signalStrength);
1051 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001052 if (r.matchPhoneStateListenerEvent(
1053 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001054 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001055 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001056 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001057 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001058 + " subId=" + subId + " phoneId=" + phoneId
1059 + " ss=" + signalStrength);
1060 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001061 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1062 } catch (RemoteException ex) {
1063 mRemoveList.add(r.binder);
1064 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001065 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001066 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001067 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001068 try {
1069 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001070 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001071 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001072 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001073 + " subId=" + subId + " phoneId=" + phoneId
1074 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1075 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001076 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001077 } catch (RemoteException ex) {
1078 mRemoveList.add(r.binder);
1079 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 }
1081 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001082 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001083 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001085 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001087 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 }
1089
Andrew Flynn1f452642015-04-14 22:16:04 -04001090 @Override
1091 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001092 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1093
Andrew Flynn1f452642015-04-14 22:16:04 -04001094 if (VDBG) {
1095 log("notifyCarrierNetworkChange: active=" + active);
1096 }
1097
1098 synchronized (mRecords) {
1099 mCarrierNetworkChangeState = active;
1100 for (Record r : mRecords) {
1101 if (r.matchPhoneStateListenerEvent(
1102 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1103 try {
1104 r.callback.onCarrierNetworkChange(active);
1105 } catch (RemoteException ex) {
1106 mRemoveList.add(r.binder);
1107 }
1108 }
1109 }
1110 handleRemoveListLocked();
1111 }
1112 }
1113
Wink Savilleb208a242012-07-25 14:08:09 -07001114 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001115 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001116 }
1117
Wink Saville63f03dd2014-10-23 10:44:45 -07001118 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001119 if (!checkNotifyPermission("notifyCellInfo()")) {
1120 return;
1121 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001122 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001123 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001124 + " cellInfo=" + cellInfo);
1125 }
yifan.baie620ce72017-12-22 14:59:57 +08001126 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001127 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001128 if (validatePhoneId(phoneId)) {
1129 mCellInfo.set(phoneId, cellInfo);
1130 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001131 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001132 idMatch(r.subId, subId, phoneId) &&
1133 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001134 try {
1135 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001136 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001137 }
1138 r.callback.onCellInfoChanged(cellInfo);
1139 } catch (RemoteException ex) {
1140 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001141 }
John Wang963db55d2012-03-30 16:04:06 -07001142 }
1143 }
1144 }
1145 handleRemoveListLocked();
1146 }
1147 }
1148
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001149 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1150 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1151 configs);
1152 }
1153
1154 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1155 List<PhysicalChannelConfig> configs) {
1156 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1157 return;
1158 }
1159
1160 if (VDBG) {
1161 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1162 }
1163
1164 synchronized (mRecords) {
1165 int phoneId = SubscriptionManager.getPhoneId(subId);
1166 if (validatePhoneId(phoneId)) {
1167 mPhysicalChannelConfigs.set(phoneId, configs);
1168 for (Record r : mRecords) {
1169 if (r.matchPhoneStateListenerEvent(
1170 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1171 && idMatch(r.subId, subId, phoneId)) {
1172 try {
1173 if (DBG_LOC) {
1174 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1175 + configs + " r=" + r);
1176 }
1177 r.callback.onPhysicalChannelConfigurationChanged(configs);
1178 } catch (RemoteException ex) {
1179 mRemoveList.add(r.binder);
1180 }
1181 }
1182 }
1183 }
1184 handleRemoveListLocked();
1185 }
1186 }
1187
xinhe43c50292014-09-18 17:56:48 -07001188 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001189 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001190 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001191 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001192 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001193 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001194 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001195 + " mwi=" + mwi);
1196 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001198 if (validatePhoneId(phoneId)) {
1199 mMessageWaiting[phoneId] = mwi;
1200 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001201 if (r.matchPhoneStateListenerEvent(
1202 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001203 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001204 try {
1205 r.callback.onMessageWaitingIndicatorChanged(mwi);
1206 } catch (RemoteException ex) {
1207 mRemoveList.add(r.binder);
1208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 }
1210 }
1211 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001212 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 }
1214 }
1215
zxuan35a47022018-01-04 11:24:04 -08001216 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1217 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1218 return;
1219 }
1220 if (VDBG) {
1221 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1222 + " state=" + state);
1223 }
1224 synchronized (mRecords) {
1225 if (validatePhoneId(phoneId)) {
1226 mMessageWaiting[phoneId] = state;
1227 for (Record r : mRecords) {
1228 if (r.matchPhoneStateListenerEvent(
1229 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1230 idMatch(r.subId, subId, phoneId)) {
1231 try {
1232 r.callback.onUserMobileDataStateChanged(state);
1233 } catch (RemoteException ex) {
1234 mRemoveList.add(r.binder);
1235 }
1236 }
1237 }
1238 }
1239 handleRemoveListLocked();
1240 }
1241 }
1242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001244 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001245 }
1246
Wink Saville63f03dd2014-10-23 10:44:45 -07001247 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001248 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001249 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001250 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001251 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001252 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001253 + " cfi=" + cfi);
1254 }
yifan.baie620ce72017-12-22 14:59:57 +08001255 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001257 if (validatePhoneId(phoneId)) {
1258 mCallForwarding[phoneId] = cfi;
1259 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001260 if (r.matchPhoneStateListenerEvent(
1261 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001262 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001263 try {
1264 r.callback.onCallForwardingIndicatorChanged(cfi);
1265 } catch (RemoteException ex) {
1266 mRemoveList.add(r.binder);
1267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 }
1269 }
1270 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001271 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 }
1273 }
1274
1275 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001276 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001277 }
1278
Wink Saville63f03dd2014-10-23 10:44:45 -07001279 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001280 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001281 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001282 }
yifan.baie620ce72017-12-22 14:59:57 +08001283 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001285 if (validatePhoneId(phoneId)) {
1286 mDataActivity[phoneId] = state;
1287 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001288 // Notify by correct subId.
1289 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1290 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001291 try {
1292 r.callback.onDataActivity(state);
1293 } catch (RemoteException ex) {
1294 mRemoveList.add(r.binder);
1295 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 }
1297 }
1298 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001299 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 }
1301 }
1302
Jack Yubaeec622017-05-01 17:01:11 -07001303 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001304 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001305 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001306 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001307 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001308 networkCapabilities, networkType, roaming);
1309 }
1310
Wink Saville63f03dd2014-10-23 10:44:45 -07001311 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001312 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001313 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1314 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001315 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001316 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001317 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001318 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001319 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001320 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001321 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001322 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001323 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001324 }
yifan.baie620ce72017-12-22 14:59:57 +08001325 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001327 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001328 // We only call the callback when the change is for default APN type.
1329 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1330 && (mDataConnectionState[phoneId] != state
1331 || mDataConnectionNetworkType[phoneId] != networkType)) {
1332 String str = "onDataConnectionStateChanged(" + state
1333 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001334 log(str);
1335 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001336 for (Record r : mRecords) {
1337 if (r.matchPhoneStateListenerEvent(
1338 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1339 idMatch(r.subId, subId, phoneId)) {
1340 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001341 if (DBG) {
1342 log("Notify data connection state changed on sub: " + subId);
1343 }
Jack Yub1bac542018-03-14 16:23:38 -07001344 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001345 } catch (RemoteException ex) {
1346 mRemoveList.add(r.binder);
1347 }
1348 }
1349 }
1350 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001351
1352 mDataConnectionState[phoneId] = state;
1353 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001354 }
1355 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1356 apnType, apn, reason, linkProperties, "");
1357 for (Record r : mRecords) {
1358 if (r.matchPhoneStateListenerEvent(
1359 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1360 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001361 r.callback.onPreciseDataConnectionStateChanged(
1362 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001363 } catch (RemoteException ex) {
1364 mRemoveList.add(r.binder);
1365 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001366 }
1367 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001368 }
1369 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 }
Jack Yubaeec622017-05-01 17:01:11 -07001371 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001372 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001373 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1374 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 }
1376
Robert Greenwalt02648a42010-05-18 10:52:51 -07001377 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001378 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001379 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001380 }
1381
Wink Saville63f03dd2014-10-23 10:44:45 -07001382 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001383 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001384 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001385 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001386 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001387 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001388 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001389 + " reason=" + reason + " apnType=" + apnType);
1390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001392 mPreciseDataConnectionState = new PreciseDataConnectionState(
1393 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1394 apnType, "", reason, null, "");
1395 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001396 if (r.matchPhoneStateListenerEvent(
1397 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001398 try {
1399 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1400 } catch (RemoteException ex) {
1401 mRemoveList.add(r.binder);
1402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001403 }
1404 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001405 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001407 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001408 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1409 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 }
1411
1412 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001413 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001414 }
1415
Wink Saville63f03dd2014-10-23 10:44:45 -07001416 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001417 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001418 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001419 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001420 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001421 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001422 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001423 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001424 + " cellLocation=" + cellLocation);
1425 }
yifan.baie620ce72017-12-22 14:59:57 +08001426 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001428 if (validatePhoneId(phoneId)) {
1429 mCellLocation[phoneId] = cellLocation;
1430 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001431 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001432 idMatch(r.subId, subId, phoneId) &&
1433 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001434 try {
1435 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001436 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001437 + " r=" + r);
1438 }
1439 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1440 } catch (RemoteException ex) {
1441 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001442 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 }
1445 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001446 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001447 }
1448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449
Wink Savillefd2d0132010-10-28 14:22:26 -07001450 public void notifyOtaspChanged(int otaspMode) {
1451 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1452 return;
1453 }
1454 synchronized (mRecords) {
1455 mOtaspMode = otaspMode;
1456 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001457 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001458 try {
1459 r.callback.onOtaspChanged(otaspMode);
1460 } catch (RemoteException ex) {
1461 mRemoveList.add(r.binder);
1462 }
1463 }
1464 }
1465 handleRemoveListLocked();
1466 }
1467 }
1468
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001469 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1470 int backgroundCallState) {
1471 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1472 return;
1473 }
1474 synchronized (mRecords) {
1475 mRingingCallState = ringingCallState;
1476 mForegroundCallState = foregroundCallState;
1477 mBackgroundCallState = backgroundCallState;
1478 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1479 backgroundCallState,
1480 DisconnectCause.NOT_VALID,
1481 PreciseDisconnectCause.NOT_VALID);
1482 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001483 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001484 try {
1485 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1486 } catch (RemoteException ex) {
1487 mRemoveList.add(r.binder);
1488 }
1489 }
1490 }
1491 handleRemoveListLocked();
1492 }
chen xu970d7792018-12-12 19:59:30 -08001493 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1494 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001495 }
1496
1497 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1498 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1499 return;
1500 }
1501 synchronized (mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001502 mCallDisconnectCause = disconnectCause;
1503 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001504 for (Record r : mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001505 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1506 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001507 try {
chen xu970d7792018-12-12 19:59:30 -08001508 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1509 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001510 } catch (RemoteException ex) {
1511 mRemoveList.add(r.binder);
1512 }
1513 }
1514 }
1515 handleRemoveListLocked();
1516 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001517 }
1518
1519 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1520 String apn, String failCause) {
1521 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1522 return;
1523 }
1524 synchronized (mRecords) {
1525 mPreciseDataConnectionState = new PreciseDataConnectionState(
1526 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1527 apnType, apn, reason, null, failCause);
1528 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001529 if (r.matchPhoneStateListenerEvent(
1530 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001531 try {
1532 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1533 } catch (RemoteException ex) {
1534 mRemoveList.add(r.binder);
1535 }
1536 }
1537 }
1538 handleRemoveListLocked();
1539 }
1540 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1541 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1542 }
1543
Brad Ebingerefed9822018-10-26 10:25:57 -07001544 @Override
1545 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1546 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001547 return;
1548 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001549 if (VDBG) {
1550 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1551 }
1552 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001553 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001554 if (validatePhoneId(phoneId)) {
1555 mSrvccState[phoneId] = state;
1556 for (Record r : mRecords) {
1557 if (r.matchPhoneStateListenerEvent(
1558 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1559 idMatch(r.subId, subId, phoneId)) {
1560 try {
1561 if (DBG_LOC) {
1562 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1563 }
1564 r.callback.onSrvccStateChanged(state);
1565 } catch (RemoteException ex) {
1566 mRemoveList.add(r.binder);
1567 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001568 }
1569 }
1570 }
1571 handleRemoveListLocked();
1572 }
1573 }
1574
Shuo Qian066e8652018-04-25 21:02:35 +00001575 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1576 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1577 return;
1578 }
1579
1580 synchronized (mRecords) {
1581 for (Record r : mRecords) {
1582 if (VDBG) {
1583 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1584 }
1585 if ((r.matchPhoneStateListenerEvent(
1586 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1587 ((r.subId == subId) ||
1588 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1589 try {
1590 r.callback.onOemHookRawEvent(rawData);
1591 } catch (RemoteException ex) {
1592 mRemoveList.add(r.binder);
1593 }
1594 }
1595 }
1596 handleRemoveListLocked();
1597 }
1598 }
1599
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001600 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1601 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1602 return;
1603 }
1604
1605 if (VDBG) {
1606 log("notifyPhoneCapabilityChanged: capability=" + capability);
1607 }
1608
1609 synchronized (mRecords) {
1610 mPhoneCapability = capability;
1611
1612 for (Record r : mRecords) {
1613 if (r.matchPhoneStateListenerEvent(
1614 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1615 try {
1616 r.callback.onPhoneCapabilityChanged(capability);
1617 } catch (RemoteException ex) {
1618 mRemoveList.add(r.binder);
1619 }
1620 }
1621 }
1622 handleRemoveListLocked();
1623 }
1624 }
1625
Malcolm Chenc1873af2018-09-24 20:01:32 -07001626 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1627 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1628 return;
1629 }
1630
1631 if (VDBG) {
1632 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1633 }
1634
1635 synchronized (mRecords) {
1636 mPreferredDataSubId = preferredSubId;
1637
1638 for (Record r : mRecords) {
1639 if (r.matchPhoneStateListenerEvent(
1640 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1641 try {
1642 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1643 } catch (RemoteException ex) {
1644 mRemoveList.add(r.binder);
1645 }
1646 }
1647 }
1648 handleRemoveListLocked();
1649 }
1650 }
1651
chen xu760729c2018-10-11 13:18:26 -07001652 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1653 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1654 return;
1655 }
1656
1657 if (VDBG) {
1658 log("notifyRadioPowerStateChanged: state= " + state);
1659 }
1660
1661 synchronized (mRecords) {
1662 mRadioPowerState = state;
1663
1664 for (Record r : mRecords) {
1665 if (r.matchPhoneStateListenerEvent(
1666 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1667 try {
1668 r.callback.onRadioPowerStateChanged(state);
1669 } catch (RemoteException ex) {
1670 mRemoveList.add(r.binder);
1671 }
1672 }
1673 }
1674 handleRemoveListLocked();
1675 }
1676 }
1677
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 @Override
sqianbf165bc2018-12-07 17:09:39 -08001680 public void notifyEmergencyNumberList(List<EmergencyNumber> emergencyNumberList) {
1681 // TODO checkPermission, modify Listener constent documentation
1682 // TODO implement multisim emergency number list update in listener
1683 // TODO implement PhoneStateListenerTest
1684 }
1685
1686
1687 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001688 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1689 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1690
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001691 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001694 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001696 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301697 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001698 pw.println("Phone Id=" + i);
1699 pw.increaseIndent();
1700 pw.println("mCallState=" + mCallState[i]);
1701 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1702 pw.println("mServiceState=" + mServiceState[i]);
1703 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1704 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001705 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001706 pw.println("mSignalStrength=" + mSignalStrength[i]);
1707 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1708 pw.println("mCallForwarding=" + mCallForwarding[i]);
1709 pw.println("mDataActivity=" + mDataActivity[i]);
1710 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001711 pw.println("mCellLocation=" + mCellLocation[i]);
1712 pw.println("mCellInfo=" + mCellInfo.get(i));
1713 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301714 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001715 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1716 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu970d7792018-12-12 19:59:30 -08001717 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1718 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001719 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1720 pw.println("mRingingCallState=" + mRingingCallState);
1721 pw.println("mForegroundCallState=" + mForegroundCallState);
1722 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001723 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001724 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chenc1873af2018-09-24 20:01:32 -07001725 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
chen xu760729c2018-10-11 13:18:26 -07001726 pw.println("mRadioPowerState=" + mRadioPowerState);
Jack Yud19b6ae2017-04-05 14:12:09 -07001727
1728 pw.decreaseIndent();
1729
1730 pw.println("local logs:");
1731 pw.increaseIndent();
1732 mLocalLog.dump(fd, pw, args);
1733 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001734 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001735 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001736 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001737 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001739 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 }
1741 }
1742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001743 //
1744 // the legacy intent broadcasting
1745 //
1746
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001747 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001748 long ident = Binder.clearCallingIdentity();
1749 try {
1750 mBatteryStats.notePhoneState(state.getState());
1751 } catch (RemoteException re) {
1752 // Can't do much
1753 } finally {
1754 Binder.restoreCallingIdentity(ident);
1755 }
1756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001757 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001758 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 Bundle data = new Bundle();
1760 state.fillInNotifierBundle(data);
1761 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001762 // Pass the subscription along with the intent.
1763 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001764 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001765 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001766 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001767 }
1768
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001769 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1770 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001771 long ident = Binder.clearCallingIdentity();
1772 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001773 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001774 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001775 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001776 } finally {
1777 Binder.restoreCallingIdentity(ident);
1778 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001781 Bundle data = new Bundle();
1782 signalStrength.fillInNotifierBundle(data);
1783 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001784 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001785 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001786 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 }
1788
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001789 /**
1790 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1791 * a valid subId, in which case this function fires a subId-specific intent, or it
1792 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1793 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1794 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001795 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1796 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 long ident = Binder.clearCallingIdentity();
1798 try {
1799 if (state == TelephonyManager.CALL_STATE_IDLE) {
1800 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001801 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1802 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 } else {
1804 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001805 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1806 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 }
1808 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001809 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 } finally {
1811 Binder.restoreCallingIdentity(ident);
1812 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001815 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001816 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001817
1818 // If a valid subId was specified, we should fire off a subId-specific state
1819 // change intent and include the subId.
1820 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1821 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1822 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001823 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001824 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001825 // If the phoneId is invalid, the broadcast is for overall call state.
1826 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1827 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1828 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001829
Brad Ebinger51de96a2017-04-21 17:05:18 -07001830 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1831 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1832
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001833 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001834 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001835 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1836
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001837 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1838 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001839 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001840 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001841 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001842 android.Manifest.permission.READ_PHONE_STATE,
1843 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001844 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1845 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1846 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 }
1848
Robert Greenwalt42acef32009-08-12 16:08:25 -07001849 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001850 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001851 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001852 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001853 // Note: not reporting to the battery stats service here, because the
1854 // status bar takes care of that after taking into account all of the
1855 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001857 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001858 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001859 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001860 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 }
1862 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001863 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001865 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001866 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001867 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001868 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001869 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001870 }
1871 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001872 if (networkCapabilities != null) {
1873 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001874 }
Wink Savillea639b312012-07-10 12:37:54 -07001875 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001876
Wink Savillea639b312012-07-10 12:37:54 -07001877 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1878 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001879 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001880 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 }
1882
Wink Savillefb40dd42014-06-12 17:02:31 -07001883 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001884 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001886 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1887 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001888 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001889 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001891
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001892 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
chen xu970d7792018-12-12 19:59:30 -08001893 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001894 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1895 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1896 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1897 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001898 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1899 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1900 }
1901
1902 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001903 String apnType, String apn, String reason, LinkProperties linkProperties,
1904 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001905 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1906 intent.putExtra(PhoneConstants.STATE_KEY, state);
1907 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1908 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1909 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1910 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001911 if (linkProperties != null) {
1912 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1913 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001914 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1915
1916 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1917 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1918 }
1919
Andrew Flynnceaed682015-06-09 12:36:58 +00001920 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001921 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001922 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001923 }
1924
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001925 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1926 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001927 }
1928
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001929 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001930 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001931 return true;
1932 }
1933 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001934 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001935 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001936 return false;
1937 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001938
Andrew Flynn1f452642015-04-14 22:16:04 -04001939 private boolean checkNotifyPermission() {
1940 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1941 == PackageManager.PERMISSION_GRANTED;
1942 }
1943
Jeff Davidson29da89f2018-02-28 17:50:16 -08001944 private boolean checkListenerPermission(
1945 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001946 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001947 mContext.enforceCallingOrSelfPermission(
1948 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001949 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1950 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1951 return false;
1952 }
John Wang963db55d2012-03-30 16:04:06 -07001953 }
1954
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001955 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1957 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001958 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001959 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001960 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001961
1962 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1963 mContext.enforceCallingOrSelfPermission(
1964 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001965 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001966
Shuo Qian066e8652018-04-25 21:02:35 +00001967 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1968 mContext.enforceCallingOrSelfPermission(
1969 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1970 }
1971
Brad Ebingerefed9822018-10-26 10:25:57 -07001972 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
1973 mContext.enforceCallingOrSelfPermission(
1974 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1975 }
1976
1977
chen xu970d7792018-12-12 19:59:30 -08001978 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
1979 mContext.enforceCallingOrSelfPermission(
1980 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1981 }
1982
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001983 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001984 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001985
1986 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001987 int size = mRemoveList.size();
1988 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1989 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001990 for (IBinder b: mRemoveList) {
1991 remove(b);
1992 }
1993 mRemoveList.clear();
1994 }
1995 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001996
1997 private boolean validateEventsAndUserLocked(Record r, int events) {
1998 int foregroundUser;
1999 long callingIdentity = Binder.clearCallingIdentity();
2000 boolean valid = false;
2001 try {
2002 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002003 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2004 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002005 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002006 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002007 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002008 + " r.events=" + r.events + " events=" + events);
2009 }
2010 } finally {
2011 Binder.restoreCallingIdentity(callingIdentity);
2012 }
2013 return valid;
2014 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002015
2016 private boolean validatePhoneId(int phoneId) {
2017 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002018 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002019 return valid;
2020 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002021
2022 private static void log(String s) {
2023 Rlog.d(TAG, s);
2024 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002025
xinhe8b79fb62014-11-05 14:55:03 -08002026 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002027
2028 if(subId < 0) {
2029 // Invalid case, we need compare phoneId with default one.
2030 return (mDefaultPhoneId == phoneId);
2031 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002032 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002033 return (subId == mDefaultSubId);
2034 } else {
2035 return (rSubId == subId);
2036 }
2037 }
2038
Hall Liu5fb337f2017-11-22 17:38:15 -08002039 private boolean checkLocationAccess(Record r) {
2040 long token = Binder.clearCallingIdentity();
2041 try {
2042 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08002043 r.callingPackage, r.callerUid, r.callerPid,
2044 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08002045 } finally {
2046 Binder.restoreCallingIdentity(token);
2047 }
2048 }
2049
xinhee9f16402014-09-25 16:39:28 -07002050 private void checkPossibleMissNotify(Record r, int phoneId) {
2051 int events = r.events;
2052
2053 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2054 try {
2055 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2056 mServiceState[phoneId]);
2057 r.callback.onServiceStateChanged(
2058 new ServiceState(mServiceState[phoneId]));
2059 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002060 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002061 }
2062 }
2063
2064 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2065 try {
2066 SignalStrength signalStrength = mSignalStrength[phoneId];
2067 if (DBG) {
2068 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2069 }
2070 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2071 } catch (RemoteException ex) {
2072 mRemoveList.add(r.binder);
2073 }
2074 }
2075
2076 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2077 try {
2078 int gsmSignalStrength = mSignalStrength[phoneId]
2079 .getGsmSignalStrength();
2080 if (DBG) {
2081 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2082 gsmSignalStrength);
2083 }
2084 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2085 : gsmSignalStrength));
2086 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002087 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002088 }
2089 }
2090
2091 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2092 try {
2093 if (DBG_LOC) {
2094 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2095 + mCellInfo.get(phoneId));
2096 }
Hall Liu5fb337f2017-11-22 17:38:15 -08002097 if (checkLocationAccess(r)) {
2098 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2099 }
xinhee9f16402014-09-25 16:39:28 -07002100 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002101 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002102 }
2103 }
2104
zxuan35a47022018-01-04 11:24:04 -08002105 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2106 try {
2107 if (VDBG) {
2108 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2109 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2110 }
2111 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2112 } catch (RemoteException ex) {
2113 mRemoveList.add(r.binder);
2114 }
2115 }
2116
xinhee9f16402014-09-25 16:39:28 -07002117 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2118 try {
2119 if (VDBG) {
2120 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2121 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2122 }
2123 r.callback.onMessageWaitingIndicatorChanged(
2124 mMessageWaiting[phoneId]);
2125 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002126 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002127 }
2128 }
2129
2130 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2131 try {
2132 if (VDBG) {
2133 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2134 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2135 }
2136 r.callback.onCallForwardingIndicatorChanged(
2137 mCallForwarding[phoneId]);
2138 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002139 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002140 }
2141 }
2142
2143 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2144 try {
2145 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2146 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002147 if (checkLocationAccess(r)) {
2148 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2149 }
xinhee9f16402014-09-25 16:39:28 -07002150 } catch (RemoteException ex) {
2151 mRemoveList.add(r.binder);
2152 }
2153 }
2154
2155 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2156 try {
2157 if (DBG) {
2158 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2159 + "=" + mDataConnectionState[phoneId]
2160 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2161 + ")");
2162 }
2163 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2164 mDataConnectionNetworkType[phoneId]);
2165 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002166 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002167 }
2168 }
2169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170}