blob: b560761aa94fdb3fc3c2d75513c3942ce71b32f8 [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;
Meng Wangbe15dba2019-12-10 10:54:50 -0800449 mCallQuality[i] = createCallQuality();
Malcolm Chen5d354612019-11-06 15:03:23 -0800450 mCallAttributes[i] = new CallAttributes(new PreciseCallState(),
Meng Wangbe15dba2019-12-10 10:54:50 -0800451 TelephonyManager.NETWORK_TYPE_UNKNOWN, createCallQuality());
Malcolm Chen5d354612019-11-06 15:03:23 -0800452 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;
Meng Wangbe15dba2019-12-10 10:54:50 -0800544 mCallQuality[i] = createCallQuality();
chen xud5deeb12019-04-29 13:57:42 -0700545 mCallAttributes[i] = new CallAttributes(new PreciseCallState(),
Meng Wangbe15dba2019-12-10 10:54:50 -0800546 TelephonyManager.NETWORK_TYPE_UNKNOWN, createCallQuality());
chen xud5deeb12019-04-29 13:57:42 -0700547 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);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 }
1575
Jack Yu4d1c9452019-01-02 16:51:08 -08001576 public void notifyDataConnectionFailed(String apnType) {
chen xud5deeb12019-04-29 13:57:42 -07001577 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX,
1578 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yu4d1c9452019-01-02 16:51:08 -08001579 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001580 }
1581
chen xud5deeb12019-04-29 13:57:42 -07001582 public void notifyDataConnectionFailedForSubscriber(int phoneId, int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001583 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001584 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001585 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001586 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001587 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yu4d1c9452019-01-02 16:51:08 -08001588 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001589 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001591 if (validatePhoneId(phoneId)) {
1592 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1593 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1594 ApnSetting.getApnTypesBitmaskFromString(apnType), null, null,
1595 DataFailCause.NONE);
1596 for (Record r : mRecords) {
1597 if (r.matchPhoneStateListenerEvent(
1598 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1599 && idMatch(r.subId, subId, phoneId)) {
1600 try {
1601 r.callback.onPreciseDataConnectionStateChanged(
1602 mPreciseDataConnectionState[phoneId]);
1603 } catch (RemoteException ex) {
1604 mRemoveList.add(r.binder);
1605 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 }
1608 }
chen xud5deeb12019-04-29 13:57:42 -07001609
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001610 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 }
Jack Yu4d1c9452019-01-02 16:51:08 -08001612 broadcastDataConnectionFailed(apnType, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 }
1614
1615 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001616 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001617 }
1618
Wink Saville63f03dd2014-10-23 10:44:45 -07001619 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001620 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001621 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001622 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001623 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001624 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001625 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001626 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001627 + " cellLocation=" + cellLocation);
1628 }
yifan.baie620ce72017-12-22 14:59:57 +08001629 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001631 if (validatePhoneId(phoneId)) {
1632 mCellLocation[phoneId] = cellLocation;
1633 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001634 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001635 idMatch(r.subId, subId, phoneId) &&
Hall Liuee313732018-11-27 14:36:51 -08001636 checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001637 try {
1638 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001639 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001640 + " r=" + r);
1641 }
1642 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1643 } catch (RemoteException ex) {
1644 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001645 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 }
1648 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001649 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001650 }
1651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652
chen xud5deeb12019-04-29 13:57:42 -07001653 public void notifyOtaspChanged(int subId, int otaspMode) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001654 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1655 return;
1656 }
chen xud5deeb12019-04-29 13:57:42 -07001657 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefd2d0132010-10-28 14:22:26 -07001658 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001659 if (validatePhoneId(phoneId)) {
1660 mOtaspMode[phoneId] = otaspMode;
1661 for (Record r : mRecords) {
1662 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)
1663 && idMatch(r.subId, subId, phoneId)) {
1664 try {
1665 r.callback.onOtaspChanged(otaspMode);
1666 } catch (RemoteException ex) {
1667 mRemoveList.add(r.binder);
1668 }
Wink Savillefd2d0132010-10-28 14:22:26 -07001669 }
1670 }
1671 }
1672 handleRemoveListLocked();
1673 }
1674 }
1675
chen xud5deeb12019-04-29 13:57:42 -07001676 public void notifyPreciseCallState(int phoneId, int subId, int ringingCallState,
1677 int foregroundCallState, int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001678 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1679 return;
1680 }
1681 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001682 if (validatePhoneId(phoneId)) {
1683 mRingingCallState[phoneId] = ringingCallState;
1684 mForegroundCallState[phoneId] = foregroundCallState;
1685 mBackgroundCallState[phoneId] = backgroundCallState;
1686 mPreciseCallState[phoneId] = new PreciseCallState(
1687 ringingCallState, foregroundCallState,
1688 backgroundCallState,
1689 DisconnectCause.NOT_VALID,
1690 PreciseDisconnectCause.NOT_VALID);
1691 boolean notifyCallAttributes = true;
1692 if (mCallQuality == null) {
1693 log("notifyPreciseCallState: mCallQuality is null, "
1694 + "skipping call attributes");
1695 notifyCallAttributes = false;
1696 } else {
1697 // If the precise call state is no longer active, reset the call network type
1698 // and call quality.
1699 if (mPreciseCallState[phoneId].getForegroundCallState()
1700 != PreciseCallState.PRECISE_CALL_STATE_ACTIVE) {
1701 mCallNetworkType[phoneId] = TelephonyManager.NETWORK_TYPE_UNKNOWN;
Meng Wangbe15dba2019-12-10 10:54:50 -08001702 mCallQuality[phoneId] = createCallQuality();
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001703 }
chen xud5deeb12019-04-29 13:57:42 -07001704 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
1705 mCallNetworkType[phoneId], mCallQuality[phoneId]);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001706 }
chen xud5deeb12019-04-29 13:57:42 -07001707
1708 for (Record r : mRecords) {
1709 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)
1710 && idMatch(r.subId, subId, phoneId)) {
1711 try {
1712 r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]);
1713 } catch (RemoteException ex) {
1714 mRemoveList.add(r.binder);
1715 }
1716 }
1717 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1718 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
1719 && idMatch(r.subId, subId, phoneId)) {
1720 try {
1721 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
1722 } catch (RemoteException ex) {
1723 mRemoveList.add(r.binder);
1724 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001725 }
1726 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001727 }
1728 handleRemoveListLocked();
1729 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001730 }
1731
chen xud5deeb12019-04-29 13:57:42 -07001732 public void notifyDisconnectCause(int phoneId, int subId, int disconnectCause,
1733 int preciseDisconnectCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001734 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1735 return;
1736 }
1737 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001738 if (validatePhoneId(phoneId)) {
1739 mCallDisconnectCause[phoneId] = disconnectCause;
1740 mCallPreciseDisconnectCause[phoneId] = preciseDisconnectCause;
1741 for (Record r : mRecords) {
1742 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1743 .LISTEN_CALL_DISCONNECT_CAUSES) && idMatch(r.subId, subId, phoneId)) {
1744 try {
1745 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId],
1746 mCallPreciseDisconnectCause[phoneId]);
1747 } catch (RemoteException ex) {
1748 mRemoveList.add(r.binder);
1749 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001750 }
1751 }
1752 }
1753 handleRemoveListLocked();
1754 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001755 }
1756
chen xu6ac5fc12019-01-24 14:14:13 -08001757 public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) {
1758 if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) {
1759 return;
1760 }
1761 int phoneId = SubscriptionManager.getPhoneId(subId);
1762 synchronized (mRecords) {
1763 if (validatePhoneId(phoneId)) {
1764 mImsReasonInfo.set(phoneId, imsReasonInfo);
1765 for (Record r : mRecords) {
1766 if (r.matchPhoneStateListenerEvent(
1767 PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES)
1768 && idMatch(r.subId, subId, phoneId)) {
1769 try {
1770 if (DBG_LOC) {
1771 log("notifyImsCallDisconnectCause: mImsReasonInfo="
1772 + imsReasonInfo + " r=" + r);
1773 }
1774 r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId));
1775 } catch (RemoteException ex) {
1776 mRemoveList.add(r.binder);
1777 }
1778 }
1779 }
1780 }
1781 handleRemoveListLocked();
1782 }
1783 }
1784
chen xud5deeb12019-04-29 13:57:42 -07001785 public void notifyPreciseDataConnectionFailed(int phoneId, int subId, String apnType,
Chen Xuc9d4ee12019-09-26 16:11:59 -07001786 String apn, @DataFailureCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001787 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1788 return;
1789 }
1790 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001791 if (validatePhoneId(phoneId)) {
1792 mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState(
1793 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1794 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
1795 for (Record r : mRecords) {
1796 if (r.matchPhoneStateListenerEvent(
1797 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)
1798 && idMatch(r.subId, subId, phoneId)) {
1799 try {
1800 r.callback.onPreciseDataConnectionStateChanged(
1801 mPreciseDataConnectionState[phoneId]);
1802 } catch (RemoteException ex) {
1803 mRemoveList.add(r.binder);
1804 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001805 }
1806 }
1807 }
chen xud5deeb12019-04-29 13:57:42 -07001808
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001809 handleRemoveListLocked();
1810 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001811 }
1812
Brad Ebingerefed9822018-10-26 10:25:57 -07001813 @Override
Chen Xuc9d4ee12019-09-26 16:11:59 -07001814 public void notifySrvccStateChanged(int subId, @SrvccState int state) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001815 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001816 return;
1817 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001818 if (VDBG) {
1819 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1820 }
1821 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001822 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001823 if (validatePhoneId(phoneId)) {
chen xu6ac5fc12019-01-24 14:14:13 -08001824 mSrvccState[phoneId] = state;
Brad Ebingerefed9822018-10-26 10:25:57 -07001825 for (Record r : mRecords) {
1826 if (r.matchPhoneStateListenerEvent(
1827 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1828 idMatch(r.subId, subId, phoneId)) {
1829 try {
1830 if (DBG_LOC) {
1831 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1832 }
1833 r.callback.onSrvccStateChanged(state);
1834 } catch (RemoteException ex) {
1835 mRemoveList.add(r.binder);
1836 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001837 }
1838 }
1839 }
1840 handleRemoveListLocked();
1841 }
1842 }
1843
chen xud5deeb12019-04-29 13:57:42 -07001844 public void notifyOemHookRawEventForSubscriber(int phoneId, int subId, byte[] rawData) {
Shuo Qian066e8652018-04-25 21:02:35 +00001845 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1846 return;
1847 }
1848
1849 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001850 if (validatePhoneId(phoneId)) {
1851 for (Record r : mRecords) {
1852 if (VDBG) {
1853 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1854 }
1855 if ((r.matchPhoneStateListenerEvent(
1856 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT))
1857 && idMatch(r.subId, subId, phoneId)) {
1858 try {
1859 r.callback.onOemHookRawEvent(rawData);
1860 } catch (RemoteException ex) {
1861 mRemoveList.add(r.binder);
1862 }
Shuo Qian066e8652018-04-25 21:02:35 +00001863 }
1864 }
1865 }
1866 handleRemoveListLocked();
1867 }
1868 }
1869
Malcolm Chene1623652018-08-08 20:27:45 -07001870 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1871 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1872 return;
1873 }
1874
1875 if (VDBG) {
1876 log("notifyPhoneCapabilityChanged: capability=" + capability);
1877 }
1878
1879 synchronized (mRecords) {
1880 mPhoneCapability = capability;
1881
1882 for (Record r : mRecords) {
1883 if (r.matchPhoneStateListenerEvent(
1884 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1885 try {
1886 r.callback.onPhoneCapabilityChanged(capability);
1887 } catch (RemoteException ex) {
1888 mRemoveList.add(r.binder);
1889 }
1890 }
1891 }
1892 handleRemoveListLocked();
1893 }
1894 }
1895
Malcolm Chen026451d2019-02-14 19:50:19 -08001896 public void notifyActiveDataSubIdChanged(int activeDataSubId) {
1897 if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001898 return;
1899 }
1900
1901 if (VDBG) {
Malcolm Chen026451d2019-02-14 19:50:19 -08001902 log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001903 }
1904
sqian9e9ed182019-03-20 16:17:09 -07001905 mActiveDataSubId = activeDataSubId;
sqian9e9ed182019-03-20 16:17:09 -07001906 synchronized (mRecords) {
Malcolm Chenf028c3b2019-09-04 16:10:34 -07001907 for (Record r : mRecords) {
1908 if (r.matchPhoneStateListenerEvent(
1909 PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE)) {
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001910 try {
Malcolm Chen026451d2019-02-14 19:50:19 -08001911 r.callback.onActiveDataSubIdChanged(activeDataSubId);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001912 } catch (RemoteException ex) {
1913 mRemoveList.add(r.binder);
1914 }
1915 }
1916 }
1917 handleRemoveListLocked();
1918 }
1919 }
Malcolm Chene1623652018-08-08 20:27:45 -07001920
Chen Xuc9d4ee12019-09-26 16:11:59 -07001921 public void notifyRadioPowerStateChanged(int phoneId, int subId, @RadioPowerState int state) {
Chen Xu7395c632018-10-17 17:53:47 +00001922 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1923 return;
1924 }
1925
1926 if (VDBG) {
chen xud5deeb12019-04-29 13:57:42 -07001927 log("notifyRadioPowerStateChanged: state= " + state + " subId=" + subId);
Chen Xu7395c632018-10-17 17:53:47 +00001928 }
1929
1930 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001931 if (validatePhoneId(phoneId)) {
1932 mRadioPowerState = state;
Chen Xu7395c632018-10-17 17:53:47 +00001933
chen xud5deeb12019-04-29 13:57:42 -07001934 for (Record r : mRecords) {
1935 if (r.matchPhoneStateListenerEvent(
1936 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)
1937 && idMatch(r.subId, subId, phoneId)) {
1938 try {
1939 r.callback.onRadioPowerStateChanged(state);
1940 } catch (RemoteException ex) {
1941 mRemoveList.add(r.binder);
1942 }
Chen Xu7395c632018-10-17 17:53:47 +00001943 }
1944 }
chen xud5deeb12019-04-29 13:57:42 -07001945
Chen Xu7395c632018-10-17 17:53:47 +00001946 }
1947 handleRemoveListLocked();
1948 }
1949 }
1950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 @Override
chen xud5deeb12019-04-29 13:57:42 -07001952 public void notifyEmergencyNumberList(int phoneId, int subId) {
sqian9f93a122018-12-03 22:40:41 -08001953 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1954 return;
1955 }
1956
1957 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07001958 if (validatePhoneId(phoneId)) {
1959 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1960 Context.TELEPHONY_SERVICE);
1961 mEmergencyNumberList = tm.getEmergencyNumberList();
sqian9f93a122018-12-03 22:40:41 -08001962
chen xud5deeb12019-04-29 13:57:42 -07001963 for (Record r : mRecords) {
1964 if (r.matchPhoneStateListenerEvent(
1965 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)
1966 && idMatch(r.subId, subId, phoneId)) {
1967 try {
1968 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1969 if (VDBG) {
1970 log("notifyEmergencyNumberList: emergencyNumberList= "
1971 + mEmergencyNumberList);
1972 }
1973 } catch (RemoteException ex) {
1974 mRemoveList.add(r.binder);
sqian9f93a122018-12-03 22:40:41 -08001975 }
sqian9f93a122018-12-03 22:40:41 -08001976 }
1977 }
1978 }
chen xud5deeb12019-04-29 13:57:42 -07001979
sqian9f93a122018-12-03 22:40:41 -08001980 handleRemoveListLocked();
1981 }
sqianbdc5a732018-10-26 13:27:51 -07001982 }
1983
Jordan Liu8218ddd2018-11-28 11:22:39 -08001984 @Override
Shuo Qian134334b2019-09-12 17:00:31 -07001985 public void notifyOutgoingEmergencyCall(int phoneId, int subId,
1986 EmergencyNumber emergencyNumber) {
1987 if (!checkNotifyPermission("notifyOutgoingEmergencyCall()")) {
1988 return;
1989 }
1990 synchronized (mRecords) {
1991 if (validatePhoneId(phoneId)) {
1992 mOutgoingCallEmergencyNumber[phoneId] = emergencyNumber;
1993 for (Record r : mRecords) {
1994 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07001995 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL)
Shuo Qian134334b2019-09-12 17:00:31 -07001996 && idMatch(r.subId, subId, phoneId)) {
1997 try {
1998 r.callback.onOutgoingEmergencyCall(emergencyNumber);
1999 } catch (RemoteException ex) {
2000 mRemoveList.add(r.binder);
2001 }
2002 }
2003 }
2004 }
2005 handleRemoveListLocked();
2006 }
2007 }
2008
2009 @Override
2010 public void notifyOutgoingEmergencySms(int phoneId, int subId,
2011 EmergencyNumber emergencyNumber) {
2012 if (!checkNotifyPermission("notifyOutgoingEmergencySms()")) {
2013 return;
2014 }
2015 synchronized (mRecords) {
2016 if (validatePhoneId(phoneId)) {
2017 mOutgoingSmsEmergencyNumber[phoneId] = emergencyNumber;
2018 for (Record r : mRecords) {
2019 if (r.matchPhoneStateListenerEvent(
Shuo Qiand9663762019-10-04 13:20:45 -07002020 PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS)
Shuo Qian134334b2019-09-12 17:00:31 -07002021 && idMatch(r.subId, subId, phoneId)) {
2022 try {
2023 r.callback.onOutgoingEmergencySms(emergencyNumber);
2024 } catch (RemoteException ex) {
2025 mRemoveList.add(r.binder);
2026 }
2027 }
2028 }
2029 }
2030 handleRemoveListLocked();
2031 }
2032 }
2033
2034 @Override
chen xud5deeb12019-04-29 13:57:42 -07002035 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId, int subId,
Jordan Liu65ed9d92019-02-19 14:42:07 -08002036 int callNetworkType) {
Jordan Liu8218ddd2018-11-28 11:22:39 -08002037 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
2038 return;
2039 }
2040
Jordan Liu8218ddd2018-11-28 11:22:39 -08002041 synchronized (mRecords) {
chen xud5deeb12019-04-29 13:57:42 -07002042 if (validatePhoneId(phoneId)) {
2043 // merge CallQuality with PreciseCallState and network type
2044 mCallQuality[phoneId] = callQuality;
2045 mCallNetworkType[phoneId] = callNetworkType;
2046 mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId],
2047 callNetworkType, callQuality);
Jordan Liu8218ddd2018-11-28 11:22:39 -08002048
chen xud5deeb12019-04-29 13:57:42 -07002049 for (Record r : mRecords) {
2050 if (r.matchPhoneStateListenerEvent(
2051 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)
2052 && idMatch(r.subId, subId, phoneId)) {
2053 try {
2054 r.callback.onCallAttributesChanged(mCallAttributes[phoneId]);
2055 } catch (RemoteException ex) {
2056 mRemoveList.add(r.binder);
2057 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08002058 }
2059 }
2060 }
chen xud5deeb12019-04-29 13:57:42 -07002061
Jordan Liu8218ddd2018-11-28 11:22:39 -08002062 handleRemoveListLocked();
2063 }
2064 }
2065
sqianbdc5a732018-10-26 13:27:51 -07002066
2067 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07002068 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
2069 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
2070
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06002071 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07002072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002074 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07002076 pw.increaseIndent();
Malcolm Chen5d354612019-11-06 15:03:23 -08002077 for (int i = 0; i < getTelephonyManager().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002078 pw.println("Phone Id=" + i);
2079 pw.increaseIndent();
2080 pw.println("mCallState=" + mCallState[i]);
chen xud5deeb12019-04-29 13:57:42 -07002081 pw.println("mRingingCallState=" + mRingingCallState[i]);
2082 pw.println("mForegroundCallState=" + mForegroundCallState[i]);
2083 pw.println("mBackgroundCallState=" + mBackgroundCallState[i]);
2084 pw.println("mPreciseCallState=" + mPreciseCallState[i]);
2085 pw.println("mCallDisconnectCause=" + mCallDisconnectCause[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002086 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
2087 pw.println("mServiceState=" + mServiceState[i]);
2088 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
2089 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08002090 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002091 pw.println("mSignalStrength=" + mSignalStrength[i]);
2092 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
2093 pw.println("mCallForwarding=" + mCallForwarding[i]);
2094 pw.println("mDataActivity=" + mDataActivity[i]);
2095 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002096 pw.println("mCellLocation=" + mCellLocation[i]);
2097 pw.println("mCellInfo=" + mCellInfo.get(i));
Tyler Gunnf3f89d02019-03-25 07:26:33 -07002098 pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i));
chen xud5deeb12019-04-29 13:57:42 -07002099 pw.println("mSrvccState=" + mSrvccState[i]);
2100 pw.println("mOtaspMode=" + mOtaspMode[i]);
2101 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause[i]);
2102 pw.println("mCallQuality=" + mCallQuality[i]);
2103 pw.println("mCallAttributes=" + mCallAttributes[i]);
2104 pw.println("mCallNetworkType=" + mCallNetworkType[i]);
2105 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState[i]);
Shuo Qian134334b2019-09-12 17:00:31 -07002106 pw.println("mOutgoingCallEmergencyNumber=" + mOutgoingCallEmergencyNumber[i]);
2107 pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07002108 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05302109 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002110 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
chen xud5deeb12019-04-29 13:57:42 -07002111
Malcolm Chene1623652018-08-08 20:27:45 -07002112 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen026451d2019-02-14 19:50:19 -08002113 pw.println("mActiveDataSubId=" + mActiveDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00002114 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian9f93a122018-12-03 22:40:41 -08002115 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
chen xuaddc2702019-05-07 16:25:12 -07002116 pw.println("mDefaultPhoneId=" + mDefaultPhoneId);
2117 pw.println("mDefaultSubId=" + mDefaultSubId);
Jack Yud19b6ae2017-04-05 14:12:09 -07002118
2119 pw.decreaseIndent();
2120
2121 pw.println("local logs:");
2122 pw.increaseIndent();
2123 mLocalLog.dump(fd, pw, args);
Jack Yu0c92c232019-04-04 15:10:17 -07002124 pw.println("listen logs:");
2125 mListenLog.dump(fd, pw, args);
Jack Yud19b6ae2017-04-05 14:12:09 -07002126 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07002127 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07002128 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07002129 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07002130 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 }
Jack Yud19b6ae2017-04-05 14:12:09 -07002132 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 }
2134 }
2135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 //
2137 // the legacy intent broadcasting
2138 //
2139
Meng Wang4c18a3a2019-12-09 17:00:01 -08002140 // Legacy intent action.
2141 /** Fired when a subscription's phone state changes. */
2142 private static final String ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED =
2143 "android.intent.action.SUBSCRIPTION_PHONE_STATE";
2144
2145 // Legacy intent extra keys, copied from PhoneConstants.
2146 // Used in legacy intents sent here, for backward compatibility.
2147 private static final String PHONE_CONSTANTS_SLOT_KEY = "slot";
2148 private static final String PHONE_CONSTANTS_SUBSCRIPTION_KEY = "subscription";
2149
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002150 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07002151 long ident = Binder.clearCallingIdentity();
2152 try {
2153 mBatteryStats.notePhoneState(state.getState());
2154 } catch (RemoteException re) {
2155 // Can't do much
2156 } finally {
2157 Binder.restoreCallingIdentity(ident);
2158 }
2159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08002161 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 Bundle data = new Bundle();
2163 state.fillInNotifierBundle(data);
2164 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07002165 // Pass the subscription along with the intent.
Meng Wang4c18a3a2019-12-09 17:00:01 -08002166 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002167 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002168 intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId);
2169 intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002170 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 }
2172
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002173 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
2174 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002175 long ident = Binder.clearCallingIdentity();
2176 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07002177 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002178 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002179 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07002180 } finally {
2181 Binder.restoreCallingIdentity(ident);
2182 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07002185 Bundle data = new Bundle();
2186 signalStrength.fillInNotifierBundle(data);
2187 intent.putExtras(data);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002188 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
2189 intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002190 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 }
2192
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002193 /**
2194 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
2195 * a valid subId, in which case this function fires a subId-specific intent, or it
2196 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
2197 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
2198 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002199 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
2200 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 long ident = Binder.clearCallingIdentity();
2202 try {
2203 if (state == TelephonyManager.CALL_STATE_IDLE) {
2204 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07002205 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2206 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 } else {
2208 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07002209 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
2210 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 }
2212 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07002213 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 } finally {
2215 Binder.restoreCallingIdentity(ident);
2216 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Meng Wang762281b2019-12-06 10:37:58 -08002219 intent.putExtra(TelephonyManager.EXTRA_STATE, callStateToString(state));
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002220
2221 // If a valid subId was specified, we should fire off a subId-specific state
2222 // change intent and include the subId.
2223 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
Meng Wang4c18a3a2019-12-09 17:00:01 -08002224 intent.setAction(ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
2225 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07002226 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002227 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002228 // If the phoneId is invalid, the broadcast is for overall call state.
2229 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
Meng Wang4c18a3a2019-12-09 17:00:01 -08002230 intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId);
2231 intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07002232 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07002233
Brad Ebinger51de96a2017-04-21 17:05:18 -07002234 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
2235 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
2236
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002237 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07002238 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07002239 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
2240
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002241 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
2242 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07002243 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002244 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002245 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07002246 android.Manifest.permission.READ_PHONE_STATE,
2247 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07002248 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
2249 new String[] { android.Manifest.permission.READ_PHONE_STATE,
2250 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 }
2252
Meng Wang762281b2019-12-06 10:37:58 -08002253 /** Converts TelephonyManager#CALL_STATE_* to TelephonyManager#EXTRA_STATE_*. */
2254 private static String callStateToString(int callState) {
2255 switch (callState) {
2256 case TelephonyManager.CALL_STATE_RINGING:
2257 return TelephonyManager.EXTRA_STATE_RINGING;
2258 case TelephonyManager.CALL_STATE_OFFHOOK:
2259 return TelephonyManager.EXTRA_STATE_OFFHOOK;
2260 default:
2261 return TelephonyManager.EXTRA_STATE_IDLE;
2262 }
2263 }
2264
Jack Yu4d1c9452019-01-02 16:51:08 -08002265 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
2266 String apnType, LinkProperties linkProperties,
2267 NetworkCapabilities networkCapabilities,
2268 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07002269 // Note: not reporting to the battery stats service here, because the
2270 // status bar takes care of that after taking into account all of the
2271 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002272 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Meng Wang762281b2019-12-06 10:37:58 -08002273 intent.putExtra(TelephonyManager.EXTRA_STATE, dataStateToString(state));
Jack Yubaeec622017-05-01 17:01:11 -07002274 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07002275 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07002277 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002278 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07002279 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002280 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07002281 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07002282 }
2283 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002284 if (networkCapabilities != null) {
2285 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002286 }
Wink Savillea639b312012-07-10 12:37:54 -07002287 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002288
Wink Savillea639b312012-07-10 12:37:54 -07002289 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2290 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002291 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002292 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 }
2294
Jack Yu4d1c9452019-01-02 16:51:08 -08002295 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002297 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Meng Wang4c18a3a2019-12-09 17:00:01 -08002298 intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002299 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002301
Andrew Flynnceaed682015-06-09 12:36:58 +00002302 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002303 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002304 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002305 }
2306
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002307 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2308 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002309 }
2310
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002311 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002312 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002313 return true;
2314 }
2315 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002316 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002317 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002318 return false;
2319 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002320
Andrew Flynn1f452642015-04-14 22:16:04 -04002321 private boolean checkNotifyPermission() {
2322 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2323 == PackageManager.PERMISSION_GRANTED;
2324 }
2325
Philip P. Moltmann33692f72019-10-03 11:56:11 -07002326 private boolean checkListenerPermission(int events, int subId, String callingPackage,
2327 @Nullable String callingFeatureId, String message) {
Hall Liuee313732018-11-27 14:36:51 -08002328 LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
2329 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2330 .setCallingPackage(callingPackage)
2331 .setMethod(message + " events: " + events)
2332 .setCallingPid(Binder.getCallingPid())
2333 .setCallingUid(Binder.getCallingUid());
2334
2335 boolean shouldCheckLocationPermissions = false;
Hall Liu70bbc162018-03-02 17:44:46 -08002336 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Hall Liuee313732018-11-27 14:36:51 -08002337 locationQueryBuilder.setMinSdkVersionForCoarse(0);
2338 shouldCheckLocationPermissions = true;
2339 }
2340
2341 if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
2342 // Everything that requires fine location started in Q. So far...
2343 locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
2344 shouldCheckLocationPermissions = true;
2345 }
2346
2347 if (shouldCheckLocationPermissions) {
2348 LocationAccessPolicy.LocationPermissionResult result =
2349 LocationAccessPolicy.checkLocationPermission(
2350 mContext, locationQueryBuilder.build());
2351 switch (result) {
2352 case DENIED_HARD:
2353 throw new SecurityException("Unable to listen for events " + events + " due to "
2354 + "insufficient location permissions.");
2355 case DENIED_SOFT:
2356 return false;
Hall Liu70bbc162018-03-02 17:44:46 -08002357 }
John Wang963db55d2012-03-30 16:04:06 -07002358 }
2359
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002360 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann33692f72019-10-03 11:56:11 -07002362 mContext, subId, callingPackage, callingFeatureId, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002363 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002364 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002365 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002366
2367 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2368 mContext.enforceCallingOrSelfPermission(
2369 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002370 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002371
Shuo Qian134334b2019-09-12 17:00:31 -07002372 if ((events & READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK) != 0) {
2373 mContext.enforceCallingOrSelfPermission(
2374 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2375 }
2376
Shuo Qian066e8652018-04-25 21:02:35 +00002377 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2378 mContext.enforceCallingOrSelfPermission(
2379 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2380 }
2381
Brad Ebingerefed9822018-10-26 10:25:57 -07002382 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2383 mContext.enforceCallingOrSelfPermission(
2384 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2385 }
2386
chen xu6a942d482018-12-12 19:59:30 -08002387 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2388 mContext.enforceCallingOrSelfPermission(
2389 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2390 }
2391
Jordan Liu8218ddd2018-11-28 11:22:39 -08002392 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2393 mContext.enforceCallingOrSelfPermission(
2394 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2395 }
2396
chen xu52797b62019-01-18 13:16:31 -08002397 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2398 mContext.enforceCallingOrSelfPermission(
2399 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2400 }
2401
2402 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2403 mContext.enforceCallingOrSelfPermission(
2404 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2405 }
2406
chen xu6ac5fc12019-01-24 14:14:13 -08002407 if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
2408 mContext.enforceCallingOrSelfPermission(
2409 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2410 }
2411
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002412 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002413 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002414
2415 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002416 int size = mRemoveList.size();
2417 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2418 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002419 for (IBinder b: mRemoveList) {
2420 remove(b);
2421 }
2422 mRemoveList.clear();
2423 }
2424 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002425
2426 private boolean validateEventsAndUserLocked(Record r, int events) {
2427 int foregroundUser;
2428 long callingIdentity = Binder.clearCallingIdentity();
2429 boolean valid = false;
2430 try {
2431 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002432 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2433 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002434 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002435 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002436 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002437 + " r.events=" + r.events + " events=" + events);
2438 }
2439 } finally {
2440 Binder.restoreCallingIdentity(callingIdentity);
2441 }
2442 return valid;
2443 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002444
2445 private boolean validatePhoneId(int phoneId) {
2446 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002447 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002448 return valid;
2449 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002450
2451 private static void log(String s) {
2452 Rlog.d(TAG, s);
2453 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002454
chen xu627d1b22019-04-11 02:16:19 -07002455 private static void loge(String s) {
2456 Rlog.e(TAG, s);
2457 }
2458
xinhe8b79fb62014-11-05 14:55:03 -08002459 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002460
2461 if(subId < 0) {
2462 // Invalid case, we need compare phoneId with default one.
2463 return (mDefaultPhoneId == phoneId);
2464 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002465 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002466 return (subId == mDefaultSubId);
2467 } else {
2468 return (rSubId == subId);
2469 }
2470 }
2471
Hall Liuee313732018-11-27 14:36:51 -08002472 private boolean checkFineLocationAccess(Record r, int minSdk) {
2473 LocationAccessPolicy.LocationPermissionQuery query =
2474 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2475 .setCallingPackage(r.callingPackage)
2476 .setCallingPid(r.callerPid)
2477 .setCallingUid(r.callerUid)
2478 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002479 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002480 .setMinSdkVersionForFine(minSdk)
2481 .build();
2482
2483 return Binder.withCleanCallingIdentity(() -> {
2484 LocationAccessPolicy.LocationPermissionResult locationResult =
2485 LocationAccessPolicy.checkLocationPermission(mContext, query);
2486 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2487 });
2488 }
2489
2490 private boolean checkCoarseLocationAccess(Record r, int minSdk) {
2491 LocationAccessPolicy.LocationPermissionQuery query =
2492 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2493 .setCallingPackage(r.callingPackage)
2494 .setCallingPid(r.callerPid)
2495 .setCallingUid(r.callerUid)
2496 .setMethod("TelephonyRegistry push")
Hall Liu879024a2019-04-17 13:33:43 -07002497 .setLogAsInfo(true) // we don't need to log an error every time we push
Hall Liuee313732018-11-27 14:36:51 -08002498 .setMinSdkVersionForCoarse(minSdk)
2499 .build();
2500
2501 return Binder.withCleanCallingIdentity(() -> {
2502 LocationAccessPolicy.LocationPermissionResult locationResult =
2503 LocationAccessPolicy.checkLocationPermission(mContext, query);
2504 return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
2505 });
Hall Liu5fb337f2017-11-22 17:38:15 -08002506 }
2507
xinhee9f16402014-09-25 16:39:28 -07002508 private void checkPossibleMissNotify(Record r, int phoneId) {
2509 int events = r.events;
2510
2511 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2512 try {
2513 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2514 mServiceState[phoneId]);
2515 r.callback.onServiceStateChanged(
2516 new ServiceState(mServiceState[phoneId]));
2517 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002518 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002519 }
2520 }
2521
2522 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2523 try {
2524 SignalStrength signalStrength = mSignalStrength[phoneId];
2525 if (DBG) {
2526 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2527 }
2528 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2529 } catch (RemoteException ex) {
2530 mRemoveList.add(r.binder);
2531 }
2532 }
2533
2534 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2535 try {
2536 int gsmSignalStrength = mSignalStrength[phoneId]
2537 .getGsmSignalStrength();
2538 if (DBG) {
2539 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2540 gsmSignalStrength);
2541 }
2542 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2543 : gsmSignalStrength));
2544 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002545 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002546 }
2547 }
2548
2549 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2550 try {
2551 if (DBG_LOC) {
2552 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2553 + mCellInfo.get(phoneId));
2554 }
Hall Liuee313732018-11-27 14:36:51 -08002555 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002556 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2557 }
xinhee9f16402014-09-25 16:39:28 -07002558 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002559 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002560 }
2561 }
2562
zxuan35a47022018-01-04 11:24:04 -08002563 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2564 try {
2565 if (VDBG) {
2566 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2567 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2568 }
2569 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2570 } catch (RemoteException ex) {
2571 mRemoveList.add(r.binder);
2572 }
2573 }
2574
xinhee9f16402014-09-25 16:39:28 -07002575 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2576 try {
2577 if (VDBG) {
2578 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2579 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2580 }
2581 r.callback.onMessageWaitingIndicatorChanged(
2582 mMessageWaiting[phoneId]);
2583 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002584 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002585 }
2586 }
2587
2588 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2589 try {
2590 if (VDBG) {
2591 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2592 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2593 }
2594 r.callback.onCallForwardingIndicatorChanged(
2595 mCallForwarding[phoneId]);
2596 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002597 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002598 }
2599 }
2600
2601 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2602 try {
2603 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2604 + mCellLocation[phoneId]);
Hall Liuee313732018-11-27 14:36:51 -08002605 if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
Hall Liu5fb337f2017-11-22 17:38:15 -08002606 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2607 }
xinhee9f16402014-09-25 16:39:28 -07002608 } catch (RemoteException ex) {
2609 mRemoveList.add(r.binder);
2610 }
2611 }
2612
2613 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2614 try {
2615 if (DBG) {
2616 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2617 + "=" + mDataConnectionState[phoneId]
2618 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2619 + ")");
2620 }
2621 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2622 mDataConnectionNetworkType[phoneId]);
2623 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002624 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002625 }
2626 }
2627 }
zoey chenc722b452019-12-03 17:23:22 +08002628
2629 /**
Meng Wang762281b2019-12-06 10:37:58 -08002630 * Convert TelephonyManager.DATA_* to string.
zoey chenc722b452019-12-03 17:23:22 +08002631 *
2632 * @return The data state in string format.
2633 */
Meng Wang762281b2019-12-06 10:37:58 -08002634 private static String dataStateToString(int state) {
zoey chenc722b452019-12-03 17:23:22 +08002635 switch (state) {
2636 case TelephonyManager.DATA_DISCONNECTED: return "DISCONNECTED";
2637 case TelephonyManager.DATA_CONNECTING: return "CONNECTING";
2638 case TelephonyManager.DATA_CONNECTED: return "CONNECTED";
2639 case TelephonyManager.DATA_SUSPENDED: return "SUSPENDED";
2640 }
2641 return "UNKNOWN(" + state + ")";
2642 }
2643
2644 /**
2645 * Returns a string representation of the radio technology (network type)
2646 * currently in use on the device.
2647 * @param subId for which network type is returned
2648 * @return the name of the radio technology
2649 *
2650 */
2651 private String getNetworkTypeName(@Annotation.NetworkType int type) {
2652 switch (type) {
2653 case TelephonyManager.NETWORK_TYPE_GPRS:
2654 return "GPRS";
2655 case TelephonyManager.NETWORK_TYPE_EDGE:
2656 return "EDGE";
2657 case TelephonyManager.NETWORK_TYPE_UMTS:
2658 return "UMTS";
2659 case TelephonyManager.NETWORK_TYPE_HSDPA:
2660 return "HSDPA";
2661 case TelephonyManager.NETWORK_TYPE_HSUPA:
2662 return "HSUPA";
2663 case TelephonyManager.NETWORK_TYPE_HSPA:
2664 return "HSPA";
2665 case TelephonyManager.NETWORK_TYPE_CDMA:
2666 return "CDMA";
2667 case TelephonyManager.NETWORK_TYPE_EVDO_0:
2668 return "CDMA - EvDo rev. 0";
2669 case TelephonyManager.NETWORK_TYPE_EVDO_A:
2670 return "CDMA - EvDo rev. A";
2671 case TelephonyManager.NETWORK_TYPE_EVDO_B:
2672 return "CDMA - EvDo rev. B";
2673 case TelephonyManager.NETWORK_TYPE_1xRTT:
2674 return "CDMA - 1xRTT";
2675 case TelephonyManager.NETWORK_TYPE_LTE:
2676 return "LTE";
2677 case TelephonyManager.NETWORK_TYPE_EHRPD:
2678 return "CDMA - eHRPD";
2679 case TelephonyManager.NETWORK_TYPE_IDEN:
2680 return "iDEN";
2681 case TelephonyManager.NETWORK_TYPE_HSPAP:
2682 return "HSPA+";
2683 case TelephonyManager.NETWORK_TYPE_GSM:
2684 return "GSM";
2685 case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
2686 return "TD_SCDMA";
2687 case TelephonyManager.NETWORK_TYPE_IWLAN:
2688 return "IWLAN";
2689 case TelephonyManager.NETWORK_TYPE_LTE_CA:
2690 return "LTE_CA";
2691 case TelephonyManager.NETWORK_TYPE_NR:
2692 return "NR";
2693 default:
2694 return "UNKNOWN";
2695 }
2696 }
Meng Wangbe15dba2019-12-10 10:54:50 -08002697
2698 /** Returns a new CallQuality object with default values. */
2699 private static CallQuality createCallQuality() {
2700 return new CallQuality(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702}