blob: 0834eb8f9cbae21732f88763811baba609c584cf [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
Amit Mahajan1cfd4572015-07-09 11:12:19 -070019import android.Manifest;
Wink Savillea12a7b32012-09-20 10:09:45 -070020import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070021import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070022import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
24import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070025import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070027import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070028import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Binder;
30import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070031import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070033import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070035import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.telephony.CellLocation;
Wink Savillef4cd25b2014-07-08 19:03:20 -070037import android.telephony.Rlog;
Wink Savillefb40dd42014-06-12 17:02:31 -070038import android.telephony.TelephonyManager;
39import android.telephony.SubscriptionManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.telephony.PhoneStateListener;
41import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070042import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070043import android.telephony.CellInfo;
Wink Savillefb40dd42014-06-12 17:02:31 -070044import android.telephony.VoLteServiceState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020045import android.telephony.DisconnectCause;
46import android.telephony.PreciseCallState;
47import android.telephony.PreciseDataConnectionState;
48import android.telephony.PreciseDisconnectCause;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.text.TextUtils;
Wink Saville47d8d1b2014-07-10 13:01:52 -070050import android.text.format.Time;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52import java.util.ArrayList;
Wink Savilleb208a242012-07-25 14:08:09 -070053import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import java.io.FileDescriptor;
55import java.io.PrintWriter;
56
57import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080058import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.ITelephonyRegistry;
60import com.android.internal.telephony.IPhoneStateListener;
61import com.android.internal.telephony.DefaultPhoneNotifier;
Wink Savillea639b312012-07-10 12:37:54 -070062import com.android.internal.telephony.PhoneConstants;
Wink Savillec9330dd2011-01-12 13:37:38 -080063import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import com.android.internal.telephony.TelephonyIntents;
65import com.android.server.am.BatteryStatsService;
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067/**
Wink Savillee9b06d72009-05-18 21:47:50 -070068 * Since phone process can be restarted, this class provides a centralized place
69 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070070 *
71 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
72 * and 15973975 by saving the phoneId of the registrant and then using the
73 * phoneId when deciding to to make a callback. This is necessary because
74 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070075 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070076 * the dummy value conversion we properly do the callbacks.
77 *
78 * Eventually we may want to remove the notion of dummy value but for now this
79 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 */
81class TelephonyRegistry extends ITelephonyRegistry.Stub {
82 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070083 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070084 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070085 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070088 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080093 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070094
Fyodor Kupolov309b2f632015-06-03 16:29:01 -070095 int callerUserId;
Wink Savillea12a7b32012-09-20 10:09:45 -070096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070098
Wink Savilled09c4ca2014-11-22 10:08:16 -080099 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700100
Wink Savilled09c4ca2014-11-22 10:08:16 -0800101 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800102
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700103 boolean canReadPhoneState;
104
Wink Savillea374c3d2014-11-11 11:48:04 -0800105 boolean matchPhoneStateListenerEvent(int events) {
106 return (callback != null) && ((events & this.events) != 0);
107 }
108
Wink Savilled09c4ca2014-11-22 10:08:16 -0800109 boolean matchOnSubscriptionsChangedListener() {
110 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800111 }
Wink Savillee380b982014-07-26 18:24:22 -0700112
Wink Savillea12a7b32012-09-20 10:09:45 -0700113 @Override
114 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700115 return "{callingPackage=" + callingPackage + " binder=" + binder
116 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800117 + " onSubscriptionsChangedListenererCallback="
118 + onSubscriptionsChangedListenerCallback
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700119 + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
120 + " events=" + Integer.toHexString(events)
121 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 }
124
125 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700126
Joe Onorato163d8d92010-10-21 13:21:20 -0400127 // access should be inside synchronized (mRecords) for these two fields
128 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
129 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 private final IBatteryStats mBatteryStats;
132
Svet Ganov16a16892015-04-16 10:32:04 -0700133 private final AppOpsManager mAppOps;
134
Wink Savilled09c4ca2014-11-22 10:08:16 -0800135 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
136
Wink Savillefb40dd42014-06-12 17:02:31 -0700137 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700138
Wink Savillefb40dd42014-06-12 17:02:31 -0700139 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700140
Wink Savillefb40dd42014-06-12 17:02:31 -0700141 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700142
Wink Savillefb40dd42014-06-12 17:02:31 -0700143 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700144
Wink Savillefb40dd42014-06-12 17:02:31 -0700145 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700146
Wink Savillefb40dd42014-06-12 17:02:31 -0700147 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700148
Wink Savillefb40dd42014-06-12 17:02:31 -0700149 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700150
Wink Savillefb40dd42014-06-12 17:02:31 -0700151 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700152
Wink Savillefb40dd42014-06-12 17:02:31 -0700153 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700154
Wink Savillefb40dd42014-06-12 17:02:31 -0700155 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700156
Wink Savillefb40dd42014-06-12 17:02:31 -0700157 private String[] mDataConnectionReason;
158
159 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700160
Yifan Bai57b39e32016-04-01 16:24:33 +0800161 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700162
Wink Savillefb40dd42014-06-12 17:02:31 -0700163 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700164
Wink Savillefb40dd42014-06-12 17:02:31 -0700165 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700166
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168
Wink Savillefb40dd42014-06-12 17:02:31 -0700169 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700170
Wink Savillec9330dd2011-01-12 13:37:38 -0800171 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700172
Wink Savillefb40dd42014-06-12 17:02:31 -0700173 private ArrayList<List<CellInfo>> mCellInfo = null;
174
175 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
176
Wink Savilled09c4ca2014-11-22 10:08:16 -0800177 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700178
Wink Savilled09c4ca2014-11-22 10:08:16 -0800179 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700180
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200181 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
182
183 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
184
185 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
186
187 private PreciseCallState mPreciseCallState = new PreciseCallState();
188
Andrew Flynn1f452642015-04-14 22:16:04 -0400189 private boolean mCarrierNetworkChangeState = false;
190
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200191 private PreciseDataConnectionState mPreciseDataConnectionState =
192 new PreciseDataConnectionState();
193
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700194 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700195 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700196 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
197 PhoneStateListener.LISTEN_VOLTE_STATE;
198
199 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700200 PhoneStateListener.LISTEN_CALL_STATE |
201 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700202 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700203
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200204 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
205 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
206 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
207
Wink Savillea12a7b32012-09-20 10:09:45 -0700208 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700209 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700210
211 private final Handler mHandler = new Handler() {
212 @Override
213 public void handleMessage(Message msg) {
214 switch (msg.what) {
215 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700216 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700217 int numPhones = TelephonyManager.getDefault().getPhoneCount();
218 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700219 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700220 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700221 }
222 break;
223 }
xinhee9f16402014-09-25 16:39:28 -0700224 case MSG_UPDATE_DEFAULT_SUB: {
225 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700226 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700227 if (VDBG) {
228 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
229 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
230 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
231 }
232
233 //Due to possible risk condition,(notify call back using the new
234 //defaultSubId comes before new defaultSubId update) we need to recall all
235 //possible missed notify callback
236 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700237 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800238 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700239 checkPossibleMissNotify(r, newDefaultPhoneId);
240 }
241 }
242 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700243 }
244 mDefaultSubId = newDefaultSubId;
245 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700246 }
247 }
248 }
249 };
250
251 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
252 @Override
253 public void onReceive(Context context, Intent intent) {
254 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700255 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700256 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700257 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700258 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700259 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700260 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700261 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800262 PhoneConstants.SUBSCRIPTION_KEY,
263 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700264 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
265 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700266 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700267 log("onReceive:current mDefaultSubId=" + mDefaultSubId
268 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
269 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700270 }
xinhee9f16402014-09-25 16:39:28 -0700271
Junda Liu985f52c2015-02-23 16:06:51 -0800272 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700273 || (newDefaultPhoneId != mDefaultPhoneId))) {
274 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
275 newDefaultPhoneId, 0, newDefaultSubIdObj));
276 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700277 }
278 }
279 };
280
Wink Savillee9b06d72009-05-18 21:47:50 -0700281 // we keep a copy of all of the state so we can send it out when folks
282 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700284 // In these calls we call with the lock held. This is safe becasuse remote
285 // calls go through a oneway interface and local calls going through a
286 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287
288 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700289 CellLocation location = CellLocation.getEmpty();
290
Wink Savillefb40dd42014-06-12 17:02:31 -0700291 mContext = context;
292 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700293
Wink Savillefb40dd42014-06-12 17:02:31 -0700294 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700295 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700296 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800297 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700298 mCallState = new int[numPhones];
299 mDataActivity = new int[numPhones];
300 mDataConnectionState = new int[numPhones];
301 mDataConnectionNetworkType = new int[numPhones];
302 mCallIncomingNumber = new String[numPhones];
303 mServiceState = new ServiceState[numPhones];
304 mSignalStrength = new SignalStrength[numPhones];
305 mMessageWaiting = new boolean[numPhones];
306 mDataConnectionPossible = new boolean[numPhones];
307 mDataConnectionReason = new String[numPhones];
308 mDataConnectionApn = new String[numPhones];
309 mCallForwarding = new boolean[numPhones];
310 mCellLocation = new Bundle[numPhones];
311 mDataConnectionLinkProperties = new LinkProperties[numPhones];
312 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
313 mCellInfo = new ArrayList<List<CellInfo>>();
314 for (int i = 0; i < numPhones; i++) {
315 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
316 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
317 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
318 mCallIncomingNumber[i] = "";
319 mServiceState[i] = new ServiceState();
320 mSignalStrength[i] = new SignalStrength();
321 mMessageWaiting[i] = false;
322 mCallForwarding[i] = false;
323 mDataConnectionPossible[i] = false;
324 mDataConnectionReason[i] = "";
325 mDataConnectionApn[i] = "";
326 mCellLocation[i] = new Bundle();
327 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800328 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700329 }
330
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700331 // Note that location can be null for non-phone builds like
332 // like the generic one.
333 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700334 for (int i = 0; i < numPhones; i++) {
335 location.fillInNotifierBundle(mCellLocation[i]);
336 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700337 }
Svet Ganov16a16892015-04-16 10:32:04 -0700338
339 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 }
341
Svetoslav Ganova0027152013-06-25 14:59:53 -0700342 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700343 // Watch for interesting updates
344 final IntentFilter filter = new IntentFilter();
345 filter.addAction(Intent.ACTION_USER_SWITCHED);
346 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700347 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700348 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700349 mContext.registerReceiver(mBroadcastReceiver, filter);
350 }
351
352 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700353 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800354 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700355 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800356 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700357 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
358 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800359 + " callback.asBinder=" + callback.asBinder());
360 }
361
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700362 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700363 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700364 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
365 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700366 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700367 } catch (SecurityException e) {
368 mContext.enforceCallingOrSelfPermission(
369 android.Manifest.permission.READ_PHONE_STATE,
370 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700371
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700372 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
373 callingPackage) != AppOpsManager.MODE_ALLOWED) {
374 return;
375 }
Svet Ganov16a16892015-04-16 10:32:04 -0700376 }
377
Fyodor Kupolovac038a92015-06-09 13:14:54 -0700378 Record r;
Wink Savillea374c3d2014-11-11 11:48:04 -0800379
Wink Savilled09c4ca2014-11-22 10:08:16 -0800380 synchronized (mRecords) {
381 // register
382 find_and_add: {
383 IBinder b = callback.asBinder();
384 final int N = mRecords.size();
385 for (int i = 0; i < N; i++) {
386 r = mRecords.get(i);
387 if (b == r.binder) {
388 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800389 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800390 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800391 r = new Record();
392 r.binder = b;
393 mRecords.add(r);
394 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800395 }
396
Wink Savilled09c4ca2014-11-22 10:08:16 -0800397 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700398 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700399 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800400 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700401 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800402 if (DBG) {
403 log("listen oscl: Register r=" + r);
404 }
405 // Always notify when registration occurs if there has been a notification.
406 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800407 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800408 if (VDBG) log("listen oscl: send to r=" + r);
409 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
410 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800411 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800412 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800413 remove(r.binder);
414 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800415 } else {
416 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800417 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800418 }
419 }
420
421 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800422 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800423 IOnSubscriptionsChangedListener callback) {
424 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 remove(callback.asBinder());
426 }
427
Wink Savillea374c3d2014-11-11 11:48:04 -0800428 @Override
429 public void notifySubscriptionInfoChanged() {
430 if (VDBG) log("notifySubscriptionInfoChanged:");
431 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800432 if (!hasNotifySubscriptionInfoChangedOccurred) {
433 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
434 + mRecords.size());
435 }
436 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800437 mRemoveList.clear();
438 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800440 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800441 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
442 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
443 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 } catch (RemoteException ex) {
445 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
446 mRemoveList.add(r.binder);
447 }
448 }
449 }
450 handleRemoveListLocked();
451 }
452 }
453
454 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
456 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800457 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
458 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700459 }
460
461 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700462 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700463 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700464 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700465 }
466
Svet Ganov16a16892015-04-16 10:32:04 -0700467 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700468 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700469 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700470 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700471 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700472 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
473 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700474 }
xinhe75c2c152014-10-16 11:49:45 -0700475
476 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700477 /* Checks permission and throws Security exception */
478 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700479
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700480 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700481 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700482 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700483 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700484 // SKIP checking for run-time permission since caller or self has PRIVILEGED
485 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700486 } catch (SecurityException e) {
487 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
488 callingPackage) != AppOpsManager.MODE_ALLOWED) {
489 return;
490 }
Svet Ganov16a16892015-04-16 10:32:04 -0700491 }
492 }
493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 synchronized (mRecords) {
495 // register
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700496 Record r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 find_and_add: {
498 IBinder b = callback.asBinder();
499 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700500 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 r = mRecords.get(i);
502 if (b == r.binder) {
503 break find_and_add;
504 }
505 }
506 r = new Record();
507 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700509 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
xinhe43c50292014-09-18 17:56:48 -0700511
xinhe75c2c152014-10-16 11:49:45 -0700512 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700513 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700514 r.callerUserId = callerUserId;
515 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
516 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
517 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700518 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
519 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800520 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800521 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700522 } else {//APP specify subID
523 r.subId = subId;
524 }
525 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
526
xinhe43c50292014-09-18 17:56:48 -0700527 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700529 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700530 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700531 }
532 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700533 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400535 try {
Wink Savillee380b982014-07-26 18:24:22 -0700536 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700537 r.callback.onServiceStateChanged(
538 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400539 } catch (RemoteException ex) {
540 remove(r.binder);
541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 }
543 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
544 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700545 int gsmSignalStrength = mSignalStrength[phoneId]
546 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700547 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
548 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 } catch (RemoteException ex) {
550 remove(r.binder);
551 }
552 }
553 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
554 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700555 r.callback.onMessageWaitingIndicatorChanged(
556 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 } catch (RemoteException ex) {
558 remove(r.binder);
559 }
560 }
561 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
562 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700563 r.callback.onCallForwardingIndicatorChanged(
564 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 } catch (RemoteException ex) {
566 remove(r.binder);
567 }
568 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700569 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400570 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700571 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700572 + mCellLocation[phoneId]);
573 r.callback.onCellLocationChanged(
574 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400575 } catch (RemoteException ex) {
576 remove(r.binder);
577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
580 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700581 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700582 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 } catch (RemoteException ex) {
584 remove(r.binder);
585 }
586 }
587 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
588 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700589 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
590 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 } catch (RemoteException ex) {
592 remove(r.binder);
593 }
594 }
595 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
596 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700597 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 } catch (RemoteException ex) {
599 remove(r.binder);
600 }
601 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700602 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
603 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700604 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700605 } catch (RemoteException ex) {
606 remove(r.binder);
607 }
608 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700609 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
610 try {
611 r.callback.onOtaspChanged(mOtaspMode);
612 } catch (RemoteException ex) {
613 remove(r.binder);
614 }
615 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700616 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700617 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700618 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700619 + mCellInfo.get(phoneId));
620 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700621 } catch (RemoteException ex) {
622 remove(r.binder);
623 }
624 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200625 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
626 try {
627 r.callback.onPreciseCallStateChanged(mPreciseCallState);
628 } catch (RemoteException ex) {
629 remove(r.binder);
630 }
631 }
632 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
633 try {
634 r.callback.onPreciseDataConnectionStateChanged(
635 mPreciseDataConnectionState);
636 } catch (RemoteException ex) {
637 remove(r.binder);
638 }
639 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400640 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
641 try {
642 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
643 } catch (RemoteException ex) {
644 remove(r.binder);
645 }
646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 }
648 }
649 } else {
xinhe75c2c152014-10-16 11:49:45 -0700650 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 remove(callback.asBinder());
652 }
653 }
654
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700655 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700656 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700657 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
658 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700659 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700660 return true;
661 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700662 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
663 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
664 if (canReadPhoneState &&
665 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
666 callingPackage) != AppOpsManager.MODE_ALLOWED) {
667 return false;
668 }
669 return canReadPhoneState;
670 }
671
672 private String getCallIncomingNumber(Record record, int phoneId) {
673 // Hide the number if record's process has no READ_PHONE_STATE permission
674 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
675 }
676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 private void remove(IBinder binder) {
678 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700679 final int recordCount = mRecords.size();
680 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800682 if (DBG) {
683 Record r = mRecords.get(i);
Svet Ganov16a16892015-04-16 10:32:04 -0700684 log("remove: binder=" + binder + "r.callingPackage" + r.callingPackage
xinheac11ae92014-12-18 10:02:14 -0800685 + "r.callback" + r.callback);
686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 mRecords.remove(i);
688 return;
689 }
690 }
691 }
692 }
693
694 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700695 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700696 return;
697 }
xinhe43c50292014-09-18 17:56:48 -0700698
699 if (VDBG) {
700 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
701 }
702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700704 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800705 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800706 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700708 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
709 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400711 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 }
713 }
714 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400715 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700717
718 // Called only by Telecomm to communicate call state across different phone accounts. So
719 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800720 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700721 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700722 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 }
724
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700725 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
726 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700727 if (!checkNotifyPermission("notifyCallState()")) {
728 return;
729 }
Wink Savillee380b982014-07-26 18:24:22 -0700730 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700731 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700732 + " state=" + state + " incomingNumber=" + incomingNumber);
733 }
734 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700735 if (validatePhoneId(phoneId)) {
736 mCallState[phoneId] = state;
737 mCallIncomingNumber[phoneId] = incomingNumber;
738 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800739 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700740 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800741 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700742 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700743 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
744 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700745 } catch (RemoteException ex) {
746 mRemoveList.add(r.binder);
747 }
748 }
749 }
750 }
751 handleRemoveListLocked();
752 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700753 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700754 }
755
Wink Saville63f03dd2014-10-23 10:44:45 -0700756 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700757 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700758 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700759 }
xinhe43c50292014-09-18 17:56:48 -0700760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 synchronized (mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700762 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700763 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700764 + " state=" + state);
765 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700766 if (validatePhoneId(phoneId)) {
767 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700768 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
769 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700770
Wink Savillefb40dd42014-06-12 17:02:31 -0700771 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700772 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700773 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700774 + " phoneId=" + phoneId + " state=" + state);
775 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800776 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800777 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700778 try {
Wink Savillee380b982014-07-26 18:24:22 -0700779 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700780 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700781 + " subId=" + subId + " phoneId=" + phoneId
782 + " state=" + state);
783 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700784 r.callback.onServiceStateChanged(new ServiceState(state));
785 } catch (RemoteException ex) {
786 mRemoveList.add(r.binder);
787 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400788 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700790 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700791 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400793 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700795 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 }
797
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700798 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
799 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700800 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700801 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700802 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000803 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700804 log("notifySignalStrengthForPhoneId: subId=" + subId
805 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
806 toStringLogSSC("notifySignalStrengthForPhoneId");
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000807 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700810 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700811 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700812 mSignalStrength[phoneId] = signalStrength;
813 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000814 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700815 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000816 + " phoneId=" + phoneId + " ss=" + signalStrength);
817 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800818 if (r.matchPhoneStateListenerEvent(
819 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800820 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700821 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000822 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700823 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000824 + " subId=" + subId + " phoneId=" + phoneId
825 + " ss=" + signalStrength);
826 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700827 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
828 } catch (RemoteException ex) {
829 mRemoveList.add(r.binder);
830 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400831 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800832 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800833 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700834 try {
835 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700836 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000837 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700838 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000839 + " subId=" + subId + " phoneId=" + phoneId
840 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
841 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700842 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700843 } catch (RemoteException ex) {
844 mRemoveList.add(r.binder);
845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 }
847 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700848 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700849 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400851 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700853 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
855
Andrew Flynn1f452642015-04-14 22:16:04 -0400856 @Override
857 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000858 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
859
Andrew Flynn1f452642015-04-14 22:16:04 -0400860 if (VDBG) {
861 log("notifyCarrierNetworkChange: active=" + active);
862 }
863
864 synchronized (mRecords) {
865 mCarrierNetworkChangeState = active;
866 for (Record r : mRecords) {
867 if (r.matchPhoneStateListenerEvent(
868 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
869 try {
870 r.callback.onCarrierNetworkChange(active);
871 } catch (RemoteException ex) {
872 mRemoveList.add(r.binder);
873 }
874 }
875 }
876 handleRemoveListLocked();
877 }
878 }
879
Wink Savilleb208a242012-07-25 14:08:09 -0700880 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800881 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700882 }
883
Wink Saville63f03dd2014-10-23 10:44:45 -0700884 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700885 if (!checkNotifyPermission("notifyCellInfo()")) {
886 return;
887 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700888 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700889 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700890 + " cellInfo=" + cellInfo);
891 }
John Wang963db55d2012-03-30 16:04:06 -0700892
893 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700894 int phoneId = SubscriptionManager.getPhoneId(subId);
895 if (validatePhoneId(phoneId)) {
896 mCellInfo.set(phoneId, cellInfo);
897 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700898 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800899 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700900 try {
901 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700902 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700903 }
904 r.callback.onCellInfoChanged(cellInfo);
905 } catch (RemoteException ex) {
906 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700907 }
John Wang963db55d2012-03-30 16:04:06 -0700908 }
909 }
910 }
911 handleRemoveListLocked();
912 }
913 }
914
xinhe43c50292014-09-18 17:56:48 -0700915 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700916 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700917 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700918 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700919 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700920 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -0700921 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700922 + " mwi=" + mwi);
923 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 if (validatePhoneId(phoneId)) {
926 mMessageWaiting[phoneId] = mwi;
927 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800928 if (r.matchPhoneStateListenerEvent(
929 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800930 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700931 try {
932 r.callback.onMessageWaitingIndicatorChanged(mwi);
933 } catch (RemoteException ex) {
934 mRemoveList.add(r.binder);
935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 }
937 }
938 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400939 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 }
941 }
942
943 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800944 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700945 }
946
Wink Saville63f03dd2014-10-23 10:44:45 -0700947 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700948 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700949 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700950 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700951 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700952 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700953 + " cfi=" + cfi);
954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700956 int phoneId = SubscriptionManager.getPhoneId(subId);
957 if (validatePhoneId(phoneId)) {
958 mCallForwarding[phoneId] = cfi;
959 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800960 if (r.matchPhoneStateListenerEvent(
961 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800962 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700963 try {
964 r.callback.onCallForwardingIndicatorChanged(cfi);
965 } catch (RemoteException ex) {
966 mRemoveList.add(r.binder);
967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 }
969 }
970 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400971 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 }
973 }
974
975 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800976 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700977 }
978
Wink Saville63f03dd2014-10-23 10:44:45 -0700979 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700980 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700981 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700984 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800985 if (validatePhoneId(phoneId)) {
986 mDataActivity[phoneId] = state;
987 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +0800988 // Notify by correct subId.
989 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
990 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800991 try {
992 r.callback.onDataActivity(state);
993 } catch (RemoteException ex) {
994 mRemoveList.add(r.binder);
995 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 }
997 }
998 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400999 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 }
1001 }
1002
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001003 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001004 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001005 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001006 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -07001007 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001008 networkCapabilities, networkType, roaming);
1009 }
1010
Wink Saville63f03dd2014-10-23 10:44:45 -07001011 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
1013 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1014 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001015 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001016 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001017 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001018 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001019 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001020 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
1021 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001022 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001023 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001026 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001027 if (validatePhoneId(phoneId)) {
1028 boolean modified = false;
1029 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001030 if (!mConnectedApns[phoneId].contains(apnType)) {
1031 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001032 if (mDataConnectionState[phoneId] != state) {
1033 mDataConnectionState[phoneId] = state;
1034 modified = true;
1035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001037 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001038 if (mConnectedApns[phoneId].remove(apnType)) {
1039 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001040 mDataConnectionState[phoneId] = state;
1041 modified = true;
1042 } else {
1043 // leave mDataConnectionState as is and
1044 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001045 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001046 }
1047 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001048 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
1049 mDataConnectionReason[phoneId] = reason;
1050 mDataConnectionLinkProperties[phoneId] = linkProperties;
1051 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1052 if (mDataConnectionNetworkType[phoneId] != networkType) {
1053 mDataConnectionNetworkType[phoneId] = networkType;
1054 // need to tell registered listeners about the new network type
1055 modified = true;
1056 }
1057 if (modified) {
1058 if (DBG) {
1059 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1060 + ", " + mDataConnectionNetworkType[phoneId] + ")");
1061 }
1062 for (Record r : mRecords) {
1063 if (r.matchPhoneStateListenerEvent(
1064 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1065 idMatch(r.subId, subId, phoneId)) {
1066 try {
1067 log("Notify data connection state changed on sub: " +
1068 subId);
1069 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1070 mDataConnectionNetworkType[phoneId]);
1071 } catch (RemoteException ex) {
1072 mRemoveList.add(r.binder);
1073 }
1074 }
1075 }
1076 handleRemoveListLocked();
1077 }
1078 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1079 apnType, apn, reason, linkProperties, "");
1080 for (Record r : mRecords) {
1081 if (r.matchPhoneStateListenerEvent(
1082 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1083 try {
1084 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1085 } catch (RemoteException ex) {
1086 mRemoveList.add(r.binder);
1087 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001088 }
1089 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001090 }
1091 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001093 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001094 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001095 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1096 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
1098
Robert Greenwalt02648a42010-05-18 10:52:51 -07001099 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001100 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001101 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001102 }
1103
Wink Saville63f03dd2014-10-23 10:44:45 -07001104 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001105 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001106 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001107 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001108 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001109 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001110 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001111 + " reason=" + reason + " apnType=" + apnType);
1112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001114 mPreciseDataConnectionState = new PreciseDataConnectionState(
1115 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1116 apnType, "", reason, null, "");
1117 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001118 if (r.matchPhoneStateListenerEvent(
1119 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001120 try {
1121 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1122 } catch (RemoteException ex) {
1123 mRemoveList.add(r.binder);
1124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 }
1126 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001127 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001129 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001130 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1131 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133
1134 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001135 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001136 }
1137
Wink Saville63f03dd2014-10-23 10:44:45 -07001138 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001139 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001140 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001141 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001142 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001143 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001144 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001145 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001146 + " cellLocation=" + cellLocation);
1147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001149 int phoneId = SubscriptionManager.getPhoneId(subId);
1150 if (validatePhoneId(phoneId)) {
1151 mCellLocation[phoneId] = cellLocation;
1152 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001153 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001154 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001155 try {
1156 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001157 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001158 + " r=" + r);
1159 }
1160 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1161 } catch (RemoteException ex) {
1162 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001163 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 }
1166 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001167 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001168 }
1169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170
Wink Savillefd2d0132010-10-28 14:22:26 -07001171 public void notifyOtaspChanged(int otaspMode) {
1172 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1173 return;
1174 }
1175 synchronized (mRecords) {
1176 mOtaspMode = otaspMode;
1177 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001178 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001179 try {
1180 r.callback.onOtaspChanged(otaspMode);
1181 } catch (RemoteException ex) {
1182 mRemoveList.add(r.binder);
1183 }
1184 }
1185 }
1186 handleRemoveListLocked();
1187 }
1188 }
1189
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001190 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1191 int backgroundCallState) {
1192 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1193 return;
1194 }
1195 synchronized (mRecords) {
1196 mRingingCallState = ringingCallState;
1197 mForegroundCallState = foregroundCallState;
1198 mBackgroundCallState = backgroundCallState;
1199 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1200 backgroundCallState,
1201 DisconnectCause.NOT_VALID,
1202 PreciseDisconnectCause.NOT_VALID);
1203 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001204 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001205 try {
1206 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1207 } catch (RemoteException ex) {
1208 mRemoveList.add(r.binder);
1209 }
1210 }
1211 }
1212 handleRemoveListLocked();
1213 }
1214 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1215 DisconnectCause.NOT_VALID,
1216 PreciseDisconnectCause.NOT_VALID);
1217 }
1218
1219 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1220 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1221 return;
1222 }
1223 synchronized (mRecords) {
1224 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1225 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1226 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001227 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001228 try {
1229 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1230 } catch (RemoteException ex) {
1231 mRemoveList.add(r.binder);
1232 }
1233 }
1234 }
1235 handleRemoveListLocked();
1236 }
1237 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1238 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1239 }
1240
1241 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1242 String apn, String failCause) {
1243 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1244 return;
1245 }
1246 synchronized (mRecords) {
1247 mPreciseDataConnectionState = new PreciseDataConnectionState(
1248 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1249 apnType, apn, reason, null, failCause);
1250 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001251 if (r.matchPhoneStateListenerEvent(
1252 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001253 try {
1254 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1255 } catch (RemoteException ex) {
1256 mRemoveList.add(r.binder);
1257 }
1258 }
1259 }
1260 handleRemoveListLocked();
1261 }
1262 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1263 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1264 }
1265
Wink Savillefb40dd42014-06-12 17:02:31 -07001266 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1267 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1268 return;
1269 }
1270 synchronized (mRecords) {
1271 mVoLteServiceState = lteState;
1272 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001273 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001274 try {
1275 r.callback.onVoLteServiceStateChanged(
1276 new VoLteServiceState(mVoLteServiceState));
1277 } catch (RemoteException ex) {
1278 mRemoveList.add(r.binder);
1279 }
1280 }
1281 }
1282 handleRemoveListLocked();
1283 }
1284 }
1285
Wink Saville63f03dd2014-10-23 10:44:45 -07001286 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001287 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1288 return;
1289 }
1290
1291 synchronized (mRecords) {
1292 for (Record r : mRecords) {
1293 if (VDBG) {
1294 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1295 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001296 if ((r.matchPhoneStateListenerEvent(
1297 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001298 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001299 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001300 try {
1301 r.callback.onOemHookRawEvent(rawData);
1302 } catch (RemoteException ex) {
1303 mRemoveList.add(r.binder);
1304 }
1305 }
1306 }
1307 handleRemoveListLocked();
1308 }
1309 }
1310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 @Override
1312 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1313 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1314 != PackageManager.PERMISSION_GRANTED) {
1315 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001316 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 return;
1318 }
1319 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001320 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301322 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1323 pw.println(" Phone Id=" + i);
1324 pw.println(" mCallState=" + mCallState[i]);
1325 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1326 pw.println(" mServiceState=" + mServiceState[i]);
1327 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1328 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1329 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1330 pw.println(" mDataActivity=" + mDataActivity[i]);
1331 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1332 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1333 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1334 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1335 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1336 pw.println(" mDataConnectionNetworkCapabilities=" +
1337 mDataConnectionNetworkCapabilities[i]);
1338 pw.println(" mCellLocation=" + mCellLocation[i]);
1339 pw.println(" mCellInfo=" + mCellInfo.get(i));
1340 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001341 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001342 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001343 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 }
1345 }
1346 }
1347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 //
1349 // the legacy intent broadcasting
1350 //
1351
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001352 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001353 long ident = Binder.clearCallingIdentity();
1354 try {
1355 mBatteryStats.notePhoneState(state.getState());
1356 } catch (RemoteException re) {
1357 // Can't do much
1358 } finally {
1359 Binder.restoreCallingIdentity(ident);
1360 }
1361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001363 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 Bundle data = new Bundle();
1365 state.fillInNotifierBundle(data);
1366 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001367 // Pass the subscription along with the intent.
1368 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001369 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001370 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 }
1372
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001373 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1374 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001375 long ident = Binder.clearCallingIdentity();
1376 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001377 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001378 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001379 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001380 } finally {
1381 Binder.restoreCallingIdentity(ident);
1382 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001385 Bundle data = new Bundle();
1386 signalStrength.fillInNotifierBundle(data);
1387 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001388 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001389 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001390 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 }
1392
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001393 /**
1394 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1395 * a valid subId, in which case this function fires a subId-specific intent, or it
1396 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1397 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1398 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001399 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1400 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 long ident = Binder.clearCallingIdentity();
1402 try {
1403 if (state == TelephonyManager.CALL_STATE_IDLE) {
1404 mBatteryStats.notePhoneOff();
1405 } else {
1406 mBatteryStats.notePhoneOn();
1407 }
1408 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001409 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 } finally {
1411 Binder.restoreCallingIdentity(ident);
1412 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001415 intent.putExtra(PhoneConstants.STATE_KEY,
1416 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001417 if (!TextUtils.isEmpty(incomingNumber)) {
1418 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1419 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001420
1421 // If a valid subId was specified, we should fire off a subId-specific state
1422 // change intent and include the subId.
1423 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1424 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1425 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1426 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001427 // If the phoneId is invalid, the broadcast is for overall call state.
1428 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1429 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1430 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001431
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001432 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1433 // that have the runtime one
1434 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1435 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001436 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001437 android.Manifest.permission.READ_PHONE_STATE,
1438 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 }
1440
Robert Greenwalt42acef32009-08-12 16:08:25 -07001441 private void broadcastDataConnectionStateChanged(int state,
1442 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001443 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001444 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001445 // Note: not reporting to the battery stats service here, because the
1446 // status bar takes care of that after taking into account all of the
1447 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001449 intent.putExtra(PhoneConstants.STATE_KEY,
1450 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001452 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 }
1454 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001455 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001457 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001458 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001459 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001460 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001461 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001462 }
1463 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001464 if (networkCapabilities != null) {
1465 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001466 }
Wink Savillea639b312012-07-10 12:37:54 -07001467 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001468
Wink Savillea639b312012-07-10 12:37:54 -07001469 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1470 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001471 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001472 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 }
1474
Wink Savillefb40dd42014-06-12 17:02:31 -07001475 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001476 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001478 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1479 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001480 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001481 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001483
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001484 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1485 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1486 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1487 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1488 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1489 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1490 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1491 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1492 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1493 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1494 }
1495
1496 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001497 String apnType, String apn, String reason, LinkProperties linkProperties,
1498 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001499 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1500 intent.putExtra(PhoneConstants.STATE_KEY, state);
1501 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1502 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1503 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1504 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001505 if (linkProperties != null) {
1506 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1507 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001508 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1509
1510 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1511 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1512 }
1513
Andrew Flynnceaed682015-06-09 12:36:58 +00001514 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1515 if (checkNotifyPermission()) {
1516 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001517 }
1518
Andrew Flynnceaed682015-06-09 12:36:58 +00001519 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001520 }
1521
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001522 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001523 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001524 return true;
1525 }
1526 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001527 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001528 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001529 return false;
1530 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001531
Andrew Flynn1f452642015-04-14 22:16:04 -04001532 private boolean checkNotifyPermission() {
1533 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1534 == PackageManager.PERMISSION_GRANTED;
1535 }
1536
Andrew Flynnceaed682015-06-09 12:36:58 +00001537 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001538 TelephonyManager tm = TelephonyManager.getDefault();
1539 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1540 for (String pkg : pkgs) {
1541 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1542 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001543 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001544 }
1545 }
1546
Andrew Flynnceaed682015-06-09 12:36:58 +00001547 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1548 + ", uid=" + Binder.getCallingUid();
1549 if (DBG) log(msg);
1550 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001551 }
1552
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001553 private void checkListenerPermission(int events) {
1554 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1555 mContext.enforceCallingOrSelfPermission(
1556 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1557
1558 }
1559
John Wang963db55d2012-03-30 16:04:06 -07001560 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1561 mContext.enforceCallingOrSelfPermission(
1562 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1563
1564 }
1565
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001566 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001567 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001568 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001569 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001570 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1571 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001572 } catch (SecurityException e) {
1573 mContext.enforceCallingOrSelfPermission(
1574 android.Manifest.permission.READ_PHONE_STATE, null);
1575 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001576 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001577
1578 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1579 mContext.enforceCallingOrSelfPermission(
1580 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1581
1582 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001583
1584 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1585 mContext.enforceCallingOrSelfPermission(
1586 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1587 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001588 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001589
1590 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001591 int size = mRemoveList.size();
1592 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1593 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001594 for (IBinder b: mRemoveList) {
1595 remove(b);
1596 }
1597 mRemoveList.clear();
1598 }
1599 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001600
1601 private boolean validateEventsAndUserLocked(Record r, int events) {
1602 int foregroundUser;
1603 long callingIdentity = Binder.clearCallingIdentity();
1604 boolean valid = false;
1605 try {
1606 foregroundUser = ActivityManager.getCurrentUser();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001607 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001608 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001609 log("validateEventsAndUserLocked: valid=" + valid
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001610 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001611 + " r.events=" + r.events + " events=" + events);
1612 }
1613 } finally {
1614 Binder.restoreCallingIdentity(callingIdentity);
1615 }
1616 return valid;
1617 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001618
1619 private boolean validatePhoneId(int phoneId) {
1620 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001621 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001622 return valid;
1623 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001624
1625 private static void log(String s) {
1626 Rlog.d(TAG, s);
1627 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001628
1629 private static class LogSSC {
1630 private Time mTime;
1631 private String mS;
Wink Saville63f03dd2014-10-23 10:44:45 -07001632 private int mSubId;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001633 private int mPhoneId;
1634 private ServiceState mState;
1635
Wink Saville63f03dd2014-10-23 10:44:45 -07001636 public void set(Time t, String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001637 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1638 }
1639
1640 @Override
1641 public String toString() {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001642 return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId "
1643 + mPhoneId + " mState " + mState;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001644 }
1645 }
1646
1647 private LogSSC logSSC [] = new LogSSC[10];
1648 private int next = 0;
1649
Wink Saville63f03dd2014-10-23 10:44:45 -07001650 private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001651 if (logSSC == null || logSSC.length == 0) {
1652 return;
1653 }
1654 if (logSSC[next] == null) {
1655 logSSC[next] = new LogSSC();
1656 }
1657 Time t = new Time();
1658 t.setToNow();
1659 logSSC[next].set(t, s, subId, phoneId, state);
1660 if (++next >= logSSC.length) {
1661 next = 0;
1662 }
1663 }
1664
1665 private void toStringLogSSC(String prompt) {
1666 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1667 log(prompt + ": logSSC is empty");
1668 } else {
1669 // There is at least one element
1670 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1671 int i = next;
1672 if (logSSC[i] == null) {
1673 // logSSC is not full so back to the beginning
1674 i = 0;
1675 }
1676 do {
1677 log(logSSC[i].toString());
1678 if (++i >= logSSC.length) {
1679 i = 0;
1680 }
1681 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001682 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001683 }
1684 }
xinhee9f16402014-09-25 16:39:28 -07001685
xinhe8b79fb62014-11-05 14:55:03 -08001686 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001687
1688 if(subId < 0) {
1689 // Invalid case, we need compare phoneId with default one.
1690 return (mDefaultPhoneId == phoneId);
1691 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001692 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001693 return (subId == mDefaultSubId);
1694 } else {
1695 return (rSubId == subId);
1696 }
1697 }
1698
1699 private void checkPossibleMissNotify(Record r, int phoneId) {
1700 int events = r.events;
1701
1702 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1703 try {
1704 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1705 mServiceState[phoneId]);
1706 r.callback.onServiceStateChanged(
1707 new ServiceState(mServiceState[phoneId]));
1708 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001709 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001710 }
1711 }
1712
1713 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1714 try {
1715 SignalStrength signalStrength = mSignalStrength[phoneId];
1716 if (DBG) {
1717 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1718 }
1719 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1720 } catch (RemoteException ex) {
1721 mRemoveList.add(r.binder);
1722 }
1723 }
1724
1725 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1726 try {
1727 int gsmSignalStrength = mSignalStrength[phoneId]
1728 .getGsmSignalStrength();
1729 if (DBG) {
1730 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1731 gsmSignalStrength);
1732 }
1733 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1734 : gsmSignalStrength));
1735 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001736 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001737 }
1738 }
1739
1740 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1741 try {
1742 if (DBG_LOC) {
1743 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1744 + mCellInfo.get(phoneId));
1745 }
1746 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1747 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001748 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001749 }
1750 }
1751
1752 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1753 try {
1754 if (VDBG) {
1755 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1756 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1757 }
1758 r.callback.onMessageWaitingIndicatorChanged(
1759 mMessageWaiting[phoneId]);
1760 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001761 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001762 }
1763 }
1764
1765 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1766 try {
1767 if (VDBG) {
1768 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1769 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1770 }
1771 r.callback.onCallForwardingIndicatorChanged(
1772 mCallForwarding[phoneId]);
1773 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001774 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001775 }
1776 }
1777
1778 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1779 try {
1780 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1781 + mCellLocation[phoneId]);
1782 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1783 } catch (RemoteException ex) {
1784 mRemoveList.add(r.binder);
1785 }
1786 }
1787
1788 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1789 try {
1790 if (DBG) {
1791 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1792 + "=" + mDataConnectionState[phoneId]
1793 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1794 + ")");
1795 }
1796 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1797 mDataConnectionNetworkType[phoneId]);
1798 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001799 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001800 }
1801 }
1802 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803}