blob: 32c9ce13a2494326e8818489c893d3bac3b5cc27 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080038import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070039import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070040import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080041import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020042import android.telephony.PreciseCallState;
43import android.telephony.PreciseDataConnectionState;
44import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070045import android.telephony.Rlog;
46import android.telephony.ServiceState;
47import android.telephony.SignalStrength;
48import android.telephony.SubscriptionManager;
49import android.telephony.TelephonyManager;
50import android.telephony.VoLteServiceState;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070053import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080055import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070057import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080058import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070059import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080061import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060062import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070063import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import com.android.server.am.BatteryStatsService;
65
Jack Yud19b6ae2017-04-05 14:12:09 -070066import java.io.FileDescriptor;
67import java.io.PrintWriter;
68import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070069import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080070import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072/**
Wink Savillee9b06d72009-05-18 21:47:50 -070073 * Since phone process can be restarted, this class provides a centralized place
74 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070075 *
76 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
77 * and 15973975 by saving the phoneId of the registrant and then using the
78 * phoneId when deciding to to make a callback. This is necessary because
79 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070080 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070081 * the dummy value conversion we properly do the callbacks.
82 *
83 * Eventually we may want to remove the notion of dummy value but for now this
84 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070086@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
87public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070089 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070090 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070091 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080094 Context context;
95
Svet Ganov16a16892015-04-16 10:32:04 -070096 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070099
Malcolm Chenabbfac22018-02-12 19:15:59 -0800100 TelephonyRegistryDeathRecipient deathRecipient;
101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800103 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700104 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700105
Hall Liu5fb337f2017-11-22 17:38:15 -0800106 int callerUid;
107 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700110
Wink Savilled09c4ca2014-11-22 10:08:16 -0800111 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700112
Wink Savilled09c4ca2014-11-22 10:08:16 -0800113 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800114
115 boolean matchPhoneStateListenerEvent(int events) {
116 return (callback != null) && ((events & this.events) != 0);
117 }
118
Wink Savilled09c4ca2014-11-22 10:08:16 -0800119 boolean matchOnSubscriptionsChangedListener() {
120 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800121 }
Wink Savillee380b982014-07-26 18:24:22 -0700122
Malcolm Chen13f31af2018-09-04 22:12:31 -0700123 boolean matchOnOpportunisticSubscriptionsChangedListener() {
124 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
125 }
126
Tyler Gunnf955e562018-04-26 14:43:31 -0700127 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800128 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700129 return TelephonyPermissions.checkReadCallLog(
130 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800131 } catch (SecurityException e) {
132 return false;
133 }
134 }
135
Wink Savillea12a7b32012-09-20 10:09:45 -0700136 @Override
137 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700138 return "{callingPackage=" + callingPackage + " binder=" + binder
139 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800140 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700141 + onSubscriptionsChangedListenerCallback
142 + " onOpportunisticSubscriptionsChangedListenererCallback="
143 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800144 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800145 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 }
148
149 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700150
Joe Onorato163d8d92010-10-21 13:21:20 -0400151 // access should be inside synchronized (mRecords) for these two fields
152 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
153 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 private final IBatteryStats mBatteryStats;
156
Svet Ganov16a16892015-04-16 10:32:04 -0700157 private final AppOpsManager mAppOps;
158
Malcolm Chen13f31af2018-09-04 22:12:31 -0700159 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
160
161 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800162
Wink Savillefb40dd42014-06-12 17:02:31 -0700163 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700164
Wink Savillefb40dd42014-06-12 17:02:31 -0700165 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700166
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700168
Wink Savillefb40dd42014-06-12 17:02:31 -0700169 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700170
fionaxu12312f62016-11-14 13:32:14 -0800171 private int[] mVoiceActivationState;
172
173 private int[] mDataActivationState;
174
zxuan35a47022018-01-04 11:24:04 -0800175 private boolean[] mUserMobileDataState;
176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700180
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700182
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700184
Jack Yub1bac542018-03-14 16:23:38 -0700185 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700191
Nathan Harold016e9c62016-12-14 11:24:48 -0800192 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700193
Wink Savillefb40dd42014-06-12 17:02:31 -0700194 private ArrayList<List<CellInfo>> mCellInfo = null;
195
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800196 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
197
Wink Savillefb40dd42014-06-12 17:02:31 -0700198 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
199
Wink Savilled09c4ca2014-11-22 10:08:16 -0800200 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700201
Wink Savilled09c4ca2014-11-22 10:08:16 -0800202 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700203
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200204 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
205
206 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
207
208 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
209
210 private PreciseCallState mPreciseCallState = new PreciseCallState();
211
Andrew Flynn1f452642015-04-14 22:16:04 -0400212 private boolean mCarrierNetworkChangeState = false;
213
Malcolm Chene1623652018-08-08 20:27:45 -0700214 private PhoneCapability mPhoneCapability = null;
215
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700216 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
217
Jack Yud19b6ae2017-04-05 14:12:09 -0700218 private final LocalLog mLocalLog = new LocalLog(100);
219
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200220 private PreciseDataConnectionState mPreciseDataConnectionState =
221 new PreciseDataConnectionState();
222
Hall Liu70bbc162018-03-02 17:44:46 -0800223 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
224 PhoneStateListener.LISTEN_CELL_LOCATION
225 | PhoneStateListener.LISTEN_CELL_INFO;
226
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700227 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700228 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700229 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
230 PhoneStateListener.LISTEN_VOLTE_STATE;
231
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200232 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
233 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
234 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
235
Wink Savillea12a7b32012-09-20 10:09:45 -0700236 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700237 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700238
239 private final Handler mHandler = new Handler() {
240 @Override
241 public void handleMessage(Message msg) {
242 switch (msg.what) {
243 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700244 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700245 int numPhones = TelephonyManager.getDefault().getPhoneCount();
246 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700247 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700248 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700249 }
250 break;
251 }
xinhee9f16402014-09-25 16:39:28 -0700252 case MSG_UPDATE_DEFAULT_SUB: {
253 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700254 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700255 if (VDBG) {
256 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
257 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
258 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
259 }
260
261 //Due to possible risk condition,(notify call back using the new
262 //defaultSubId comes before new defaultSubId update) we need to recall all
263 //possible missed notify callback
264 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700265 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800266 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700267 checkPossibleMissNotify(r, newDefaultPhoneId);
268 }
269 }
270 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700271 }
272 mDefaultSubId = newDefaultSubId;
273 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700274 }
275 }
276 }
277 };
278
Malcolm Chenabbfac22018-02-12 19:15:59 -0800279 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
280
281 private final IBinder binder;
282
283 TelephonyRegistryDeathRecipient(IBinder binder) {
284 this.binder = binder;
285 }
286
287 @Override
288 public void binderDied() {
289 if (DBG) log("binderDied " + binder);
290 remove(binder);
291 }
292 }
293
Wink Savillea12a7b32012-09-20 10:09:45 -0700294 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
295 @Override
296 public void onReceive(Context context, Intent intent) {
297 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700298 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700299 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700300 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700301 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700302 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700303 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700304 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800305 PhoneConstants.SUBSCRIPTION_KEY,
306 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700307 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
308 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700309 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700310 log("onReceive:current mDefaultSubId=" + mDefaultSubId
311 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
312 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700313 }
xinhee9f16402014-09-25 16:39:28 -0700314
Junda Liu985f52c2015-02-23 16:06:51 -0800315 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700316 || (newDefaultPhoneId != mDefaultPhoneId))) {
317 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
318 newDefaultPhoneId, 0, newDefaultSubIdObj));
319 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700320 }
321 }
322 };
323
Wink Savillee9b06d72009-05-18 21:47:50 -0700324 // we keep a copy of all of the state so we can send it out when folks
325 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700327 // In these calls we call with the lock held. This is safe becasuse remote
328 // calls go through a oneway interface and local calls going through a
329 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700331 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
332 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700333 CellLocation location = CellLocation.getEmpty();
334
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 mContext = context;
336 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700337
Wink Savillefb40dd42014-06-12 17:02:31 -0700338 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700339 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700340 mNumPhones = numPhones;
341 mCallState = new int[numPhones];
342 mDataActivity = new int[numPhones];
343 mDataConnectionState = new int[numPhones];
344 mDataConnectionNetworkType = new int[numPhones];
345 mCallIncomingNumber = new String[numPhones];
346 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800347 mVoiceActivationState = new int[numPhones];
348 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800349 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700350 mSignalStrength = new SignalStrength[numPhones];
351 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 mCallForwarding = new boolean[numPhones];
353 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800355 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700356 for (int i = 0; i < numPhones; i++) {
357 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
358 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
359 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800360 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
361 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700362 mCallIncomingNumber[i] = "";
363 mServiceState[i] = new ServiceState();
364 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800365 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 mMessageWaiting[i] = false;
367 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700368 mCellLocation[i] = new Bundle();
369 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700370 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700371 }
372
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700373 // Note that location can be null for non-phone builds like
374 // like the generic one.
375 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700376 for (int i = 0; i < numPhones; i++) {
377 location.fillInNotifierBundle(mCellLocation[i]);
378 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700379 }
Svet Ganov16a16892015-04-16 10:32:04 -0700380
381 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 }
383
Svetoslav Ganova0027152013-06-25 14:59:53 -0700384 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700385 // Watch for interesting updates
386 final IntentFilter filter = new IntentFilter();
387 filter.addAction(Intent.ACTION_USER_SWITCHED);
388 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700389 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700390 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700391 mContext.registerReceiver(mBroadcastReceiver, filter);
392 }
393
394 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700395 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800396 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700397 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800399 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700400 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
401 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800402 + " callback.asBinder=" + callback.asBinder());
403 }
404
Wink Savilled09c4ca2014-11-22 10:08:16 -0800405 synchronized (mRecords) {
406 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800407 IBinder b = callback.asBinder();
408 Record r = add(b);
409
410 if (r == null) {
411 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800412 }
413
Jeff Davidson29da89f2018-02-28 17:50:16 -0800414 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800415 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700416 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800417 r.callerUid = Binder.getCallingUid();
418 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 r.events = 0;
420 if (DBG) {
421 log("listen oscl: Register r=" + r);
422 }
423 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700424 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800426 if (VDBG) log("listen oscl: send to r=" + r);
427 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
428 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800429 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800430 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800431 remove(r.binder);
432 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800433 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700434 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800436 }
437 }
438
439 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800440 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800441 IOnSubscriptionsChangedListener callback) {
442 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800443 remove(callback.asBinder());
444 }
445
Malcolm Chen13f31af2018-09-04 22:12:31 -0700446
447 @Override
448 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
449 IOnSubscriptionsChangedListener callback) {
450 int callerUserId = UserHandle.getCallingUserId();
451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
452 if (VDBG) {
453 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
454 + " callerUserId=" + callerUserId + " callback=" + callback
455 + " callback.asBinder=" + callback.asBinder());
456 }
457
458 synchronized (mRecords) {
459 // register
460 IBinder b = callback.asBinder();
461 Record r = add(b);
462
463 if (r == null) {
464 return;
465 }
466
467 r.context = mContext;
468 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
469 r.callingPackage = callingPackage;
470 r.callerUid = Binder.getCallingUid();
471 r.callerPid = Binder.getCallingPid();
472 r.events = 0;
473 if (DBG) {
474 log("listen ooscl: Register r=" + r);
475 }
476 // Always notify when registration occurs if there has been a notification.
477 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
478 try {
479 if (VDBG) log("listen ooscl: send to r=" + r);
480 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
481 if (VDBG) log("listen ooscl: sent to r=" + r);
482 } catch (RemoteException e) {
483 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
484 remove(r.binder);
485 }
486 } else {
487 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
488 }
489 }
490 }
491
Wink Savillea374c3d2014-11-11 11:48:04 -0800492 @Override
493 public void notifySubscriptionInfoChanged() {
494 if (VDBG) log("notifySubscriptionInfoChanged:");
495 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700496 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800497 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
498 + mRecords.size());
499 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700500 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800501 mRemoveList.clear();
502 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800503 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800504 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800505 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
506 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
507 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800508 } catch (RemoteException ex) {
509 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
510 mRemoveList.add(r.binder);
511 }
512 }
513 }
514 handleRemoveListLocked();
515 }
516 }
517
518 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700519 public void notifyOpportunisticSubscriptionInfoChanged() {
520 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
521 synchronized (mRecords) {
522 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
523 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
524 + mRecords.size());
525 }
526 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
527 mRemoveList.clear();
528 for (Record r : mRecords) {
529 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
530 try {
531 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
532 r.onOpportunisticSubscriptionsChangedListenerCallback
533 .onSubscriptionsChanged();
534 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
535 } catch (RemoteException ex) {
536 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
537 mRemoveList.add(r.binder);
538 }
539 }
540 }
541 handleRemoveListLocked();
542 }
543 }
544
545 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
547 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800548 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
549 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700550 }
551
552 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700553 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700554 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700555 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700556 }
557
Svet Ganov16a16892015-04-16 10:32:04 -0700558 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700559 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700560 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800561 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700562 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700563 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700564 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
565 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700566 }
xinhe75c2c152014-10-16 11:49:45 -0700567
568 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800569 // Checks permission and throws SecurityException for disallowed operations. For pre-M
570 // apps whose runtime permission has been revoked, we return immediately to skip sending
571 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800572 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800573 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700574 }
575
yifan.baie620ce72017-12-22 14:59:57 +0800576 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 synchronized (mRecords) {
578 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800579 IBinder b = callback.asBinder();
580 Record r = add(b);
581
582 if (r == null) {
583 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 }
xinhe43c50292014-09-18 17:56:48 -0700585
Jeff Davidson29da89f2018-02-28 17:50:16 -0800586 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700587 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700588 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800589 r.callerUid = Binder.getCallingUid();
590 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700591 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
592 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800593 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800594 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700595 } else {//APP specify subID
596 r.subId = subId;
597 }
yifan.baie620ce72017-12-22 14:59:57 +0800598 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700600 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700601 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700602 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700603 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400605 try {
Wink Savillee380b982014-07-26 18:24:22 -0700606 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700607 r.callback.onServiceStateChanged(
608 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400609 } catch (RemoteException ex) {
610 remove(r.binder);
611 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
613 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
614 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700615 int gsmSignalStrength = mSignalStrength[phoneId]
616 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700617 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
618 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 } catch (RemoteException ex) {
620 remove(r.binder);
621 }
622 }
623 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
624 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700625 r.callback.onMessageWaitingIndicatorChanged(
626 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 } catch (RemoteException ex) {
628 remove(r.binder);
629 }
630 }
631 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
632 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700633 r.callback.onCallForwardingIndicatorChanged(
634 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 } catch (RemoteException ex) {
636 remove(r.binder);
637 }
638 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700639 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400640 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700641 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700642 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800643 if (checkLocationAccess(r)) {
644 r.callback.onCellLocationChanged(
645 new Bundle(mCellLocation[phoneId]));
646 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400647 } catch (RemoteException ex) {
648 remove(r.binder);
649 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 }
651 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
652 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700653 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700654 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 } catch (RemoteException ex) {
656 remove(r.binder);
657 }
658 }
659 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
660 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700661 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
662 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 } catch (RemoteException ex) {
664 remove(r.binder);
665 }
666 }
667 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
668 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700669 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 } catch (RemoteException ex) {
671 remove(r.binder);
672 }
673 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700674 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
675 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700676 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700677 } catch (RemoteException ex) {
678 remove(r.binder);
679 }
680 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700681 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
682 try {
683 r.callback.onOtaspChanged(mOtaspMode);
684 } catch (RemoteException ex) {
685 remove(r.binder);
686 }
687 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700688 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700689 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700690 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700691 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800692 if (checkLocationAccess(r)) {
693 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
694 }
John Wang963db55d2012-03-30 16:04:06 -0700695 } catch (RemoteException ex) {
696 remove(r.binder);
697 }
698 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200699 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
700 try {
701 r.callback.onPreciseCallStateChanged(mPreciseCallState);
702 } catch (RemoteException ex) {
703 remove(r.binder);
704 }
705 }
706 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
707 try {
708 r.callback.onPreciseDataConnectionStateChanged(
709 mPreciseDataConnectionState);
710 } catch (RemoteException ex) {
711 remove(r.binder);
712 }
713 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400714 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
715 try {
716 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
717 } catch (RemoteException ex) {
718 remove(r.binder);
719 }
720 }
fionaxu12312f62016-11-14 13:32:14 -0800721 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
722 try {
723 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
724 } catch (RemoteException ex) {
725 remove(r.binder);
726 }
727 }
728 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
729 try {
730 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
731 } catch (RemoteException ex) {
732 remove(r.binder);
733 }
734 }
zxuan35a47022018-01-04 11:24:04 -0800735 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
736 try {
737 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
738 } catch (RemoteException ex) {
739 remove(r.binder);
740 }
741 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800742 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
743 try {
744 r.callback.onPhysicalChannelConfigurationChanged(
745 mPhysicalChannelConfigs.get(phoneId));
746 } catch (RemoteException ex) {
747 remove(r.binder);
748 }
749 }
Malcolm Chene1623652018-08-08 20:27:45 -0700750 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
751 try {
752 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
753 } catch (RemoteException ex) {
754 remove(r.binder);
755 }
756 }
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700757 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
758 try {
759 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
760 } catch (RemoteException ex) {
761 remove(r.binder);
762 }
763 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 }
765 }
766 } else {
xinhe75c2c152014-10-16 11:49:45 -0700767 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 remove(callback.asBinder());
769 }
770 }
771
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700772 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700773 // Only reveal the incoming number if the record has read call log permission.
774 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700775 }
776
Malcolm Chenabbfac22018-02-12 19:15:59 -0800777 private Record add(IBinder binder) {
778 Record r;
779
780 synchronized (mRecords) {
781 final int N = mRecords.size();
782 for (int i = 0; i < N; i++) {
783 r = mRecords.get(i);
784 if (binder == r.binder) {
785 // Already existed.
786 return r;
787 }
788 }
789 r = new Record();
790 r.binder = binder;
791 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
792
793 try {
794 binder.linkToDeath(r.deathRecipient, 0);
795 } catch (RemoteException e) {
796 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
797 // Binder already died. Return null.
798 return null;
799 }
800
801 mRecords.add(r);
802 if (DBG) log("add new record");
803 }
804
805 return r;
806 }
807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 private void remove(IBinder binder) {
809 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700810 final int recordCount = mRecords.size();
811 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800812 Record r = mRecords.get(i);
813 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800814 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800815 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
816 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800817 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800818
819 if (r.deathRecipient != null) {
820 try {
821 binder.unlinkToDeath(r.deathRecipient, 0);
822 } catch (NoSuchElementException e) {
823 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
824 + r + " e=" + e);
825 }
826 }
827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 mRecords.remove(i);
829 return;
830 }
831 }
832 }
833 }
834
Tyler Gunnf955e562018-04-26 14:43:31 -0700835 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700836 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700837 return;
838 }
xinhe43c50292014-09-18 17:56:48 -0700839
840 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700841 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700842 }
843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700845 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800846 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800847 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700849 // Ensure the listener has read call log permission; if they do not return
850 // an empty phone number.
851 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
852 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400854 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 }
856 }
857 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400858 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700860
861 // Called only by Telecomm to communicate call state across different phone accounts. So
862 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700863 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700864 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700865 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 }
867
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700868 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
869 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700870 if (!checkNotifyPermission("notifyCallState()")) {
871 return;
872 }
Wink Savillee380b982014-07-26 18:24:22 -0700873 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700874 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700875 + " state=" + state + " incomingNumber=" + incomingNumber);
876 }
877 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700878 if (validatePhoneId(phoneId)) {
879 mCallState[phoneId] = state;
880 mCallIncomingNumber[phoneId] = incomingNumber;
881 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800882 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700883 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800884 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700885 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700886 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
887 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700888 } catch (RemoteException ex) {
889 mRemoveList.add(r.binder);
890 }
891 }
892 }
893 }
894 handleRemoveListLocked();
895 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700896 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700897 }
898
Wink Saville63f03dd2014-10-23 10:44:45 -0700899 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700900 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700901 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700902 }
xinhe43c50292014-09-18 17:56:48 -0700903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700905 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
906 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700907 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700908 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700909 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700910 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700911 if (validatePhoneId(phoneId)) {
912 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700913
Wink Savillefb40dd42014-06-12 17:02:31 -0700914 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700915 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700916 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700917 + " phoneId=" + phoneId + " state=" + state);
918 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800919 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800920 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700921 try {
Wink Savillee380b982014-07-26 18:24:22 -0700922 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700923 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700924 + " subId=" + subId + " phoneId=" + phoneId
925 + " state=" + state);
926 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700927 r.callback.onServiceStateChanged(new ServiceState(state));
928 } catch (RemoteException ex) {
929 mRemoveList.add(r.binder);
930 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400931 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700933 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700934 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400936 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700938 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 }
940
fionaxu12312f62016-11-14 13:32:14 -0800941 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
942 int activationType, int activationState) {
943 if (!checkNotifyPermission("notifySimActivationState()")){
944 return;
945 }
946 if (VDBG) {
947 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
948 + "type=" + activationType + " state=" + activationState);
949 }
950 synchronized (mRecords) {
951 if (validatePhoneId(phoneId)) {
952 switch (activationType) {
953 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
954 mVoiceActivationState[phoneId] = activationState;
955 break;
956 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
957 mDataActivationState[phoneId] = activationState;
958 break;
959 default:
960 return;
961 }
962 for (Record r : mRecords) {
963 if (VDBG) {
964 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
965 + " phoneId=" + phoneId + "type=" + activationType
966 + " state=" + activationState);
967 }
968 try {
969 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
970 r.matchPhoneStateListenerEvent(
971 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
972 idMatch(r.subId, subId, phoneId)) {
973 if (DBG) {
974 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
975 + " subId=" + subId + " phoneId=" + phoneId
976 + " state=" + activationState);
977 }
978 r.callback.onVoiceActivationStateChanged(activationState);
979 }
980 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
981 r.matchPhoneStateListenerEvent(
982 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
983 idMatch(r.subId, subId, phoneId)) {
984 if (DBG) {
985 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
986 + " subId=" + subId + " phoneId=" + phoneId
987 + " state=" + activationState);
988 }
989 r.callback.onDataActivationStateChanged(activationState);
990 }
991 } catch (RemoteException ex) {
992 mRemoveList.add(r.binder);
993 }
994 }
995 } else {
996 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
997 }
998 handleRemoveListLocked();
999 }
1000 }
1001
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001002 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1003 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001004 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001005 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001006 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001007 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001008 log("notifySignalStrengthForPhoneId: subId=" + subId
1009 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001010 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001013 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001014 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001015 mSignalStrength[phoneId] = signalStrength;
1016 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001017 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001018 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001019 + " phoneId=" + phoneId + " ss=" + signalStrength);
1020 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001021 if (r.matchPhoneStateListenerEvent(
1022 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001023 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001024 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001025 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001026 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001027 + " subId=" + subId + " phoneId=" + phoneId
1028 + " ss=" + signalStrength);
1029 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001030 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1031 } catch (RemoteException ex) {
1032 mRemoveList.add(r.binder);
1033 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001034 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001035 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001036 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001037 try {
1038 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001039 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001040 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001041 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001042 + " subId=" + subId + " phoneId=" + phoneId
1043 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1044 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001045 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001046 } catch (RemoteException ex) {
1047 mRemoveList.add(r.binder);
1048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 }
1050 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001051 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001052 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001054 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001056 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 }
1058
Andrew Flynn1f452642015-04-14 22:16:04 -04001059 @Override
1060 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001061 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1062
Andrew Flynn1f452642015-04-14 22:16:04 -04001063 if (VDBG) {
1064 log("notifyCarrierNetworkChange: active=" + active);
1065 }
1066
1067 synchronized (mRecords) {
1068 mCarrierNetworkChangeState = active;
1069 for (Record r : mRecords) {
1070 if (r.matchPhoneStateListenerEvent(
1071 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1072 try {
1073 r.callback.onCarrierNetworkChange(active);
1074 } catch (RemoteException ex) {
1075 mRemoveList.add(r.binder);
1076 }
1077 }
1078 }
1079 handleRemoveListLocked();
1080 }
1081 }
1082
Wink Savilleb208a242012-07-25 14:08:09 -07001083 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001084 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001085 }
1086
Wink Saville63f03dd2014-10-23 10:44:45 -07001087 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001088 if (!checkNotifyPermission("notifyCellInfo()")) {
1089 return;
1090 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001091 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001092 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001093 + " cellInfo=" + cellInfo);
1094 }
yifan.baie620ce72017-12-22 14:59:57 +08001095 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001096 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001097 if (validatePhoneId(phoneId)) {
1098 mCellInfo.set(phoneId, cellInfo);
1099 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001100 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001101 idMatch(r.subId, subId, phoneId) &&
1102 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001103 try {
1104 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001105 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001106 }
1107 r.callback.onCellInfoChanged(cellInfo);
1108 } catch (RemoteException ex) {
1109 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001110 }
John Wang963db55d2012-03-30 16:04:06 -07001111 }
1112 }
1113 }
1114 handleRemoveListLocked();
1115 }
1116 }
1117
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001118 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1119 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1120 configs);
1121 }
1122
1123 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1124 List<PhysicalChannelConfig> configs) {
1125 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1126 return;
1127 }
1128
1129 if (VDBG) {
1130 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1131 }
1132
1133 synchronized (mRecords) {
1134 int phoneId = SubscriptionManager.getPhoneId(subId);
1135 if (validatePhoneId(phoneId)) {
1136 mPhysicalChannelConfigs.set(phoneId, configs);
1137 for (Record r : mRecords) {
1138 if (r.matchPhoneStateListenerEvent(
1139 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1140 && idMatch(r.subId, subId, phoneId)) {
1141 try {
1142 if (DBG_LOC) {
1143 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1144 + configs + " r=" + r);
1145 }
1146 r.callback.onPhysicalChannelConfigurationChanged(configs);
1147 } catch (RemoteException ex) {
1148 mRemoveList.add(r.binder);
1149 }
1150 }
1151 }
1152 }
1153 handleRemoveListLocked();
1154 }
1155 }
1156
xinhe43c50292014-09-18 17:56:48 -07001157 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001158 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001159 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001160 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001161 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001162 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001163 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001164 + " mwi=" + mwi);
1165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001167 if (validatePhoneId(phoneId)) {
1168 mMessageWaiting[phoneId] = mwi;
1169 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001170 if (r.matchPhoneStateListenerEvent(
1171 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001172 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001173 try {
1174 r.callback.onMessageWaitingIndicatorChanged(mwi);
1175 } catch (RemoteException ex) {
1176 mRemoveList.add(r.binder);
1177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 }
1179 }
1180 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001181 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 }
1183 }
1184
zxuan35a47022018-01-04 11:24:04 -08001185 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1186 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1187 return;
1188 }
1189 if (VDBG) {
1190 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1191 + " state=" + state);
1192 }
1193 synchronized (mRecords) {
1194 if (validatePhoneId(phoneId)) {
1195 mMessageWaiting[phoneId] = state;
1196 for (Record r : mRecords) {
1197 if (r.matchPhoneStateListenerEvent(
1198 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1199 idMatch(r.subId, subId, phoneId)) {
1200 try {
1201 r.callback.onUserMobileDataStateChanged(state);
1202 } catch (RemoteException ex) {
1203 mRemoveList.add(r.binder);
1204 }
1205 }
1206 }
1207 }
1208 handleRemoveListLocked();
1209 }
1210 }
1211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001213 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001214 }
1215
Wink Saville63f03dd2014-10-23 10:44:45 -07001216 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001217 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001218 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001219 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001220 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001221 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001222 + " cfi=" + cfi);
1223 }
yifan.baie620ce72017-12-22 14:59:57 +08001224 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001226 if (validatePhoneId(phoneId)) {
1227 mCallForwarding[phoneId] = cfi;
1228 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001229 if (r.matchPhoneStateListenerEvent(
1230 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001231 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001232 try {
1233 r.callback.onCallForwardingIndicatorChanged(cfi);
1234 } catch (RemoteException ex) {
1235 mRemoveList.add(r.binder);
1236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 }
1238 }
1239 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001240 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 }
1242 }
1243
1244 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001245 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001246 }
1247
Wink Saville63f03dd2014-10-23 10:44:45 -07001248 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001249 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001250 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001251 }
yifan.baie620ce72017-12-22 14:59:57 +08001252 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001254 if (validatePhoneId(phoneId)) {
1255 mDataActivity[phoneId] = state;
1256 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001257 // Notify by correct subId.
1258 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1259 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001260 try {
1261 r.callback.onDataActivity(state);
1262 } catch (RemoteException ex) {
1263 mRemoveList.add(r.binder);
1264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 }
1266 }
1267 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001268 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 }
1270 }
1271
Jack Yubaeec622017-05-01 17:01:11 -07001272 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001273 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001274 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001275 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001276 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001277 networkCapabilities, networkType, roaming);
1278 }
1279
Wink Saville63f03dd2014-10-23 10:44:45 -07001280 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001281 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001282 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1283 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001284 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001285 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001286 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001287 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001288 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001289 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001290 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001291 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001292 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001293 }
yifan.baie620ce72017-12-22 14:59:57 +08001294 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001296 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001297 // We only call the callback when the change is for default APN type.
1298 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1299 && (mDataConnectionState[phoneId] != state
1300 || mDataConnectionNetworkType[phoneId] != networkType)) {
1301 String str = "onDataConnectionStateChanged(" + state
1302 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001303 log(str);
1304 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001305 for (Record r : mRecords) {
1306 if (r.matchPhoneStateListenerEvent(
1307 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1308 idMatch(r.subId, subId, phoneId)) {
1309 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001310 if (DBG) {
1311 log("Notify data connection state changed on sub: " + subId);
1312 }
Jack Yub1bac542018-03-14 16:23:38 -07001313 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001314 } catch (RemoteException ex) {
1315 mRemoveList.add(r.binder);
1316 }
1317 }
1318 }
1319 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001320
1321 mDataConnectionState[phoneId] = state;
1322 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001323 }
1324 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1325 apnType, apn, reason, linkProperties, "");
1326 for (Record r : mRecords) {
1327 if (r.matchPhoneStateListenerEvent(
1328 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1329 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001330 r.callback.onPreciseDataConnectionStateChanged(
1331 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001332 } catch (RemoteException ex) {
1333 mRemoveList.add(r.binder);
1334 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001335 }
1336 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001337 }
1338 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 }
Jack Yubaeec622017-05-01 17:01:11 -07001340 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001341 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001342 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1343 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 }
1345
Robert Greenwalt02648a42010-05-18 10:52:51 -07001346 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001347 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001348 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001349 }
1350
Wink Saville63f03dd2014-10-23 10:44:45 -07001351 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001352 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001353 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001354 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001355 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001356 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001357 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001358 + " reason=" + reason + " apnType=" + apnType);
1359 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001361 mPreciseDataConnectionState = new PreciseDataConnectionState(
1362 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1363 apnType, "", reason, null, "");
1364 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001365 if (r.matchPhoneStateListenerEvent(
1366 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001367 try {
1368 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1369 } catch (RemoteException ex) {
1370 mRemoveList.add(r.binder);
1371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 }
1373 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001374 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001376 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001377 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1378 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 }
1380
1381 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001382 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001383 }
1384
Wink Saville63f03dd2014-10-23 10:44:45 -07001385 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001386 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001387 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001388 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001389 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001390 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001391 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001392 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001393 + " cellLocation=" + cellLocation);
1394 }
yifan.baie620ce72017-12-22 14:59:57 +08001395 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001397 if (validatePhoneId(phoneId)) {
1398 mCellLocation[phoneId] = cellLocation;
1399 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001400 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001401 idMatch(r.subId, subId, phoneId) &&
1402 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001403 try {
1404 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001405 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001406 + " r=" + r);
1407 }
1408 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1409 } catch (RemoteException ex) {
1410 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001411 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 }
1414 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001415 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001416 }
1417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418
Wink Savillefd2d0132010-10-28 14:22:26 -07001419 public void notifyOtaspChanged(int otaspMode) {
1420 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1421 return;
1422 }
1423 synchronized (mRecords) {
1424 mOtaspMode = otaspMode;
1425 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001426 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001427 try {
1428 r.callback.onOtaspChanged(otaspMode);
1429 } catch (RemoteException ex) {
1430 mRemoveList.add(r.binder);
1431 }
1432 }
1433 }
1434 handleRemoveListLocked();
1435 }
1436 }
1437
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001438 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1439 int backgroundCallState) {
1440 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1441 return;
1442 }
1443 synchronized (mRecords) {
1444 mRingingCallState = ringingCallState;
1445 mForegroundCallState = foregroundCallState;
1446 mBackgroundCallState = backgroundCallState;
1447 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1448 backgroundCallState,
1449 DisconnectCause.NOT_VALID,
1450 PreciseDisconnectCause.NOT_VALID);
1451 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001452 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001453 try {
1454 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1455 } catch (RemoteException ex) {
1456 mRemoveList.add(r.binder);
1457 }
1458 }
1459 }
1460 handleRemoveListLocked();
1461 }
1462 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1463 DisconnectCause.NOT_VALID,
1464 PreciseDisconnectCause.NOT_VALID);
1465 }
1466
1467 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1468 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1469 return;
1470 }
1471 synchronized (mRecords) {
1472 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1473 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1474 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001475 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001476 try {
1477 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1478 } catch (RemoteException ex) {
1479 mRemoveList.add(r.binder);
1480 }
1481 }
1482 }
1483 handleRemoveListLocked();
1484 }
1485 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1486 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1487 }
1488
1489 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1490 String apn, String failCause) {
1491 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1492 return;
1493 }
1494 synchronized (mRecords) {
1495 mPreciseDataConnectionState = new PreciseDataConnectionState(
1496 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1497 apnType, apn, reason, null, failCause);
1498 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001499 if (r.matchPhoneStateListenerEvent(
1500 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001501 try {
1502 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1503 } catch (RemoteException ex) {
1504 mRemoveList.add(r.binder);
1505 }
1506 }
1507 }
1508 handleRemoveListLocked();
1509 }
1510 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1511 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1512 }
1513
Wink Savillefb40dd42014-06-12 17:02:31 -07001514 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1515 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1516 return;
1517 }
1518 synchronized (mRecords) {
1519 mVoLteServiceState = lteState;
1520 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001521 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001522 try {
1523 r.callback.onVoLteServiceStateChanged(
1524 new VoLteServiceState(mVoLteServiceState));
1525 } catch (RemoteException ex) {
1526 mRemoveList.add(r.binder);
1527 }
1528 }
1529 }
1530 handleRemoveListLocked();
1531 }
1532 }
1533
Shuo Qian066e8652018-04-25 21:02:35 +00001534 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1535 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1536 return;
1537 }
1538
1539 synchronized (mRecords) {
1540 for (Record r : mRecords) {
1541 if (VDBG) {
1542 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1543 }
1544 if ((r.matchPhoneStateListenerEvent(
1545 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1546 ((r.subId == subId) ||
1547 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1548 try {
1549 r.callback.onOemHookRawEvent(rawData);
1550 } catch (RemoteException ex) {
1551 mRemoveList.add(r.binder);
1552 }
1553 }
1554 }
1555 handleRemoveListLocked();
1556 }
1557 }
1558
Malcolm Chene1623652018-08-08 20:27:45 -07001559 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1560 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1561 return;
1562 }
1563
1564 if (VDBG) {
1565 log("notifyPhoneCapabilityChanged: capability=" + capability);
1566 }
1567
1568 synchronized (mRecords) {
1569 mPhoneCapability = capability;
1570
1571 for (Record r : mRecords) {
1572 if (r.matchPhoneStateListenerEvent(
1573 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1574 try {
1575 r.callback.onPhoneCapabilityChanged(capability);
1576 } catch (RemoteException ex) {
1577 mRemoveList.add(r.binder);
1578 }
1579 }
1580 }
1581 handleRemoveListLocked();
1582 }
1583 }
1584
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001585 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1586 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1587 return;
1588 }
1589
1590 if (VDBG) {
1591 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1592 }
1593
1594 synchronized (mRecords) {
1595 mPreferredDataSubId = preferredSubId;
1596
1597 for (Record r : mRecords) {
1598 if (r.matchPhoneStateListenerEvent(
1599 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1600 try {
1601 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1602 } catch (RemoteException ex) {
1603 mRemoveList.add(r.binder);
1604 }
1605 }
1606 }
1607 handleRemoveListLocked();
1608 }
1609 }
Malcolm Chene1623652018-08-08 20:27:45 -07001610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001612 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1613 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1614
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001615 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001618 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001620 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301621 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001622 pw.println("Phone Id=" + i);
1623 pw.increaseIndent();
1624 pw.println("mCallState=" + mCallState[i]);
1625 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1626 pw.println("mServiceState=" + mServiceState[i]);
1627 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1628 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001629 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001630 pw.println("mSignalStrength=" + mSignalStrength[i]);
1631 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1632 pw.println("mCallForwarding=" + mCallForwarding[i]);
1633 pw.println("mDataActivity=" + mDataActivity[i]);
1634 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001635 pw.println("mCellLocation=" + mCellLocation[i]);
1636 pw.println("mCellInfo=" + mCellInfo.get(i));
1637 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301638 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001639 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1640 pw.println("mPreciseCallState=" + mPreciseCallState);
1641 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1642 pw.println("mRingingCallState=" + mRingingCallState);
1643 pw.println("mForegroundCallState=" + mForegroundCallState);
1644 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1645 pw.println("mVoLteServiceState=" + mVoLteServiceState);
Malcolm Chene1623652018-08-08 20:27:45 -07001646 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001647 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
Jack Yud19b6ae2017-04-05 14:12:09 -07001648
1649 pw.decreaseIndent();
1650
1651 pw.println("local logs:");
1652 pw.increaseIndent();
1653 mLocalLog.dump(fd, pw, args);
1654 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001655 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001656 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001657 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001658 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001660 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 }
1662 }
1663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001664 //
1665 // the legacy intent broadcasting
1666 //
1667
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001668 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001669 long ident = Binder.clearCallingIdentity();
1670 try {
1671 mBatteryStats.notePhoneState(state.getState());
1672 } catch (RemoteException re) {
1673 // Can't do much
1674 } finally {
1675 Binder.restoreCallingIdentity(ident);
1676 }
1677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001679 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 Bundle data = new Bundle();
1681 state.fillInNotifierBundle(data);
1682 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001683 // Pass the subscription along with the intent.
1684 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001685 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001686 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 }
1688
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001689 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1690 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001691 long ident = Binder.clearCallingIdentity();
1692 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001693 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001694 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001695 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001696 } finally {
1697 Binder.restoreCallingIdentity(ident);
1698 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001701 Bundle data = new Bundle();
1702 signalStrength.fillInNotifierBundle(data);
1703 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001704 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001705 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001706 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 }
1708
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001709 /**
1710 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1711 * a valid subId, in which case this function fires a subId-specific intent, or it
1712 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1713 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1714 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001715 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1716 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 long ident = Binder.clearCallingIdentity();
1718 try {
1719 if (state == TelephonyManager.CALL_STATE_IDLE) {
1720 mBatteryStats.notePhoneOff();
1721 } else {
1722 mBatteryStats.notePhoneOn();
1723 }
1724 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001725 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 } finally {
1727 Binder.restoreCallingIdentity(ident);
1728 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001731 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001732 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001733
1734 // If a valid subId was specified, we should fire off a subId-specific state
1735 // change intent and include the subId.
1736 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1737 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1738 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1739 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001740 // If the phoneId is invalid, the broadcast is for overall call state.
1741 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1742 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1743 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001744
Brad Ebinger51de96a2017-04-21 17:05:18 -07001745 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1746 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1747
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001748 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001749 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001750 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1751
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001752 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1753 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001754 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001755 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001756 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001757 android.Manifest.permission.READ_PHONE_STATE,
1758 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001759 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1760 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1761 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762 }
1763
Robert Greenwalt42acef32009-08-12 16:08:25 -07001764 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001765 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001766 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001767 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001768 // Note: not reporting to the battery stats service here, because the
1769 // status bar takes care of that after taking into account all of the
1770 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001772 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001773 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001774 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001775 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001776 }
1777 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001778 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001779 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001780 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001781 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001782 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001783 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001784 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001785 }
1786 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001787 if (networkCapabilities != null) {
1788 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001789 }
Wink Savillea639b312012-07-10 12:37:54 -07001790 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001791
Wink Savillea639b312012-07-10 12:37:54 -07001792 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1793 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001794 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001795 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 }
1797
Wink Savillefb40dd42014-06-12 17:02:31 -07001798 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001799 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001801 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1802 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001803 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001804 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001806
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001807 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1808 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1809 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1810 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1811 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1812 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1813 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1814 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1815 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1816 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1817 }
1818
1819 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001820 String apnType, String apn, String reason, LinkProperties linkProperties,
1821 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001822 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1823 intent.putExtra(PhoneConstants.STATE_KEY, state);
1824 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1825 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1826 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1827 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001828 if (linkProperties != null) {
1829 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1830 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001831 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1832
1833 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1834 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1835 }
1836
Andrew Flynnceaed682015-06-09 12:36:58 +00001837 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001838 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001839 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001840 }
1841
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001842 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1843 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001844 }
1845
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001846 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001847 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001848 return true;
1849 }
1850 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001851 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001852 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001853 return false;
1854 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001855
Andrew Flynn1f452642015-04-14 22:16:04 -04001856 private boolean checkNotifyPermission() {
1857 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1858 == PackageManager.PERMISSION_GRANTED;
1859 }
1860
Jeff Davidson29da89f2018-02-28 17:50:16 -08001861 private boolean checkListenerPermission(
1862 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001863 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001864 mContext.enforceCallingOrSelfPermission(
1865 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001866 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1867 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1868 return false;
1869 }
John Wang963db55d2012-03-30 16:04:06 -07001870 }
1871
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001872 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1874 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001875 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001876 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001877 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001878
1879 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1880 mContext.enforceCallingOrSelfPermission(
1881 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001882 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001883
Shuo Qian066e8652018-04-25 21:02:35 +00001884 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1885 mContext.enforceCallingOrSelfPermission(
1886 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1887 }
1888
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001889 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001890 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001891
1892 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001893 int size = mRemoveList.size();
1894 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1895 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001896 for (IBinder b: mRemoveList) {
1897 remove(b);
1898 }
1899 mRemoveList.clear();
1900 }
1901 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001902
1903 private boolean validateEventsAndUserLocked(Record r, int events) {
1904 int foregroundUser;
1905 long callingIdentity = Binder.clearCallingIdentity();
1906 boolean valid = false;
1907 try {
1908 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001909 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1910 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001911 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001912 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001913 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001914 + " r.events=" + r.events + " events=" + events);
1915 }
1916 } finally {
1917 Binder.restoreCallingIdentity(callingIdentity);
1918 }
1919 return valid;
1920 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001921
1922 private boolean validatePhoneId(int phoneId) {
1923 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001924 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001925 return valid;
1926 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001927
1928 private static void log(String s) {
1929 Rlog.d(TAG, s);
1930 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001931
xinhe8b79fb62014-11-05 14:55:03 -08001932 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001933
1934 if(subId < 0) {
1935 // Invalid case, we need compare phoneId with default one.
1936 return (mDefaultPhoneId == phoneId);
1937 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001938 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001939 return (subId == mDefaultSubId);
1940 } else {
1941 return (rSubId == subId);
1942 }
1943 }
1944
Hall Liu5fb337f2017-11-22 17:38:15 -08001945 private boolean checkLocationAccess(Record r) {
1946 long token = Binder.clearCallingIdentity();
1947 try {
1948 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001949 r.callingPackage, r.callerUid, r.callerPid,
1950 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001951 } finally {
1952 Binder.restoreCallingIdentity(token);
1953 }
1954 }
1955
xinhee9f16402014-09-25 16:39:28 -07001956 private void checkPossibleMissNotify(Record r, int phoneId) {
1957 int events = r.events;
1958
1959 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1960 try {
1961 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1962 mServiceState[phoneId]);
1963 r.callback.onServiceStateChanged(
1964 new ServiceState(mServiceState[phoneId]));
1965 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001966 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001967 }
1968 }
1969
1970 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1971 try {
1972 SignalStrength signalStrength = mSignalStrength[phoneId];
1973 if (DBG) {
1974 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1975 }
1976 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1977 } catch (RemoteException ex) {
1978 mRemoveList.add(r.binder);
1979 }
1980 }
1981
1982 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1983 try {
1984 int gsmSignalStrength = mSignalStrength[phoneId]
1985 .getGsmSignalStrength();
1986 if (DBG) {
1987 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1988 gsmSignalStrength);
1989 }
1990 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1991 : gsmSignalStrength));
1992 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001993 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001994 }
1995 }
1996
1997 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1998 try {
1999 if (DBG_LOC) {
2000 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2001 + mCellInfo.get(phoneId));
2002 }
Hall Liu5fb337f2017-11-22 17:38:15 -08002003 if (checkLocationAccess(r)) {
2004 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2005 }
xinhee9f16402014-09-25 16:39:28 -07002006 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002007 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002008 }
2009 }
2010
zxuan35a47022018-01-04 11:24:04 -08002011 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2012 try {
2013 if (VDBG) {
2014 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2015 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2016 }
2017 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2018 } catch (RemoteException ex) {
2019 mRemoveList.add(r.binder);
2020 }
2021 }
2022
xinhee9f16402014-09-25 16:39:28 -07002023 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2024 try {
2025 if (VDBG) {
2026 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2027 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2028 }
2029 r.callback.onMessageWaitingIndicatorChanged(
2030 mMessageWaiting[phoneId]);
2031 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002032 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002033 }
2034 }
2035
2036 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2037 try {
2038 if (VDBG) {
2039 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2040 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2041 }
2042 r.callback.onCallForwardingIndicatorChanged(
2043 mCallForwarding[phoneId]);
2044 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002045 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002046 }
2047 }
2048
2049 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2050 try {
2051 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2052 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002053 if (checkLocationAccess(r)) {
2054 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2055 }
xinhee9f16402014-09-25 16:39:28 -07002056 } catch (RemoteException ex) {
2057 mRemoveList.add(r.binder);
2058 }
2059 }
2060
2061 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2062 try {
2063 if (DBG) {
2064 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2065 + "=" + mDataConnectionState[phoneId]
2066 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2067 + ")");
2068 }
2069 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2070 mDataConnectionNetworkType[phoneId]);
2071 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002072 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002073 }
2074 }
2075 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076}