blob: cbfcd6035d5eb902e6656697b09f23dd63890f21 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
Jordan Liu8218ddd2018-11-28 11:22:39 -080035import android.telephony.CallAttributes;
36import android.telephony.CallQuality;
John Wang963db55d2012-03-30 16:04:06 -070037import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070038import android.telephony.CellLocation;
chen xu896e3d42018-12-11 18:09:41 -080039import android.telephony.DataFailCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020040import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080041import android.telephony.LocationAccessPolicy;
Malcolm Chen5ee5c142018-08-08 20:27:45 -070042import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070043import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080044import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020045import android.telephony.PreciseCallState;
46import android.telephony.PreciseDataConnectionState;
47import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070048import android.telephony.Rlog;
49import android.telephony.ServiceState;
50import android.telephony.SignalStrength;
51import android.telephony.SubscriptionManager;
52import android.telephony.TelephonyManager;
chen xu896e3d42018-12-11 18:09:41 -080053import android.telephony.data.ApnSetting;
sqianbf165bc2018-12-07 17:09:39 -080054import android.telephony.emergency.EmergencyNumber;
Jack Yud19b6ae2017-04-05 14:12:09 -070055import android.util.LocalLog;
Yangster4ccebea2018-10-09 17:09:02 -070056import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Malcolm Chen800a7d62018-08-27 20:38:29 -070058import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080060import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070062import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080063import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070064import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080066import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060067import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070068import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import com.android.server.am.BatteryStatsService;
70
Jack Yud19b6ae2017-04-05 14:12:09 -070071import java.io.FileDescriptor;
72import java.io.PrintWriter;
73import java.util.ArrayList;
sqian46c0c302018-12-27 14:12:11 -080074import java.util.HashMap;
Jack Yud19b6ae2017-04-05 14:12:09 -070075import java.util.List;
sqian46c0c302018-12-27 14:12:11 -080076import java.util.Map;
Malcolm Chenabbfac22018-02-12 19:15:59 -080077import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079/**
Wink Savillee9b06d72009-05-18 21:47:50 -070080 * Since phone process can be restarted, this class provides a centralized place
81 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070082 *
83 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
84 * and 15973975 by saving the phoneId of the registrant and then using the
85 * phoneId when deciding to to make a callback. This is necessary because
86 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070087 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070088 * the dummy value conversion we properly do the callbacks.
89 *
90 * Eventually we may want to remove the notion of dummy value but for now this
91 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 */
Malcolm Chen800a7d62018-08-27 20:38:29 -070093@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
94public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070096 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070097 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070098 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099
100 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800101 Context context;
102
Svet Ganov16a16892015-04-16 10:32:04 -0700103 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -0700104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
Malcolm Chenabbfac22018-02-12 19:15:59 -0800107 TelephonyRegistryDeathRecipient deathRecipient;
108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800110 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen27829e22018-09-04 22:12:31 -0700111 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700112
Hall Liu5fb337f2017-11-22 17:38:15 -0800113 int callerUid;
114 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700117
Wink Savilled09c4ca2014-11-22 10:08:16 -0800118 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700119
Wink Savilled09c4ca2014-11-22 10:08:16 -0800120 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800121
122 boolean matchPhoneStateListenerEvent(int events) {
123 return (callback != null) && ((events & this.events) != 0);
124 }
125
Wink Savilled09c4ca2014-11-22 10:08:16 -0800126 boolean matchOnSubscriptionsChangedListener() {
127 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800128 }
Wink Savillee380b982014-07-26 18:24:22 -0700129
Malcolm Chen27829e22018-09-04 22:12:31 -0700130 boolean matchOnOpportunisticSubscriptionsChangedListener() {
131 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
132 }
133
Tyler Gunnf955e562018-04-26 14:43:31 -0700134 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800135 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700136 return TelephonyPermissions.checkReadCallLog(
137 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800138 } catch (SecurityException e) {
139 return false;
140 }
141 }
142
Wink Savillea12a7b32012-09-20 10:09:45 -0700143 @Override
144 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700145 return "{callingPackage=" + callingPackage + " binder=" + binder
146 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800147 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen27829e22018-09-04 22:12:31 -0700148 + onSubscriptionsChangedListenerCallback
149 + " onOpportunisticSubscriptionsChangedListenererCallback="
150 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800151 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800152 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 }
155
156 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Joe Onorato163d8d92010-10-21 13:21:20 -0400158 // access should be inside synchronized (mRecords) for these two fields
159 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
160 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 private final IBatteryStats mBatteryStats;
163
Svet Ganov16a16892015-04-16 10:32:04 -0700164 private final AppOpsManager mAppOps;
165
Malcolm Chen27829e22018-09-04 22:12:31 -0700166 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
167
168 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700175
Wink Savillefb40dd42014-06-12 17:02:31 -0700176 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700177
Jordan Liu8218ddd2018-11-28 11:22:39 -0800178 private int[] mNetworkType;
179
fionaxu12312f62016-11-14 13:32:14 -0800180 private int[] mVoiceActivationState;
181
182 private int[] mDataActivationState;
183
zxuan35a47022018-01-04 11:24:04 -0800184 private boolean[] mUserMobileDataState;
185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700189
Wink Savillefb40dd42014-06-12 17:02:31 -0700190 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700191
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700193
Jack Yub1bac542018-03-14 16:23:38 -0700194 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700196
Wink Savillefb40dd42014-06-12 17:02:31 -0700197 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700200
Nathan Harold016e9c62016-12-14 11:24:48 -0800201 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700202
Wink Savillefb40dd42014-06-12 17:02:31 -0700203 private ArrayList<List<CellInfo>> mCellInfo = null;
204
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800205 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
206
sqian46c0c302018-12-27 14:12:11 -0800207 private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList;
208
Jordan Liueae57b22019-01-22 16:17:35 -0800209 private CallQuality mCallQuality = new CallQuality();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800210
Jordan Liueae57b22019-01-22 16:17:35 -0800211 private CallAttributes mCallAttributes = new CallAttributes(new PreciseCallState(),
212 TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality());
Jordan Liu8218ddd2018-11-28 11:22:39 -0800213
Brad Ebingerefed9822018-10-26 10:25:57 -0700214 private int[] mSrvccState;
Wink Savillefb40dd42014-06-12 17:02:31 -0700215
Wink Savilled09c4ca2014-11-22 10:08:16 -0800216 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700217
Wink Savilled09c4ca2014-11-22 10:08:16 -0800218 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700219
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200220 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
221
222 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
223
224 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
225
226 private PreciseCallState mPreciseCallState = new PreciseCallState();
227
chen xu970d7792018-12-12 19:59:30 -0800228 private int mCallDisconnectCause = DisconnectCause.NOT_VALID;
229
230 private int mCallPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
231
Andrew Flynn1f452642015-04-14 22:16:04 -0400232 private boolean mCarrierNetworkChangeState = false;
233
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700234 private PhoneCapability mPhoneCapability = null;
235
chen xu760729c2018-10-11 13:18:26 -0700236 @TelephonyManager.RadioPowerState
237 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
238
Malcolm Chenc1873af2018-09-24 20:01:32 -0700239 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
240
Jack Yud19b6ae2017-04-05 14:12:09 -0700241 private final LocalLog mLocalLog = new LocalLog(100);
242
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200243 private PreciseDataConnectionState mPreciseDataConnectionState =
244 new PreciseDataConnectionState();
245
Hall Liu70bbc162018-03-02 17:44:46 -0800246 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
247 PhoneStateListener.LISTEN_CELL_LOCATION
248 | PhoneStateListener.LISTEN_CELL_INFO;
249
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700250 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
sqian46c0c302018-12-27 14:12:11 -0800251 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
252 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
253 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700254
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200255 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
256 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
257 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
258
Wink Savillea12a7b32012-09-20 10:09:45 -0700259 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700260 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700261
262 private final Handler mHandler = new Handler() {
263 @Override
264 public void handleMessage(Message msg) {
265 switch (msg.what) {
266 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700267 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700268 int numPhones = TelephonyManager.getDefault().getPhoneCount();
269 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700270 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700271 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700272 }
273 break;
274 }
xinhee9f16402014-09-25 16:39:28 -0700275 case MSG_UPDATE_DEFAULT_SUB: {
276 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700277 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700278 if (VDBG) {
279 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
280 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
281 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
282 }
283
284 //Due to possible risk condition,(notify call back using the new
285 //defaultSubId comes before new defaultSubId update) we need to recall all
286 //possible missed notify callback
287 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700288 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800289 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700290 checkPossibleMissNotify(r, newDefaultPhoneId);
291 }
292 }
293 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700294 }
295 mDefaultSubId = newDefaultSubId;
296 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700297 }
298 }
299 }
300 };
301
Malcolm Chenabbfac22018-02-12 19:15:59 -0800302 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
303
304 private final IBinder binder;
305
306 TelephonyRegistryDeathRecipient(IBinder binder) {
307 this.binder = binder;
308 }
309
310 @Override
311 public void binderDied() {
312 if (DBG) log("binderDied " + binder);
313 remove(binder);
314 }
315 }
316
Wink Savillea12a7b32012-09-20 10:09:45 -0700317 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
318 @Override
319 public void onReceive(Context context, Intent intent) {
320 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700321 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700322 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700323 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700324 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700325 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700326 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700327 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800328 PhoneConstants.SUBSCRIPTION_KEY,
329 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700330 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
331 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700332 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700333 log("onReceive:current mDefaultSubId=" + mDefaultSubId
334 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
335 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700336 }
xinhee9f16402014-09-25 16:39:28 -0700337
Junda Liu985f52c2015-02-23 16:06:51 -0800338 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700339 || (newDefaultPhoneId != mDefaultPhoneId))) {
340 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
341 newDefaultPhoneId, 0, newDefaultSubIdObj));
342 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700343 }
344 }
345 };
346
Wink Savillee9b06d72009-05-18 21:47:50 -0700347 // we keep a copy of all of the state so we can send it out when folks
348 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700350 // In these calls we call with the lock held. This is safe becasuse remote
351 // calls go through a oneway interface and local calls going through a
352 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353
Malcolm Chen800a7d62018-08-27 20:38:29 -0700354 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
355 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700356 CellLocation location = CellLocation.getEmpty();
357
Wink Savillefb40dd42014-06-12 17:02:31 -0700358 mContext = context;
359 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700360
Wink Savillefb40dd42014-06-12 17:02:31 -0700361 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700362 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700363 mNumPhones = numPhones;
364 mCallState = new int[numPhones];
365 mDataActivity = new int[numPhones];
366 mDataConnectionState = new int[numPhones];
367 mDataConnectionNetworkType = new int[numPhones];
368 mCallIncomingNumber = new String[numPhones];
369 mServiceState = new ServiceState[numPhones];
Jordan Liu8218ddd2018-11-28 11:22:39 -0800370 mNetworkType = new int[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800371 mVoiceActivationState = new int[numPhones];
372 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800373 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700374 mSignalStrength = new SignalStrength[numPhones];
375 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700376 mCallForwarding = new boolean[numPhones];
377 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700378 mCellInfo = new ArrayList<List<CellInfo>>();
Brad Ebingerefed9822018-10-26 10:25:57 -0700379 mSrvccState = new int[numPhones];
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800380 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
sqian46c0c302018-12-27 14:12:11 -0800381 mEmergencyNumberList = new HashMap<>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700382 for (int i = 0; i < numPhones; i++) {
383 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
384 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
385 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800386 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
387 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700388 mCallIncomingNumber[i] = "";
389 mServiceState[i] = new ServiceState();
Jordan Liu8218ddd2018-11-28 11:22:39 -0800390 mNetworkType[i] = mServiceState[i].getVoiceNetworkType();
Wink Savillefb40dd42014-06-12 17:02:31 -0700391 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800392 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700393 mMessageWaiting[i] = false;
394 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700395 mCellLocation[i] = new Bundle();
396 mCellInfo.add(i, null);
Brad Ebingerefed9822018-10-26 10:25:57 -0700397 mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE;
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700398 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700399 }
400
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700401 // Note that location can be null for non-phone builds like
402 // like the generic one.
403 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700404 for (int i = 0; i < numPhones; i++) {
405 location.fillInNotifierBundle(mCellLocation[i]);
406 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700407 }
Svet Ganov16a16892015-04-16 10:32:04 -0700408
409 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 }
411
Svetoslav Ganova0027152013-06-25 14:59:53 -0700412 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700413 // Watch for interesting updates
414 final IntentFilter filter = new IntentFilter();
415 filter.addAction(Intent.ACTION_USER_SWITCHED);
416 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700417 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700418 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700419 mContext.registerReceiver(mBroadcastReceiver, filter);
420 }
421
422 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700423 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800424 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700425 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800427 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700428 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
429 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800430 + " callback.asBinder=" + callback.asBinder());
431 }
432
Wink Savilled09c4ca2014-11-22 10:08:16 -0800433 synchronized (mRecords) {
434 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800435 IBinder b = callback.asBinder();
436 Record r = add(b);
437
438 if (r == null) {
439 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800440 }
441
Jeff Davidson29da89f2018-02-28 17:50:16 -0800442 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800443 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700444 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800445 r.callerUid = Binder.getCallingUid();
446 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800447 r.events = 0;
448 if (DBG) {
449 log("listen oscl: Register r=" + r);
450 }
451 // Always notify when registration occurs if there has been a notification.
Malcolm Chen27829e22018-09-04 22:12:31 -0700452 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800453 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800454 if (VDBG) log("listen oscl: send to r=" + r);
455 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
456 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800457 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800458 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800459 remove(r.binder);
460 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800461 } else {
Malcolm Chen27829e22018-09-04 22:12:31 -0700462 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800463 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800464 }
465 }
466
467 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800468 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800469 IOnSubscriptionsChangedListener callback) {
470 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800471 remove(callback.asBinder());
472 }
473
Malcolm Chen27829e22018-09-04 22:12:31 -0700474
475 @Override
476 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
477 IOnSubscriptionsChangedListener callback) {
478 int callerUserId = UserHandle.getCallingUserId();
479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
480 if (VDBG) {
481 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
482 + " callerUserId=" + callerUserId + " callback=" + callback
483 + " callback.asBinder=" + callback.asBinder());
484 }
485
486 synchronized (mRecords) {
487 // register
488 IBinder b = callback.asBinder();
489 Record r = add(b);
490
491 if (r == null) {
492 return;
493 }
494
495 r.context = mContext;
496 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
497 r.callingPackage = callingPackage;
498 r.callerUid = Binder.getCallingUid();
499 r.callerPid = Binder.getCallingPid();
500 r.events = 0;
501 if (DBG) {
502 log("listen ooscl: Register r=" + r);
503 }
504 // Always notify when registration occurs if there has been a notification.
505 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
506 try {
507 if (VDBG) log("listen ooscl: send to r=" + r);
508 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
509 if (VDBG) log("listen ooscl: sent to r=" + r);
510 } catch (RemoteException e) {
511 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
512 remove(r.binder);
513 }
514 } else {
515 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
516 }
517 }
518 }
519
Wink Savillea374c3d2014-11-11 11:48:04 -0800520 @Override
521 public void notifySubscriptionInfoChanged() {
522 if (VDBG) log("notifySubscriptionInfoChanged:");
523 synchronized (mRecords) {
Malcolm Chen27829e22018-09-04 22:12:31 -0700524 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800525 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
526 + mRecords.size());
527 }
Malcolm Chen27829e22018-09-04 22:12:31 -0700528 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800529 mRemoveList.clear();
530 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800531 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800532 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800533 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
534 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
535 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800536 } catch (RemoteException ex) {
537 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
538 mRemoveList.add(r.binder);
539 }
540 }
541 }
542 handleRemoveListLocked();
543 }
544 }
545
546 @Override
Malcolm Chen27829e22018-09-04 22:12:31 -0700547 public void notifyOpportunisticSubscriptionInfoChanged() {
548 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
549 synchronized (mRecords) {
550 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
551 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
552 + mRecords.size());
553 }
554 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
555 mRemoveList.clear();
556 for (Record r : mRecords) {
557 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
558 try {
559 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
560 r.onOpportunisticSubscriptionsChangedListenerCallback
561 .onSubscriptionsChanged();
562 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
563 } catch (RemoteException ex) {
564 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
565 mRemoveList.add(r.binder);
566 }
567 }
568 }
569 handleRemoveListLocked();
570 }
571 }
572
573 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
575 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800576 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
577 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700578 }
579
580 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700581 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700583 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700584 }
585
Svet Ganov16a16892015-04-16 10:32:04 -0700586 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700587 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700588 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700590 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700591 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700592 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
593 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700594 }
xinhe75c2c152014-10-16 11:49:45 -0700595
596 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800597 // Checks permission and throws SecurityException for disallowed operations. For pre-M
598 // apps whose runtime permission has been revoked, we return immediately to skip sending
599 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800600 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800601 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700602 }
603
yifan.baie620ce72017-12-22 14:59:57 +0800604 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 synchronized (mRecords) {
606 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800607 IBinder b = callback.asBinder();
608 Record r = add(b);
609
610 if (r == null) {
611 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
xinhe43c50292014-09-18 17:56:48 -0700613
Jeff Davidson29da89f2018-02-28 17:50:16 -0800614 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700615 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700616 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800617 r.callerUid = Binder.getCallingUid();
618 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700619 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
620 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800622 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700623 } else {//APP specify subID
624 r.subId = subId;
625 }
yifan.baie620ce72017-12-22 14:59:57 +0800626 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700628 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700629 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700630 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700631 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400633 try {
Wink Savillee380b982014-07-26 18:24:22 -0700634 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700635 r.callback.onServiceStateChanged(
636 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400637 } catch (RemoteException ex) {
638 remove(r.binder);
639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 }
641 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
642 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700643 int gsmSignalStrength = mSignalStrength[phoneId]
644 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700645 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
646 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 } catch (RemoteException ex) {
648 remove(r.binder);
649 }
650 }
651 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
652 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700653 r.callback.onMessageWaitingIndicatorChanged(
654 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 } catch (RemoteException ex) {
656 remove(r.binder);
657 }
658 }
659 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
660 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700661 r.callback.onCallForwardingIndicatorChanged(
662 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 } catch (RemoteException ex) {
664 remove(r.binder);
665 }
666 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700667 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400668 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700669 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700670 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800671 if (checkLocationAccess(r)) {
672 r.callback.onCellLocationChanged(
673 new Bundle(mCellLocation[phoneId]));
674 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400675 } catch (RemoteException ex) {
676 remove(r.binder);
677 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 }
679 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
680 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700681 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700682 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 } catch (RemoteException ex) {
684 remove(r.binder);
685 }
686 }
687 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
688 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700689 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
690 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 } catch (RemoteException ex) {
692 remove(r.binder);
693 }
694 }
695 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
696 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700697 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 } catch (RemoteException ex) {
699 remove(r.binder);
700 }
701 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700702 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
703 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700704 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700705 } catch (RemoteException ex) {
706 remove(r.binder);
707 }
708 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700709 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
710 try {
711 r.callback.onOtaspChanged(mOtaspMode);
712 } catch (RemoteException ex) {
713 remove(r.binder);
714 }
715 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700716 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700717 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700718 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700719 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800720 if (checkLocationAccess(r)) {
721 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
722 }
John Wang963db55d2012-03-30 16:04:06 -0700723 } catch (RemoteException ex) {
724 remove(r.binder);
725 }
726 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200727 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
728 try {
729 r.callback.onPreciseCallStateChanged(mPreciseCallState);
730 } catch (RemoteException ex) {
731 remove(r.binder);
732 }
733 }
chen xu970d7792018-12-12 19:59:30 -0800734 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
735 try {
736 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
737 mCallPreciseDisconnectCause);
738 } catch (RemoteException ex) {
739 remove(r.binder);
740 }
741 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200742 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
743 try {
744 r.callback.onPreciseDataConnectionStateChanged(
745 mPreciseDataConnectionState);
746 } catch (RemoteException ex) {
747 remove(r.binder);
748 }
749 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400750 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
751 try {
752 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
753 } catch (RemoteException ex) {
754 remove(r.binder);
755 }
756 }
fionaxu12312f62016-11-14 13:32:14 -0800757 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
758 try {
759 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
760 } catch (RemoteException ex) {
761 remove(r.binder);
762 }
763 }
764 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
765 try {
766 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
767 } catch (RemoteException ex) {
768 remove(r.binder);
769 }
770 }
zxuan35a47022018-01-04 11:24:04 -0800771 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
772 try {
773 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
774 } catch (RemoteException ex) {
775 remove(r.binder);
776 }
777 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800778 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
779 try {
780 r.callback.onPhysicalChannelConfigurationChanged(
781 mPhysicalChannelConfigs.get(phoneId));
782 } catch (RemoteException ex) {
783 remove(r.binder);
784 }
785 }
sqian46c0c302018-12-27 14:12:11 -0800786 if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
787 try {
788 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
789 } catch (RemoteException ex) {
790 remove(r.binder);
791 }
792 }
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700793 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
794 try {
795 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
796 } catch (RemoteException ex) {
797 remove(r.binder);
798 }
799 }
Malcolm Chenc1873af2018-09-24 20:01:32 -0700800 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
801 try {
802 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
803 } catch (RemoteException ex) {
804 remove(r.binder);
805 }
806 }
chen xu760729c2018-10-11 13:18:26 -0700807 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
808 try {
809 r.callback.onRadioPowerStateChanged(mRadioPowerState);
810 } catch (RemoteException ex) {
811 remove(r.binder);
812 }
813 }
Brad Ebingerefed9822018-10-26 10:25:57 -0700814 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
815 try {
816 r.callback.onSrvccStateChanged(mSrvccState[phoneId]);
817 } catch (RemoteException ex) {
818 remove(r.binder);
819 }
820 }
Jordan Liu8218ddd2018-11-28 11:22:39 -0800821 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
822 try {
823 r.callback.onCallAttributesChanged(mCallAttributes);
824 } catch (RemoteException ex) {
825 remove(r.binder);
826 }
827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 }
829 }
830 } else {
xinhe75c2c152014-10-16 11:49:45 -0700831 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 remove(callback.asBinder());
833 }
834 }
835
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700836 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700837 // Only reveal the incoming number if the record has read call log permission.
838 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700839 }
840
Malcolm Chenabbfac22018-02-12 19:15:59 -0800841 private Record add(IBinder binder) {
842 Record r;
843
844 synchronized (mRecords) {
845 final int N = mRecords.size();
846 for (int i = 0; i < N; i++) {
847 r = mRecords.get(i);
848 if (binder == r.binder) {
849 // Already existed.
850 return r;
851 }
852 }
853 r = new Record();
854 r.binder = binder;
855 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
856
857 try {
858 binder.linkToDeath(r.deathRecipient, 0);
859 } catch (RemoteException e) {
860 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
861 // Binder already died. Return null.
862 return null;
863 }
864
865 mRecords.add(r);
866 if (DBG) log("add new record");
867 }
868
869 return r;
870 }
871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 private void remove(IBinder binder) {
873 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700874 final int recordCount = mRecords.size();
875 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800876 Record r = mRecords.get(i);
877 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800878 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800879 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
880 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800881 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800882
883 if (r.deathRecipient != null) {
884 try {
885 binder.unlinkToDeath(r.deathRecipient, 0);
886 } catch (NoSuchElementException e) {
887 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
888 + r + " e=" + e);
889 }
890 }
891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 mRecords.remove(i);
893 return;
894 }
895 }
896 }
897 }
898
Tyler Gunnf955e562018-04-26 14:43:31 -0700899 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700900 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700901 return;
902 }
xinhe43c50292014-09-18 17:56:48 -0700903
904 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700905 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700906 }
907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700909 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800910 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800911 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700913 // Ensure the listener has read call log permission; if they do not return
914 // an empty phone number.
915 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
916 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400918 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 }
920 }
921 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400922 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700924
925 // Called only by Telecomm to communicate call state across different phone accounts. So
926 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700927 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700928 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700929 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
931
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700932 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
933 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700934 if (!checkNotifyPermission("notifyCallState()")) {
935 return;
936 }
Wink Savillee380b982014-07-26 18:24:22 -0700937 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700938 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700939 + " state=" + state + " incomingNumber=" + incomingNumber);
940 }
941 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700942 if (validatePhoneId(phoneId)) {
943 mCallState[phoneId] = state;
944 mCallIncomingNumber[phoneId] = incomingNumber;
945 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800946 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700947 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800948 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700949 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700950 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
951 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700952 } catch (RemoteException ex) {
953 mRemoveList.add(r.binder);
954 }
955 }
956 }
957 }
958 handleRemoveListLocked();
959 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700960 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700961 }
962
Wink Saville63f03dd2014-10-23 10:44:45 -0700963 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700964 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700965 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700966 }
xinhe43c50292014-09-18 17:56:48 -0700967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700969 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
970 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700971 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700972 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700973 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700974 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700975 if (validatePhoneId(phoneId)) {
976 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700977
Jordan Liu8218ddd2018-11-28 11:22:39 -0800978 boolean notifyCallAttributes = true;
979 if (mNetworkType[phoneId] != mServiceState[phoneId].getVoiceNetworkType()) {
980 mNetworkType[phoneId] = state.getVoiceNetworkType();
981 mCallAttributes = new CallAttributes(mPreciseCallState, mNetworkType[phoneId],
982 mCallQuality);
983 } else {
984 // No change to network type, so no need to notify call attributes
985 notifyCallAttributes = false;
986 }
987
988 if (mCallQuality == null) {
989 // No call quality reported yet, so no need to notify call attributes
990 notifyCallAttributes = false;
991 }
992
Wink Savillefb40dd42014-06-12 17:02:31 -0700993 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700994 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700995 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700996 + " phoneId=" + phoneId + " state=" + state);
997 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800998 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800999 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001000 try {
Wink Savillee380b982014-07-26 18:24:22 -07001001 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001002 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -07001003 + " subId=" + subId + " phoneId=" + phoneId
1004 + " state=" + state);
1005 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001006 r.callback.onServiceStateChanged(new ServiceState(state));
1007 } catch (RemoteException ex) {
1008 mRemoveList.add(r.binder);
1009 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001010 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001011 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1012 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1013 try {
1014 r.callback.onCallAttributesChanged(mCallAttributes);
1015 } catch (RemoteException ex) {
1016 mRemoveList.add(r.binder);
1017 }
1018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001020 } else {
Wink Savillebc027272014-09-08 14:50:58 -07001021 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001023 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001025 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 }
1027
fionaxu12312f62016-11-14 13:32:14 -08001028 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
1029 int activationType, int activationState) {
1030 if (!checkNotifyPermission("notifySimActivationState()")){
1031 return;
1032 }
1033 if (VDBG) {
1034 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
1035 + "type=" + activationType + " state=" + activationState);
1036 }
1037 synchronized (mRecords) {
1038 if (validatePhoneId(phoneId)) {
1039 switch (activationType) {
1040 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
1041 mVoiceActivationState[phoneId] = activationState;
1042 break;
1043 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
1044 mDataActivationState[phoneId] = activationState;
1045 break;
1046 default:
1047 return;
1048 }
1049 for (Record r : mRecords) {
1050 if (VDBG) {
1051 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
1052 + " phoneId=" + phoneId + "type=" + activationType
1053 + " state=" + activationState);
1054 }
1055 try {
1056 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
1057 r.matchPhoneStateListenerEvent(
1058 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
1059 idMatch(r.subId, subId, phoneId)) {
1060 if (DBG) {
1061 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
1062 + " subId=" + subId + " phoneId=" + phoneId
1063 + " state=" + activationState);
1064 }
1065 r.callback.onVoiceActivationStateChanged(activationState);
1066 }
1067 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
1068 r.matchPhoneStateListenerEvent(
1069 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
1070 idMatch(r.subId, subId, phoneId)) {
1071 if (DBG) {
1072 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
1073 + " subId=" + subId + " phoneId=" + phoneId
1074 + " state=" + activationState);
1075 }
1076 r.callback.onDataActivationStateChanged(activationState);
1077 }
1078 } catch (RemoteException ex) {
1079 mRemoveList.add(r.binder);
1080 }
1081 }
1082 } else {
1083 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1084 }
1085 handleRemoveListLocked();
1086 }
1087 }
1088
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001089 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1090 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001091 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001092 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001093 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001094 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001095 log("notifySignalStrengthForPhoneId: subId=" + subId
1096 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001097 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001100 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001101 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001102 mSignalStrength[phoneId] = signalStrength;
1103 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001104 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001105 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001106 + " phoneId=" + phoneId + " ss=" + signalStrength);
1107 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001108 if (r.matchPhoneStateListenerEvent(
1109 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001110 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001111 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001112 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001113 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001114 + " subId=" + subId + " phoneId=" + phoneId
1115 + " ss=" + signalStrength);
1116 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001117 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1118 } catch (RemoteException ex) {
1119 mRemoveList.add(r.binder);
1120 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001121 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001122 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001123 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001124 try {
1125 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001126 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001127 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001128 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001129 + " subId=" + subId + " phoneId=" + phoneId
1130 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1131 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001132 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001133 } catch (RemoteException ex) {
1134 mRemoveList.add(r.binder);
1135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 }
1137 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001138 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001139 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001141 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001143 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 }
1145
Andrew Flynn1f452642015-04-14 22:16:04 -04001146 @Override
1147 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001148 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1149
Andrew Flynn1f452642015-04-14 22:16:04 -04001150 if (VDBG) {
1151 log("notifyCarrierNetworkChange: active=" + active);
1152 }
1153
1154 synchronized (mRecords) {
1155 mCarrierNetworkChangeState = active;
1156 for (Record r : mRecords) {
1157 if (r.matchPhoneStateListenerEvent(
1158 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1159 try {
1160 r.callback.onCarrierNetworkChange(active);
1161 } catch (RemoteException ex) {
1162 mRemoveList.add(r.binder);
1163 }
1164 }
1165 }
1166 handleRemoveListLocked();
1167 }
1168 }
1169
Wink Savilleb208a242012-07-25 14:08:09 -07001170 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001171 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001172 }
1173
Wink Saville63f03dd2014-10-23 10:44:45 -07001174 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001175 if (!checkNotifyPermission("notifyCellInfo()")) {
1176 return;
1177 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001178 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001179 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001180 + " cellInfo=" + cellInfo);
1181 }
yifan.baie620ce72017-12-22 14:59:57 +08001182 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001183 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 if (validatePhoneId(phoneId)) {
1185 mCellInfo.set(phoneId, cellInfo);
1186 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001187 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001188 idMatch(r.subId, subId, phoneId) &&
1189 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001190 try {
1191 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001192 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001193 }
1194 r.callback.onCellInfoChanged(cellInfo);
1195 } catch (RemoteException ex) {
1196 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001197 }
John Wang963db55d2012-03-30 16:04:06 -07001198 }
1199 }
1200 }
1201 handleRemoveListLocked();
1202 }
1203 }
1204
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001205 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1206 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1207 configs);
1208 }
1209
1210 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1211 List<PhysicalChannelConfig> configs) {
1212 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1213 return;
1214 }
1215
1216 if (VDBG) {
1217 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1218 }
1219
1220 synchronized (mRecords) {
1221 int phoneId = SubscriptionManager.getPhoneId(subId);
1222 if (validatePhoneId(phoneId)) {
1223 mPhysicalChannelConfigs.set(phoneId, configs);
1224 for (Record r : mRecords) {
1225 if (r.matchPhoneStateListenerEvent(
1226 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1227 && idMatch(r.subId, subId, phoneId)) {
1228 try {
1229 if (DBG_LOC) {
1230 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1231 + configs + " r=" + r);
1232 }
1233 r.callback.onPhysicalChannelConfigurationChanged(configs);
1234 } catch (RemoteException ex) {
1235 mRemoveList.add(r.binder);
1236 }
1237 }
1238 }
1239 }
1240 handleRemoveListLocked();
1241 }
1242 }
1243
xinhe43c50292014-09-18 17:56:48 -07001244 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001245 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001246 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001247 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001248 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001249 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001250 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001251 + " mwi=" + mwi);
1252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001254 if (validatePhoneId(phoneId)) {
1255 mMessageWaiting[phoneId] = mwi;
1256 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001257 if (r.matchPhoneStateListenerEvent(
1258 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001259 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001260 try {
1261 r.callback.onMessageWaitingIndicatorChanged(mwi);
1262 } catch (RemoteException ex) {
1263 mRemoveList.add(r.binder);
1264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 }
1266 }
1267 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001268 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 }
1270 }
1271
zxuan35a47022018-01-04 11:24:04 -08001272 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1273 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1274 return;
1275 }
1276 if (VDBG) {
1277 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1278 + " state=" + state);
1279 }
1280 synchronized (mRecords) {
1281 if (validatePhoneId(phoneId)) {
1282 mMessageWaiting[phoneId] = state;
1283 for (Record r : mRecords) {
1284 if (r.matchPhoneStateListenerEvent(
1285 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1286 idMatch(r.subId, subId, phoneId)) {
1287 try {
1288 r.callback.onUserMobileDataStateChanged(state);
1289 } catch (RemoteException ex) {
1290 mRemoveList.add(r.binder);
1291 }
1292 }
1293 }
1294 }
1295 handleRemoveListLocked();
1296 }
1297 }
1298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001300 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001301 }
1302
Wink Saville63f03dd2014-10-23 10:44:45 -07001303 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001304 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001305 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001306 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001307 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001308 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001309 + " cfi=" + cfi);
1310 }
yifan.baie620ce72017-12-22 14:59:57 +08001311 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001313 if (validatePhoneId(phoneId)) {
1314 mCallForwarding[phoneId] = cfi;
1315 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001316 if (r.matchPhoneStateListenerEvent(
1317 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001318 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001319 try {
1320 r.callback.onCallForwardingIndicatorChanged(cfi);
1321 } catch (RemoteException ex) {
1322 mRemoveList.add(r.binder);
1323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 }
1325 }
1326 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001327 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 }
1329 }
1330
1331 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001332 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001333 }
1334
Wink Saville63f03dd2014-10-23 10:44:45 -07001335 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001336 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001337 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001338 }
yifan.baie620ce72017-12-22 14:59:57 +08001339 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001341 if (validatePhoneId(phoneId)) {
1342 mDataActivity[phoneId] = state;
1343 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001344 // Notify by correct subId.
1345 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1346 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001347 try {
1348 r.callback.onDataActivity(state);
1349 } catch (RemoteException ex) {
1350 mRemoveList.add(r.binder);
1351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 }
1353 }
1354 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001355 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 }
1357 }
1358
Jack Yuf05919a2019-01-02 16:51:08 -08001359 public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType,
1360 LinkProperties linkProperties,
1361 NetworkCapabilities networkCapabilities, int networkType,
1362 boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001363 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yuf05919a2019-01-02 16:51:08 -08001364 isDataAllowed, apn, apnType, linkProperties,
1365 networkCapabilities, networkType, roaming);
Wink Savillefb40dd42014-06-12 17:02:31 -07001366 }
1367
Jack Yuf05919a2019-01-02 16:51:08 -08001368 public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataAllowed,
1369 String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001370 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1371 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001372 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001373 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001374 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001375 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001376 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001377 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillea12a7b32012-09-20 10:09:45 -07001378 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001379 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001380 }
yifan.baie620ce72017-12-22 14:59:57 +08001381 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001383 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001384 // We only call the callback when the change is for default APN type.
1385 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1386 && (mDataConnectionState[phoneId] != state
1387 || mDataConnectionNetworkType[phoneId] != networkType)) {
1388 String str = "onDataConnectionStateChanged(" + state
1389 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001390 log(str);
1391 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001392 for (Record r : mRecords) {
1393 if (r.matchPhoneStateListenerEvent(
1394 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1395 idMatch(r.subId, subId, phoneId)) {
1396 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001397 if (DBG) {
1398 log("Notify data connection state changed on sub: " + subId);
1399 }
Jack Yub1bac542018-03-14 16:23:38 -07001400 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001401 } catch (RemoteException ex) {
1402 mRemoveList.add(r.binder);
1403 }
1404 }
1405 }
1406 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001407
1408 mDataConnectionState[phoneId] = state;
1409 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001410 }
1411 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
chen xu896e3d42018-12-11 18:09:41 -08001412 ApnSetting.getApnTypesBitmaskFromString(apnType), apn,
1413 linkProperties, DataFailCause.NONE);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001414 for (Record r : mRecords) {
1415 if (r.matchPhoneStateListenerEvent(
1416 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1417 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001418 r.callback.onPreciseDataConnectionStateChanged(
1419 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001420 } catch (RemoteException ex) {
1421 mRemoveList.add(r.binder);
1422 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001423 }
1424 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001425 }
1426 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 }
Jack Yuf05919a2019-01-02 16:51:08 -08001428 broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties,
1429 networkCapabilities, roaming, subId);
1430 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn,
chen xu896e3d42018-12-11 18:09:41 -08001431 linkProperties, DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 }
1433
Jack Yuf05919a2019-01-02 16:51:08 -08001434 public void notifyDataConnectionFailed(String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001435 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
Jack Yuf05919a2019-01-02 16:51:08 -08001436 apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001437 }
1438
Jack Yuf05919a2019-01-02 16:51:08 -08001439 public void notifyDataConnectionFailedForSubscriber(int subId, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001440 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001441 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001442 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001443 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001444 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Jack Yuf05919a2019-01-02 16:51:08 -08001445 + " apnType=" + apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001448 mPreciseDataConnectionState = new PreciseDataConnectionState(
1449 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001450 ApnSetting.getApnTypesBitmaskFromString(apnType), "", null,
1451 DataFailCause.NONE);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001452 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001453 if (r.matchPhoneStateListenerEvent(
1454 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001455 try {
1456 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1457 } catch (RemoteException ex) {
1458 mRemoveList.add(r.binder);
1459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 }
1461 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001462 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 }
Jack Yuf05919a2019-01-02 16:51:08 -08001464 broadcastDataConnectionFailed(apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001465 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001466 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", null,
1467 DataFailCause.NONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 }
1469
1470 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001471 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001472 }
1473
Wink Saville63f03dd2014-10-23 10:44:45 -07001474 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001475 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001476 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001477 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001478 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001479 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001480 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001481 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001482 + " cellLocation=" + cellLocation);
1483 }
yifan.baie620ce72017-12-22 14:59:57 +08001484 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001486 if (validatePhoneId(phoneId)) {
1487 mCellLocation[phoneId] = cellLocation;
1488 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001489 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001490 idMatch(r.subId, subId, phoneId) &&
1491 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001492 try {
1493 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001494 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001495 + " r=" + r);
1496 }
1497 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1498 } catch (RemoteException ex) {
1499 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001500 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 }
1503 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001504 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001505 }
1506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507
Wink Savillefd2d0132010-10-28 14:22:26 -07001508 public void notifyOtaspChanged(int otaspMode) {
1509 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1510 return;
1511 }
1512 synchronized (mRecords) {
1513 mOtaspMode = otaspMode;
1514 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001515 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001516 try {
1517 r.callback.onOtaspChanged(otaspMode);
1518 } catch (RemoteException ex) {
1519 mRemoveList.add(r.binder);
1520 }
1521 }
1522 }
1523 handleRemoveListLocked();
1524 }
1525 }
1526
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001527 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
Jordan Liu8218ddd2018-11-28 11:22:39 -08001528 int backgroundCallState, int phoneId) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001529 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1530 return;
1531 }
1532 synchronized (mRecords) {
1533 mRingingCallState = ringingCallState;
1534 mForegroundCallState = foregroundCallState;
1535 mBackgroundCallState = backgroundCallState;
1536 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1537 backgroundCallState,
1538 DisconnectCause.NOT_VALID,
1539 PreciseDisconnectCause.NOT_VALID);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001540 boolean notifyCallAttributes = true;
1541 if (mCallQuality == null) {
1542 log("notifyPreciseCallState: mCallQuality is null, skipping call attributes");
1543 notifyCallAttributes = false;
1544 } else {
1545 mCallAttributes = new CallAttributes(mPreciseCallState, mNetworkType[phoneId],
1546 mCallQuality);
1547 }
1548
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001549 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001550 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001551 try {
1552 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1553 } catch (RemoteException ex) {
1554 mRemoveList.add(r.binder);
1555 }
1556 }
Jordan Liu8218ddd2018-11-28 11:22:39 -08001557 if (notifyCallAttributes && r.matchPhoneStateListenerEvent(
1558 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1559 try {
1560 r.callback.onCallAttributesChanged(mCallAttributes);
1561 } catch (RemoteException ex) {
1562 mRemoveList.add(r.binder);
1563 }
1564 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001565 }
1566 handleRemoveListLocked();
1567 }
chen xu970d7792018-12-12 19:59:30 -08001568 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState,
1569 backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001570 }
1571
1572 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1573 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1574 return;
1575 }
1576 synchronized (mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001577 mCallDisconnectCause = disconnectCause;
1578 mCallPreciseDisconnectCause = preciseDisconnectCause;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001579 for (Record r : mRecords) {
chen xu970d7792018-12-12 19:59:30 -08001580 if (r.matchPhoneStateListenerEvent(PhoneStateListener
1581 .LISTEN_CALL_DISCONNECT_CAUSES)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001582 try {
chen xu970d7792018-12-12 19:59:30 -08001583 r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause,
1584 mCallPreciseDisconnectCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001585 } catch (RemoteException ex) {
1586 mRemoveList.add(r.binder);
1587 }
1588 }
1589 }
1590 handleRemoveListLocked();
1591 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001592 }
1593
chen xu896e3d42018-12-11 18:09:41 -08001594 public void notifyPreciseDataConnectionFailed(String apnType,
1595 String apn, @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001596 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1597 return;
1598 }
1599 synchronized (mRecords) {
1600 mPreciseDataConnectionState = new PreciseDataConnectionState(
1601 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
chen xu896e3d42018-12-11 18:09:41 -08001602 ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001603 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001604 if (r.matchPhoneStateListenerEvent(
1605 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001606 try {
1607 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1608 } catch (RemoteException ex) {
1609 mRemoveList.add(r.binder);
1610 }
1611 }
1612 }
1613 handleRemoveListLocked();
1614 }
1615 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
Jack Yuf05919a2019-01-02 16:51:08 -08001616 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, null, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001617 }
1618
Brad Ebingerefed9822018-10-26 10:25:57 -07001619 @Override
1620 public void notifySrvccStateChanged(int subId, @TelephonyManager.SrvccState int state) {
1621 if (!checkNotifyPermission("notifySrvccStateChanged()")) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001622 return;
1623 }
Brad Ebingerefed9822018-10-26 10:25:57 -07001624 if (VDBG) {
1625 log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state);
1626 }
1627 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001628 synchronized (mRecords) {
Brad Ebingerefed9822018-10-26 10:25:57 -07001629 if (validatePhoneId(phoneId)) {
1630 mSrvccState[phoneId] = state;
1631 for (Record r : mRecords) {
1632 if (r.matchPhoneStateListenerEvent(
1633 PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) &&
1634 idMatch(r.subId, subId, phoneId)) {
1635 try {
1636 if (DBG_LOC) {
1637 log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r);
1638 }
1639 r.callback.onSrvccStateChanged(state);
1640 } catch (RemoteException ex) {
1641 mRemoveList.add(r.binder);
1642 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001643 }
1644 }
1645 }
1646 handleRemoveListLocked();
1647 }
1648 }
1649
Shuo Qian066e8652018-04-25 21:02:35 +00001650 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1651 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1652 return;
1653 }
1654
1655 synchronized (mRecords) {
1656 for (Record r : mRecords) {
1657 if (VDBG) {
1658 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1659 }
1660 if ((r.matchPhoneStateListenerEvent(
1661 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1662 ((r.subId == subId) ||
1663 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1664 try {
1665 r.callback.onOemHookRawEvent(rawData);
1666 } catch (RemoteException ex) {
1667 mRemoveList.add(r.binder);
1668 }
1669 }
1670 }
1671 handleRemoveListLocked();
1672 }
1673 }
1674
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001675 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1676 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1677 return;
1678 }
1679
1680 if (VDBG) {
1681 log("notifyPhoneCapabilityChanged: capability=" + capability);
1682 }
1683
1684 synchronized (mRecords) {
1685 mPhoneCapability = capability;
1686
1687 for (Record r : mRecords) {
1688 if (r.matchPhoneStateListenerEvent(
1689 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1690 try {
1691 r.callback.onPhoneCapabilityChanged(capability);
1692 } catch (RemoteException ex) {
1693 mRemoveList.add(r.binder);
1694 }
1695 }
1696 }
1697 handleRemoveListLocked();
1698 }
1699 }
1700
Malcolm Chenc1873af2018-09-24 20:01:32 -07001701 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1702 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1703 return;
1704 }
1705
1706 if (VDBG) {
1707 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1708 }
1709
1710 synchronized (mRecords) {
1711 mPreferredDataSubId = preferredSubId;
1712
1713 for (Record r : mRecords) {
1714 if (r.matchPhoneStateListenerEvent(
1715 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1716 try {
1717 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1718 } catch (RemoteException ex) {
1719 mRemoveList.add(r.binder);
1720 }
1721 }
1722 }
1723 handleRemoveListLocked();
1724 }
1725 }
1726
chen xu760729c2018-10-11 13:18:26 -07001727 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1728 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1729 return;
1730 }
1731
1732 if (VDBG) {
1733 log("notifyRadioPowerStateChanged: state= " + state);
1734 }
1735
1736 synchronized (mRecords) {
1737 mRadioPowerState = state;
1738
1739 for (Record r : mRecords) {
1740 if (r.matchPhoneStateListenerEvent(
1741 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1742 try {
1743 r.callback.onRadioPowerStateChanged(state);
1744 } catch (RemoteException ex) {
1745 mRemoveList.add(r.binder);
1746 }
1747 }
1748 }
1749 handleRemoveListLocked();
1750 }
1751 }
1752
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 @Override
sqian46c0c302018-12-27 14:12:11 -08001755 public void notifyEmergencyNumberList() {
1756 if (!checkNotifyPermission("notifyEmergencyNumberList()")) {
1757 return;
1758 }
1759
1760 synchronized (mRecords) {
sqian3e8647c2018-12-14 21:47:49 -08001761 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1762 Context.TELEPHONY_SERVICE);
1763 mEmergencyNumberList = tm.getCurrentEmergencyNumberList();
sqian46c0c302018-12-27 14:12:11 -08001764
1765 for (Record r : mRecords) {
1766 if (r.matchPhoneStateListenerEvent(
1767 PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST)) {
1768 try {
1769 r.callback.onEmergencyNumberListChanged(mEmergencyNumberList);
1770 if (VDBG) {
1771 log("notifyEmergencyNumberList: emergencyNumberList= "
1772 + mEmergencyNumberList);
1773 }
1774 } catch (RemoteException ex) {
1775 mRemoveList.add(r.binder);
1776 }
1777 }
1778 }
1779 handleRemoveListLocked();
1780 }
sqianbf165bc2018-12-07 17:09:39 -08001781 }
1782
Jordan Liu8218ddd2018-11-28 11:22:39 -08001783 @Override
1784 public void notifyCallQualityChanged(CallQuality callQuality, int phoneId) {
1785 if (!checkNotifyPermission("notifyCallQualityChanged()")) {
1786 return;
1787 }
1788
1789 // merge CallQuality with PreciseCallState and network type
1790 mCallQuality = callQuality;
1791 mCallAttributes = new CallAttributes(mPreciseCallState,
1792 mNetworkType[phoneId],
1793 callQuality);
1794
1795 synchronized (mRecords) {
1796 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1797 Context.TELEPHONY_SERVICE);
1798
1799 for (Record r : mRecords) {
1800 if (r.matchPhoneStateListenerEvent(
1801 PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED)) {
1802 try {
1803 r.callback.onCallAttributesChanged(mCallAttributes);
1804 } catch (RemoteException ex) {
1805 mRemoveList.add(r.binder);
1806 }
1807 }
1808 }
1809 handleRemoveListLocked();
1810 }
1811 }
1812
sqianbf165bc2018-12-07 17:09:39 -08001813
1814 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001815 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1816 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1817
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001818 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001821 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001823 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301824 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001825 pw.println("Phone Id=" + i);
1826 pw.increaseIndent();
1827 pw.println("mCallState=" + mCallState[i]);
1828 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1829 pw.println("mServiceState=" + mServiceState[i]);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001830 pw.println("mNetworkType=" + mNetworkType[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001831 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1832 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001833 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001834 pw.println("mSignalStrength=" + mSignalStrength[i]);
1835 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1836 pw.println("mCallForwarding=" + mCallForwarding[i]);
1837 pw.println("mDataActivity=" + mDataActivity[i]);
1838 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001839 pw.println("mCellLocation=" + mCellLocation[i]);
1840 pw.println("mCellInfo=" + mCellInfo.get(i));
1841 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301842 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001843 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1844 pw.println("mPreciseCallState=" + mPreciseCallState);
chen xu970d7792018-12-12 19:59:30 -08001845 pw.println("mCallDisconnectCause=" + mCallDisconnectCause);
1846 pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause);
Jack Yud19b6ae2017-04-05 14:12:09 -07001847 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1848 pw.println("mRingingCallState=" + mRingingCallState);
1849 pw.println("mForegroundCallState=" + mForegroundCallState);
1850 pw.println("mBackgroundCallState=" + mBackgroundCallState);
Brad Ebingerefed9822018-10-26 10:25:57 -07001851 pw.println("mSrvccState=" + mSrvccState);
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001852 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chenc1873af2018-09-24 20:01:32 -07001853 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
chen xu760729c2018-10-11 13:18:26 -07001854 pw.println("mRadioPowerState=" + mRadioPowerState);
sqian46c0c302018-12-27 14:12:11 -08001855 pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
Jordan Liu8218ddd2018-11-28 11:22:39 -08001856 pw.println("mCallQuality=" + mCallQuality);
1857 pw.println("mCallAttributes=" + mCallAttributes);
Jack Yud19b6ae2017-04-05 14:12:09 -07001858
1859 pw.decreaseIndent();
1860
1861 pw.println("local logs:");
1862 pw.increaseIndent();
1863 mLocalLog.dump(fd, pw, args);
1864 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001865 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001866 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001867 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001868 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001870 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 }
1872 }
1873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 //
1875 // the legacy intent broadcasting
1876 //
1877
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001878 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001879 long ident = Binder.clearCallingIdentity();
1880 try {
1881 mBatteryStats.notePhoneState(state.getState());
1882 } catch (RemoteException re) {
1883 // Can't do much
1884 } finally {
1885 Binder.restoreCallingIdentity(ident);
1886 }
1887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001889 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 Bundle data = new Bundle();
1891 state.fillInNotifierBundle(data);
1892 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001893 // Pass the subscription along with the intent.
1894 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001895 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001896 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001897 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 }
1899
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001900 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1901 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001902 long ident = Binder.clearCallingIdentity();
1903 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001904 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001905 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001906 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001907 } finally {
1908 Binder.restoreCallingIdentity(ident);
1909 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001912 Bundle data = new Bundle();
1913 signalStrength.fillInNotifierBundle(data);
1914 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001915 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001916 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001917 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 }
1919
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001920 /**
1921 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1922 * a valid subId, in which case this function fires a subId-specific intent, or it
1923 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1924 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1925 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001926 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1927 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 long ident = Binder.clearCallingIdentity();
1929 try {
1930 if (state == TelephonyManager.CALL_STATE_IDLE) {
1931 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001932 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1933 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 } else {
1935 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001936 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1937 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 }
1939 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001940 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 } finally {
1942 Binder.restoreCallingIdentity(ident);
1943 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001946 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001947 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001948
1949 // If a valid subId was specified, we should fire off a subId-specific state
1950 // change intent and include the subId.
1951 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1952 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1953 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001954 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001955 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001956 // If the phoneId is invalid, the broadcast is for overall call state.
1957 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1958 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1959 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001960
Brad Ebinger51de96a2017-04-21 17:05:18 -07001961 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1962 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1963
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001964 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001965 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001966 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1967
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001968 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1969 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001970 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001971 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001972 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001973 android.Manifest.permission.READ_PHONE_STATE,
1974 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001975 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1976 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1977 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 }
1979
Jack Yuf05919a2019-01-02 16:51:08 -08001980 private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn,
1981 String apnType, LinkProperties linkProperties,
1982 NetworkCapabilities networkCapabilities,
1983 boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001984 // Note: not reporting to the battery stats service here, because the
1985 // status bar takes care of that after taking into account all of the
1986 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001988 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001989 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001990 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001991 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001993 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001994 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001995 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001996 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001997 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001998 }
1999 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07002000 if (networkCapabilities != null) {
2001 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07002002 }
Wink Savillea639b312012-07-10 12:37:54 -07002003 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07002004
Wink Savillea639b312012-07-10 12:37:54 -07002005 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
2006 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002007 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002008 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 }
2010
Jack Yuf05919a2019-01-02 16:51:08 -08002011 private void broadcastDataConnectionFailed(String apnType, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07002013 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07002014 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002015 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002016 }
Wink Savillee9b06d72009-05-18 21:47:50 -07002017
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002018 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
Jack Yuf05919a2019-01-02 16:51:08 -08002019 int backgroundCallState) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002020 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
2021 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
2022 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
2023 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002024 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2025 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2026 }
2027
2028 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
chen xu896e3d42018-12-11 18:09:41 -08002029 String apnType, String apn, LinkProperties linkProperties,
2030 @DataFailCause.FailCause int failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002031 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
2032 intent.putExtra(PhoneConstants.STATE_KEY, state);
2033 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002034 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
2035 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002036 if (linkProperties != null) {
Jack Yuf05919a2019-01-02 16:51:08 -08002037 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002038 }
chen xu896e3d42018-12-11 18:09:41 -08002039 intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002040
2041 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
2042 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
2043 }
2044
Andrew Flynnceaed682015-06-09 12:36:58 +00002045 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002046 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00002047 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04002048 }
2049
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002050 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2051 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04002052 }
2053
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002054 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04002055 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002056 return true;
2057 }
2058 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07002059 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07002060 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07002061 return false;
2062 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002063
Andrew Flynn1f452642015-04-14 22:16:04 -04002064 private boolean checkNotifyPermission() {
2065 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2066 == PackageManager.PERMISSION_GRANTED;
2067 }
2068
Jeff Davidson29da89f2018-02-28 17:50:16 -08002069 private boolean checkListenerPermission(
2070 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08002071 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002072 mContext.enforceCallingOrSelfPermission(
2073 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08002074 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
2075 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2076 return false;
2077 }
John Wang963db55d2012-03-30 16:04:06 -07002078 }
2079
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07002080 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08002081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2082 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002083 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07002084 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002085 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002086
2087 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
2088 mContext.enforceCallingOrSelfPermission(
2089 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02002090 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002091
Shuo Qian066e8652018-04-25 21:02:35 +00002092 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
2093 mContext.enforceCallingOrSelfPermission(
2094 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2095 }
2096
Brad Ebingerefed9822018-10-26 10:25:57 -07002097 if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
2098 mContext.enforceCallingOrSelfPermission(
2099 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2100 }
2101
Malcolm Chend4dc4ee2018-12-11 13:56:53 -08002102 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
2103 // It can have either READ_PHONE_STATE or READ_PRIVILEGED_PHONE_STATE.
2104 TelephonyPermissions.checkReadPhoneState(mContext,
2105 SubscriptionManager.INVALID_SUBSCRIPTION_ID, Binder.getCallingPid(),
2106 Binder.getCallingUid(), callingPackage, "listen to "
2107 + "LISTEN_PREFERRED_DATA_SUBID_CHANGE");
2108 }
Brad Ebingerefed9822018-10-26 10:25:57 -07002109
chen xu970d7792018-12-12 19:59:30 -08002110 if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
2111 mContext.enforceCallingOrSelfPermission(
2112 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2113 }
2114
Jordan Liu8218ddd2018-11-28 11:22:39 -08002115 if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
2116 mContext.enforceCallingOrSelfPermission(
2117 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
2118 }
2119
chen xu52797b62019-01-18 13:16:31 -08002120 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
2121 mContext.enforceCallingOrSelfPermission(
2122 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2123 }
2124
2125 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
2126 mContext.enforceCallingOrSelfPermission(
2127 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
2128 }
2129
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08002130 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07002131 }
Joe Onorato163d8d92010-10-21 13:21:20 -04002132
2133 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08002134 int size = mRemoveList.size();
2135 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
2136 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04002137 for (IBinder b: mRemoveList) {
2138 remove(b);
2139 }
2140 mRemoveList.clear();
2141 }
2142 }
Wink Savillea12a7b32012-09-20 10:09:45 -07002143
2144 private boolean validateEventsAndUserLocked(Record r, int events) {
2145 int foregroundUser;
2146 long callingIdentity = Binder.clearCallingIdentity();
2147 boolean valid = false;
2148 try {
2149 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08002150 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
2151 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07002152 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07002153 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08002154 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07002155 + " r.events=" + r.events + " events=" + events);
2156 }
2157 } finally {
2158 Binder.restoreCallingIdentity(callingIdentity);
2159 }
2160 return valid;
2161 }
Wink Savillefb40dd42014-06-12 17:02:31 -07002162
2163 private boolean validatePhoneId(int phoneId) {
2164 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07002165 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07002166 return valid;
2167 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07002168
2169 private static void log(String s) {
2170 Rlog.d(TAG, s);
2171 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07002172
xinhe8b79fb62014-11-05 14:55:03 -08002173 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08002174
2175 if(subId < 0) {
2176 // Invalid case, we need compare phoneId with default one.
2177 return (mDefaultPhoneId == phoneId);
2178 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08002179 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07002180 return (subId == mDefaultSubId);
2181 } else {
2182 return (rSubId == subId);
2183 }
2184 }
2185
Hall Liu5fb337f2017-11-22 17:38:15 -08002186 private boolean checkLocationAccess(Record r) {
2187 long token = Binder.clearCallingIdentity();
2188 try {
2189 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08002190 r.callingPackage, r.callerUid, r.callerPid,
2191 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08002192 } finally {
2193 Binder.restoreCallingIdentity(token);
2194 }
2195 }
2196
xinhee9f16402014-09-25 16:39:28 -07002197 private void checkPossibleMissNotify(Record r, int phoneId) {
2198 int events = r.events;
2199
2200 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2201 try {
2202 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2203 mServiceState[phoneId]);
2204 r.callback.onServiceStateChanged(
2205 new ServiceState(mServiceState[phoneId]));
2206 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002207 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002208 }
2209 }
2210
2211 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2212 try {
2213 SignalStrength signalStrength = mSignalStrength[phoneId];
2214 if (DBG) {
2215 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2216 }
2217 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2218 } catch (RemoteException ex) {
2219 mRemoveList.add(r.binder);
2220 }
2221 }
2222
2223 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2224 try {
2225 int gsmSignalStrength = mSignalStrength[phoneId]
2226 .getGsmSignalStrength();
2227 if (DBG) {
2228 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2229 gsmSignalStrength);
2230 }
2231 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2232 : gsmSignalStrength));
2233 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002234 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002235 }
2236 }
2237
2238 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2239 try {
2240 if (DBG_LOC) {
2241 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2242 + mCellInfo.get(phoneId));
2243 }
Hall Liu5fb337f2017-11-22 17:38:15 -08002244 if (checkLocationAccess(r)) {
2245 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2246 }
xinhee9f16402014-09-25 16:39:28 -07002247 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002248 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002249 }
2250 }
2251
zxuan35a47022018-01-04 11:24:04 -08002252 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2253 try {
2254 if (VDBG) {
2255 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2256 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2257 }
2258 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2259 } catch (RemoteException ex) {
2260 mRemoveList.add(r.binder);
2261 }
2262 }
2263
xinhee9f16402014-09-25 16:39:28 -07002264 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2265 try {
2266 if (VDBG) {
2267 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2268 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2269 }
2270 r.callback.onMessageWaitingIndicatorChanged(
2271 mMessageWaiting[phoneId]);
2272 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002273 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002274 }
2275 }
2276
2277 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2278 try {
2279 if (VDBG) {
2280 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2281 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2282 }
2283 r.callback.onCallForwardingIndicatorChanged(
2284 mCallForwarding[phoneId]);
2285 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002286 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002287 }
2288 }
2289
2290 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2291 try {
2292 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2293 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002294 if (checkLocationAccess(r)) {
2295 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2296 }
xinhee9f16402014-09-25 16:39:28 -07002297 } catch (RemoteException ex) {
2298 mRemoveList.add(r.binder);
2299 }
2300 }
2301
2302 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2303 try {
2304 if (DBG) {
2305 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2306 + "=" + mDataConnectionState[phoneId]
2307 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2308 + ")");
2309 }
2310 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2311 mDataConnectionNetworkType[phoneId]);
2312 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002313 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002314 }
2315 }
2316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317}