blob: c44a81e2dcd0d4dce4d6f8cee5adec63d2236c04 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080038import android.telephony.LocationAccessPolicy;
Malcolm Chene1623652018-08-08 20:27:45 -070039import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070040import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080041import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020042import android.telephony.PreciseCallState;
43import android.telephony.PreciseDataConnectionState;
44import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070045import android.telephony.Rlog;
46import android.telephony.ServiceState;
47import android.telephony.SignalStrength;
48import android.telephony.SubscriptionManager;
49import android.telephony.TelephonyManager;
50import android.telephony.VoLteServiceState;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070053import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080055import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070057import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080058import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070059import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080061import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060062import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070063import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import com.android.server.am.BatteryStatsService;
65
Jack Yud19b6ae2017-04-05 14:12:09 -070066import java.io.FileDescriptor;
67import java.io.PrintWriter;
68import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070069import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080070import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072/**
Wink Savillee9b06d72009-05-18 21:47:50 -070073 * Since phone process can be restarted, this class provides a centralized place
74 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070075 *
76 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
77 * and 15973975 by saving the phoneId of the registrant and then using the
78 * phoneId when deciding to to make a callback. This is necessary because
79 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070080 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070081 * the dummy value conversion we properly do the callbacks.
82 *
83 * Eventually we may want to remove the notion of dummy value but for now this
84 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070086@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
87public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070089 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070090 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070091 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080094 Context context;
95
Svet Ganov16a16892015-04-16 10:32:04 -070096 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070099
Malcolm Chenabbfac22018-02-12 19:15:59 -0800100 TelephonyRegistryDeathRecipient deathRecipient;
101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800103 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700104
Hall Liu5fb337f2017-11-22 17:38:15 -0800105 int callerUid;
106 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700109
Wink Savilled09c4ca2014-11-22 10:08:16 -0800110 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700111
Wink Savilled09c4ca2014-11-22 10:08:16 -0800112 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800113
114 boolean matchPhoneStateListenerEvent(int events) {
115 return (callback != null) && ((events & this.events) != 0);
116 }
117
Wink Savilled09c4ca2014-11-22 10:08:16 -0800118 boolean matchOnSubscriptionsChangedListener() {
119 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800120 }
Wink Savillee380b982014-07-26 18:24:22 -0700121
Tyler Gunnf955e562018-04-26 14:43:31 -0700122 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800123 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700124 return TelephonyPermissions.checkReadCallLog(
125 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800126 } catch (SecurityException e) {
127 return false;
128 }
129 }
130
Wink Savillea12a7b32012-09-20 10:09:45 -0700131 @Override
132 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700133 return "{callingPackage=" + callingPackage + " binder=" + binder
134 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800135 + " onSubscriptionsChangedListenererCallback="
136 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800137 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800138 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 }
141
142 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Joe Onorato163d8d92010-10-21 13:21:20 -0400144 // access should be inside synchronized (mRecords) for these two fields
145 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
146 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 private final IBatteryStats mBatteryStats;
149
Svet Ganov16a16892015-04-16 10:32:04 -0700150 private final AppOpsManager mAppOps;
151
Wink Savilled09c4ca2014-11-22 10:08:16 -0800152 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
fionaxu12312f62016-11-14 13:32:14 -0800162 private int[] mVoiceActivationState;
163
164 private int[] mDataActivationState;
165
zxuan35a47022018-01-04 11:24:04 -0800166 private boolean[] mUserMobileDataState;
167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700175
Jack Yub1bac542018-03-14 16:23:38 -0700176 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700182
Nathan Harold016e9c62016-12-14 11:24:48 -0800183 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700184
Wink Savillefb40dd42014-06-12 17:02:31 -0700185 private ArrayList<List<CellInfo>> mCellInfo = null;
186
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800187 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
188
Wink Savillefb40dd42014-06-12 17:02:31 -0700189 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
190
Wink Savilled09c4ca2014-11-22 10:08:16 -0800191 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700192
Wink Savilled09c4ca2014-11-22 10:08:16 -0800193 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700194
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200195 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
196
197 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
198
199 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
200
201 private PreciseCallState mPreciseCallState = new PreciseCallState();
202
Andrew Flynn1f452642015-04-14 22:16:04 -0400203 private boolean mCarrierNetworkChangeState = false;
204
Malcolm Chene1623652018-08-08 20:27:45 -0700205 private PhoneCapability mPhoneCapability = null;
206
Jack Yud19b6ae2017-04-05 14:12:09 -0700207 private final LocalLog mLocalLog = new LocalLog(100);
208
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200209 private PreciseDataConnectionState mPreciseDataConnectionState =
210 new PreciseDataConnectionState();
211
Hall Liu70bbc162018-03-02 17:44:46 -0800212 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
213 PhoneStateListener.LISTEN_CELL_LOCATION
214 | PhoneStateListener.LISTEN_CELL_INFO;
215
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700216 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700217 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700218 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
219 PhoneStateListener.LISTEN_VOLTE_STATE;
220
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200221 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
222 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
223 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
224
Wink Savillea12a7b32012-09-20 10:09:45 -0700225 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700226 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700227
228 private final Handler mHandler = new Handler() {
229 @Override
230 public void handleMessage(Message msg) {
231 switch (msg.what) {
232 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700233 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700234 int numPhones = TelephonyManager.getDefault().getPhoneCount();
235 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700236 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700237 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700238 }
239 break;
240 }
xinhee9f16402014-09-25 16:39:28 -0700241 case MSG_UPDATE_DEFAULT_SUB: {
242 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700243 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700244 if (VDBG) {
245 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
246 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
247 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
248 }
249
250 //Due to possible risk condition,(notify call back using the new
251 //defaultSubId comes before new defaultSubId update) we need to recall all
252 //possible missed notify callback
253 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700254 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800255 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700256 checkPossibleMissNotify(r, newDefaultPhoneId);
257 }
258 }
259 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700260 }
261 mDefaultSubId = newDefaultSubId;
262 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700263 }
264 }
265 }
266 };
267
Malcolm Chenabbfac22018-02-12 19:15:59 -0800268 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
269
270 private final IBinder binder;
271
272 TelephonyRegistryDeathRecipient(IBinder binder) {
273 this.binder = binder;
274 }
275
276 @Override
277 public void binderDied() {
278 if (DBG) log("binderDied " + binder);
279 remove(binder);
280 }
281 }
282
Wink Savillea12a7b32012-09-20 10:09:45 -0700283 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
284 @Override
285 public void onReceive(Context context, Intent intent) {
286 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700287 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700288 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700289 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700290 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700291 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700292 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700293 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800294 PhoneConstants.SUBSCRIPTION_KEY,
295 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700296 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
297 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700298 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700299 log("onReceive:current mDefaultSubId=" + mDefaultSubId
300 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
301 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700302 }
xinhee9f16402014-09-25 16:39:28 -0700303
Junda Liu985f52c2015-02-23 16:06:51 -0800304 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700305 || (newDefaultPhoneId != mDefaultPhoneId))) {
306 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
307 newDefaultPhoneId, 0, newDefaultSubIdObj));
308 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700309 }
310 }
311 };
312
Wink Savillee9b06d72009-05-18 21:47:50 -0700313 // we keep a copy of all of the state so we can send it out when folks
314 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700316 // In these calls we call with the lock held. This is safe becasuse remote
317 // calls go through a oneway interface and local calls going through a
318 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700320 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
321 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700322 CellLocation location = CellLocation.getEmpty();
323
Wink Savillefb40dd42014-06-12 17:02:31 -0700324 mContext = context;
325 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700326
Wink Savillefb40dd42014-06-12 17:02:31 -0700327 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700328 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700329 mNumPhones = numPhones;
330 mCallState = new int[numPhones];
331 mDataActivity = new int[numPhones];
332 mDataConnectionState = new int[numPhones];
333 mDataConnectionNetworkType = new int[numPhones];
334 mCallIncomingNumber = new String[numPhones];
335 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800336 mVoiceActivationState = new int[numPhones];
337 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800338 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700339 mSignalStrength = new SignalStrength[numPhones];
340 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700341 mCallForwarding = new boolean[numPhones];
342 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700343 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800344 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700345 for (int i = 0; i < numPhones; i++) {
346 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
347 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
348 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800349 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
350 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700351 mCallIncomingNumber[i] = "";
352 mServiceState[i] = new ServiceState();
353 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800354 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 mMessageWaiting[i] = false;
356 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700357 mCellLocation[i] = new Bundle();
358 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700359 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700360 }
361
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700362 // Note that location can be null for non-phone builds like
363 // like the generic one.
364 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700365 for (int i = 0; i < numPhones; i++) {
366 location.fillInNotifierBundle(mCellLocation[i]);
367 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700368 }
Svet Ganov16a16892015-04-16 10:32:04 -0700369
370 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 }
372
Svetoslav Ganova0027152013-06-25 14:59:53 -0700373 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700374 // Watch for interesting updates
375 final IntentFilter filter = new IntentFilter();
376 filter.addAction(Intent.ACTION_USER_SWITCHED);
377 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700378 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700379 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700380 mContext.registerReceiver(mBroadcastReceiver, filter);
381 }
382
383 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700384 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800385 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700386 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800388 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700389 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
390 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800391 + " callback.asBinder=" + callback.asBinder());
392 }
393
Wink Savilled09c4ca2014-11-22 10:08:16 -0800394 synchronized (mRecords) {
395 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800396 IBinder b = callback.asBinder();
397 Record r = add(b);
398
399 if (r == null) {
400 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800401 }
402
Jeff Davidson29da89f2018-02-28 17:50:16 -0800403 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800404 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700405 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800406 r.callerUid = Binder.getCallingUid();
407 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800408 r.events = 0;
409 if (DBG) {
410 log("listen oscl: Register r=" + r);
411 }
412 // Always notify when registration occurs if there has been a notification.
413 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800414 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800415 if (VDBG) log("listen oscl: send to r=" + r);
416 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
417 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800418 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 remove(r.binder);
421 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800422 } else {
423 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 }
426 }
427
428 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800429 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800430 IOnSubscriptionsChangedListener callback) {
431 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800432 remove(callback.asBinder());
433 }
434
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 @Override
436 public void notifySubscriptionInfoChanged() {
437 if (VDBG) log("notifySubscriptionInfoChanged:");
438 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 if (!hasNotifySubscriptionInfoChangedOccurred) {
440 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
441 + mRecords.size());
442 }
443 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 mRemoveList.clear();
445 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800446 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800447 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800448 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
449 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
450 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800451 } catch (RemoteException ex) {
452 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
453 mRemoveList.add(r.binder);
454 }
455 }
456 }
457 handleRemoveListLocked();
458 }
459 }
460
461 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
463 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800464 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
465 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700466 }
467
468 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700469 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700470 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700471 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700472 }
473
Svet Ganov16a16892015-04-16 10:32:04 -0700474 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700475 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700476 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700478 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700479 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700480 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
481 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700482 }
xinhe75c2c152014-10-16 11:49:45 -0700483
484 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800485 // Checks permission and throws SecurityException for disallowed operations. For pre-M
486 // apps whose runtime permission has been revoked, we return immediately to skip sending
487 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800488 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800489 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700490 }
491
yifan.baie620ce72017-12-22 14:59:57 +0800492 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 synchronized (mRecords) {
494 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800495 IBinder b = callback.asBinder();
496 Record r = add(b);
497
498 if (r == null) {
499 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 }
xinhe43c50292014-09-18 17:56:48 -0700501
Jeff Davidson29da89f2018-02-28 17:50:16 -0800502 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700503 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700504 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800505 r.callerUid = Binder.getCallingUid();
506 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700507 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
508 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800510 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700511 } else {//APP specify subID
512 r.subId = subId;
513 }
yifan.baie620ce72017-12-22 14:59:57 +0800514 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700516 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700517 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700518 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700519 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400521 try {
Wink Savillee380b982014-07-26 18:24:22 -0700522 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700523 r.callback.onServiceStateChanged(
524 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400525 } catch (RemoteException ex) {
526 remove(r.binder);
527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 }
529 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
530 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700531 int gsmSignalStrength = mSignalStrength[phoneId]
532 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700533 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
534 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 } catch (RemoteException ex) {
536 remove(r.binder);
537 }
538 }
539 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
540 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700541 r.callback.onMessageWaitingIndicatorChanged(
542 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 } catch (RemoteException ex) {
544 remove(r.binder);
545 }
546 }
547 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
548 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700549 r.callback.onCallForwardingIndicatorChanged(
550 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 } catch (RemoteException ex) {
552 remove(r.binder);
553 }
554 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700555 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400556 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700557 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700558 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800559 if (checkLocationAccess(r)) {
560 r.callback.onCellLocationChanged(
561 new Bundle(mCellLocation[phoneId]));
562 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400563 } catch (RemoteException ex) {
564 remove(r.binder);
565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 }
567 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
568 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700569 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700570 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 } catch (RemoteException ex) {
572 remove(r.binder);
573 }
574 }
575 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
576 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700577 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
578 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 } catch (RemoteException ex) {
580 remove(r.binder);
581 }
582 }
583 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
584 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700585 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 } catch (RemoteException ex) {
587 remove(r.binder);
588 }
589 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700590 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
591 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700592 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700593 } catch (RemoteException ex) {
594 remove(r.binder);
595 }
596 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700597 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
598 try {
599 r.callback.onOtaspChanged(mOtaspMode);
600 } catch (RemoteException ex) {
601 remove(r.binder);
602 }
603 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700604 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700605 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700606 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700607 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800608 if (checkLocationAccess(r)) {
609 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
610 }
John Wang963db55d2012-03-30 16:04:06 -0700611 } catch (RemoteException ex) {
612 remove(r.binder);
613 }
614 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200615 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
616 try {
617 r.callback.onPreciseCallStateChanged(mPreciseCallState);
618 } catch (RemoteException ex) {
619 remove(r.binder);
620 }
621 }
622 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
623 try {
624 r.callback.onPreciseDataConnectionStateChanged(
625 mPreciseDataConnectionState);
626 } catch (RemoteException ex) {
627 remove(r.binder);
628 }
629 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400630 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
631 try {
632 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
633 } catch (RemoteException ex) {
634 remove(r.binder);
635 }
636 }
fionaxu12312f62016-11-14 13:32:14 -0800637 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
638 try {
639 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
640 } catch (RemoteException ex) {
641 remove(r.binder);
642 }
643 }
644 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
645 try {
646 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
647 } catch (RemoteException ex) {
648 remove(r.binder);
649 }
650 }
zxuan35a47022018-01-04 11:24:04 -0800651 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
652 try {
653 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
654 } catch (RemoteException ex) {
655 remove(r.binder);
656 }
657 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800658 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
659 try {
660 r.callback.onPhysicalChannelConfigurationChanged(
661 mPhysicalChannelConfigs.get(phoneId));
662 } catch (RemoteException ex) {
663 remove(r.binder);
664 }
665 }
Malcolm Chene1623652018-08-08 20:27:45 -0700666 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
667 try {
668 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
669 } catch (RemoteException ex) {
670 remove(r.binder);
671 }
672 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
674 }
675 } else {
xinhe75c2c152014-10-16 11:49:45 -0700676 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 remove(callback.asBinder());
678 }
679 }
680
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700681 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700682 // Only reveal the incoming number if the record has read call log permission.
683 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700684 }
685
Malcolm Chenabbfac22018-02-12 19:15:59 -0800686 private Record add(IBinder binder) {
687 Record r;
688
689 synchronized (mRecords) {
690 final int N = mRecords.size();
691 for (int i = 0; i < N; i++) {
692 r = mRecords.get(i);
693 if (binder == r.binder) {
694 // Already existed.
695 return r;
696 }
697 }
698 r = new Record();
699 r.binder = binder;
700 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
701
702 try {
703 binder.linkToDeath(r.deathRecipient, 0);
704 } catch (RemoteException e) {
705 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
706 // Binder already died. Return null.
707 return null;
708 }
709
710 mRecords.add(r);
711 if (DBG) log("add new record");
712 }
713
714 return r;
715 }
716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 private void remove(IBinder binder) {
718 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700719 final int recordCount = mRecords.size();
720 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800721 Record r = mRecords.get(i);
722 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800723 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800724 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
725 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800726 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800727
728 if (r.deathRecipient != null) {
729 try {
730 binder.unlinkToDeath(r.deathRecipient, 0);
731 } catch (NoSuchElementException e) {
732 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
733 + r + " e=" + e);
734 }
735 }
736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 mRecords.remove(i);
738 return;
739 }
740 }
741 }
742 }
743
Tyler Gunnf955e562018-04-26 14:43:31 -0700744 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700745 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700746 return;
747 }
xinhe43c50292014-09-18 17:56:48 -0700748
749 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700750 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700751 }
752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700754 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800755 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800756 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700758 // Ensure the listener has read call log permission; if they do not return
759 // an empty phone number.
760 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
761 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400763 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 }
765 }
766 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400767 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700769
770 // Called only by Telecomm to communicate call state across different phone accounts. So
771 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700772 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700773 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700774 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 }
776
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700777 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
778 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700779 if (!checkNotifyPermission("notifyCallState()")) {
780 return;
781 }
Wink Savillee380b982014-07-26 18:24:22 -0700782 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700783 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700784 + " state=" + state + " incomingNumber=" + incomingNumber);
785 }
786 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700787 if (validatePhoneId(phoneId)) {
788 mCallState[phoneId] = state;
789 mCallIncomingNumber[phoneId] = incomingNumber;
790 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800791 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700792 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800793 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700794 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700795 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
796 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700797 } catch (RemoteException ex) {
798 mRemoveList.add(r.binder);
799 }
800 }
801 }
802 }
803 handleRemoveListLocked();
804 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700805 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700806 }
807
Wink Saville63f03dd2014-10-23 10:44:45 -0700808 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700809 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700810 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700811 }
xinhe43c50292014-09-18 17:56:48 -0700812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700814 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
815 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700816 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700817 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700818 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700819 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700820 if (validatePhoneId(phoneId)) {
821 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700822
Wink Savillefb40dd42014-06-12 17:02:31 -0700823 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700824 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700825 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700826 + " phoneId=" + phoneId + " state=" + state);
827 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800828 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800829 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700830 try {
Wink Savillee380b982014-07-26 18:24:22 -0700831 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700832 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700833 + " subId=" + subId + " phoneId=" + phoneId
834 + " state=" + state);
835 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700836 r.callback.onServiceStateChanged(new ServiceState(state));
837 } catch (RemoteException ex) {
838 mRemoveList.add(r.binder);
839 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400840 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700842 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700843 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400845 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700847 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
849
fionaxu12312f62016-11-14 13:32:14 -0800850 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
851 int activationType, int activationState) {
852 if (!checkNotifyPermission("notifySimActivationState()")){
853 return;
854 }
855 if (VDBG) {
856 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
857 + "type=" + activationType + " state=" + activationState);
858 }
859 synchronized (mRecords) {
860 if (validatePhoneId(phoneId)) {
861 switch (activationType) {
862 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
863 mVoiceActivationState[phoneId] = activationState;
864 break;
865 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
866 mDataActivationState[phoneId] = activationState;
867 break;
868 default:
869 return;
870 }
871 for (Record r : mRecords) {
872 if (VDBG) {
873 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
874 + " phoneId=" + phoneId + "type=" + activationType
875 + " state=" + activationState);
876 }
877 try {
878 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
879 r.matchPhoneStateListenerEvent(
880 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
881 idMatch(r.subId, subId, phoneId)) {
882 if (DBG) {
883 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
884 + " subId=" + subId + " phoneId=" + phoneId
885 + " state=" + activationState);
886 }
887 r.callback.onVoiceActivationStateChanged(activationState);
888 }
889 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
890 r.matchPhoneStateListenerEvent(
891 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
892 idMatch(r.subId, subId, phoneId)) {
893 if (DBG) {
894 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
895 + " subId=" + subId + " phoneId=" + phoneId
896 + " state=" + activationState);
897 }
898 r.callback.onDataActivationStateChanged(activationState);
899 }
900 } catch (RemoteException ex) {
901 mRemoveList.add(r.binder);
902 }
903 }
904 } else {
905 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
906 }
907 handleRemoveListLocked();
908 }
909 }
910
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700911 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
912 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700913 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700914 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700915 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000916 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700917 log("notifySignalStrengthForPhoneId: subId=" + subId
918 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000919 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700922 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700923 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700924 mSignalStrength[phoneId] = signalStrength;
925 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000926 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700927 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000928 + " phoneId=" + phoneId + " ss=" + signalStrength);
929 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800930 if (r.matchPhoneStateListenerEvent(
931 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800932 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700933 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000934 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700935 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000936 + " subId=" + subId + " phoneId=" + phoneId
937 + " ss=" + signalStrength);
938 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700939 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
940 } catch (RemoteException ex) {
941 mRemoveList.add(r.binder);
942 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400943 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800944 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800945 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700946 try {
947 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700948 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000949 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700950 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000951 + " subId=" + subId + " phoneId=" + phoneId
952 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
953 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700954 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700955 } catch (RemoteException ex) {
956 mRemoveList.add(r.binder);
957 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 }
959 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700960 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700961 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400963 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700965 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 }
967
Andrew Flynn1f452642015-04-14 22:16:04 -0400968 @Override
969 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000970 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
971
Andrew Flynn1f452642015-04-14 22:16:04 -0400972 if (VDBG) {
973 log("notifyCarrierNetworkChange: active=" + active);
974 }
975
976 synchronized (mRecords) {
977 mCarrierNetworkChangeState = active;
978 for (Record r : mRecords) {
979 if (r.matchPhoneStateListenerEvent(
980 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
981 try {
982 r.callback.onCarrierNetworkChange(active);
983 } catch (RemoteException ex) {
984 mRemoveList.add(r.binder);
985 }
986 }
987 }
988 handleRemoveListLocked();
989 }
990 }
991
Wink Savilleb208a242012-07-25 14:08:09 -0700992 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800993 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700994 }
995
Wink Saville63f03dd2014-10-23 10:44:45 -0700996 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700997 if (!checkNotifyPermission("notifyCellInfo()")) {
998 return;
999 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001000 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001001 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001002 + " cellInfo=" + cellInfo);
1003 }
yifan.baie620ce72017-12-22 14:59:57 +08001004 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001005 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001006 if (validatePhoneId(phoneId)) {
1007 mCellInfo.set(phoneId, cellInfo);
1008 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001009 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001010 idMatch(r.subId, subId, phoneId) &&
1011 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 try {
1013 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001014 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001015 }
1016 r.callback.onCellInfoChanged(cellInfo);
1017 } catch (RemoteException ex) {
1018 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001019 }
John Wang963db55d2012-03-30 16:04:06 -07001020 }
1021 }
1022 }
1023 handleRemoveListLocked();
1024 }
1025 }
1026
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001027 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1028 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1029 configs);
1030 }
1031
1032 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1033 List<PhysicalChannelConfig> configs) {
1034 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1035 return;
1036 }
1037
1038 if (VDBG) {
1039 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1040 }
1041
1042 synchronized (mRecords) {
1043 int phoneId = SubscriptionManager.getPhoneId(subId);
1044 if (validatePhoneId(phoneId)) {
1045 mPhysicalChannelConfigs.set(phoneId, configs);
1046 for (Record r : mRecords) {
1047 if (r.matchPhoneStateListenerEvent(
1048 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1049 && idMatch(r.subId, subId, phoneId)) {
1050 try {
1051 if (DBG_LOC) {
1052 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1053 + configs + " r=" + r);
1054 }
1055 r.callback.onPhysicalChannelConfigurationChanged(configs);
1056 } catch (RemoteException ex) {
1057 mRemoveList.add(r.binder);
1058 }
1059 }
1060 }
1061 }
1062 handleRemoveListLocked();
1063 }
1064 }
1065
xinhe43c50292014-09-18 17:56:48 -07001066 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001067 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001068 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001069 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001070 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001071 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001072 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001073 + " mwi=" + mwi);
1074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001076 if (validatePhoneId(phoneId)) {
1077 mMessageWaiting[phoneId] = mwi;
1078 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001079 if (r.matchPhoneStateListenerEvent(
1080 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001081 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001082 try {
1083 r.callback.onMessageWaitingIndicatorChanged(mwi);
1084 } catch (RemoteException ex) {
1085 mRemoveList.add(r.binder);
1086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 }
1088 }
1089 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001090 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 }
1092 }
1093
zxuan35a47022018-01-04 11:24:04 -08001094 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1095 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1096 return;
1097 }
1098 if (VDBG) {
1099 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1100 + " state=" + state);
1101 }
1102 synchronized (mRecords) {
1103 if (validatePhoneId(phoneId)) {
1104 mMessageWaiting[phoneId] = state;
1105 for (Record r : mRecords) {
1106 if (r.matchPhoneStateListenerEvent(
1107 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1108 idMatch(r.subId, subId, phoneId)) {
1109 try {
1110 r.callback.onUserMobileDataStateChanged(state);
1111 } catch (RemoteException ex) {
1112 mRemoveList.add(r.binder);
1113 }
1114 }
1115 }
1116 }
1117 handleRemoveListLocked();
1118 }
1119 }
1120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001122 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001123 }
1124
Wink Saville63f03dd2014-10-23 10:44:45 -07001125 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001126 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001127 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001128 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001129 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001130 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001131 + " cfi=" + cfi);
1132 }
yifan.baie620ce72017-12-22 14:59:57 +08001133 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001135 if (validatePhoneId(phoneId)) {
1136 mCallForwarding[phoneId] = cfi;
1137 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001138 if (r.matchPhoneStateListenerEvent(
1139 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001140 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001141 try {
1142 r.callback.onCallForwardingIndicatorChanged(cfi);
1143 } catch (RemoteException ex) {
1144 mRemoveList.add(r.binder);
1145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 }
1147 }
1148 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001149 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 }
1151 }
1152
1153 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001154 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001155 }
1156
Wink Saville63f03dd2014-10-23 10:44:45 -07001157 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001158 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001159 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001160 }
yifan.baie620ce72017-12-22 14:59:57 +08001161 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001163 if (validatePhoneId(phoneId)) {
1164 mDataActivity[phoneId] = state;
1165 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001166 // Notify by correct subId.
1167 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1168 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001169 try {
1170 r.callback.onDataActivity(state);
1171 } catch (RemoteException ex) {
1172 mRemoveList.add(r.binder);
1173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
1175 }
1176 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001177 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 }
1179 }
1180
Jack Yubaeec622017-05-01 17:01:11 -07001181 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001182 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001183 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001184 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001185 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001186 networkCapabilities, networkType, roaming);
1187 }
1188
Wink Saville63f03dd2014-10-23 10:44:45 -07001189 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001190 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001191 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1192 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001193 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001194 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001195 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001196 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001197 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001198 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001199 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001200 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001201 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001202 }
yifan.baie620ce72017-12-22 14:59:57 +08001203 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001205 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001206 // We only call the callback when the change is for default APN type.
1207 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1208 && (mDataConnectionState[phoneId] != state
1209 || mDataConnectionNetworkType[phoneId] != networkType)) {
1210 String str = "onDataConnectionStateChanged(" + state
1211 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001212 log(str);
1213 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001214 for (Record r : mRecords) {
1215 if (r.matchPhoneStateListenerEvent(
1216 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1217 idMatch(r.subId, subId, phoneId)) {
1218 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001219 if (DBG) {
1220 log("Notify data connection state changed on sub: " + subId);
1221 }
Jack Yub1bac542018-03-14 16:23:38 -07001222 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001223 } catch (RemoteException ex) {
1224 mRemoveList.add(r.binder);
1225 }
1226 }
1227 }
1228 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001229
1230 mDataConnectionState[phoneId] = state;
1231 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001232 }
1233 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1234 apnType, apn, reason, linkProperties, "");
1235 for (Record r : mRecords) {
1236 if (r.matchPhoneStateListenerEvent(
1237 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1238 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001239 r.callback.onPreciseDataConnectionStateChanged(
1240 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001241 } catch (RemoteException ex) {
1242 mRemoveList.add(r.binder);
1243 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001244 }
1245 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001246 }
1247 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 }
Jack Yubaeec622017-05-01 17:01:11 -07001249 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001250 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001251 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1252 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 }
1254
Robert Greenwalt02648a42010-05-18 10:52:51 -07001255 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001256 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001257 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001258 }
1259
Wink Saville63f03dd2014-10-23 10:44:45 -07001260 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001261 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001262 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001263 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001264 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001265 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001266 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001267 + " reason=" + reason + " apnType=" + apnType);
1268 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001270 mPreciseDataConnectionState = new PreciseDataConnectionState(
1271 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1272 apnType, "", reason, null, "");
1273 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001274 if (r.matchPhoneStateListenerEvent(
1275 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001276 try {
1277 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1278 } catch (RemoteException ex) {
1279 mRemoveList.add(r.binder);
1280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 }
1282 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001283 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001285 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001286 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1287 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 }
1289
1290 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001291 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001292 }
1293
Wink Saville63f03dd2014-10-23 10:44:45 -07001294 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001295 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001296 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001297 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001298 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001299 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001300 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001301 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001302 + " cellLocation=" + cellLocation);
1303 }
yifan.baie620ce72017-12-22 14:59:57 +08001304 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001306 if (validatePhoneId(phoneId)) {
1307 mCellLocation[phoneId] = cellLocation;
1308 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001309 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001310 idMatch(r.subId, subId, phoneId) &&
1311 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001312 try {
1313 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001314 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001315 + " r=" + r);
1316 }
1317 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1318 } catch (RemoteException ex) {
1319 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001320 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001321 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 }
1323 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001324 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001325 }
1326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327
Wink Savillefd2d0132010-10-28 14:22:26 -07001328 public void notifyOtaspChanged(int otaspMode) {
1329 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1330 return;
1331 }
1332 synchronized (mRecords) {
1333 mOtaspMode = otaspMode;
1334 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001335 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001336 try {
1337 r.callback.onOtaspChanged(otaspMode);
1338 } catch (RemoteException ex) {
1339 mRemoveList.add(r.binder);
1340 }
1341 }
1342 }
1343 handleRemoveListLocked();
1344 }
1345 }
1346
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001347 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1348 int backgroundCallState) {
1349 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1350 return;
1351 }
1352 synchronized (mRecords) {
1353 mRingingCallState = ringingCallState;
1354 mForegroundCallState = foregroundCallState;
1355 mBackgroundCallState = backgroundCallState;
1356 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1357 backgroundCallState,
1358 DisconnectCause.NOT_VALID,
1359 PreciseDisconnectCause.NOT_VALID);
1360 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001361 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001362 try {
1363 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1364 } catch (RemoteException ex) {
1365 mRemoveList.add(r.binder);
1366 }
1367 }
1368 }
1369 handleRemoveListLocked();
1370 }
1371 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1372 DisconnectCause.NOT_VALID,
1373 PreciseDisconnectCause.NOT_VALID);
1374 }
1375
1376 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1377 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1378 return;
1379 }
1380 synchronized (mRecords) {
1381 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1382 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1383 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001384 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001385 try {
1386 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1387 } catch (RemoteException ex) {
1388 mRemoveList.add(r.binder);
1389 }
1390 }
1391 }
1392 handleRemoveListLocked();
1393 }
1394 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1395 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1396 }
1397
1398 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1399 String apn, String failCause) {
1400 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1401 return;
1402 }
1403 synchronized (mRecords) {
1404 mPreciseDataConnectionState = new PreciseDataConnectionState(
1405 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1406 apnType, apn, reason, null, failCause);
1407 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001408 if (r.matchPhoneStateListenerEvent(
1409 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001410 try {
1411 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1412 } catch (RemoteException ex) {
1413 mRemoveList.add(r.binder);
1414 }
1415 }
1416 }
1417 handleRemoveListLocked();
1418 }
1419 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1420 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1421 }
1422
Wink Savillefb40dd42014-06-12 17:02:31 -07001423 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1424 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1425 return;
1426 }
1427 synchronized (mRecords) {
1428 mVoLteServiceState = lteState;
1429 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001430 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001431 try {
1432 r.callback.onVoLteServiceStateChanged(
1433 new VoLteServiceState(mVoLteServiceState));
1434 } catch (RemoteException ex) {
1435 mRemoveList.add(r.binder);
1436 }
1437 }
1438 }
1439 handleRemoveListLocked();
1440 }
1441 }
1442
Shuo Qian066e8652018-04-25 21:02:35 +00001443 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1444 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1445 return;
1446 }
1447
1448 synchronized (mRecords) {
1449 for (Record r : mRecords) {
1450 if (VDBG) {
1451 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1452 }
1453 if ((r.matchPhoneStateListenerEvent(
1454 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1455 ((r.subId == subId) ||
1456 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1457 try {
1458 r.callback.onOemHookRawEvent(rawData);
1459 } catch (RemoteException ex) {
1460 mRemoveList.add(r.binder);
1461 }
1462 }
1463 }
1464 handleRemoveListLocked();
1465 }
1466 }
1467
Malcolm Chene1623652018-08-08 20:27:45 -07001468 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1469 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1470 return;
1471 }
1472
1473 if (VDBG) {
1474 log("notifyPhoneCapabilityChanged: capability=" + capability);
1475 }
1476
1477 synchronized (mRecords) {
1478 mPhoneCapability = capability;
1479
1480 for (Record r : mRecords) {
1481 if (r.matchPhoneStateListenerEvent(
1482 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1483 try {
1484 r.callback.onPhoneCapabilityChanged(capability);
1485 } catch (RemoteException ex) {
1486 mRemoveList.add(r.binder);
1487 }
1488 }
1489 }
1490 handleRemoveListLocked();
1491 }
1492 }
1493
1494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001496 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1497 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1498
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001499 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001502 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001504 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301505 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001506 pw.println("Phone Id=" + i);
1507 pw.increaseIndent();
1508 pw.println("mCallState=" + mCallState[i]);
1509 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1510 pw.println("mServiceState=" + mServiceState[i]);
1511 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1512 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001513 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001514 pw.println("mSignalStrength=" + mSignalStrength[i]);
1515 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1516 pw.println("mCallForwarding=" + mCallForwarding[i]);
1517 pw.println("mDataActivity=" + mDataActivity[i]);
1518 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001519 pw.println("mCellLocation=" + mCellLocation[i]);
1520 pw.println("mCellInfo=" + mCellInfo.get(i));
1521 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301522 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001523 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1524 pw.println("mPreciseCallState=" + mPreciseCallState);
1525 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1526 pw.println("mRingingCallState=" + mRingingCallState);
1527 pw.println("mForegroundCallState=" + mForegroundCallState);
1528 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1529 pw.println("mVoLteServiceState=" + mVoLteServiceState);
Malcolm Chene1623652018-08-08 20:27:45 -07001530 pw.println("mPhoneCapability=" + mPhoneCapability);
Jack Yud19b6ae2017-04-05 14:12:09 -07001531
1532 pw.decreaseIndent();
1533
1534 pw.println("local logs:");
1535 pw.increaseIndent();
1536 mLocalLog.dump(fd, pw, args);
1537 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001538 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001539 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001540 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001541 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001543 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 }
1545 }
1546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 //
1548 // the legacy intent broadcasting
1549 //
1550
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001551 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001552 long ident = Binder.clearCallingIdentity();
1553 try {
1554 mBatteryStats.notePhoneState(state.getState());
1555 } catch (RemoteException re) {
1556 // Can't do much
1557 } finally {
1558 Binder.restoreCallingIdentity(ident);
1559 }
1560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001562 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 Bundle data = new Bundle();
1564 state.fillInNotifierBundle(data);
1565 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001566 // Pass the subscription along with the intent.
1567 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001568 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001569 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 }
1571
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001572 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1573 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001574 long ident = Binder.clearCallingIdentity();
1575 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001576 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001577 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001578 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001579 } finally {
1580 Binder.restoreCallingIdentity(ident);
1581 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001584 Bundle data = new Bundle();
1585 signalStrength.fillInNotifierBundle(data);
1586 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001587 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001588 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001589 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 }
1591
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001592 /**
1593 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1594 * a valid subId, in which case this function fires a subId-specific intent, or it
1595 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1596 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1597 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001598 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1599 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 long ident = Binder.clearCallingIdentity();
1601 try {
1602 if (state == TelephonyManager.CALL_STATE_IDLE) {
1603 mBatteryStats.notePhoneOff();
1604 } else {
1605 mBatteryStats.notePhoneOn();
1606 }
1607 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001608 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 } finally {
1610 Binder.restoreCallingIdentity(ident);
1611 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001614 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001615 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001616
1617 // If a valid subId was specified, we should fire off a subId-specific state
1618 // change intent and include the subId.
1619 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1620 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1621 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1622 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001623 // If the phoneId is invalid, the broadcast is for overall call state.
1624 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1625 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1626 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001627
Brad Ebinger51de96a2017-04-21 17:05:18 -07001628 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1629 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1630
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001631 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001632 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001633 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1634
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001635 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1636 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001637 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001638 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001639 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001640 android.Manifest.permission.READ_PHONE_STATE,
1641 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001642 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1643 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1644 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 }
1646
Robert Greenwalt42acef32009-08-12 16:08:25 -07001647 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001648 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001649 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001650 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001651 // Note: not reporting to the battery stats service here, because the
1652 // status bar takes care of that after taking into account all of the
1653 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001655 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001656 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001657 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001658 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 }
1660 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001661 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001663 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001664 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001665 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001666 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001667 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001668 }
1669 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001670 if (networkCapabilities != null) {
1671 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001672 }
Wink Savillea639b312012-07-10 12:37:54 -07001673 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001674
Wink Savillea639b312012-07-10 12:37:54 -07001675 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1676 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001677 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001678 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 }
1680
Wink Savillefb40dd42014-06-12 17:02:31 -07001681 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001682 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001684 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1685 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001686 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001687 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001689
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001690 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1691 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1692 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1693 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1694 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1695 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1696 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1697 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1698 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1699 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1700 }
1701
1702 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001703 String apnType, String apn, String reason, LinkProperties linkProperties,
1704 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001705 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1706 intent.putExtra(PhoneConstants.STATE_KEY, state);
1707 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1708 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1709 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1710 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001711 if (linkProperties != null) {
1712 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1713 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001714 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1715
1716 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1717 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1718 }
1719
Andrew Flynnceaed682015-06-09 12:36:58 +00001720 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001721 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001722 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001723 }
1724
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001725 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1726 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001727 }
1728
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001729 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001730 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001731 return true;
1732 }
1733 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001734 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001735 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001736 return false;
1737 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001738
Andrew Flynn1f452642015-04-14 22:16:04 -04001739 private boolean checkNotifyPermission() {
1740 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1741 == PackageManager.PERMISSION_GRANTED;
1742 }
1743
Jeff Davidson29da89f2018-02-28 17:50:16 -08001744 private boolean checkListenerPermission(
1745 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001746 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001747 mContext.enforceCallingOrSelfPermission(
1748 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001749 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1750 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1751 return false;
1752 }
John Wang963db55d2012-03-30 16:04:06 -07001753 }
1754
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001755 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1757 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001758 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001759 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001760 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001761
1762 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1763 mContext.enforceCallingOrSelfPermission(
1764 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001765 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001766
Shuo Qian066e8652018-04-25 21:02:35 +00001767 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1768 mContext.enforceCallingOrSelfPermission(
1769 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1770 }
1771
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001772 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001773 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001774
1775 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001776 int size = mRemoveList.size();
1777 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1778 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001779 for (IBinder b: mRemoveList) {
1780 remove(b);
1781 }
1782 mRemoveList.clear();
1783 }
1784 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001785
1786 private boolean validateEventsAndUserLocked(Record r, int events) {
1787 int foregroundUser;
1788 long callingIdentity = Binder.clearCallingIdentity();
1789 boolean valid = false;
1790 try {
1791 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001792 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1793 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001794 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001795 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001796 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001797 + " r.events=" + r.events + " events=" + events);
1798 }
1799 } finally {
1800 Binder.restoreCallingIdentity(callingIdentity);
1801 }
1802 return valid;
1803 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001804
1805 private boolean validatePhoneId(int phoneId) {
1806 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001807 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001808 return valid;
1809 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001810
1811 private static void log(String s) {
1812 Rlog.d(TAG, s);
1813 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001814
xinhe8b79fb62014-11-05 14:55:03 -08001815 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001816
1817 if(subId < 0) {
1818 // Invalid case, we need compare phoneId with default one.
1819 return (mDefaultPhoneId == phoneId);
1820 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001821 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001822 return (subId == mDefaultSubId);
1823 } else {
1824 return (rSubId == subId);
1825 }
1826 }
1827
Hall Liu5fb337f2017-11-22 17:38:15 -08001828 private boolean checkLocationAccess(Record r) {
1829 long token = Binder.clearCallingIdentity();
1830 try {
1831 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001832 r.callingPackage, r.callerUid, r.callerPid,
1833 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001834 } finally {
1835 Binder.restoreCallingIdentity(token);
1836 }
1837 }
1838
xinhee9f16402014-09-25 16:39:28 -07001839 private void checkPossibleMissNotify(Record r, int phoneId) {
1840 int events = r.events;
1841
1842 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1843 try {
1844 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1845 mServiceState[phoneId]);
1846 r.callback.onServiceStateChanged(
1847 new ServiceState(mServiceState[phoneId]));
1848 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001849 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001850 }
1851 }
1852
1853 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1854 try {
1855 SignalStrength signalStrength = mSignalStrength[phoneId];
1856 if (DBG) {
1857 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1858 }
1859 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1860 } catch (RemoteException ex) {
1861 mRemoveList.add(r.binder);
1862 }
1863 }
1864
1865 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1866 try {
1867 int gsmSignalStrength = mSignalStrength[phoneId]
1868 .getGsmSignalStrength();
1869 if (DBG) {
1870 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1871 gsmSignalStrength);
1872 }
1873 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1874 : gsmSignalStrength));
1875 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001876 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001877 }
1878 }
1879
1880 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1881 try {
1882 if (DBG_LOC) {
1883 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1884 + mCellInfo.get(phoneId));
1885 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001886 if (checkLocationAccess(r)) {
1887 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1888 }
xinhee9f16402014-09-25 16:39:28 -07001889 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001890 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001891 }
1892 }
1893
zxuan35a47022018-01-04 11:24:04 -08001894 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1895 try {
1896 if (VDBG) {
1897 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1898 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1899 }
1900 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1901 } catch (RemoteException ex) {
1902 mRemoveList.add(r.binder);
1903 }
1904 }
1905
xinhee9f16402014-09-25 16:39:28 -07001906 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1907 try {
1908 if (VDBG) {
1909 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1910 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1911 }
1912 r.callback.onMessageWaitingIndicatorChanged(
1913 mMessageWaiting[phoneId]);
1914 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001915 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001916 }
1917 }
1918
1919 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1920 try {
1921 if (VDBG) {
1922 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1923 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1924 }
1925 r.callback.onCallForwardingIndicatorChanged(
1926 mCallForwarding[phoneId]);
1927 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001928 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001929 }
1930 }
1931
1932 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1933 try {
1934 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1935 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001936 if (checkLocationAccess(r)) {
1937 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1938 }
xinhee9f16402014-09-25 16:39:28 -07001939 } catch (RemoteException ex) {
1940 mRemoveList.add(r.binder);
1941 }
1942 }
1943
1944 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1945 try {
1946 if (DBG) {
1947 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1948 + "=" + mDataConnectionState[phoneId]
1949 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1950 + ")");
1951 }
1952 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1953 mDataConnectionNetworkType[phoneId]);
1954 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001955 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001956 }
1957 }
1958 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959}