blob: 3927ebd593bd0bcfaddfb9ad00c0a689dc1bedb6 [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;
Jack Yud19b6ae2017-04-05 14:12:09 -070039import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080040import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020041import android.telephony.PreciseCallState;
42import android.telephony.PreciseDataConnectionState;
43import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070044import android.telephony.Rlog;
45import android.telephony.ServiceState;
46import android.telephony.SignalStrength;
47import android.telephony.SubscriptionManager;
48import android.telephony.TelephonyManager;
49import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080054import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070056import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080057import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070058import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080060import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060061import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070062import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.server.am.BatteryStatsService;
64
Jack Yud19b6ae2017-04-05 14:12:09 -070065import java.io.FileDescriptor;
66import java.io.PrintWriter;
67import java.util.ArrayList;
68import java.util.Arrays;
69import 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 */
86class TelephonyRegistry extends ITelephonyRegistry.Stub {
87 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070088 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070089 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070090 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
92 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070093 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070096
Malcolm Chenabbfac22018-02-12 19:15:59 -080097 TelephonyRegistryDeathRecipient deathRecipient;
98
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800100 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700101
Hall Liu5fb337f2017-11-22 17:38:15 -0800102 int callerUid;
103 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700106
Wink Savilled09c4ca2014-11-22 10:08:16 -0800107 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700108
Wink Savilled09c4ca2014-11-22 10:08:16 -0800109 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800110
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700111 boolean canReadPhoneState;
112
Wink Savillea374c3d2014-11-11 11:48:04 -0800113 boolean matchPhoneStateListenerEvent(int events) {
114 return (callback != null) && ((events & this.events) != 0);
115 }
116
Wink Savilled09c4ca2014-11-22 10:08:16 -0800117 boolean matchOnSubscriptionsChangedListener() {
118 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800119 }
Wink Savillee380b982014-07-26 18:24:22 -0700120
Wink Savillea12a7b32012-09-20 10:09:45 -0700121 @Override
122 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700123 return "{callingPackage=" + callingPackage + " binder=" + binder
124 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800125 + " onSubscriptionsChangedListenererCallback="
126 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800127 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700128 + " events=" + Integer.toHexString(events)
129 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 }
132
133 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700134
Joe Onorato163d8d92010-10-21 13:21:20 -0400135 // access should be inside synchronized (mRecords) for these two fields
136 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
137 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 private final IBatteryStats mBatteryStats;
140
Svet Ganov16a16892015-04-16 10:32:04 -0700141 private final AppOpsManager mAppOps;
142
Wink Savilled09c4ca2014-11-22 10:08:16 -0800143 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
144
Wink Savillefb40dd42014-06-12 17:02:31 -0700145 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700146
Wink Savillefb40dd42014-06-12 17:02:31 -0700147 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700148
Wink Savillefb40dd42014-06-12 17:02:31 -0700149 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700150
Wink Savillefb40dd42014-06-12 17:02:31 -0700151 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700152
fionaxu12312f62016-11-14 13:32:14 -0800153 private int[] mVoiceActivationState;
154
155 private int[] mDataActivationState;
156
zxuan35a47022018-01-04 11:24:04 -0800157 private boolean[] mUserMobileDataState;
158
Wink Savillefb40dd42014-06-12 17:02:31 -0700159 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700160
Wink Savillefb40dd42014-06-12 17:02:31 -0700161 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700162
Wink Savillefb40dd42014-06-12 17:02:31 -0700163 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700164
Wink Savillefb40dd42014-06-12 17:02:31 -0700165 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700166
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700168
Yifan Bai57b39e32016-04-01 16:24:33 +0800169 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700170
Wink Savillefb40dd42014-06-12 17:02:31 -0700171 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700172
Wink Savillefb40dd42014-06-12 17:02:31 -0700173 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700174
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700178
Nathan Harold016e9c62016-12-14 11:24:48 -0800179 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700180
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 private ArrayList<List<CellInfo>> mCellInfo = null;
182
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800183 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
184
Wink Savillefb40dd42014-06-12 17:02:31 -0700185 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
186
Wink Savilled09c4ca2014-11-22 10:08:16 -0800187 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700188
Wink Savilled09c4ca2014-11-22 10:08:16 -0800189 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700190
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200191 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
192
193 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
194
195 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
196
197 private PreciseCallState mPreciseCallState = new PreciseCallState();
198
Andrew Flynn1f452642015-04-14 22:16:04 -0400199 private boolean mCarrierNetworkChangeState = false;
200
Jack Yud19b6ae2017-04-05 14:12:09 -0700201 private final LocalLog mLocalLog = new LocalLog(100);
202
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200203 private PreciseDataConnectionState mPreciseDataConnectionState =
204 new PreciseDataConnectionState();
205
Hall Liu70bbc162018-03-02 17:44:46 -0800206 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
207 PhoneStateListener.LISTEN_CELL_LOCATION
208 | PhoneStateListener.LISTEN_CELL_INFO;
209
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700210 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700211 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700212 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
213 PhoneStateListener.LISTEN_VOLTE_STATE;
214
215 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700216 PhoneStateListener.LISTEN_CALL_STATE |
217 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700218 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700219
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200220 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
221 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
222 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
223
Wink Savillea12a7b32012-09-20 10:09:45 -0700224 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700225 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700226
227 private final Handler mHandler = new Handler() {
228 @Override
229 public void handleMessage(Message msg) {
230 switch (msg.what) {
231 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700232 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700233 int numPhones = TelephonyManager.getDefault().getPhoneCount();
234 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700235 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700236 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700237 }
238 break;
239 }
xinhee9f16402014-09-25 16:39:28 -0700240 case MSG_UPDATE_DEFAULT_SUB: {
241 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700242 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700243 if (VDBG) {
244 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
245 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
246 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
247 }
248
249 //Due to possible risk condition,(notify call back using the new
250 //defaultSubId comes before new defaultSubId update) we need to recall all
251 //possible missed notify callback
252 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700253 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800254 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700255 checkPossibleMissNotify(r, newDefaultPhoneId);
256 }
257 }
258 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700259 }
260 mDefaultSubId = newDefaultSubId;
261 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700262 }
263 }
264 }
265 };
266
Malcolm Chenabbfac22018-02-12 19:15:59 -0800267 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
268
269 private final IBinder binder;
270
271 TelephonyRegistryDeathRecipient(IBinder binder) {
272 this.binder = binder;
273 }
274
275 @Override
276 public void binderDied() {
277 if (DBG) log("binderDied " + binder);
278 remove(binder);
279 }
280 }
281
Wink Savillea12a7b32012-09-20 10:09:45 -0700282 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
283 @Override
284 public void onReceive(Context context, Intent intent) {
285 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700286 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700287 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700288 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700289 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700290 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700291 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700292 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800293 PhoneConstants.SUBSCRIPTION_KEY,
294 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700295 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
296 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700297 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700298 log("onReceive:current mDefaultSubId=" + mDefaultSubId
299 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
300 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700301 }
xinhee9f16402014-09-25 16:39:28 -0700302
Junda Liu985f52c2015-02-23 16:06:51 -0800303 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700304 || (newDefaultPhoneId != mDefaultPhoneId))) {
305 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
306 newDefaultPhoneId, 0, newDefaultSubIdObj));
307 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700308 }
309 }
310 };
311
Wink Savillee9b06d72009-05-18 21:47:50 -0700312 // we keep a copy of all of the state so we can send it out when folks
313 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700315 // In these calls we call with the lock held. This is safe becasuse remote
316 // calls go through a oneway interface and local calls going through a
317 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318
319 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700320 CellLocation location = CellLocation.getEmpty();
321
Wink Savillefb40dd42014-06-12 17:02:31 -0700322 mContext = context;
323 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700324
Wink Savillefb40dd42014-06-12 17:02:31 -0700325 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700326 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700327 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800328 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700329 mCallState = new int[numPhones];
330 mDataActivity = new int[numPhones];
331 mDataConnectionState = new int[numPhones];
332 mDataConnectionNetworkType = new int[numPhones];
333 mCallIncomingNumber = new String[numPhones];
334 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800335 mVoiceActivationState = new int[numPhones];
336 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800337 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700338 mSignalStrength = new SignalStrength[numPhones];
339 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700340 mCallForwarding = new boolean[numPhones];
341 mCellLocation = new Bundle[numPhones];
342 mDataConnectionLinkProperties = new LinkProperties[numPhones];
343 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
344 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800345 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700346 for (int i = 0; i < numPhones; i++) {
347 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
348 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
349 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800350 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
351 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 mCallIncomingNumber[i] = "";
353 mServiceState[i] = new ServiceState();
354 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800355 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700356 mMessageWaiting[i] = false;
357 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700358 mCellLocation[i] = new Bundle();
359 mCellInfo.add(i, null);
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800360 mPhysicalChannelConfigs.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800361 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700362 }
363
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700364 // Note that location can be null for non-phone builds like
365 // like the generic one.
366 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700367 for (int i = 0; i < numPhones; i++) {
368 location.fillInNotifierBundle(mCellLocation[i]);
369 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700370 }
Svet Ganov16a16892015-04-16 10:32:04 -0700371
372 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 }
374
Svetoslav Ganova0027152013-06-25 14:59:53 -0700375 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700376 // Watch for interesting updates
377 final IntentFilter filter = new IntentFilter();
378 filter.addAction(Intent.ACTION_USER_SWITCHED);
379 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700380 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700381 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700382 mContext.registerReceiver(mBroadcastReceiver, filter);
383 }
384
385 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700386 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800387 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700388 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800389 mContext.getSystemService(AppOpsManager.class)
390 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800391 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700392 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
393 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800394 + " callback.asBinder=" + callback.asBinder());
395 }
396
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
398 mContext, callingPackage, "addOnSubscriptionsChangedListener")) {
399 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700400 }
401
Wink Savillea374c3d2014-11-11 11:48:04 -0800402
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 synchronized (mRecords) {
404 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800405 IBinder b = callback.asBinder();
406 Record r = add(b);
407
408 if (r == null) {
409 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800410 }
411
Wink Savilled09c4ca2014-11-22 10:08:16 -0800412 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700413 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800414 r.callerUid = Binder.getCallingUid();
415 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800416 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700417 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800418 if (DBG) {
419 log("listen oscl: Register r=" + r);
420 }
421 // Always notify when registration occurs if there has been a notification.
422 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800423 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800424 if (VDBG) log("listen oscl: send to r=" + r);
425 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
426 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800427 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800428 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800429 remove(r.binder);
430 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800431 } else {
432 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800433 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800434 }
435 }
436
437 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800438 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 IOnSubscriptionsChangedListener callback) {
440 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800441 remove(callback.asBinder());
442 }
443
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 @Override
445 public void notifySubscriptionInfoChanged() {
446 if (VDBG) log("notifySubscriptionInfoChanged:");
447 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800448 if (!hasNotifySubscriptionInfoChangedOccurred) {
449 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
450 + mRecords.size());
451 }
452 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800453 mRemoveList.clear();
454 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800455 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800456 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800457 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
458 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
459 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800460 } catch (RemoteException ex) {
461 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
462 mRemoveList.add(r.binder);
463 }
464 }
465 }
466 handleRemoveListLocked();
467 }
468 }
469
470 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
472 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800473 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
474 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700475 }
476
477 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700478 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700479 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700480 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700481 }
482
Svet Ganov16a16892015-04-16 10:32:04 -0700483 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700484 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700485 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800486 mContext.getSystemService(AppOpsManager.class)
487 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700488 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700489 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700490 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
491 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700492 }
xinhe75c2c152014-10-16 11:49:45 -0700493
494 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800495 // Checks permission and throws SecurityException for disallowed operations. For pre-M
496 // apps whose runtime permission has been revoked, we return immediately to skip sending
497 // events to the app without crashing it.
498 if (!checkListenerPermission(events, callingPackage, "listen")) {
499 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700500 }
501
yifan.baie620ce72017-12-22 14:59:57 +0800502 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 synchronized (mRecords) {
504 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800505 IBinder b = callback.asBinder();
506 Record r = add(b);
507
508 if (r == null) {
509 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
xinhe43c50292014-09-18 17:56:48 -0700511
xinhe75c2c152014-10-16 11:49:45 -0700512 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700513 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800514 r.callerUid = Binder.getCallingUid();
515 r.callerPid = Binder.getCallingPid();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700516 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
517 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800518 r.canReadPhoneState =
519 isPhoneStateEvent && canReadPhoneState(callingPackage, "listen");
xinhe75c2c152014-10-16 11:49:45 -0700520 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
521 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800522 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800523 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700524 } else {//APP specify subID
525 r.subId = subId;
526 }
yifan.baie620ce72017-12-22 14:59:57 +0800527 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700529 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700530 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700531 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700532 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400534 try {
Wink Savillee380b982014-07-26 18:24:22 -0700535 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700536 r.callback.onServiceStateChanged(
537 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400538 } catch (RemoteException ex) {
539 remove(r.binder);
540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
542 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
543 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700544 int gsmSignalStrength = mSignalStrength[phoneId]
545 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700546 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
547 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 } catch (RemoteException ex) {
549 remove(r.binder);
550 }
551 }
552 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
553 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700554 r.callback.onMessageWaitingIndicatorChanged(
555 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 } catch (RemoteException ex) {
557 remove(r.binder);
558 }
559 }
560 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
561 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 r.callback.onCallForwardingIndicatorChanged(
563 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 } catch (RemoteException ex) {
565 remove(r.binder);
566 }
567 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700568 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400569 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700570 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700571 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800572 if (checkLocationAccess(r)) {
573 r.callback.onCellLocationChanged(
574 new Bundle(mCellLocation[phoneId]));
575 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400576 } catch (RemoteException ex) {
577 remove(r.binder);
578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
580 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
581 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700583 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 } catch (RemoteException ex) {
585 remove(r.binder);
586 }
587 }
588 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
589 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700590 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
591 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 } catch (RemoteException ex) {
593 remove(r.binder);
594 }
595 }
596 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
597 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700598 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 } catch (RemoteException ex) {
600 remove(r.binder);
601 }
602 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700603 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
604 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700605 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700606 } catch (RemoteException ex) {
607 remove(r.binder);
608 }
609 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700610 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
611 try {
612 r.callback.onOtaspChanged(mOtaspMode);
613 } catch (RemoteException ex) {
614 remove(r.binder);
615 }
616 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700617 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700618 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700619 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700620 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800621 if (checkLocationAccess(r)) {
622 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
623 }
John Wang963db55d2012-03-30 16:04:06 -0700624 } catch (RemoteException ex) {
625 remove(r.binder);
626 }
627 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200628 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
629 try {
630 r.callback.onPreciseCallStateChanged(mPreciseCallState);
631 } catch (RemoteException ex) {
632 remove(r.binder);
633 }
634 }
635 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
636 try {
637 r.callback.onPreciseDataConnectionStateChanged(
638 mPreciseDataConnectionState);
639 } catch (RemoteException ex) {
640 remove(r.binder);
641 }
642 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400643 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
644 try {
645 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
646 } catch (RemoteException ex) {
647 remove(r.binder);
648 }
649 }
fionaxu12312f62016-11-14 13:32:14 -0800650 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
651 try {
652 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
653 } catch (RemoteException ex) {
654 remove(r.binder);
655 }
656 }
657 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
658 try {
659 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
660 } catch (RemoteException ex) {
661 remove(r.binder);
662 }
663 }
zxuan35a47022018-01-04 11:24:04 -0800664 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
665 try {
666 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
667 } catch (RemoteException ex) {
668 remove(r.binder);
669 }
670 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800671 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
672 try {
673 r.callback.onPhysicalChannelConfigurationChanged(
674 mPhysicalChannelConfigs.get(phoneId));
675 } catch (RemoteException ex) {
676 remove(r.binder);
677 }
678 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 }
680 }
681 } else {
xinhe75c2c152014-10-16 11:49:45 -0700682 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 remove(callback.asBinder());
684 }
685 }
686
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800687 private boolean canReadPhoneState(String callingPackage, String message) {
688 try {
689 return TelephonyPermissions.checkCallingOrSelfReadPhoneState(
690 mContext, callingPackage, message);
691 } catch (SecurityException e) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700692 return false;
693 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700694 }
695
696 private String getCallIncomingNumber(Record record, int phoneId) {
697 // Hide the number if record's process has no READ_PHONE_STATE permission
698 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
699 }
700
Malcolm Chenabbfac22018-02-12 19:15:59 -0800701 private Record add(IBinder binder) {
702 Record r;
703
704 synchronized (mRecords) {
705 final int N = mRecords.size();
706 for (int i = 0; i < N; i++) {
707 r = mRecords.get(i);
708 if (binder == r.binder) {
709 // Already existed.
710 return r;
711 }
712 }
713 r = new Record();
714 r.binder = binder;
715 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
716
717 try {
718 binder.linkToDeath(r.deathRecipient, 0);
719 } catch (RemoteException e) {
720 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
721 // Binder already died. Return null.
722 return null;
723 }
724
725 mRecords.add(r);
726 if (DBG) log("add new record");
727 }
728
729 return r;
730 }
731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 private void remove(IBinder binder) {
733 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700734 final int recordCount = mRecords.size();
735 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800736 Record r = mRecords.get(i);
737 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800738 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800739 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
740 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800741 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800742
743 if (r.deathRecipient != null) {
744 try {
745 binder.unlinkToDeath(r.deathRecipient, 0);
746 } catch (NoSuchElementException e) {
747 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
748 + r + " e=" + e);
749 }
750 }
751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 mRecords.remove(i);
753 return;
754 }
755 }
756 }
757 }
758
759 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700760 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700761 return;
762 }
xinhe43c50292014-09-18 17:56:48 -0700763
764 if (VDBG) {
765 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
766 }
767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700769 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800770 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800771 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700773 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
774 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400776 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 }
778 }
779 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400780 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700782
783 // Called only by Telecomm to communicate call state across different phone accounts. So
784 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800785 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700786 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700787 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 }
789
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700790 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
791 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700792 if (!checkNotifyPermission("notifyCallState()")) {
793 return;
794 }
Wink Savillee380b982014-07-26 18:24:22 -0700795 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700796 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700797 + " state=" + state + " incomingNumber=" + incomingNumber);
798 }
799 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700800 if (validatePhoneId(phoneId)) {
801 mCallState[phoneId] = state;
802 mCallIncomingNumber[phoneId] = incomingNumber;
803 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800804 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700805 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800806 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700807 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700808 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
809 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700810 } catch (RemoteException ex) {
811 mRemoveList.add(r.binder);
812 }
813 }
814 }
815 }
816 handleRemoveListLocked();
817 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700818 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700819 }
820
Wink Saville63f03dd2014-10-23 10:44:45 -0700821 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700822 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700823 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700824 }
xinhe43c50292014-09-18 17:56:48 -0700825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700827 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
828 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700829 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700830 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700831 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700832 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700833 if (validatePhoneId(phoneId)) {
834 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700835
Wink Savillefb40dd42014-06-12 17:02:31 -0700836 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700837 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700838 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700839 + " phoneId=" + phoneId + " state=" + state);
840 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800841 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800842 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700843 try {
Wink Savillee380b982014-07-26 18:24:22 -0700844 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700845 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700846 + " subId=" + subId + " phoneId=" + phoneId
847 + " state=" + state);
848 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700849 r.callback.onServiceStateChanged(new ServiceState(state));
850 } catch (RemoteException ex) {
851 mRemoveList.add(r.binder);
852 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700855 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700856 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400858 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700860 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
862
fionaxu12312f62016-11-14 13:32:14 -0800863 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
864 int activationType, int activationState) {
865 if (!checkNotifyPermission("notifySimActivationState()")){
866 return;
867 }
868 if (VDBG) {
869 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
870 + "type=" + activationType + " state=" + activationState);
871 }
872 synchronized (mRecords) {
873 if (validatePhoneId(phoneId)) {
874 switch (activationType) {
875 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
876 mVoiceActivationState[phoneId] = activationState;
877 break;
878 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
879 mDataActivationState[phoneId] = activationState;
880 break;
881 default:
882 return;
883 }
884 for (Record r : mRecords) {
885 if (VDBG) {
886 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
887 + " phoneId=" + phoneId + "type=" + activationType
888 + " state=" + activationState);
889 }
890 try {
891 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
892 r.matchPhoneStateListenerEvent(
893 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
894 idMatch(r.subId, subId, phoneId)) {
895 if (DBG) {
896 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
897 + " subId=" + subId + " phoneId=" + phoneId
898 + " state=" + activationState);
899 }
900 r.callback.onVoiceActivationStateChanged(activationState);
901 }
902 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
903 r.matchPhoneStateListenerEvent(
904 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
905 idMatch(r.subId, subId, phoneId)) {
906 if (DBG) {
907 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
908 + " subId=" + subId + " phoneId=" + phoneId
909 + " state=" + activationState);
910 }
911 r.callback.onDataActivationStateChanged(activationState);
912 }
913 } catch (RemoteException ex) {
914 mRemoveList.add(r.binder);
915 }
916 }
917 } else {
918 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
919 }
920 handleRemoveListLocked();
921 }
922 }
923
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700924 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
925 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700926 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700927 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700928 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000929 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700930 log("notifySignalStrengthForPhoneId: subId=" + subId
931 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000932 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700935 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700936 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700937 mSignalStrength[phoneId] = signalStrength;
938 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000939 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700940 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000941 + " phoneId=" + phoneId + " ss=" + signalStrength);
942 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800943 if (r.matchPhoneStateListenerEvent(
944 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800945 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700946 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000947 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700948 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000949 + " subId=" + subId + " phoneId=" + phoneId
950 + " ss=" + signalStrength);
951 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700952 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
953 } catch (RemoteException ex) {
954 mRemoveList.add(r.binder);
955 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400956 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800957 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800958 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700959 try {
960 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700961 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000962 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700963 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000964 + " subId=" + subId + " phoneId=" + phoneId
965 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
966 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700967 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700968 } catch (RemoteException ex) {
969 mRemoveList.add(r.binder);
970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 }
972 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700973 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700974 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400976 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700978 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 }
980
Andrew Flynn1f452642015-04-14 22:16:04 -0400981 @Override
982 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000983 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
984
Andrew Flynn1f452642015-04-14 22:16:04 -0400985 if (VDBG) {
986 log("notifyCarrierNetworkChange: active=" + active);
987 }
988
989 synchronized (mRecords) {
990 mCarrierNetworkChangeState = active;
991 for (Record r : mRecords) {
992 if (r.matchPhoneStateListenerEvent(
993 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
994 try {
995 r.callback.onCarrierNetworkChange(active);
996 } catch (RemoteException ex) {
997 mRemoveList.add(r.binder);
998 }
999 }
1000 }
1001 handleRemoveListLocked();
1002 }
1003 }
1004
Wink Savilleb208a242012-07-25 14:08:09 -07001005 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001006 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001007 }
1008
Wink Saville63f03dd2014-10-23 10:44:45 -07001009 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001010 if (!checkNotifyPermission("notifyCellInfo()")) {
1011 return;
1012 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001013 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001014 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001015 + " cellInfo=" + cellInfo);
1016 }
yifan.baie620ce72017-12-22 14:59:57 +08001017 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001018 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001019 if (validatePhoneId(phoneId)) {
1020 mCellInfo.set(phoneId, cellInfo);
1021 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001022 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001023 idMatch(r.subId, subId, phoneId) &&
1024 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001025 try {
1026 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001027 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001028 }
1029 r.callback.onCellInfoChanged(cellInfo);
1030 } catch (RemoteException ex) {
1031 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001032 }
John Wang963db55d2012-03-30 16:04:06 -07001033 }
1034 }
1035 }
1036 handleRemoveListLocked();
1037 }
1038 }
1039
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001040 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1041 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1042 configs);
1043 }
1044
1045 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1046 List<PhysicalChannelConfig> configs) {
1047 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1048 return;
1049 }
1050
1051 if (VDBG) {
1052 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1053 }
1054
1055 synchronized (mRecords) {
1056 int phoneId = SubscriptionManager.getPhoneId(subId);
1057 if (validatePhoneId(phoneId)) {
1058 mPhysicalChannelConfigs.set(phoneId, configs);
1059 for (Record r : mRecords) {
1060 if (r.matchPhoneStateListenerEvent(
1061 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1062 && idMatch(r.subId, subId, phoneId)) {
1063 try {
1064 if (DBG_LOC) {
1065 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1066 + configs + " r=" + r);
1067 }
1068 r.callback.onPhysicalChannelConfigurationChanged(configs);
1069 } catch (RemoteException ex) {
1070 mRemoveList.add(r.binder);
1071 }
1072 }
1073 }
1074 }
1075 handleRemoveListLocked();
1076 }
1077 }
1078
xinhe43c50292014-09-18 17:56:48 -07001079 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001080 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001081 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001082 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001083 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001084 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001085 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001086 + " mwi=" + mwi);
1087 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001089 if (validatePhoneId(phoneId)) {
1090 mMessageWaiting[phoneId] = mwi;
1091 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001092 if (r.matchPhoneStateListenerEvent(
1093 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001094 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001095 try {
1096 r.callback.onMessageWaitingIndicatorChanged(mwi);
1097 } catch (RemoteException ex) {
1098 mRemoveList.add(r.binder);
1099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 }
1101 }
1102 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001103 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
1105 }
1106
zxuan35a47022018-01-04 11:24:04 -08001107 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1108 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1109 return;
1110 }
1111 if (VDBG) {
1112 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1113 + " state=" + state);
1114 }
1115 synchronized (mRecords) {
1116 if (validatePhoneId(phoneId)) {
1117 mMessageWaiting[phoneId] = state;
1118 for (Record r : mRecords) {
1119 if (r.matchPhoneStateListenerEvent(
1120 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1121 idMatch(r.subId, subId, phoneId)) {
1122 try {
1123 r.callback.onUserMobileDataStateChanged(state);
1124 } catch (RemoteException ex) {
1125 mRemoveList.add(r.binder);
1126 }
1127 }
1128 }
1129 }
1130 handleRemoveListLocked();
1131 }
1132 }
1133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001135 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001136 }
1137
Wink Saville63f03dd2014-10-23 10:44:45 -07001138 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001139 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001140 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001141 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001142 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001143 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001144 + " cfi=" + cfi);
1145 }
yifan.baie620ce72017-12-22 14:59:57 +08001146 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001148 if (validatePhoneId(phoneId)) {
1149 mCallForwarding[phoneId] = cfi;
1150 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001151 if (r.matchPhoneStateListenerEvent(
1152 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001153 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001154 try {
1155 r.callback.onCallForwardingIndicatorChanged(cfi);
1156 } catch (RemoteException ex) {
1157 mRemoveList.add(r.binder);
1158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 }
1160 }
1161 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001162 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 }
1164 }
1165
1166 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001167 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001168 }
1169
Wink Saville63f03dd2014-10-23 10:44:45 -07001170 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001171 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001172 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001173 }
yifan.baie620ce72017-12-22 14:59:57 +08001174 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001176 if (validatePhoneId(phoneId)) {
1177 mDataActivity[phoneId] = state;
1178 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001179 // Notify by correct subId.
1180 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1181 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001182 try {
1183 r.callback.onDataActivity(state);
1184 } catch (RemoteException ex) {
1185 mRemoveList.add(r.binder);
1186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 }
1188 }
1189 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001190 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 }
1192 }
1193
Jack Yubaeec622017-05-01 17:01:11 -07001194 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001195 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001196 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001197 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001198 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001199 networkCapabilities, networkType, roaming);
1200 }
1201
Wink Saville63f03dd2014-10-23 10:44:45 -07001202 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001203 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001204 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1205 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001206 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001207 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001208 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001209 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001210 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001211 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001212 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001213 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001214 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001215 }
yifan.baie620ce72017-12-22 14:59:57 +08001216 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001218 if (validatePhoneId(phoneId)) {
1219 boolean modified = false;
1220 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001221 if (!mConnectedApns[phoneId].contains(apnType)) {
1222 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001223 if (mDataConnectionState[phoneId] != state) {
1224 mDataConnectionState[phoneId] = state;
1225 modified = true;
1226 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001228 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001229 if (mConnectedApns[phoneId].remove(apnType)) {
1230 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001231 mDataConnectionState[phoneId] = state;
1232 modified = true;
1233 } else {
1234 // leave mDataConnectionState as is and
1235 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001236 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001237 }
1238 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001239 mDataConnectionLinkProperties[phoneId] = linkProperties;
1240 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1241 if (mDataConnectionNetworkType[phoneId] != networkType) {
1242 mDataConnectionNetworkType[phoneId] = networkType;
1243 // need to tell registered listeners about the new network type
1244 modified = true;
1245 }
1246 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001247 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1248 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1249 log(str);
1250 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001251 for (Record r : mRecords) {
1252 if (r.matchPhoneStateListenerEvent(
1253 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1254 idMatch(r.subId, subId, phoneId)) {
1255 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001256 if (DBG) {
1257 log("Notify data connection state changed on sub: " + subId);
1258 }
1259 r.callback.onDataConnectionStateChanged(
1260 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001261 mDataConnectionNetworkType[phoneId]);
1262 } catch (RemoteException ex) {
1263 mRemoveList.add(r.binder);
1264 }
1265 }
1266 }
1267 handleRemoveListLocked();
1268 }
1269 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1270 apnType, apn, reason, linkProperties, "");
1271 for (Record r : mRecords) {
1272 if (r.matchPhoneStateListenerEvent(
1273 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1274 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001275 r.callback.onPreciseDataConnectionStateChanged(
1276 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001277 } catch (RemoteException ex) {
1278 mRemoveList.add(r.binder);
1279 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001280 }
1281 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001282 }
1283 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 }
Jack Yubaeec622017-05-01 17:01:11 -07001285 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001286 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001287 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1288 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 }
1290
Robert Greenwalt02648a42010-05-18 10:52:51 -07001291 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001292 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001293 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001294 }
1295
Wink Saville63f03dd2014-10-23 10:44:45 -07001296 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001297 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001298 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001299 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001300 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001301 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001302 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001303 + " reason=" + reason + " apnType=" + apnType);
1304 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001306 mPreciseDataConnectionState = new PreciseDataConnectionState(
1307 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1308 apnType, "", reason, null, "");
1309 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001310 if (r.matchPhoneStateListenerEvent(
1311 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001312 try {
1313 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1314 } catch (RemoteException ex) {
1315 mRemoveList.add(r.binder);
1316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 }
1318 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001319 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001321 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001322 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1323 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 }
1325
1326 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001327 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001328 }
1329
Wink Saville63f03dd2014-10-23 10:44:45 -07001330 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001331 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001332 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001333 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001334 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001335 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001336 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001337 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001338 + " cellLocation=" + cellLocation);
1339 }
yifan.baie620ce72017-12-22 14:59:57 +08001340 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001342 if (validatePhoneId(phoneId)) {
1343 mCellLocation[phoneId] = cellLocation;
1344 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001345 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001346 idMatch(r.subId, subId, phoneId) &&
1347 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001348 try {
1349 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001350 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001351 + " r=" + r);
1352 }
1353 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1354 } catch (RemoteException ex) {
1355 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001356 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 }
1359 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001360 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001361 }
1362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363
Wink Savillefd2d0132010-10-28 14:22:26 -07001364 public void notifyOtaspChanged(int otaspMode) {
1365 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1366 return;
1367 }
1368 synchronized (mRecords) {
1369 mOtaspMode = otaspMode;
1370 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001371 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001372 try {
1373 r.callback.onOtaspChanged(otaspMode);
1374 } catch (RemoteException ex) {
1375 mRemoveList.add(r.binder);
1376 }
1377 }
1378 }
1379 handleRemoveListLocked();
1380 }
1381 }
1382
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001383 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1384 int backgroundCallState) {
1385 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1386 return;
1387 }
1388 synchronized (mRecords) {
1389 mRingingCallState = ringingCallState;
1390 mForegroundCallState = foregroundCallState;
1391 mBackgroundCallState = backgroundCallState;
1392 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1393 backgroundCallState,
1394 DisconnectCause.NOT_VALID,
1395 PreciseDisconnectCause.NOT_VALID);
1396 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001397 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001398 try {
1399 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1400 } catch (RemoteException ex) {
1401 mRemoveList.add(r.binder);
1402 }
1403 }
1404 }
1405 handleRemoveListLocked();
1406 }
1407 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1408 DisconnectCause.NOT_VALID,
1409 PreciseDisconnectCause.NOT_VALID);
1410 }
1411
1412 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1413 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1414 return;
1415 }
1416 synchronized (mRecords) {
1417 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1418 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1419 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001420 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001421 try {
1422 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1423 } catch (RemoteException ex) {
1424 mRemoveList.add(r.binder);
1425 }
1426 }
1427 }
1428 handleRemoveListLocked();
1429 }
1430 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1431 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1432 }
1433
1434 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1435 String apn, String failCause) {
1436 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1437 return;
1438 }
1439 synchronized (mRecords) {
1440 mPreciseDataConnectionState = new PreciseDataConnectionState(
1441 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1442 apnType, apn, reason, null, failCause);
1443 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001444 if (r.matchPhoneStateListenerEvent(
1445 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001446 try {
1447 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1448 } catch (RemoteException ex) {
1449 mRemoveList.add(r.binder);
1450 }
1451 }
1452 }
1453 handleRemoveListLocked();
1454 }
1455 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1456 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1457 }
1458
Wink Savillefb40dd42014-06-12 17:02:31 -07001459 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1460 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1461 return;
1462 }
1463 synchronized (mRecords) {
1464 mVoLteServiceState = lteState;
1465 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001466 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001467 try {
1468 r.callback.onVoLteServiceStateChanged(
1469 new VoLteServiceState(mVoLteServiceState));
1470 } catch (RemoteException ex) {
1471 mRemoveList.add(r.binder);
1472 }
1473 }
1474 }
1475 handleRemoveListLocked();
1476 }
1477 }
1478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001480 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1481 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1482
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001483 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001486 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001488 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301489 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001490 pw.println("Phone Id=" + i);
1491 pw.increaseIndent();
1492 pw.println("mCallState=" + mCallState[i]);
1493 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1494 pw.println("mServiceState=" + mServiceState[i]);
1495 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1496 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001497 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001498 pw.println("mSignalStrength=" + mSignalStrength[i]);
1499 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1500 pw.println("mCallForwarding=" + mCallForwarding[i]);
1501 pw.println("mDataActivity=" + mDataActivity[i]);
1502 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001503 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1504 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301505 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001506 pw.println("mCellLocation=" + mCellLocation[i]);
1507 pw.println("mCellInfo=" + mCellInfo.get(i));
1508 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301509 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001510 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1511 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1512 pw.println("mPreciseCallState=" + mPreciseCallState);
1513 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1514 pw.println("mRingingCallState=" + mRingingCallState);
1515 pw.println("mForegroundCallState=" + mForegroundCallState);
1516 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1517 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1518
1519 pw.decreaseIndent();
1520
1521 pw.println("local logs:");
1522 pw.increaseIndent();
1523 mLocalLog.dump(fd, pw, args);
1524 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001525 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001526 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001527 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001528 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001530 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 }
1532 }
1533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 //
1535 // the legacy intent broadcasting
1536 //
1537
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001538 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001539 long ident = Binder.clearCallingIdentity();
1540 try {
1541 mBatteryStats.notePhoneState(state.getState());
1542 } catch (RemoteException re) {
1543 // Can't do much
1544 } finally {
1545 Binder.restoreCallingIdentity(ident);
1546 }
1547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001549 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 Bundle data = new Bundle();
1551 state.fillInNotifierBundle(data);
1552 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001553 // Pass the subscription along with the intent.
1554 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001555 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001556 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 }
1558
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001559 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1560 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001561 long ident = Binder.clearCallingIdentity();
1562 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001563 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001564 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001565 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001566 } finally {
1567 Binder.restoreCallingIdentity(ident);
1568 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001571 Bundle data = new Bundle();
1572 signalStrength.fillInNotifierBundle(data);
1573 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001574 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001575 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001576 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 }
1578
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001579 /**
1580 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1581 * a valid subId, in which case this function fires a subId-specific intent, or it
1582 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1583 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1584 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001585 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1586 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 long ident = Binder.clearCallingIdentity();
1588 try {
1589 if (state == TelephonyManager.CALL_STATE_IDLE) {
1590 mBatteryStats.notePhoneOff();
1591 } else {
1592 mBatteryStats.notePhoneOn();
1593 }
1594 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001595 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 } finally {
1597 Binder.restoreCallingIdentity(ident);
1598 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001601 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001602 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 if (!TextUtils.isEmpty(incomingNumber)) {
1604 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1605 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001606
1607 // If a valid subId was specified, we should fire off a subId-specific state
1608 // change intent and include the subId.
1609 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1610 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1611 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1612 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001613 // If the phoneId is invalid, the broadcast is for overall call state.
1614 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1615 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1616 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001617
Brad Ebinger51de96a2017-04-21 17:05:18 -07001618 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1619 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1620
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001621 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1622 // that have the runtime one
1623 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1624 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001625 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001626 android.Manifest.permission.READ_PHONE_STATE,
1627 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
1629
Robert Greenwalt42acef32009-08-12 16:08:25 -07001630 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001631 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001632 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001633 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001634 // Note: not reporting to the battery stats service here, because the
1635 // status bar takes care of that after taking into account all of the
1636 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001638 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001639 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001640 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001641 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 }
1643 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001644 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001646 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001647 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001648 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001649 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001650 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001651 }
1652 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001653 if (networkCapabilities != null) {
1654 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001655 }
Wink Savillea639b312012-07-10 12:37:54 -07001656 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001657
Wink Savillea639b312012-07-10 12:37:54 -07001658 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1659 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001660 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001661 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 }
1663
Wink Savillefb40dd42014-06-12 17:02:31 -07001664 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001665 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001667 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1668 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001669 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001670 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001672
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001673 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1674 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1675 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1676 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1677 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1678 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1679 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1680 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1681 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1682 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1683 }
1684
1685 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001686 String apnType, String apn, String reason, LinkProperties linkProperties,
1687 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001688 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1689 intent.putExtra(PhoneConstants.STATE_KEY, state);
1690 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1691 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1692 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1693 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001694 if (linkProperties != null) {
1695 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1696 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001697 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1698
1699 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1700 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1701 }
1702
Andrew Flynnceaed682015-06-09 12:36:58 +00001703 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001704 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001705 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001706 }
1707
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001708 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1709 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001710 }
1711
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001712 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001713 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001714 return true;
1715 }
1716 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001717 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001718 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001719 return false;
1720 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001721
Andrew Flynn1f452642015-04-14 22:16:04 -04001722 private boolean checkNotifyPermission() {
1723 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1724 == PackageManager.PERMISSION_GRANTED;
1725 }
1726
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001727 private boolean checkListenerPermission(int events, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001728 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001729 mContext.enforceCallingOrSelfPermission(
1730 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001731 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1732 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1733 return false;
1734 }
John Wang963db55d2012-03-30 16:04:06 -07001735 }
1736
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001737 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1739 mContext, callingPackage, message)) {
1740 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001741 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001742 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001743
1744 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1745 mContext.enforceCallingOrSelfPermission(
1746 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001747 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001748
1749 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001750 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001751
1752 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001753 int size = mRemoveList.size();
1754 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1755 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001756 for (IBinder b: mRemoveList) {
1757 remove(b);
1758 }
1759 mRemoveList.clear();
1760 }
1761 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001762
1763 private boolean validateEventsAndUserLocked(Record r, int events) {
1764 int foregroundUser;
1765 long callingIdentity = Binder.clearCallingIdentity();
1766 boolean valid = false;
1767 try {
1768 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001769 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1770 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001771 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001772 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001773 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001774 + " r.events=" + r.events + " events=" + events);
1775 }
1776 } finally {
1777 Binder.restoreCallingIdentity(callingIdentity);
1778 }
1779 return valid;
1780 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001781
1782 private boolean validatePhoneId(int phoneId) {
1783 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001784 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001785 return valid;
1786 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001787
1788 private static void log(String s) {
1789 Rlog.d(TAG, s);
1790 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001791
xinhe8b79fb62014-11-05 14:55:03 -08001792 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001793
1794 if(subId < 0) {
1795 // Invalid case, we need compare phoneId with default one.
1796 return (mDefaultPhoneId == phoneId);
1797 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001798 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001799 return (subId == mDefaultSubId);
1800 } else {
1801 return (rSubId == subId);
1802 }
1803 }
1804
Hall Liu5fb337f2017-11-22 17:38:15 -08001805 private boolean checkLocationAccess(Record r) {
1806 long token = Binder.clearCallingIdentity();
1807 try {
1808 return LocationAccessPolicy.canAccessCellLocation(mContext,
1809 r.callingPackage, r.callerUid, r.callerPid);
1810 } finally {
1811 Binder.restoreCallingIdentity(token);
1812 }
1813 }
1814
xinhee9f16402014-09-25 16:39:28 -07001815 private void checkPossibleMissNotify(Record r, int phoneId) {
1816 int events = r.events;
1817
1818 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1819 try {
1820 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1821 mServiceState[phoneId]);
1822 r.callback.onServiceStateChanged(
1823 new ServiceState(mServiceState[phoneId]));
1824 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001825 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001826 }
1827 }
1828
1829 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1830 try {
1831 SignalStrength signalStrength = mSignalStrength[phoneId];
1832 if (DBG) {
1833 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1834 }
1835 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1836 } catch (RemoteException ex) {
1837 mRemoveList.add(r.binder);
1838 }
1839 }
1840
1841 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1842 try {
1843 int gsmSignalStrength = mSignalStrength[phoneId]
1844 .getGsmSignalStrength();
1845 if (DBG) {
1846 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1847 gsmSignalStrength);
1848 }
1849 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1850 : gsmSignalStrength));
1851 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001852 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001853 }
1854 }
1855
1856 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1857 try {
1858 if (DBG_LOC) {
1859 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1860 + mCellInfo.get(phoneId));
1861 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001862 if (checkLocationAccess(r)) {
1863 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1864 }
xinhee9f16402014-09-25 16:39:28 -07001865 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001866 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001867 }
1868 }
1869
zxuan35a47022018-01-04 11:24:04 -08001870 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1871 try {
1872 if (VDBG) {
1873 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1874 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1875 }
1876 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1877 } catch (RemoteException ex) {
1878 mRemoveList.add(r.binder);
1879 }
1880 }
1881
xinhee9f16402014-09-25 16:39:28 -07001882 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1883 try {
1884 if (VDBG) {
1885 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1886 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1887 }
1888 r.callback.onMessageWaitingIndicatorChanged(
1889 mMessageWaiting[phoneId]);
1890 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001891 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001892 }
1893 }
1894
1895 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1896 try {
1897 if (VDBG) {
1898 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1899 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1900 }
1901 r.callback.onCallForwardingIndicatorChanged(
1902 mCallForwarding[phoneId]);
1903 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001904 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001905 }
1906 }
1907
1908 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1909 try {
1910 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1911 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001912 if (checkLocationAccess(r)) {
1913 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1914 }
xinhee9f16402014-09-25 16:39:28 -07001915 } catch (RemoteException ex) {
1916 mRemoveList.add(r.binder);
1917 }
1918 }
1919
1920 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1921 try {
1922 if (DBG) {
1923 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1924 + "=" + mDataConnectionState[phoneId]
1925 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1926 + ")");
1927 }
1928 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1929 mDataConnectionNetworkType[phoneId]);
1930 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001931 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001932 }
1933 }
1934 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935}