blob: 3a68311bf8b8bca67b6028bdd7750cb24acd7701 [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
yifan.baie620ce72017-12-22 14:59:57 +0800506 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 synchronized (mRecords) {
508 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800509 IBinder b = callback.asBinder();
510 Record r = add(b);
511
512 if (r == null) {
513 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 }
xinhe43c50292014-09-18 17:56:48 -0700515
xinhe75c2c152014-10-16 11:49:45 -0700516 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700517 r.callingPackage = callingPackage;
Hall Liu3d309462018-02-06 18:13:36 +0000518 r.callerUserId = callerUserId;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700519 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
520 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
521 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700522 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
523 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800524 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800525 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700526 } else {//APP specify subID
527 r.subId = subId;
528 }
yifan.baie620ce72017-12-22 14:59:57 +0800529 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700531 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700532 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700533 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700534 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400536 try {
Wink Savillee380b982014-07-26 18:24:22 -0700537 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700538 r.callback.onServiceStateChanged(
539 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400540 } catch (RemoteException ex) {
541 remove(r.binder);
542 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 }
544 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
545 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700546 int gsmSignalStrength = mSignalStrength[phoneId]
547 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700548 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
549 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 } catch (RemoteException ex) {
551 remove(r.binder);
552 }
553 }
554 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
555 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700556 r.callback.onMessageWaitingIndicatorChanged(
557 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 } catch (RemoteException ex) {
559 remove(r.binder);
560 }
561 }
562 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
563 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700564 r.callback.onCallForwardingIndicatorChanged(
565 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 } catch (RemoteException ex) {
567 remove(r.binder);
568 }
569 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700570 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400571 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700572 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700573 + mCellLocation[phoneId]);
Hall Liu3d309462018-02-06 18:13:36 +0000574 r.callback.onCellLocationChanged(
575 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400576 } catch (RemoteException ex) {
577 remove(r.binder);
578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
580 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
581 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700583 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 } catch (RemoteException ex) {
585 remove(r.binder);
586 }
587 }
588 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
589 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700590 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
591 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 } catch (RemoteException ex) {
593 remove(r.binder);
594 }
595 }
596 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
597 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700598 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 } catch (RemoteException ex) {
600 remove(r.binder);
601 }
602 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700603 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
604 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700605 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700606 } catch (RemoteException ex) {
607 remove(r.binder);
608 }
609 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700610 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
611 try {
612 r.callback.onOtaspChanged(mOtaspMode);
613 } catch (RemoteException ex) {
614 remove(r.binder);
615 }
616 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700617 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700618 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700619 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700620 + mCellInfo.get(phoneId));
Hall Liu3d309462018-02-06 18:13:36 +0000621 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700622 } catch (RemoteException ex) {
623 remove(r.binder);
624 }
625 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200626 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
627 try {
628 r.callback.onPreciseCallStateChanged(mPreciseCallState);
629 } catch (RemoteException ex) {
630 remove(r.binder);
631 }
632 }
633 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
634 try {
635 r.callback.onPreciseDataConnectionStateChanged(
636 mPreciseDataConnectionState);
637 } catch (RemoteException ex) {
638 remove(r.binder);
639 }
640 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400641 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
642 try {
643 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
644 } catch (RemoteException ex) {
645 remove(r.binder);
646 }
647 }
fionaxu12312f62016-11-14 13:32:14 -0800648 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
649 try {
650 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
651 } catch (RemoteException ex) {
652 remove(r.binder);
653 }
654 }
655 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
656 try {
657 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
658 } catch (RemoteException ex) {
659 remove(r.binder);
660 }
661 }
zxuan35a47022018-01-04 11:24:04 -0800662 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
663 try {
664 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
665 } catch (RemoteException ex) {
666 remove(r.binder);
667 }
668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 }
670 }
671 } else {
xinhe75c2c152014-10-16 11:49:45 -0700672 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 remove(callback.asBinder());
674 }
675 }
676
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700677 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700678 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700679 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
680 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700681 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700682 return true;
683 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700684 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
685 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
686 if (canReadPhoneState &&
687 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
688 callingPackage) != AppOpsManager.MODE_ALLOWED) {
689 return false;
690 }
691 return canReadPhoneState;
692 }
693
694 private String getCallIncomingNumber(Record record, int phoneId) {
695 // Hide the number if record's process has no READ_PHONE_STATE permission
696 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
697 }
698
Malcolm Chenabbfac22018-02-12 19:15:59 -0800699 private Record add(IBinder binder) {
700 Record r;
701
702 synchronized (mRecords) {
703 final int N = mRecords.size();
704 for (int i = 0; i < N; i++) {
705 r = mRecords.get(i);
706 if (binder == r.binder) {
707 // Already existed.
708 return r;
709 }
710 }
711 r = new Record();
712 r.binder = binder;
713 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
714
715 try {
716 binder.linkToDeath(r.deathRecipient, 0);
717 } catch (RemoteException e) {
718 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
719 // Binder already died. Return null.
720 return null;
721 }
722
723 mRecords.add(r);
724 if (DBG) log("add new record");
725 }
726
727 return r;
728 }
729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 private void remove(IBinder binder) {
731 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700732 final int recordCount = mRecords.size();
733 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800734 Record r = mRecords.get(i);
735 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800736 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800737 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
738 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800739 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800740
741 if (r.deathRecipient != null) {
742 try {
743 binder.unlinkToDeath(r.deathRecipient, 0);
744 } catch (NoSuchElementException e) {
745 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
746 + r + " e=" + e);
747 }
748 }
749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 mRecords.remove(i);
751 return;
752 }
753 }
754 }
755 }
756
757 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700758 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700759 return;
760 }
xinhe43c50292014-09-18 17:56:48 -0700761
762 if (VDBG) {
763 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
764 }
765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700767 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800768 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800769 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700771 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
772 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400774 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 }
776 }
777 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400778 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700780
781 // Called only by Telecomm to communicate call state across different phone accounts. So
782 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800783 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700784 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700785 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 }
787
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700788 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
789 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700790 if (!checkNotifyPermission("notifyCallState()")) {
791 return;
792 }
Wink Savillee380b982014-07-26 18:24:22 -0700793 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700794 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700795 + " state=" + state + " incomingNumber=" + incomingNumber);
796 }
797 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700798 if (validatePhoneId(phoneId)) {
799 mCallState[phoneId] = state;
800 mCallIncomingNumber[phoneId] = incomingNumber;
801 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800802 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700803 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800804 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700805 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700806 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
807 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700808 } catch (RemoteException ex) {
809 mRemoveList.add(r.binder);
810 }
811 }
812 }
813 }
814 handleRemoveListLocked();
815 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700816 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700817 }
818
Wink Saville63f03dd2014-10-23 10:44:45 -0700819 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700820 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700821 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700822 }
xinhe43c50292014-09-18 17:56:48 -0700823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700825 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
826 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700827 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700828 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700829 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700830 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700831 if (validatePhoneId(phoneId)) {
832 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700833
Wink Savillefb40dd42014-06-12 17:02:31 -0700834 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700835 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700836 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700837 + " phoneId=" + phoneId + " state=" + state);
838 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800839 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800840 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700841 try {
Wink Savillee380b982014-07-26 18:24:22 -0700842 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700843 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700844 + " subId=" + subId + " phoneId=" + phoneId
845 + " state=" + state);
846 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700847 r.callback.onServiceStateChanged(new ServiceState(state));
848 } catch (RemoteException ex) {
849 mRemoveList.add(r.binder);
850 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700853 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700854 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400856 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700858 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 }
860
fionaxu12312f62016-11-14 13:32:14 -0800861 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
862 int activationType, int activationState) {
863 if (!checkNotifyPermission("notifySimActivationState()")){
864 return;
865 }
866 if (VDBG) {
867 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
868 + "type=" + activationType + " state=" + activationState);
869 }
870 synchronized (mRecords) {
871 if (validatePhoneId(phoneId)) {
872 switch (activationType) {
873 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
874 mVoiceActivationState[phoneId] = activationState;
875 break;
876 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
877 mDataActivationState[phoneId] = activationState;
878 break;
879 default:
880 return;
881 }
882 for (Record r : mRecords) {
883 if (VDBG) {
884 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
885 + " phoneId=" + phoneId + "type=" + activationType
886 + " state=" + activationState);
887 }
888 try {
889 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
890 r.matchPhoneStateListenerEvent(
891 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
892 idMatch(r.subId, subId, phoneId)) {
893 if (DBG) {
894 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
895 + " subId=" + subId + " phoneId=" + phoneId
896 + " state=" + activationState);
897 }
898 r.callback.onVoiceActivationStateChanged(activationState);
899 }
900 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
901 r.matchPhoneStateListenerEvent(
902 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
903 idMatch(r.subId, subId, phoneId)) {
904 if (DBG) {
905 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
906 + " subId=" + subId + " phoneId=" + phoneId
907 + " state=" + activationState);
908 }
909 r.callback.onDataActivationStateChanged(activationState);
910 }
911 } catch (RemoteException ex) {
912 mRemoveList.add(r.binder);
913 }
914 }
915 } else {
916 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
917 }
918 handleRemoveListLocked();
919 }
920 }
921
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700922 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
923 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700924 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700925 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700926 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000927 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700928 log("notifySignalStrengthForPhoneId: subId=" + subId
929 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000930 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700933 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700934 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700935 mSignalStrength[phoneId] = signalStrength;
936 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000937 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700938 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000939 + " phoneId=" + phoneId + " ss=" + signalStrength);
940 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800941 if (r.matchPhoneStateListenerEvent(
942 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800943 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700944 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000945 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700946 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000947 + " subId=" + subId + " phoneId=" + phoneId
948 + " ss=" + signalStrength);
949 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700950 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
951 } catch (RemoteException ex) {
952 mRemoveList.add(r.binder);
953 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400954 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800955 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800956 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700957 try {
958 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700959 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000960 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700961 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000962 + " subId=" + subId + " phoneId=" + phoneId
963 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
964 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700965 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700966 } catch (RemoteException ex) {
967 mRemoveList.add(r.binder);
968 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 }
970 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700971 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700972 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400974 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700976 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 }
978
Andrew Flynn1f452642015-04-14 22:16:04 -0400979 @Override
980 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000981 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
982
Andrew Flynn1f452642015-04-14 22:16:04 -0400983 if (VDBG) {
984 log("notifyCarrierNetworkChange: active=" + active);
985 }
986
987 synchronized (mRecords) {
988 mCarrierNetworkChangeState = active;
989 for (Record r : mRecords) {
990 if (r.matchPhoneStateListenerEvent(
991 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
992 try {
993 r.callback.onCarrierNetworkChange(active);
994 } catch (RemoteException ex) {
995 mRemoveList.add(r.binder);
996 }
997 }
998 }
999 handleRemoveListLocked();
1000 }
1001 }
1002
Wink Savilleb208a242012-07-25 14:08:09 -07001003 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001004 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001005 }
1006
Wink Saville63f03dd2014-10-23 10:44:45 -07001007 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001008 if (!checkNotifyPermission("notifyCellInfo()")) {
1009 return;
1010 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001011 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001012 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001013 + " cellInfo=" + cellInfo);
1014 }
yifan.baie620ce72017-12-22 14:59:57 +08001015 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001016 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001017 if (validatePhoneId(phoneId)) {
1018 mCellInfo.set(phoneId, cellInfo);
1019 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001020 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu3d309462018-02-06 18:13:36 +00001021 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001022 try {
1023 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001024 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001025 }
1026 r.callback.onCellInfoChanged(cellInfo);
1027 } catch (RemoteException ex) {
1028 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001029 }
John Wang963db55d2012-03-30 16:04:06 -07001030 }
1031 }
1032 }
1033 handleRemoveListLocked();
1034 }
1035 }
1036
xinhe43c50292014-09-18 17:56:48 -07001037 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001038 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001039 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001040 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001041 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001042 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001043 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001044 + " mwi=" + mwi);
1045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001047 if (validatePhoneId(phoneId)) {
1048 mMessageWaiting[phoneId] = mwi;
1049 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001050 if (r.matchPhoneStateListenerEvent(
1051 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001052 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001053 try {
1054 r.callback.onMessageWaitingIndicatorChanged(mwi);
1055 } catch (RemoteException ex) {
1056 mRemoveList.add(r.binder);
1057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 }
1059 }
1060 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001061 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 }
1063 }
1064
zxuan35a47022018-01-04 11:24:04 -08001065 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1066 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1067 return;
1068 }
1069 if (VDBG) {
1070 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1071 + " state=" + state);
1072 }
1073 synchronized (mRecords) {
1074 if (validatePhoneId(phoneId)) {
1075 mMessageWaiting[phoneId] = state;
1076 for (Record r : mRecords) {
1077 if (r.matchPhoneStateListenerEvent(
1078 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1079 idMatch(r.subId, subId, phoneId)) {
1080 try {
1081 r.callback.onUserMobileDataStateChanged(state);
1082 } catch (RemoteException ex) {
1083 mRemoveList.add(r.binder);
1084 }
1085 }
1086 }
1087 }
1088 handleRemoveListLocked();
1089 }
1090 }
1091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001093 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001094 }
1095
Wink Saville63f03dd2014-10-23 10:44:45 -07001096 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001097 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001098 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001099 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001100 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001101 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001102 + " cfi=" + cfi);
1103 }
yifan.baie620ce72017-12-22 14:59:57 +08001104 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001106 if (validatePhoneId(phoneId)) {
1107 mCallForwarding[phoneId] = cfi;
1108 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001109 if (r.matchPhoneStateListenerEvent(
1110 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001111 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001112 try {
1113 r.callback.onCallForwardingIndicatorChanged(cfi);
1114 } catch (RemoteException ex) {
1115 mRemoveList.add(r.binder);
1116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 }
1118 }
1119 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001120 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 }
1122 }
1123
1124 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001125 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001126 }
1127
Wink Saville63f03dd2014-10-23 10:44:45 -07001128 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001129 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001130 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001131 }
yifan.baie620ce72017-12-22 14:59:57 +08001132 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001134 if (validatePhoneId(phoneId)) {
1135 mDataActivity[phoneId] = state;
1136 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001137 // Notify by correct subId.
1138 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1139 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001140 try {
1141 r.callback.onDataActivity(state);
1142 } catch (RemoteException ex) {
1143 mRemoveList.add(r.binder);
1144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 }
1146 }
1147 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001148 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 }
1150 }
1151
Jack Yubaeec622017-05-01 17:01:11 -07001152 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001153 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001154 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001155 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001156 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001157 networkCapabilities, networkType, roaming);
1158 }
1159
Wink Saville63f03dd2014-10-23 10:44:45 -07001160 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001161 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001162 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1163 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001164 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001165 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001166 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001167 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001168 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001169 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001170 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001171 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001172 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001173 }
yifan.baie620ce72017-12-22 14:59:57 +08001174 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001176 if (validatePhoneId(phoneId)) {
1177 boolean modified = false;
1178 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001179 if (!mConnectedApns[phoneId].contains(apnType)) {
1180 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001181 if (mDataConnectionState[phoneId] != state) {
1182 mDataConnectionState[phoneId] = state;
1183 modified = true;
1184 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001186 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001187 if (mConnectedApns[phoneId].remove(apnType)) {
1188 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001189 mDataConnectionState[phoneId] = state;
1190 modified = true;
1191 } else {
1192 // leave mDataConnectionState as is and
1193 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001194 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001195 }
1196 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001197 mDataConnectionLinkProperties[phoneId] = linkProperties;
1198 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1199 if (mDataConnectionNetworkType[phoneId] != networkType) {
1200 mDataConnectionNetworkType[phoneId] = networkType;
1201 // need to tell registered listeners about the new network type
1202 modified = true;
1203 }
1204 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001205 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1206 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1207 log(str);
1208 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001209 for (Record r : mRecords) {
1210 if (r.matchPhoneStateListenerEvent(
1211 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1212 idMatch(r.subId, subId, phoneId)) {
1213 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001214 if (DBG) {
1215 log("Notify data connection state changed on sub: " + subId);
1216 }
1217 r.callback.onDataConnectionStateChanged(
1218 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001219 mDataConnectionNetworkType[phoneId]);
1220 } catch (RemoteException ex) {
1221 mRemoveList.add(r.binder);
1222 }
1223 }
1224 }
1225 handleRemoveListLocked();
1226 }
1227 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1228 apnType, apn, reason, linkProperties, "");
1229 for (Record r : mRecords) {
1230 if (r.matchPhoneStateListenerEvent(
1231 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1232 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001233 r.callback.onPreciseDataConnectionStateChanged(
1234 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001235 } catch (RemoteException ex) {
1236 mRemoveList.add(r.binder);
1237 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001238 }
1239 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001240 }
1241 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
Jack Yubaeec622017-05-01 17:01:11 -07001243 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001244 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001245 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1246 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 }
1248
Robert Greenwalt02648a42010-05-18 10:52:51 -07001249 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001250 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001251 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001252 }
1253
Wink Saville63f03dd2014-10-23 10:44:45 -07001254 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001255 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001256 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001257 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001258 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001259 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001260 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001261 + " reason=" + reason + " apnType=" + apnType);
1262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001264 mPreciseDataConnectionState = new PreciseDataConnectionState(
1265 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1266 apnType, "", reason, null, "");
1267 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001268 if (r.matchPhoneStateListenerEvent(
1269 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001270 try {
1271 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1272 } catch (RemoteException ex) {
1273 mRemoveList.add(r.binder);
1274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 }
1276 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001277 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001279 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001280 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1281 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 }
1283
1284 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001285 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001286 }
1287
Wink Saville63f03dd2014-10-23 10:44:45 -07001288 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001289 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001290 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001291 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001292 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001293 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001294 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001295 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001296 + " cellLocation=" + cellLocation);
1297 }
yifan.baie620ce72017-12-22 14:59:57 +08001298 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001300 if (validatePhoneId(phoneId)) {
1301 mCellLocation[phoneId] = cellLocation;
1302 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001303 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu3d309462018-02-06 18:13:36 +00001304 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001305 try {
1306 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001307 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001308 + " r=" + r);
1309 }
1310 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1311 } catch (RemoteException ex) {
1312 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001313 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 }
1316 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001317 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001318 }
1319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320
Wink Savillefd2d0132010-10-28 14:22:26 -07001321 public void notifyOtaspChanged(int otaspMode) {
1322 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1323 return;
1324 }
1325 synchronized (mRecords) {
1326 mOtaspMode = otaspMode;
1327 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001328 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001329 try {
1330 r.callback.onOtaspChanged(otaspMode);
1331 } catch (RemoteException ex) {
1332 mRemoveList.add(r.binder);
1333 }
1334 }
1335 }
1336 handleRemoveListLocked();
1337 }
1338 }
1339
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001340 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1341 int backgroundCallState) {
1342 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1343 return;
1344 }
1345 synchronized (mRecords) {
1346 mRingingCallState = ringingCallState;
1347 mForegroundCallState = foregroundCallState;
1348 mBackgroundCallState = backgroundCallState;
1349 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1350 backgroundCallState,
1351 DisconnectCause.NOT_VALID,
1352 PreciseDisconnectCause.NOT_VALID);
1353 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001354 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001355 try {
1356 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1357 } catch (RemoteException ex) {
1358 mRemoveList.add(r.binder);
1359 }
1360 }
1361 }
1362 handleRemoveListLocked();
1363 }
1364 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1365 DisconnectCause.NOT_VALID,
1366 PreciseDisconnectCause.NOT_VALID);
1367 }
1368
1369 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1370 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1371 return;
1372 }
1373 synchronized (mRecords) {
1374 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1375 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1376 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001377 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001378 try {
1379 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1380 } catch (RemoteException ex) {
1381 mRemoveList.add(r.binder);
1382 }
1383 }
1384 }
1385 handleRemoveListLocked();
1386 }
1387 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1388 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1389 }
1390
1391 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1392 String apn, String failCause) {
1393 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1394 return;
1395 }
1396 synchronized (mRecords) {
1397 mPreciseDataConnectionState = new PreciseDataConnectionState(
1398 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1399 apnType, apn, reason, null, failCause);
1400 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001401 if (r.matchPhoneStateListenerEvent(
1402 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001403 try {
1404 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1405 } catch (RemoteException ex) {
1406 mRemoveList.add(r.binder);
1407 }
1408 }
1409 }
1410 handleRemoveListLocked();
1411 }
1412 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1413 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1414 }
1415
Wink Savillefb40dd42014-06-12 17:02:31 -07001416 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1417 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1418 return;
1419 }
1420 synchronized (mRecords) {
1421 mVoLteServiceState = lteState;
1422 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001423 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001424 try {
1425 r.callback.onVoLteServiceStateChanged(
1426 new VoLteServiceState(mVoLteServiceState));
1427 } catch (RemoteException ex) {
1428 mRemoveList.add(r.binder);
1429 }
1430 }
1431 }
1432 handleRemoveListLocked();
1433 }
1434 }
1435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001437 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1438 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1439
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001440 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001443 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001445 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301446 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001447 pw.println("Phone Id=" + i);
1448 pw.increaseIndent();
1449 pw.println("mCallState=" + mCallState[i]);
1450 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1451 pw.println("mServiceState=" + mServiceState[i]);
1452 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1453 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001454 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001455 pw.println("mSignalStrength=" + mSignalStrength[i]);
1456 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1457 pw.println("mCallForwarding=" + mCallForwarding[i]);
1458 pw.println("mDataActivity=" + mDataActivity[i]);
1459 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001460 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1461 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301462 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001463 pw.println("mCellLocation=" + mCellLocation[i]);
1464 pw.println("mCellInfo=" + mCellInfo.get(i));
1465 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301466 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001467 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1468 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1469 pw.println("mPreciseCallState=" + mPreciseCallState);
1470 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1471 pw.println("mRingingCallState=" + mRingingCallState);
1472 pw.println("mForegroundCallState=" + mForegroundCallState);
1473 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1474 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1475
1476 pw.decreaseIndent();
1477
1478 pw.println("local logs:");
1479 pw.increaseIndent();
1480 mLocalLog.dump(fd, pw, args);
1481 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001482 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001483 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001484 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001485 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001487 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 }
1489 }
1490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 //
1492 // the legacy intent broadcasting
1493 //
1494
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001495 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001496 long ident = Binder.clearCallingIdentity();
1497 try {
1498 mBatteryStats.notePhoneState(state.getState());
1499 } catch (RemoteException re) {
1500 // Can't do much
1501 } finally {
1502 Binder.restoreCallingIdentity(ident);
1503 }
1504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001506 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 Bundle data = new Bundle();
1508 state.fillInNotifierBundle(data);
1509 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001510 // Pass the subscription along with the intent.
1511 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001512 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001513 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 }
1515
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001516 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1517 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001518 long ident = Binder.clearCallingIdentity();
1519 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001520 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001521 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001522 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001523 } finally {
1524 Binder.restoreCallingIdentity(ident);
1525 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001528 Bundle data = new Bundle();
1529 signalStrength.fillInNotifierBundle(data);
1530 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001531 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001532 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001533 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 }
1535
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001536 /**
1537 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1538 * a valid subId, in which case this function fires a subId-specific intent, or it
1539 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1540 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1541 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001542 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1543 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 long ident = Binder.clearCallingIdentity();
1545 try {
1546 if (state == TelephonyManager.CALL_STATE_IDLE) {
1547 mBatteryStats.notePhoneOff();
1548 } else {
1549 mBatteryStats.notePhoneOn();
1550 }
1551 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001552 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 } finally {
1554 Binder.restoreCallingIdentity(ident);
1555 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001558 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001559 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 if (!TextUtils.isEmpty(incomingNumber)) {
1561 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1562 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001563
1564 // If a valid subId was specified, we should fire off a subId-specific state
1565 // change intent and include the subId.
1566 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1567 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1568 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1569 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001570 // If the phoneId is invalid, the broadcast is for overall call state.
1571 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1572 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1573 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001574
Brad Ebinger51de96a2017-04-21 17:05:18 -07001575 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1576 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1577
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001578 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1579 // that have the runtime one
1580 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1581 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001582 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001583 android.Manifest.permission.READ_PHONE_STATE,
1584 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 }
1586
Robert Greenwalt42acef32009-08-12 16:08:25 -07001587 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001588 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001589 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001590 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001591 // Note: not reporting to the battery stats service here, because the
1592 // status bar takes care of that after taking into account all of the
1593 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001595 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001596 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001597 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001598 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 }
1600 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001601 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001603 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001604 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001605 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001606 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001607 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001608 }
1609 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001610 if (networkCapabilities != null) {
1611 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001612 }
Wink Savillea639b312012-07-10 12:37:54 -07001613 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001614
Wink Savillea639b312012-07-10 12:37:54 -07001615 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1616 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001617 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001618 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 }
1620
Wink Savillefb40dd42014-06-12 17:02:31 -07001621 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001622 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001624 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1625 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001626 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001627 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001629
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001630 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1631 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1632 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1633 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1634 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1635 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1636 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1637 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1638 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1639 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1640 }
1641
1642 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001643 String apnType, String apn, String reason, LinkProperties linkProperties,
1644 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001645 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1646 intent.putExtra(PhoneConstants.STATE_KEY, state);
1647 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1648 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1649 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1650 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001651 if (linkProperties != null) {
1652 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1653 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001654 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1655
1656 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1657 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1658 }
1659
Andrew Flynnceaed682015-06-09 12:36:58 +00001660 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1661 if (checkNotifyPermission()) {
1662 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001663 }
1664
Andrew Flynnceaed682015-06-09 12:36:58 +00001665 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001666 }
1667
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001668 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001669 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001670 return true;
1671 }
1672 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001673 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001674 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001675 return false;
1676 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001677
Andrew Flynn1f452642015-04-14 22:16:04 -04001678 private boolean checkNotifyPermission() {
1679 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1680 == PackageManager.PERMISSION_GRANTED;
1681 }
1682
Andrew Flynnceaed682015-06-09 12:36:58 +00001683 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001684 TelephonyManager tm = TelephonyManager.getDefault();
1685 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1686 for (String pkg : pkgs) {
1687 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1688 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001689 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001690 }
1691 }
1692
Andrew Flynnceaed682015-06-09 12:36:58 +00001693 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1694 + ", uid=" + Binder.getCallingUid();
1695 if (DBG) log(msg);
1696 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001697 }
1698
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001699 private void checkListenerPermission(int events) {
1700 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1701 mContext.enforceCallingOrSelfPermission(
1702 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1703
1704 }
1705
John Wang963db55d2012-03-30 16:04:06 -07001706 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1707 mContext.enforceCallingOrSelfPermission(
1708 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1709
1710 }
1711
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001712 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001713 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001714 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001715 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001716 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1717 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001718 } catch (SecurityException e) {
1719 mContext.enforceCallingOrSelfPermission(
1720 android.Manifest.permission.READ_PHONE_STATE, null);
1721 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001722 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001723
1724 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1725 mContext.enforceCallingOrSelfPermission(
1726 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1727
1728 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001729 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001730
1731 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001732 int size = mRemoveList.size();
1733 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1734 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001735 for (IBinder b: mRemoveList) {
1736 remove(b);
1737 }
1738 mRemoveList.clear();
1739 }
1740 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001741
1742 private boolean validateEventsAndUserLocked(Record r, int events) {
1743 int foregroundUser;
1744 long callingIdentity = Binder.clearCallingIdentity();
1745 boolean valid = false;
1746 try {
1747 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu3d309462018-02-06 18:13:36 +00001748 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001749 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001750 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu3d309462018-02-06 18:13:36 +00001751 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001752 + " r.events=" + r.events + " events=" + events);
1753 }
1754 } finally {
1755 Binder.restoreCallingIdentity(callingIdentity);
1756 }
1757 return valid;
1758 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001759
1760 private boolean validatePhoneId(int phoneId) {
1761 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001762 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001763 return valid;
1764 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001765
1766 private static void log(String s) {
1767 Rlog.d(TAG, s);
1768 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001769
xinhe8b79fb62014-11-05 14:55:03 -08001770 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001771
1772 if(subId < 0) {
1773 // Invalid case, we need compare phoneId with default one.
1774 return (mDefaultPhoneId == phoneId);
1775 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001776 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001777 return (subId == mDefaultSubId);
1778 } else {
1779 return (rSubId == subId);
1780 }
1781 }
1782
1783 private void checkPossibleMissNotify(Record r, int phoneId) {
1784 int events = r.events;
1785
1786 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1787 try {
1788 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1789 mServiceState[phoneId]);
1790 r.callback.onServiceStateChanged(
1791 new ServiceState(mServiceState[phoneId]));
1792 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001793 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001794 }
1795 }
1796
1797 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1798 try {
1799 SignalStrength signalStrength = mSignalStrength[phoneId];
1800 if (DBG) {
1801 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1802 }
1803 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1804 } catch (RemoteException ex) {
1805 mRemoveList.add(r.binder);
1806 }
1807 }
1808
1809 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1810 try {
1811 int gsmSignalStrength = mSignalStrength[phoneId]
1812 .getGsmSignalStrength();
1813 if (DBG) {
1814 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1815 gsmSignalStrength);
1816 }
1817 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1818 : gsmSignalStrength));
1819 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001820 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001821 }
1822 }
1823
1824 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1825 try {
1826 if (DBG_LOC) {
1827 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1828 + mCellInfo.get(phoneId));
1829 }
Hall Liu3d309462018-02-06 18:13:36 +00001830 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
xinhee9f16402014-09-25 16:39:28 -07001831 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001832 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001833 }
1834 }
1835
zxuan35a47022018-01-04 11:24:04 -08001836 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1837 try {
1838 if (VDBG) {
1839 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1840 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1841 }
1842 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1843 } catch (RemoteException ex) {
1844 mRemoveList.add(r.binder);
1845 }
1846 }
1847
xinhee9f16402014-09-25 16:39:28 -07001848 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1849 try {
1850 if (VDBG) {
1851 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1852 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1853 }
1854 r.callback.onMessageWaitingIndicatorChanged(
1855 mMessageWaiting[phoneId]);
1856 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001857 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001858 }
1859 }
1860
1861 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1862 try {
1863 if (VDBG) {
1864 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1865 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1866 }
1867 r.callback.onCallForwardingIndicatorChanged(
1868 mCallForwarding[phoneId]);
1869 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001870 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001871 }
1872 }
1873
1874 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1875 try {
1876 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1877 + mCellLocation[phoneId]);
Hall Liu3d309462018-02-06 18:13:36 +00001878 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
xinhee9f16402014-09-25 16:39:28 -07001879 } catch (RemoteException ex) {
1880 mRemoveList.add(r.binder);
1881 }
1882 }
1883
1884 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1885 try {
1886 if (DBG) {
1887 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1888 + "=" + mDataConnectionState[phoneId]
1889 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1890 + ")");
1891 }
1892 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1893 mDataConnectionNetworkType[phoneId]);
1894 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001895 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001896 }
1897 }
1898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899}