blob: 37c23bb91005811a5226e1b00367a886b722723b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
20import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
22import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070023import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070025import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070026import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Binder;
28import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070029import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070031import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070033import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.telephony.CellLocation;
Wink Saville070e0612014-04-15 22:04:10 -070035import android.telephony.DataConnectionRealTimeInfo;
Wink Savillef4cd25b2014-07-08 19:03:20 -070036import android.telephony.Rlog;
Wink Savillefb40dd42014-06-12 17:02:31 -070037import android.telephony.TelephonyManager;
38import android.telephony.SubscriptionManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.telephony.PhoneStateListener;
40import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070041import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070042import android.telephony.CellInfo;
Wink Savillefb40dd42014-06-12 17:02:31 -070043import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.telephony.TelephonyManager;
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 Saville47d8d1b2014-07-10 13:01:52 -070053import java.util.Calendar;
Wink Savilleb208a242012-07-25 14:08:09 -070054import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import java.io.FileDescriptor;
56import java.io.PrintWriter;
57
58import com.android.internal.app.IBatteryStats;
59import 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
75 * compare properly. Because SubscriptionManager.getPhoneId(long subId) handles
76 * 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 {
88 String pkgForDebug;
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 Savillee9b06d72009-05-18 21:47:50 -070093
Wink Savillea12a7b32012-09-20 10:09:45 -070094 int callerUid;
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070097
Wink Savillefb40dd42014-06-12 17:02:31 -070098 long subId;
99
Wink Savillee380b982014-07-26 18:24:22 -0700100 int phoneId;
101
Wink Savillefb40dd42014-06-12 17:02:31 -0700102 boolean isLegacyApp;
103
Wink Savillea12a7b32012-09-20 10:09:45 -0700104 @Override
105 public String toString() {
Wink Savilleeeacf932014-06-18 01:07:10 -0700106 return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid + " subId=" + subId +
Wink Savillee380b982014-07-26 18:24:22 -0700107 " phoneId=" + phoneId + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
110
111 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700112
Joe Onorato163d8d92010-10-21 13:21:20 -0400113 // access should be inside synchronized (mRecords) for these two fields
114 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
115 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 private final IBatteryStats mBatteryStats;
118
Wink Savillefb40dd42014-06-12 17:02:31 -0700119 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700120
Wink Savillefb40dd42014-06-12 17:02:31 -0700121 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700122
Wink Savillefb40dd42014-06-12 17:02:31 -0700123 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700124
Wink Savillefb40dd42014-06-12 17:02:31 -0700125 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700126
Wink Savillefb40dd42014-06-12 17:02:31 -0700127 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700128
Wink Savillefb40dd42014-06-12 17:02:31 -0700129 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700130
Wink Savillefb40dd42014-06-12 17:02:31 -0700131 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700132
Wink Savillefb40dd42014-06-12 17:02:31 -0700133 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700134
Wink Savillefb40dd42014-06-12 17:02:31 -0700135 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700136
Wink Savillefb40dd42014-06-12 17:02:31 -0700137 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700138
Wink Savillefb40dd42014-06-12 17:02:31 -0700139 private String[] mDataConnectionReason;
140
141 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700142
Robert Greenwalt02648a42010-05-18 10:52:51 -0700143 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700144
Wink Savillefb40dd42014-06-12 17:02:31 -0700145 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700146
Wink Savillefb40dd42014-06-12 17:02:31 -0700147 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700148
Wink Savillefb40dd42014-06-12 17:02:31 -0700149 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
Wink Savillefb40dd42014-06-12 17:02:31 -0700151 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700152
Wink Savillec9330dd2011-01-12 13:37:38 -0800153 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700154
Wink Savillefb40dd42014-06-12 17:02:31 -0700155 private ArrayList<List<CellInfo>> mCellInfo = null;
156
157 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
158
159 private long mDefaultSubId;
John Wang963db55d2012-03-30 16:04:06 -0700160
Wink Savillee380b982014-07-26 18:24:22 -0700161 private int mDefaultPhoneIdForDefaultSubId;
162
Wink Saville070e0612014-04-15 22:04:10 -0700163 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
164
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200165 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
166
167 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
168
169 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
170
171 private PreciseCallState mPreciseCallState = new PreciseCallState();
172
173 private PreciseDataConnectionState mPreciseDataConnectionState =
174 new PreciseDataConnectionState();
175
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700176 static final int PHONE_STATE_PERMISSION_MASK =
177 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
178 PhoneStateListener.LISTEN_CALL_STATE |
179 PhoneStateListener.LISTEN_DATA_ACTIVITY |
180 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
182 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700183
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200184 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
185 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
186 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
187
Wink Savillea12a7b32012-09-20 10:09:45 -0700188 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700189 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700190
191 private final Handler mHandler = new Handler() {
192 @Override
193 public void handleMessage(Message msg) {
194 switch (msg.what) {
195 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700196 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700197 int numPhones = TelephonyManager.getDefault().getPhoneCount();
198 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700199 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700200 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700201 }
202 break;
203 }
204 case MSG_UPDATE_DEFAULT_SUB: {
Wink Savillee380b982014-07-26 18:24:22 -0700205 if (VDBG) {
206 log("MSG_UPDATE_DEFAULT_SUB subid=" + mDefaultSubId
207 + " phoneId=" + mDefaultPhoneIdForDefaultSubId);
208 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700209 // Default subscription id changed, update the changed default subscription
210 // id in all the legacy application listener records.
211 synchronized (mRecords) {
212 for (Record r : mRecords) {
213 // FIXME: Be sure we're using isLegacyApp correctly!
214 if (r.isLegacyApp == true) {
215 r.subId = mDefaultSubId;
Wink Savillee380b982014-07-26 18:24:22 -0700216 r.phoneId = mDefaultPhoneIdForDefaultSubId;
Wink Savillefb40dd42014-06-12 17:02:31 -0700217 }
218 }
219 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700220 break;
221 }
222 }
223 }
224 };
225
226 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
227 @Override
228 public void onReceive(Context context, Intent intent) {
229 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700230 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700231 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700232 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700233 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700234 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700235 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
236 mDefaultSubId = intent.getLongExtra(PhoneConstants.SUBSCRIPTION_KEY,
237 SubscriptionManager.getDefaultSubId());
Wink Savillee380b982014-07-26 18:24:22 -0700238 mDefaultPhoneIdForDefaultSubId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
239 SubscriptionManager.getPhoneId(mDefaultSubId));
240 if (DBG) {
241 log("onReceive: mDefaultSubId=" + mDefaultSubId
242 + " mDefaultPhoneIdForDefaultSubId=" + mDefaultPhoneIdForDefaultSubId);
243 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700244 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB, 0, 0));
Wink Savillea12a7b32012-09-20 10:09:45 -0700245 }
246 }
247 };
248
Wink Savillee9b06d72009-05-18 21:47:50 -0700249 // we keep a copy of all of the state so we can send it out when folks
250 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700252 // In these calls we call with the lock held. This is safe becasuse remote
253 // calls go through a oneway interface and local calls going through a
254 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255
256 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700257 CellLocation location = CellLocation.getEmpty();
258
Wink Savillefb40dd42014-06-12 17:02:31 -0700259 mContext = context;
260 mBatteryStats = BatteryStatsService.getService();
261 mConnectedApns = new ArrayList<String>();
262
Wink Savillee380b982014-07-26 18:24:22 -0700263 // Initialize default subId and its phoneId.
Wink Savillefb40dd42014-06-12 17:02:31 -0700264 mDefaultSubId = SubscriptionManager.getDefaultSubId();
Wink Savillee380b982014-07-26 18:24:22 -0700265 mDefaultPhoneIdForDefaultSubId = SubscriptionManager.getPhoneId(mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700266
267 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700268 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700269 mNumPhones = numPhones;
270 mCallState = new int[numPhones];
271 mDataActivity = new int[numPhones];
272 mDataConnectionState = new int[numPhones];
273 mDataConnectionNetworkType = new int[numPhones];
274 mCallIncomingNumber = new String[numPhones];
275 mServiceState = new ServiceState[numPhones];
276 mSignalStrength = new SignalStrength[numPhones];
277 mMessageWaiting = new boolean[numPhones];
278 mDataConnectionPossible = new boolean[numPhones];
279 mDataConnectionReason = new String[numPhones];
280 mDataConnectionApn = new String[numPhones];
281 mCallForwarding = new boolean[numPhones];
282 mCellLocation = new Bundle[numPhones];
283 mDataConnectionLinkProperties = new LinkProperties[numPhones];
284 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
285 mCellInfo = new ArrayList<List<CellInfo>>();
286 for (int i = 0; i < numPhones; i++) {
287 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
288 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
289 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
290 mCallIncomingNumber[i] = "";
291 mServiceState[i] = new ServiceState();
292 mSignalStrength[i] = new SignalStrength();
293 mMessageWaiting[i] = false;
294 mCallForwarding[i] = false;
295 mDataConnectionPossible[i] = false;
296 mDataConnectionReason[i] = "";
297 mDataConnectionApn[i] = "";
298 mCellLocation[i] = new Bundle();
299 mCellInfo.add(i, null);
300 }
301
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700302 // Note that location can be null for non-phone builds like
303 // like the generic one.
304 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700305 for (int i = 0; i < numPhones; i++) {
306 location.fillInNotifierBundle(mCellLocation[i]);
307 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700308 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700309 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 }
311
Svetoslav Ganova0027152013-06-25 14:59:53 -0700312 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700313 // Watch for interesting updates
314 final IntentFilter filter = new IntentFilter();
315 filter.addAction(Intent.ACTION_USER_SWITCHED);
316 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700317 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700318 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700319 mContext.registerReceiver(mBroadcastReceiver, filter);
320 }
321
322 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
324 boolean notifyNow) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700325 listen(pkgForDebug, callback, events, notifyNow, mDefaultSubId, true);
326 }
327
328 @Override
Wink Savillebc027272014-09-08 14:50:58 -0700329 public void listenForSubscriber(long subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700330 int events, boolean notifyNow) {
331 listen(pkgForDebug, callback, events, notifyNow, subId, false);
332 }
333
334 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
335 boolean notifyNow, long subId, boolean isLegacyApp) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700336 int callerUid = UserHandle.getCallingUserId();
337 int myUid = UserHandle.myUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700338 int phoneId = SubscriptionManager.getPhoneId(subId);
339 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700340 log("listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
Wink Savillee380b982014-07-26 18:24:22 -0700341 + " notifyNow=" + notifyNow + " subId=" + subId + " phoneId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700342 + " isLegacyApp=" + isLegacyApp
Wink Savillea12a7b32012-09-20 10:09:45 -0700343 + " myUid=" + myUid
344 + " callerUid=" + callerUid);
345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 if (events != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700347 /* Checks permission and throws Security exception */
348 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349
350 synchronized (mRecords) {
351 // register
352 Record r = null;
353 find_and_add: {
354 IBinder b = callback.asBinder();
355 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700356 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 r = mRecords.get(i);
358 if (b == r.binder) {
359 break find_and_add;
360 }
361 }
362 r = new Record();
363 r.binder = b;
364 r.callback = callback;
365 r.pkgForDebug = pkgForDebug;
Wink Savillea12a7b32012-09-20 10:09:45 -0700366 r.callerUid = callerUid;
Wink Savillefb40dd42014-06-12 17:02:31 -0700367 r.subId = subId;
Wink Savillee380b982014-07-26 18:24:22 -0700368 r.phoneId = phoneId;
Wink Savillefb40dd42014-06-12 17:02:31 -0700369 r.isLegacyApp = isLegacyApp;
370 // Legacy applications pass invalid subId(-1), based on
371 // the received subId value update the isLegacyApp field
372 if ((r.subId <= 0) || (r.subId == SubscriptionManager.INVALID_SUB_ID)) {
373 r.subId = mDefaultSubId;
Wink Savillee380b982014-07-26 18:24:22 -0700374 r.phoneId = mDefaultPhoneIdForDefaultSubId;
375 r.isLegacyApp = true; // subId & phoneId are updated when default changes.
Wink Savillefb40dd42014-06-12 17:02:31 -0700376 }
377 if (r.subId == SubscriptionManager.DEFAULT_SUB_ID) {
378 r.subId = mDefaultSubId;
Wink Savillee380b982014-07-26 18:24:22 -0700379 r.phoneId = mDefaultPhoneIdForDefaultSubId;
380 r.isLegacyApp = true; // subId & phoneId are updated when default changes.
381 if (DBG) log("listen: DEFAULT_SUB_ID");
Wink Savillefb40dd42014-06-12 17:02:31 -0700382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700384 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700387 if (DBG) {
388 log("listen: r=" + r + " subId=" + subId + " phoneId=" + phoneId);
389 }
390 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700391 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400393 try {
Wink Savillee380b982014-07-26 18:24:22 -0700394 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700395 r.callback.onServiceStateChanged(
396 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400397 } catch (RemoteException ex) {
398 remove(r.binder);
399 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 }
401 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
402 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700403 int gsmSignalStrength = mSignalStrength[phoneId]
404 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700405 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
406 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 } catch (RemoteException ex) {
408 remove(r.binder);
409 }
410 }
411 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
412 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700413 r.callback.onMessageWaitingIndicatorChanged(
414 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 } catch (RemoteException ex) {
416 remove(r.binder);
417 }
418 }
419 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
420 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700421 r.callback.onCallForwardingIndicatorChanged(
422 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 } catch (RemoteException ex) {
424 remove(r.binder);
425 }
426 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700427 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400428 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700429 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700430 + mCellLocation[phoneId]);
431 r.callback.onCellLocationChanged(
432 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400433 } catch (RemoteException ex) {
434 remove(r.binder);
435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 }
437 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
438 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700439 r.callback.onCallStateChanged(mCallState[phoneId],
440 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 } catch (RemoteException ex) {
442 remove(r.binder);
443 }
444 }
445 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
446 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700447 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
448 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 } catch (RemoteException ex) {
450 remove(r.binder);
451 }
452 }
453 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
454 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700455 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 } catch (RemoteException ex) {
457 remove(r.binder);
458 }
459 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700460 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
461 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700462 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700463 } catch (RemoteException ex) {
464 remove(r.binder);
465 }
466 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700467 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
468 try {
469 r.callback.onOtaspChanged(mOtaspMode);
470 } catch (RemoteException ex) {
471 remove(r.binder);
472 }
473 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700474 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700475 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700476 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700477 + mCellInfo.get(phoneId));
478 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700479 } catch (RemoteException ex) {
480 remove(r.binder);
481 }
482 }
Wink Saville070e0612014-04-15 22:04:10 -0700483 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
484 try {
485 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
486 } catch (RemoteException ex) {
487 remove(r.binder);
488 }
489 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200490 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
491 try {
492 r.callback.onPreciseCallStateChanged(mPreciseCallState);
493 } catch (RemoteException ex) {
494 remove(r.binder);
495 }
496 }
497 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
498 try {
499 r.callback.onPreciseDataConnectionStateChanged(
500 mPreciseDataConnectionState);
501 } catch (RemoteException ex) {
502 remove(r.binder);
503 }
504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 }
506 }
507 } else {
508 remove(callback.asBinder());
509 }
510 }
511
512 private void remove(IBinder binder) {
513 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700514 final int recordCount = mRecords.size();
515 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 if (mRecords.get(i).binder == binder) {
517 mRecords.remove(i);
518 return;
519 }
520 }
521 }
522 }
523
524 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700525 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700526 return;
527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700529 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700530 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
531 (r.isLegacyApp == true)) {
532 // FIXME: why does isLegacyApp need to be true?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 try {
534 r.callback.onCallStateChanged(state, incomingNumber);
535 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400536 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 }
538 }
539 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400540 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700542 broadcastCallStateChanged(state, incomingNumber, mDefaultSubId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 }
544
Wink Savillebc027272014-09-08 14:50:58 -0700545 public void notifyCallStateForSubscriber(long subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700546 if (!checkNotifyPermission("notifyCallState()")) {
547 return;
548 }
Wink Savillee380b982014-07-26 18:24:22 -0700549 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700550 log("notifyCallStateForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700551 + " state=" + state + " incomingNumber=" + incomingNumber);
552 }
553 synchronized (mRecords) {
554 int phoneId = SubscriptionManager.getPhoneId(subId);
555 if (validatePhoneId(phoneId)) {
556 mCallState[phoneId] = state;
557 mCallIncomingNumber[phoneId] = incomingNumber;
558 for (Record r : mRecords) {
559 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
Wink Savillee380b982014-07-26 18:24:22 -0700560 (r.phoneId == phoneId) &&
561 (r.isLegacyApp == false)) { // FIXME: why isLegacyApp false?
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 try {
563 r.callback.onCallStateChanged(state, incomingNumber);
564 } catch (RemoteException ex) {
565 mRemoveList.add(r.binder);
566 }
567 }
568 }
569 }
570 handleRemoveListLocked();
571 }
572 broadcastCallStateChanged(state, incomingNumber, subId);
573 }
574
575 public void notifyServiceState(ServiceState state) {
Wink Savillebc027272014-09-08 14:50:58 -0700576 notifyServiceStateForSubscriber(mDefaultSubId, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700577 }
578
Wink Savillebc027272014-09-08 14:50:58 -0700579 public void notifyServiceStateForSubscriber(long subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700580 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700581 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700582 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700583 if (subId == SubscriptionManager.DEFAULT_SUB_ID) {
584 subId = mDefaultSubId;
Wink Savillebc027272014-09-08 14:50:58 -0700585 if (VDBG) log("notifyServiceStateForSubscriber: using mDefaultSubId=" + mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700588 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savillee380b982014-07-26 18:24:22 -0700589 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700590 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700591 + " state=" + state);
592 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700593 if (validatePhoneId(phoneId)) {
594 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700595 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
596 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700597
Wink Savillefb40dd42014-06-12 17:02:31 -0700598 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700599 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700600 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700601 + " phoneId=" + phoneId + " state=" + state);
602 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700603 if (((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) &&
Wink Savillee380b982014-07-26 18:24:22 -0700604 (r.phoneId == phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700605 try {
Wink Savillee380b982014-07-26 18:24:22 -0700606 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700607 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700608 + " subId=" + subId + " phoneId=" + phoneId
609 + " state=" + state);
610 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700611 r.callback.onServiceStateChanged(new ServiceState(state));
612 } catch (RemoteException ex) {
613 mRemoveList.add(r.binder);
614 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700617 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700618 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400620 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700622 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 }
624
Wink Savillee9b06d72009-05-18 21:47:50 -0700625 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savillebc027272014-09-08 14:50:58 -0700626 notifySignalStrengthForSubscriber(mDefaultSubId, signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700627 }
628
Wink Savillebc027272014-09-08 14:50:58 -0700629 public void notifySignalStrengthForSubscriber(long subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700630 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700631 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700632 }
Wink Savillee380b982014-07-26 18:24:22 -0700633 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700634 log("notifySignalStrengthForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700635 + " signalStrength=" + signalStrength);
Wink Savillebc027272014-09-08 14:50:58 -0700636 toStringLogSSC("notifySignalStrengthForSubscriber");
Wink Savillefb40dd42014-06-12 17:02:31 -0700637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700639 int phoneId = SubscriptionManager.getPhoneId(subId);
640 if (validatePhoneId(phoneId)) {
Wink Savillebc027272014-09-08 14:50:58 -0700641 if (VDBG) log("notifySignalStrengthForSubscriber: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700642 mSignalStrength[phoneId] = signalStrength;
643 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700644 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700645 log("notifySignalStrengthForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700646 + " phoneId=" + phoneId + " ss=" + signalStrength);
647 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700648 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) &&
Wink Savillee380b982014-07-26 18:24:22 -0700649 (r.phoneId == phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700650 try {
Wink Savillee380b982014-07-26 18:24:22 -0700651 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700652 log("notifySignalStrengthForSubscriber: callback.onSsS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700653 + " subId=" + subId + " phoneId=" + phoneId
654 + " ss=" + signalStrength);
655 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700656 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
657 } catch (RemoteException ex) {
658 mRemoveList.add(r.binder);
659 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400660 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700661 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) &&
Wink Savillee380b982014-07-26 18:24:22 -0700662 (r.phoneId == phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700663 try {
664 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700665 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Wink Savillee380b982014-07-26 18:24:22 -0700666 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700667 log("notifySignalStrengthForSubscriber: callback.onSS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700668 + " subId=" + subId + " phoneId=" + phoneId
669 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
670 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700671 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700672 } catch (RemoteException ex) {
673 mRemoveList.add(r.binder);
674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 }
676 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700677 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700678 log("notifySignalStrengthForSubscriber: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400680 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700682 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 }
684
Wink Savilleb208a242012-07-25 14:08:09 -0700685 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savillebc027272014-09-08 14:50:58 -0700686 notifyCellInfoForSubscriber(mDefaultSubId, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700687 }
688
Wink Savillebc027272014-09-08 14:50:58 -0700689 public void notifyCellInfoForSubscriber(long subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700690 if (!checkNotifyPermission("notifyCellInfo()")) {
691 return;
692 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700693 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700694 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700695 + " cellInfo=" + cellInfo);
696 }
John Wang963db55d2012-03-30 16:04:06 -0700697
698 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700699 int phoneId = SubscriptionManager.getPhoneId(subId);
700 if (validatePhoneId(phoneId)) {
701 mCellInfo.set(phoneId, cellInfo);
702 for (Record r : mRecords) {
703 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)
704 && r.subId == subId) {
705 try {
706 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700707 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700708 }
709 r.callback.onCellInfoChanged(cellInfo);
710 } catch (RemoteException ex) {
711 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700712 }
John Wang963db55d2012-03-30 16:04:06 -0700713 }
714 }
715 }
716 handleRemoveListLocked();
717 }
718 }
719
Wink Saville070e0612014-04-15 22:04:10 -0700720 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
721 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
722 return;
723 }
724
725 synchronized (mRecords) {
726 mDcRtInfo = dcRtInfo;
727 for (Record r : mRecords) {
728 if (validateEventsAndUserLocked(r,
729 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
730 try {
731 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700732 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700733 + mDcRtInfo + " r=" + r);
734 }
735 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
736 } catch (RemoteException ex) {
737 mRemoveList.add(r.binder);
738 }
739 }
740 }
741 handleRemoveListLocked();
742 }
743 }
744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 public void notifyMessageWaitingChanged(boolean mwi) {
Wink Savillebc027272014-09-08 14:50:58 -0700746 notifyMessageWaitingChangedForSubscriber(mDefaultSubId, mwi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700747 }
748
Wink Savillebc027272014-09-08 14:50:58 -0700749 public void notifyMessageWaitingChangedForSubscriber(long subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700750 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700751 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700752 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700753 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700754 log("notifyMessageWaitingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700755 + " mwi=" + mwi);
756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700758 int phoneId = SubscriptionManager.getPhoneId(subId);
759 if (validatePhoneId(phoneId)) {
760 mMessageWaiting[phoneId] = mwi;
761 for (Record r : mRecords) {
762 if (((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) &&
Wink Savillee380b982014-07-26 18:24:22 -0700763 (r.phoneId == phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700764 try {
765 r.callback.onMessageWaitingIndicatorChanged(mwi);
766 } catch (RemoteException ex) {
767 mRemoveList.add(r.binder);
768 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 }
770 }
771 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400772 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 }
774 }
775
776 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savillebc027272014-09-08 14:50:58 -0700777 notifyCallForwardingChangedForSubscriber(mDefaultSubId, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700778 }
779
Wink Savillebc027272014-09-08 14:50:58 -0700780 public void notifyCallForwardingChangedForSubscriber(long subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700781 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700782 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700783 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700784 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700785 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700786 + " cfi=" + cfi);
787 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700789 int phoneId = SubscriptionManager.getPhoneId(subId);
790 if (validatePhoneId(phoneId)) {
791 mCallForwarding[phoneId] = cfi;
792 for (Record r : mRecords) {
793 if (((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) &&
Wink Savillee380b982014-07-26 18:24:22 -0700794 (r.phoneId == phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700795 try {
796 r.callback.onCallForwardingIndicatorChanged(cfi);
797 } catch (RemoteException ex) {
798 mRemoveList.add(r.binder);
799 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 }
801 }
802 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400803 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 }
805 }
806
807 public void notifyDataActivity(int state) {
Wink Savillebc027272014-09-08 14:50:58 -0700808 notifyDataActivityForSubscriber(mDefaultSubId, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700809 }
810
Wink Savillebc027272014-09-08 14:50:58 -0700811 public void notifyDataActivityForSubscriber(long subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700812 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700813 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700814 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700816 int phoneId = SubscriptionManager.getPhoneId(subId);
817 mDataActivity[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700818 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
820 try {
821 r.callback.onDataActivity(state);
822 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400823 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 }
825 }
826 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400827 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 }
829 }
830
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700831 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700832 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700833 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savillebc027272014-09-08 14:50:58 -0700834 notifyDataConnectionForSubscriber(mDefaultSubId, state, isDataConnectivityPossible,
Wink Savillefb40dd42014-06-12 17:02:31 -0700835 reason, apn, apnType, linkProperties,
836 networkCapabilities, networkType, roaming);
837 }
838
Wink Savillebc027272014-09-08 14:50:58 -0700839 public void notifyDataConnectionForSubscriber(long subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -0700840 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
841 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
842 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700843 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700844 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700845 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700846 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700847 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700848 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
849 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700850 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
851 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700854 int phoneId = SubscriptionManager.getPhoneId(subId);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700855 boolean modified = false;
856 if (state == TelephonyManager.DATA_CONNECTED) {
857 if (!mConnectedApns.contains(apnType)) {
858 mConnectedApns.add(apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700859 if (mDataConnectionState[phoneId] != state) {
860 mDataConnectionState[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700861 modified = true;
862 }
863 }
864 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800865 if (mConnectedApns.remove(apnType)) {
866 if (mConnectedApns.isEmpty()) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700867 mDataConnectionState[phoneId] = state;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800868 modified = true;
869 } else {
870 // leave mDataConnectionState as is and
871 // send out the new status for the APN in question.
872 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700873 }
874 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700875 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
876 mDataConnectionReason[phoneId] = reason;
877 mDataConnectionLinkProperties[phoneId] = linkProperties;
878 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
879 if (mDataConnectionNetworkType[phoneId] != networkType) {
880 mDataConnectionNetworkType[phoneId] = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800881 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700882 modified = true;
883 }
884 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700885 if (DBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700886 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
Wink Savillefb40dd42014-06-12 17:02:31 -0700887 + ", " + mDataConnectionNetworkType[phoneId] + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700888 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700889 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700890 if (((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) &&
Wink Savillee380b982014-07-26 18:24:22 -0700891 (r.phoneId == phoneId)) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700892 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700893 log("Notify data connection state changed on sub: " +
Wink Savillefb40dd42014-06-12 17:02:31 -0700894 subId);
895 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
896 mDataConnectionNetworkType[phoneId]);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700897 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400898 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700899 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 }
901 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400902 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200904 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
905 apnType, apn, reason, linkProperties, "");
906 for (Record r : mRecords) {
907 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
908 try {
909 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
910 } catch (RemoteException ex) {
911 mRemoveList.add(r.binder);
912 }
913 }
914 }
915 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700917 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -0700918 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200919 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
920 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 }
922
Robert Greenwalt02648a42010-05-18 10:52:51 -0700923 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savillebc027272014-09-08 14:50:58 -0700924 notifyDataConnectionFailedForSubscriber(mDefaultSubId, reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 }
926
Wink Savillebc027272014-09-08 14:50:58 -0700927 public void notifyDataConnectionFailedForSubscriber(long subId,
Wink Savillefb40dd42014-06-12 17:02:31 -0700928 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700929 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700930 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700931 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700932 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700933 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700934 + " reason=" + reason + " apnType=" + apnType);
935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200937 mPreciseDataConnectionState = new PreciseDataConnectionState(
938 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
939 apnType, "", reason, null, "");
940 for (Record r : mRecords) {
941 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
942 try {
943 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
944 } catch (RemoteException ex) {
945 mRemoveList.add(r.binder);
946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 }
948 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200949 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700951 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200952 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
953 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 }
955
956 public void notifyCellLocation(Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -0700957 notifyCellLocationForSubscriber(mDefaultSubId, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -0700958 }
959
Wink Savillebc027272014-09-08 14:50:58 -0700960 public void notifyCellLocationForSubscriber(long subId, Bundle cellLocation) {
961 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700962 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700963 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700964 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700965 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700966 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700967 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700968 + " cellLocation=" + cellLocation);
969 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700971 int phoneId = SubscriptionManager.getPhoneId(subId);
972 if (validatePhoneId(phoneId)) {
973 mCellLocation[phoneId] = cellLocation;
974 for (Record r : mRecords) {
975 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)
976 && r.subId == subId) {
977 try {
978 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700979 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -0700980 + " r=" + r);
981 }
982 r.callback.onCellLocationChanged(new Bundle(cellLocation));
983 } catch (RemoteException ex) {
984 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700985 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 }
988 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400989 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700990 }
991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992
Wink Savillefd2d0132010-10-28 14:22:26 -0700993 public void notifyOtaspChanged(int otaspMode) {
994 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
995 return;
996 }
997 synchronized (mRecords) {
998 mOtaspMode = otaspMode;
999 for (Record r : mRecords) {
1000 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
1001 try {
1002 r.callback.onOtaspChanged(otaspMode);
1003 } catch (RemoteException ex) {
1004 mRemoveList.add(r.binder);
1005 }
1006 }
1007 }
1008 handleRemoveListLocked();
1009 }
1010 }
1011
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001012 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1013 int backgroundCallState) {
1014 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1015 return;
1016 }
1017 synchronized (mRecords) {
1018 mRingingCallState = ringingCallState;
1019 mForegroundCallState = foregroundCallState;
1020 mBackgroundCallState = backgroundCallState;
1021 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1022 backgroundCallState,
1023 DisconnectCause.NOT_VALID,
1024 PreciseDisconnectCause.NOT_VALID);
1025 for (Record r : mRecords) {
1026 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
1027 try {
1028 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1029 } catch (RemoteException ex) {
1030 mRemoveList.add(r.binder);
1031 }
1032 }
1033 }
1034 handleRemoveListLocked();
1035 }
1036 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1037 DisconnectCause.NOT_VALID,
1038 PreciseDisconnectCause.NOT_VALID);
1039 }
1040
1041 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1042 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1043 return;
1044 }
1045 synchronized (mRecords) {
1046 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1047 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1048 for (Record r : mRecords) {
1049 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
1050 try {
1051 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1052 } catch (RemoteException ex) {
1053 mRemoveList.add(r.binder);
1054 }
1055 }
1056 }
1057 handleRemoveListLocked();
1058 }
1059 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1060 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1061 }
1062
1063 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1064 String apn, String failCause) {
1065 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1066 return;
1067 }
1068 synchronized (mRecords) {
1069 mPreciseDataConnectionState = new PreciseDataConnectionState(
1070 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1071 apnType, apn, reason, null, failCause);
1072 for (Record r : mRecords) {
1073 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
1074 try {
1075 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1076 } catch (RemoteException ex) {
1077 mRemoveList.add(r.binder);
1078 }
1079 }
1080 }
1081 handleRemoveListLocked();
1082 }
1083 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1084 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1085 }
1086
Wink Savillefb40dd42014-06-12 17:02:31 -07001087 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1088 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1089 return;
1090 }
1091 synchronized (mRecords) {
1092 mVoLteServiceState = lteState;
1093 for (Record r : mRecords) {
1094 if ((r.events & PhoneStateListener.LISTEN_VOLTE_STATE) != 0) {
1095 try {
1096 r.callback.onVoLteServiceStateChanged(
1097 new VoLteServiceState(mVoLteServiceState));
1098 } catch (RemoteException ex) {
1099 mRemoveList.add(r.binder);
1100 }
1101 }
1102 }
1103 handleRemoveListLocked();
1104 }
1105 }
1106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 @Override
1108 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1109 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1110 != PackageManager.PERMISSION_GRANTED) {
1111 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001112 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 return;
1114 }
1115 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001116 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301118 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1119 pw.println(" Phone Id=" + i);
1120 pw.println(" mCallState=" + mCallState[i]);
1121 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1122 pw.println(" mServiceState=" + mServiceState[i]);
1123 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1124 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1125 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1126 pw.println(" mDataActivity=" + mDataActivity[i]);
1127 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1128 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1129 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1130 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1131 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1132 pw.println(" mDataConnectionNetworkCapabilities=" +
1133 mDataConnectionNetworkCapabilities[i]);
1134 pw.println(" mCellLocation=" + mCellLocation[i]);
1135 pw.println(" mCellInfo=" + mCellInfo.get(i));
1136 }
Wink Savilleeeacf932014-06-18 01:07:10 -07001137 pw.println(" mDefaultSubId=" + mDefaultSubId);
Wink Saville070e0612014-04-15 22:04:10 -07001138 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001139 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001140 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001141 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 }
1143 }
1144 }
1145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 //
1147 // the legacy intent broadcasting
1148 //
1149
Wink Savillefb40dd42014-06-12 17:02:31 -07001150 private void broadcastServiceStateChanged(ServiceState state, long subId) {
1151 long ident = Binder.clearCallingIdentity();
1152 try {
1153 mBatteryStats.notePhoneState(state.getState());
1154 } catch (RemoteException re) {
1155 // Can't do much
1156 } finally {
1157 Binder.restoreCallingIdentity(ident);
1158 }
1159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1161 Bundle data = new Bundle();
1162 state.fillInNotifierBundle(data);
1163 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001164 // Pass the subscription along with the intent.
1165 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001166 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 }
1168
Wink Savillefb40dd42014-06-12 17:02:31 -07001169 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001170 long ident = Binder.clearCallingIdentity();
1171 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001172 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001173 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001174 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001175 } finally {
1176 Binder.restoreCallingIdentity(ident);
1177 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001180 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001181 Bundle data = new Bundle();
1182 signalStrength.fillInNotifierBundle(data);
1183 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001185 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 }
1187
Wink Savillefb40dd42014-06-12 17:02:31 -07001188 private void broadcastCallStateChanged(int state, String incomingNumber, long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 long ident = Binder.clearCallingIdentity();
1190 try {
1191 if (state == TelephonyManager.CALL_STATE_IDLE) {
1192 mBatteryStats.notePhoneOff();
1193 } else {
1194 mBatteryStats.notePhoneOn();
1195 }
1196 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001197 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 } finally {
1199 Binder.restoreCallingIdentity(ident);
1200 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001203 intent.putExtra(PhoneConstants.STATE_KEY,
1204 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 if (!TextUtils.isEmpty(incomingNumber)) {
1206 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1207 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001208 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001209 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1210 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 }
1212
Robert Greenwalt42acef32009-08-12 16:08:25 -07001213 private void broadcastDataConnectionStateChanged(int state,
1214 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001215 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001216 NetworkCapabilities networkCapabilities, boolean roaming, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001217 // Note: not reporting to the battery stats service here, because the
1218 // status bar takes care of that after taking into account all of the
1219 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001221 intent.putExtra(PhoneConstants.STATE_KEY,
1222 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001224 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 }
1226 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001227 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001229 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001230 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001231 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001232 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001233 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001234 }
1235 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001236 if (networkCapabilities != null) {
1237 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001238 }
Wink Savillea639b312012-07-10 12:37:54 -07001239 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001240
Wink Savillea639b312012-07-10 12:37:54 -07001241 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1242 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001243 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001244 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 }
1246
Wink Savillefb40dd42014-06-12 17:02:31 -07001247 private void broadcastDataConnectionFailed(String reason, String apnType,
1248 long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001250 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1251 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001252 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001253 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001255
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001256 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1257 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1258 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1259 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1260 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1261 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1262 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1263 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1264 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1265 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1266 }
1267
1268 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
1269 String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) {
1270 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1271 intent.putExtra(PhoneConstants.STATE_KEY, state);
1272 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1273 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1274 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1275 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1276 if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
1277 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1278
1279 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1280 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1281 }
1282
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001283 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001284 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1285 == PackageManager.PERMISSION_GRANTED) {
1286 return true;
1287 }
1288 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001289 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001290 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001291 return false;
1292 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001293
1294 private void checkListenerPermission(int events) {
1295 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1296 mContext.enforceCallingOrSelfPermission(
1297 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1298
1299 }
1300
John Wang963db55d2012-03-30 16:04:06 -07001301 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1302 mContext.enforceCallingOrSelfPermission(
1303 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1304
1305 }
1306
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001307 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1308 mContext.enforceCallingOrSelfPermission(
1309 android.Manifest.permission.READ_PHONE_STATE, null);
1310 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001311
1312 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1313 mContext.enforceCallingOrSelfPermission(
1314 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1315
1316 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001317 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001318
1319 private void handleRemoveListLocked() {
1320 if (mRemoveList.size() > 0) {
1321 for (IBinder b: mRemoveList) {
1322 remove(b);
1323 }
1324 mRemoveList.clear();
1325 }
1326 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001327
1328 private boolean validateEventsAndUserLocked(Record r, int events) {
1329 int foregroundUser;
1330 long callingIdentity = Binder.clearCallingIdentity();
1331 boolean valid = false;
1332 try {
1333 foregroundUser = ActivityManager.getCurrentUser();
1334 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
1335 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001336 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001337 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1338 + " r.events=" + r.events + " events=" + events);
1339 }
1340 } finally {
1341 Binder.restoreCallingIdentity(callingIdentity);
1342 }
1343 return valid;
1344 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001345
1346 private boolean validatePhoneId(int phoneId) {
1347 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001348 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001349 return valid;
1350 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001351
1352 private static void log(String s) {
1353 Rlog.d(TAG, s);
1354 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001355
1356 private static class LogSSC {
1357 private Time mTime;
1358 private String mS;
1359 private long mSubId;
1360 private int mPhoneId;
1361 private ServiceState mState;
1362
1363 public void set(Time t, String s, long subId, int phoneId, ServiceState state) {
1364 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1365 }
1366
1367 @Override
1368 public String toString() {
1369 return mS + " " + mTime.toString() + " " + mSubId + " " + mPhoneId + " " + mState;
1370 }
1371 }
1372
1373 private LogSSC logSSC [] = new LogSSC[10];
1374 private int next = 0;
1375
1376 private void logServiceStateChanged(String s, long subId, int phoneId, ServiceState state) {
1377 if (logSSC == null || logSSC.length == 0) {
1378 return;
1379 }
1380 if (logSSC[next] == null) {
1381 logSSC[next] = new LogSSC();
1382 }
1383 Time t = new Time();
1384 t.setToNow();
1385 logSSC[next].set(t, s, subId, phoneId, state);
1386 if (++next >= logSSC.length) {
1387 next = 0;
1388 }
1389 }
1390
1391 private void toStringLogSSC(String prompt) {
1392 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1393 log(prompt + ": logSSC is empty");
1394 } else {
1395 // There is at least one element
1396 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1397 int i = next;
1398 if (logSSC[i] == null) {
1399 // logSSC is not full so back to the beginning
1400 i = 0;
1401 }
1402 do {
1403 log(logSSC[i].toString());
1404 if (++i >= logSSC.length) {
1405 i = 0;
1406 }
1407 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001408 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001409 }
1410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411}