blob: 0f9fe83ba6a52015f9ee083b8148820f69de2c50 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Hall Liu5fb337f2017-11-22 17:38:15 -080038import android.telephony.LocationAccessPolicy;
Malcolm Chen5ee5c142018-08-08 20:27:45 -070039import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070040import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080041import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020042import android.telephony.PreciseCallState;
43import android.telephony.PreciseDataConnectionState;
44import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070045import android.telephony.Rlog;
46import android.telephony.ServiceState;
47import android.telephony.SignalStrength;
48import android.telephony.SubscriptionManager;
49import android.telephony.TelephonyManager;
50import android.telephony.VoLteServiceState;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
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;
Jack Yud19b6ae2017-04-05 14:12:09 -070068import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080069import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071/**
Wink Savillee9b06d72009-05-18 21:47:50 -070072 * Since phone process can be restarted, this class provides a centralized place
73 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070074 *
75 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
76 * and 15973975 by saving the phoneId of the registrant and then using the
77 * phoneId when deciding to to make a callback. This is necessary because
78 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070079 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070080 * the dummy value conversion we properly do the callbacks.
81 *
82 * Eventually we may want to remove the notion of dummy value but for now this
83 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 */
85class TelephonyRegistry extends ITelephonyRegistry.Stub {
86 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070087 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070088 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070089 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080092 Context context;
93
Svet Ganov16a16892015-04-16 10:32:04 -070094 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
Malcolm Chenabbfac22018-02-12 19:15:59 -080098 TelephonyRegistryDeathRecipient deathRecipient;
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800101 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen27829e22018-09-04 22:12:31 -0700102 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700103
Hall Liu5fb337f2017-11-22 17:38:15 -0800104 int callerUid;
105 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700108
Wink Savilled09c4ca2014-11-22 10:08:16 -0800109 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700110
Wink Savilled09c4ca2014-11-22 10:08:16 -0800111 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800112
113 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
Malcolm Chen27829e22018-09-04 22:12:31 -0700121 boolean matchOnOpportunisticSubscriptionsChangedListener() {
122 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
123 }
124
Tyler Gunnf955e562018-04-26 14:43:31 -0700125 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800126 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700127 return TelephonyPermissions.checkReadCallLog(
128 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800129 } catch (SecurityException e) {
130 return false;
131 }
132 }
133
Wink Savillea12a7b32012-09-20 10:09:45 -0700134 @Override
135 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700136 return "{callingPackage=" + callingPackage + " binder=" + binder
137 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800138 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen27829e22018-09-04 22:12:31 -0700139 + onSubscriptionsChangedListenerCallback
140 + " onOpportunisticSubscriptionsChangedListenererCallback="
141 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800142 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800143 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 }
146
147 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700148
Joe Onorato163d8d92010-10-21 13:21:20 -0400149 // access should be inside synchronized (mRecords) for these two fields
150 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
151 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 private final IBatteryStats mBatteryStats;
154
Svet Ganov16a16892015-04-16 10:32:04 -0700155 private final AppOpsManager mAppOps;
156
Malcolm Chen27829e22018-09-04 22:12:31 -0700157 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
158
159 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800160
Wink Savillefb40dd42014-06-12 17:02:31 -0700161 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700162
Wink Savillefb40dd42014-06-12 17:02:31 -0700163 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700164
Wink Savillefb40dd42014-06-12 17:02:31 -0700165 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700166
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700168
fionaxu12312f62016-11-14 13:32:14 -0800169 private int[] mVoiceActivationState;
170
171 private int[] mDataActivationState;
172
zxuan35a47022018-01-04 11:24:04 -0800173 private boolean[] mUserMobileDataState;
174
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700180
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700182
Jack Yub1bac542018-03-14 16:23:38 -0700183 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700184 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700185
Wink Savillefb40dd42014-06-12 17:02:31 -0700186 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187
Wink Savillefb40dd42014-06-12 17:02:31 -0700188 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700189
Nathan Harold016e9c62016-12-14 11:24:48 -0800190 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700191
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 private ArrayList<List<CellInfo>> mCellInfo = null;
193
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800194 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
195
Wink Savillefb40dd42014-06-12 17:02:31 -0700196 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
197
Wink Savilled09c4ca2014-11-22 10:08:16 -0800198 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700199
Wink Savilled09c4ca2014-11-22 10:08:16 -0800200 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700201
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200202 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
203
204 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
205
206 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
207
208 private PreciseCallState mPreciseCallState = new PreciseCallState();
209
Andrew Flynn1f452642015-04-14 22:16:04 -0400210 private boolean mCarrierNetworkChangeState = false;
211
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700212 private PhoneCapability mPhoneCapability = null;
213
Jack Yud19b6ae2017-04-05 14:12:09 -0700214 private final LocalLog mLocalLog = new LocalLog(100);
215
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200216 private PreciseDataConnectionState mPreciseDataConnectionState =
217 new PreciseDataConnectionState();
218
Hall Liu70bbc162018-03-02 17:44:46 -0800219 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
220 PhoneStateListener.LISTEN_CELL_LOCATION
221 | PhoneStateListener.LISTEN_CELL_INFO;
222
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700223 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700224 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700225 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
226 PhoneStateListener.LISTEN_VOLTE_STATE;
227
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200228 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
229 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
230 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
231
Wink Savillea12a7b32012-09-20 10:09:45 -0700232 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700233 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700234
235 private final Handler mHandler = new Handler() {
236 @Override
237 public void handleMessage(Message msg) {
238 switch (msg.what) {
239 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700240 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700241 int numPhones = TelephonyManager.getDefault().getPhoneCount();
242 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700243 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700244 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700245 }
246 break;
247 }
xinhee9f16402014-09-25 16:39:28 -0700248 case MSG_UPDATE_DEFAULT_SUB: {
249 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700250 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700251 if (VDBG) {
252 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
253 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
254 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
255 }
256
257 //Due to possible risk condition,(notify call back using the new
258 //defaultSubId comes before new defaultSubId update) we need to recall all
259 //possible missed notify callback
260 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700261 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800262 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700263 checkPossibleMissNotify(r, newDefaultPhoneId);
264 }
265 }
266 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700267 }
268 mDefaultSubId = newDefaultSubId;
269 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700270 }
271 }
272 }
273 };
274
Malcolm Chenabbfac22018-02-12 19:15:59 -0800275 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
276
277 private final IBinder binder;
278
279 TelephonyRegistryDeathRecipient(IBinder binder) {
280 this.binder = binder;
281 }
282
283 @Override
284 public void binderDied() {
285 if (DBG) log("binderDied " + binder);
286 remove(binder);
287 }
288 }
289
Wink Savillea12a7b32012-09-20 10:09:45 -0700290 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
291 @Override
292 public void onReceive(Context context, Intent intent) {
293 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700294 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700295 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700296 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700297 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700298 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700299 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700300 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800301 PhoneConstants.SUBSCRIPTION_KEY,
302 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700303 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
304 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700305 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700306 log("onReceive:current mDefaultSubId=" + mDefaultSubId
307 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
308 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700309 }
xinhee9f16402014-09-25 16:39:28 -0700310
Junda Liu985f52c2015-02-23 16:06:51 -0800311 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700312 || (newDefaultPhoneId != mDefaultPhoneId))) {
313 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
314 newDefaultPhoneId, 0, newDefaultSubIdObj));
315 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700316 }
317 }
318 };
319
Wink Savillee9b06d72009-05-18 21:47:50 -0700320 // we keep a copy of all of the state so we can send it out when folks
321 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700323 // In these calls we call with the lock held. This is safe becasuse remote
324 // calls go through a oneway interface and local calls going through a
325 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326
327 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700328 CellLocation location = CellLocation.getEmpty();
329
Wink Savillefb40dd42014-06-12 17:02:31 -0700330 mContext = context;
331 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700332
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700334 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 mNumPhones = numPhones;
336 mCallState = new int[numPhones];
337 mDataActivity = new int[numPhones];
338 mDataConnectionState = new int[numPhones];
339 mDataConnectionNetworkType = new int[numPhones];
340 mCallIncomingNumber = new String[numPhones];
341 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800342 mVoiceActivationState = new int[numPhones];
343 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800344 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700345 mSignalStrength = new SignalStrength[numPhones];
346 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700347 mCallForwarding = new boolean[numPhones];
348 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700349 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800350 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700351 for (int i = 0; i < numPhones; i++) {
352 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
353 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
354 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800355 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
356 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700357 mCallIncomingNumber[i] = "";
358 mServiceState[i] = new ServiceState();
359 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800360 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700361 mMessageWaiting[i] = false;
362 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700363 mCellLocation[i] = new Bundle();
364 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700365 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 }
367
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700368 // Note that location can be null for non-phone builds like
369 // like the generic one.
370 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700371 for (int i = 0; i < numPhones; i++) {
372 location.fillInNotifierBundle(mCellLocation[i]);
373 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700374 }
Svet Ganov16a16892015-04-16 10:32:04 -0700375
376 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 }
378
Svetoslav Ganova0027152013-06-25 14:59:53 -0700379 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700380 // Watch for interesting updates
381 final IntentFilter filter = new IntentFilter();
382 filter.addAction(Intent.ACTION_USER_SWITCHED);
383 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700384 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700385 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700386 mContext.registerReceiver(mBroadcastReceiver, filter);
387 }
388
389 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700390 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800391 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700392 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800394 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700395 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
396 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800397 + " callback.asBinder=" + callback.asBinder());
398 }
399
Wink Savilled09c4ca2014-11-22 10:08:16 -0800400 synchronized (mRecords) {
401 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800402 IBinder b = callback.asBinder();
403 Record r = add(b);
404
405 if (r == null) {
406 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800407 }
408
Jeff Davidson29da89f2018-02-28 17:50:16 -0800409 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800410 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700411 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800412 r.callerUid = Binder.getCallingUid();
413 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 r.events = 0;
415 if (DBG) {
416 log("listen oscl: Register r=" + r);
417 }
418 // Always notify when registration occurs if there has been a notification.
Malcolm Chen27829e22018-09-04 22:12:31 -0700419 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800421 if (VDBG) log("listen oscl: send to r=" + r);
422 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
423 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800425 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800426 remove(r.binder);
427 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800428 } else {
Malcolm Chen27829e22018-09-04 22:12:31 -0700429 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800430 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800431 }
432 }
433
434 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800435 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800436 IOnSubscriptionsChangedListener callback) {
437 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800438 remove(callback.asBinder());
439 }
440
Malcolm Chen27829e22018-09-04 22:12:31 -0700441
442 @Override
443 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
444 IOnSubscriptionsChangedListener callback) {
445 int callerUserId = UserHandle.getCallingUserId();
446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
447 if (VDBG) {
448 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
449 + " callerUserId=" + callerUserId + " callback=" + callback
450 + " callback.asBinder=" + callback.asBinder());
451 }
452
453 synchronized (mRecords) {
454 // register
455 IBinder b = callback.asBinder();
456 Record r = add(b);
457
458 if (r == null) {
459 return;
460 }
461
462 r.context = mContext;
463 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
464 r.callingPackage = callingPackage;
465 r.callerUid = Binder.getCallingUid();
466 r.callerPid = Binder.getCallingPid();
467 r.events = 0;
468 if (DBG) {
469 log("listen ooscl: Register r=" + r);
470 }
471 // Always notify when registration occurs if there has been a notification.
472 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
473 try {
474 if (VDBG) log("listen ooscl: send to r=" + r);
475 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
476 if (VDBG) log("listen ooscl: sent to r=" + r);
477 } catch (RemoteException e) {
478 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
479 remove(r.binder);
480 }
481 } else {
482 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
483 }
484 }
485 }
486
Wink Savillea374c3d2014-11-11 11:48:04 -0800487 @Override
488 public void notifySubscriptionInfoChanged() {
489 if (VDBG) log("notifySubscriptionInfoChanged:");
490 synchronized (mRecords) {
Malcolm Chen27829e22018-09-04 22:12:31 -0700491 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800492 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
493 + mRecords.size());
494 }
Malcolm Chen27829e22018-09-04 22:12:31 -0700495 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800496 mRemoveList.clear();
497 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800498 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800499 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800500 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
501 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
502 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800503 } catch (RemoteException ex) {
504 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
505 mRemoveList.add(r.binder);
506 }
507 }
508 }
509 handleRemoveListLocked();
510 }
511 }
512
513 @Override
Malcolm Chen27829e22018-09-04 22:12:31 -0700514 public void notifyOpportunisticSubscriptionInfoChanged() {
515 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
516 synchronized (mRecords) {
517 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
518 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
519 + mRecords.size());
520 }
521 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
522 mRemoveList.clear();
523 for (Record r : mRecords) {
524 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
525 try {
526 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
527 r.onOpportunisticSubscriptionsChangedListenerCallback
528 .onSubscriptionsChanged();
529 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
530 } catch (RemoteException ex) {
531 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
532 mRemoveList.add(r.binder);
533 }
534 }
535 }
536 handleRemoveListLocked();
537 }
538 }
539
540 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
542 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800543 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
544 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700545 }
546
547 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700548 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700549 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700550 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700551 }
552
Svet Ganov16a16892015-04-16 10:32:04 -0700553 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700554 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700555 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700557 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700558 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700559 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
560 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700561 }
xinhe75c2c152014-10-16 11:49:45 -0700562
563 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800564 // Checks permission and throws SecurityException for disallowed operations. For pre-M
565 // apps whose runtime permission has been revoked, we return immediately to skip sending
566 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800567 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800568 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700569 }
570
yifan.baie620ce72017-12-22 14:59:57 +0800571 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 synchronized (mRecords) {
573 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800574 IBinder b = callback.asBinder();
575 Record r = add(b);
576
577 if (r == null) {
578 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
xinhe43c50292014-09-18 17:56:48 -0700580
Jeff Davidson29da89f2018-02-28 17:50:16 -0800581 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700582 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700583 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800584 r.callerUid = Binder.getCallingUid();
585 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700586 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
587 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800588 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800589 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700590 } else {//APP specify subID
591 r.subId = subId;
592 }
yifan.baie620ce72017-12-22 14:59:57 +0800593 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700595 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700596 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700597 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700598 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400600 try {
Wink Savillee380b982014-07-26 18:24:22 -0700601 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 r.callback.onServiceStateChanged(
603 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400604 } catch (RemoteException ex) {
605 remove(r.binder);
606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 }
608 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
609 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700610 int gsmSignalStrength = mSignalStrength[phoneId]
611 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700612 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
613 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 } catch (RemoteException ex) {
615 remove(r.binder);
616 }
617 }
618 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
619 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700620 r.callback.onMessageWaitingIndicatorChanged(
621 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 } catch (RemoteException ex) {
623 remove(r.binder);
624 }
625 }
626 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
627 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700628 r.callback.onCallForwardingIndicatorChanged(
629 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 } catch (RemoteException ex) {
631 remove(r.binder);
632 }
633 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700634 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400635 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700636 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700637 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800638 if (checkLocationAccess(r)) {
639 r.callback.onCellLocationChanged(
640 new Bundle(mCellLocation[phoneId]));
641 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400642 } catch (RemoteException ex) {
643 remove(r.binder);
644 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 }
646 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
647 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700648 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700649 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 } catch (RemoteException ex) {
651 remove(r.binder);
652 }
653 }
654 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
655 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700656 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
657 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 } catch (RemoteException ex) {
659 remove(r.binder);
660 }
661 }
662 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
663 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700664 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 } catch (RemoteException ex) {
666 remove(r.binder);
667 }
668 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700669 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
670 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700671 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700672 } catch (RemoteException ex) {
673 remove(r.binder);
674 }
675 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700676 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
677 try {
678 r.callback.onOtaspChanged(mOtaspMode);
679 } catch (RemoteException ex) {
680 remove(r.binder);
681 }
682 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700683 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700684 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700685 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700686 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800687 if (checkLocationAccess(r)) {
688 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
689 }
John Wang963db55d2012-03-30 16:04:06 -0700690 } catch (RemoteException ex) {
691 remove(r.binder);
692 }
693 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200694 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
695 try {
696 r.callback.onPreciseCallStateChanged(mPreciseCallState);
697 } catch (RemoteException ex) {
698 remove(r.binder);
699 }
700 }
701 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
702 try {
703 r.callback.onPreciseDataConnectionStateChanged(
704 mPreciseDataConnectionState);
705 } catch (RemoteException ex) {
706 remove(r.binder);
707 }
708 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400709 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
710 try {
711 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
712 } catch (RemoteException ex) {
713 remove(r.binder);
714 }
715 }
fionaxu12312f62016-11-14 13:32:14 -0800716 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
717 try {
718 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
719 } catch (RemoteException ex) {
720 remove(r.binder);
721 }
722 }
723 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
724 try {
725 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
726 } catch (RemoteException ex) {
727 remove(r.binder);
728 }
729 }
zxuan35a47022018-01-04 11:24:04 -0800730 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
731 try {
732 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
733 } catch (RemoteException ex) {
734 remove(r.binder);
735 }
736 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800737 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
738 try {
739 r.callback.onPhysicalChannelConfigurationChanged(
740 mPhysicalChannelConfigs.get(phoneId));
741 } catch (RemoteException ex) {
742 remove(r.binder);
743 }
744 }
Malcolm Chen5ee5c142018-08-08 20:27:45 -0700745 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
746 try {
747 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
748 } catch (RemoteException ex) {
749 remove(r.binder);
750 }
751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 }
753 }
754 } else {
xinhe75c2c152014-10-16 11:49:45 -0700755 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 remove(callback.asBinder());
757 }
758 }
759
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700760 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700761 // Only reveal the incoming number if the record has read call log permission.
762 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700763 }
764
Malcolm Chenabbfac22018-02-12 19:15:59 -0800765 private Record add(IBinder binder) {
766 Record r;
767
768 synchronized (mRecords) {
769 final int N = mRecords.size();
770 for (int i = 0; i < N; i++) {
771 r = mRecords.get(i);
772 if (binder == r.binder) {
773 // Already existed.
774 return r;
775 }
776 }
777 r = new Record();
778 r.binder = binder;
779 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
780
781 try {
782 binder.linkToDeath(r.deathRecipient, 0);
783 } catch (RemoteException e) {
784 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
785 // Binder already died. Return null.
786 return null;
787 }
788
789 mRecords.add(r);
790 if (DBG) log("add new record");
791 }
792
793 return r;
794 }
795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 private void remove(IBinder binder) {
797 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700798 final int recordCount = mRecords.size();
799 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800800 Record r = mRecords.get(i);
801 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800802 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800803 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
804 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800805 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800806
807 if (r.deathRecipient != null) {
808 try {
809 binder.unlinkToDeath(r.deathRecipient, 0);
810 } catch (NoSuchElementException e) {
811 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
812 + r + " e=" + e);
813 }
814 }
815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 mRecords.remove(i);
817 return;
818 }
819 }
820 }
821 }
822
Tyler Gunnf955e562018-04-26 14:43:31 -0700823 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700824 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700825 return;
826 }
xinhe43c50292014-09-18 17:56:48 -0700827
828 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700829 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700830 }
831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700833 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800834 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800835 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700837 // Ensure the listener has read call log permission; if they do not return
838 // an empty phone number.
839 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
840 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400842 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 }
844 }
845 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400846 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700848
849 // Called only by Telecomm to communicate call state across different phone accounts. So
850 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700851 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700852 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700853 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
855
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700856 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
857 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700858 if (!checkNotifyPermission("notifyCallState()")) {
859 return;
860 }
Wink Savillee380b982014-07-26 18:24:22 -0700861 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700862 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700863 + " state=" + state + " incomingNumber=" + incomingNumber);
864 }
865 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700866 if (validatePhoneId(phoneId)) {
867 mCallState[phoneId] = state;
868 mCallIncomingNumber[phoneId] = incomingNumber;
869 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800870 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700871 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800872 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700873 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700874 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
875 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700876 } catch (RemoteException ex) {
877 mRemoveList.add(r.binder);
878 }
879 }
880 }
881 }
882 handleRemoveListLocked();
883 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700884 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700885 }
886
Wink Saville63f03dd2014-10-23 10:44:45 -0700887 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700888 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700889 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700890 }
xinhe43c50292014-09-18 17:56:48 -0700891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700893 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
894 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700895 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700896 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700897 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700898 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700899 if (validatePhoneId(phoneId)) {
900 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700901
Wink Savillefb40dd42014-06-12 17:02:31 -0700902 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700903 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700904 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700905 + " phoneId=" + phoneId + " state=" + state);
906 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800907 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800908 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700909 try {
Wink Savillee380b982014-07-26 18:24:22 -0700910 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700911 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700912 + " subId=" + subId + " phoneId=" + phoneId
913 + " state=" + state);
914 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700915 r.callback.onServiceStateChanged(new ServiceState(state));
916 } catch (RemoteException ex) {
917 mRemoveList.add(r.binder);
918 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700921 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700922 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400924 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700926 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 }
928
fionaxu12312f62016-11-14 13:32:14 -0800929 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
930 int activationType, int activationState) {
931 if (!checkNotifyPermission("notifySimActivationState()")){
932 return;
933 }
934 if (VDBG) {
935 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
936 + "type=" + activationType + " state=" + activationState);
937 }
938 synchronized (mRecords) {
939 if (validatePhoneId(phoneId)) {
940 switch (activationType) {
941 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
942 mVoiceActivationState[phoneId] = activationState;
943 break;
944 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
945 mDataActivationState[phoneId] = activationState;
946 break;
947 default:
948 return;
949 }
950 for (Record r : mRecords) {
951 if (VDBG) {
952 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
953 + " phoneId=" + phoneId + "type=" + activationType
954 + " state=" + activationState);
955 }
956 try {
957 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
958 r.matchPhoneStateListenerEvent(
959 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
960 idMatch(r.subId, subId, phoneId)) {
961 if (DBG) {
962 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
963 + " subId=" + subId + " phoneId=" + phoneId
964 + " state=" + activationState);
965 }
966 r.callback.onVoiceActivationStateChanged(activationState);
967 }
968 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
969 r.matchPhoneStateListenerEvent(
970 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
971 idMatch(r.subId, subId, phoneId)) {
972 if (DBG) {
973 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
974 + " subId=" + subId + " phoneId=" + phoneId
975 + " state=" + activationState);
976 }
977 r.callback.onDataActivationStateChanged(activationState);
978 }
979 } catch (RemoteException ex) {
980 mRemoveList.add(r.binder);
981 }
982 }
983 } else {
984 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
985 }
986 handleRemoveListLocked();
987 }
988 }
989
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700990 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
991 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700992 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700993 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700994 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000995 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700996 log("notifySignalStrengthForPhoneId: subId=" + subId
997 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000998 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001001 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001002 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001003 mSignalStrength[phoneId] = signalStrength;
1004 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001005 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001006 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001007 + " phoneId=" + phoneId + " ss=" + signalStrength);
1008 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001009 if (r.matchPhoneStateListenerEvent(
1010 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001011 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001013 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001014 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001015 + " subId=" + subId + " phoneId=" + phoneId
1016 + " ss=" + signalStrength);
1017 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001018 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1019 } catch (RemoteException ex) {
1020 mRemoveList.add(r.binder);
1021 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001022 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001023 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001024 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001025 try {
1026 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001027 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001028 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001029 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001030 + " subId=" + subId + " phoneId=" + phoneId
1031 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1032 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001033 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001034 } catch (RemoteException ex) {
1035 mRemoveList.add(r.binder);
1036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 }
1038 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001039 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001040 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001042 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001044 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 }
1046
Andrew Flynn1f452642015-04-14 22:16:04 -04001047 @Override
1048 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001049 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1050
Andrew Flynn1f452642015-04-14 22:16:04 -04001051 if (VDBG) {
1052 log("notifyCarrierNetworkChange: active=" + active);
1053 }
1054
1055 synchronized (mRecords) {
1056 mCarrierNetworkChangeState = active;
1057 for (Record r : mRecords) {
1058 if (r.matchPhoneStateListenerEvent(
1059 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1060 try {
1061 r.callback.onCarrierNetworkChange(active);
1062 } catch (RemoteException ex) {
1063 mRemoveList.add(r.binder);
1064 }
1065 }
1066 }
1067 handleRemoveListLocked();
1068 }
1069 }
1070
Wink Savilleb208a242012-07-25 14:08:09 -07001071 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001072 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001073 }
1074
Wink Saville63f03dd2014-10-23 10:44:45 -07001075 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001076 if (!checkNotifyPermission("notifyCellInfo()")) {
1077 return;
1078 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001079 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001080 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001081 + " cellInfo=" + cellInfo);
1082 }
yifan.baie620ce72017-12-22 14:59:57 +08001083 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001084 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001085 if (validatePhoneId(phoneId)) {
1086 mCellInfo.set(phoneId, cellInfo);
1087 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001088 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001089 idMatch(r.subId, subId, phoneId) &&
1090 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001091 try {
1092 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001093 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001094 }
1095 r.callback.onCellInfoChanged(cellInfo);
1096 } catch (RemoteException ex) {
1097 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001098 }
John Wang963db55d2012-03-30 16:04:06 -07001099 }
1100 }
1101 }
1102 handleRemoveListLocked();
1103 }
1104 }
1105
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001106 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1107 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1108 configs);
1109 }
1110
1111 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1112 List<PhysicalChannelConfig> configs) {
1113 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1114 return;
1115 }
1116
1117 if (VDBG) {
1118 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1119 }
1120
1121 synchronized (mRecords) {
1122 int phoneId = SubscriptionManager.getPhoneId(subId);
1123 if (validatePhoneId(phoneId)) {
1124 mPhysicalChannelConfigs.set(phoneId, configs);
1125 for (Record r : mRecords) {
1126 if (r.matchPhoneStateListenerEvent(
1127 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1128 && idMatch(r.subId, subId, phoneId)) {
1129 try {
1130 if (DBG_LOC) {
1131 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1132 + configs + " r=" + r);
1133 }
1134 r.callback.onPhysicalChannelConfigurationChanged(configs);
1135 } catch (RemoteException ex) {
1136 mRemoveList.add(r.binder);
1137 }
1138 }
1139 }
1140 }
1141 handleRemoveListLocked();
1142 }
1143 }
1144
xinhe43c50292014-09-18 17:56:48 -07001145 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001146 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001147 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001148 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001149 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001150 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001151 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001152 + " mwi=" + mwi);
1153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001155 if (validatePhoneId(phoneId)) {
1156 mMessageWaiting[phoneId] = mwi;
1157 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001158 if (r.matchPhoneStateListenerEvent(
1159 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001160 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001161 try {
1162 r.callback.onMessageWaitingIndicatorChanged(mwi);
1163 } catch (RemoteException ex) {
1164 mRemoveList.add(r.binder);
1165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 }
1167 }
1168 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001169 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 }
1171 }
1172
zxuan35a47022018-01-04 11:24:04 -08001173 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1174 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1175 return;
1176 }
1177 if (VDBG) {
1178 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1179 + " state=" + state);
1180 }
1181 synchronized (mRecords) {
1182 if (validatePhoneId(phoneId)) {
1183 mMessageWaiting[phoneId] = state;
1184 for (Record r : mRecords) {
1185 if (r.matchPhoneStateListenerEvent(
1186 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1187 idMatch(r.subId, subId, phoneId)) {
1188 try {
1189 r.callback.onUserMobileDataStateChanged(state);
1190 } catch (RemoteException ex) {
1191 mRemoveList.add(r.binder);
1192 }
1193 }
1194 }
1195 }
1196 handleRemoveListLocked();
1197 }
1198 }
1199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001201 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001202 }
1203
Wink Saville63f03dd2014-10-23 10:44:45 -07001204 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001205 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001206 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001207 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001208 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001209 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001210 + " cfi=" + cfi);
1211 }
yifan.baie620ce72017-12-22 14:59:57 +08001212 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001214 if (validatePhoneId(phoneId)) {
1215 mCallForwarding[phoneId] = cfi;
1216 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001217 if (r.matchPhoneStateListenerEvent(
1218 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001219 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001220 try {
1221 r.callback.onCallForwardingIndicatorChanged(cfi);
1222 } catch (RemoteException ex) {
1223 mRemoveList.add(r.binder);
1224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 }
1226 }
1227 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001228 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 }
1230 }
1231
1232 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001233 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001234 }
1235
Wink Saville63f03dd2014-10-23 10:44:45 -07001236 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001237 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001238 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001239 }
yifan.baie620ce72017-12-22 14:59:57 +08001240 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001242 if (validatePhoneId(phoneId)) {
1243 mDataActivity[phoneId] = state;
1244 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001245 // Notify by correct subId.
1246 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1247 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001248 try {
1249 r.callback.onDataActivity(state);
1250 } catch (RemoteException ex) {
1251 mRemoveList.add(r.binder);
1252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 }
1254 }
1255 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001256 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 }
1258 }
1259
Jack Yubaeec622017-05-01 17:01:11 -07001260 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001261 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001262 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001263 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001264 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001265 networkCapabilities, networkType, roaming);
1266 }
1267
Wink Saville63f03dd2014-10-23 10:44:45 -07001268 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001269 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001270 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1271 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001272 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001273 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001274 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001275 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001276 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001277 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001278 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001279 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001280 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001281 }
yifan.baie620ce72017-12-22 14:59:57 +08001282 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001284 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001285 // We only call the callback when the change is for default APN type.
1286 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1287 && (mDataConnectionState[phoneId] != state
1288 || mDataConnectionNetworkType[phoneId] != networkType)) {
1289 String str = "onDataConnectionStateChanged(" + state
1290 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001291 log(str);
1292 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001293 for (Record r : mRecords) {
1294 if (r.matchPhoneStateListenerEvent(
1295 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1296 idMatch(r.subId, subId, phoneId)) {
1297 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001298 if (DBG) {
1299 log("Notify data connection state changed on sub: " + subId);
1300 }
Jack Yub1bac542018-03-14 16:23:38 -07001301 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001302 } catch (RemoteException ex) {
1303 mRemoveList.add(r.binder);
1304 }
1305 }
1306 }
1307 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001308
1309 mDataConnectionState[phoneId] = state;
1310 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001311 }
1312 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1313 apnType, apn, reason, linkProperties, "");
1314 for (Record r : mRecords) {
1315 if (r.matchPhoneStateListenerEvent(
1316 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1317 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001318 r.callback.onPreciseDataConnectionStateChanged(
1319 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001320 } catch (RemoteException ex) {
1321 mRemoveList.add(r.binder);
1322 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001323 }
1324 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001325 }
1326 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 }
Jack Yubaeec622017-05-01 17:01:11 -07001328 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001329 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001330 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1331 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 }
1333
Robert Greenwalt02648a42010-05-18 10:52:51 -07001334 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001335 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001336 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001337 }
1338
Wink Saville63f03dd2014-10-23 10:44:45 -07001339 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001340 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001341 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001342 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001343 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001344 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001345 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001346 + " reason=" + reason + " apnType=" + apnType);
1347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001349 mPreciseDataConnectionState = new PreciseDataConnectionState(
1350 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1351 apnType, "", reason, null, "");
1352 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001353 if (r.matchPhoneStateListenerEvent(
1354 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001355 try {
1356 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1357 } catch (RemoteException ex) {
1358 mRemoveList.add(r.binder);
1359 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 }
1361 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001362 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001364 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001365 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1366 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 }
1368
1369 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001370 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001371 }
1372
Wink Saville63f03dd2014-10-23 10:44:45 -07001373 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001374 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001375 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001376 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001377 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001378 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001379 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001380 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001381 + " cellLocation=" + cellLocation);
1382 }
yifan.baie620ce72017-12-22 14:59:57 +08001383 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001385 if (validatePhoneId(phoneId)) {
1386 mCellLocation[phoneId] = cellLocation;
1387 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001388 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001389 idMatch(r.subId, subId, phoneId) &&
1390 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001391 try {
1392 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001393 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001394 + " r=" + r);
1395 }
1396 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1397 } catch (RemoteException ex) {
1398 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001399 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 }
1402 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001403 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001404 }
1405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406
Wink Savillefd2d0132010-10-28 14:22:26 -07001407 public void notifyOtaspChanged(int otaspMode) {
1408 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1409 return;
1410 }
1411 synchronized (mRecords) {
1412 mOtaspMode = otaspMode;
1413 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001414 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001415 try {
1416 r.callback.onOtaspChanged(otaspMode);
1417 } catch (RemoteException ex) {
1418 mRemoveList.add(r.binder);
1419 }
1420 }
1421 }
1422 handleRemoveListLocked();
1423 }
1424 }
1425
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001426 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1427 int backgroundCallState) {
1428 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1429 return;
1430 }
1431 synchronized (mRecords) {
1432 mRingingCallState = ringingCallState;
1433 mForegroundCallState = foregroundCallState;
1434 mBackgroundCallState = backgroundCallState;
1435 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1436 backgroundCallState,
1437 DisconnectCause.NOT_VALID,
1438 PreciseDisconnectCause.NOT_VALID);
1439 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001440 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001441 try {
1442 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1443 } catch (RemoteException ex) {
1444 mRemoveList.add(r.binder);
1445 }
1446 }
1447 }
1448 handleRemoveListLocked();
1449 }
1450 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1451 DisconnectCause.NOT_VALID,
1452 PreciseDisconnectCause.NOT_VALID);
1453 }
1454
1455 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1456 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1457 return;
1458 }
1459 synchronized (mRecords) {
1460 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1461 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1462 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001463 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001464 try {
1465 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1466 } catch (RemoteException ex) {
1467 mRemoveList.add(r.binder);
1468 }
1469 }
1470 }
1471 handleRemoveListLocked();
1472 }
1473 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1474 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1475 }
1476
1477 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1478 String apn, String failCause) {
1479 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1480 return;
1481 }
1482 synchronized (mRecords) {
1483 mPreciseDataConnectionState = new PreciseDataConnectionState(
1484 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1485 apnType, apn, reason, null, failCause);
1486 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001487 if (r.matchPhoneStateListenerEvent(
1488 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001489 try {
1490 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1491 } catch (RemoteException ex) {
1492 mRemoveList.add(r.binder);
1493 }
1494 }
1495 }
1496 handleRemoveListLocked();
1497 }
1498 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1499 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1500 }
1501
Wink Savillefb40dd42014-06-12 17:02:31 -07001502 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1503 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1504 return;
1505 }
1506 synchronized (mRecords) {
1507 mVoLteServiceState = lteState;
1508 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001509 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001510 try {
1511 r.callback.onVoLteServiceStateChanged(
1512 new VoLteServiceState(mVoLteServiceState));
1513 } catch (RemoteException ex) {
1514 mRemoveList.add(r.binder);
1515 }
1516 }
1517 }
1518 handleRemoveListLocked();
1519 }
1520 }
1521
Shuo Qian066e8652018-04-25 21:02:35 +00001522 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1523 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1524 return;
1525 }
1526
1527 synchronized (mRecords) {
1528 for (Record r : mRecords) {
1529 if (VDBG) {
1530 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1531 }
1532 if ((r.matchPhoneStateListenerEvent(
1533 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1534 ((r.subId == subId) ||
1535 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1536 try {
1537 r.callback.onOemHookRawEvent(rawData);
1538 } catch (RemoteException ex) {
1539 mRemoveList.add(r.binder);
1540 }
1541 }
1542 }
1543 handleRemoveListLocked();
1544 }
1545 }
1546
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001547 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1548 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1549 return;
1550 }
1551
1552 if (VDBG) {
1553 log("notifyPhoneCapabilityChanged: capability=" + capability);
1554 }
1555
1556 synchronized (mRecords) {
1557 mPhoneCapability = capability;
1558
1559 for (Record r : mRecords) {
1560 if (r.matchPhoneStateListenerEvent(
1561 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1562 try {
1563 r.callback.onPhoneCapabilityChanged(capability);
1564 } catch (RemoteException ex) {
1565 mRemoveList.add(r.binder);
1566 }
1567 }
1568 }
1569 handleRemoveListLocked();
1570 }
1571 }
1572
1573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001575 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1576 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1577
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001578 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001581 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001583 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301584 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001585 pw.println("Phone Id=" + i);
1586 pw.increaseIndent();
1587 pw.println("mCallState=" + mCallState[i]);
1588 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1589 pw.println("mServiceState=" + mServiceState[i]);
1590 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1591 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001592 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001593 pw.println("mSignalStrength=" + mSignalStrength[i]);
1594 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1595 pw.println("mCallForwarding=" + mCallForwarding[i]);
1596 pw.println("mDataActivity=" + mDataActivity[i]);
1597 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001598 pw.println("mCellLocation=" + mCellLocation[i]);
1599 pw.println("mCellInfo=" + mCellInfo.get(i));
1600 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301601 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001602 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1603 pw.println("mPreciseCallState=" + mPreciseCallState);
1604 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1605 pw.println("mRingingCallState=" + mRingingCallState);
1606 pw.println("mForegroundCallState=" + mForegroundCallState);
1607 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1608 pw.println("mVoLteServiceState=" + mVoLteServiceState);
Malcolm Chen5ee5c142018-08-08 20:27:45 -07001609 pw.println("mPhoneCapability=" + mPhoneCapability);
Jack Yud19b6ae2017-04-05 14:12:09 -07001610
1611 pw.decreaseIndent();
1612
1613 pw.println("local logs:");
1614 pw.increaseIndent();
1615 mLocalLog.dump(fd, pw, args);
1616 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001617 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001618 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001619 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001620 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001622 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 }
1624 }
1625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 //
1627 // the legacy intent broadcasting
1628 //
1629
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001630 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001631 long ident = Binder.clearCallingIdentity();
1632 try {
1633 mBatteryStats.notePhoneState(state.getState());
1634 } catch (RemoteException re) {
1635 // Can't do much
1636 } finally {
1637 Binder.restoreCallingIdentity(ident);
1638 }
1639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001641 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 Bundle data = new Bundle();
1643 state.fillInNotifierBundle(data);
1644 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001645 // Pass the subscription along with the intent.
1646 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001647 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001648 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001649 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 }
1651
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001652 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1653 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001654 long ident = Binder.clearCallingIdentity();
1655 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001656 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001657 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001658 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001659 } finally {
1660 Binder.restoreCallingIdentity(ident);
1661 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001664 Bundle data = new Bundle();
1665 signalStrength.fillInNotifierBundle(data);
1666 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001667 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001668 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001669 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 }
1671
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001672 /**
1673 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1674 * a valid subId, in which case this function fires a subId-specific intent, or it
1675 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1676 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1677 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001678 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1679 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 long ident = Binder.clearCallingIdentity();
1681 try {
1682 if (state == TelephonyManager.CALL_STATE_IDLE) {
1683 mBatteryStats.notePhoneOff();
1684 } else {
1685 mBatteryStats.notePhoneOn();
1686 }
1687 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001688 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 } finally {
1690 Binder.restoreCallingIdentity(ident);
1691 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001694 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001695 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001696
1697 // If a valid subId was specified, we should fire off a subId-specific state
1698 // change intent and include the subId.
1699 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1700 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1701 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001702 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001703 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001704 // If the phoneId is invalid, the broadcast is for overall call state.
1705 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1706 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1707 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001708
Brad Ebinger51de96a2017-04-21 17:05:18 -07001709 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1710 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1711
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001712 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001713 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunnb8bd19e2018-06-19 09:55:43 -07001714 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1715
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001716 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1717 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001718 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001719 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001720 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001721 android.Manifest.permission.READ_PHONE_STATE,
1722 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001723 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1724 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1725 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 }
1727
Robert Greenwalt42acef32009-08-12 16:08:25 -07001728 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001729 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001730 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001731 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001732 // Note: not reporting to the battery stats service here, because the
1733 // status bar takes care of that after taking into account all of the
1734 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001736 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001737 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001738 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001739 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 }
1741 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001742 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001743 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001744 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001745 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001746 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001747 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001748 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001749 }
1750 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001751 if (networkCapabilities != null) {
1752 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001753 }
Wink Savillea639b312012-07-10 12:37:54 -07001754 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001755
Wink Savillea639b312012-07-10 12:37:54 -07001756 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1757 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001758 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001759 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 }
1761
Wink Savillefb40dd42014-06-12 17:02:31 -07001762 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001763 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001765 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1766 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001767 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001768 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001770
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001771 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1772 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1773 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1774 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1775 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1776 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1777 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1778 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1779 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1780 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1781 }
1782
1783 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001784 String apnType, String apn, String reason, LinkProperties linkProperties,
1785 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001786 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1787 intent.putExtra(PhoneConstants.STATE_KEY, state);
1788 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1789 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1790 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1791 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001792 if (linkProperties != null) {
1793 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1794 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001795 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1796
1797 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1798 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1799 }
1800
Andrew Flynnceaed682015-06-09 12:36:58 +00001801 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001802 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001803 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001804 }
1805
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001806 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1807 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001808 }
1809
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001810 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001811 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001812 return true;
1813 }
1814 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001815 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001816 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001817 return false;
1818 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001819
Andrew Flynn1f452642015-04-14 22:16:04 -04001820 private boolean checkNotifyPermission() {
1821 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1822 == PackageManager.PERMISSION_GRANTED;
1823 }
1824
Jeff Davidson29da89f2018-02-28 17:50:16 -08001825 private boolean checkListenerPermission(
1826 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001827 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001828 mContext.enforceCallingOrSelfPermission(
1829 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001830 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1831 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1832 return false;
1833 }
John Wang963db55d2012-03-30 16:04:06 -07001834 }
1835
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001836 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1838 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001839 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001840 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001841 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001842
1843 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1844 mContext.enforceCallingOrSelfPermission(
1845 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001846 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001847
Shuo Qian066e8652018-04-25 21:02:35 +00001848 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1849 mContext.enforceCallingOrSelfPermission(
1850 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1851 }
1852
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001853 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001854 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001855
1856 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001857 int size = mRemoveList.size();
1858 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1859 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001860 for (IBinder b: mRemoveList) {
1861 remove(b);
1862 }
1863 mRemoveList.clear();
1864 }
1865 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001866
1867 private boolean validateEventsAndUserLocked(Record r, int events) {
1868 int foregroundUser;
1869 long callingIdentity = Binder.clearCallingIdentity();
1870 boolean valid = false;
1871 try {
1872 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001873 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1874 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001875 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001876 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001877 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001878 + " r.events=" + r.events + " events=" + events);
1879 }
1880 } finally {
1881 Binder.restoreCallingIdentity(callingIdentity);
1882 }
1883 return valid;
1884 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001885
1886 private boolean validatePhoneId(int phoneId) {
1887 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001888 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001889 return valid;
1890 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001891
1892 private static void log(String s) {
1893 Rlog.d(TAG, s);
1894 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001895
xinhe8b79fb62014-11-05 14:55:03 -08001896 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001897
1898 if(subId < 0) {
1899 // Invalid case, we need compare phoneId with default one.
1900 return (mDefaultPhoneId == phoneId);
1901 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001902 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001903 return (subId == mDefaultSubId);
1904 } else {
1905 return (rSubId == subId);
1906 }
1907 }
1908
Hall Liu5fb337f2017-11-22 17:38:15 -08001909 private boolean checkLocationAccess(Record r) {
1910 long token = Binder.clearCallingIdentity();
1911 try {
1912 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001913 r.callingPackage, r.callerUid, r.callerPid,
1914 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001915 } finally {
1916 Binder.restoreCallingIdentity(token);
1917 }
1918 }
1919
xinhee9f16402014-09-25 16:39:28 -07001920 private void checkPossibleMissNotify(Record r, int phoneId) {
1921 int events = r.events;
1922
1923 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1924 try {
1925 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1926 mServiceState[phoneId]);
1927 r.callback.onServiceStateChanged(
1928 new ServiceState(mServiceState[phoneId]));
1929 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001930 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001931 }
1932 }
1933
1934 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1935 try {
1936 SignalStrength signalStrength = mSignalStrength[phoneId];
1937 if (DBG) {
1938 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1939 }
1940 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1941 } catch (RemoteException ex) {
1942 mRemoveList.add(r.binder);
1943 }
1944 }
1945
1946 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1947 try {
1948 int gsmSignalStrength = mSignalStrength[phoneId]
1949 .getGsmSignalStrength();
1950 if (DBG) {
1951 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1952 gsmSignalStrength);
1953 }
1954 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1955 : gsmSignalStrength));
1956 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001957 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001958 }
1959 }
1960
1961 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1962 try {
1963 if (DBG_LOC) {
1964 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1965 + mCellInfo.get(phoneId));
1966 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001967 if (checkLocationAccess(r)) {
1968 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1969 }
xinhee9f16402014-09-25 16:39:28 -07001970 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001971 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001972 }
1973 }
1974
zxuan35a47022018-01-04 11:24:04 -08001975 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1976 try {
1977 if (VDBG) {
1978 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1979 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1980 }
1981 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1982 } catch (RemoteException ex) {
1983 mRemoveList.add(r.binder);
1984 }
1985 }
1986
xinhee9f16402014-09-25 16:39:28 -07001987 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1988 try {
1989 if (VDBG) {
1990 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1991 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1992 }
1993 r.callback.onMessageWaitingIndicatorChanged(
1994 mMessageWaiting[phoneId]);
1995 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001996 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001997 }
1998 }
1999
2000 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2001 try {
2002 if (VDBG) {
2003 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2004 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2005 }
2006 r.callback.onCallForwardingIndicatorChanged(
2007 mCallForwarding[phoneId]);
2008 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002009 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002010 }
2011 }
2012
2013 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2014 try {
2015 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2016 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002017 if (checkLocationAccess(r)) {
2018 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2019 }
xinhee9f16402014-09-25 16:39:28 -07002020 } catch (RemoteException ex) {
2021 mRemoveList.add(r.binder);
2022 }
2023 }
2024
2025 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2026 try {
2027 if (DBG) {
2028 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2029 + "=" + mDataConnectionState[phoneId]
2030 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2031 + ")");
2032 }
2033 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2034 mDataConnectionNetworkType[phoneId]);
2035 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002036 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002037 }
2038 }
2039 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040}