blob: 305d0fb00c69a923f6adaeca2a5abf281c1e346e [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 Chen5d354612019-11-06 15:03:23 -080019import static android.telephony.TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED;
Meng Wang62d2ff82019-12-04 18:02:55 -080020import static android.telephony.TelephonyRegistryManager.SIM_ACTIVATION_TYPE_DATA;
21import static android.telephony.TelephonyRegistryManager.SIM_ACTIVATION_TYPE_VOICE;
Malcolm Chen5d354612019-11-06 15:03:23 -080022
23import static java.util.Arrays.copyOf;
24
Philip P. Moltmann33692f72019-10-03 11:56:11 -070025import android.annotation.Nullable;
Wink Savillea12a7b32012-09-20 10:09:45 -070026import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070027import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070028import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.Context;
30import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070031import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070033import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070034import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.os.Binder;
Hall Liuee313732018-11-27 14:36:51 -080036import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070038import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070040import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070042import android.os.UserHandle;
zoey chenc722b452019-12-03 17:23:22 +080043import android.telephony.Annotation;
Chen Xuc9d4ee12019-09-26 16:11:59 -070044import android.telephony.Annotation.DataFailureCause;
45import android.telephony.Annotation.RadioPowerState;
46import android.telephony.Annotation.SrvccState;
Jordan Liu8218ddd2018-11-28 11:22:39 -080047import android.telephony.CallAttributes;
48import android.telephony.CallQuality;
John Wang963db55d2012-03-30 16:04:06 -070049import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070050import android.telephony.CellLocation;
chen xu16e24cd2018-12-11 18:09:41 -080051import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020052import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080053import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070054import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070055import android.telephony.PhoneStateListener;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020056import android.telephony.PreciseCallState;
57import android.telephony.PreciseDataConnectionState;
58import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070059import android.telephony.Rlog;
60import android.telephony.ServiceState;
61import android.telephony.SignalStrength;
62import android.telephony.SubscriptionManager;
63import android.telephony.TelephonyManager;
chen xu16e24cd2018-12-11 18:09:41 -080064import android.telephony.data.ApnSetting;
sqianbdc5a732018-10-26 13:27:51 -070065import android.telephony.emergency.EmergencyNumber;
chen xu6ac5fc12019-01-24 14:14:13 -080066import android.telephony.ims.ImsReasonInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070067import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070068import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070070import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080072import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070074import com.android.internal.telephony.ITelephonyRegistry;
Wink Savillea639b312012-07-10 12:37:54 -070075import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080077import com.android.internal.telephony.TelephonyPermissions;
chen xubadf2b02019-04-26 17:45:26 -070078import com.android.internal.util.ArrayUtils;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060079import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070080import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081import com.android.server.am.BatteryStatsService;
82
Jack Yud19b6ae2017-04-05 14:12:09 -070083import java.io.FileDescriptor;
84import java.io.PrintWriter;
85import java.util.ArrayList;
chen xu5b98d402019-03-22 16:56:34 -070086import java.util.Arrays;
sqian9f93a122018-12-03 22:40:41 -080087import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070088import java.util.List;
sqian9f93a122018-12-03 22:40:41 -080089import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080090import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092/**
Wink Savillee9b06d72009-05-18 21:47:50 -070093 * Since phone process can be restarted, this class provides a centralized place
94 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070095 *
96 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
97 * and 15973975 by saving the phoneId of the registrant and then using the
98 * phoneId when deciding to to make a callback. This is necessary because
99 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -0700100 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -0700101 * the dummy value conversion we properly do the callbacks.
102 *
103 * Eventually we may want to remove the notion of dummy value but for now this
104 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700106@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
107public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -0700109 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -0700110 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -0700111 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112
113 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800114 Context context;
115
Svet Ganov16a16892015-04-16 10:32:04 -0700116 String callingPackage;
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700117 String callingFeatureId;
Wink Savillee9b06d72009-05-18 21:47:50 -0700118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700120
Malcolm Chenabbfac22018-02-12 19:15:59 -0800121 TelephonyRegistryDeathRecipient deathRecipient;
122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800124 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700125 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700126
Hall Liu5fb337f2017-11-22 17:38:15 -0800127 int callerUid;
128 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700131
Wink Savilled09c4ca2014-11-22 10:08:16 -0800132 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700133
Wink Savilled09c4ca2014-11-22 10:08:16 -0800134 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800135
136 boolean matchPhoneStateListenerEvent(int events) {
137 return (callback != null) && ((events & this.events) != 0);
138 }
139
Wink Savilled09c4ca2014-11-22 10:08:16 -0800140 boolean matchOnSubscriptionsChangedListener() {
141 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800142 }
Wink Savillee380b982014-07-26 18:24:22 -0700143
Malcolm Chen13f31af2018-09-04 22:12:31 -0700144 boolean matchOnOpportunisticSubscriptionsChangedListener() {
145 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
146 }
147
Tyler Gunnf955e562018-04-26 14:43:31 -0700148 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800149 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700150 return TelephonyPermissions.checkReadCallLog(
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700151 context, subId, callerPid, callerUid, callingPackage, callingFeatureId);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800152 } catch (SecurityException e) {
153 return false;
154 }
155 }
156
Wink Savillea12a7b32012-09-20 10:09:45 -0700157 @Override
158 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700159 return "{callingPackage=" + callingPackage + " binder=" + binder
160 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800161 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700162 + onSubscriptionsChangedListenerCallback
163 + " onOpportunisticSubscriptionsChangedListenererCallback="
164 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800165 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800166 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 }
169
170 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Joe Onorato163d8d92010-10-21 13:21:20 -0400172 // access should be inside synchronized (mRecords) for these two fields
173 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
174 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 private final IBatteryStats mBatteryStats;
177
Svet Ganov16a16892015-04-16 10:32:04 -0700178 private final AppOpsManager mAppOps;
179
Malcolm Chen13f31af2018-09-04 22:12:31 -0700180 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
181
182 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800183
Wink Savillefb40dd42014-06-12 17:02:31 -0700184 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700191
fionaxu12312f62016-11-14 13:32:14 -0800192 private int[] mVoiceActivationState;
193
194 private int[] mDataActivationState;
195
zxuan35a47022018-01-04 11:24:04 -0800196 private boolean[] mUserMobileDataState;
197
Wink Savillefb40dd42014-06-12 17:02:31 -0700198 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700199
Wink Savillefb40dd42014-06-12 17:02:31 -0700200 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700201
Wink Savillefb40dd42014-06-12 17:02:31 -0700202 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700203
Wink Savillefb40dd42014-06-12 17:02:31 -0700204 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700205
Jack Yub1bac542018-03-14 16:23:38 -0700206 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700207 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700208
Wink Savillefb40dd42014-06-12 17:02:31 -0700209 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210
Wink Savillefb40dd42014-06-12 17:02:31 -0700211 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700212
chen xud5deeb12019-04-29 13:57:42 -0700213 private int[] mOtaspMode;
Wink Savillefd2d0132010-10-28 14:22:26 -0700214
Wink Savillefb40dd42014-06-12 17:02:31 -0700215 private ArrayList<List<CellInfo>> mCellInfo = null;
216
sqian9f93a122018-12-03 22:40:41 -0800217 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
218
Shuo Qian134334b2019-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 Xuc9d4ee12019-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 Qian134334b2019-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 Qian134334b2019-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 Chen5d354612019-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(
Meng Wang92bc49b2019-12-09 16:06:51 -0800360 SubscriptionManager.EXTRA_SLOT_INDEX,
Taesu Leec955cd92019-09-23 08:06:31 +0900361 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 Chen5d354612019-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 Chen5d354612019-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);
Malcolm Chen5d354612019-11-06 15:03:23 -0800426 return;
427 }
428
429 // mNumPhones > oldNumPhones: ss -> ds switch
430 for (int i = oldNumPhones; i < mNumPhones; i++) {
431 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
432 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
433 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
434 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
435 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
436 mCallIncomingNumber[i] = "";
437 mServiceState[i] = new ServiceState();
438 mSignalStrength[i] = new SignalStrength();
439 mUserMobileDataState[i] = false;
440 mMessageWaiting[i] = false;
441 mCallForwarding[i] = false;
442 mCellLocation[i] = new Bundle();
443 mCellInfo.add(i, null);
444 mImsReasonInfo.add(i, null);
445 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Malcolm Chen5d354612019-11-06 15:03:23 -0800446 mOtaspMode[i] = TelephonyManager.OTASP_UNKNOWN;
447 mCallDisconnectCause[i] = DisconnectCause.NOT_VALID;
448 mCallPreciseDisconnectCause[i] = PreciseDisconnectCause.NOT_VALID;
449 mCallQuality[i] = new CallQuality();
450 mCallAttributes[i] = new CallAttributes(new PreciseCallState(),
451 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
452 mCallNetworkType[i] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
453 mPreciseCallState[i] = new PreciseCallState();
454 mRingingCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
455 mForegroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
456 mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
457 mPreciseDataConnectionState[i] = new PreciseDataConnectionState();
458 }
459
460 // Note that location can be null for non-phone builds like
461 // like the generic one.
462 CellLocation location = CellLocation.getEmpty();
463 if (location != null) {
464 for (int i = oldNumPhones; i < mNumPhones; i++) {
465 location.fillInNotifierBundle(mCellLocation[i]);
466 }
467 }
468 }
469
470 private void cutListToSize(List list, int size) {
471 if (list == null) return;
472
473 while (list.size() > size) {
474 list.remove(list.size() - 1);
475 }
476 }
477
Wink Savillee9b06d72009-05-18 21:47:50 -0700478 // we keep a copy of all of the state so we can send it out when folks
479 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700481 // In these calls we call with the lock held. This is safe becasuse remote
482 // calls go through a oneway interface and local calls going through a
483 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700485 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
486 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700487 CellLocation location = CellLocation.getEmpty();
488
Wink Savillefb40dd42014-06-12 17:02:31 -0700489 mContext = context;
490 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700491
Malcolm Chen5d354612019-11-06 15:03:23 -0800492 int numPhones = getTelephonyManager().getActiveModemCount();
Jack Yub1bac542018-03-14 16:23:38 -0700493 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700494 mNumPhones = numPhones;
495 mCallState = new int[numPhones];
496 mDataActivity = new int[numPhones];
497 mDataConnectionState = new int[numPhones];
498 mDataConnectionNetworkType = new int[numPhones];
499 mCallIncomingNumber = new String[numPhones];
500 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800501 mVoiceActivationState = new int[numPhones];
502 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800503 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700504 mSignalStrength = new SignalStrength[numPhones];
505 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700506 mCallForwarding = new boolean[numPhones];
507 mCellLocation = new Bundle[numPhones];
Brad Ebingerefed9822018-10-26 10:25:57 -0700508 mSrvccState = new int[numPhones];
chen xud5deeb12019-04-29 13:57:42 -0700509 mOtaspMode = new int[numPhones];
510 mPreciseCallState = new PreciseCallState[numPhones];
511 mForegroundCallState = new int[numPhones];
512 mBackgroundCallState = new int[numPhones];
513 mRingingCallState = new int[numPhones];
514 mCallDisconnectCause = new int[numPhones];
515 mCallPreciseDisconnectCause = new int[numPhones];
516 mCallQuality = new CallQuality[numPhones];
517 mCallNetworkType = new int[numPhones];
518 mCallAttributes = new CallAttributes[numPhones];
519 mPreciseDataConnectionState = new PreciseDataConnectionState[numPhones];
520 mCellInfo = new ArrayList<>();
521 mImsReasonInfo = new ArrayList<>();
sqian9f93a122018-12-03 22:40:41 -0800522 mEmergencyNumberList = new HashMap<>();
Shuo Qian134334b2019-09-12 17:00:31 -0700523 mOutgoingCallEmergencyNumber = new EmergencyNumber[numPhones];
524 mOutgoingSmsEmergencyNumber = new EmergencyNumber[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700525 for (int i = 0; i < numPhones; i++) {
526 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
527 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
528 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800529 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
530 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700531 mCallIncomingNumber[i] = "";
532 mServiceState[i] = new ServiceState();
533 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800534 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700535 mMessageWaiting[i] = false;
536 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700537 mCellLocation[i] = new Bundle();
538 mCellInfo.add(i, null);
chen xu6ac5fc12019-01-24 14:14:13 -0800539 mImsReasonInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700540 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
chen xud5deeb12019-04-29 13:57:42 -0700541 mOtaspMode[i] = TelephonyManager.OTASP_UNKNOWN;
542 mCallDisconnectCause[i] = DisconnectCause.NOT_VALID;
543 mCallPreciseDisconnectCause[i] = PreciseDisconnectCause.NOT_VALID;
544 mCallQuality[i] = new CallQuality();
545 mCallAttributes[i] = new CallAttributes(new PreciseCallState(),
546 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
547 mCallNetworkType[i] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
548 mPreciseCallState[i] = new PreciseCallState();
549 mRingingCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
550 mForegroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
551 mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
552 mPreciseDataConnectionState[i] = new PreciseDataConnectionState();
Wink Savillefb40dd42014-06-12 17:02:31 -0700553 }
554
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700555 // Note that location can be null for non-phone builds like
556 // like the generic one.
557 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700558 for (int i = 0; i < numPhones; i++) {
559 location.fillInNotifierBundle(mCellLocation[i]);
560 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700561 }
Svet Ganov16a16892015-04-16 10:32:04 -0700562
563 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
565
Svetoslav Ganova0027152013-06-25 14:59:53 -0700566 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700567 // Watch for interesting updates
568 final IntentFilter filter = new IntentFilter();
569 filter.addAction(Intent.ACTION_USER_SWITCHED);
570 filter.addAction(Intent.ACTION_USER_REMOVED);
Taesu Leec955cd92019-09-23 08:06:31 +0900571 filter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Malcolm Chen5d354612019-11-06 15:03:23 -0800572 filter.addAction(ACTION_MULTI_SIM_CONFIG_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700573 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700574 mContext.registerReceiver(mBroadcastReceiver, filter);
575 }
576
577 @Override
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700578 public void addOnSubscriptionsChangedListener(String callingPackage, String callingFeatureId,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800579 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700580 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800582 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700583 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
584 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800585 + " callback.asBinder=" + callback.asBinder());
586 }
587
Wink Savilled09c4ca2014-11-22 10:08:16 -0800588 synchronized (mRecords) {
589 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800590 IBinder b = callback.asBinder();
591 Record r = add(b);
592
593 if (r == null) {
594 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800595 }
596
Jeff Davidson29da89f2018-02-28 17:50:16 -0800597 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800598 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700599 r.callingPackage = callingPackage;
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700600 r.callingFeatureId = callingFeatureId;
Hall Liu5fb337f2017-11-22 17:38:15 -0800601 r.callerUid = Binder.getCallingUid();
602 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800603 r.events = 0;
604 if (DBG) {
605 log("listen oscl: Register r=" + r);
606 }
607 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700608 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800609 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800610 if (VDBG) log("listen oscl: send to r=" + r);
611 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
612 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800613 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800614 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800615 remove(r.binder);
616 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800617 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700618 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800619 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800620 }
621 }
622
623 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800624 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800625 IOnSubscriptionsChangedListener callback) {
626 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800627 remove(callback.asBinder());
628 }
629
Malcolm Chen13f31af2018-09-04 22:12:31 -0700630
631 @Override
632 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700633 String callingFeatureId, IOnSubscriptionsChangedListener callback) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700634 int callerUserId = UserHandle.getCallingUserId();
635 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
636 if (VDBG) {
637 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
638 + " callerUserId=" + callerUserId + " callback=" + callback
639 + " callback.asBinder=" + callback.asBinder());
640 }
641
642 synchronized (mRecords) {
643 // register
644 IBinder b = callback.asBinder();
645 Record r = add(b);
646
647 if (r == null) {
648 return;
649 }
650
651 r.context = mContext;
652 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
653 r.callingPackage = callingPackage;
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700654 r.callingFeatureId = callingFeatureId;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700655 r.callerUid = Binder.getCallingUid();
656 r.callerPid = Binder.getCallingPid();
657 r.events = 0;
658 if (DBG) {
659 log("listen ooscl: Register r=" + r);
660 }
661 // Always notify when registration occurs if there has been a notification.
662 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
663 try {
664 if (VDBG) log("listen ooscl: send to r=" + r);
665 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
666 if (VDBG) log("listen ooscl: sent to r=" + r);
667 } catch (RemoteException e) {
668 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
669 remove(r.binder);
670 }
671 } else {
672 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
673 }
674 }
675 }
676
Wink Savillea374c3d2014-11-11 11:48:04 -0800677 @Override
678 public void notifySubscriptionInfoChanged() {
679 if (VDBG) log("notifySubscriptionInfoChanged:");
680 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700681 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800682 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
683 + mRecords.size());
684 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700685 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800686 mRemoveList.clear();
687 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800688 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800689 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800690 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
691 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
692 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800693 } catch (RemoteException ex) {
694 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
695 mRemoveList.add(r.binder);
696 }
697 }
698 }
699 handleRemoveListLocked();
700 }
701 }
702
703 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700704 public void notifyOpportunisticSubscriptionInfoChanged() {
705 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
706 synchronized (mRecords) {
707 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
708 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
709 + mRecords.size());
710 }
711 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
712 mRemoveList.clear();
713 for (Record r : mRecords) {
714 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
715 try {
716 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
717 r.onOpportunisticSubscriptionsChangedListenerCallback
718 .onSubscriptionsChanged();
719 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
720 } catch (RemoteException ex) {
721 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
722 mRemoveList.add(r.binder);
723 }
724 }
725 }
726 handleRemoveListLocked();
727 }
728 }
729
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700730 @Deprecated
Malcolm Chen13f31af2018-09-04 22:12:31 -0700731 @Override
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700732 public void listen(String callingPackage, IPhoneStateListener callback, int events,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 boolean notifyNow) {
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700734 listenWithFeature(callingPackage, null, callback, events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700735 }
736
737 @Override
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700738 public void listenWithFeature(String callingPackage, String callingFeatureId,
739 IPhoneStateListener callback, int events, boolean notifyNow) {
740 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, callingPackage,
741 callingFeatureId, callback, events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700742 }
743
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700744 @Override
745 public void listenForSubscriber(int subId, String callingPackage, String callingFeatureId,
746 IPhoneStateListener callback, int events, boolean notifyNow) {
747 listen(callingPackage, callingFeatureId, callback, events, notifyNow, subId);
748 }
749
750 private void listen(String callingPackage, @Nullable String callingFeatureId,
751 IPhoneStateListener callback, int events, boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700752 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jack Yu0c92c232019-04-04 15:10:17 -0700754 String str = "listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700755 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
Jack Yu0c92c232019-04-04 15:10:17 -0700756 + UserHandle.myUserId() + " callerUserId=" + callerUserId;
757 mListenLog.log(str);
758 if (VDBG) {
759 log(str);
Wink Savillea12a7b32012-09-20 10:09:45 -0700760 }
xinhe75c2c152014-10-16 11:49:45 -0700761
762 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800763 // Checks permission and throws SecurityException for disallowed operations. For pre-M
764 // apps whose runtime permission has been revoked, we return immediately to skip sending
765 // events to the app without crashing it.
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700766 if (!checkListenerPermission(events, subId, callingPackage, callingFeatureId,
767 "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800768 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700769 }
770
yifan.baie620ce72017-12-22 14:59:57 +0800771 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 synchronized (mRecords) {
773 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800774 IBinder b = callback.asBinder();
775 Record r = add(b);
776
777 if (r == null) {
778 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 }
xinhe43c50292014-09-18 17:56:48 -0700780
Jeff Davidson29da89f2018-02-28 17:50:16 -0800781 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700782 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700783 r.callingPackage = callingPackage;
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700784 r.callingFeatureId = callingFeatureId;
Hall Liu5fb337f2017-11-22 17:38:15 -0800785 r.callerUid = Binder.getCallingUid();
786 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700787 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
788 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800790 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700791 } else {//APP specify subID
792 r.subId = subId;
793 }
yifan.baie620ce72017-12-22 14:59:57 +0800794 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700796 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700797 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700798 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700799 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400801 try {
Wink Savillee380b982014-07-26 18:24:22 -0700802 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800803 ServiceState rawSs = new ServiceState(mServiceState[phoneId]);
804 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
805 r.callback.onServiceStateChanged(rawSs);
806 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
807 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(false));
808 } else {
809 r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(true));
810 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400811 } catch (RemoteException ex) {
812 remove(r.binder);
813 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 }
815 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
816 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700817 int gsmSignalStrength = mSignalStrength[phoneId]
818 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700819 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
820 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 } catch (RemoteException ex) {
822 remove(r.binder);
823 }
824 }
825 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
826 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700827 r.callback.onMessageWaitingIndicatorChanged(
828 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 } catch (RemoteException ex) {
830 remove(r.binder);
831 }
832 }
833 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
834 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700835 r.callback.onCallForwardingIndicatorChanged(
836 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 } catch (RemoteException ex) {
838 remove(r.binder);
839 }
840 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700841 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400842 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700843 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700844 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -0800845 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800846 r.callback.onCellLocationChanged(
847 new Bundle(mCellLocation[phoneId]));
848 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400849 } catch (RemoteException ex) {
850 remove(r.binder);
851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
853 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
854 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700855 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700856 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 } catch (RemoteException ex) {
858 remove(r.binder);
859 }
860 }
861 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
862 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700863 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
864 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 } catch (RemoteException ex) {
866 remove(r.binder);
867 }
868 }
869 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
870 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700871 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 } catch (RemoteException ex) {
873 remove(r.binder);
874 }
875 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700876 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
877 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700878 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700879 } catch (RemoteException ex) {
880 remove(r.binder);
881 }
882 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700883 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
884 try {
chen xud5deeb12019-04-29 13:57:42 -0700885 r.callback.onOtaspChanged(mOtaspMode[phoneId]);
Wink Savillefd2d0132010-10-28 14:22:26 -0700886 } catch (RemoteException ex) {
887 remove(r.binder);
888 }
889 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700890 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700891 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700892 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700893 + mCellInfo.get(phoneId));
Hall Liuee313732018-11-27 14:36:51 -0800894 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -0800895 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
896 }
John Wang963db55d2012-03-30 16:04:06 -0700897 } catch (RemoteException ex) {
898 remove(r.binder);
899 }
900 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200901 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
902 try {
chen xud5deeb12019-04-29 13:57:42 -0700903 r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200904 } catch (RemoteException ex) {
905 remove(r.binder);
906 }
907 }
chen xu6a942d482018-12-12 19:59:30 -0800908 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
909 try {
chen xud5deeb12019-04-29 13:57:42 -0700910 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId],
911 mCallPreciseDisconnectCause[phoneId]);
chen xu6a942d482018-12-12 19:59:30 -0800912 } catch (RemoteException ex) {
913 remove(r.binder);
914 }
915 }
chen xu6ac5fc12019-01-24 14:14:13 -0800916 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
917 try {
918 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
919 } catch (RemoteException ex) {
920 remove(r.binder);
921 }
922 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200923 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
924 try {
925 r.callback.onPreciseDataConnectionStateChanged(
chen xud5deeb12019-04-29 13:57:42 -0700926 mPreciseDataConnectionState[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200927 } catch (RemoteException ex) {
928 remove(r.binder);
929 }
930 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400931 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
932 try {
933 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
934 } catch (RemoteException ex) {
935 remove(r.binder);
936 }
937 }
fionaxu12312f62016-11-14 13:32:14 -0800938 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
939 try {
940 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
941 } catch (RemoteException ex) {
942 remove(r.binder);
943 }
944 }
945 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
946 try {
947 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
948 } catch (RemoteException ex) {
949 remove(r.binder);
950 }
951 }
zxuan35a47022018-01-04 11:24:04 -0800952 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
953 try {
954 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
955 } catch (RemoteException ex) {
956 remove(r.binder);
957 }
958 }
sqian9f93a122018-12-03 22:40:41 -0800959 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
960 try {
961 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
962 } catch (RemoteException ex) {
963 remove(r.binder);
964 }
965 }
Malcolm Chene1623652018-08-08 20:27:45 -0700966 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
967 try {
968 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
969 } catch (RemoteException ex) {
970 remove(r.binder);
971 }
972 }
Nazanin Bakhshi026c42d2019-03-01 10:10:22 -0800973 if ((events & PhoneStateListener
Malcolm Chenf028c3b2019-09-04 16:10:34 -0700974 .LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700975 try {
Malcolm Chen026451d2019-02-14 19:50:19 -0800976 r.callback.onActiveDataSubIdChanged(mActiveDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700977 } catch (RemoteException ex) {
978 remove(r.binder);
979 }
980 }
Chen Xu7395c632018-10-17 17:53:47 +0000981 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
982 try {
983 r.callback.onRadioPowerStateChanged(mRadioPowerState);
984 } catch (RemoteException ex) {
985 remove(r.binder);
986 }
987 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700988 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
989 try {
990 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
991 } catch (RemoteException ex) {
992 remove(r.binder);
993 }
994 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800995 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
996 try {
chen xud5deeb12019-04-29 13:57:42 -0700997 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
Jordan Liu8218ddd2018-11-28 11:22:39 -0800998 } catch (RemoteException ex) {
999 remove(r.binder);
1000 }
1001 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 }
1003 }
1004 } else {
xinhe75c2c152014-10-16 11:49:45 -07001005 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 remove(callback.asBinder());
1007 }
1008 }
1009
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001010 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -07001011 // Only reveal the incoming number if the record has read call log permission.
1012 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001013 }
1014
Malcolm Chenabbfac22018-02-12 19:15:59 -08001015 private Record add(IBinder binder) {
1016 Record r;
1017
1018 synchronized (mRecords) {
1019 final int N = mRecords.size();
1020 for (int i = 0; i < N; i++) {
1021 r = mRecords.get(i);
1022 if (binder == r.binder) {
1023 // Already existed.
1024 return r;
1025 }
1026 }
1027 r = new Record();
1028 r.binder = binder;
1029 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
1030
1031 try {
1032 binder.linkToDeath(r.deathRecipient, 0);
1033 } catch (RemoteException e) {
1034 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
1035 // Binder already died. Return null.
1036 return null;
1037 }
1038
1039 mRecords.add(r);
1040 if (DBG) log("add new record");
1041 }
1042
1043 return r;
1044 }
1045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 private void remove(IBinder binder) {
1047 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001048 final int recordCount = mRecords.size();
1049 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -08001050 Record r = mRecords.get(i);
1051 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -08001052 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -08001053 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
1054 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -08001055 }
Malcolm Chenabbfac22018-02-12 19:15:59 -08001056
1057 if (r.deathRecipient != null) {
1058 try {
1059 binder.unlinkToDeath(r.deathRecipient, 0);
1060 } catch (NoSuchElementException e) {
1061 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
1062 + r + " e=" + e);
1063 }
1064 }
1065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 mRecords.remove(i);
1067 return;
1068 }
1069 }
1070 }
1071 }
1072
Chen Xu288b71c2019-09-15 18:28:21 -07001073 public void notifyCallStateForAllSubs(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001074 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001075 return;
1076 }
xinhe43c50292014-09-18 17:56:48 -07001077
1078 if (VDBG) {
Chen Xu288b71c2019-09-15 18:28:21 -07001079 log("notifyCallStateForAllSubs: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -07001080 }
1081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -07001083 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001084 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -08001085 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 try {
Tyler Gunnf955e562018-04-26 14:43:31 -07001087 // Ensure the listener has read call log permission; if they do not return
1088 // an empty phone number.
1089 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
1090 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001092 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 }
1094 }
1095 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001096 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001098
1099 // Called only by Telecomm to communicate call state across different phone accounts. So
1100 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -07001101 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001102 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001103 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
1105
Chen Xu288b71c2019-09-15 18:28:21 -07001106 public void notifyCallState(int phoneId, int subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001107 if (!checkNotifyPermission("notifyCallState()")) {
1108 return;
1109 }
Wink Savillee380b982014-07-26 18:24:22 -07001110 if (VDBG) {
Chen Xu288b71c2019-09-15 18:28:21 -07001111 log("notifyCallState: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001112 + " state=" + state + " incomingNumber=" + incomingNumber);
1113 }
1114 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001115 if (validatePhoneId(phoneId)) {
1116 mCallState[phoneId] = state;
1117 mCallIncomingNumber[phoneId] = incomingNumber;
1118 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001119 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -07001120 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -08001121 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001122 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001123 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
1124 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -07001125 } catch (RemoteException ex) {
1126 mRemoveList.add(r.binder);
1127 }
1128 }
1129 }
1130 }
1131 handleRemoveListLocked();
1132 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001133 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001134 }
1135
Wink Saville63f03dd2014-10-23 10:44:45 -07001136 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001137 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001138 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001139 }
xinhe43c50292014-09-18 17:56:48 -07001140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001142 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
1143 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -07001144 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001145 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -07001146 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001147 mLocalLog.log(str);
Jordan Liu55b2bc462019-06-24 11:27:34 -07001148 // for service state updates, don't notify clients when subId is invalid. This prevents
1149 // us from sending incorrect notifications like b/133140128
1150 // In the future, we can remove this logic for every notification here and add a
1151 // callback so listeners know when their PhoneStateListener's subId becomes invalid, but
1152 // for now we use the simplest fix.
1153 if (validatePhoneId(phoneId) && SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001154 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001155
Wink Savillefb40dd42014-06-12 17:02:31 -07001156 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001157 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001158 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -07001159 + " phoneId=" + phoneId + " state=" + state);
1160 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001161 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -08001162 idMatch(r.subId, subId, phoneId)) {
Hall Liuee313732018-11-27 14:36:51 -08001163
Wink Savillefb40dd42014-06-12 17:02:31 -07001164 try {
Hall Liuee313732018-11-27 14:36:51 -08001165 ServiceState stateToSend;
1166 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
1167 stateToSend = new ServiceState(state);
1168 } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
1169 stateToSend = state.sanitizeLocationInfo(false);
1170 } else {
1171 stateToSend = state.sanitizeLocationInfo(true);
1172 }
Wink Savillee380b982014-07-26 18:24:22 -07001173 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001174 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001175 + " subId=" + subId + " phoneId=" + phoneId
1176 + " state=" + state);
1177 }
Hall Liuee313732018-11-27 14:36:51 -08001178 r.callback.onServiceStateChanged(stateToSend);
Wink Savillefb40dd42014-06-12 17:02:31 -07001179 } catch (RemoteException ex) {
1180 mRemoveList.add(r.binder);
1181 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 } else {
Jordan Liu55b2bc462019-06-24 11:27:34 -07001185 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId
1186 + " or subId=" + subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001188 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001190 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 }
1192
fionaxu12312f62016-11-14 13:32:14 -08001193 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1194 int activationType, int activationState) {
1195 if (!checkNotifyPermission("notifySimActivationState()")){
1196 return;
1197 }
1198 if (VDBG) {
1199 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1200 + "type=" + activationType + " state=" + activationState);
1201 }
1202 synchronized (mRecords) {
1203 if (validatePhoneId(phoneId)) {
1204 switch (activationType) {
Meng Wang62d2ff82019-12-04 18:02:55 -08001205 case SIM_ACTIVATION_TYPE_VOICE:
fionaxu12312f62016-11-14 13:32:14 -08001206 mVoiceActivationState[phoneId] = activationState;
1207 break;
Meng Wang62d2ff82019-12-04 18:02:55 -08001208 case SIM_ACTIVATION_TYPE_DATA:
fionaxu12312f62016-11-14 13:32:14 -08001209 mDataActivationState[phoneId] = activationState;
1210 break;
1211 default:
1212 return;
1213 }
1214 for (Record r : mRecords) {
1215 if (VDBG) {
1216 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1217 + " phoneId=" + phoneId + "type=" + activationType
1218 + " state=" + activationState);
1219 }
1220 try {
Meng Wang62d2ff82019-12-04 18:02:55 -08001221 if ((activationType == SIM_ACTIVATION_TYPE_VOICE)
1222 && r.matchPhoneStateListenerEvent(
1223 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE)
1224 && idMatch(r.subId, subId, phoneId)) {
fionaxu12312f62016-11-14 13:32:14 -08001225 if (DBG) {
1226 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1227 + " subId=" + subId + " phoneId=" + phoneId
1228 + " state=" + activationState);
1229 }
1230 r.callback.onVoiceActivationStateChanged(activationState);
1231 }
Meng Wang62d2ff82019-12-04 18:02:55 -08001232 if ((activationType == SIM_ACTIVATION_TYPE_DATA)
1233 && r.matchPhoneStateListenerEvent(
1234 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE)
1235 && idMatch(r.subId, subId, phoneId)) {
fionaxu12312f62016-11-14 13:32:14 -08001236 if (DBG) {
1237 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1238 + " subId=" + subId + " phoneId=" + phoneId
1239 + " state=" + activationState);
1240 }
1241 r.callback.onDataActivationStateChanged(activationState);
1242 }
1243 } catch (RemoteException ex) {
1244 mRemoveList.add(r.binder);
1245 }
1246 }
1247 } else {
1248 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1249 }
1250 handleRemoveListLocked();
1251 }
1252 }
1253
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001254 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1255 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001256 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001257 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001258 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001259 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001260 log("notifySignalStrengthForPhoneId: subId=" + subId
1261 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001262 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001265 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001266 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001267 mSignalStrength[phoneId] = signalStrength;
1268 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001269 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001270 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001271 + " phoneId=" + phoneId + " ss=" + signalStrength);
1272 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001273 if (r.matchPhoneStateListenerEvent(
1274 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001275 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001276 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001277 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001278 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001279 + " subId=" + subId + " phoneId=" + phoneId
1280 + " ss=" + signalStrength);
1281 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001282 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1283 } catch (RemoteException ex) {
1284 mRemoveList.add(r.binder);
1285 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001286 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001287 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001288 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001289 try {
1290 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001291 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001292 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001293 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001294 + " subId=" + subId + " phoneId=" + phoneId
1295 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1296 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001297 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001298 } catch (RemoteException ex) {
1299 mRemoveList.add(r.binder);
1300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 }
1302 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001303 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001304 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001306 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001308 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 }
1310
Andrew Flynn1f452642015-04-14 22:16:04 -04001311 @Override
1312 public void notifyCarrierNetworkChange(boolean active) {
chen xubadf2b02019-04-26 17:45:26 -07001313 // only CarrierService with carrier privilege rule should have the permission
1314 int[] subIds = Arrays.stream(SubscriptionManager.from(mContext)
Malcolm Chen2c95aa92019-09-25 14:02:14 -07001315 .getActiveSubscriptionIdList(false))
chen xubadf2b02019-04-26 17:45:26 -07001316 .filter(i -> TelephonyPermissions.checkCarrierPrivilegeForSubId(i)).toArray();
1317 if (ArrayUtils.isEmpty(subIds)) {
chen xu627d1b22019-04-11 02:16:19 -07001318 loge("notifyCarrierNetworkChange without carrier privilege");
chen xubadf2b02019-04-26 17:45:26 -07001319 // the active subId does not have carrier privilege.
chen xu627d1b22019-04-11 02:16:19 -07001320 throw new SecurityException("notifyCarrierNetworkChange without carrier privilege");
chen xu5b98d402019-03-22 16:56:34 -07001321 }
Andrew Flynn1f452642015-04-14 22:16:04 -04001322
1323 synchronized (mRecords) {
1324 mCarrierNetworkChangeState = active;
chen xubadf2b02019-04-26 17:45:26 -07001325 for (int subId : subIds) {
1326 int phoneId = SubscriptionManager.getPhoneId(subId);
1327
1328 if (VDBG) {
1329 log("notifyCarrierNetworkChange: active=" + active + "subId: " + subId);
1330 }
1331 for (Record r : mRecords) {
1332 if (r.matchPhoneStateListenerEvent(
1333 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) &&
1334 idMatch(r.subId, subId, phoneId)) {
1335 try {
1336 r.callback.onCarrierNetworkChange(active);
1337 } catch (RemoteException ex) {
1338 mRemoveList.add(r.binder);
1339 }
Andrew Flynn1f452642015-04-14 22:16:04 -04001340 }
1341 }
1342 }
1343 handleRemoveListLocked();
1344 }
1345 }
1346
Wink Savilleb208a242012-07-25 14:08:09 -07001347 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001348 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001349 }
1350
Wink Saville63f03dd2014-10-23 10:44:45 -07001351 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
Chen Xu288b71c2019-09-15 18:28:21 -07001352 if (!checkNotifyPermission("notifyCellInfoForSubscriber()")) {
John Wang963db55d2012-03-30 16:04:06 -07001353 return;
1354 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001355 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001356 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001357 + " cellInfo=" + cellInfo);
1358 }
yifan.baie620ce72017-12-22 14:59:57 +08001359 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001360 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001361 if (validatePhoneId(phoneId)) {
1362 mCellInfo.set(phoneId, cellInfo);
1363 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001364 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001365 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001366 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001367 try {
1368 if (DBG_LOC) {
Chen Xu288b71c2019-09-15 18:28:21 -07001369 log("notifyCellInfoForSubscriber: mCellInfo=" + cellInfo
1370 + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001371 }
1372 r.callback.onCellInfoChanged(cellInfo);
1373 } catch (RemoteException ex) {
1374 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001375 }
John Wang963db55d2012-03-30 16:04:06 -07001376 }
1377 }
1378 }
1379 handleRemoveListLocked();
1380 }
1381 }
1382
xinhe43c50292014-09-18 17:56:48 -07001383 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001384 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001385 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001386 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001387 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001388 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001389 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001390 + " mwi=" + mwi);
1391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001393 if (validatePhoneId(phoneId)) {
1394 mMessageWaiting[phoneId] = mwi;
1395 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001396 if (r.matchPhoneStateListenerEvent(
1397 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001398 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001399 try {
1400 r.callback.onMessageWaitingIndicatorChanged(mwi);
1401 } catch (RemoteException ex) {
1402 mRemoveList.add(r.binder);
1403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 }
1405 }
1406 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001407 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 }
1409 }
1410
zxuan35a47022018-01-04 11:24:04 -08001411 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1412 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1413 return;
1414 }
1415 if (VDBG) {
SongFerngWang0b109f5f2019-04-09 17:29:29 +08001416 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: PhoneId=" + phoneId
1417 + " subId=" + subId + " state=" + state);
zxuan35a47022018-01-04 11:24:04 -08001418 }
1419 synchronized (mRecords) {
1420 if (validatePhoneId(phoneId)) {
SongFerngWang0b109f5f2019-04-09 17:29:29 +08001421 mUserMobileDataState[phoneId] = state;
zxuan35a47022018-01-04 11:24:04 -08001422 for (Record r : mRecords) {
1423 if (r.matchPhoneStateListenerEvent(
1424 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1425 idMatch(r.subId, subId, phoneId)) {
1426 try {
1427 r.callback.onUserMobileDataStateChanged(state);
1428 } catch (RemoteException ex) {
1429 mRemoveList.add(r.binder);
1430 }
1431 }
1432 }
1433 }
1434 handleRemoveListLocked();
1435 }
1436 }
1437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001439 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001440 }
1441
Wink Saville63f03dd2014-10-23 10:44:45 -07001442 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001443 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001444 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001445 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001446 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001447 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001448 + " cfi=" + cfi);
1449 }
yifan.baie620ce72017-12-22 14:59:57 +08001450 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001452 if (validatePhoneId(phoneId)) {
1453 mCallForwarding[phoneId] = cfi;
1454 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001455 if (r.matchPhoneStateListenerEvent(
1456 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001457 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001458 try {
1459 r.callback.onCallForwardingIndicatorChanged(cfi);
1460 } catch (RemoteException ex) {
1461 mRemoveList.add(r.binder);
1462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 }
1464 }
1465 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001466 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 }
1468 }
1469
1470 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001471 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001472 }
1473
Wink Saville63f03dd2014-10-23 10:44:45 -07001474 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001475 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001476 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001477 }
yifan.baie620ce72017-12-22 14:59:57 +08001478 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001480 if (validatePhoneId(phoneId)) {
1481 mDataActivity[phoneId] = state;
1482 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001483 // Notify by correct subId.
1484 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1485 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001486 try {
1487 r.callback.onDataActivity(state);
1488 } catch (RemoteException ex) {
1489 mRemoveList.add(r.binder);
1490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 }
1492 }
1493 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001494 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 }
1496 }
1497
Jack Yu4d1c9452019-01-02 16:51:08 -08001498 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1499 LinkProperties linkProperties,
1500 NetworkCapabilities networkCapabilities, int networkType,
1501 boolean roaming) {
chen xud5deeb12019-04-29 13:57:42 -07001502 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX,
1503 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yu4d1c9452019-01-02 16:51:08 -08001504 isDataAllowed, apn, apnType, linkProperties,
1505 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001506 }
1507
chen xud5deeb12019-04-29 13:57:42 -07001508 public void notifyDataConnectionForSubscriber(int phoneId, int subId, int state,
1509 boolean isDataAllowed,
Jack Yu4d1c9452019-01-02 16:51:08 -08001510 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001511 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1512 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001513 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001514 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001515 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001516 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001517 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001518 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001519 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001520 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001523 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001524 // We only call the callback when the change is for default APN type.
1525 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1526 && (mDataConnectionState[phoneId] != state
1527 || mDataConnectionNetworkType[phoneId] != networkType)) {
Jack Yu0c92c232019-04-04 15:10:17 -07001528 String str = "onDataConnectionStateChanged("
zoey chenc722b452019-12-03 17:23:22 +08001529 + dataStateToString(state)
1530 + ", " + getNetworkTypeName(networkType)
Jack Yu0c92c232019-04-04 15:10:17 -07001531 + ") subId=" + subId + ", phoneId=" + phoneId;
Jack Yud19b6ae2017-04-05 14:12:09 -07001532 log(str);
1533 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001534 for (Record r : mRecords) {
1535 if (r.matchPhoneStateListenerEvent(
chen xud5deeb12019-04-29 13:57:42 -07001536 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE)
1537 && idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001538 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001539 if (DBG) {
1540 log("Notify data connection state changed on sub: " + subId);
1541 }
Jack Yub1bac542018-03-14 16:23:38 -07001542 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001543 } catch (RemoteException ex) {
1544 mRemoveList.add(r.binder);
1545 }
1546 }
1547 }
1548 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001549
1550 mDataConnectionState[phoneId] = state;
1551 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001552 }
chen xud5deeb12019-04-29 13:57:42 -07001553 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1554 state, networkType,
chen xu16e24cd2018-12-11 18:09:41 -08001555 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1556 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001557 for (Record r : mRecords) {
1558 if (r.matchPhoneStateListenerEvent(
chen xud5deeb12019-04-29 13:57:42 -07001559 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1560 && idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001561 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001562 r.callback.onPreciseDataConnectionStateChanged(
chen xud5deeb12019-04-29 13:57:42 -07001563 mPreciseDataConnectionState[phoneId]);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001564 } catch (RemoteException ex) {
1565 mRemoveList.add(r.binder);
1566 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001567 }
1568 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001569 }
1570 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001572 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1573 networkCapabilities, roaming, subId);
1574 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu16e24cd2018-12-11 18:09:41 -08001575 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 }
1577
Jack Yu4d1c9452019-01-02 16:51:08 -08001578 public void notifyDataConnectionFailed(String apnType) {
chen xud5deeb12019-04-29 13:57:42 -07001579 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX,
1580 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yu4d1c9452019-01-02 16:51:08 -08001581 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001582 }
1583
chen xud5deeb12019-04-29 13:57:42 -07001584 public void notifyDataConnectionFailedForSubscriber(int phoneId, int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001585 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001586 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001587 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001588 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001589 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yu4d1c9452019-01-02 16:51:08 -08001590 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001593 if (validatePhoneId(phoneId)) {
1594 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1595 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1596 ApnSetting.getApnTypesBitmaskFromString(apnType), null, null,
1597 DataFailCause.NONE);
1598 for (Record r : mRecords) {
1599 if (r.matchPhoneStateListenerEvent(
1600 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1601 && idMatch(r.subId, subId, phoneId)) {
1602 try {
1603 r.callback.onPreciseDataConnectionStateChanged(
1604 mPreciseDataConnectionState[phoneId]);
1605 } catch (RemoteException ex) {
1606 mRemoveList.add(r.binder);
1607 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 }
1610 }
chen xud5deeb12019-04-29 13:57:42 -07001611
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001612 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001614 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001615 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu81653862019-02-28 10:44:54 -08001616 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, null, null,
chen xu16e24cd2018-12-11 18:09:41 -08001617 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 }
1619
1620 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001621 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001622 }
1623
Wink Saville63f03dd2014-10-23 10:44:45 -07001624 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001625 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001626 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001627 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001628 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001629 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001630 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001631 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001632 + " cellLocation=" + cellLocation);
1633 }
yifan.baie620ce72017-12-22 14:59:57 +08001634 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001636 if (validatePhoneId(phoneId)) {
1637 mCellLocation[phoneId] = cellLocation;
1638 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001639 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001640 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001641 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001642 try {
1643 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001644 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001645 + " r=" + r);
1646 }
1647 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1648 } catch (RemoteException ex) {
1649 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001650 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 }
1653 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001654 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001655 }
1656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001657
chen xud5deeb12019-04-29 13:57:42 -07001658 public void notifyOtaspChanged(int subId, int otaspMode) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001659 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1660 return;
1661 }
chen xud5deeb12019-04-29 13:57:42 -07001662 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefd2d0132010-10-28 14:22:26 -07001663 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001664 if (validatePhoneId(phoneId)) {
1665 mOtaspMode[phoneId] = otaspMode;
1666 for (Record r : mRecords) {
1667 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)
1668 && idMatch(r.subId, subId, phoneId)) {
1669 try {
1670 r.callback.onOtaspChanged(otaspMode);
1671 } catch (RemoteException ex) {
1672 mRemoveList.add(r.binder);
1673 }
Wink Savillefd2d0132010-10-28 14:22:26 -07001674 }
1675 }
1676 }
1677 handleRemoveListLocked();
1678 }
1679 }
1680
chen xud5deeb12019-04-29 13:57:42 -07001681 public void notifyPreciseCallState(int phoneId, int subId, int ringingCallState,
1682 int foregroundCallState, int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001683 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1684 return;
1685 }
1686 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001687 if (validatePhoneId(phoneId)) {
1688 mRingingCallState[phoneId] = ringingCallState;
1689 mForegroundCallState[phoneId] = foregroundCallState;
1690 mBackgroundCallState[phoneId] = backgroundCallState;
1691 mPreciseCallState[phoneId] = new PreciseCallState(
1692 ringingCallState, foregroundCallState,
1693 backgroundCallState,
1694 DisconnectCause.NOT_VALID,
1695 PreciseDisconnectCause.NOT_VALID);
1696 boolean notifyCallAttributes = true;
1697 if (mCallQuality == null) {
1698 log("notifyPreciseCallState: mCallQuality is null, "
1699 + "skipping call attributes");
1700 notifyCallAttributes = false;
1701 } else {
1702 // If the precise call state is no longer active, reset the call network type
1703 // and call quality.
1704 if (mPreciseCallState[phoneId].getForegroundCallState()
1705 != PreciseCallState.PRECISE_CALL_STATE_ACTIVE) {
1706 mCallNetworkType[phoneId] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1707 mCallQuality[phoneId] = new CallQuality();
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001708 }
chen xud5deeb12019-04-29 13:57:42 -07001709 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
1710 mCallNetworkType[phoneId], mCallQuality[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001711 }
chen xud5deeb12019-04-29 13:57:42 -07001712
1713 for (Record r : mRecords) {
1714 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)
1715 && idMatch(r.subId, subId, phoneId)) {
1716 try {
1717 r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]);
1718 } catch (RemoteException ex) {
1719 mRemoveList.add(r.binder);
1720 }
1721 }
1722 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1723 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
1724 && idMatch(r.subId, subId, phoneId)) {
1725 try {
1726 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
1727 } catch (RemoteException ex) {
1728 mRemoveList.add(r.binder);
1729 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001730 }
1731 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001732 }
1733 handleRemoveListLocked();
1734 }
chen xu6a942d482018-12-12 19:59:30 -08001735 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1736 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001737 }
1738
chen xud5deeb12019-04-29 13:57:42 -07001739 public void notifyDisconnectCause(int phoneId, int subId, int disconnectCause,
1740 int preciseDisconnectCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001741 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1742 return;
1743 }
1744 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001745 if (validatePhoneId(phoneId)) {
1746 mCallDisconnectCause[phoneId] = disconnectCause;
1747 mCallPreciseDisconnectCause[phoneId] = preciseDisconnectCause;
1748 for (Record r : mRecords) {
1749 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1750 .LISTEN_CALL_DISCONNECT_CAUSES) && idMatch(r.subId, subId, phoneId)) {
1751 try {
1752 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId],
1753 mCallPreciseDisconnectCause[phoneId]);
1754 } catch (RemoteException ex) {
1755 mRemoveList.add(r.binder);
1756 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001757 }
1758 }
1759 }
1760 handleRemoveListLocked();
1761 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001762 }
1763
chen xu6ac5fc12019-01-24 14:14:13 -08001764 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1765 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1766 return;
1767 }
1768 int phoneId = SubscriptionManager.getPhoneId(subId);
1769 synchronized (mRecords) {
1770 if (validatePhoneId(phoneId)) {
1771 mImsReasonInfo.set(phoneId, imsReasonInfo);
1772 for (Record r : mRecords) {
1773 if (r.matchPhoneStateListenerEvent(
1774 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1775 && idMatch(r.subId, subId, phoneId)) {
1776 try {
1777 if (DBG_LOC) {
1778 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1779 + imsReasonInfo + " r=" + r);
1780 }
1781 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1782 } catch (RemoteException ex) {
1783 mRemoveList.add(r.binder);
1784 }
1785 }
1786 }
1787 }
1788 handleRemoveListLocked();
1789 }
1790 }
1791
chen xud5deeb12019-04-29 13:57:42 -07001792 public void notifyPreciseDataConnectionFailed(int phoneId, int subId, String apnType,
Chen Xuc9d4ee12019-09-26 16:11:59 -07001793 String apn, @DataFailureCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001794 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1795 return;
1796 }
1797 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001798 if (validatePhoneId(phoneId)) {
1799 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1800 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1801 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
1802 for (Record r : mRecords) {
1803 if (r.matchPhoneStateListenerEvent(
1804 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1805 && idMatch(r.subId, subId, phoneId)) {
1806 try {
1807 r.callback.onPreciseDataConnectionStateChanged(
1808 mPreciseDataConnectionState[phoneId]);
1809 } catch (RemoteException ex) {
1810 mRemoveList.add(r.binder);
1811 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001812 }
1813 }
1814 }
chen xud5deeb12019-04-29 13:57:42 -07001815
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001816 handleRemoveListLocked();
1817 }
1818 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yu4d1c9452019-01-02 16:51:08 -08001819 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001820 }
1821
Brad Ebingerefed9822018-10-26 10:25:57 -07001822 @Override
Chen Xuc9d4ee12019-09-26 16:11:59 -07001823 public void notifySrvccStateChanged(int subId, @SrvccState int state) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001824 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001825 return;
1826 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001827 if (VDBG) {
1828 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1829 }
1830 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001831 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001832 if (validatePhoneId(phoneId)) {
chen xu6ac5fc12019-01-24 14:14:13 -08001833 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001834 for (Record r : mRecords) {
1835 if (r.matchPhoneStateListenerEvent(
1836 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1837 idMatch(r.subId, subId, phoneId)) {
1838 try {
1839 if (DBG_LOC) {
1840 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1841 }
1842 r.callback.onSrvccStateChanged(state);
1843 } catch (RemoteException ex) {
1844 mRemoveList.add(r.binder);
1845 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001846 }
1847 }
1848 }
1849 handleRemoveListLocked();
1850 }
1851 }
1852
chen xud5deeb12019-04-29 13:57:42 -07001853 public void notifyOemHookRawEventForSubscriber(int phoneId, int subId, byte[] rawData) {
Shuo Qian066e8652018-04-25 21:02:35 +00001854 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1855 return;
1856 }
1857
1858 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001859 if (validatePhoneId(phoneId)) {
1860 for (Record r : mRecords) {
1861 if (VDBG) {
1862 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1863 }
1864 if ((r.matchPhoneStateListenerEvent(
1865 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT))
1866 && idMatch(r.subId, subId, phoneId)) {
1867 try {
1868 r.callback.onOemHookRawEvent(rawData);
1869 } catch (RemoteException ex) {
1870 mRemoveList.add(r.binder);
1871 }
Shuo Qian066e8652018-04-25 21:02:35 +00001872 }
1873 }
1874 }
1875 handleRemoveListLocked();
1876 }
1877 }
1878
Malcolm Chene1623652018-08-08 20:27:45 -07001879 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1880 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1881 return;
1882 }
1883
1884 if (VDBG) {
1885 log("notifyPhoneCapabilityChanged: capability=" + capability);
1886 }
1887
1888 synchronized (mRecords) {
1889 mPhoneCapability = capability;
1890
1891 for (Record r : mRecords) {
1892 if (r.matchPhoneStateListenerEvent(
1893 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1894 try {
1895 r.callback.onPhoneCapabilityChanged(capability);
1896 } catch (RemoteException ex) {
1897 mRemoveList.add(r.binder);
1898 }
1899 }
1900 }
1901 handleRemoveListLocked();
1902 }
1903 }
1904
Malcolm Chen026451d2019-02-14 19:50:19 -08001905 public void notifyActiveDataSubIdChanged(int activeDataSubId) {
1906 if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001907 return;
1908 }
1909
1910 if (VDBG) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001911 log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001912 }
1913
sqian9e9ed182019-03-20 16:17:09 -07001914 mActiveDataSubId = activeDataSubId;
sqian9e9ed182019-03-20 16:17:09 -07001915 synchronized (mRecords) {
Malcolm Chenf028c3b2019-09-04 16:10:34 -07001916 for (Record r : mRecords) {
1917 if (r.matchPhoneStateListenerEvent(
1918 PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE)) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001919 try {
Malcolm Chen026451d2019-02-14 19:50:19 -08001920 r.callback.onActiveDataSubIdChanged(activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001921 } catch (RemoteException ex) {
1922 mRemoveList.add(r.binder);
1923 }
1924 }
1925 }
1926 handleRemoveListLocked();
1927 }
1928 }
Malcolm Chene1623652018-08-08 20:27:45 -07001929
Chen Xuc9d4ee12019-09-26 16:11:59 -07001930 public void notifyRadioPowerStateChanged(int phoneId, int subId, @RadioPowerState int state) {
Chen Xu7395c632018-10-17 17:53:47 +00001931 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1932 return;
1933 }
1934
1935 if (VDBG) {
chen xud5deeb12019-04-29 13:57:42 -07001936 log("notifyRadioPowerStateChanged: state= " + state + " subId=" + subId);
Chen Xu7395c632018-10-17 17:53:47 +00001937 }
1938
1939 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001940 if (validatePhoneId(phoneId)) {
1941 mRadioPowerState = state;
Chen Xu7395c632018-10-17 17:53:47 +00001942
chen xud5deeb12019-04-29 13:57:42 -07001943 for (Record r : mRecords) {
1944 if (r.matchPhoneStateListenerEvent(
1945 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)
1946 && idMatch(r.subId, subId, phoneId)) {
1947 try {
1948 r.callback.onRadioPowerStateChanged(state);
1949 } catch (RemoteException ex) {
1950 mRemoveList.add(r.binder);
1951 }
Chen Xu7395c632018-10-17 17:53:47 +00001952 }
1953 }
chen xud5deeb12019-04-29 13:57:42 -07001954
Chen Xu7395c632018-10-17 17:53:47 +00001955 }
1956 handleRemoveListLocked();
1957 }
1958 }
1959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 @Override
chen xud5deeb12019-04-29 13:57:42 -07001961 public void notifyEmergencyNumberList(int phoneId, int subId) {
sqian9f93a122018-12-03 22:40:41 -08001962 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1963 return;
1964 }
1965
1966 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001967 if (validatePhoneId(phoneId)) {
1968 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1969 Context.TELEPHONY_SERVICE);
1970 mEmergencyNumberList = tm.getEmergencyNumberList();
sqian9f93a122018-12-03 22:40:41 -08001971
chen xud5deeb12019-04-29 13:57:42 -07001972 for (Record r : mRecords) {
1973 if (r.matchPhoneStateListenerEvent(
1974 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)
1975 && idMatch(r.subId, subId, phoneId)) {
1976 try {
1977 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1978 if (VDBG) {
1979 log("notifyEmergencyNumberList: emergencyNumberList= "
1980 + mEmergencyNumberList);
1981 }
1982 } catch (RemoteException ex) {
1983 mRemoveList.add(r.binder);
sqian9f93a122018-12-03 22:40:41 -08001984 }
sqian9f93a122018-12-03 22:40:41 -08001985 }
1986 }
1987 }
chen xud5deeb12019-04-29 13:57:42 -07001988
sqian9f93a122018-12-03 22:40:41 -08001989 handleRemoveListLocked();
1990 }
sqianbdc5a732018-10-26 13:27:51 -07001991 }
1992
Jordan Liu8218ddd2018-11-28 11:22:39 -08001993 @Override
Shuo Qian134334b2019-09-12 17:00:31 -07001994 public void notifyOutgoingEmergencyCall(int phoneId, int subId,
1995 EmergencyNumber emergencyNumber) {
1996 if (!checkNotifyPermission("notifyOutgoingEmergencyCall()")) {
1997 return;
1998 }
1999 synchronized (mRecords) {
2000 if (validatePhoneId(phoneId)) {
2001 mOutgoingCallEmergencyNumber[phoneId] = emergencyNumber;
2002 for (Record r : mRecords) {
2003 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07002004 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL)
Shuo Qian134334b2019-09-12 17:00:31 -07002005 && idMatch(r.subId, subId, phoneId)) {
2006 try {
2007 r.callback.onOutgoingEmergencyCall(emergencyNumber);
2008 } catch (RemoteException ex) {
2009 mRemoveList.add(r.binder);
2010 }
2011 }
2012 }
2013 }
2014 handleRemoveListLocked();
2015 }
2016 }
2017
2018 @Override
2019 public void notifyOutgoingEmergencySms(int phoneId, int subId,
2020 EmergencyNumber emergencyNumber) {
2021 if (!checkNotifyPermission("notifyOutgoingEmergencySms()")) {
2022 return;
2023 }
2024 synchronized (mRecords) {
2025 if (validatePhoneId(phoneId)) {
2026 mOutgoingSmsEmergencyNumber[phoneId] = emergencyNumber;
2027 for (Record r : mRecords) {
2028 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07002029 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS)
Shuo Qian134334b2019-09-12 17:00:31 -07002030 && idMatch(r.subId, subId, phoneId)) {
2031 try {
2032 r.callback.onOutgoingEmergencySms(emergencyNumber);
2033 } catch (RemoteException ex) {
2034 mRemoveList.add(r.binder);
2035 }
2036 }
2037 }
2038 }
2039 handleRemoveListLocked();
2040 }
2041 }
2042
2043 @Override
chen xud5deeb12019-04-29 13:57:42 -07002044 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId, int subId,
Jordan Liu65ed9d92019-02-19 14:42:07 -08002045 int callNetworkType) {
Jordan Liu8218ddd2018-11-28 11:22:39 -08002046 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
2047 return;
2048 }
2049
Jordan Liu8218ddd2018-11-28 11:22:39 -08002050 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07002051 if (validatePhoneId(phoneId)) {
2052 // merge CallQuality with PreciseCallState and network type
2053 mCallQuality[phoneId] = callQuality;
2054 mCallNetworkType[phoneId] = callNetworkType;
2055 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
2056 callNetworkType, callQuality);
Jordan Liu8218ddd2018-11-28 11:22:39 -08002057
chen xud5deeb12019-04-29 13:57:42 -07002058 for (Record r : mRecords) {
2059 if (r.matchPhoneStateListenerEvent(
2060 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
2061 && idMatch(r.subId, subId, phoneId)) {
2062 try {
2063 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
2064 } catch (RemoteException ex) {
2065 mRemoveList.add(r.binder);
2066 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08002067 }
2068 }
2069 }
chen xud5deeb12019-04-29 13:57:42 -07002070
Jordan Liu8218ddd2018-11-28 11:22:39 -08002071 handleRemoveListLocked();
2072 }
2073 }
2074
sqianbdc5a732018-10-26 13:27:51 -07002075
2076 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07002077 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
2078 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
2079
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06002080 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07002081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002083 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07002085 pw.increaseIndent();
Malcolm Chen5d354612019-11-06 15:03:23 -08002086 for (int i = 0; i < getTelephonyManager().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002087 pw.println("Phone Id=" + i);
2088 pw.increaseIndent();
2089 pw.println("mCallState=" + mCallState[i]);
chen xud5deeb12019-04-29 13:57:42 -07002090 pw.println("mRingingCallState=" + mRingingCallState[i]);
2091 pw.println("mForegroundCallState=" + mForegroundCallState[i]);
2092 pw.println("mBackgroundCallState=" + mBackgroundCallState[i]);
2093 pw.println("mPreciseCallState=" + mPreciseCallState[i]);
2094 pw.println("mCallDisconnectCause=" + mCallDisconnectCause[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002095 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
2096 pw.println("mServiceState=" + mServiceState[i]);
2097 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
2098 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08002099 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002100 pw.println("mSignalStrength=" + mSignalStrength[i]);
2101 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
2102 pw.println("mCallForwarding=" + mCallForwarding[i]);
2103 pw.println("mDataActivity=" + mDataActivity[i]);
2104 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002105 pw.println("mCellLocation=" + mCellLocation[i]);
2106 pw.println("mCellInfo=" + mCellInfo.get(i));
Tyler Gunnf3f89d02019-03-25 07:26:33 -07002107 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i));
chen xud5deeb12019-04-29 13:57:42 -07002108 pw.println("mSrvccState=" + mSrvccState[i]);
2109 pw.println("mOtaspMode=" + mOtaspMode[i]);
2110 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause[i]);
2111 pw.println("mCallQuality=" + mCallQuality[i]);
2112 pw.println("mCallAttributes=" + mCallAttributes[i]);
2113 pw.println("mCallNetworkType=" + mCallNetworkType[i]);
2114 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState[i]);
Shuo Qian134334b2019-09-12 17:00:31 -07002115 pw.println("mOutgoingCallEmergencyNumber=" + mOutgoingCallEmergencyNumber[i]);
2116 pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002117 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05302118 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002119 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
chen xud5deeb12019-04-29 13:57:42 -07002120
Malcolm Chene1623652018-08-08 20:27:45 -07002121 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen026451d2019-02-14 19:50:19 -08002122 pw.println("mActiveDataSubId=" + mActiveDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00002123 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian9f93a122018-12-03 22:40:41 -08002124 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
chen xuaddc2702019-05-07 16:25:12 -07002125 pw.println("mDefaultPhoneId=" + mDefaultPhoneId);
2126 pw.println("mDefaultSubId=" + mDefaultSubId);
Jack Yud19b6ae2017-04-05 14:12:09 -07002127
2128 pw.decreaseIndent();
2129
2130 pw.println("local logs:");
2131 pw.increaseIndent();
2132 mLocalLog.dump(fd, pw, args);
Jack Yu0c92c232019-04-04 15:10:17 -07002133 pw.println("listen logs:");
2134 mListenLog.dump(fd, pw, args);
Jack Yud19b6ae2017-04-05 14:12:09 -07002135 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07002136 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07002137 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07002138 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002139 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002141 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 }
2143 }
2144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 //
2146 // the legacy intent broadcasting
2147 //
2148
Meng Wang4c18a3a2019-12-09 17:00:01 -08002149 // Legacy intent action.
2150 /** Fired when a subscription's phone state changes. */
2151 private static final String ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED =
2152 "android.intent.action.SUBSCRIPTION_PHONE_STATE";
2153
2154 // Legacy intent extra keys, copied from PhoneConstants.
2155 // Used in legacy intents sent here, for backward compatibility.
2156 private static final String PHONE_CONSTANTS_SLOT_KEY = "slot";
2157 private static final String PHONE_CONSTANTS_SUBSCRIPTION_KEY = "subscription";
2158
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002159 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07002160 long ident = Binder.clearCallingIdentity();
2161 try {
2162 mBatteryStats.notePhoneState(state.getState());
2163 } catch (RemoteException re) {
2164 // Can't do much
2165 } finally {
2166 Binder.restoreCallingIdentity(ident);
2167 }
2168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08002170 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 Bundle data = new Bundle();
2172 state.fillInNotifierBundle(data);
2173 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07002174 // Pass the subscription along with the intent.
Meng Wang4c18a3a2019-12-09 17:00:01 -08002175 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002176 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002177 intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId);
2178 intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002179 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 }
2181
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002182 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
2183 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002184 long ident = Binder.clearCallingIdentity();
2185 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07002186 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002187 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002188 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07002189 } finally {
2190 Binder.restoreCallingIdentity(ident);
2191 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07002194 Bundle data = new Bundle();
2195 signalStrength.fillInNotifierBundle(data);
2196 intent.putExtras(data);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002197 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
2198 intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002199 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002200 }
2201
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002202 /**
2203 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
2204 * a valid subId, in which case this function fires a subId-specific intent, or it
2205 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
2206 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
2207 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002208 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
2209 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 long ident = Binder.clearCallingIdentity();
2211 try {
2212 if (state == TelephonyManager.CALL_STATE_IDLE) {
2213 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07002214 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2215 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 } else {
2217 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07002218 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2219 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 }
2221 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002222 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 } finally {
2224 Binder.restoreCallingIdentity(ident);
2225 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Meng Wang762281b2019-12-06 10:37:58 -08002228 intent.putExtra(TelephonyManager.EXTRA_STATE, callStateToString(state));
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002229
2230 // If a valid subId was specified, we should fire off a subId-specific state
2231 // change intent and include the subId.
2232 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
Meng Wang4c18a3a2019-12-09 17:00:01 -08002233 intent.setAction(ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
2234 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002235 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002236 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002237 // If the phoneId is invalid, the broadcast is for overall call state.
2238 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
Meng Wang4c18a3a2019-12-09 17:00:01 -08002239 intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId);
2240 intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002241 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002242
Brad Ebinger51de96a2017-04-21 17:05:18 -07002243 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
2244 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
2245
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002246 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002247 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002248 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2249
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002250 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2251 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002252 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002253 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002254 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002255 android.Manifest.permission.READ_PHONE_STATE,
2256 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002257 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2258 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2259 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 }
2261
Meng Wang762281b2019-12-06 10:37:58 -08002262 /** Converts TelephonyManager#CALL_STATE_* to TelephonyManager#EXTRA_STATE_*. */
2263 private static String callStateToString(int callState) {
2264 switch (callState) {
2265 case TelephonyManager.CALL_STATE_RINGING:
2266 return TelephonyManager.EXTRA_STATE_RINGING;
2267 case TelephonyManager.CALL_STATE_OFFHOOK:
2268 return TelephonyManager.EXTRA_STATE_OFFHOOK;
2269 default:
2270 return TelephonyManager.EXTRA_STATE_IDLE;
2271 }
2272 }
2273
Jack Yu4d1c9452019-01-02 16:51:08 -08002274 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2275 String apnType, LinkProperties linkProperties,
2276 NetworkCapabilities networkCapabilities,
2277 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002278 // Note: not reporting to the battery stats service here, because the
2279 // status bar takes care of that after taking into account all of the
2280 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Meng Wang762281b2019-12-06 10:37:58 -08002282 intent.putExtra(TelephonyManager.EXTRA_STATE, dataStateToString(state));
Jack Yubaeec622017-05-01 17:01:11 -07002283 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002284 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002286 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002287 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002288 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002289 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002290 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002291 }
2292 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002293 if (networkCapabilities != null) {
2294 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002295 }
Wink Savillea639b312012-07-10 12:37:54 -07002296 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002297
Wink Savillea639b312012-07-10 12:37:54 -07002298 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2299 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002300 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002301 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 }
2303
Jack Yu4d1c9452019-01-02 16:51:08 -08002304 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002306 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002307 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002308 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002310
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002311 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yu4d1c9452019-01-02 16:51:08 -08002312 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002313 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2314 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2315 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2316 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002317 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2318 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2319 }
2320
2321 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu16e24cd2018-12-11 18:09:41 -08002322 String apnType, String apn, LinkProperties linkProperties,
Chen Xuc9d4ee12019-09-26 16:11:59 -07002323 @DataFailureCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002324 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
Meng Wang762281b2019-12-06 10:37:58 -08002325 intent.putExtra(TelephonyManager.EXTRA_STATE, state);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002326 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002327 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2328 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002329 if (linkProperties != null) {
Jack Yu4d1c9452019-01-02 16:51:08 -08002330 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002331 }
chen xu16e24cd2018-12-11 18:09:41 -08002332 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002333
2334 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2335 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2336 }
2337
Andrew Flynnceaed682015-06-09 12:36:58 +00002338 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002339 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002340 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002341 }
2342
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002343 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2344 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002345 }
2346
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002347 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002348 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002349 return true;
2350 }
2351 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002352 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002353 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002354 return false;
2355 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002356
Andrew Flynn1f452642015-04-14 22:16:04 -04002357 private boolean checkNotifyPermission() {
2358 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2359 == PackageManager.PERMISSION_GRANTED;
2360 }
2361
Philip P. Moltmann33692f72019-10-03 11:56:11 -07002362 private boolean checkListenerPermission(int events, int subId, String callingPackage,
2363 @Nullable String callingFeatureId, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002364 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2365 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2366 .setCallingPackage(callingPackage)
2367 .setMethod(message + " events: " + events)
2368 .setCallingPid(Binder.getCallingPid())
2369 .setCallingUid(Binder.getCallingUid());
2370
2371 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002372 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002373 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2374 shouldCheckLocationPermissions = true;
2375 }
2376
2377 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2378 // Everything that requires fine location started in Q. So far...
2379 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2380 shouldCheckLocationPermissions = true;
2381 }
2382
2383 if (shouldCheckLocationPermissions) {
2384 LocationAccessPolicy.LocationPermissionResult result =
2385 LocationAccessPolicy.checkLocationPermission(
2386 mContext, locationQueryBuilder.build());
2387 switch (result) {
2388 case DENIED_HARD:
2389 throw new SecurityException("Unable to listen for events " + events + " due to "
2390 + "insufficient location permissions.");
2391 case DENIED_SOFT:
2392 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002393 }
John Wang963db55d2012-03-30 16:04:06 -07002394 }
2395
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002396 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann33692f72019-10-03 11:56:11 -07002398 mContext, subId, callingPackage, callingFeatureId, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002399 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002400 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002401 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002402
2403 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2404 mContext.enforceCallingOrSelfPermission(
2405 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002406 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002407
Shuo Qian134334b2019-09-12 17:00:31 -07002408 if ((events & READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK) != 0) {
2409 mContext.enforceCallingOrSelfPermission(
2410 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2411 }
2412
Shuo Qian066e8652018-04-25 21:02:35 +00002413 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2414 mContext.enforceCallingOrSelfPermission(
2415 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2416 }
2417
Brad Ebingerefed9822018-10-26 10:25:57 -07002418 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2419 mContext.enforceCallingOrSelfPermission(
2420 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2421 }
2422
chen xu6a942d482018-12-12 19:59:30 -08002423 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2424 mContext.enforceCallingOrSelfPermission(
2425 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2426 }
2427
Jordan Liu8218ddd2018-11-28 11:22:39 -08002428 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2429 mContext.enforceCallingOrSelfPermission(
2430 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2431 }
2432
chen xu52797b62019-01-18 13:16:31 -08002433 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2434 mContext.enforceCallingOrSelfPermission(
2435 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2436 }
2437
2438 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2439 mContext.enforceCallingOrSelfPermission(
2440 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2441 }
2442
chen xu6ac5fc12019-01-24 14:14:13 -08002443 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2444 mContext.enforceCallingOrSelfPermission(
2445 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2446 }
2447
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002448 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002449 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002450
2451 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002452 int size = mRemoveList.size();
2453 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2454 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002455 for (IBinder b: mRemoveList) {
2456 remove(b);
2457 }
2458 mRemoveList.clear();
2459 }
2460 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002461
2462 private boolean validateEventsAndUserLocked(Record r, int events) {
2463 int foregroundUser;
2464 long callingIdentity = Binder.clearCallingIdentity();
2465 boolean valid = false;
2466 try {
2467 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002468 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2469 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002470 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002471 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002472 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002473 + " r.events=" + r.events + " events=" + events);
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(callingIdentity);
2477 }
2478 return valid;
2479 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002480
2481 private boolean validatePhoneId(int phoneId) {
2482 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002483 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002484 return valid;
2485 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002486
2487 private static void log(String s) {
2488 Rlog.d(TAG, s);
2489 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002490
chen xu627d1b22019-04-11 02:16:19 -07002491 private static void loge(String s) {
2492 Rlog.e(TAG, s);
2493 }
2494
xinhe8b79fb62014-11-05 14:55:03 -08002495 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002496
2497 if(subId < 0) {
2498 // Invalid case, we need compare phoneId with default one.
2499 return (mDefaultPhoneId == phoneId);
2500 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002501 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002502 return (subId == mDefaultSubId);
2503 } else {
2504 return (rSubId == subId);
2505 }
2506 }
2507
Hall Liuee313732018-11-27 14:36:51 -08002508 private boolean checkFineLocationAccess(Record r, int minSdk) {
2509 LocationAccessPolicy.LocationPermissionQuery query =
2510 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2511 .setCallingPackage(r.callingPackage)
2512 .setCallingPid(r.callerPid)
2513 .setCallingUid(r.callerUid)
2514 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002515 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002516 .setMinSdkVersionForFine(minSdk)
2517 .build();
2518
2519 return Binder.withCleanCallingIdentity(() -> {
2520 LocationAccessPolicy.LocationPermissionResult locationResult =
2521 LocationAccessPolicy.checkLocationPermission(mContext, query);
2522 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2523 });
2524 }
2525
2526 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2527 LocationAccessPolicy.LocationPermissionQuery query =
2528 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2529 .setCallingPackage(r.callingPackage)
2530 .setCallingPid(r.callerPid)
2531 .setCallingUid(r.callerUid)
2532 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002533 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002534 .setMinSdkVersionForCoarse(minSdk)
2535 .build();
2536
2537 return Binder.withCleanCallingIdentity(() -> {
2538 LocationAccessPolicy.LocationPermissionResult locationResult =
2539 LocationAccessPolicy.checkLocationPermission(mContext, query);
2540 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2541 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002542 }
2543
xinhee9f16402014-09-25 16:39:28 -07002544 private void checkPossibleMissNotify(Record r, int phoneId) {
2545 int events = r.events;
2546
2547 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2548 try {
2549 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2550 mServiceState[phoneId]);
2551 r.callback.onServiceStateChanged(
2552 new ServiceState(mServiceState[phoneId]));
2553 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002554 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002555 }
2556 }
2557
2558 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2559 try {
2560 SignalStrength signalStrength = mSignalStrength[phoneId];
2561 if (DBG) {
2562 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2563 }
2564 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2565 } catch (RemoteException ex) {
2566 mRemoveList.add(r.binder);
2567 }
2568 }
2569
2570 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2571 try {
2572 int gsmSignalStrength = mSignalStrength[phoneId]
2573 .getGsmSignalStrength();
2574 if (DBG) {
2575 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2576 gsmSignalStrength);
2577 }
2578 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2579 : gsmSignalStrength));
2580 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002581 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002582 }
2583 }
2584
2585 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2586 try {
2587 if (DBG_LOC) {
2588 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2589 + mCellInfo.get(phoneId));
2590 }
Hall Liuee313732018-11-27 14:36:51 -08002591 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002592 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2593 }
xinhee9f16402014-09-25 16:39:28 -07002594 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002595 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002596 }
2597 }
2598
zxuan35a47022018-01-04 11:24:04 -08002599 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2600 try {
2601 if (VDBG) {
2602 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2603 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2604 }
2605 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2606 } catch (RemoteException ex) {
2607 mRemoveList.add(r.binder);
2608 }
2609 }
2610
xinhee9f16402014-09-25 16:39:28 -07002611 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2612 try {
2613 if (VDBG) {
2614 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2615 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2616 }
2617 r.callback.onMessageWaitingIndicatorChanged(
2618 mMessageWaiting[phoneId]);
2619 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002620 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002621 }
2622 }
2623
2624 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2625 try {
2626 if (VDBG) {
2627 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2628 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2629 }
2630 r.callback.onCallForwardingIndicatorChanged(
2631 mCallForwarding[phoneId]);
2632 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002633 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002634 }
2635 }
2636
2637 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2638 try {
2639 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2640 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002641 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002642 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2643 }
xinhee9f16402014-09-25 16:39:28 -07002644 } catch (RemoteException ex) {
2645 mRemoveList.add(r.binder);
2646 }
2647 }
2648
2649 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2650 try {
2651 if (DBG) {
2652 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2653 + "=" + mDataConnectionState[phoneId]
2654 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2655 + ")");
2656 }
2657 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2658 mDataConnectionNetworkType[phoneId]);
2659 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002660 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002661 }
2662 }
2663 }
zoey chenc722b452019-12-03 17:23:22 +08002664
2665 /**
Meng Wang762281b2019-12-06 10:37:58 -08002666 * Convert TelephonyManager.DATA_* to string.
zoey chenc722b452019-12-03 17:23:22 +08002667 *
2668 * @return The data state in string format.
2669 */
Meng Wang762281b2019-12-06 10:37:58 -08002670 private static String dataStateToString(int state) {
zoey chenc722b452019-12-03 17:23:22 +08002671 switch (state) {
2672 case TelephonyManager.DATA_DISCONNECTED: return "DISCONNECTED";
2673 case TelephonyManager.DATA_CONNECTING: return "CONNECTING";
2674 case TelephonyManager.DATA_CONNECTED: return "CONNECTED";
2675 case TelephonyManager.DATA_SUSPENDED: return "SUSPENDED";
2676 }
2677 return "UNKNOWN(" + state + ")";
2678 }
2679
2680 /**
2681 * Returns a string representation of the radio technology (network type)
2682 * currently in use on the device.
2683 * @param subId for which network type is returned
2684 * @return the name of the radio technology
2685 *
2686 */
2687 private String getNetworkTypeName(@Annotation.NetworkType int type) {
2688 switch (type) {
2689 case TelephonyManager.NETWORK_TYPE_GPRS:
2690 return "GPRS";
2691 case TelephonyManager.NETWORK_TYPE_EDGE:
2692 return "EDGE";
2693 case TelephonyManager.NETWORK_TYPE_UMTS:
2694 return "UMTS";
2695 case TelephonyManager.NETWORK_TYPE_HSDPA:
2696 return "HSDPA";
2697 case TelephonyManager.NETWORK_TYPE_HSUPA:
2698 return "HSUPA";
2699 case TelephonyManager.NETWORK_TYPE_HSPA:
2700 return "HSPA";
2701 case TelephonyManager.NETWORK_TYPE_CDMA:
2702 return "CDMA";
2703 case TelephonyManager.NETWORK_TYPE_EVDO_0:
2704 return "CDMA - EvDo rev. 0";
2705 case TelephonyManager.NETWORK_TYPE_EVDO_A:
2706 return "CDMA - EvDo rev. A";
2707 case TelephonyManager.NETWORK_TYPE_EVDO_B:
2708 return "CDMA - EvDo rev. B";
2709 case TelephonyManager.NETWORK_TYPE_1xRTT:
2710 return "CDMA - 1xRTT";
2711 case TelephonyManager.NETWORK_TYPE_LTE:
2712 return "LTE";
2713 case TelephonyManager.NETWORK_TYPE_EHRPD:
2714 return "CDMA - eHRPD";
2715 case TelephonyManager.NETWORK_TYPE_IDEN:
2716 return "iDEN";
2717 case TelephonyManager.NETWORK_TYPE_HSPAP:
2718 return "HSPA+";
2719 case TelephonyManager.NETWORK_TYPE_GSM:
2720 return "GSM";
2721 case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
2722 return "TD_SCDMA";
2723 case TelephonyManager.NETWORK_TYPE_IWLAN:
2724 return "IWLAN";
2725 case TelephonyManager.NETWORK_TYPE_LTE_CA:
2726 return "LTE_CA";
2727 case TelephonyManager.NETWORK_TYPE_NR:
2728 return "NR";
2729 default:
2730 return "UNKNOWN";
2731 }
2732 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002733}