blob: ceb213594b8e3fcdc90e437e80adf2fce4b7d6c8 [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;
Jack Yud19b6ae2017-04-05 14:12:09 -070038import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080039import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020040import android.telephony.PreciseCallState;
41import android.telephony.PreciseDataConnectionState;
42import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070043import android.telephony.Rlog;
44import android.telephony.ServiceState;
45import android.telephony.SignalStrength;
46import android.telephony.SubscriptionManager;
47import android.telephony.TelephonyManager;
48import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070050import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080053import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070055import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080056import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070057import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import com.android.internal.telephony.TelephonyIntents;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060059import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070060import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.server.am.BatteryStatsService;
62
Jack Yud19b6ae2017-04-05 14:12:09 -070063import java.io.FileDescriptor;
64import java.io.PrintWriter;
65import java.util.ArrayList;
66import java.util.Arrays;
67import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080068import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070/**
Wink Savillee9b06d72009-05-18 21:47:50 -070071 * Since phone process can be restarted, this class provides a centralized place
72 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070073 *
74 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
75 * and 15973975 by saving the phoneId of the registrant and then using the
76 * phoneId when deciding to to make a callback. This is necessary because
77 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070078 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070079 * the dummy value conversion we properly do the callbacks.
80 *
81 * Eventually we may want to remove the notion of dummy value but for now this
82 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 */
84class TelephonyRegistry extends ITelephonyRegistry.Stub {
85 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070086 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070087 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070088 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
90 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070091 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070094
Malcolm Chenabbfac22018-02-12 19:15:59 -080095 TelephonyRegistryDeathRecipient deathRecipient;
96
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080098 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070099
Hall Liu3d309462018-02-06 18:13:36 +0000100 int callerUserId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700103
Wink Savilled09c4ca2014-11-22 10:08:16 -0800104 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700105
Wink Savilled09c4ca2014-11-22 10:08:16 -0800106 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800107
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700108 boolean canReadPhoneState;
109
Wink Savillea374c3d2014-11-11 11:48:04 -0800110 boolean matchPhoneStateListenerEvent(int events) {
111 return (callback != null) && ((events & this.events) != 0);
112 }
113
Wink Savilled09c4ca2014-11-22 10:08:16 -0800114 boolean matchOnSubscriptionsChangedListener() {
115 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800116 }
Wink Savillee380b982014-07-26 18:24:22 -0700117
Wink Savillea12a7b32012-09-20 10:09:45 -0700118 @Override
119 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700120 return "{callingPackage=" + callingPackage + " binder=" + binder
121 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800122 + " onSubscriptionsChangedListenererCallback="
123 + onSubscriptionsChangedListenerCallback
Hall Liu3d309462018-02-06 18:13:36 +0000124 + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700125 + " events=" + Integer.toHexString(events)
126 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 }
129
130 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700131
Joe Onorato163d8d92010-10-21 13:21:20 -0400132 // access should be inside synchronized (mRecords) for these two fields
133 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
134 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 private final IBatteryStats mBatteryStats;
137
Svet Ganov16a16892015-04-16 10:32:04 -0700138 private final AppOpsManager mAppOps;
139
Wink Savilled09c4ca2014-11-22 10:08:16 -0800140 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
Wink Savillefb40dd42014-06-12 17:02:31 -0700146 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
Wink Savillefb40dd42014-06-12 17:02:31 -0700148 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700149
fionaxu12312f62016-11-14 13:32:14 -0800150 private int[] mVoiceActivationState;
151
152 private int[] mDataActivationState;
153
zxuan35a47022018-01-04 11:24:04 -0800154 private boolean[] mUserMobileDataState;
155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700165
Yifan Bai57b39e32016-04-01 16:24:33 +0800166 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700175
Nathan Harold016e9c62016-12-14 11:24:48 -0800176 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700177
Wink Savillefb40dd42014-06-12 17:02:31 -0700178 private ArrayList<List<CellInfo>> mCellInfo = null;
179
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800180 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
181
Wink Savillefb40dd42014-06-12 17:02:31 -0700182 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
183
Wink Savilled09c4ca2014-11-22 10:08:16 -0800184 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700185
Wink Savilled09c4ca2014-11-22 10:08:16 -0800186 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700187
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200188 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
189
190 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
191
192 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
193
194 private PreciseCallState mPreciseCallState = new PreciseCallState();
195
Andrew Flynn1f452642015-04-14 22:16:04 -0400196 private boolean mCarrierNetworkChangeState = false;
197
Jack Yud19b6ae2017-04-05 14:12:09 -0700198 private final LocalLog mLocalLog = new LocalLog(100);
199
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200200 private PreciseDataConnectionState mPreciseDataConnectionState =
201 new PreciseDataConnectionState();
202
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700203 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700204 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700205 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
206 PhoneStateListener.LISTEN_VOLTE_STATE;
207
208 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700209 PhoneStateListener.LISTEN_CALL_STATE |
210 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700211 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700212
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200213 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
214 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
215 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
216
Wink Savillea12a7b32012-09-20 10:09:45 -0700217 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700218 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700219
220 private final Handler mHandler = new Handler() {
221 @Override
222 public void handleMessage(Message msg) {
223 switch (msg.what) {
224 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700225 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700226 int numPhones = TelephonyManager.getDefault().getPhoneCount();
227 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700228 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700229 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700230 }
231 break;
232 }
xinhee9f16402014-09-25 16:39:28 -0700233 case MSG_UPDATE_DEFAULT_SUB: {
234 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700235 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700236 if (VDBG) {
237 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
238 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
239 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
240 }
241
242 //Due to possible risk condition,(notify call back using the new
243 //defaultSubId comes before new defaultSubId update) we need to recall all
244 //possible missed notify callback
245 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700246 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800247 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700248 checkPossibleMissNotify(r, newDefaultPhoneId);
249 }
250 }
251 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700252 }
253 mDefaultSubId = newDefaultSubId;
254 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700255 }
256 }
257 }
258 };
259
Malcolm Chenabbfac22018-02-12 19:15:59 -0800260 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
261
262 private final IBinder binder;
263
264 TelephonyRegistryDeathRecipient(IBinder binder) {
265 this.binder = binder;
266 }
267
268 @Override
269 public void binderDied() {
270 if (DBG) log("binderDied " + binder);
271 remove(binder);
272 }
273 }
274
Wink Savillea12a7b32012-09-20 10:09:45 -0700275 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
276 @Override
277 public void onReceive(Context context, Intent intent) {
278 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700279 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700280 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700281 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700282 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700283 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700284 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700285 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800286 PhoneConstants.SUBSCRIPTION_KEY,
287 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700288 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
289 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700290 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700291 log("onReceive:current mDefaultSubId=" + mDefaultSubId
292 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
293 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700294 }
xinhee9f16402014-09-25 16:39:28 -0700295
Junda Liu985f52c2015-02-23 16:06:51 -0800296 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700297 || (newDefaultPhoneId != mDefaultPhoneId))) {
298 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
299 newDefaultPhoneId, 0, newDefaultSubIdObj));
300 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700301 }
302 }
303 };
304
Wink Savillee9b06d72009-05-18 21:47:50 -0700305 // we keep a copy of all of the state so we can send it out when folks
306 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700308 // In these calls we call with the lock held. This is safe becasuse remote
309 // calls go through a oneway interface and local calls going through a
310 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311
312 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700313 CellLocation location = CellLocation.getEmpty();
314
Wink Savillefb40dd42014-06-12 17:02:31 -0700315 mContext = context;
316 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700317
Wink Savillefb40dd42014-06-12 17:02:31 -0700318 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700319 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700320 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800321 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700322 mCallState = new int[numPhones];
323 mDataActivity = new int[numPhones];
324 mDataConnectionState = new int[numPhones];
325 mDataConnectionNetworkType = new int[numPhones];
326 mCallIncomingNumber = new String[numPhones];
327 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800328 mVoiceActivationState = new int[numPhones];
329 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800330 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700331 mSignalStrength = new SignalStrength[numPhones];
332 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 mCallForwarding = new boolean[numPhones];
334 mCellLocation = new Bundle[numPhones];
335 mDataConnectionLinkProperties = new LinkProperties[numPhones];
336 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
337 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800338 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700339 for (int i = 0; i < numPhones; i++) {
340 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
341 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
342 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800343 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
344 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700345 mCallIncomingNumber[i] = "";
346 mServiceState[i] = new ServiceState();
347 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800348 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700349 mMessageWaiting[i] = false;
350 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700351 mCellLocation[i] = new Bundle();
352 mCellInfo.add(i, null);
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800353 mPhysicalChannelConfigs.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800354 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 }
356
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700357 // Note that location can be null for non-phone builds like
358 // like the generic one.
359 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700360 for (int i = 0; i < numPhones; i++) {
361 location.fillInNotifierBundle(mCellLocation[i]);
362 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700363 }
Svet Ganov16a16892015-04-16 10:32:04 -0700364
365 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367
Svetoslav Ganova0027152013-06-25 14:59:53 -0700368 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700369 // Watch for interesting updates
370 final IntentFilter filter = new IntentFilter();
371 filter.addAction(Intent.ACTION_USER_SWITCHED);
372 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700373 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700374 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700375 mContext.registerReceiver(mBroadcastReceiver, filter);
376 }
377
378 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700379 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800380 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700381 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800382 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700383 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
384 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800385 + " callback.asBinder=" + callback.asBinder());
386 }
387
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700388 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700389 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700390 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
391 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700392 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700393 } catch (SecurityException e) {
394 mContext.enforceCallingOrSelfPermission(
395 android.Manifest.permission.READ_PHONE_STATE,
396 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700397
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700398 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
399 callingPackage) != AppOpsManager.MODE_ALLOWED) {
400 return;
401 }
Svet Ganov16a16892015-04-16 10:32:04 -0700402 }
403
Wink Savillea374c3d2014-11-11 11:48:04 -0800404
Wink Savilled09c4ca2014-11-22 10:08:16 -0800405 synchronized (mRecords) {
406 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800407 IBinder b = callback.asBinder();
408 Record r = add(b);
409
410 if (r == null) {
411 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800412 }
413
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700415 r.callingPackage = callingPackage;
Hall Liu3d309462018-02-06 18:13:36 +0000416 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800417 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700418 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 if (DBG) {
420 log("listen oscl: Register r=" + r);
421 }
422 // Always notify when registration occurs if there has been a notification.
423 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800425 if (VDBG) log("listen oscl: send to r=" + r);
426 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
427 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800428 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800429 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800430 remove(r.binder);
431 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800432 } else {
433 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800434 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 }
436 }
437
438 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800439 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800440 IOnSubscriptionsChangedListener callback) {
441 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800442 remove(callback.asBinder());
443 }
444
Wink Savillea374c3d2014-11-11 11:48:04 -0800445 @Override
446 public void notifySubscriptionInfoChanged() {
447 if (VDBG) log("notifySubscriptionInfoChanged:");
448 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800449 if (!hasNotifySubscriptionInfoChangedOccurred) {
450 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
451 + mRecords.size());
452 }
453 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800454 mRemoveList.clear();
455 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800456 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800457 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800458 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
459 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
460 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800461 } catch (RemoteException ex) {
462 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
463 mRemoveList.add(r.binder);
464 }
465 }
466 }
467 handleRemoveListLocked();
468 }
469 }
470
471 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
473 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800474 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
475 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700476 }
477
478 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700479 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700480 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700481 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700482 }
483
Svet Ganov16a16892015-04-16 10:32:04 -0700484 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700485 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700486 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700487 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700488 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700489 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
490 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700491 }
xinhe75c2c152014-10-16 11:49:45 -0700492
493 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700494 /* Checks permission and throws Security exception */
495 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700496
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700497 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700498 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700499 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700500 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700501 // SKIP checking for run-time permission since caller or self has PRIVILEGED
502 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700503 } catch (SecurityException e) {
504 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
505 callingPackage) != AppOpsManager.MODE_ALLOWED) {
506 return;
507 }
Svet Ganov16a16892015-04-16 10:32:04 -0700508 }
509 }
510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 synchronized (mRecords) {
512 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800513 IBinder b = callback.asBinder();
514 Record r = add(b);
515
516 if (r == null) {
517 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 }
xinhe43c50292014-09-18 17:56:48 -0700519
xinhe75c2c152014-10-16 11:49:45 -0700520 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700521 r.callingPackage = callingPackage;
Hall Liu3d309462018-02-06 18:13:36 +0000522 r.callerUserId = callerUserId;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700523 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
524 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
525 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700526 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
527 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800528 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800529 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700530 } else {//APP specify subID
531 r.subId = subId;
532 }
533 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
534
xinhe43c50292014-09-18 17:56:48 -0700535 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700537 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700538 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700539 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700540 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400542 try {
Wink Savillee380b982014-07-26 18:24:22 -0700543 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700544 r.callback.onServiceStateChanged(
545 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400546 } catch (RemoteException ex) {
547 remove(r.binder);
548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
550 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
551 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700552 int gsmSignalStrength = mSignalStrength[phoneId]
553 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700554 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
555 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 } catch (RemoteException ex) {
557 remove(r.binder);
558 }
559 }
560 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
561 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 r.callback.onMessageWaitingIndicatorChanged(
563 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 } catch (RemoteException ex) {
565 remove(r.binder);
566 }
567 }
568 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
569 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700570 r.callback.onCallForwardingIndicatorChanged(
571 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 } catch (RemoteException ex) {
573 remove(r.binder);
574 }
575 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700576 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400577 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700578 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700579 + mCellLocation[phoneId]);
Hall Liu3d309462018-02-06 18:13:36 +0000580 r.callback.onCellLocationChanged(
581 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400582 } catch (RemoteException ex) {
583 remove(r.binder);
584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 }
586 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
587 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700588 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700589 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 } catch (RemoteException ex) {
591 remove(r.binder);
592 }
593 }
594 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
595 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700596 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
597 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 } catch (RemoteException ex) {
599 remove(r.binder);
600 }
601 }
602 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
603 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700604 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 } catch (RemoteException ex) {
606 remove(r.binder);
607 }
608 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700609 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
610 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700611 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700612 } catch (RemoteException ex) {
613 remove(r.binder);
614 }
615 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700616 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
617 try {
618 r.callback.onOtaspChanged(mOtaspMode);
619 } catch (RemoteException ex) {
620 remove(r.binder);
621 }
622 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700623 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700624 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700625 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700626 + mCellInfo.get(phoneId));
Hall Liu3d309462018-02-06 18:13:36 +0000627 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700628 } catch (RemoteException ex) {
629 remove(r.binder);
630 }
631 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200632 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
633 try {
634 r.callback.onPreciseCallStateChanged(mPreciseCallState);
635 } catch (RemoteException ex) {
636 remove(r.binder);
637 }
638 }
639 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
640 try {
641 r.callback.onPreciseDataConnectionStateChanged(
642 mPreciseDataConnectionState);
643 } catch (RemoteException ex) {
644 remove(r.binder);
645 }
646 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400647 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
648 try {
649 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
650 } catch (RemoteException ex) {
651 remove(r.binder);
652 }
653 }
fionaxu12312f62016-11-14 13:32:14 -0800654 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
655 try {
656 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
657 } catch (RemoteException ex) {
658 remove(r.binder);
659 }
660 }
661 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
662 try {
663 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
664 } catch (RemoteException ex) {
665 remove(r.binder);
666 }
667 }
zxuan35a47022018-01-04 11:24:04 -0800668 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
669 try {
670 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
671 } catch (RemoteException ex) {
672 remove(r.binder);
673 }
674 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800675 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
676 try {
677 r.callback.onPhysicalChannelConfigurationChanged(
678 mPhysicalChannelConfigs.get(phoneId));
679 } catch (RemoteException ex) {
680 remove(r.binder);
681 }
682 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 }
684 }
685 } else {
xinhe75c2c152014-10-16 11:49:45 -0700686 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 remove(callback.asBinder());
688 }
689 }
690
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700691 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700692 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700693 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
694 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700695 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700696 return true;
697 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700698 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
699 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
700 if (canReadPhoneState &&
701 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
702 callingPackage) != AppOpsManager.MODE_ALLOWED) {
703 return false;
704 }
705 return canReadPhoneState;
706 }
707
708 private String getCallIncomingNumber(Record record, int phoneId) {
709 // Hide the number if record's process has no READ_PHONE_STATE permission
710 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
711 }
712
Malcolm Chenabbfac22018-02-12 19:15:59 -0800713 private Record add(IBinder binder) {
714 Record r;
715
716 synchronized (mRecords) {
717 final int N = mRecords.size();
718 for (int i = 0; i < N; i++) {
719 r = mRecords.get(i);
720 if (binder == r.binder) {
721 // Already existed.
722 return r;
723 }
724 }
725 r = new Record();
726 r.binder = binder;
727 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
728
729 try {
730 binder.linkToDeath(r.deathRecipient, 0);
731 } catch (RemoteException e) {
732 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
733 // Binder already died. Return null.
734 return null;
735 }
736
737 mRecords.add(r);
738 if (DBG) log("add new record");
739 }
740
741 return r;
742 }
743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 private void remove(IBinder binder) {
745 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700746 final int recordCount = mRecords.size();
747 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800748 Record r = mRecords.get(i);
749 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800750 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800751 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
752 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800753 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800754
755 if (r.deathRecipient != null) {
756 try {
757 binder.unlinkToDeath(r.deathRecipient, 0);
758 } catch (NoSuchElementException e) {
759 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
760 + r + " e=" + e);
761 }
762 }
763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 mRecords.remove(i);
765 return;
766 }
767 }
768 }
769 }
770
771 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700772 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700773 return;
774 }
xinhe43c50292014-09-18 17:56:48 -0700775
776 if (VDBG) {
777 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
778 }
779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700781 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800782 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800783 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700785 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
786 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400788 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 }
790 }
791 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400792 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700794
795 // Called only by Telecomm to communicate call state across different phone accounts. So
796 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800797 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700798 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700799 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 }
801
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700802 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
803 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700804 if (!checkNotifyPermission("notifyCallState()")) {
805 return;
806 }
Wink Savillee380b982014-07-26 18:24:22 -0700807 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700808 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700809 + " state=" + state + " incomingNumber=" + incomingNumber);
810 }
811 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700812 if (validatePhoneId(phoneId)) {
813 mCallState[phoneId] = state;
814 mCallIncomingNumber[phoneId] = incomingNumber;
815 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800816 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700817 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800818 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700819 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700820 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
821 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700822 } catch (RemoteException ex) {
823 mRemoveList.add(r.binder);
824 }
825 }
826 }
827 }
828 handleRemoveListLocked();
829 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700830 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700831 }
832
Wink Saville63f03dd2014-10-23 10:44:45 -0700833 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700834 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700835 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700836 }
xinhe43c50292014-09-18 17:56:48 -0700837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700839 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
840 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700841 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700842 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700843 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700844 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700845 if (validatePhoneId(phoneId)) {
846 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700847
Wink Savillefb40dd42014-06-12 17:02:31 -0700848 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700849 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700850 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700851 + " phoneId=" + phoneId + " state=" + state);
852 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800853 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800854 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700855 try {
Wink Savillee380b982014-07-26 18:24:22 -0700856 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700857 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700858 + " subId=" + subId + " phoneId=" + phoneId
859 + " state=" + state);
860 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700861 r.callback.onServiceStateChanged(new ServiceState(state));
862 } catch (RemoteException ex) {
863 mRemoveList.add(r.binder);
864 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700867 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700868 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400870 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700872 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 }
874
fionaxu12312f62016-11-14 13:32:14 -0800875 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
876 int activationType, int activationState) {
877 if (!checkNotifyPermission("notifySimActivationState()")){
878 return;
879 }
880 if (VDBG) {
881 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
882 + "type=" + activationType + " state=" + activationState);
883 }
884 synchronized (mRecords) {
885 if (validatePhoneId(phoneId)) {
886 switch (activationType) {
887 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
888 mVoiceActivationState[phoneId] = activationState;
889 break;
890 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
891 mDataActivationState[phoneId] = activationState;
892 break;
893 default:
894 return;
895 }
896 for (Record r : mRecords) {
897 if (VDBG) {
898 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
899 + " phoneId=" + phoneId + "type=" + activationType
900 + " state=" + activationState);
901 }
902 try {
903 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
904 r.matchPhoneStateListenerEvent(
905 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
906 idMatch(r.subId, subId, phoneId)) {
907 if (DBG) {
908 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
909 + " subId=" + subId + " phoneId=" + phoneId
910 + " state=" + activationState);
911 }
912 r.callback.onVoiceActivationStateChanged(activationState);
913 }
914 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
915 r.matchPhoneStateListenerEvent(
916 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
917 idMatch(r.subId, subId, phoneId)) {
918 if (DBG) {
919 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
920 + " subId=" + subId + " phoneId=" + phoneId
921 + " state=" + activationState);
922 }
923 r.callback.onDataActivationStateChanged(activationState);
924 }
925 } catch (RemoteException ex) {
926 mRemoveList.add(r.binder);
927 }
928 }
929 } else {
930 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
931 }
932 handleRemoveListLocked();
933 }
934 }
935
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700936 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
937 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700938 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700939 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700940 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000941 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700942 log("notifySignalStrengthForPhoneId: subId=" + subId
943 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000944 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700947 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700948 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700949 mSignalStrength[phoneId] = signalStrength;
950 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000951 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700952 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000953 + " phoneId=" + phoneId + " ss=" + signalStrength);
954 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800955 if (r.matchPhoneStateListenerEvent(
956 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800957 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700958 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000959 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700960 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000961 + " subId=" + subId + " phoneId=" + phoneId
962 + " ss=" + signalStrength);
963 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700964 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
965 } catch (RemoteException ex) {
966 mRemoveList.add(r.binder);
967 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400968 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800969 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800970 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700971 try {
972 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700973 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000974 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700975 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000976 + " subId=" + subId + " phoneId=" + phoneId
977 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
978 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700979 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700980 } catch (RemoteException ex) {
981 mRemoveList.add(r.binder);
982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 }
984 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700985 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700986 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400988 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700990 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 }
992
Andrew Flynn1f452642015-04-14 22:16:04 -0400993 @Override
994 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000995 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
996
Andrew Flynn1f452642015-04-14 22:16:04 -0400997 if (VDBG) {
998 log("notifyCarrierNetworkChange: active=" + active);
999 }
1000
1001 synchronized (mRecords) {
1002 mCarrierNetworkChangeState = active;
1003 for (Record r : mRecords) {
1004 if (r.matchPhoneStateListenerEvent(
1005 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1006 try {
1007 r.callback.onCarrierNetworkChange(active);
1008 } catch (RemoteException ex) {
1009 mRemoveList.add(r.binder);
1010 }
1011 }
1012 }
1013 handleRemoveListLocked();
1014 }
1015 }
1016
Wink Savilleb208a242012-07-25 14:08:09 -07001017 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001018 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001019 }
1020
Wink Saville63f03dd2014-10-23 10:44:45 -07001021 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001022 if (!checkNotifyPermission("notifyCellInfo()")) {
1023 return;
1024 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001025 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001026 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001027 + " cellInfo=" + cellInfo);
1028 }
John Wang963db55d2012-03-30 16:04:06 -07001029
1030 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001031 int phoneId = SubscriptionManager.getPhoneId(subId);
1032 if (validatePhoneId(phoneId)) {
1033 mCellInfo.set(phoneId, cellInfo);
1034 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001035 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu3d309462018-02-06 18:13:36 +00001036 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001037 try {
1038 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001039 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001040 }
1041 r.callback.onCellInfoChanged(cellInfo);
1042 } catch (RemoteException ex) {
1043 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001044 }
John Wang963db55d2012-03-30 16:04:06 -07001045 }
1046 }
1047 }
1048 handleRemoveListLocked();
1049 }
1050 }
1051
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001052 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1053 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1054 configs);
1055 }
1056
1057 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1058 List<PhysicalChannelConfig> configs) {
1059 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1060 return;
1061 }
1062
1063 if (VDBG) {
1064 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1065 }
1066
1067 synchronized (mRecords) {
1068 int phoneId = SubscriptionManager.getPhoneId(subId);
1069 if (validatePhoneId(phoneId)) {
1070 mPhysicalChannelConfigs.set(phoneId, configs);
1071 for (Record r : mRecords) {
1072 if (r.matchPhoneStateListenerEvent(
1073 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1074 && idMatch(r.subId, subId, phoneId)) {
1075 try {
1076 if (DBG_LOC) {
1077 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1078 + configs + " r=" + r);
1079 }
1080 r.callback.onPhysicalChannelConfigurationChanged(configs);
1081 } catch (RemoteException ex) {
1082 mRemoveList.add(r.binder);
1083 }
1084 }
1085 }
1086 }
1087 handleRemoveListLocked();
1088 }
1089 }
1090
xinhe43c50292014-09-18 17:56:48 -07001091 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001092 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001093 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001094 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001095 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001096 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001097 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001098 + " mwi=" + mwi);
1099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001101 if (validatePhoneId(phoneId)) {
1102 mMessageWaiting[phoneId] = mwi;
1103 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001104 if (r.matchPhoneStateListenerEvent(
1105 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001106 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001107 try {
1108 r.callback.onMessageWaitingIndicatorChanged(mwi);
1109 } catch (RemoteException ex) {
1110 mRemoveList.add(r.binder);
1111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 }
1113 }
1114 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001115 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 }
1117 }
1118
zxuan35a47022018-01-04 11:24:04 -08001119 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1120 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1121 return;
1122 }
1123 if (VDBG) {
1124 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1125 + " state=" + state);
1126 }
1127 synchronized (mRecords) {
1128 if (validatePhoneId(phoneId)) {
1129 mMessageWaiting[phoneId] = state;
1130 for (Record r : mRecords) {
1131 if (r.matchPhoneStateListenerEvent(
1132 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1133 idMatch(r.subId, subId, phoneId)) {
1134 try {
1135 r.callback.onUserMobileDataStateChanged(state);
1136 } catch (RemoteException ex) {
1137 mRemoveList.add(r.binder);
1138 }
1139 }
1140 }
1141 }
1142 handleRemoveListLocked();
1143 }
1144 }
1145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001147 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001148 }
1149
Wink Saville63f03dd2014-10-23 10:44:45 -07001150 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001151 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001152 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001153 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001154 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001155 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001156 + " cfi=" + cfi);
1157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001159 int phoneId = SubscriptionManager.getPhoneId(subId);
1160 if (validatePhoneId(phoneId)) {
1161 mCallForwarding[phoneId] = cfi;
1162 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001163 if (r.matchPhoneStateListenerEvent(
1164 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001165 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001166 try {
1167 r.callback.onCallForwardingIndicatorChanged(cfi);
1168 } catch (RemoteException ex) {
1169 mRemoveList.add(r.binder);
1170 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 }
1172 }
1173 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001174 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176 }
1177
1178 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001179 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001180 }
1181
Wink Saville63f03dd2014-10-23 10:44:45 -07001182 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001183 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001184 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001187 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001188 if (validatePhoneId(phoneId)) {
1189 mDataActivity[phoneId] = state;
1190 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001191 // Notify by correct subId.
1192 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1193 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001194 try {
1195 r.callback.onDataActivity(state);
1196 } catch (RemoteException ex) {
1197 mRemoveList.add(r.binder);
1198 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 }
1200 }
1201 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001202 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
1204 }
1205
Jack Yubaeec622017-05-01 17:01:11 -07001206 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001207 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001208 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001209 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001210 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001211 networkCapabilities, networkType, roaming);
1212 }
1213
Wink Saville63f03dd2014-10-23 10:44:45 -07001214 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001215 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001216 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1217 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001218 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001219 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001220 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001221 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001222 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001223 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001224 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001225 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001226 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001229 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001230 if (validatePhoneId(phoneId)) {
1231 boolean modified = false;
1232 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001233 if (!mConnectedApns[phoneId].contains(apnType)) {
1234 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001235 if (mDataConnectionState[phoneId] != state) {
1236 mDataConnectionState[phoneId] = state;
1237 modified = true;
1238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001240 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001241 if (mConnectedApns[phoneId].remove(apnType)) {
1242 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001243 mDataConnectionState[phoneId] = state;
1244 modified = true;
1245 } else {
1246 // leave mDataConnectionState as is and
1247 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001248 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001249 }
1250 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001251 mDataConnectionLinkProperties[phoneId] = linkProperties;
1252 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1253 if (mDataConnectionNetworkType[phoneId] != networkType) {
1254 mDataConnectionNetworkType[phoneId] = networkType;
1255 // need to tell registered listeners about the new network type
1256 modified = true;
1257 }
1258 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001259 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1260 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1261 log(str);
1262 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001263 for (Record r : mRecords) {
1264 if (r.matchPhoneStateListenerEvent(
1265 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1266 idMatch(r.subId, subId, phoneId)) {
1267 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001268 if (DBG) {
1269 log("Notify data connection state changed on sub: " + subId);
1270 }
1271 r.callback.onDataConnectionStateChanged(
1272 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001273 mDataConnectionNetworkType[phoneId]);
1274 } catch (RemoteException ex) {
1275 mRemoveList.add(r.binder);
1276 }
1277 }
1278 }
1279 handleRemoveListLocked();
1280 }
1281 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1282 apnType, apn, reason, linkProperties, "");
1283 for (Record r : mRecords) {
1284 if (r.matchPhoneStateListenerEvent(
1285 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1286 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001287 r.callback.onPreciseDataConnectionStateChanged(
1288 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001289 } catch (RemoteException ex) {
1290 mRemoveList.add(r.binder);
1291 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001292 }
1293 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001294 }
1295 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 }
Jack Yubaeec622017-05-01 17:01:11 -07001297 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001298 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001299 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1300 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 }
1302
Robert Greenwalt02648a42010-05-18 10:52:51 -07001303 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001304 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001305 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001306 }
1307
Wink Saville63f03dd2014-10-23 10:44:45 -07001308 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001309 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001310 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001311 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001312 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001313 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001314 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001315 + " reason=" + reason + " apnType=" + apnType);
1316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001318 mPreciseDataConnectionState = new PreciseDataConnectionState(
1319 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1320 apnType, "", reason, null, "");
1321 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001322 if (r.matchPhoneStateListenerEvent(
1323 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001324 try {
1325 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1326 } catch (RemoteException ex) {
1327 mRemoveList.add(r.binder);
1328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 }
1330 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001331 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001333 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001334 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1335 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 }
1337
1338 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001339 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001340 }
1341
Wink Saville63f03dd2014-10-23 10:44:45 -07001342 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001343 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001344 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001345 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001346 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001347 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001348 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001349 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001350 + " cellLocation=" + cellLocation);
1351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001353 int phoneId = SubscriptionManager.getPhoneId(subId);
1354 if (validatePhoneId(phoneId)) {
1355 mCellLocation[phoneId] = cellLocation;
1356 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001357 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu3d309462018-02-06 18:13:36 +00001358 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001359 try {
1360 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001361 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001362 + " r=" + r);
1363 }
1364 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1365 } catch (RemoteException ex) {
1366 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001367 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001368 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 }
1370 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001371 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001372 }
1373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374
Wink Savillefd2d0132010-10-28 14:22:26 -07001375 public void notifyOtaspChanged(int otaspMode) {
1376 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1377 return;
1378 }
1379 synchronized (mRecords) {
1380 mOtaspMode = otaspMode;
1381 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001382 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001383 try {
1384 r.callback.onOtaspChanged(otaspMode);
1385 } catch (RemoteException ex) {
1386 mRemoveList.add(r.binder);
1387 }
1388 }
1389 }
1390 handleRemoveListLocked();
1391 }
1392 }
1393
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001394 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1395 int backgroundCallState) {
1396 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1397 return;
1398 }
1399 synchronized (mRecords) {
1400 mRingingCallState = ringingCallState;
1401 mForegroundCallState = foregroundCallState;
1402 mBackgroundCallState = backgroundCallState;
1403 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1404 backgroundCallState,
1405 DisconnectCause.NOT_VALID,
1406 PreciseDisconnectCause.NOT_VALID);
1407 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001408 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001409 try {
1410 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1411 } catch (RemoteException ex) {
1412 mRemoveList.add(r.binder);
1413 }
1414 }
1415 }
1416 handleRemoveListLocked();
1417 }
1418 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1419 DisconnectCause.NOT_VALID,
1420 PreciseDisconnectCause.NOT_VALID);
1421 }
1422
1423 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1424 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1425 return;
1426 }
1427 synchronized (mRecords) {
1428 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1429 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1430 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001431 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001432 try {
1433 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1434 } catch (RemoteException ex) {
1435 mRemoveList.add(r.binder);
1436 }
1437 }
1438 }
1439 handleRemoveListLocked();
1440 }
1441 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1442 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1443 }
1444
1445 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1446 String apn, String failCause) {
1447 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1448 return;
1449 }
1450 synchronized (mRecords) {
1451 mPreciseDataConnectionState = new PreciseDataConnectionState(
1452 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1453 apnType, apn, reason, null, failCause);
1454 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001455 if (r.matchPhoneStateListenerEvent(
1456 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001457 try {
1458 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1459 } catch (RemoteException ex) {
1460 mRemoveList.add(r.binder);
1461 }
1462 }
1463 }
1464 handleRemoveListLocked();
1465 }
1466 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1467 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1468 }
1469
Wink Savillefb40dd42014-06-12 17:02:31 -07001470 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1471 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1472 return;
1473 }
1474 synchronized (mRecords) {
1475 mVoLteServiceState = lteState;
1476 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001477 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001478 try {
1479 r.callback.onVoLteServiceStateChanged(
1480 new VoLteServiceState(mVoLteServiceState));
1481 } catch (RemoteException ex) {
1482 mRemoveList.add(r.binder);
1483 }
1484 }
1485 }
1486 handleRemoveListLocked();
1487 }
1488 }
1489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001491 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1492 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1493
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001494 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001497 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001499 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301500 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001501 pw.println("Phone Id=" + i);
1502 pw.increaseIndent();
1503 pw.println("mCallState=" + mCallState[i]);
1504 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1505 pw.println("mServiceState=" + mServiceState[i]);
1506 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1507 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001508 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001509 pw.println("mSignalStrength=" + mSignalStrength[i]);
1510 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1511 pw.println("mCallForwarding=" + mCallForwarding[i]);
1512 pw.println("mDataActivity=" + mDataActivity[i]);
1513 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001514 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1515 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301516 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001517 pw.println("mCellLocation=" + mCellLocation[i]);
1518 pw.println("mCellInfo=" + mCellInfo.get(i));
1519 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301520 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001521 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1522 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1523 pw.println("mPreciseCallState=" + mPreciseCallState);
1524 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1525 pw.println("mRingingCallState=" + mRingingCallState);
1526 pw.println("mForegroundCallState=" + mForegroundCallState);
1527 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1528 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1529
1530 pw.decreaseIndent();
1531
1532 pw.println("local logs:");
1533 pw.increaseIndent();
1534 mLocalLog.dump(fd, pw, args);
1535 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001536 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001537 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001538 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001539 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001541 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 }
1543 }
1544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 //
1546 // the legacy intent broadcasting
1547 //
1548
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001549 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001550 long ident = Binder.clearCallingIdentity();
1551 try {
1552 mBatteryStats.notePhoneState(state.getState());
1553 } catch (RemoteException re) {
1554 // Can't do much
1555 } finally {
1556 Binder.restoreCallingIdentity(ident);
1557 }
1558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001560 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 Bundle data = new Bundle();
1562 state.fillInNotifierBundle(data);
1563 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001564 // Pass the subscription along with the intent.
1565 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001566 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001567 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 }
1569
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001570 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1571 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001572 long ident = Binder.clearCallingIdentity();
1573 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001574 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001575 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001576 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001577 } finally {
1578 Binder.restoreCallingIdentity(ident);
1579 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001582 Bundle data = new Bundle();
1583 signalStrength.fillInNotifierBundle(data);
1584 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001585 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001586 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001587 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 }
1589
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001590 /**
1591 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1592 * a valid subId, in which case this function fires a subId-specific intent, or it
1593 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1594 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1595 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001596 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1597 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 long ident = Binder.clearCallingIdentity();
1599 try {
1600 if (state == TelephonyManager.CALL_STATE_IDLE) {
1601 mBatteryStats.notePhoneOff();
1602 } else {
1603 mBatteryStats.notePhoneOn();
1604 }
1605 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001606 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 } finally {
1608 Binder.restoreCallingIdentity(ident);
1609 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001612 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001613 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 if (!TextUtils.isEmpty(incomingNumber)) {
1615 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1616 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001617
1618 // If a valid subId was specified, we should fire off a subId-specific state
1619 // change intent and include the subId.
1620 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1621 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1622 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1623 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001624 // If the phoneId is invalid, the broadcast is for overall call state.
1625 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1626 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1627 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001628
Brad Ebinger51de96a2017-04-21 17:05:18 -07001629 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1630 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1631
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001632 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1633 // that have the runtime one
1634 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1635 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001636 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001637 android.Manifest.permission.READ_PHONE_STATE,
1638 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 }
1640
Robert Greenwalt42acef32009-08-12 16:08:25 -07001641 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001642 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001643 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001644 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001645 // Note: not reporting to the battery stats service here, because the
1646 // status bar takes care of that after taking into account all of the
1647 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001649 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001650 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001651 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001652 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 }
1654 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001655 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001657 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001658 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001659 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001660 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001661 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001662 }
1663 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001664 if (networkCapabilities != null) {
1665 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001666 }
Wink Savillea639b312012-07-10 12:37:54 -07001667 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001668
Wink Savillea639b312012-07-10 12:37:54 -07001669 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1670 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001671 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001672 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 }
1674
Wink Savillefb40dd42014-06-12 17:02:31 -07001675 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001676 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001678 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1679 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001680 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001681 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001683
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001684 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1685 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1686 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1687 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1688 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1689 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1690 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1691 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1692 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1693 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1694 }
1695
1696 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001697 String apnType, String apn, String reason, LinkProperties linkProperties,
1698 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001699 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1700 intent.putExtra(PhoneConstants.STATE_KEY, state);
1701 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1702 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1703 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1704 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001705 if (linkProperties != null) {
1706 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1707 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001708 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1709
1710 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1711 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1712 }
1713
Andrew Flynnceaed682015-06-09 12:36:58 +00001714 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1715 if (checkNotifyPermission()) {
1716 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001717 }
1718
Andrew Flynnceaed682015-06-09 12:36:58 +00001719 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001720 }
1721
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001722 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001723 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001724 return true;
1725 }
1726 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001727 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001728 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001729 return false;
1730 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001731
Andrew Flynn1f452642015-04-14 22:16:04 -04001732 private boolean checkNotifyPermission() {
1733 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1734 == PackageManager.PERMISSION_GRANTED;
1735 }
1736
Andrew Flynnceaed682015-06-09 12:36:58 +00001737 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001738 TelephonyManager tm = TelephonyManager.getDefault();
1739 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1740 for (String pkg : pkgs) {
1741 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1742 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001743 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001744 }
1745 }
1746
Andrew Flynnceaed682015-06-09 12:36:58 +00001747 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1748 + ", uid=" + Binder.getCallingUid();
1749 if (DBG) log(msg);
1750 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001751 }
1752
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001753 private void checkListenerPermission(int events) {
1754 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1755 mContext.enforceCallingOrSelfPermission(
1756 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1757
1758 }
1759
John Wang963db55d2012-03-30 16:04:06 -07001760 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1761 mContext.enforceCallingOrSelfPermission(
1762 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1763
1764 }
1765
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001766 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001767 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001768 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001769 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001770 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1771 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001772 } catch (SecurityException e) {
1773 mContext.enforceCallingOrSelfPermission(
1774 android.Manifest.permission.READ_PHONE_STATE, null);
1775 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001776 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001777
1778 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1779 mContext.enforceCallingOrSelfPermission(
1780 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1781
1782 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001783 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001784
1785 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001786 int size = mRemoveList.size();
1787 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1788 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001789 for (IBinder b: mRemoveList) {
1790 remove(b);
1791 }
1792 mRemoveList.clear();
1793 }
1794 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001795
1796 private boolean validateEventsAndUserLocked(Record r, int events) {
1797 int foregroundUser;
1798 long callingIdentity = Binder.clearCallingIdentity();
1799 boolean valid = false;
1800 try {
1801 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu3d309462018-02-06 18:13:36 +00001802 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001803 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001804 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu3d309462018-02-06 18:13:36 +00001805 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001806 + " r.events=" + r.events + " events=" + events);
1807 }
1808 } finally {
1809 Binder.restoreCallingIdentity(callingIdentity);
1810 }
1811 return valid;
1812 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001813
1814 private boolean validatePhoneId(int phoneId) {
1815 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001816 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001817 return valid;
1818 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001819
1820 private static void log(String s) {
1821 Rlog.d(TAG, s);
1822 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001823
xinhe8b79fb62014-11-05 14:55:03 -08001824 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001825
1826 if(subId < 0) {
1827 // Invalid case, we need compare phoneId with default one.
1828 return (mDefaultPhoneId == phoneId);
1829 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001830 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001831 return (subId == mDefaultSubId);
1832 } else {
1833 return (rSubId == subId);
1834 }
1835 }
1836
1837 private void checkPossibleMissNotify(Record r, int phoneId) {
1838 int events = r.events;
1839
1840 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1841 try {
1842 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1843 mServiceState[phoneId]);
1844 r.callback.onServiceStateChanged(
1845 new ServiceState(mServiceState[phoneId]));
1846 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001847 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001848 }
1849 }
1850
1851 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1852 try {
1853 SignalStrength signalStrength = mSignalStrength[phoneId];
1854 if (DBG) {
1855 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1856 }
1857 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1858 } catch (RemoteException ex) {
1859 mRemoveList.add(r.binder);
1860 }
1861 }
1862
1863 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1864 try {
1865 int gsmSignalStrength = mSignalStrength[phoneId]
1866 .getGsmSignalStrength();
1867 if (DBG) {
1868 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1869 gsmSignalStrength);
1870 }
1871 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1872 : gsmSignalStrength));
1873 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001874 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001875 }
1876 }
1877
1878 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1879 try {
1880 if (DBG_LOC) {
1881 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1882 + mCellInfo.get(phoneId));
1883 }
Hall Liu3d309462018-02-06 18:13:36 +00001884 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
xinhee9f16402014-09-25 16:39:28 -07001885 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001886 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001887 }
1888 }
1889
zxuan35a47022018-01-04 11:24:04 -08001890 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1891 try {
1892 if (VDBG) {
1893 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1894 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1895 }
1896 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1897 } catch (RemoteException ex) {
1898 mRemoveList.add(r.binder);
1899 }
1900 }
1901
xinhee9f16402014-09-25 16:39:28 -07001902 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1903 try {
1904 if (VDBG) {
1905 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1906 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1907 }
1908 r.callback.onMessageWaitingIndicatorChanged(
1909 mMessageWaiting[phoneId]);
1910 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001911 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001912 }
1913 }
1914
1915 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1916 try {
1917 if (VDBG) {
1918 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1919 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1920 }
1921 r.callback.onCallForwardingIndicatorChanged(
1922 mCallForwarding[phoneId]);
1923 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001924 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001925 }
1926 }
1927
1928 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1929 try {
1930 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1931 + mCellLocation[phoneId]);
Hall Liu3d309462018-02-06 18:13:36 +00001932 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
xinhee9f16402014-09-25 16:39:28 -07001933 } catch (RemoteException ex) {
1934 mRemoveList.add(r.binder);
1935 }
1936 }
1937
1938 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1939 try {
1940 if (DBG) {
1941 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1942 + "=" + mDataConnectionState[phoneId]
1943 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1944 + ")");
1945 }
1946 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1947 mDataConnectionNetworkType[phoneId]);
1948 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001949 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001950 }
1951 }
1952 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953}