blob: fc34434b57b21c0f3cb65ec23121b87acd1d9fc7 [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
Malcolm Chena37405b2019-11-06 15:03:23 -080019import static android.telephony.TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED;
20
21import static java.util.Arrays.copyOf;
22
Wink Savillea12a7b32012-09-20 10:09:45 -070023import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070024import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070025import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.Context;
27import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070028import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070030import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070031import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Binder;
Hall Liuee313732018-11-27 14:36:51 -080033import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070035import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070037import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070039import android.os.UserHandle;
zoey chenb1f74e72019-12-04 16:33:59 +080040import android.telephony.Annotation;
Chen Xu7631ff72019-09-26 16:11:59 -070041import android.telephony.Annotation.DataFailureCause;
42import android.telephony.Annotation.RadioPowerState;
43import android.telephony.Annotation.SrvccState;
Jordan Liu8218ddd2018-11-28 11:22:39 -080044import android.telephony.CallAttributes;
45import android.telephony.CallQuality;
John Wang963db55d2012-03-30 16:04:06 -070046import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070047import android.telephony.CellLocation;
chen xu16e24cd2018-12-11 18:09:41 -080048import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020049import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080050import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070051import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070052import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080053import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020054import android.telephony.PreciseCallState;
55import android.telephony.PreciseDataConnectionState;
56import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070057import android.telephony.Rlog;
58import android.telephony.ServiceState;
59import android.telephony.SignalStrength;
60import android.telephony.SubscriptionManager;
61import android.telephony.TelephonyManager;
chen xu16e24cd2018-12-11 18:09:41 -080062import android.telephony.data.ApnSetting;
sqianbdc5a732018-10-26 13:27:51 -070063import android.telephony.emergency.EmergencyNumber;
chen xu6ac5fc12019-01-24 14:14:13 -080064import android.telephony.ims.ImsReasonInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070065import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070066import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070068import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080070import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070072import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080073import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070074import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080076import com.android.internal.telephony.TelephonyPermissions;
chen xubadf2b02019-04-26 17:45:26 -070077import com.android.internal.util.ArrayUtils;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060078import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070079import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080import com.android.server.am.BatteryStatsService;
81
Jack Yud19b6ae2017-04-05 14:12:09 -070082import java.io.FileDescriptor;
83import java.io.PrintWriter;
84import java.util.ArrayList;
chen xu5b98d402019-03-22 16:56:34 -070085import java.util.Arrays;
sqian9f93a122018-12-03 22:40:41 -080086import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070087import java.util.List;
sqian9f93a122018-12-03 22:40:41 -080088import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080089import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091/**
Wink Savillee9b06d72009-05-18 21:47:50 -070092 * Since phone process can be restarted, this class provides a centralized place
93 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070094 *
95 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
96 * and 15973975 by saving the phoneId of the registrant and then using the
97 * phoneId when deciding to to make a callback. This is necessary because
98 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070099 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -0700100 * the dummy value conversion we properly do the callbacks.
101 *
102 * Eventually we may want to remove the notion of dummy value but for now this
103 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700105@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
106public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -0700108 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -0700109 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -0700110 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111
112 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800113 Context context;
114
Svet Ganov16a16892015-04-16 10:32:04 -0700115 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700118
Malcolm Chenabbfac22018-02-12 19:15:59 -0800119 TelephonyRegistryDeathRecipient deathRecipient;
120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800122 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700123 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700124
Hall Liu5fb337f2017-11-22 17:38:15 -0800125 int callerUid;
126 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700129
Wink Savilled09c4ca2014-11-22 10:08:16 -0800130 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700131
Wink Savilled09c4ca2014-11-22 10:08:16 -0800132 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800133
134 boolean matchPhoneStateListenerEvent(int events) {
135 return (callback != null) && ((events & this.events) != 0);
136 }
137
Wink Savilled09c4ca2014-11-22 10:08:16 -0800138 boolean matchOnSubscriptionsChangedListener() {
139 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800140 }
Wink Savillee380b982014-07-26 18:24:22 -0700141
Malcolm Chen13f31af2018-09-04 22:12:31 -0700142 boolean matchOnOpportunisticSubscriptionsChangedListener() {
143 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
144 }
145
Tyler Gunnf955e562018-04-26 14:43:31 -0700146 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800147 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700148 return TelephonyPermissions.checkReadCallLog(
149 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800150 } catch (SecurityException e) {
151 return false;
152 }
153 }
154
Wink Savillea12a7b32012-09-20 10:09:45 -0700155 @Override
156 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700157 return "{callingPackage=" + callingPackage + " binder=" + binder
158 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800159 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700160 + onSubscriptionsChangedListenerCallback
161 + " onOpportunisticSubscriptionsChangedListenererCallback="
162 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800163 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800164 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 }
167
168 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Joe Onorato163d8d92010-10-21 13:21:20 -0400170 // access should be inside synchronized (mRecords) for these two fields
171 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
172 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 private final IBatteryStats mBatteryStats;
175
Svet Ganov16a16892015-04-16 10:32:04 -0700176 private final AppOpsManager mAppOps;
177
Malcolm Chen13f31af2018-09-04 22:12:31 -0700178 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
179
180 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800181
Wink Savillefb40dd42014-06-12 17:02:31 -0700182 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700183
Wink Savillefb40dd42014-06-12 17:02:31 -0700184 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
fionaxu12312f62016-11-14 13:32:14 -0800190 private int[] mVoiceActivationState;
191
192 private int[] mDataActivationState;
193
zxuan35a47022018-01-04 11:24:04 -0800194 private boolean[] mUserMobileDataState;
195
Wink Savillefb40dd42014-06-12 17:02:31 -0700196 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700197
Wink Savillefb40dd42014-06-12 17:02:31 -0700198 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700199
Wink Savillefb40dd42014-06-12 17:02:31 -0700200 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700201
Wink Savillefb40dd42014-06-12 17:02:31 -0700202 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700203
Jack Yub1bac542018-03-14 16:23:38 -0700204 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700205 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700206
Wink Savillefb40dd42014-06-12 17:02:31 -0700207 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208
Wink Savillefb40dd42014-06-12 17:02:31 -0700209 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700210
chen xud5deeb12019-04-29 13:57:42 -0700211 private int[] mOtaspMode;
Wink Savillefd2d0132010-10-28 14:22:26 -0700212
Wink Savillefb40dd42014-06-12 17:02:31 -0700213 private ArrayList<List<CellInfo>> mCellInfo = null;
214
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800215 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
216
sqian9f93a122018-12-03 22:40:41 -0800217 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
218
Shuo Qianb61230c2019-09-12 17:00:31 -0700219 private EmergencyNumber[] mOutgoingSmsEmergencyNumber;
220
221 private EmergencyNumber[] mOutgoingCallEmergencyNumber;
222
chen xud5deeb12019-04-29 13:57:42 -0700223 private CallQuality[] mCallQuality;
Jordan Liu8218ddd2018-11-28 11:22:39 -0800224
chen xud5deeb12019-04-29 13:57:42 -0700225 private CallAttributes[] mCallAttributes;
Jordan Liu8218ddd2018-11-28 11:22:39 -0800226
Jordan Liu65ed9d92019-02-19 14:42:07 -0800227 // network type of the call associated with the mCallAttributes and mCallQuality
chen xud5deeb12019-04-29 13:57:42 -0700228 private int[] mCallNetworkType;
Jordan Liu65ed9d92019-02-19 14:42:07 -0800229
Brad Ebingerefed9822018-10-26 10:25:57 -0700230 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700231
Wink Savilled09c4ca2014-11-22 10:08:16 -0800232 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700233
Wink Savilled09c4ca2014-11-22 10:08:16 -0800234 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700235
chen xud5deeb12019-04-29 13:57:42 -0700236 private int[] mRingingCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200237
chen xud5deeb12019-04-29 13:57:42 -0700238 private int[] mForegroundCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200239
chen xud5deeb12019-04-29 13:57:42 -0700240 private int[] mBackgroundCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200241
chen xud5deeb12019-04-29 13:57:42 -0700242 private PreciseCallState[] mPreciseCallState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200243
chen xud5deeb12019-04-29 13:57:42 -0700244 private int[] mCallDisconnectCause;
chen xu6a942d482018-12-12 19:59:30 -0800245
chen xu6ac5fc12019-01-24 14:14:13 -0800246 private List<ImsReasonInfo> mImsReasonInfo = null;
247
chen xud5deeb12019-04-29 13:57:42 -0700248 private int[] mCallPreciseDisconnectCause;
chen xu6a942d482018-12-12 19:59:30 -0800249
Andrew Flynn1f452642015-04-14 22:16:04 -0400250 private boolean mCarrierNetworkChangeState = false;
251
Malcolm Chene1623652018-08-08 20:27:45 -0700252 private PhoneCapability mPhoneCapability = null;
253
Malcolm Chen026451d2019-02-14 19:50:19 -0800254 private int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700255
Chen Xu7631ff72019-09-26 16:11:59 -0700256 @RadioPowerState
Chen Xu7395c632018-10-17 17:53:47 +0000257 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
258
Jack Yud19b6ae2017-04-05 14:12:09 -0700259 private final LocalLog mLocalLog = new LocalLog(100);
260
Jack Yu0c92c232019-04-04 15:10:17 -0700261 private final LocalLog mListenLog = new LocalLog(100);
262
chen xud5deeb12019-04-29 13:57:42 -0700263 private PreciseDataConnectionState[] mPreciseDataConnectionState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200264
Hall Liuee313732018-11-27 14:36:51 -0800265 // Nothing here yet, but putting it here in case we want to add more in the future.
266 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = 0;
267
268 static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK =
Hall Liu70bbc162018-03-02 17:44:46 -0800269 PhoneStateListener.LISTEN_CELL_LOCATION
270 | PhoneStateListener.LISTEN_CELL_INFO;
271
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700272 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian9f93a122018-12-03 22:40:41 -0800273 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
274 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
sqian9e9ed182019-03-20 16:17:09 -0700275 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700276
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200277 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
278 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
279 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
280
Shuo Qianb61230c2019-09-12 17:00:31 -0700281 static final int READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK =
Shuo Qiand9663762019-10-04 13:20:45 -0700282 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL
283 | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS;
Shuo Qianb61230c2019-09-12 17:00:31 -0700284
Wink Savillea12a7b32012-09-20 10:09:45 -0700285 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700286 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700287
288 private final Handler mHandler = new Handler() {
289 @Override
290 public void handleMessage(Message msg) {
291 switch (msg.what) {
292 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700293 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Malcolm Chena37405b2019-11-06 15:03:23 -0800294 int numPhones = getTelephonyManager().getPhoneCount();
Wink Savillefb40dd42014-06-12 17:02:31 -0700295 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700296 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700297 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700298 }
299 break;
300 }
xinhee9f16402014-09-25 16:39:28 -0700301 case MSG_UPDATE_DEFAULT_SUB: {
302 int newDefaultPhoneId = msg.arg1;
Taesu Leec955cd92019-09-23 08:06:31 +0900303 int newDefaultSubId = msg.arg2;
xinhee9f16402014-09-25 16:39:28 -0700304 if (VDBG) {
305 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
Taesu Leec955cd92019-09-23 08:06:31 +0900306 + " current mDefaultPhoneId=" + mDefaultPhoneId
307 + " newDefaultSubId=" + newDefaultSubId
308 + " newDefaultPhoneId=" + newDefaultPhoneId);
xinhee9f16402014-09-25 16:39:28 -0700309 }
310
311 //Due to possible risk condition,(notify call back using the new
312 //defaultSubId comes before new defaultSubId update) we need to recall all
313 //possible missed notify callback
314 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700315 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800316 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700317 checkPossibleMissNotify(r, newDefaultPhoneId);
318 }
319 }
320 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700321 }
322 mDefaultSubId = newDefaultSubId;
323 mDefaultPhoneId = newDefaultPhoneId;
Jack Yu0c92c232019-04-04 15:10:17 -0700324 mLocalLog.log("Default subscription updated: mDefaultPhoneId="
Taesu Leec955cd92019-09-23 08:06:31 +0900325 + mDefaultPhoneId + ", mDefaultSubId=" + mDefaultSubId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700326 }
327 }
328 }
329 };
330
Malcolm Chenabbfac22018-02-12 19:15:59 -0800331 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
332
333 private final IBinder binder;
334
335 TelephonyRegistryDeathRecipient(IBinder binder) {
336 this.binder = binder;
337 }
338
339 @Override
340 public void binderDied() {
341 if (DBG) log("binderDied " + binder);
342 remove(binder);
343 }
344 }
345
Wink Savillea12a7b32012-09-20 10:09:45 -0700346 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
347 @Override
348 public void onReceive(Context context, Intent intent) {
349 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700350 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700351 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700352 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700353 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700354 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Taesu Leec955cd92019-09-23 08:06:31 +0900355 } else if (action.equals(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
356 int newDefaultSubId = intent.getIntExtra(
357 SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
358 SubscriptionManager.getDefaultSubscriptionId());
359 int newDefaultPhoneId = intent.getIntExtra(
360 PhoneConstants.PHONE_KEY,
361 SubscriptionManager.getPhoneId(newDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700362 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700363 log("onReceive:current mDefaultSubId=" + mDefaultSubId
Taesu Leec955cd92019-09-23 08:06:31 +0900364 + " current mDefaultPhoneId=" + mDefaultPhoneId
365 + " newDefaultSubId=" + newDefaultSubId
366 + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700367 }
xinhee9f16402014-09-25 16:39:28 -0700368
Taesu Leec955cd92019-09-23 08:06:31 +0900369 if (validatePhoneId(newDefaultPhoneId)
370 && (newDefaultSubId != mDefaultSubId
371 || newDefaultPhoneId != mDefaultPhoneId)) {
xinhee9f16402014-09-25 16:39:28 -0700372 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
Taesu Leec955cd92019-09-23 08:06:31 +0900373 newDefaultPhoneId, newDefaultSubId));
xinhee9f16402014-09-25 16:39:28 -0700374 }
Malcolm Chena37405b2019-11-06 15:03:23 -0800375 } else if (action.equals(ACTION_MULTI_SIM_CONFIG_CHANGED)) {
376 onMultiSimConfigChanged();
Wink Savillea12a7b32012-09-20 10:09:45 -0700377 }
378 }
379 };
380
Malcolm Chena37405b2019-11-06 15:03:23 -0800381 private TelephonyManager getTelephonyManager() {
382 return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
383 }
384
385 private void onMultiSimConfigChanged() {
386 int oldNumPhones = mNumPhones;
387 mNumPhones = getTelephonyManager().getActiveModemCount();
388 if (oldNumPhones == mNumPhones) return;
389
390 if (DBG) {
391 log("TelephonyRegistry: activeModemCount changed from " + oldNumPhones
392 + " to " + mNumPhones);
393 }
394 mCallState = copyOf(mCallState, mNumPhones);
395 mDataActivity = copyOf(mCallState, mNumPhones);
396 mDataConnectionState = copyOf(mCallState, mNumPhones);
397 mDataConnectionNetworkType = copyOf(mCallState, mNumPhones);
398 mCallIncomingNumber = copyOf(mCallIncomingNumber, mNumPhones);
399 mServiceState = copyOf(mServiceState, mNumPhones);
400 mVoiceActivationState = copyOf(mVoiceActivationState, mNumPhones);
401 mDataActivationState = copyOf(mDataActivationState, mNumPhones);
402 mUserMobileDataState = copyOf(mUserMobileDataState, mNumPhones);
403 mSignalStrength = copyOf(mSignalStrength, mNumPhones);
404 mMessageWaiting = copyOf(mMessageWaiting, mNumPhones);
405 mCallForwarding = copyOf(mCallForwarding, mNumPhones);
406 mCellLocation = copyOf(mCellLocation, mNumPhones);
407 mSrvccState = copyOf(mSrvccState, mNumPhones);
408 mOtaspMode = copyOf(mOtaspMode, mNumPhones);
409 mPreciseCallState = copyOf(mPreciseCallState, mNumPhones);
410 mForegroundCallState = copyOf(mForegroundCallState, mNumPhones);
411 mBackgroundCallState = copyOf(mBackgroundCallState, mNumPhones);
412 mRingingCallState = copyOf(mRingingCallState, mNumPhones);
413 mCallDisconnectCause = copyOf(mCallDisconnectCause, mNumPhones);
414 mCallPreciseDisconnectCause = copyOf(mCallPreciseDisconnectCause, mNumPhones);
415 mCallQuality = copyOf(mCallQuality, mNumPhones);
416 mCallNetworkType = copyOf(mCallNetworkType, mNumPhones);
417 mCallAttributes = copyOf(mCallAttributes, mNumPhones);
418 mPreciseDataConnectionState = copyOf(mPreciseDataConnectionState, mNumPhones);
419 mOutgoingCallEmergencyNumber = copyOf(mOutgoingCallEmergencyNumber, mNumPhones);
420 mOutgoingSmsEmergencyNumber = copyOf(mOutgoingSmsEmergencyNumber, mNumPhones);
421
422 // ds -> ss switch.
423 if (mNumPhones < oldNumPhones) {
424 cutListToSize(mCellInfo, mNumPhones);
425 cutListToSize(mImsReasonInfo, mNumPhones);
426 cutListToSize(mPhysicalChannelConfigs, mNumPhones);
427 return;
428 }
429
430 // mNumPhones > oldNumPhones: ss -> ds switch
431 for (int i = oldNumPhones; i < mNumPhones; i++) {
432 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
433 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
434 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
435 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
436 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
437 mCallIncomingNumber[i] = "";
438 mServiceState[i] = new ServiceState();
439 mSignalStrength[i] = new SignalStrength();
440 mUserMobileDataState[i] = false;
441 mMessageWaiting[i] = false;
442 mCallForwarding[i] = false;
443 mCellLocation[i] = new Bundle();
444 mCellInfo.add(i, null);
445 mImsReasonInfo.add(i, null);
446 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
447 mPhysicalChannelConfigs.add(i, new ArrayList<>());
448 mOtaspMode[i] = TelephonyManager.OTASP_UNKNOWN;
449 mCallDisconnectCause[i] = DisconnectCause.NOT_VALID;
450 mCallPreciseDisconnectCause[i] = PreciseDisconnectCause.NOT_VALID;
451 mCallQuality[i] = new CallQuality();
452 mCallAttributes[i] = new CallAttributes(new PreciseCallState(),
453 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
454 mCallNetworkType[i] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
455 mPreciseCallState[i] = new PreciseCallState();
456 mRingingCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
457 mForegroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
458 mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
459 mPreciseDataConnectionState[i] = new PreciseDataConnectionState();
460 }
461
462 // Note that location can be null for non-phone builds like
463 // like the generic one.
464 CellLocation location = CellLocation.getEmpty();
465 if (location != null) {
466 for (int i = oldNumPhones; i < mNumPhones; i++) {
467 location.fillInNotifierBundle(mCellLocation[i]);
468 }
469 }
470 }
471
472 private void cutListToSize(List list, int size) {
473 if (list == null) return;
474
475 while (list.size() > size) {
476 list.remove(list.size() - 1);
477 }
478 }
479
Wink Savillee9b06d72009-05-18 21:47:50 -0700480 // we keep a copy of all of the state so we can send it out when folks
481 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700483 // In these calls we call with the lock held. This is safe becasuse remote
484 // calls go through a oneway interface and local calls going through a
485 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700487 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
488 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700489 CellLocation location = CellLocation.getEmpty();
490
Wink Savillefb40dd42014-06-12 17:02:31 -0700491 mContext = context;
492 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700493
Malcolm Chena37405b2019-11-06 15:03:23 -0800494 int numPhones = getTelephonyManager().getActiveModemCount();
Jack Yub1bac542018-03-14 16:23:38 -0700495 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700496 mNumPhones = numPhones;
497 mCallState = new int[numPhones];
498 mDataActivity = new int[numPhones];
499 mDataConnectionState = new int[numPhones];
500 mDataConnectionNetworkType = new int[numPhones];
501 mCallIncomingNumber = new String[numPhones];
502 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800503 mVoiceActivationState = new int[numPhones];
504 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800505 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700506 mSignalStrength = new SignalStrength[numPhones];
507 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700508 mCallForwarding = new boolean[numPhones];
509 mCellLocation = new Bundle[numPhones];
Brad Ebingerefed9822018-10-26 10:25:57 -0700510 mSrvccState = new int[numPhones];
chen xud5deeb12019-04-29 13:57:42 -0700511 mOtaspMode = new int[numPhones];
512 mPreciseCallState = new PreciseCallState[numPhones];
513 mForegroundCallState = new int[numPhones];
514 mBackgroundCallState = new int[numPhones];
515 mRingingCallState = new int[numPhones];
516 mCallDisconnectCause = new int[numPhones];
517 mCallPreciseDisconnectCause = new int[numPhones];
518 mCallQuality = new CallQuality[numPhones];
519 mCallNetworkType = new int[numPhones];
520 mCallAttributes = new CallAttributes[numPhones];
521 mPreciseDataConnectionState = new PreciseDataConnectionState[numPhones];
522 mCellInfo = new ArrayList<>();
523 mImsReasonInfo = new ArrayList<>();
524 mPhysicalChannelConfigs = new ArrayList<>();
sqian9f93a122018-12-03 22:40:41 -0800525 mEmergencyNumberList = new HashMap<>();
Shuo Qianb61230c2019-09-12 17:00:31 -0700526 mOutgoingCallEmergencyNumber = new EmergencyNumber[numPhones];
527 mOutgoingSmsEmergencyNumber = new EmergencyNumber[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700528 for (int i = 0; i < numPhones; i++) {
529 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
530 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
531 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800532 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
533 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700534 mCallIncomingNumber[i] = "";
535 mServiceState[i] = new ServiceState();
536 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800537 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700538 mMessageWaiting[i] = false;
539 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700540 mCellLocation[i] = new Bundle();
541 mCellInfo.add(i, null);
chen xu6ac5fc12019-01-24 14:14:13 -0800542 mImsReasonInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700543 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
chen xud5deeb12019-04-29 13:57:42 -0700544 mPhysicalChannelConfigs.add(i, new ArrayList<>());
545 mOtaspMode[i] = TelephonyManager.OTASP_UNKNOWN;
546 mCallDisconnectCause[i] = DisconnectCause.NOT_VALID;
547 mCallPreciseDisconnectCause[i] = PreciseDisconnectCause.NOT_VALID;
548 mCallQuality[i] = new CallQuality();
549 mCallAttributes[i] = new CallAttributes(new PreciseCallState(),
550 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
551 mCallNetworkType[i] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
552 mPreciseCallState[i] = new PreciseCallState();
553 mRingingCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
554 mForegroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
555 mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
556 mPreciseDataConnectionState[i] = new PreciseDataConnectionState();
Wink Savillefb40dd42014-06-12 17:02:31 -0700557 }
558
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700559 // Note that location can be null for non-phone builds like
560 // like the generic one.
561 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 for (int i = 0; i < numPhones; i++) {
563 location.fillInNotifierBundle(mCellLocation[i]);
564 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700565 }
Svet Ganov16a16892015-04-16 10:32:04 -0700566
567 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 }
569
Svetoslav Ganova0027152013-06-25 14:59:53 -0700570 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700571 // Watch for interesting updates
572 final IntentFilter filter = new IntentFilter();
573 filter.addAction(Intent.ACTION_USER_SWITCHED);
574 filter.addAction(Intent.ACTION_USER_REMOVED);
Taesu Leec955cd92019-09-23 08:06:31 +0900575 filter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Malcolm Chena37405b2019-11-06 15:03:23 -0800576 filter.addAction(ACTION_MULTI_SIM_CONFIG_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700577 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700578 mContext.registerReceiver(mBroadcastReceiver, filter);
579 }
580
581 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700582 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800583 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700584 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800586 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700587 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
588 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800589 + " callback.asBinder=" + callback.asBinder());
590 }
591
Wink Savilled09c4ca2014-11-22 10:08:16 -0800592 synchronized (mRecords) {
593 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800594 IBinder b = callback.asBinder();
595 Record r = add(b);
596
597 if (r == null) {
598 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800599 }
600
Jeff Davidson29da89f2018-02-28 17:50:16 -0800601 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800602 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700603 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800604 r.callerUid = Binder.getCallingUid();
605 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800606 r.events = 0;
607 if (DBG) {
608 log("listen oscl: Register r=" + r);
609 }
610 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700611 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800612 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800613 if (VDBG) log("listen oscl: send to r=" + r);
614 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
615 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800616 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800617 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800618 remove(r.binder);
619 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800620 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700621 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800622 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800623 }
624 }
625
626 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800627 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800628 IOnSubscriptionsChangedListener callback) {
629 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800630 remove(callback.asBinder());
631 }
632
Malcolm Chen13f31af2018-09-04 22:12:31 -0700633
634 @Override
635 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
636 IOnSubscriptionsChangedListener callback) {
637 int callerUserId = UserHandle.getCallingUserId();
638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
639 if (VDBG) {
640 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
641 + " callerUserId=" + callerUserId + " callback=" + callback
642 + " callback.asBinder=" + callback.asBinder());
643 }
644
645 synchronized (mRecords) {
646 // register
647 IBinder b = callback.asBinder();
648 Record r = add(b);
649
650 if (r == null) {
651 return;
652 }
653
654 r.context = mContext;
655 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
656 r.callingPackage = callingPackage;
657 r.callerUid = Binder.getCallingUid();
658 r.callerPid = Binder.getCallingPid();
659 r.events = 0;
660 if (DBG) {
661 log("listen ooscl: Register r=" + r);
662 }
663 // Always notify when registration occurs if there has been a notification.
664 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
665 try {
666 if (VDBG) log("listen ooscl: send to r=" + r);
667 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
668 if (VDBG) log("listen ooscl: sent to r=" + r);
669 } catch (RemoteException e) {
670 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
671 remove(r.binder);
672 }
673 } else {
674 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
675 }
676 }
677 }
678
Wink Savillea374c3d2014-11-11 11:48:04 -0800679 @Override
680 public void notifySubscriptionInfoChanged() {
681 if (VDBG) log("notifySubscriptionInfoChanged:");
682 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700683 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800684 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
685 + mRecords.size());
686 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700687 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800688 mRemoveList.clear();
689 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800690 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800691 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800692 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
693 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
694 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800695 } catch (RemoteException ex) {
696 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
697 mRemoveList.add(r.binder);
698 }
699 }
700 }
701 handleRemoveListLocked();
702 }
703 }
704
705 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700706 public void notifyOpportunisticSubscriptionInfoChanged() {
707 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
708 synchronized (mRecords) {
709 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
710 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
711 + mRecords.size());
712 }
713 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
714 mRemoveList.clear();
715 for (Record r : mRecords) {
716 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
717 try {
718 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
719 r.onOpportunisticSubscriptionsChangedListenerCallback
720 .onSubscriptionsChanged();
721 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
722 } catch (RemoteException ex) {
723 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
724 mRemoveList.add(r.binder);
725 }
726 }
727 }
728 handleRemoveListLocked();
729 }
730 }
731
732 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
734 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800735 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
736 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700737 }
738
739 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700740 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700741 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700742 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700743 }
744
Svet Ganov16a16892015-04-16 10:32:04 -0700745 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700746 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700747 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jack Yu0c92c232019-04-04 15:10:17 -0700749 String str = "listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700750 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
Jack Yu0c92c232019-04-04 15:10:17 -0700751 + UserHandle.myUserId() + " callerUserId=" + callerUserId;
752 mListenLog.log(str);
753 if (VDBG) {
754 log(str);
Wink Savillea12a7b32012-09-20 10:09:45 -0700755 }
xinhe75c2c152014-10-16 11:49:45 -0700756
757 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800758 // Checks permission and throws SecurityException for disallowed operations. For pre-M
759 // apps whose runtime permission has been revoked, we return immediately to skip sending
760 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800761 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800762 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700763 }
764
yifan.baie620ce72017-12-22 14:59:57 +0800765 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 synchronized (mRecords) {
767 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800768 IBinder b = callback.asBinder();
769 Record r = add(b);
770
771 if (r == null) {
772 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 }
xinhe43c50292014-09-18 17:56:48 -0700774
Jeff Davidson29da89f2018-02-28 17:50:16 -0800775 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700776 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700777 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800778 r.callerUid = Binder.getCallingUid();
779 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700780 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
781 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800783 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700784 } else {//APP specify subID
785 r.subId = subId;
786 }
yifan.baie620ce72017-12-22 14:59:57 +0800787 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700789 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700790 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700791 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700792 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400794 try {
Wink Savillee380b982014-07-26 18:24:22 -0700795 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800796 ServiceState rawSs = new ServiceState(mServiceState[phoneId]);
797 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
798 r.callback.onServiceStateChanged(rawSs);
799 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
800 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(false));
801 } else {
802 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(true));
803 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400804 } catch (RemoteException ex) {
805 remove(r.binder);
806 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 }
808 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
809 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700810 int gsmSignalStrength = mSignalStrength[phoneId]
811 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700812 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
813 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 } catch (RemoteException ex) {
815 remove(r.binder);
816 }
817 }
818 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
819 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700820 r.callback.onMessageWaitingIndicatorChanged(
821 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 } catch (RemoteException ex) {
823 remove(r.binder);
824 }
825 }
826 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
827 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700828 r.callback.onCallForwardingIndicatorChanged(
829 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 } catch (RemoteException ex) {
831 remove(r.binder);
832 }
833 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700834 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400835 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700836 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700837 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800838 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800839 r.callback.onCellLocationChanged(
840 new Bundle(mCellLocation[phoneId]));
841 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400842 } catch (RemoteException ex) {
843 remove(r.binder);
844 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 }
846 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
847 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700848 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700849 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 } catch (RemoteException ex) {
851 remove(r.binder);
852 }
853 }
854 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
855 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700856 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
857 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 } catch (RemoteException ex) {
859 remove(r.binder);
860 }
861 }
862 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
863 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700864 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 } catch (RemoteException ex) {
866 remove(r.binder);
867 }
868 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700869 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
870 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700871 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700872 } catch (RemoteException ex) {
873 remove(r.binder);
874 }
875 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700876 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
877 try {
chen xud5deeb12019-04-29 13:57:42 -0700878 r.callback.onOtaspChanged(mOtaspMode[phoneId]);
Wink Savillefd2d0132010-10-28 14:22:26 -0700879 } catch (RemoteException ex) {
880 remove(r.binder);
881 }
882 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700883 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700884 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700885 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700886 + mCellInfo.get(phoneId));
Hall Liuee313732018-11-27 14:36:51 -0800887 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800888 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
889 }
John Wang963db55d2012-03-30 16:04:06 -0700890 } catch (RemoteException ex) {
891 remove(r.binder);
892 }
893 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200894 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
895 try {
chen xud5deeb12019-04-29 13:57:42 -0700896 r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200897 } catch (RemoteException ex) {
898 remove(r.binder);
899 }
900 }
chen xu6a942d482018-12-12 19:59:30 -0800901 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
902 try {
chen xud5deeb12019-04-29 13:57:42 -0700903 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId],
904 mCallPreciseDisconnectCause[phoneId]);
chen xu6a942d482018-12-12 19:59:30 -0800905 } catch (RemoteException ex) {
906 remove(r.binder);
907 }
908 }
chen xu6ac5fc12019-01-24 14:14:13 -0800909 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
910 try {
911 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
912 } catch (RemoteException ex) {
913 remove(r.binder);
914 }
915 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200916 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
917 try {
918 r.callback.onPreciseDataConnectionStateChanged(
chen xud5deeb12019-04-29 13:57:42 -0700919 mPreciseDataConnectionState[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200920 } catch (RemoteException ex) {
921 remove(r.binder);
922 }
923 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400924 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
925 try {
926 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
927 } catch (RemoteException ex) {
928 remove(r.binder);
929 }
930 }
fionaxu12312f62016-11-14 13:32:14 -0800931 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
932 try {
933 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
934 } catch (RemoteException ex) {
935 remove(r.binder);
936 }
937 }
938 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
939 try {
940 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
941 } catch (RemoteException ex) {
942 remove(r.binder);
943 }
944 }
zxuan35a47022018-01-04 11:24:04 -0800945 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
946 try {
947 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
948 } catch (RemoteException ex) {
949 remove(r.binder);
950 }
951 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800952 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
953 try {
954 r.callback.onPhysicalChannelConfigurationChanged(
955 mPhysicalChannelConfigs.get(phoneId));
956 } catch (RemoteException ex) {
957 remove(r.binder);
958 }
959 }
sqian9f93a122018-12-03 22:40:41 -0800960 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
961 try {
962 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
963 } catch (RemoteException ex) {
964 remove(r.binder);
965 }
966 }
Malcolm Chene1623652018-08-08 20:27:45 -0700967 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
968 try {
969 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
970 } catch (RemoteException ex) {
971 remove(r.binder);
972 }
973 }
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800974 if ((events & PhoneStateListener
Malcolm Chen118b02f2019-09-04 16:10:34 -0700975 .LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700976 try {
Malcolm Chen026451d2019-02-14 19:50:19 -0800977 r.callback.onActiveDataSubIdChanged(mActiveDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700978 } catch (RemoteException ex) {
979 remove(r.binder);
980 }
981 }
Chen Xu7395c632018-10-17 17:53:47 +0000982 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
983 try {
984 r.callback.onRadioPowerStateChanged(mRadioPowerState);
985 } catch (RemoteException ex) {
986 remove(r.binder);
987 }
988 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700989 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
990 try {
991 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
992 } catch (RemoteException ex) {
993 remove(r.binder);
994 }
995 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800996 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
997 try {
chen xud5deeb12019-04-29 13:57:42 -0700998 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
Jordan Liu8218ddd2018-11-28 11:22:39 -0800999 } catch (RemoteException ex) {
1000 remove(r.binder);
1001 }
1002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 }
1004 }
1005 } else {
xinhe75c2c152014-10-16 11:49:45 -07001006 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 remove(callback.asBinder());
1008 }
1009 }
1010
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001011 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -07001012 // Only reveal the incoming number if the record has read call log permission.
1013 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001014 }
1015
Malcolm Chenabbfac22018-02-12 19:15:59 -08001016 private Record add(IBinder binder) {
1017 Record r;
1018
1019 synchronized (mRecords) {
1020 final int N = mRecords.size();
1021 for (int i = 0; i < N; i++) {
1022 r = mRecords.get(i);
1023 if (binder == r.binder) {
1024 // Already existed.
1025 return r;
1026 }
1027 }
1028 r = new Record();
1029 r.binder = binder;
1030 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
1031
1032 try {
1033 binder.linkToDeath(r.deathRecipient, 0);
1034 } catch (RemoteException e) {
1035 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
1036 // Binder already died. Return null.
1037 return null;
1038 }
1039
1040 mRecords.add(r);
1041 if (DBG) log("add new record");
1042 }
1043
1044 return r;
1045 }
1046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 private void remove(IBinder binder) {
1048 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001049 final int recordCount = mRecords.size();
1050 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -08001051 Record r = mRecords.get(i);
1052 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -08001053 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -08001054 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
1055 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -08001056 }
Malcolm Chenabbfac22018-02-12 19:15:59 -08001057
1058 if (r.deathRecipient != null) {
1059 try {
1060 binder.unlinkToDeath(r.deathRecipient, 0);
1061 } catch (NoSuchElementException e) {
1062 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
1063 + r + " e=" + e);
1064 }
1065 }
1066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 mRecords.remove(i);
1068 return;
1069 }
1070 }
1071 }
1072 }
1073
Chen Xu1f1c25e2019-09-15 18:28:21 -07001074 public void notifyCallStateForAllSubs(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001075 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001076 return;
1077 }
xinhe43c50292014-09-18 17:56:48 -07001078
1079 if (VDBG) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001080 log("notifyCallStateForAllSubs: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -07001081 }
1082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -07001084 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001085 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -08001086 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 try {
Tyler Gunnf955e562018-04-26 14:43:31 -07001088 // Ensure the listener has read call log permission; if they do not return
1089 // an empty phone number.
1090 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
1091 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001093 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 }
1095 }
1096 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001097 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001099
1100 // Called only by Telecomm to communicate call state across different phone accounts. So
1101 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -07001102 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001103 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001104 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
1106
Chen Xu1f1c25e2019-09-15 18:28:21 -07001107 public void notifyCallState(int phoneId, int subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001108 if (!checkNotifyPermission("notifyCallState()")) {
1109 return;
1110 }
Wink Savillee380b982014-07-26 18:24:22 -07001111 if (VDBG) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001112 log("notifyCallState: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001113 + " state=" + state + " incomingNumber=" + incomingNumber);
1114 }
1115 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001116 if (validatePhoneId(phoneId)) {
1117 mCallState[phoneId] = state;
1118 mCallIncomingNumber[phoneId] = incomingNumber;
1119 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001120 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -07001121 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -08001122 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001123 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001124 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
1125 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -07001126 } catch (RemoteException ex) {
1127 mRemoveList.add(r.binder);
1128 }
1129 }
1130 }
1131 }
1132 handleRemoveListLocked();
1133 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001134 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001135 }
1136
Wink Saville63f03dd2014-10-23 10:44:45 -07001137 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001138 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001139 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001140 }
xinhe43c50292014-09-18 17:56:48 -07001141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001143 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
1144 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -07001145 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001146 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -07001147 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001148 mLocalLog.log(str);
Jordan Liud2d614a2019-06-24 11:27:34 -07001149 // for service state updates, don't notify clients when subId is invalid. This prevents
1150 // us from sending incorrect notifications like b/133140128
1151 // In the future, we can remove this logic for every notification here and add a
1152 // callback so listeners know when their PhoneStateListener's subId becomes invalid, but
1153 // for now we use the simplest fix.
1154 if (validatePhoneId(phoneId) && SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001155 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001156
Wink Savillefb40dd42014-06-12 17:02:31 -07001157 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001158 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001159 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001160 + " phoneId=" + phoneId + " state=" + state);
1161 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001162 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001163 idMatch(r.subId, subId, phoneId)) {
Hall Liuee313732018-11-27 14:36:51 -08001164
Wink Savillefb40dd42014-06-12 17:02:31 -07001165 try {
Hall Liuee313732018-11-27 14:36:51 -08001166 ServiceState stateToSend;
1167 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
1168 stateToSend = new ServiceState(state);
1169 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
1170 stateToSend = state.sanitizeLocationInfo(false);
1171 } else {
1172 stateToSend = state.sanitizeLocationInfo(true);
1173 }
Wink Savillee380b982014-07-26 18:24:22 -07001174 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001175 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001176 + " subId=" + subId + " phoneId=" + phoneId
1177 + " state=" + state);
1178 }
Hall Liuee313732018-11-27 14:36:51 -08001179 r.callback.onServiceStateChanged(stateToSend);
Wink Savillefb40dd42014-06-12 17:02:31 -07001180 } catch (RemoteException ex) {
1181 mRemoveList.add(r.binder);
1182 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001185 } else {
Jordan Liud2d614a2019-06-24 11:27:34 -07001186 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId
1187 + " or subId=" + subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001189 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001191 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 }
1193
fionaxu12312f62016-11-14 13:32:14 -08001194 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1195 int activationType, int activationState) {
1196 if (!checkNotifyPermission("notifySimActivationState()")){
1197 return;
1198 }
1199 if (VDBG) {
1200 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1201 + "type=" + activationType + " state=" + activationState);
1202 }
1203 synchronized (mRecords) {
1204 if (validatePhoneId(phoneId)) {
1205 switch (activationType) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001206 case TelephonyManager.SIM_ACTIVATION_TYPE_VOICE:
fionaxu12312f62016-11-14 13:32:14 -08001207 mVoiceActivationState[phoneId] = activationState;
1208 break;
Chen Xu1f1c25e2019-09-15 18:28:21 -07001209 case TelephonyManager.SIM_ACTIVATION_TYPE_DATA:
fionaxu12312f62016-11-14 13:32:14 -08001210 mDataActivationState[phoneId] = activationState;
1211 break;
1212 default:
1213 return;
1214 }
1215 for (Record r : mRecords) {
1216 if (VDBG) {
1217 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1218 + " phoneId=" + phoneId + "type=" + activationType
1219 + " state=" + activationState);
1220 }
1221 try {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001222 if ((activationType == TelephonyManager.SIM_ACTIVATION_TYPE_VOICE) &&
fionaxu12312f62016-11-14 13:32:14 -08001223 r.matchPhoneStateListenerEvent(
1224 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1225 idMatch(r.subId, subId, phoneId)) {
1226 if (DBG) {
1227 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1228 + " subId=" + subId + " phoneId=" + phoneId
1229 + " state=" + activationState);
1230 }
1231 r.callback.onVoiceActivationStateChanged(activationState);
1232 }
Chen Xu1f1c25e2019-09-15 18:28:21 -07001233 if ((activationType == TelephonyManager.SIM_ACTIVATION_TYPE_DATA) &&
fionaxu12312f62016-11-14 13:32:14 -08001234 r.matchPhoneStateListenerEvent(
1235 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1236 idMatch(r.subId, subId, phoneId)) {
1237 if (DBG) {
1238 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1239 + " subId=" + subId + " phoneId=" + phoneId
1240 + " state=" + activationState);
1241 }
1242 r.callback.onDataActivationStateChanged(activationState);
1243 }
1244 } catch (RemoteException ex) {
1245 mRemoveList.add(r.binder);
1246 }
1247 }
1248 } else {
1249 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1250 }
1251 handleRemoveListLocked();
1252 }
1253 }
1254
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001255 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1256 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001257 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001258 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001259 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001260 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001261 log("notifySignalStrengthForPhoneId: subId=" + subId
1262 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001263 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001266 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001267 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001268 mSignalStrength[phoneId] = signalStrength;
1269 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001270 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001271 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001272 + " phoneId=" + phoneId + " ss=" + signalStrength);
1273 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001274 if (r.matchPhoneStateListenerEvent(
1275 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001276 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001277 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001278 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001279 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001280 + " subId=" + subId + " phoneId=" + phoneId
1281 + " ss=" + signalStrength);
1282 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001283 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1284 } catch (RemoteException ex) {
1285 mRemoveList.add(r.binder);
1286 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001287 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001288 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001289 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001290 try {
1291 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001292 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001293 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001294 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001295 + " subId=" + subId + " phoneId=" + phoneId
1296 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1297 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001298 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001299 } catch (RemoteException ex) {
1300 mRemoveList.add(r.binder);
1301 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 }
1303 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001304 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001305 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001307 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001309 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 }
1311
Andrew Flynn1f452642015-04-14 22:16:04 -04001312 @Override
1313 public void notifyCarrierNetworkChange(boolean active) {
chen xubadf2b02019-04-26 17:45:26 -07001314 // only CarrierService with carrier privilege rule should have the permission
1315 int[] subIds = Arrays.stream(SubscriptionManager.from(mContext)
Malcolm Chen1eb939c2019-09-25 14:02:14 -07001316 .getActiveSubscriptionIdList(false))
chen xubadf2b02019-04-26 17:45:26 -07001317 .filter(i -> TelephonyPermissions.checkCarrierPrivilegeForSubId(i)).toArray();
1318 if (ArrayUtils.isEmpty(subIds)) {
chen xu627d1b22019-04-11 02:16:19 -07001319 loge("notifyCarrierNetworkChange without carrier privilege");
chen xubadf2b02019-04-26 17:45:26 -07001320 // the active subId does not have carrier privilege.
chen xu627d1b22019-04-11 02:16:19 -07001321 throw new SecurityException("notifyCarrierNetworkChange without carrier privilege");
chen xu5b98d402019-03-22 16:56:34 -07001322 }
Andrew Flynn1f452642015-04-14 22:16:04 -04001323
1324 synchronized (mRecords) {
1325 mCarrierNetworkChangeState = active;
chen xubadf2b02019-04-26 17:45:26 -07001326 for (int subId : subIds) {
1327 int phoneId = SubscriptionManager.getPhoneId(subId);
1328
1329 if (VDBG) {
1330 log("notifyCarrierNetworkChange: active=" + active + "subId: " + subId);
1331 }
1332 for (Record r : mRecords) {
1333 if (r.matchPhoneStateListenerEvent(
1334 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) &&
1335 idMatch(r.subId, subId, phoneId)) {
1336 try {
1337 r.callback.onCarrierNetworkChange(active);
1338 } catch (RemoteException ex) {
1339 mRemoveList.add(r.binder);
1340 }
Andrew Flynn1f452642015-04-14 22:16:04 -04001341 }
1342 }
1343 }
1344 handleRemoveListLocked();
1345 }
1346 }
1347
Wink Savilleb208a242012-07-25 14:08:09 -07001348 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001349 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001350 }
1351
Wink Saville63f03dd2014-10-23 10:44:45 -07001352 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001353 if (!checkNotifyPermission("notifyCellInfoForSubscriber()")) {
John Wang963db55d2012-03-30 16:04:06 -07001354 return;
1355 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001356 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001357 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001358 + " cellInfo=" + cellInfo);
1359 }
yifan.baie620ce72017-12-22 14:59:57 +08001360 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001361 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001362 if (validatePhoneId(phoneId)) {
1363 mCellInfo.set(phoneId, cellInfo);
1364 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001365 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001366 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001367 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001368 try {
1369 if (DBG_LOC) {
Chen Xu1f1c25e2019-09-15 18:28:21 -07001370 log("notifyCellInfoForSubscriber: mCellInfo=" + cellInfo
1371 + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001372 }
1373 r.callback.onCellInfoChanged(cellInfo);
1374 } catch (RemoteException ex) {
1375 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001376 }
John Wang963db55d2012-03-30 16:04:06 -07001377 }
1378 }
1379 }
1380 handleRemoveListLocked();
1381 }
1382 }
1383
andychouce659222019-06-19 20:54:32 +08001384 /**
1385 * Notify physical channel configuration according to subscripton ID and phone ID
1386 */
1387 public void notifyPhysicalChannelConfigurationForSubscriber(int phoneId, int subId,
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001388 List<PhysicalChannelConfig> configs) {
1389 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1390 return;
1391 }
1392
1393 if (VDBG) {
andychouce659222019-06-19 20:54:32 +08001394 log("notifyPhysicalChannelConfiguration: subId=" + subId + " phoneId=" + phoneId
1395 + " configs=" + configs);
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001396 }
1397
1398 synchronized (mRecords) {
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001399 if (validatePhoneId(phoneId)) {
1400 mPhysicalChannelConfigs.set(phoneId, configs);
1401 for (Record r : mRecords) {
1402 if (r.matchPhoneStateListenerEvent(
1403 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1404 && idMatch(r.subId, subId, phoneId)) {
1405 try {
1406 if (DBG_LOC) {
1407 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1408 + configs + " r=" + r);
1409 }
1410 r.callback.onPhysicalChannelConfigurationChanged(configs);
1411 } catch (RemoteException ex) {
1412 mRemoveList.add(r.binder);
1413 }
1414 }
1415 }
1416 }
1417 handleRemoveListLocked();
1418 }
1419 }
1420
xinhe43c50292014-09-18 17:56:48 -07001421 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001422 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001423 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001424 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001425 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001426 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001427 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001428 + " mwi=" + mwi);
1429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001431 if (validatePhoneId(phoneId)) {
1432 mMessageWaiting[phoneId] = mwi;
1433 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001434 if (r.matchPhoneStateListenerEvent(
1435 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001436 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001437 try {
1438 r.callback.onMessageWaitingIndicatorChanged(mwi);
1439 } catch (RemoteException ex) {
1440 mRemoveList.add(r.binder);
1441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 }
1443 }
1444 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001445 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 }
1447 }
1448
zxuan35a47022018-01-04 11:24:04 -08001449 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1450 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1451 return;
1452 }
1453 if (VDBG) {
SongFerngWang0b109f5f2019-04-09 17:29:29 +08001454 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: PhoneId=" + phoneId
1455 + " subId=" + subId + " state=" + state);
zxuan35a47022018-01-04 11:24:04 -08001456 }
1457 synchronized (mRecords) {
1458 if (validatePhoneId(phoneId)) {
SongFerngWang0b109f5f2019-04-09 17:29:29 +08001459 mUserMobileDataState[phoneId] = state;
zxuan35a47022018-01-04 11:24:04 -08001460 for (Record r : mRecords) {
1461 if (r.matchPhoneStateListenerEvent(
1462 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1463 idMatch(r.subId, subId, phoneId)) {
1464 try {
1465 r.callback.onUserMobileDataStateChanged(state);
1466 } catch (RemoteException ex) {
1467 mRemoveList.add(r.binder);
1468 }
1469 }
1470 }
1471 }
1472 handleRemoveListLocked();
1473 }
1474 }
1475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001477 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001478 }
1479
Wink Saville63f03dd2014-10-23 10:44:45 -07001480 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001481 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001482 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001483 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001484 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001485 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001486 + " cfi=" + cfi);
1487 }
yifan.baie620ce72017-12-22 14:59:57 +08001488 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001490 if (validatePhoneId(phoneId)) {
1491 mCallForwarding[phoneId] = cfi;
1492 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001493 if (r.matchPhoneStateListenerEvent(
1494 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001495 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001496 try {
1497 r.callback.onCallForwardingIndicatorChanged(cfi);
1498 } catch (RemoteException ex) {
1499 mRemoveList.add(r.binder);
1500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 }
1502 }
1503 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001504 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 }
1506 }
1507
1508 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001509 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001510 }
1511
Wink Saville63f03dd2014-10-23 10:44:45 -07001512 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001513 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001514 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001515 }
yifan.baie620ce72017-12-22 14:59:57 +08001516 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001518 if (validatePhoneId(phoneId)) {
1519 mDataActivity[phoneId] = state;
1520 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001521 // Notify by correct subId.
1522 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1523 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001524 try {
1525 r.callback.onDataActivity(state);
1526 } catch (RemoteException ex) {
1527 mRemoveList.add(r.binder);
1528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 }
1530 }
1531 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001532 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 }
1534 }
1535
Jack Yu4d1c9452019-01-02 16:51:08 -08001536 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1537 LinkProperties linkProperties,
1538 NetworkCapabilities networkCapabilities, int networkType,
1539 boolean roaming) {
chen xud5deeb12019-04-29 13:57:42 -07001540 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX,
1541 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yu4d1c9452019-01-02 16:51:08 -08001542 isDataAllowed, apn, apnType, linkProperties,
1543 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001544 }
1545
chen xud5deeb12019-04-29 13:57:42 -07001546 public void notifyDataConnectionForSubscriber(int phoneId, int subId, int state,
1547 boolean isDataAllowed,
Jack Yu4d1c9452019-01-02 16:51:08 -08001548 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001549 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1550 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001551 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001552 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001553 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001554 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001555 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001556 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001557 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001558 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001561 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001562 // We only call the callback when the change is for default APN type.
1563 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1564 && (mDataConnectionState[phoneId] != state
1565 || mDataConnectionNetworkType[phoneId] != networkType)) {
Jack Yu0c92c232019-04-04 15:10:17 -07001566 String str = "onDataConnectionStateChanged("
zoey chenb1f74e72019-12-04 16:33:59 +08001567 + dataStateToString(state)
1568 + ", " + getNetworkTypeName(networkType)
Jack Yu0c92c232019-04-04 15:10:17 -07001569 + ") subId=" + subId + ", phoneId=" + phoneId;
Jack Yud19b6ae2017-04-05 14:12:09 -07001570 log(str);
1571 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001572 for (Record r : mRecords) {
1573 if (r.matchPhoneStateListenerEvent(
chen xud5deeb12019-04-29 13:57:42 -07001574 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE)
1575 && idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001576 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001577 if (DBG) {
1578 log("Notify data connection state changed on sub: " + subId);
1579 }
Jack Yub1bac542018-03-14 16:23:38 -07001580 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001581 } catch (RemoteException ex) {
1582 mRemoveList.add(r.binder);
1583 }
1584 }
1585 }
1586 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001587
1588 mDataConnectionState[phoneId] = state;
1589 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001590 }
chen xud5deeb12019-04-29 13:57:42 -07001591 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1592 state, networkType,
chen xu16e24cd2018-12-11 18:09:41 -08001593 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1594 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001595 for (Record r : mRecords) {
1596 if (r.matchPhoneStateListenerEvent(
chen xud5deeb12019-04-29 13:57:42 -07001597 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1598 && idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001599 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001600 r.callback.onPreciseDataConnectionStateChanged(
chen xud5deeb12019-04-29 13:57:42 -07001601 mPreciseDataConnectionState[phoneId]);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001602 } catch (RemoteException ex) {
1603 mRemoveList.add(r.binder);
1604 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001605 }
1606 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001607 }
1608 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001610 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1611 networkCapabilities, roaming, subId);
1612 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu16e24cd2018-12-11 18:09:41 -08001613 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 }
1615
Jack Yu4d1c9452019-01-02 16:51:08 -08001616 public void notifyDataConnectionFailed(String apnType) {
chen xud5deeb12019-04-29 13:57:42 -07001617 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX,
1618 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yu4d1c9452019-01-02 16:51:08 -08001619 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001620 }
1621
chen xud5deeb12019-04-29 13:57:42 -07001622 public void notifyDataConnectionFailedForSubscriber(int phoneId, int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001623 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001624 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001625 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001626 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001627 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yu4d1c9452019-01-02 16:51:08 -08001628 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001629 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001631 if (validatePhoneId(phoneId)) {
1632 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1633 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1634 ApnSetting.getApnTypesBitmaskFromString(apnType), null, null,
1635 DataFailCause.NONE);
1636 for (Record r : mRecords) {
1637 if (r.matchPhoneStateListenerEvent(
1638 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1639 && idMatch(r.subId, subId, phoneId)) {
1640 try {
1641 r.callback.onPreciseDataConnectionStateChanged(
1642 mPreciseDataConnectionState[phoneId]);
1643 } catch (RemoteException ex) {
1644 mRemoveList.add(r.binder);
1645 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 }
1648 }
chen xud5deeb12019-04-29 13:57:42 -07001649
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001650 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001652 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001653 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu81653862019-02-28 10:44:54 -08001654 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, null, null,
chen xu16e24cd2018-12-11 18:09:41 -08001655 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 }
1657
1658 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001659 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001660 }
1661
Wink Saville63f03dd2014-10-23 10:44:45 -07001662 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001663 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001664 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001665 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001666 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001667 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001668 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001669 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001670 + " cellLocation=" + cellLocation);
1671 }
yifan.baie620ce72017-12-22 14:59:57 +08001672 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001674 if (validatePhoneId(phoneId)) {
1675 mCellLocation[phoneId] = cellLocation;
1676 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001677 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001678 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001679 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001680 try {
1681 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001682 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001683 + " r=" + r);
1684 }
1685 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1686 } catch (RemoteException ex) {
1687 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001688 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 }
1691 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001692 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001693 }
1694 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695
chen xud5deeb12019-04-29 13:57:42 -07001696 public void notifyOtaspChanged(int subId, int otaspMode) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001697 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1698 return;
1699 }
chen xud5deeb12019-04-29 13:57:42 -07001700 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefd2d0132010-10-28 14:22:26 -07001701 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001702 if (validatePhoneId(phoneId)) {
1703 mOtaspMode[phoneId] = otaspMode;
1704 for (Record r : mRecords) {
1705 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)
1706 && idMatch(r.subId, subId, phoneId)) {
1707 try {
1708 r.callback.onOtaspChanged(otaspMode);
1709 } catch (RemoteException ex) {
1710 mRemoveList.add(r.binder);
1711 }
Wink Savillefd2d0132010-10-28 14:22:26 -07001712 }
1713 }
1714 }
1715 handleRemoveListLocked();
1716 }
1717 }
1718
chen xud5deeb12019-04-29 13:57:42 -07001719 public void notifyPreciseCallState(int phoneId, int subId, int ringingCallState,
1720 int foregroundCallState, int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001721 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1722 return;
1723 }
1724 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001725 if (validatePhoneId(phoneId)) {
1726 mRingingCallState[phoneId] = ringingCallState;
1727 mForegroundCallState[phoneId] = foregroundCallState;
1728 mBackgroundCallState[phoneId] = backgroundCallState;
1729 mPreciseCallState[phoneId] = new PreciseCallState(
1730 ringingCallState, foregroundCallState,
1731 backgroundCallState,
1732 DisconnectCause.NOT_VALID,
1733 PreciseDisconnectCause.NOT_VALID);
1734 boolean notifyCallAttributes = true;
1735 if (mCallQuality == null) {
1736 log("notifyPreciseCallState: mCallQuality is null, "
1737 + "skipping call attributes");
1738 notifyCallAttributes = false;
1739 } else {
1740 // If the precise call state is no longer active, reset the call network type
1741 // and call quality.
1742 if (mPreciseCallState[phoneId].getForegroundCallState()
1743 != PreciseCallState.PRECISE_CALL_STATE_ACTIVE) {
1744 mCallNetworkType[phoneId] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1745 mCallQuality[phoneId] = new CallQuality();
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001746 }
chen xud5deeb12019-04-29 13:57:42 -07001747 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
1748 mCallNetworkType[phoneId], mCallQuality[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001749 }
chen xud5deeb12019-04-29 13:57:42 -07001750
1751 for (Record r : mRecords) {
1752 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)
1753 && idMatch(r.subId, subId, phoneId)) {
1754 try {
1755 r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]);
1756 } catch (RemoteException ex) {
1757 mRemoveList.add(r.binder);
1758 }
1759 }
1760 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1761 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
1762 && idMatch(r.subId, subId, phoneId)) {
1763 try {
1764 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
1765 } catch (RemoteException ex) {
1766 mRemoveList.add(r.binder);
1767 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001768 }
1769 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001770 }
1771 handleRemoveListLocked();
1772 }
chen xu6a942d482018-12-12 19:59:30 -08001773 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1774 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001775 }
1776
chen xud5deeb12019-04-29 13:57:42 -07001777 public void notifyDisconnectCause(int phoneId, int subId, int disconnectCause,
1778 int preciseDisconnectCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001779 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1780 return;
1781 }
1782 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001783 if (validatePhoneId(phoneId)) {
1784 mCallDisconnectCause[phoneId] = disconnectCause;
1785 mCallPreciseDisconnectCause[phoneId] = preciseDisconnectCause;
1786 for (Record r : mRecords) {
1787 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1788 .LISTEN_CALL_DISCONNECT_CAUSES) && idMatch(r.subId, subId, phoneId)) {
1789 try {
1790 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId],
1791 mCallPreciseDisconnectCause[phoneId]);
1792 } catch (RemoteException ex) {
1793 mRemoveList.add(r.binder);
1794 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001795 }
1796 }
1797 }
1798 handleRemoveListLocked();
1799 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001800 }
1801
chen xu6ac5fc12019-01-24 14:14:13 -08001802 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1803 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1804 return;
1805 }
1806 int phoneId = SubscriptionManager.getPhoneId(subId);
1807 synchronized (mRecords) {
1808 if (validatePhoneId(phoneId)) {
1809 mImsReasonInfo.set(phoneId, imsReasonInfo);
1810 for (Record r : mRecords) {
1811 if (r.matchPhoneStateListenerEvent(
1812 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1813 && idMatch(r.subId, subId, phoneId)) {
1814 try {
1815 if (DBG_LOC) {
1816 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1817 + imsReasonInfo + " r=" + r);
1818 }
1819 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1820 } catch (RemoteException ex) {
1821 mRemoveList.add(r.binder);
1822 }
1823 }
1824 }
1825 }
1826 handleRemoveListLocked();
1827 }
1828 }
1829
chen xud5deeb12019-04-29 13:57:42 -07001830 public void notifyPreciseDataConnectionFailed(int phoneId, int subId, String apnType,
Chen Xu7631ff72019-09-26 16:11:59 -07001831 String apn, @DataFailureCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001832 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1833 return;
1834 }
1835 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001836 if (validatePhoneId(phoneId)) {
1837 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1838 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1839 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
1840 for (Record r : mRecords) {
1841 if (r.matchPhoneStateListenerEvent(
1842 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1843 && idMatch(r.subId, subId, phoneId)) {
1844 try {
1845 r.callback.onPreciseDataConnectionStateChanged(
1846 mPreciseDataConnectionState[phoneId]);
1847 } catch (RemoteException ex) {
1848 mRemoveList.add(r.binder);
1849 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001850 }
1851 }
1852 }
chen xud5deeb12019-04-29 13:57:42 -07001853
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001854 handleRemoveListLocked();
1855 }
1856 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yu4d1c9452019-01-02 16:51:08 -08001857 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001858 }
1859
Brad Ebingerefed9822018-10-26 10:25:57 -07001860 @Override
Chen Xu7631ff72019-09-26 16:11:59 -07001861 public void notifySrvccStateChanged(int subId, @SrvccState int state) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001862 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001863 return;
1864 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001865 if (VDBG) {
1866 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1867 }
1868 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001869 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001870 if (validatePhoneId(phoneId)) {
chen xu6ac5fc12019-01-24 14:14:13 -08001871 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001872 for (Record r : mRecords) {
1873 if (r.matchPhoneStateListenerEvent(
1874 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1875 idMatch(r.subId, subId, phoneId)) {
1876 try {
1877 if (DBG_LOC) {
1878 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1879 }
1880 r.callback.onSrvccStateChanged(state);
1881 } catch (RemoteException ex) {
1882 mRemoveList.add(r.binder);
1883 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001884 }
1885 }
1886 }
1887 handleRemoveListLocked();
1888 }
1889 }
1890
chen xud5deeb12019-04-29 13:57:42 -07001891 public void notifyOemHookRawEventForSubscriber(int phoneId, int subId, byte[] rawData) {
Shuo Qian066e8652018-04-25 21:02:35 +00001892 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1893 return;
1894 }
1895
1896 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001897 if (validatePhoneId(phoneId)) {
1898 for (Record r : mRecords) {
1899 if (VDBG) {
1900 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1901 }
1902 if ((r.matchPhoneStateListenerEvent(
1903 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT))
1904 && idMatch(r.subId, subId, phoneId)) {
1905 try {
1906 r.callback.onOemHookRawEvent(rawData);
1907 } catch (RemoteException ex) {
1908 mRemoveList.add(r.binder);
1909 }
Shuo Qian066e8652018-04-25 21:02:35 +00001910 }
1911 }
1912 }
1913 handleRemoveListLocked();
1914 }
1915 }
1916
Malcolm Chene1623652018-08-08 20:27:45 -07001917 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1918 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1919 return;
1920 }
1921
1922 if (VDBG) {
1923 log("notifyPhoneCapabilityChanged: capability=" + capability);
1924 }
1925
1926 synchronized (mRecords) {
1927 mPhoneCapability = capability;
1928
1929 for (Record r : mRecords) {
1930 if (r.matchPhoneStateListenerEvent(
1931 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1932 try {
1933 r.callback.onPhoneCapabilityChanged(capability);
1934 } catch (RemoteException ex) {
1935 mRemoveList.add(r.binder);
1936 }
1937 }
1938 }
1939 handleRemoveListLocked();
1940 }
1941 }
1942
Malcolm Chen026451d2019-02-14 19:50:19 -08001943 public void notifyActiveDataSubIdChanged(int activeDataSubId) {
1944 if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001945 return;
1946 }
1947
1948 if (VDBG) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001949 log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001950 }
1951
sqian9e9ed182019-03-20 16:17:09 -07001952 mActiveDataSubId = activeDataSubId;
sqian9e9ed182019-03-20 16:17:09 -07001953 synchronized (mRecords) {
Malcolm Chen118b02f2019-09-04 16:10:34 -07001954 for (Record r : mRecords) {
1955 if (r.matchPhoneStateListenerEvent(
1956 PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE)) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001957 try {
Malcolm Chen026451d2019-02-14 19:50:19 -08001958 r.callback.onActiveDataSubIdChanged(activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001959 } catch (RemoteException ex) {
1960 mRemoveList.add(r.binder);
1961 }
1962 }
1963 }
1964 handleRemoveListLocked();
1965 }
1966 }
Malcolm Chene1623652018-08-08 20:27:45 -07001967
Chen Xu7631ff72019-09-26 16:11:59 -07001968 public void notifyRadioPowerStateChanged(int phoneId, int subId, @RadioPowerState int state) {
Chen Xu7395c632018-10-17 17:53:47 +00001969 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1970 return;
1971 }
1972
1973 if (VDBG) {
chen xud5deeb12019-04-29 13:57:42 -07001974 log("notifyRadioPowerStateChanged: state= " + state + " subId=" + subId);
Chen Xu7395c632018-10-17 17:53:47 +00001975 }
1976
1977 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001978 if (validatePhoneId(phoneId)) {
1979 mRadioPowerState = state;
Chen Xu7395c632018-10-17 17:53:47 +00001980
chen xud5deeb12019-04-29 13:57:42 -07001981 for (Record r : mRecords) {
1982 if (r.matchPhoneStateListenerEvent(
1983 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)
1984 && idMatch(r.subId, subId, phoneId)) {
1985 try {
1986 r.callback.onRadioPowerStateChanged(state);
1987 } catch (RemoteException ex) {
1988 mRemoveList.add(r.binder);
1989 }
Chen Xu7395c632018-10-17 17:53:47 +00001990 }
1991 }
chen xud5deeb12019-04-29 13:57:42 -07001992
Chen Xu7395c632018-10-17 17:53:47 +00001993 }
1994 handleRemoveListLocked();
1995 }
1996 }
1997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 @Override
chen xud5deeb12019-04-29 13:57:42 -07001999 public void notifyEmergencyNumberList(int phoneId, int subId) {
sqian9f93a122018-12-03 22:40:41 -08002000 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
2001 return;
2002 }
2003
2004 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07002005 if (validatePhoneId(phoneId)) {
2006 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
2007 Context.TELEPHONY_SERVICE);
2008 mEmergencyNumberList = tm.getEmergencyNumberList();
sqian9f93a122018-12-03 22:40:41 -08002009
chen xud5deeb12019-04-29 13:57:42 -07002010 for (Record r : mRecords) {
2011 if (r.matchPhoneStateListenerEvent(
2012 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)
2013 && idMatch(r.subId, subId, phoneId)) {
2014 try {
2015 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
2016 if (VDBG) {
2017 log("notifyEmergencyNumberList: emergencyNumberList= "
2018 + mEmergencyNumberList);
2019 }
2020 } catch (RemoteException ex) {
2021 mRemoveList.add(r.binder);
sqian9f93a122018-12-03 22:40:41 -08002022 }
sqian9f93a122018-12-03 22:40:41 -08002023 }
2024 }
2025 }
chen xud5deeb12019-04-29 13:57:42 -07002026
sqian9f93a122018-12-03 22:40:41 -08002027 handleRemoveListLocked();
2028 }
sqianbdc5a732018-10-26 13:27:51 -07002029 }
2030
Jordan Liu8218ddd2018-11-28 11:22:39 -08002031 @Override
Shuo Qianb61230c2019-09-12 17:00:31 -07002032 public void notifyOutgoingEmergencyCall(int phoneId, int subId,
2033 EmergencyNumber emergencyNumber) {
2034 if (!checkNotifyPermission("notifyOutgoingEmergencyCall()")) {
2035 return;
2036 }
2037 synchronized (mRecords) {
2038 if (validatePhoneId(phoneId)) {
2039 mOutgoingCallEmergencyNumber[phoneId] = emergencyNumber;
2040 for (Record r : mRecords) {
2041 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07002042 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL)
Shuo Qianb61230c2019-09-12 17:00:31 -07002043 && idMatch(r.subId, subId, phoneId)) {
2044 try {
2045 r.callback.onOutgoingEmergencyCall(emergencyNumber);
2046 } catch (RemoteException ex) {
2047 mRemoveList.add(r.binder);
2048 }
2049 }
2050 }
2051 }
2052 handleRemoveListLocked();
2053 }
2054 }
2055
2056 @Override
2057 public void notifyOutgoingEmergencySms(int phoneId, int subId,
2058 EmergencyNumber emergencyNumber) {
2059 if (!checkNotifyPermission("notifyOutgoingEmergencySms()")) {
2060 return;
2061 }
2062 synchronized (mRecords) {
2063 if (validatePhoneId(phoneId)) {
2064 mOutgoingSmsEmergencyNumber[phoneId] = emergencyNumber;
2065 for (Record r : mRecords) {
2066 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07002067 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS)
Shuo Qianb61230c2019-09-12 17:00:31 -07002068 && idMatch(r.subId, subId, phoneId)) {
2069 try {
2070 r.callback.onOutgoingEmergencySms(emergencyNumber);
2071 } catch (RemoteException ex) {
2072 mRemoveList.add(r.binder);
2073 }
2074 }
2075 }
2076 }
2077 handleRemoveListLocked();
2078 }
2079 }
2080
2081 @Override
chen xud5deeb12019-04-29 13:57:42 -07002082 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId, int subId,
Jordan Liu65ed9d92019-02-19 14:42:07 -08002083 int callNetworkType) {
Jordan Liu8218ddd2018-11-28 11:22:39 -08002084 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
2085 return;
2086 }
2087
Jordan Liu8218ddd2018-11-28 11:22:39 -08002088 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07002089 if (validatePhoneId(phoneId)) {
2090 // merge CallQuality with PreciseCallState and network type
2091 mCallQuality[phoneId] = callQuality;
2092 mCallNetworkType[phoneId] = callNetworkType;
2093 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
2094 callNetworkType, callQuality);
Jordan Liu8218ddd2018-11-28 11:22:39 -08002095
chen xud5deeb12019-04-29 13:57:42 -07002096 for (Record r : mRecords) {
2097 if (r.matchPhoneStateListenerEvent(
2098 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
2099 && idMatch(r.subId, subId, phoneId)) {
2100 try {
2101 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
2102 } catch (RemoteException ex) {
2103 mRemoveList.add(r.binder);
2104 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08002105 }
2106 }
2107 }
chen xud5deeb12019-04-29 13:57:42 -07002108
Jordan Liu8218ddd2018-11-28 11:22:39 -08002109 handleRemoveListLocked();
2110 }
2111 }
2112
sqianbdc5a732018-10-26 13:27:51 -07002113
2114 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07002115 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
2116 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
2117
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06002118 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07002119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002121 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07002123 pw.increaseIndent();
Malcolm Chena37405b2019-11-06 15:03:23 -08002124 for (int i = 0; i < getTelephonyManager().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002125 pw.println("Phone Id=" + i);
2126 pw.increaseIndent();
2127 pw.println("mCallState=" + mCallState[i]);
chen xud5deeb12019-04-29 13:57:42 -07002128 pw.println("mRingingCallState=" + mRingingCallState[i]);
2129 pw.println("mForegroundCallState=" + mForegroundCallState[i]);
2130 pw.println("mBackgroundCallState=" + mBackgroundCallState[i]);
2131 pw.println("mPreciseCallState=" + mPreciseCallState[i]);
2132 pw.println("mCallDisconnectCause=" + mCallDisconnectCause[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002133 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
2134 pw.println("mServiceState=" + mServiceState[i]);
2135 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
2136 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08002137 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002138 pw.println("mSignalStrength=" + mSignalStrength[i]);
2139 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
2140 pw.println("mCallForwarding=" + mCallForwarding[i]);
2141 pw.println("mDataActivity=" + mDataActivity[i]);
2142 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002143 pw.println("mCellLocation=" + mCellLocation[i]);
2144 pw.println("mCellInfo=" + mCellInfo.get(i));
Tyler Gunnf3f89d02019-03-25 07:26:33 -07002145 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i));
chen xud5deeb12019-04-29 13:57:42 -07002146 pw.println("mSrvccState=" + mSrvccState[i]);
2147 pw.println("mOtaspMode=" + mOtaspMode[i]);
2148 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause[i]);
2149 pw.println("mCallQuality=" + mCallQuality[i]);
2150 pw.println("mCallAttributes=" + mCallAttributes[i]);
2151 pw.println("mCallNetworkType=" + mCallNetworkType[i]);
2152 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState[i]);
Shuo Qianb61230c2019-09-12 17:00:31 -07002153 pw.println("mOutgoingCallEmergencyNumber=" + mOutgoingCallEmergencyNumber[i]);
2154 pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002155 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05302156 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002157 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
chen xud5deeb12019-04-29 13:57:42 -07002158
Malcolm Chene1623652018-08-08 20:27:45 -07002159 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen026451d2019-02-14 19:50:19 -08002160 pw.println("mActiveDataSubId=" + mActiveDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00002161 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian9f93a122018-12-03 22:40:41 -08002162 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
chen xuaddc2702019-05-07 16:25:12 -07002163 pw.println("mDefaultPhoneId=" + mDefaultPhoneId);
2164 pw.println("mDefaultSubId=" + mDefaultSubId);
Jack Yud19b6ae2017-04-05 14:12:09 -07002165
2166 pw.decreaseIndent();
2167
2168 pw.println("local logs:");
2169 pw.increaseIndent();
2170 mLocalLog.dump(fd, pw, args);
Jack Yu0c92c232019-04-04 15:10:17 -07002171 pw.println("listen logs:");
2172 mListenLog.dump(fd, pw, args);
Jack Yud19b6ae2017-04-05 14:12:09 -07002173 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07002174 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07002175 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07002176 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002177 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002179 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 }
2181 }
2182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 //
2184 // the legacy intent broadcasting
2185 //
2186
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002187 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07002188 long ident = Binder.clearCallingIdentity();
2189 try {
2190 mBatteryStats.notePhoneState(state.getState());
2191 } catch (RemoteException re) {
2192 // Can't do much
2193 } finally {
2194 Binder.restoreCallingIdentity(ident);
2195 }
2196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08002198 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 Bundle data = new Bundle();
2200 state.fillInNotifierBundle(data);
2201 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07002202 // Pass the subscription along with the intent.
2203 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002204 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002205 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002206 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 }
2208
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002209 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
2210 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002211 long ident = Binder.clearCallingIdentity();
2212 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07002213 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002214 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002215 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07002216 } finally {
2217 Binder.restoreCallingIdentity(ident);
2218 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07002221 Bundle data = new Bundle();
2222 signalStrength.fillInNotifierBundle(data);
2223 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07002224 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002225 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002226 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 }
2228
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002229 /**
2230 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
2231 * a valid subId, in which case this function fires a subId-specific intent, or it
2232 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
2233 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
2234 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002235 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
2236 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 long ident = Binder.clearCallingIdentity();
2238 try {
2239 if (state == TelephonyManager.CALL_STATE_IDLE) {
2240 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07002241 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2242 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 } else {
2244 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07002245 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2246 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 }
2248 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002249 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 } finally {
2251 Binder.restoreCallingIdentity(ident);
2252 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002255 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002256 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002257
2258 // If a valid subId was specified, we should fire off a subId-specific state
2259 // change intent and include the subId.
2260 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
2261 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
2262 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002263 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002264 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002265 // If the phoneId is invalid, the broadcast is for overall call state.
2266 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
2267 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
2268 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002269
Brad Ebinger51de96a2017-04-21 17:05:18 -07002270 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
2271 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
2272
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002273 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002274 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002275 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2276
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002277 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2278 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002279 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002280 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002281 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002282 android.Manifest.permission.READ_PHONE_STATE,
2283 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002284 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2285 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2286 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 }
2288
Jack Yu4d1c9452019-01-02 16:51:08 -08002289 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2290 String apnType, LinkProperties linkProperties,
2291 NetworkCapabilities networkCapabilities,
2292 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002293 // Note: not reporting to the battery stats service here, because the
2294 // status bar takes care of that after taking into account all of the
2295 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07002297 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08002298 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07002299 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002300 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002302 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002303 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002304 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002305 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002306 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002307 }
2308 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002309 if (networkCapabilities != null) {
2310 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002311 }
Wink Savillea639b312012-07-10 12:37:54 -07002312 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002313
Wink Savillea639b312012-07-10 12:37:54 -07002314 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2315 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002316 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002317 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 }
2319
Jack Yu4d1c9452019-01-02 16:51:08 -08002320 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002322 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002323 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002324 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002326
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002327 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yu4d1c9452019-01-02 16:51:08 -08002328 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002329 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2330 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2331 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2332 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002333 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2334 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2335 }
2336
2337 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu16e24cd2018-12-11 18:09:41 -08002338 String apnType, String apn, LinkProperties linkProperties,
Chen Xu7631ff72019-09-26 16:11:59 -07002339 @DataFailureCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002340 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2341 intent.putExtra(PhoneConstants.STATE_KEY, state);
2342 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002343 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2344 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002345 if (linkProperties != null) {
Jack Yu4d1c9452019-01-02 16:51:08 -08002346 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002347 }
chen xu16e24cd2018-12-11 18:09:41 -08002348 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002349
2350 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2351 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2352 }
2353
Andrew Flynnceaed682015-06-09 12:36:58 +00002354 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002355 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002356 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002357 }
2358
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002359 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2360 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002361 }
2362
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002363 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002364 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002365 return true;
2366 }
2367 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002368 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002369 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002370 return false;
2371 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002372
Andrew Flynn1f452642015-04-14 22:16:04 -04002373 private boolean checkNotifyPermission() {
2374 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2375 == PackageManager.PERMISSION_GRANTED;
2376 }
2377
Jeff Davidson29da89f2018-02-28 17:50:16 -08002378 private boolean checkListenerPermission(
2379 int events, int subId, String callingPackage, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002380 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2381 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2382 .setCallingPackage(callingPackage)
2383 .setMethod(message + " events: " + events)
2384 .setCallingPid(Binder.getCallingPid())
2385 .setCallingUid(Binder.getCallingUid());
2386
2387 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002388 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002389 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2390 shouldCheckLocationPermissions = true;
2391 }
2392
2393 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2394 // Everything that requires fine location started in Q. So far...
2395 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2396 shouldCheckLocationPermissions = true;
2397 }
2398
2399 if (shouldCheckLocationPermissions) {
2400 LocationAccessPolicy.LocationPermissionResult result =
2401 LocationAccessPolicy.checkLocationPermission(
2402 mContext, locationQueryBuilder.build());
2403 switch (result) {
2404 case DENIED_HARD:
2405 throw new SecurityException("Unable to listen for events " + events + " due to "
2406 + "insufficient location permissions.");
2407 case DENIED_SOFT:
2408 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002409 }
John Wang963db55d2012-03-30 16:04:06 -07002410 }
2411
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002412 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2414 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002415 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002416 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002417 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002418
2419 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2420 mContext.enforceCallingOrSelfPermission(
2421 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002422 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002423
Shuo Qianb61230c2019-09-12 17:00:31 -07002424 if ((events & READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK) != 0) {
2425 mContext.enforceCallingOrSelfPermission(
2426 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2427 }
2428
Shuo Qian066e8652018-04-25 21:02:35 +00002429 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2430 mContext.enforceCallingOrSelfPermission(
2431 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2432 }
2433
Brad Ebingerefed9822018-10-26 10:25:57 -07002434 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2435 mContext.enforceCallingOrSelfPermission(
2436 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2437 }
2438
chen xu6a942d482018-12-12 19:59:30 -08002439 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2440 mContext.enforceCallingOrSelfPermission(
2441 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2442 }
2443
Jordan Liu8218ddd2018-11-28 11:22:39 -08002444 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2445 mContext.enforceCallingOrSelfPermission(
2446 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2447 }
2448
chen xu52797b62019-01-18 13:16:31 -08002449 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2450 mContext.enforceCallingOrSelfPermission(
2451 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2452 }
2453
2454 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2455 mContext.enforceCallingOrSelfPermission(
2456 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2457 }
2458
chen xu6ac5fc12019-01-24 14:14:13 -08002459 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2460 mContext.enforceCallingOrSelfPermission(
2461 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2462 }
2463
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002464 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002465 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002466
2467 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002468 int size = mRemoveList.size();
2469 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2470 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002471 for (IBinder b: mRemoveList) {
2472 remove(b);
2473 }
2474 mRemoveList.clear();
2475 }
2476 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002477
2478 private boolean validateEventsAndUserLocked(Record r, int events) {
2479 int foregroundUser;
2480 long callingIdentity = Binder.clearCallingIdentity();
2481 boolean valid = false;
2482 try {
2483 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002484 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2485 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002486 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002487 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002488 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002489 + " r.events=" + r.events + " events=" + events);
2490 }
2491 } finally {
2492 Binder.restoreCallingIdentity(callingIdentity);
2493 }
2494 return valid;
2495 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002496
2497 private boolean validatePhoneId(int phoneId) {
2498 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002499 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002500 return valid;
2501 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002502
2503 private static void log(String s) {
2504 Rlog.d(TAG, s);
2505 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002506
chen xu627d1b22019-04-11 02:16:19 -07002507 private static void loge(String s) {
2508 Rlog.e(TAG, s);
2509 }
2510
xinhe8b79fb62014-11-05 14:55:03 -08002511 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002512
2513 if(subId < 0) {
2514 // Invalid case, we need compare phoneId with default one.
2515 return (mDefaultPhoneId == phoneId);
2516 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002517 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002518 return (subId == mDefaultSubId);
2519 } else {
2520 return (rSubId == subId);
2521 }
2522 }
2523
Hall Liuee313732018-11-27 14:36:51 -08002524 private boolean checkFineLocationAccess(Record r, int minSdk) {
2525 LocationAccessPolicy.LocationPermissionQuery query =
2526 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2527 .setCallingPackage(r.callingPackage)
2528 .setCallingPid(r.callerPid)
2529 .setCallingUid(r.callerUid)
2530 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002531 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002532 .setMinSdkVersionForFine(minSdk)
2533 .build();
2534
2535 return Binder.withCleanCallingIdentity(() -> {
2536 LocationAccessPolicy.LocationPermissionResult locationResult =
2537 LocationAccessPolicy.checkLocationPermission(mContext, query);
2538 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2539 });
2540 }
2541
2542 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2543 LocationAccessPolicy.LocationPermissionQuery query =
2544 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2545 .setCallingPackage(r.callingPackage)
2546 .setCallingPid(r.callerPid)
2547 .setCallingUid(r.callerUid)
2548 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002549 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002550 .setMinSdkVersionForCoarse(minSdk)
2551 .build();
2552
2553 return Binder.withCleanCallingIdentity(() -> {
2554 LocationAccessPolicy.LocationPermissionResult locationResult =
2555 LocationAccessPolicy.checkLocationPermission(mContext, query);
2556 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2557 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002558 }
2559
xinhee9f16402014-09-25 16:39:28 -07002560 private void checkPossibleMissNotify(Record r, int phoneId) {
2561 int events = r.events;
2562
2563 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2564 try {
2565 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2566 mServiceState[phoneId]);
2567 r.callback.onServiceStateChanged(
2568 new ServiceState(mServiceState[phoneId]));
2569 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002570 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002571 }
2572 }
2573
2574 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2575 try {
2576 SignalStrength signalStrength = mSignalStrength[phoneId];
2577 if (DBG) {
2578 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2579 }
2580 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2581 } catch (RemoteException ex) {
2582 mRemoveList.add(r.binder);
2583 }
2584 }
2585
2586 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2587 try {
2588 int gsmSignalStrength = mSignalStrength[phoneId]
2589 .getGsmSignalStrength();
2590 if (DBG) {
2591 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2592 gsmSignalStrength);
2593 }
2594 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2595 : gsmSignalStrength));
2596 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002597 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002598 }
2599 }
2600
2601 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2602 try {
2603 if (DBG_LOC) {
2604 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2605 + mCellInfo.get(phoneId));
2606 }
Hall Liuee313732018-11-27 14:36:51 -08002607 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002608 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2609 }
xinhee9f16402014-09-25 16:39:28 -07002610 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002611 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002612 }
2613 }
2614
zxuan35a47022018-01-04 11:24:04 -08002615 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2616 try {
2617 if (VDBG) {
2618 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2619 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2620 }
2621 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2622 } catch (RemoteException ex) {
2623 mRemoveList.add(r.binder);
2624 }
2625 }
2626
xinhee9f16402014-09-25 16:39:28 -07002627 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2628 try {
2629 if (VDBG) {
2630 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2631 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2632 }
2633 r.callback.onMessageWaitingIndicatorChanged(
2634 mMessageWaiting[phoneId]);
2635 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002636 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002637 }
2638 }
2639
2640 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2641 try {
2642 if (VDBG) {
2643 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2644 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2645 }
2646 r.callback.onCallForwardingIndicatorChanged(
2647 mCallForwarding[phoneId]);
2648 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002649 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002650 }
2651 }
2652
2653 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2654 try {
2655 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2656 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002657 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002658 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2659 }
xinhee9f16402014-09-25 16:39:28 -07002660 } catch (RemoteException ex) {
2661 mRemoveList.add(r.binder);
2662 }
2663 }
2664
2665 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2666 try {
2667 if (DBG) {
2668 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2669 + "=" + mDataConnectionState[phoneId]
2670 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2671 + ")");
2672 }
2673 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2674 mDataConnectionNetworkType[phoneId]);
2675 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002676 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002677 }
2678 }
2679 }
zoey chenb1f74e72019-12-04 16:33:59 +08002680
2681 /**
2682 * Convert data state to string
2683 *
2684 * @return The data state in string format.
2685 */
2686 private String dataStateToString(@TelephonyManager.DataState int state) {
2687 switch (state) {
2688 case TelephonyManager.DATA_DISCONNECTED: return "DISCONNECTED";
2689 case TelephonyManager.DATA_CONNECTING: return "CONNECTING";
2690 case TelephonyManager.DATA_CONNECTED: return "CONNECTED";
2691 case TelephonyManager.DATA_SUSPENDED: return "SUSPENDED";
2692 }
2693 return "UNKNOWN(" + state + ")";
2694 }
2695
2696 /**
2697 * Returns a string representation of the radio technology (network type)
2698 * currently in use on the device.
2699 * @param subId for which network type is returned
2700 * @return the name of the radio technology
2701 *
2702 */
2703 private String getNetworkTypeName(@Annotation.NetworkType int type) {
2704 switch (type) {
2705 case TelephonyManager.NETWORK_TYPE_GPRS:
2706 return "GPRS";
2707 case TelephonyManager.NETWORK_TYPE_EDGE:
2708 return "EDGE";
2709 case TelephonyManager.NETWORK_TYPE_UMTS:
2710 return "UMTS";
2711 case TelephonyManager.NETWORK_TYPE_HSDPA:
2712 return "HSDPA";
2713 case TelephonyManager.NETWORK_TYPE_HSUPA:
2714 return "HSUPA";
2715 case TelephonyManager.NETWORK_TYPE_HSPA:
2716 return "HSPA";
2717 case TelephonyManager.NETWORK_TYPE_CDMA:
2718 return "CDMA";
2719 case TelephonyManager.NETWORK_TYPE_EVDO_0:
2720 return "CDMA - EvDo rev. 0";
2721 case TelephonyManager.NETWORK_TYPE_EVDO_A:
2722 return "CDMA - EvDo rev. A";
2723 case TelephonyManager.NETWORK_TYPE_EVDO_B:
2724 return "CDMA - EvDo rev. B";
2725 case TelephonyManager.NETWORK_TYPE_1xRTT:
2726 return "CDMA - 1xRTT";
2727 case TelephonyManager.NETWORK_TYPE_LTE:
2728 return "LTE";
2729 case TelephonyManager.NETWORK_TYPE_EHRPD:
2730 return "CDMA - eHRPD";
2731 case TelephonyManager.NETWORK_TYPE_IDEN:
2732 return "iDEN";
2733 case TelephonyManager.NETWORK_TYPE_HSPAP:
2734 return "HSPA+";
2735 case TelephonyManager.NETWORK_TYPE_GSM:
2736 return "GSM";
2737 case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
2738 return "TD_SCDMA";
2739 case TelephonyManager.NETWORK_TYPE_IWLAN:
2740 return "IWLAN";
2741 case TelephonyManager.NETWORK_TYPE_LTE_CA:
2742 return "LTE_CA";
2743 case TelephonyManager.NETWORK_TYPE_NR:
2744 return "NR";
2745 default:
2746 return "UNKNOWN";
2747 }
2748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749}