blob: 5e5eacb5c76771356be08ea5d8aeb26c3857ab7c [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;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020039import android.telephony.PreciseCallState;
40import android.telephony.PreciseDataConnectionState;
41import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070042import android.telephony.Rlog;
43import android.telephony.ServiceState;
44import android.telephony.SignalStrength;
45import android.telephony.SubscriptionManager;
46import android.telephony.TelephonyManager;
47import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070049import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080052import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070054import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080055import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070056import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import com.android.internal.telephony.TelephonyIntents;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060058import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070059import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import com.android.server.am.BatteryStatsService;
61
Jack Yud19b6ae2017-04-05 14:12:09 -070062import java.io.FileDescriptor;
63import java.io.PrintWriter;
64import java.util.ArrayList;
65import java.util.Arrays;
66import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080067import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069/**
Wink Savillee9b06d72009-05-18 21:47:50 -070070 * Since phone process can be restarted, this class provides a centralized place
71 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070072 *
73 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
74 * and 15973975 by saving the phoneId of the registrant and then using the
75 * phoneId when deciding to to make a callback. This is necessary because
76 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070077 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070078 * the dummy value conversion we properly do the callbacks.
79 *
80 * Eventually we may want to remove the notion of dummy value but for now this
81 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 */
83class TelephonyRegistry extends ITelephonyRegistry.Stub {
84 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070085 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070086 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070087 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
89 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070090 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
Malcolm Chenabbfac22018-02-12 19:15:59 -080094 TelephonyRegistryDeathRecipient deathRecipient;
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080097 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070098
Hall Liu3d309462018-02-06 18:13:36 +000099 int callerUserId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700102
Wink Savilled09c4ca2014-11-22 10:08:16 -0800103 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700104
Wink Savilled09c4ca2014-11-22 10:08:16 -0800105 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800106
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700107 boolean canReadPhoneState;
108
Wink Savillea374c3d2014-11-11 11:48:04 -0800109 boolean matchPhoneStateListenerEvent(int events) {
110 return (callback != null) && ((events & this.events) != 0);
111 }
112
Wink Savilled09c4ca2014-11-22 10:08:16 -0800113 boolean matchOnSubscriptionsChangedListener() {
114 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800115 }
Wink Savillee380b982014-07-26 18:24:22 -0700116
Wink Savillea12a7b32012-09-20 10:09:45 -0700117 @Override
118 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700119 return "{callingPackage=" + callingPackage + " binder=" + binder
120 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800121 + " onSubscriptionsChangedListenererCallback="
122 + onSubscriptionsChangedListenerCallback
Hall Liu3d309462018-02-06 18:13:36 +0000123 + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700124 + " events=" + Integer.toHexString(events)
125 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 }
128
129 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700130
Joe Onorato163d8d92010-10-21 13:21:20 -0400131 // access should be inside synchronized (mRecords) for these two fields
132 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
133 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 private final IBatteryStats mBatteryStats;
136
Svet Ganov16a16892015-04-16 10:32:04 -0700137 private final AppOpsManager mAppOps;
138
Wink Savilled09c4ca2014-11-22 10:08:16 -0800139 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
140
Wink Savillefb40dd42014-06-12 17:02:31 -0700141 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700142
Wink Savillefb40dd42014-06-12 17:02:31 -0700143 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700144
Wink Savillefb40dd42014-06-12 17:02:31 -0700145 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700146
Wink Savillefb40dd42014-06-12 17:02:31 -0700147 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700148
fionaxu12312f62016-11-14 13:32:14 -0800149 private int[] mVoiceActivationState;
150
151 private int[] mDataActivationState;
152
zxuan35a47022018-01-04 11:24:04 -0800153 private boolean[] mUserMobileDataState;
154
Wink Savillefb40dd42014-06-12 17:02:31 -0700155 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700156
Wink Savillefb40dd42014-06-12 17:02:31 -0700157 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700158
Wink Savillefb40dd42014-06-12 17:02:31 -0700159 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700160
Wink Savillefb40dd42014-06-12 17:02:31 -0700161 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700162
Wink Savillefb40dd42014-06-12 17:02:31 -0700163 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700164
Yifan Bai57b39e32016-04-01 16:24:33 +0800165 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700166
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700168
Wink Savillefb40dd42014-06-12 17:02:31 -0700169 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700170
Wink Savillefb40dd42014-06-12 17:02:31 -0700171 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172
Wink Savillefb40dd42014-06-12 17:02:31 -0700173 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700174
Nathan Harold016e9c62016-12-14 11:24:48 -0800175 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private ArrayList<List<CellInfo>> mCellInfo = null;
178
179 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
180
Wink Savilled09c4ca2014-11-22 10:08:16 -0800181 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700182
Wink Savilled09c4ca2014-11-22 10:08:16 -0800183 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700184
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200185 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
186
187 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
188
189 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
190
191 private PreciseCallState mPreciseCallState = new PreciseCallState();
192
Andrew Flynn1f452642015-04-14 22:16:04 -0400193 private boolean mCarrierNetworkChangeState = false;
194
Jack Yud19b6ae2017-04-05 14:12:09 -0700195 private final LocalLog mLocalLog = new LocalLog(100);
196
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200197 private PreciseDataConnectionState mPreciseDataConnectionState =
198 new PreciseDataConnectionState();
199
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700200 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700201 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700202 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
203 PhoneStateListener.LISTEN_VOLTE_STATE;
204
205 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700206 PhoneStateListener.LISTEN_CALL_STATE |
207 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700208 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700209
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200210 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
211 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
212 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
213
Wink Savillea12a7b32012-09-20 10:09:45 -0700214 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700215 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700216
217 private final Handler mHandler = new Handler() {
218 @Override
219 public void handleMessage(Message msg) {
220 switch (msg.what) {
221 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700222 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700223 int numPhones = TelephonyManager.getDefault().getPhoneCount();
224 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700225 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700226 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700227 }
228 break;
229 }
xinhee9f16402014-09-25 16:39:28 -0700230 case MSG_UPDATE_DEFAULT_SUB: {
231 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700232 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700233 if (VDBG) {
234 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
235 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
236 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
237 }
238
239 //Due to possible risk condition,(notify call back using the new
240 //defaultSubId comes before new defaultSubId update) we need to recall all
241 //possible missed notify callback
242 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700243 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800244 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700245 checkPossibleMissNotify(r, newDefaultPhoneId);
246 }
247 }
248 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700249 }
250 mDefaultSubId = newDefaultSubId;
251 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700252 }
253 }
254 }
255 };
256
Malcolm Chenabbfac22018-02-12 19:15:59 -0800257 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
258
259 private final IBinder binder;
260
261 TelephonyRegistryDeathRecipient(IBinder binder) {
262 this.binder = binder;
263 }
264
265 @Override
266 public void binderDied() {
267 if (DBG) log("binderDied " + binder);
268 remove(binder);
269 }
270 }
271
Wink Savillea12a7b32012-09-20 10:09:45 -0700272 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
273 @Override
274 public void onReceive(Context context, Intent intent) {
275 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700276 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700277 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700278 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700279 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700280 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700281 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700282 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800283 PhoneConstants.SUBSCRIPTION_KEY,
284 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700285 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
286 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700287 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700288 log("onReceive:current mDefaultSubId=" + mDefaultSubId
289 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
290 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700291 }
xinhee9f16402014-09-25 16:39:28 -0700292
Junda Liu985f52c2015-02-23 16:06:51 -0800293 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700294 || (newDefaultPhoneId != mDefaultPhoneId))) {
295 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
296 newDefaultPhoneId, 0, newDefaultSubIdObj));
297 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700298 }
299 }
300 };
301
Wink Savillee9b06d72009-05-18 21:47:50 -0700302 // we keep a copy of all of the state so we can send it out when folks
303 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700305 // In these calls we call with the lock held. This is safe becasuse remote
306 // calls go through a oneway interface and local calls going through a
307 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308
309 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700310 CellLocation location = CellLocation.getEmpty();
311
Wink Savillefb40dd42014-06-12 17:02:31 -0700312 mContext = context;
313 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700314
Wink Savillefb40dd42014-06-12 17:02:31 -0700315 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700316 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700317 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800318 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700319 mCallState = new int[numPhones];
320 mDataActivity = new int[numPhones];
321 mDataConnectionState = new int[numPhones];
322 mDataConnectionNetworkType = new int[numPhones];
323 mCallIncomingNumber = new String[numPhones];
324 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800325 mVoiceActivationState = new int[numPhones];
326 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800327 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700328 mSignalStrength = new SignalStrength[numPhones];
329 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700330 mCallForwarding = new boolean[numPhones];
331 mCellLocation = new Bundle[numPhones];
332 mDataConnectionLinkProperties = new LinkProperties[numPhones];
333 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
334 mCellInfo = new ArrayList<List<CellInfo>>();
335 for (int i = 0; i < numPhones; i++) {
336 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
337 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
338 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800339 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
340 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700341 mCallIncomingNumber[i] = "";
342 mServiceState[i] = new ServiceState();
343 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800344 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700345 mMessageWaiting[i] = false;
346 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700347 mCellLocation[i] = new Bundle();
348 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800349 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700350 }
351
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700352 // Note that location can be null for non-phone builds like
353 // like the generic one.
354 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 for (int i = 0; i < numPhones; i++) {
356 location.fillInNotifierBundle(mCellLocation[i]);
357 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700358 }
Svet Ganov16a16892015-04-16 10:32:04 -0700359
360 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 }
362
Svetoslav Ganova0027152013-06-25 14:59:53 -0700363 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700364 // Watch for interesting updates
365 final IntentFilter filter = new IntentFilter();
366 filter.addAction(Intent.ACTION_USER_SWITCHED);
367 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700368 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700369 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700370 mContext.registerReceiver(mBroadcastReceiver, filter);
371 }
372
373 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700374 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800375 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700376 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800377 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700378 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
379 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800380 + " callback.asBinder=" + callback.asBinder());
381 }
382
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700383 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700384 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700385 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
386 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700387 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700388 } catch (SecurityException e) {
389 mContext.enforceCallingOrSelfPermission(
390 android.Manifest.permission.READ_PHONE_STATE,
391 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700392
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700393 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
394 callingPackage) != AppOpsManager.MODE_ALLOWED) {
395 return;
396 }
Svet Ganov16a16892015-04-16 10:32:04 -0700397 }
398
Wink Savillea374c3d2014-11-11 11:48:04 -0800399
Wink Savilled09c4ca2014-11-22 10:08:16 -0800400 synchronized (mRecords) {
401 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800402 IBinder b = callback.asBinder();
403 Record r = add(b);
404
405 if (r == null) {
406 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800407 }
408
Wink Savilled09c4ca2014-11-22 10:08:16 -0800409 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700410 r.callingPackage = callingPackage;
Hall Liu3d309462018-02-06 18:13:36 +0000411 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800412 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700413 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 if (DBG) {
415 log("listen oscl: Register r=" + r);
416 }
417 // Always notify when registration occurs if there has been a notification.
418 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800420 if (VDBG) log("listen oscl: send to r=" + r);
421 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
422 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800423 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800424 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 remove(r.binder);
426 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800427 } else {
428 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800429 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800430 }
431 }
432
433 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800434 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800435 IOnSubscriptionsChangedListener callback) {
436 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800437 remove(callback.asBinder());
438 }
439
Wink Savillea374c3d2014-11-11 11:48:04 -0800440 @Override
441 public void notifySubscriptionInfoChanged() {
442 if (VDBG) log("notifySubscriptionInfoChanged:");
443 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800444 if (!hasNotifySubscriptionInfoChangedOccurred) {
445 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
446 + mRecords.size());
447 }
448 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800449 mRemoveList.clear();
450 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800451 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800452 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800453 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
454 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
455 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800456 } catch (RemoteException ex) {
457 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
458 mRemoveList.add(r.binder);
459 }
460 }
461 }
462 handleRemoveListLocked();
463 }
464 }
465
466 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
468 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800469 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
470 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700471 }
472
473 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700474 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700475 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700476 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700477 }
478
Svet Ganov16a16892015-04-16 10:32:04 -0700479 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700480 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700481 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700482 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700483 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700484 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
485 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700486 }
xinhe75c2c152014-10-16 11:49:45 -0700487
488 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700489 /* Checks permission and throws Security exception */
490 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700491
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700492 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700493 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700494 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700495 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700496 // SKIP checking for run-time permission since caller or self has PRIVILEGED
497 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700498 } catch (SecurityException e) {
499 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
500 callingPackage) != AppOpsManager.MODE_ALLOWED) {
501 return;
502 }
Svet Ganov16a16892015-04-16 10:32:04 -0700503 }
504 }
505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 synchronized (mRecords) {
507 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800508 IBinder b = callback.asBinder();
509 Record r = add(b);
510
511 if (r == null) {
512 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
xinhe43c50292014-09-18 17:56:48 -0700514
xinhe75c2c152014-10-16 11:49:45 -0700515 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700516 r.callingPackage = callingPackage;
Hall Liu3d309462018-02-06 18:13:36 +0000517 r.callerUserId = callerUserId;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700518 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
519 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
520 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700521 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
522 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800524 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700525 } else {//APP specify subID
526 r.subId = subId;
527 }
528 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
529
xinhe43c50292014-09-18 17:56:48 -0700530 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700532 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700533 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700534 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700535 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400537 try {
Wink Savillee380b982014-07-26 18:24:22 -0700538 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700539 r.callback.onServiceStateChanged(
540 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400541 } catch (RemoteException ex) {
542 remove(r.binder);
543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 }
545 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
546 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700547 int gsmSignalStrength = mSignalStrength[phoneId]
548 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700549 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
550 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 } catch (RemoteException ex) {
552 remove(r.binder);
553 }
554 }
555 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
556 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700557 r.callback.onMessageWaitingIndicatorChanged(
558 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 } catch (RemoteException ex) {
560 remove(r.binder);
561 }
562 }
563 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
564 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700565 r.callback.onCallForwardingIndicatorChanged(
566 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 } catch (RemoteException ex) {
568 remove(r.binder);
569 }
570 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700571 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400572 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700573 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700574 + mCellLocation[phoneId]);
Hall Liu3d309462018-02-06 18:13:36 +0000575 r.callback.onCellLocationChanged(
576 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400577 } catch (RemoteException ex) {
578 remove(r.binder);
579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
581 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
582 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700583 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700584 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 } catch (RemoteException ex) {
586 remove(r.binder);
587 }
588 }
589 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
590 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700591 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
592 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 } catch (RemoteException ex) {
594 remove(r.binder);
595 }
596 }
597 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
598 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700599 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 } catch (RemoteException ex) {
601 remove(r.binder);
602 }
603 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700604 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
605 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700606 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700607 } catch (RemoteException ex) {
608 remove(r.binder);
609 }
610 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700611 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
612 try {
613 r.callback.onOtaspChanged(mOtaspMode);
614 } catch (RemoteException ex) {
615 remove(r.binder);
616 }
617 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700618 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700619 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700620 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700621 + mCellInfo.get(phoneId));
Hall Liu3d309462018-02-06 18:13:36 +0000622 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700623 } catch (RemoteException ex) {
624 remove(r.binder);
625 }
626 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200627 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
628 try {
629 r.callback.onPreciseCallStateChanged(mPreciseCallState);
630 } catch (RemoteException ex) {
631 remove(r.binder);
632 }
633 }
634 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
635 try {
636 r.callback.onPreciseDataConnectionStateChanged(
637 mPreciseDataConnectionState);
638 } catch (RemoteException ex) {
639 remove(r.binder);
640 }
641 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400642 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
643 try {
644 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
645 } catch (RemoteException ex) {
646 remove(r.binder);
647 }
648 }
fionaxu12312f62016-11-14 13:32:14 -0800649 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
650 try {
651 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
652 } catch (RemoteException ex) {
653 remove(r.binder);
654 }
655 }
656 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
657 try {
658 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
659 } catch (RemoteException ex) {
660 remove(r.binder);
661 }
662 }
zxuan35a47022018-01-04 11:24:04 -0800663 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
664 try {
665 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
666 } catch (RemoteException ex) {
667 remove(r.binder);
668 }
669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 }
671 }
672 } else {
xinhe75c2c152014-10-16 11:49:45 -0700673 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 remove(callback.asBinder());
675 }
676 }
677
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700678 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700679 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700680 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
681 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700682 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700683 return true;
684 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700685 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
686 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
687 if (canReadPhoneState &&
688 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
689 callingPackage) != AppOpsManager.MODE_ALLOWED) {
690 return false;
691 }
692 return canReadPhoneState;
693 }
694
695 private String getCallIncomingNumber(Record record, int phoneId) {
696 // Hide the number if record's process has no READ_PHONE_STATE permission
697 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
698 }
699
Malcolm Chenabbfac22018-02-12 19:15:59 -0800700 private Record add(IBinder binder) {
701 Record r;
702
703 synchronized (mRecords) {
704 final int N = mRecords.size();
705 for (int i = 0; i < N; i++) {
706 r = mRecords.get(i);
707 if (binder == r.binder) {
708 // Already existed.
709 return r;
710 }
711 }
712 r = new Record();
713 r.binder = binder;
714 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
715
716 try {
717 binder.linkToDeath(r.deathRecipient, 0);
718 } catch (RemoteException e) {
719 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
720 // Binder already died. Return null.
721 return null;
722 }
723
724 mRecords.add(r);
725 if (DBG) log("add new record");
726 }
727
728 return r;
729 }
730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 private void remove(IBinder binder) {
732 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700733 final int recordCount = mRecords.size();
734 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800735 Record r = mRecords.get(i);
736 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800737 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800738 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
739 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800740 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800741
742 if (r.deathRecipient != null) {
743 try {
744 binder.unlinkToDeath(r.deathRecipient, 0);
745 } catch (NoSuchElementException e) {
746 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
747 + r + " e=" + e);
748 }
749 }
750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 mRecords.remove(i);
752 return;
753 }
754 }
755 }
756 }
757
758 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700759 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700760 return;
761 }
xinhe43c50292014-09-18 17:56:48 -0700762
763 if (VDBG) {
764 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
765 }
766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700768 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800769 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800770 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700772 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
773 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400775 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 }
777 }
778 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400779 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700781
782 // Called only by Telecomm to communicate call state across different phone accounts. So
783 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800784 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700785 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700786 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 }
788
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700789 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
790 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700791 if (!checkNotifyPermission("notifyCallState()")) {
792 return;
793 }
Wink Savillee380b982014-07-26 18:24:22 -0700794 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700795 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700796 + " state=" + state + " incomingNumber=" + incomingNumber);
797 }
798 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700799 if (validatePhoneId(phoneId)) {
800 mCallState[phoneId] = state;
801 mCallIncomingNumber[phoneId] = incomingNumber;
802 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800803 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700804 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800805 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700806 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700807 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
808 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700809 } catch (RemoteException ex) {
810 mRemoveList.add(r.binder);
811 }
812 }
813 }
814 }
815 handleRemoveListLocked();
816 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700817 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700818 }
819
Wink Saville63f03dd2014-10-23 10:44:45 -0700820 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700821 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700822 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700823 }
xinhe43c50292014-09-18 17:56:48 -0700824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700826 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
827 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700828 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700829 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700830 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700831 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700832 if (validatePhoneId(phoneId)) {
833 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700834
Wink Savillefb40dd42014-06-12 17:02:31 -0700835 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700836 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700837 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700838 + " phoneId=" + phoneId + " state=" + state);
839 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800840 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800841 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700842 try {
Wink Savillee380b982014-07-26 18:24:22 -0700843 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700844 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700845 + " subId=" + subId + " phoneId=" + phoneId
846 + " state=" + state);
847 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700848 r.callback.onServiceStateChanged(new ServiceState(state));
849 } catch (RemoteException ex) {
850 mRemoveList.add(r.binder);
851 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700854 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700855 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400857 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700859 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 }
861
fionaxu12312f62016-11-14 13:32:14 -0800862 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
863 int activationType, int activationState) {
864 if (!checkNotifyPermission("notifySimActivationState()")){
865 return;
866 }
867 if (VDBG) {
868 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
869 + "type=" + activationType + " state=" + activationState);
870 }
871 synchronized (mRecords) {
872 if (validatePhoneId(phoneId)) {
873 switch (activationType) {
874 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
875 mVoiceActivationState[phoneId] = activationState;
876 break;
877 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
878 mDataActivationState[phoneId] = activationState;
879 break;
880 default:
881 return;
882 }
883 for (Record r : mRecords) {
884 if (VDBG) {
885 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
886 + " phoneId=" + phoneId + "type=" + activationType
887 + " state=" + activationState);
888 }
889 try {
890 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
891 r.matchPhoneStateListenerEvent(
892 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
893 idMatch(r.subId, subId, phoneId)) {
894 if (DBG) {
895 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
896 + " subId=" + subId + " phoneId=" + phoneId
897 + " state=" + activationState);
898 }
899 r.callback.onVoiceActivationStateChanged(activationState);
900 }
901 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
902 r.matchPhoneStateListenerEvent(
903 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
904 idMatch(r.subId, subId, phoneId)) {
905 if (DBG) {
906 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
907 + " subId=" + subId + " phoneId=" + phoneId
908 + " state=" + activationState);
909 }
910 r.callback.onDataActivationStateChanged(activationState);
911 }
912 } catch (RemoteException ex) {
913 mRemoveList.add(r.binder);
914 }
915 }
916 } else {
917 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
918 }
919 handleRemoveListLocked();
920 }
921 }
922
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700923 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
924 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700925 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700926 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700927 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000928 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700929 log("notifySignalStrengthForPhoneId: subId=" + subId
930 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000931 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700934 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700935 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700936 mSignalStrength[phoneId] = signalStrength;
937 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000938 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700939 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000940 + " phoneId=" + phoneId + " ss=" + signalStrength);
941 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800942 if (r.matchPhoneStateListenerEvent(
943 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800944 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700945 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000946 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700947 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000948 + " subId=" + subId + " phoneId=" + phoneId
949 + " ss=" + signalStrength);
950 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700951 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
952 } catch (RemoteException ex) {
953 mRemoveList.add(r.binder);
954 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400955 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800956 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800957 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700958 try {
959 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700960 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000961 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700962 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000963 + " subId=" + subId + " phoneId=" + phoneId
964 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
965 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700966 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700967 } catch (RemoteException ex) {
968 mRemoveList.add(r.binder);
969 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
971 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700972 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700973 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400975 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700977 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 }
979
Andrew Flynn1f452642015-04-14 22:16:04 -0400980 @Override
981 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000982 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
983
Andrew Flynn1f452642015-04-14 22:16:04 -0400984 if (VDBG) {
985 log("notifyCarrierNetworkChange: active=" + active);
986 }
987
988 synchronized (mRecords) {
989 mCarrierNetworkChangeState = active;
990 for (Record r : mRecords) {
991 if (r.matchPhoneStateListenerEvent(
992 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
993 try {
994 r.callback.onCarrierNetworkChange(active);
995 } catch (RemoteException ex) {
996 mRemoveList.add(r.binder);
997 }
998 }
999 }
1000 handleRemoveListLocked();
1001 }
1002 }
1003
Wink Savilleb208a242012-07-25 14:08:09 -07001004 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001005 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001006 }
1007
Wink Saville63f03dd2014-10-23 10:44:45 -07001008 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001009 if (!checkNotifyPermission("notifyCellInfo()")) {
1010 return;
1011 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001013 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001014 + " cellInfo=" + cellInfo);
1015 }
John Wang963db55d2012-03-30 16:04:06 -07001016
1017 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001018 int phoneId = SubscriptionManager.getPhoneId(subId);
1019 if (validatePhoneId(phoneId)) {
1020 mCellInfo.set(phoneId, cellInfo);
1021 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001022 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu3d309462018-02-06 18:13:36 +00001023 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001024 try {
1025 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001026 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001027 }
1028 r.callback.onCellInfoChanged(cellInfo);
1029 } catch (RemoteException ex) {
1030 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001031 }
John Wang963db55d2012-03-30 16:04:06 -07001032 }
1033 }
1034 }
1035 handleRemoveListLocked();
1036 }
1037 }
1038
xinhe43c50292014-09-18 17:56:48 -07001039 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001040 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001041 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001042 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001043 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001044 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001045 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001046 + " mwi=" + mwi);
1047 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001049 if (validatePhoneId(phoneId)) {
1050 mMessageWaiting[phoneId] = mwi;
1051 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001052 if (r.matchPhoneStateListenerEvent(
1053 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001054 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001055 try {
1056 r.callback.onMessageWaitingIndicatorChanged(mwi);
1057 } catch (RemoteException ex) {
1058 mRemoveList.add(r.binder);
1059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 }
1061 }
1062 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001063 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 }
1065 }
1066
zxuan35a47022018-01-04 11:24:04 -08001067 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1068 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1069 return;
1070 }
1071 if (VDBG) {
1072 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1073 + " state=" + state);
1074 }
1075 synchronized (mRecords) {
1076 if (validatePhoneId(phoneId)) {
1077 mMessageWaiting[phoneId] = state;
1078 for (Record r : mRecords) {
1079 if (r.matchPhoneStateListenerEvent(
1080 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1081 idMatch(r.subId, subId, phoneId)) {
1082 try {
1083 r.callback.onUserMobileDataStateChanged(state);
1084 } catch (RemoteException ex) {
1085 mRemoveList.add(r.binder);
1086 }
1087 }
1088 }
1089 }
1090 handleRemoveListLocked();
1091 }
1092 }
1093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001095 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001096 }
1097
Wink Saville63f03dd2014-10-23 10:44:45 -07001098 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001099 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001100 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001101 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001102 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001103 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001104 + " cfi=" + cfi);
1105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001107 int phoneId = SubscriptionManager.getPhoneId(subId);
1108 if (validatePhoneId(phoneId)) {
1109 mCallForwarding[phoneId] = cfi;
1110 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001111 if (r.matchPhoneStateListenerEvent(
1112 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001113 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001114 try {
1115 r.callback.onCallForwardingIndicatorChanged(cfi);
1116 } catch (RemoteException ex) {
1117 mRemoveList.add(r.binder);
1118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 }
1120 }
1121 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001122 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 }
1124 }
1125
1126 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001127 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001128 }
1129
Wink Saville63f03dd2014-10-23 10:44:45 -07001130 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001131 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001132 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001135 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001136 if (validatePhoneId(phoneId)) {
1137 mDataActivity[phoneId] = state;
1138 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001139 // Notify by correct subId.
1140 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1141 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001142 try {
1143 r.callback.onDataActivity(state);
1144 } catch (RemoteException ex) {
1145 mRemoveList.add(r.binder);
1146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 }
1148 }
1149 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001150 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
1152 }
1153
Jack Yubaeec622017-05-01 17:01:11 -07001154 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001155 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001156 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001157 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001158 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001159 networkCapabilities, networkType, roaming);
1160 }
1161
Wink Saville63f03dd2014-10-23 10:44:45 -07001162 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001163 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001164 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1165 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001166 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001167 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001168 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001169 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001170 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001171 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001172 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001173 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001174 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001177 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001178 if (validatePhoneId(phoneId)) {
1179 boolean modified = false;
1180 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001181 if (!mConnectedApns[phoneId].contains(apnType)) {
1182 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001183 if (mDataConnectionState[phoneId] != state) {
1184 mDataConnectionState[phoneId] = state;
1185 modified = true;
1186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001188 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001189 if (mConnectedApns[phoneId].remove(apnType)) {
1190 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001191 mDataConnectionState[phoneId] = state;
1192 modified = true;
1193 } else {
1194 // leave mDataConnectionState as is and
1195 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001196 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001197 }
1198 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001199 mDataConnectionLinkProperties[phoneId] = linkProperties;
1200 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1201 if (mDataConnectionNetworkType[phoneId] != networkType) {
1202 mDataConnectionNetworkType[phoneId] = networkType;
1203 // need to tell registered listeners about the new network type
1204 modified = true;
1205 }
1206 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001207 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1208 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1209 log(str);
1210 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001211 for (Record r : mRecords) {
1212 if (r.matchPhoneStateListenerEvent(
1213 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1214 idMatch(r.subId, subId, phoneId)) {
1215 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001216 if (DBG) {
1217 log("Notify data connection state changed on sub: " + subId);
1218 }
1219 r.callback.onDataConnectionStateChanged(
1220 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001221 mDataConnectionNetworkType[phoneId]);
1222 } catch (RemoteException ex) {
1223 mRemoveList.add(r.binder);
1224 }
1225 }
1226 }
1227 handleRemoveListLocked();
1228 }
1229 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1230 apnType, apn, reason, linkProperties, "");
1231 for (Record r : mRecords) {
1232 if (r.matchPhoneStateListenerEvent(
1233 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1234 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001235 r.callback.onPreciseDataConnectionStateChanged(
1236 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001237 } catch (RemoteException ex) {
1238 mRemoveList.add(r.binder);
1239 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001240 }
1241 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001242 }
1243 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 }
Jack Yubaeec622017-05-01 17:01:11 -07001245 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001246 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001247 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1248 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
1250
Robert Greenwalt02648a42010-05-18 10:52:51 -07001251 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001252 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001253 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001254 }
1255
Wink Saville63f03dd2014-10-23 10:44:45 -07001256 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001257 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001258 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001259 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001260 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001261 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001262 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001263 + " reason=" + reason + " apnType=" + apnType);
1264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001266 mPreciseDataConnectionState = new PreciseDataConnectionState(
1267 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1268 apnType, "", reason, null, "");
1269 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001270 if (r.matchPhoneStateListenerEvent(
1271 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001272 try {
1273 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1274 } catch (RemoteException ex) {
1275 mRemoveList.add(r.binder);
1276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 }
1278 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001279 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001281 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001282 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1283 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 }
1285
1286 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001287 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001288 }
1289
Wink Saville63f03dd2014-10-23 10:44:45 -07001290 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001291 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001292 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001293 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001294 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001295 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001296 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001297 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001298 + " cellLocation=" + cellLocation);
1299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001301 int phoneId = SubscriptionManager.getPhoneId(subId);
1302 if (validatePhoneId(phoneId)) {
1303 mCellLocation[phoneId] = cellLocation;
1304 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001305 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu3d309462018-02-06 18:13:36 +00001306 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001307 try {
1308 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001309 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001310 + " r=" + r);
1311 }
1312 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1313 } catch (RemoteException ex) {
1314 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001315 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 }
1318 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001319 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001320 }
1321 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322
Wink Savillefd2d0132010-10-28 14:22:26 -07001323 public void notifyOtaspChanged(int otaspMode) {
1324 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1325 return;
1326 }
1327 synchronized (mRecords) {
1328 mOtaspMode = otaspMode;
1329 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001330 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001331 try {
1332 r.callback.onOtaspChanged(otaspMode);
1333 } catch (RemoteException ex) {
1334 mRemoveList.add(r.binder);
1335 }
1336 }
1337 }
1338 handleRemoveListLocked();
1339 }
1340 }
1341
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001342 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1343 int backgroundCallState) {
1344 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1345 return;
1346 }
1347 synchronized (mRecords) {
1348 mRingingCallState = ringingCallState;
1349 mForegroundCallState = foregroundCallState;
1350 mBackgroundCallState = backgroundCallState;
1351 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1352 backgroundCallState,
1353 DisconnectCause.NOT_VALID,
1354 PreciseDisconnectCause.NOT_VALID);
1355 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001356 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001357 try {
1358 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1359 } catch (RemoteException ex) {
1360 mRemoveList.add(r.binder);
1361 }
1362 }
1363 }
1364 handleRemoveListLocked();
1365 }
1366 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1367 DisconnectCause.NOT_VALID,
1368 PreciseDisconnectCause.NOT_VALID);
1369 }
1370
1371 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1372 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1373 return;
1374 }
1375 synchronized (mRecords) {
1376 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1377 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1378 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001379 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001380 try {
1381 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1382 } catch (RemoteException ex) {
1383 mRemoveList.add(r.binder);
1384 }
1385 }
1386 }
1387 handleRemoveListLocked();
1388 }
1389 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1390 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1391 }
1392
1393 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1394 String apn, String failCause) {
1395 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1396 return;
1397 }
1398 synchronized (mRecords) {
1399 mPreciseDataConnectionState = new PreciseDataConnectionState(
1400 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1401 apnType, apn, reason, null, failCause);
1402 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001403 if (r.matchPhoneStateListenerEvent(
1404 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001405 try {
1406 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1407 } catch (RemoteException ex) {
1408 mRemoveList.add(r.binder);
1409 }
1410 }
1411 }
1412 handleRemoveListLocked();
1413 }
1414 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1415 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1416 }
1417
Wink Savillefb40dd42014-06-12 17:02:31 -07001418 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1419 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1420 return;
1421 }
1422 synchronized (mRecords) {
1423 mVoLteServiceState = lteState;
1424 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001425 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001426 try {
1427 r.callback.onVoLteServiceStateChanged(
1428 new VoLteServiceState(mVoLteServiceState));
1429 } catch (RemoteException ex) {
1430 mRemoveList.add(r.binder);
1431 }
1432 }
1433 }
1434 handleRemoveListLocked();
1435 }
1436 }
1437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001439 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1440 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1441
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001442 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001445 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001447 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301448 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001449 pw.println("Phone Id=" + i);
1450 pw.increaseIndent();
1451 pw.println("mCallState=" + mCallState[i]);
1452 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1453 pw.println("mServiceState=" + mServiceState[i]);
1454 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1455 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001456 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001457 pw.println("mSignalStrength=" + mSignalStrength[i]);
1458 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1459 pw.println("mCallForwarding=" + mCallForwarding[i]);
1460 pw.println("mDataActivity=" + mDataActivity[i]);
1461 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001462 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1463 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301464 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001465 pw.println("mCellLocation=" + mCellLocation[i]);
1466 pw.println("mCellInfo=" + mCellInfo.get(i));
1467 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301468 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001469 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1470 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1471 pw.println("mPreciseCallState=" + mPreciseCallState);
1472 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1473 pw.println("mRingingCallState=" + mRingingCallState);
1474 pw.println("mForegroundCallState=" + mForegroundCallState);
1475 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1476 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1477
1478 pw.decreaseIndent();
1479
1480 pw.println("local logs:");
1481 pw.increaseIndent();
1482 mLocalLog.dump(fd, pw, args);
1483 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001484 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001485 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001486 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001487 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001489 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 }
1491 }
1492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 //
1494 // the legacy intent broadcasting
1495 //
1496
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001497 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001498 long ident = Binder.clearCallingIdentity();
1499 try {
1500 mBatteryStats.notePhoneState(state.getState());
1501 } catch (RemoteException re) {
1502 // Can't do much
1503 } finally {
1504 Binder.restoreCallingIdentity(ident);
1505 }
1506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001508 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 Bundle data = new Bundle();
1510 state.fillInNotifierBundle(data);
1511 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001512 // Pass the subscription along with the intent.
1513 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001514 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001515 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 }
1517
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001518 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1519 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001520 long ident = Binder.clearCallingIdentity();
1521 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001522 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001523 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001524 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001525 } finally {
1526 Binder.restoreCallingIdentity(ident);
1527 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001530 Bundle data = new Bundle();
1531 signalStrength.fillInNotifierBundle(data);
1532 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001533 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001534 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001535 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 }
1537
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001538 /**
1539 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1540 * a valid subId, in which case this function fires a subId-specific intent, or it
1541 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1542 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1543 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001544 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1545 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 long ident = Binder.clearCallingIdentity();
1547 try {
1548 if (state == TelephonyManager.CALL_STATE_IDLE) {
1549 mBatteryStats.notePhoneOff();
1550 } else {
1551 mBatteryStats.notePhoneOn();
1552 }
1553 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001554 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 } finally {
1556 Binder.restoreCallingIdentity(ident);
1557 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001560 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001561 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 if (!TextUtils.isEmpty(incomingNumber)) {
1563 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1564 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001565
1566 // If a valid subId was specified, we should fire off a subId-specific state
1567 // change intent and include the subId.
1568 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1569 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1570 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1571 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001572 // If the phoneId is invalid, the broadcast is for overall call state.
1573 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1574 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1575 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001576
Brad Ebinger51de96a2017-04-21 17:05:18 -07001577 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1578 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1579
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001580 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1581 // that have the runtime one
1582 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1583 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001584 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001585 android.Manifest.permission.READ_PHONE_STATE,
1586 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 }
1588
Robert Greenwalt42acef32009-08-12 16:08:25 -07001589 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001590 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001591 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001592 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001593 // Note: not reporting to the battery stats service here, because the
1594 // status bar takes care of that after taking into account all of the
1595 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001597 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001598 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001599 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001600 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 }
1602 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001603 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001605 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001606 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001607 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001608 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001609 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001610 }
1611 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001612 if (networkCapabilities != null) {
1613 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001614 }
Wink Savillea639b312012-07-10 12:37:54 -07001615 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001616
Wink Savillea639b312012-07-10 12:37:54 -07001617 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1618 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001619 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001620 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 }
1622
Wink Savillefb40dd42014-06-12 17:02:31 -07001623 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001624 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001626 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1627 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001628 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001629 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001631
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001632 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1633 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1634 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1635 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1636 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1637 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1638 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1639 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1640 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1641 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1642 }
1643
1644 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001645 String apnType, String apn, String reason, LinkProperties linkProperties,
1646 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001647 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1648 intent.putExtra(PhoneConstants.STATE_KEY, state);
1649 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1650 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1651 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1652 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001653 if (linkProperties != null) {
1654 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1655 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001656 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1657
1658 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1659 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1660 }
1661
Andrew Flynnceaed682015-06-09 12:36:58 +00001662 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1663 if (checkNotifyPermission()) {
1664 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001665 }
1666
Andrew Flynnceaed682015-06-09 12:36:58 +00001667 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001668 }
1669
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001670 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001671 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001672 return true;
1673 }
1674 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001675 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001676 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001677 return false;
1678 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001679
Andrew Flynn1f452642015-04-14 22:16:04 -04001680 private boolean checkNotifyPermission() {
1681 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1682 == PackageManager.PERMISSION_GRANTED;
1683 }
1684
Andrew Flynnceaed682015-06-09 12:36:58 +00001685 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001686 TelephonyManager tm = TelephonyManager.getDefault();
1687 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1688 for (String pkg : pkgs) {
1689 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1690 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001691 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001692 }
1693 }
1694
Andrew Flynnceaed682015-06-09 12:36:58 +00001695 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1696 + ", uid=" + Binder.getCallingUid();
1697 if (DBG) log(msg);
1698 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001699 }
1700
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001701 private void checkListenerPermission(int events) {
1702 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1703 mContext.enforceCallingOrSelfPermission(
1704 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1705
1706 }
1707
John Wang963db55d2012-03-30 16:04:06 -07001708 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1709 mContext.enforceCallingOrSelfPermission(
1710 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1711
1712 }
1713
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001714 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001715 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001716 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001717 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001718 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1719 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001720 } catch (SecurityException e) {
1721 mContext.enforceCallingOrSelfPermission(
1722 android.Manifest.permission.READ_PHONE_STATE, null);
1723 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001724 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001725
1726 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1727 mContext.enforceCallingOrSelfPermission(
1728 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1729
1730 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001731 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001732
1733 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001734 int size = mRemoveList.size();
1735 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1736 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001737 for (IBinder b: mRemoveList) {
1738 remove(b);
1739 }
1740 mRemoveList.clear();
1741 }
1742 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001743
1744 private boolean validateEventsAndUserLocked(Record r, int events) {
1745 int foregroundUser;
1746 long callingIdentity = Binder.clearCallingIdentity();
1747 boolean valid = false;
1748 try {
1749 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu3d309462018-02-06 18:13:36 +00001750 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001751 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001752 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu3d309462018-02-06 18:13:36 +00001753 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001754 + " r.events=" + r.events + " events=" + events);
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(callingIdentity);
1758 }
1759 return valid;
1760 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001761
1762 private boolean validatePhoneId(int phoneId) {
1763 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001764 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001765 return valid;
1766 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001767
1768 private static void log(String s) {
1769 Rlog.d(TAG, s);
1770 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001771
xinhe8b79fb62014-11-05 14:55:03 -08001772 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001773
1774 if(subId < 0) {
1775 // Invalid case, we need compare phoneId with default one.
1776 return (mDefaultPhoneId == phoneId);
1777 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001778 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001779 return (subId == mDefaultSubId);
1780 } else {
1781 return (rSubId == subId);
1782 }
1783 }
1784
1785 private void checkPossibleMissNotify(Record r, int phoneId) {
1786 int events = r.events;
1787
1788 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1789 try {
1790 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1791 mServiceState[phoneId]);
1792 r.callback.onServiceStateChanged(
1793 new ServiceState(mServiceState[phoneId]));
1794 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001795 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001796 }
1797 }
1798
1799 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1800 try {
1801 SignalStrength signalStrength = mSignalStrength[phoneId];
1802 if (DBG) {
1803 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1804 }
1805 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1806 } catch (RemoteException ex) {
1807 mRemoveList.add(r.binder);
1808 }
1809 }
1810
1811 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1812 try {
1813 int gsmSignalStrength = mSignalStrength[phoneId]
1814 .getGsmSignalStrength();
1815 if (DBG) {
1816 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1817 gsmSignalStrength);
1818 }
1819 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1820 : gsmSignalStrength));
1821 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001822 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001823 }
1824 }
1825
1826 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1827 try {
1828 if (DBG_LOC) {
1829 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1830 + mCellInfo.get(phoneId));
1831 }
Hall Liu3d309462018-02-06 18:13:36 +00001832 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
xinhee9f16402014-09-25 16:39:28 -07001833 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001834 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001835 }
1836 }
1837
zxuan35a47022018-01-04 11:24:04 -08001838 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1839 try {
1840 if (VDBG) {
1841 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1842 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1843 }
1844 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1845 } catch (RemoteException ex) {
1846 mRemoveList.add(r.binder);
1847 }
1848 }
1849
xinhee9f16402014-09-25 16:39:28 -07001850 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1851 try {
1852 if (VDBG) {
1853 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1854 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1855 }
1856 r.callback.onMessageWaitingIndicatorChanged(
1857 mMessageWaiting[phoneId]);
1858 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001859 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001860 }
1861 }
1862
1863 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1864 try {
1865 if (VDBG) {
1866 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1867 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1868 }
1869 r.callback.onCallForwardingIndicatorChanged(
1870 mCallForwarding[phoneId]);
1871 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001872 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001873 }
1874 }
1875
1876 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1877 try {
1878 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1879 + mCellLocation[phoneId]);
Hall Liu3d309462018-02-06 18:13:36 +00001880 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
xinhee9f16402014-09-25 16:39:28 -07001881 } catch (RemoteException ex) {
1882 mRemoveList.add(r.binder);
1883 }
1884 }
1885
1886 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1887 try {
1888 if (DBG) {
1889 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1890 + "=" + mDataConnectionState[phoneId]
1891 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1892 + ")");
1893 }
1894 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1895 mDataConnectionNetworkType[phoneId]);
1896 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001897 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001898 }
1899 }
1900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001901}