blob: c17a4cf43854e670d3260ae62b95b7af5ff5f77c [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080038import android.telephony.LocationAccessPolicy;
Malcolm Chen5ee5c142018-08-08 20:27:45 -070039import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070040import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080041import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020042import android.telephony.PreciseCallState;
43import android.telephony.PreciseDataConnectionState;
44import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070045import android.telephony.Rlog;
46import android.telephony.ServiceState;
47import android.telephony.SignalStrength;
48import android.telephony.SubscriptionManager;
49import android.telephony.TelephonyManager;
50import android.telephony.VoLteServiceState;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070052import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
Malcolm Chen800a7d62018-08-27 20:38:29 -070054import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080056import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070058import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080059import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070060import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080062import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060063import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070064import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import com.android.server.am.BatteryStatsService;
66
Jack Yud19b6ae2017-04-05 14:12:09 -070067import java.io.FileDescriptor;
68import java.io.PrintWriter;
69import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070070import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080071import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073/**
Wink Savillee9b06d72009-05-18 21:47:50 -070074 * Since phone process can be restarted, this class provides a centralized place
75 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070076 *
77 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
78 * and 15973975 by saving the phoneId of the registrant and then using the
79 * phoneId when deciding to to make a callback. This is necessary because
80 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070081 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070082 * the dummy value conversion we properly do the callbacks.
83 *
84 * Eventually we may want to remove the notion of dummy value but for now this
85 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 */
Malcolm Chen800a7d62018-08-27 20:38:29 -070087@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
88public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070090 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070091 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070092 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
94 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080095 Context context;
96
Svet Ganov16a16892015-04-16 10:32:04 -070097 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
Malcolm Chenabbfac22018-02-12 19:15:59 -0800101 TelephonyRegistryDeathRecipient deathRecipient;
102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800104 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen27829e22018-09-04 22:12:31 -0700105 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
Hall Liu5fb337f2017-11-22 17:38:15 -0800107 int callerUid;
108 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700111
Wink Savilled09c4ca2014-11-22 10:08:16 -0800112 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700113
Wink Savilled09c4ca2014-11-22 10:08:16 -0800114 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800115
116 boolean matchPhoneStateListenerEvent(int events) {
117 return (callback != null) && ((events & this.events) != 0);
118 }
119
Wink Savilled09c4ca2014-11-22 10:08:16 -0800120 boolean matchOnSubscriptionsChangedListener() {
121 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800122 }
Wink Savillee380b982014-07-26 18:24:22 -0700123
Malcolm Chen27829e22018-09-04 22:12:31 -0700124 boolean matchOnOpportunisticSubscriptionsChangedListener() {
125 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
126 }
127
Tyler Gunnf955e562018-04-26 14:43:31 -0700128 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800129 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700130 return TelephonyPermissions.checkReadCallLog(
131 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800132 } catch (SecurityException e) {
133 return false;
134 }
135 }
136
Wink Savillea12a7b32012-09-20 10:09:45 -0700137 @Override
138 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700139 return "{callingPackage=" + callingPackage + " binder=" + binder
140 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800141 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen27829e22018-09-04 22:12:31 -0700142 + onSubscriptionsChangedListenerCallback
143 + " onOpportunisticSubscriptionsChangedListenererCallback="
144 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800145 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800146 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
149
150 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
Joe Onorato163d8d92010-10-21 13:21:20 -0400152 // access should be inside synchronized (mRecords) for these two fields
153 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
154 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 private final IBatteryStats mBatteryStats;
157
Svet Ganov16a16892015-04-16 10:32:04 -0700158 private final AppOpsManager mAppOps;
159
Malcolm Chen27829e22018-09-04 22:12:31 -0700160 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
161
162 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
fionaxu12312f62016-11-14 13:32:14 -0800172 private int[] mVoiceActivationState;
173
174 private int[] mDataActivationState;
175
zxuan35a47022018-01-04 11:24:04 -0800176 private boolean[] mUserMobileDataState;
177
Wink Savillefb40dd42014-06-12 17:02:31 -0700178 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700179
Wink Savillefb40dd42014-06-12 17:02:31 -0700180 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700181
Wink Savillefb40dd42014-06-12 17:02:31 -0700182 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700183
Wink Savillefb40dd42014-06-12 17:02:31 -0700184 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700185
Jack Yub1bac542018-03-14 16:23:38 -0700186 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700187 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700188
Wink Savillefb40dd42014-06-12 17:02:31 -0700189 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700192
Nathan Harold016e9c62016-12-14 11:24:48 -0800193 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700194
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private ArrayList<List<CellInfo>> mCellInfo = null;
196
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800197 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
200
Wink Savilled09c4ca2014-11-22 10:08:16 -0800201 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700202
Wink Savilled09c4ca2014-11-22 10:08:16 -0800203 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700204
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200205 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
206
207 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
208
209 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
210
211 private PreciseCallState mPreciseCallState = new PreciseCallState();
212
Andrew Flynn1f452642015-04-14 22:16:04 -0400213 private boolean mCarrierNetworkChangeState = false;
214
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700215 private PhoneCapability mPhoneCapability = null;
216
Jack Yud19b6ae2017-04-05 14:12:09 -0700217 private final LocalLog mLocalLog = new LocalLog(100);
218
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200219 private PreciseDataConnectionState mPreciseDataConnectionState =
220 new PreciseDataConnectionState();
221
Hall Liu70bbc162018-03-02 17:44:46 -0800222 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
223 PhoneStateListener.LISTEN_CELL_LOCATION
224 | PhoneStateListener.LISTEN_CELL_INFO;
225
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700226 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700227 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700228 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
229 PhoneStateListener.LISTEN_VOLTE_STATE;
230
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200231 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
232 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
233 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
234
Wink Savillea12a7b32012-09-20 10:09:45 -0700235 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700236 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700237
238 private final Handler mHandler = new Handler() {
239 @Override
240 public void handleMessage(Message msg) {
241 switch (msg.what) {
242 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700243 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700244 int numPhones = TelephonyManager.getDefault().getPhoneCount();
245 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700246 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700247 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700248 }
249 break;
250 }
xinhee9f16402014-09-25 16:39:28 -0700251 case MSG_UPDATE_DEFAULT_SUB: {
252 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700253 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700254 if (VDBG) {
255 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
256 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
257 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
258 }
259
260 //Due to possible risk condition,(notify call back using the new
261 //defaultSubId comes before new defaultSubId update) we need to recall all
262 //possible missed notify callback
263 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700264 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800265 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700266 checkPossibleMissNotify(r, newDefaultPhoneId);
267 }
268 }
269 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700270 }
271 mDefaultSubId = newDefaultSubId;
272 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700273 }
274 }
275 }
276 };
277
Malcolm Chenabbfac22018-02-12 19:15:59 -0800278 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
279
280 private final IBinder binder;
281
282 TelephonyRegistryDeathRecipient(IBinder binder) {
283 this.binder = binder;
284 }
285
286 @Override
287 public void binderDied() {
288 if (DBG) log("binderDied " + binder);
289 remove(binder);
290 }
291 }
292
Wink Savillea12a7b32012-09-20 10:09:45 -0700293 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
294 @Override
295 public void onReceive(Context context, Intent intent) {
296 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700297 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700298 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700299 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700300 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700301 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700302 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700303 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800304 PhoneConstants.SUBSCRIPTION_KEY,
305 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700306 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
307 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700308 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700309 log("onReceive:current mDefaultSubId=" + mDefaultSubId
310 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
311 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700312 }
xinhee9f16402014-09-25 16:39:28 -0700313
Junda Liu985f52c2015-02-23 16:06:51 -0800314 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700315 || (newDefaultPhoneId != mDefaultPhoneId))) {
316 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
317 newDefaultPhoneId, 0, newDefaultSubIdObj));
318 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700319 }
320 }
321 };
322
Wink Savillee9b06d72009-05-18 21:47:50 -0700323 // we keep a copy of all of the state so we can send it out when folks
324 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700326 // In these calls we call with the lock held. This is safe becasuse remote
327 // calls go through a oneway interface and local calls going through a
328 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
Malcolm Chen800a7d62018-08-27 20:38:29 -0700330 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
331 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700332 CellLocation location = CellLocation.getEmpty();
333
Wink Savillefb40dd42014-06-12 17:02:31 -0700334 mContext = context;
335 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700336
Wink Savillefb40dd42014-06-12 17:02:31 -0700337 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700338 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700339 mNumPhones = numPhones;
340 mCallState = new int[numPhones];
341 mDataActivity = new int[numPhones];
342 mDataConnectionState = new int[numPhones];
343 mDataConnectionNetworkType = new int[numPhones];
344 mCallIncomingNumber = new String[numPhones];
345 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800346 mVoiceActivationState = new int[numPhones];
347 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800348 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700349 mSignalStrength = new SignalStrength[numPhones];
350 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700351 mCallForwarding = new boolean[numPhones];
352 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700353 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800354 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 for (int i = 0; i < numPhones; i++) {
356 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
357 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
358 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800359 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
360 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700361 mCallIncomingNumber[i] = "";
362 mServiceState[i] = new ServiceState();
363 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800364 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700365 mMessageWaiting[i] = false;
366 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700367 mCellLocation[i] = new Bundle();
368 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700369 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700370 }
371
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700372 // Note that location can be null for non-phone builds like
373 // like the generic one.
374 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700375 for (int i = 0; i < numPhones; i++) {
376 location.fillInNotifierBundle(mCellLocation[i]);
377 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700378 }
Svet Ganov16a16892015-04-16 10:32:04 -0700379
380 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
382
Svetoslav Ganova0027152013-06-25 14:59:53 -0700383 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700384 // Watch for interesting updates
385 final IntentFilter filter = new IntentFilter();
386 filter.addAction(Intent.ACTION_USER_SWITCHED);
387 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700388 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700389 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700390 mContext.registerReceiver(mBroadcastReceiver, filter);
391 }
392
393 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700394 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800395 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700396 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800397 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800398 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700399 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
400 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800401 + " callback.asBinder=" + callback.asBinder());
402 }
403
Wink Savilled09c4ca2014-11-22 10:08:16 -0800404 synchronized (mRecords) {
405 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800406 IBinder b = callback.asBinder();
407 Record r = add(b);
408
409 if (r == null) {
410 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800411 }
412
Jeff Davidson29da89f2018-02-28 17:50:16 -0800413 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700415 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800416 r.callerUid = Binder.getCallingUid();
417 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800418 r.events = 0;
419 if (DBG) {
420 log("listen oscl: Register r=" + r);
421 }
422 // Always notify when registration occurs if there has been a notification.
Malcolm Chen27829e22018-09-04 22:12:31 -0700423 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800425 if (VDBG) log("listen oscl: send to r=" + r);
426 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
427 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800428 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800429 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800430 remove(r.binder);
431 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800432 } else {
Malcolm Chen27829e22018-09-04 22:12:31 -0700433 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800434 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 }
436 }
437
438 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800439 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800440 IOnSubscriptionsChangedListener callback) {
441 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800442 remove(callback.asBinder());
443 }
444
Malcolm Chen27829e22018-09-04 22:12:31 -0700445
446 @Override
447 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
448 IOnSubscriptionsChangedListener callback) {
449 int callerUserId = UserHandle.getCallingUserId();
450 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
451 if (VDBG) {
452 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
453 + " callerUserId=" + callerUserId + " callback=" + callback
454 + " callback.asBinder=" + callback.asBinder());
455 }
456
457 synchronized (mRecords) {
458 // register
459 IBinder b = callback.asBinder();
460 Record r = add(b);
461
462 if (r == null) {
463 return;
464 }
465
466 r.context = mContext;
467 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
468 r.callingPackage = callingPackage;
469 r.callerUid = Binder.getCallingUid();
470 r.callerPid = Binder.getCallingPid();
471 r.events = 0;
472 if (DBG) {
473 log("listen ooscl: Register r=" + r);
474 }
475 // Always notify when registration occurs if there has been a notification.
476 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
477 try {
478 if (VDBG) log("listen ooscl: send to r=" + r);
479 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
480 if (VDBG) log("listen ooscl: sent to r=" + r);
481 } catch (RemoteException e) {
482 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
483 remove(r.binder);
484 }
485 } else {
486 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
487 }
488 }
489 }
490
Wink Savillea374c3d2014-11-11 11:48:04 -0800491 @Override
492 public void notifySubscriptionInfoChanged() {
493 if (VDBG) log("notifySubscriptionInfoChanged:");
494 synchronized (mRecords) {
Malcolm Chen27829e22018-09-04 22:12:31 -0700495 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800496 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
497 + mRecords.size());
498 }
Malcolm Chen27829e22018-09-04 22:12:31 -0700499 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800500 mRemoveList.clear();
501 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800502 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800503 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800504 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
505 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
506 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800507 } catch (RemoteException ex) {
508 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
509 mRemoveList.add(r.binder);
510 }
511 }
512 }
513 handleRemoveListLocked();
514 }
515 }
516
517 @Override
Malcolm Chen27829e22018-09-04 22:12:31 -0700518 public void notifyOpportunisticSubscriptionInfoChanged() {
519 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
520 synchronized (mRecords) {
521 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
522 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
523 + mRecords.size());
524 }
525 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
526 mRemoveList.clear();
527 for (Record r : mRecords) {
528 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
529 try {
530 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
531 r.onOpportunisticSubscriptionsChangedListenerCallback
532 .onSubscriptionsChanged();
533 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
534 } catch (RemoteException ex) {
535 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
536 mRemoveList.add(r.binder);
537 }
538 }
539 }
540 handleRemoveListLocked();
541 }
542 }
543
544 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
546 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800547 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
548 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700549 }
550
551 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700552 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700553 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700554 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700555 }
556
Svet Ganov16a16892015-04-16 10:32:04 -0700557 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700558 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700559 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800560 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700561 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700562 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700563 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
564 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700565 }
xinhe75c2c152014-10-16 11:49:45 -0700566
567 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800568 // Checks permission and throws SecurityException for disallowed operations. For pre-M
569 // apps whose runtime permission has been revoked, we return immediately to skip sending
570 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800571 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800572 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700573 }
574
yifan.baie620ce72017-12-22 14:59:57 +0800575 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 synchronized (mRecords) {
577 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800578 IBinder b = callback.asBinder();
579 Record r = add(b);
580
581 if (r == null) {
582 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 }
xinhe43c50292014-09-18 17:56:48 -0700584
Jeff Davidson29da89f2018-02-28 17:50:16 -0800585 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700586 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700587 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800588 r.callerUid = Binder.getCallingUid();
589 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700590 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
591 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800593 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700594 } else {//APP specify subID
595 r.subId = subId;
596 }
yifan.baie620ce72017-12-22 14:59:57 +0800597 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700599 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700600 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700601 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400604 try {
Wink Savillee380b982014-07-26 18:24:22 -0700605 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700606 r.callback.onServiceStateChanged(
607 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400608 } catch (RemoteException ex) {
609 remove(r.binder);
610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 }
612 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
613 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700614 int gsmSignalStrength = mSignalStrength[phoneId]
615 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700616 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
617 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 } catch (RemoteException ex) {
619 remove(r.binder);
620 }
621 }
622 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
623 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700624 r.callback.onMessageWaitingIndicatorChanged(
625 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 } catch (RemoteException ex) {
627 remove(r.binder);
628 }
629 }
630 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
631 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700632 r.callback.onCallForwardingIndicatorChanged(
633 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 } catch (RemoteException ex) {
635 remove(r.binder);
636 }
637 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700638 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400639 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700640 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700641 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800642 if (checkLocationAccess(r)) {
643 r.callback.onCellLocationChanged(
644 new Bundle(mCellLocation[phoneId]));
645 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400646 } catch (RemoteException ex) {
647 remove(r.binder);
648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 }
650 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
651 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700652 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700653 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 } catch (RemoteException ex) {
655 remove(r.binder);
656 }
657 }
658 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
659 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700660 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
661 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 } catch (RemoteException ex) {
663 remove(r.binder);
664 }
665 }
666 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
667 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700668 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 } catch (RemoteException ex) {
670 remove(r.binder);
671 }
672 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700673 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
674 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700675 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700676 } catch (RemoteException ex) {
677 remove(r.binder);
678 }
679 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700680 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
681 try {
682 r.callback.onOtaspChanged(mOtaspMode);
683 } catch (RemoteException ex) {
684 remove(r.binder);
685 }
686 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700687 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700688 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700689 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700690 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800691 if (checkLocationAccess(r)) {
692 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
693 }
John Wang963db55d2012-03-30 16:04:06 -0700694 } catch (RemoteException ex) {
695 remove(r.binder);
696 }
697 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200698 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
699 try {
700 r.callback.onPreciseCallStateChanged(mPreciseCallState);
701 } catch (RemoteException ex) {
702 remove(r.binder);
703 }
704 }
705 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
706 try {
707 r.callback.onPreciseDataConnectionStateChanged(
708 mPreciseDataConnectionState);
709 } catch (RemoteException ex) {
710 remove(r.binder);
711 }
712 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400713 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
714 try {
715 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
716 } catch (RemoteException ex) {
717 remove(r.binder);
718 }
719 }
fionaxu12312f62016-11-14 13:32:14 -0800720 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
721 try {
722 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
723 } catch (RemoteException ex) {
724 remove(r.binder);
725 }
726 }
727 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
728 try {
729 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
730 } catch (RemoteException ex) {
731 remove(r.binder);
732 }
733 }
zxuan35a47022018-01-04 11:24:04 -0800734 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
735 try {
736 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
737 } catch (RemoteException ex) {
738 remove(r.binder);
739 }
740 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800741 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
742 try {
743 r.callback.onPhysicalChannelConfigurationChanged(
744 mPhysicalChannelConfigs.get(phoneId));
745 } catch (RemoteException ex) {
746 remove(r.binder);
747 }
748 }
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700749 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
750 try {
751 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
752 } catch (RemoteException ex) {
753 remove(r.binder);
754 }
755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 }
757 }
758 } else {
xinhe75c2c152014-10-16 11:49:45 -0700759 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 remove(callback.asBinder());
761 }
762 }
763
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700764 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700765 // Only reveal the incoming number if the record has read call log permission.
766 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700767 }
768
Malcolm Chenabbfac22018-02-12 19:15:59 -0800769 private Record add(IBinder binder) {
770 Record r;
771
772 synchronized (mRecords) {
773 final int N = mRecords.size();
774 for (int i = 0; i < N; i++) {
775 r = mRecords.get(i);
776 if (binder == r.binder) {
777 // Already existed.
778 return r;
779 }
780 }
781 r = new Record();
782 r.binder = binder;
783 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
784
785 try {
786 binder.linkToDeath(r.deathRecipient, 0);
787 } catch (RemoteException e) {
788 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
789 // Binder already died. Return null.
790 return null;
791 }
792
793 mRecords.add(r);
794 if (DBG) log("add new record");
795 }
796
797 return r;
798 }
799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 private void remove(IBinder binder) {
801 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700802 final int recordCount = mRecords.size();
803 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800804 Record r = mRecords.get(i);
805 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800806 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800807 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
808 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800809 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800810
811 if (r.deathRecipient != null) {
812 try {
813 binder.unlinkToDeath(r.deathRecipient, 0);
814 } catch (NoSuchElementException e) {
815 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
816 + r + " e=" + e);
817 }
818 }
819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 mRecords.remove(i);
821 return;
822 }
823 }
824 }
825 }
826
Tyler Gunnf955e562018-04-26 14:43:31 -0700827 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700828 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700829 return;
830 }
xinhe43c50292014-09-18 17:56:48 -0700831
832 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700833 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700834 }
835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700837 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800838 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800839 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700841 // Ensure the listener has read call log permission; if they do not return
842 // an empty phone number.
843 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
844 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400846 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 }
848 }
849 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400850 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700852
853 // Called only by Telecomm to communicate call state across different phone accounts. So
854 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700855 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700856 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700857 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 }
859
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700860 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
861 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700862 if (!checkNotifyPermission("notifyCallState()")) {
863 return;
864 }
Wink Savillee380b982014-07-26 18:24:22 -0700865 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700866 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700867 + " state=" + state + " incomingNumber=" + incomingNumber);
868 }
869 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700870 if (validatePhoneId(phoneId)) {
871 mCallState[phoneId] = state;
872 mCallIncomingNumber[phoneId] = incomingNumber;
873 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800874 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700875 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800876 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700877 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700878 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
879 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700880 } catch (RemoteException ex) {
881 mRemoveList.add(r.binder);
882 }
883 }
884 }
885 }
886 handleRemoveListLocked();
887 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700888 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700889 }
890
Wink Saville63f03dd2014-10-23 10:44:45 -0700891 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700892 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700893 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700894 }
xinhe43c50292014-09-18 17:56:48 -0700895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700897 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
898 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700899 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700900 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700901 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700902 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700903 if (validatePhoneId(phoneId)) {
904 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700905
Wink Savillefb40dd42014-06-12 17:02:31 -0700906 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700907 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700908 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700909 + " phoneId=" + phoneId + " state=" + state);
910 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800911 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800912 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700913 try {
Wink Savillee380b982014-07-26 18:24:22 -0700914 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700915 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700916 + " subId=" + subId + " phoneId=" + phoneId
917 + " state=" + state);
918 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700919 r.callback.onServiceStateChanged(new ServiceState(state));
920 } catch (RemoteException ex) {
921 mRemoveList.add(r.binder);
922 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400923 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700926 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400928 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700930 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 }
932
fionaxu12312f62016-11-14 13:32:14 -0800933 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
934 int activationType, int activationState) {
935 if (!checkNotifyPermission("notifySimActivationState()")){
936 return;
937 }
938 if (VDBG) {
939 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
940 + "type=" + activationType + " state=" + activationState);
941 }
942 synchronized (mRecords) {
943 if (validatePhoneId(phoneId)) {
944 switch (activationType) {
945 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
946 mVoiceActivationState[phoneId] = activationState;
947 break;
948 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
949 mDataActivationState[phoneId] = activationState;
950 break;
951 default:
952 return;
953 }
954 for (Record r : mRecords) {
955 if (VDBG) {
956 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
957 + " phoneId=" + phoneId + "type=" + activationType
958 + " state=" + activationState);
959 }
960 try {
961 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
962 r.matchPhoneStateListenerEvent(
963 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
964 idMatch(r.subId, subId, phoneId)) {
965 if (DBG) {
966 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
967 + " subId=" + subId + " phoneId=" + phoneId
968 + " state=" + activationState);
969 }
970 r.callback.onVoiceActivationStateChanged(activationState);
971 }
972 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
973 r.matchPhoneStateListenerEvent(
974 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
975 idMatch(r.subId, subId, phoneId)) {
976 if (DBG) {
977 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
978 + " subId=" + subId + " phoneId=" + phoneId
979 + " state=" + activationState);
980 }
981 r.callback.onDataActivationStateChanged(activationState);
982 }
983 } catch (RemoteException ex) {
984 mRemoveList.add(r.binder);
985 }
986 }
987 } else {
988 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
989 }
990 handleRemoveListLocked();
991 }
992 }
993
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700994 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
995 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700996 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700997 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700998 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000999 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001000 log("notifySignalStrengthForPhoneId: subId=" + subId
1001 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001002 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001005 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001006 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001007 mSignalStrength[phoneId] = signalStrength;
1008 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001009 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001010 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001011 + " phoneId=" + phoneId + " ss=" + signalStrength);
1012 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001013 if (r.matchPhoneStateListenerEvent(
1014 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001015 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001016 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001017 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001018 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001019 + " subId=" + subId + " phoneId=" + phoneId
1020 + " ss=" + signalStrength);
1021 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001022 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1023 } catch (RemoteException ex) {
1024 mRemoveList.add(r.binder);
1025 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001026 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001027 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001028 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001029 try {
1030 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001031 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001032 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001033 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001034 + " subId=" + subId + " phoneId=" + phoneId
1035 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1036 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001037 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001038 } catch (RemoteException ex) {
1039 mRemoveList.add(r.binder);
1040 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 }
1042 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001043 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001044 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001046 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001048 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 }
1050
Andrew Flynn1f452642015-04-14 22:16:04 -04001051 @Override
1052 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001053 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1054
Andrew Flynn1f452642015-04-14 22:16:04 -04001055 if (VDBG) {
1056 log("notifyCarrierNetworkChange: active=" + active);
1057 }
1058
1059 synchronized (mRecords) {
1060 mCarrierNetworkChangeState = active;
1061 for (Record r : mRecords) {
1062 if (r.matchPhoneStateListenerEvent(
1063 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1064 try {
1065 r.callback.onCarrierNetworkChange(active);
1066 } catch (RemoteException ex) {
1067 mRemoveList.add(r.binder);
1068 }
1069 }
1070 }
1071 handleRemoveListLocked();
1072 }
1073 }
1074
Wink Savilleb208a242012-07-25 14:08:09 -07001075 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001076 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001077 }
1078
Wink Saville63f03dd2014-10-23 10:44:45 -07001079 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001080 if (!checkNotifyPermission("notifyCellInfo()")) {
1081 return;
1082 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001083 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001084 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001085 + " cellInfo=" + cellInfo);
1086 }
yifan.baie620ce72017-12-22 14:59:57 +08001087 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001088 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001089 if (validatePhoneId(phoneId)) {
1090 mCellInfo.set(phoneId, cellInfo);
1091 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001092 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001093 idMatch(r.subId, subId, phoneId) &&
1094 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001095 try {
1096 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001097 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001098 }
1099 r.callback.onCellInfoChanged(cellInfo);
1100 } catch (RemoteException ex) {
1101 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001102 }
John Wang963db55d2012-03-30 16:04:06 -07001103 }
1104 }
1105 }
1106 handleRemoveListLocked();
1107 }
1108 }
1109
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001110 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1111 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1112 configs);
1113 }
1114
1115 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1116 List<PhysicalChannelConfig> configs) {
1117 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1118 return;
1119 }
1120
1121 if (VDBG) {
1122 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1123 }
1124
1125 synchronized (mRecords) {
1126 int phoneId = SubscriptionManager.getPhoneId(subId);
1127 if (validatePhoneId(phoneId)) {
1128 mPhysicalChannelConfigs.set(phoneId, configs);
1129 for (Record r : mRecords) {
1130 if (r.matchPhoneStateListenerEvent(
1131 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1132 && idMatch(r.subId, subId, phoneId)) {
1133 try {
1134 if (DBG_LOC) {
1135 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1136 + configs + " r=" + r);
1137 }
1138 r.callback.onPhysicalChannelConfigurationChanged(configs);
1139 } catch (RemoteException ex) {
1140 mRemoveList.add(r.binder);
1141 }
1142 }
1143 }
1144 }
1145 handleRemoveListLocked();
1146 }
1147 }
1148
xinhe43c50292014-09-18 17:56:48 -07001149 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001150 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001151 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001152 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001153 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001154 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001155 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001156 + " mwi=" + mwi);
1157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001159 if (validatePhoneId(phoneId)) {
1160 mMessageWaiting[phoneId] = mwi;
1161 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001162 if (r.matchPhoneStateListenerEvent(
1163 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001164 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001165 try {
1166 r.callback.onMessageWaitingIndicatorChanged(mwi);
1167 } catch (RemoteException ex) {
1168 mRemoveList.add(r.binder);
1169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 }
1171 }
1172 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001173 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
1175 }
1176
zxuan35a47022018-01-04 11:24:04 -08001177 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1178 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1179 return;
1180 }
1181 if (VDBG) {
1182 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1183 + " state=" + state);
1184 }
1185 synchronized (mRecords) {
1186 if (validatePhoneId(phoneId)) {
1187 mMessageWaiting[phoneId] = state;
1188 for (Record r : mRecords) {
1189 if (r.matchPhoneStateListenerEvent(
1190 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1191 idMatch(r.subId, subId, phoneId)) {
1192 try {
1193 r.callback.onUserMobileDataStateChanged(state);
1194 } catch (RemoteException ex) {
1195 mRemoveList.add(r.binder);
1196 }
1197 }
1198 }
1199 }
1200 handleRemoveListLocked();
1201 }
1202 }
1203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001205 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001206 }
1207
Wink Saville63f03dd2014-10-23 10:44:45 -07001208 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001209 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001210 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001211 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001212 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001213 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001214 + " cfi=" + cfi);
1215 }
yifan.baie620ce72017-12-22 14:59:57 +08001216 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001218 if (validatePhoneId(phoneId)) {
1219 mCallForwarding[phoneId] = cfi;
1220 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001221 if (r.matchPhoneStateListenerEvent(
1222 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001223 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001224 try {
1225 r.callback.onCallForwardingIndicatorChanged(cfi);
1226 } catch (RemoteException ex) {
1227 mRemoveList.add(r.binder);
1228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 }
1230 }
1231 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001232 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 }
1234 }
1235
1236 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001237 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001238 }
1239
Wink Saville63f03dd2014-10-23 10:44:45 -07001240 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001241 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001242 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001243 }
yifan.baie620ce72017-12-22 14:59:57 +08001244 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001246 if (validatePhoneId(phoneId)) {
1247 mDataActivity[phoneId] = state;
1248 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001249 // Notify by correct subId.
1250 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1251 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001252 try {
1253 r.callback.onDataActivity(state);
1254 } catch (RemoteException ex) {
1255 mRemoveList.add(r.binder);
1256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 }
1258 }
1259 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001260 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 }
1262 }
1263
Jack Yubaeec622017-05-01 17:01:11 -07001264 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001265 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001266 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001267 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001268 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001269 networkCapabilities, networkType, roaming);
1270 }
1271
Wink Saville63f03dd2014-10-23 10:44:45 -07001272 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001273 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001274 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1275 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001276 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001277 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001278 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001279 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001280 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001281 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001282 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001283 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001284 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001285 }
yifan.baie620ce72017-12-22 14:59:57 +08001286 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001288 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001289 // We only call the callback when the change is for default APN type.
1290 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1291 && (mDataConnectionState[phoneId] != state
1292 || mDataConnectionNetworkType[phoneId] != networkType)) {
1293 String str = "onDataConnectionStateChanged(" + state
1294 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001295 log(str);
1296 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001297 for (Record r : mRecords) {
1298 if (r.matchPhoneStateListenerEvent(
1299 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1300 idMatch(r.subId, subId, phoneId)) {
1301 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001302 if (DBG) {
1303 log("Notify data connection state changed on sub: " + subId);
1304 }
Jack Yub1bac542018-03-14 16:23:38 -07001305 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001306 } catch (RemoteException ex) {
1307 mRemoveList.add(r.binder);
1308 }
1309 }
1310 }
1311 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001312
1313 mDataConnectionState[phoneId] = state;
1314 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001315 }
1316 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1317 apnType, apn, reason, linkProperties, "");
1318 for (Record r : mRecords) {
1319 if (r.matchPhoneStateListenerEvent(
1320 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1321 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001322 r.callback.onPreciseDataConnectionStateChanged(
1323 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001324 } catch (RemoteException ex) {
1325 mRemoveList.add(r.binder);
1326 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001327 }
1328 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001329 }
1330 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 }
Jack Yubaeec622017-05-01 17:01:11 -07001332 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001333 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001334 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1335 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 }
1337
Robert Greenwalt02648a42010-05-18 10:52:51 -07001338 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001339 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001340 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001341 }
1342
Wink Saville63f03dd2014-10-23 10:44:45 -07001343 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001344 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001345 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001346 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001347 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001348 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001349 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001350 + " reason=" + reason + " apnType=" + apnType);
1351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001353 mPreciseDataConnectionState = new PreciseDataConnectionState(
1354 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1355 apnType, "", reason, null, "");
1356 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001357 if (r.matchPhoneStateListenerEvent(
1358 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001359 try {
1360 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1361 } catch (RemoteException ex) {
1362 mRemoveList.add(r.binder);
1363 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 }
1365 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001366 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001368 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001369 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1370 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 }
1372
1373 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001374 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001375 }
1376
Wink Saville63f03dd2014-10-23 10:44:45 -07001377 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001378 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001379 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001380 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001381 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001382 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001383 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001384 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001385 + " cellLocation=" + cellLocation);
1386 }
yifan.baie620ce72017-12-22 14:59:57 +08001387 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001389 if (validatePhoneId(phoneId)) {
1390 mCellLocation[phoneId] = cellLocation;
1391 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001392 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001393 idMatch(r.subId, subId, phoneId) &&
1394 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001395 try {
1396 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001397 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001398 + " r=" + r);
1399 }
1400 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1401 } catch (RemoteException ex) {
1402 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001403 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 }
1406 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001407 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001408 }
1409 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410
Wink Savillefd2d0132010-10-28 14:22:26 -07001411 public void notifyOtaspChanged(int otaspMode) {
1412 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1413 return;
1414 }
1415 synchronized (mRecords) {
1416 mOtaspMode = otaspMode;
1417 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001418 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001419 try {
1420 r.callback.onOtaspChanged(otaspMode);
1421 } catch (RemoteException ex) {
1422 mRemoveList.add(r.binder);
1423 }
1424 }
1425 }
1426 handleRemoveListLocked();
1427 }
1428 }
1429
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001430 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1431 int backgroundCallState) {
1432 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1433 return;
1434 }
1435 synchronized (mRecords) {
1436 mRingingCallState = ringingCallState;
1437 mForegroundCallState = foregroundCallState;
1438 mBackgroundCallState = backgroundCallState;
1439 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1440 backgroundCallState,
1441 DisconnectCause.NOT_VALID,
1442 PreciseDisconnectCause.NOT_VALID);
1443 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001444 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001445 try {
1446 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1447 } catch (RemoteException ex) {
1448 mRemoveList.add(r.binder);
1449 }
1450 }
1451 }
1452 handleRemoveListLocked();
1453 }
1454 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1455 DisconnectCause.NOT_VALID,
1456 PreciseDisconnectCause.NOT_VALID);
1457 }
1458
1459 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1460 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1461 return;
1462 }
1463 synchronized (mRecords) {
1464 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1465 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1466 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001467 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001468 try {
1469 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1470 } catch (RemoteException ex) {
1471 mRemoveList.add(r.binder);
1472 }
1473 }
1474 }
1475 handleRemoveListLocked();
1476 }
1477 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1478 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1479 }
1480
1481 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1482 String apn, String failCause) {
1483 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1484 return;
1485 }
1486 synchronized (mRecords) {
1487 mPreciseDataConnectionState = new PreciseDataConnectionState(
1488 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1489 apnType, apn, reason, null, failCause);
1490 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001491 if (r.matchPhoneStateListenerEvent(
1492 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001493 try {
1494 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1495 } catch (RemoteException ex) {
1496 mRemoveList.add(r.binder);
1497 }
1498 }
1499 }
1500 handleRemoveListLocked();
1501 }
1502 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1503 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1504 }
1505
Wink Savillefb40dd42014-06-12 17:02:31 -07001506 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1507 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1508 return;
1509 }
1510 synchronized (mRecords) {
1511 mVoLteServiceState = lteState;
1512 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001513 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001514 try {
1515 r.callback.onVoLteServiceStateChanged(
1516 new VoLteServiceState(mVoLteServiceState));
1517 } catch (RemoteException ex) {
1518 mRemoveList.add(r.binder);
1519 }
1520 }
1521 }
1522 handleRemoveListLocked();
1523 }
1524 }
1525
Shuo Qian066e8652018-04-25 21:02:35 +00001526 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1527 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1528 return;
1529 }
1530
1531 synchronized (mRecords) {
1532 for (Record r : mRecords) {
1533 if (VDBG) {
1534 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1535 }
1536 if ((r.matchPhoneStateListenerEvent(
1537 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1538 ((r.subId == subId) ||
1539 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1540 try {
1541 r.callback.onOemHookRawEvent(rawData);
1542 } catch (RemoteException ex) {
1543 mRemoveList.add(r.binder);
1544 }
1545 }
1546 }
1547 handleRemoveListLocked();
1548 }
1549 }
1550
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001551 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1552 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1553 return;
1554 }
1555
1556 if (VDBG) {
1557 log("notifyPhoneCapabilityChanged: capability=" + capability);
1558 }
1559
1560 synchronized (mRecords) {
1561 mPhoneCapability = capability;
1562
1563 for (Record r : mRecords) {
1564 if (r.matchPhoneStateListenerEvent(
1565 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1566 try {
1567 r.callback.onPhoneCapabilityChanged(capability);
1568 } catch (RemoteException ex) {
1569 mRemoveList.add(r.binder);
1570 }
1571 }
1572 }
1573 handleRemoveListLocked();
1574 }
1575 }
1576
1577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001579 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1580 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1581
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001582 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001585 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001587 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301588 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001589 pw.println("Phone Id=" + i);
1590 pw.increaseIndent();
1591 pw.println("mCallState=" + mCallState[i]);
1592 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1593 pw.println("mServiceState=" + mServiceState[i]);
1594 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1595 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001596 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001597 pw.println("mSignalStrength=" + mSignalStrength[i]);
1598 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1599 pw.println("mCallForwarding=" + mCallForwarding[i]);
1600 pw.println("mDataActivity=" + mDataActivity[i]);
1601 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001602 pw.println("mCellLocation=" + mCellLocation[i]);
1603 pw.println("mCellInfo=" + mCellInfo.get(i));
1604 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301605 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001606 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1607 pw.println("mPreciseCallState=" + mPreciseCallState);
1608 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1609 pw.println("mRingingCallState=" + mRingingCallState);
1610 pw.println("mForegroundCallState=" + mForegroundCallState);
1611 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1612 pw.println("mVoLteServiceState=" + mVoLteServiceState);
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001613 pw.println("mPhoneCapability=" + mPhoneCapability);
Jack Yud19b6ae2017-04-05 14:12:09 -07001614
1615 pw.decreaseIndent();
1616
1617 pw.println("local logs:");
1618 pw.increaseIndent();
1619 mLocalLog.dump(fd, pw, args);
1620 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001621 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001622 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001623 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001624 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001626 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 }
1628 }
1629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 //
1631 // the legacy intent broadcasting
1632 //
1633
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001634 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001635 long ident = Binder.clearCallingIdentity();
1636 try {
1637 mBatteryStats.notePhoneState(state.getState());
1638 } catch (RemoteException re) {
1639 // Can't do much
1640 } finally {
1641 Binder.restoreCallingIdentity(ident);
1642 }
1643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001645 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 Bundle data = new Bundle();
1647 state.fillInNotifierBundle(data);
1648 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001649 // Pass the subscription along with the intent.
1650 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001651 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001652 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001653 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 }
1655
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001656 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1657 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001658 long ident = Binder.clearCallingIdentity();
1659 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001660 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001661 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001662 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001663 } finally {
1664 Binder.restoreCallingIdentity(ident);
1665 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001668 Bundle data = new Bundle();
1669 signalStrength.fillInNotifierBundle(data);
1670 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001671 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001672 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001673 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 }
1675
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001676 /**
1677 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1678 * a valid subId, in which case this function fires a subId-specific intent, or it
1679 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1680 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1681 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001682 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1683 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 long ident = Binder.clearCallingIdentity();
1685 try {
1686 if (state == TelephonyManager.CALL_STATE_IDLE) {
1687 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001688 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1689 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 } else {
1691 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001692 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1693 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 }
1695 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001696 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 } finally {
1698 Binder.restoreCallingIdentity(ident);
1699 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001702 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001703 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001704
1705 // If a valid subId was specified, we should fire off a subId-specific state
1706 // change intent and include the subId.
1707 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1708 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1709 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001710 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001711 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001712 // If the phoneId is invalid, the broadcast is for overall call state.
1713 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1714 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1715 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001716
Brad Ebinger51de96a2017-04-21 17:05:18 -07001717 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1718 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1719
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001720 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001721 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001722 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1723
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001724 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1725 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001726 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001727 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001728 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001729 android.Manifest.permission.READ_PHONE_STATE,
1730 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001731 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1732 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1733 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001734 }
1735
Robert Greenwalt42acef32009-08-12 16:08:25 -07001736 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001737 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001738 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001739 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001740 // Note: not reporting to the battery stats service here, because the
1741 // status bar takes care of that after taking into account all of the
1742 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001743 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001744 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001745 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001746 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001747 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 }
1749 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001750 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001751 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001752 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001753 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001754 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001755 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001756 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001757 }
1758 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001759 if (networkCapabilities != null) {
1760 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001761 }
Wink Savillea639b312012-07-10 12:37:54 -07001762 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001763
Wink Savillea639b312012-07-10 12:37:54 -07001764 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1765 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001766 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001767 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768 }
1769
Wink Savillefb40dd42014-06-12 17:02:31 -07001770 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001771 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001772 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001773 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1774 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001775 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001776 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001778
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001779 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1780 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1781 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1782 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1783 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1784 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1785 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1786 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1787 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1788 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1789 }
1790
1791 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001792 String apnType, String apn, String reason, LinkProperties linkProperties,
1793 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001794 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1795 intent.putExtra(PhoneConstants.STATE_KEY, state);
1796 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1797 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1798 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1799 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001800 if (linkProperties != null) {
1801 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1802 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001803 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1804
1805 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1806 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1807 }
1808
Andrew Flynnceaed682015-06-09 12:36:58 +00001809 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001810 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001811 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001812 }
1813
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001814 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1815 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001816 }
1817
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001818 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001819 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001820 return true;
1821 }
1822 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001823 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001824 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001825 return false;
1826 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001827
Andrew Flynn1f452642015-04-14 22:16:04 -04001828 private boolean checkNotifyPermission() {
1829 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1830 == PackageManager.PERMISSION_GRANTED;
1831 }
1832
Jeff Davidson29da89f2018-02-28 17:50:16 -08001833 private boolean checkListenerPermission(
1834 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001835 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001836 mContext.enforceCallingOrSelfPermission(
1837 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001838 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1839 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1840 return false;
1841 }
John Wang963db55d2012-03-30 16:04:06 -07001842 }
1843
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001844 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1846 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001847 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001848 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001849 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001850
1851 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1852 mContext.enforceCallingOrSelfPermission(
1853 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001854 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001855
Shuo Qian066e8652018-04-25 21:02:35 +00001856 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1857 mContext.enforceCallingOrSelfPermission(
1858 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1859 }
1860
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001861 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001862 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001863
1864 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001865 int size = mRemoveList.size();
1866 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1867 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001868 for (IBinder b: mRemoveList) {
1869 remove(b);
1870 }
1871 mRemoveList.clear();
1872 }
1873 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001874
1875 private boolean validateEventsAndUserLocked(Record r, int events) {
1876 int foregroundUser;
1877 long callingIdentity = Binder.clearCallingIdentity();
1878 boolean valid = false;
1879 try {
1880 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001881 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1882 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001883 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001884 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001885 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001886 + " r.events=" + r.events + " events=" + events);
1887 }
1888 } finally {
1889 Binder.restoreCallingIdentity(callingIdentity);
1890 }
1891 return valid;
1892 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001893
1894 private boolean validatePhoneId(int phoneId) {
1895 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001896 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001897 return valid;
1898 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001899
1900 private static void log(String s) {
1901 Rlog.d(TAG, s);
1902 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001903
xinhe8b79fb62014-11-05 14:55:03 -08001904 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001905
1906 if(subId < 0) {
1907 // Invalid case, we need compare phoneId with default one.
1908 return (mDefaultPhoneId == phoneId);
1909 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001910 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001911 return (subId == mDefaultSubId);
1912 } else {
1913 return (rSubId == subId);
1914 }
1915 }
1916
Hall Liu5fb337f2017-11-22 17:38:15 -08001917 private boolean checkLocationAccess(Record r) {
1918 long token = Binder.clearCallingIdentity();
1919 try {
1920 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001921 r.callingPackage, r.callerUid, r.callerPid,
1922 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001923 } finally {
1924 Binder.restoreCallingIdentity(token);
1925 }
1926 }
1927
xinhee9f16402014-09-25 16:39:28 -07001928 private void checkPossibleMissNotify(Record r, int phoneId) {
1929 int events = r.events;
1930
1931 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1932 try {
1933 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1934 mServiceState[phoneId]);
1935 r.callback.onServiceStateChanged(
1936 new ServiceState(mServiceState[phoneId]));
1937 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001938 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001939 }
1940 }
1941
1942 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1943 try {
1944 SignalStrength signalStrength = mSignalStrength[phoneId];
1945 if (DBG) {
1946 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1947 }
1948 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1949 } catch (RemoteException ex) {
1950 mRemoveList.add(r.binder);
1951 }
1952 }
1953
1954 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1955 try {
1956 int gsmSignalStrength = mSignalStrength[phoneId]
1957 .getGsmSignalStrength();
1958 if (DBG) {
1959 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1960 gsmSignalStrength);
1961 }
1962 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1963 : gsmSignalStrength));
1964 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001965 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001966 }
1967 }
1968
1969 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1970 try {
1971 if (DBG_LOC) {
1972 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1973 + mCellInfo.get(phoneId));
1974 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001975 if (checkLocationAccess(r)) {
1976 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1977 }
xinhee9f16402014-09-25 16:39:28 -07001978 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001979 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001980 }
1981 }
1982
zxuan35a47022018-01-04 11:24:04 -08001983 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1984 try {
1985 if (VDBG) {
1986 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1987 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1988 }
1989 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1990 } catch (RemoteException ex) {
1991 mRemoveList.add(r.binder);
1992 }
1993 }
1994
xinhee9f16402014-09-25 16:39:28 -07001995 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1996 try {
1997 if (VDBG) {
1998 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1999 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2000 }
2001 r.callback.onMessageWaitingIndicatorChanged(
2002 mMessageWaiting[phoneId]);
2003 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002004 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002005 }
2006 }
2007
2008 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2009 try {
2010 if (VDBG) {
2011 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2012 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2013 }
2014 r.callback.onCallForwardingIndicatorChanged(
2015 mCallForwarding[phoneId]);
2016 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002017 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002018 }
2019 }
2020
2021 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2022 try {
2023 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2024 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002025 if (checkLocationAccess(r)) {
2026 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2027 }
xinhee9f16402014-09-25 16:39:28 -07002028 } catch (RemoteException ex) {
2029 mRemoveList.add(r.binder);
2030 }
2031 }
2032
2033 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2034 try {
2035 if (DBG) {
2036 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2037 + "=" + mDataConnectionState[phoneId]
2038 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2039 + ")");
2040 }
2041 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2042 mDataConnectionNetworkType[phoneId]);
2043 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002044 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002045 }
2046 }
2047 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048}