blob: 164a4f7cc8d0633832a62c72e43839846c687fde [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 Savillea12a7b32012-09-20 10:09:45 -0700102 @Override
103 public String toString() {
Wink Savilleeeacf932014-06-18 01:07:10 -0700104 return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid + " subId=" + subId +
Wink Savillee380b982014-07-26 18:24:22 -0700105 " phoneId=" + phoneId + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 }
108
109 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700110
Joe Onorato163d8d92010-10-21 13:21:20 -0400111 // access should be inside synchronized (mRecords) for these two fields
112 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
113 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 private final IBatteryStats mBatteryStats;
116
Wink Savillefb40dd42014-06-12 17:02:31 -0700117 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700118
Wink Savillefb40dd42014-06-12 17:02:31 -0700119 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700120
Wink Savillefb40dd42014-06-12 17:02:31 -0700121 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700122
Wink Savillefb40dd42014-06-12 17:02:31 -0700123 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700124
Wink Savillefb40dd42014-06-12 17:02:31 -0700125 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700126
Wink Savillefb40dd42014-06-12 17:02:31 -0700127 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700128
Wink Savillefb40dd42014-06-12 17:02:31 -0700129 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700130
Wink Savillefb40dd42014-06-12 17:02:31 -0700131 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700132
Wink Savillefb40dd42014-06-12 17:02:31 -0700133 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700134
Wink Savillefb40dd42014-06-12 17:02:31 -0700135 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700136
Wink Savillefb40dd42014-06-12 17:02:31 -0700137 private String[] mDataConnectionReason;
138
139 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700140
Robert Greenwalt02648a42010-05-18 10:52:51 -0700141 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700142
Wink Savillefb40dd42014-06-12 17:02:31 -0700143 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700144
Wink Savillefb40dd42014-06-12 17:02:31 -0700145 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700146
Wink Savillefb40dd42014-06-12 17:02:31 -0700147 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
Wink Savillefb40dd42014-06-12 17:02:31 -0700149 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700150
Wink Savillec9330dd2011-01-12 13:37:38 -0800151 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700152
Wink Savillefb40dd42014-06-12 17:02:31 -0700153 private ArrayList<List<CellInfo>> mCellInfo = null;
154
155 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
156
Wink Saville070e0612014-04-15 22:04:10 -0700157 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
158
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200159 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
160
161 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
162
163 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
164
165 private PreciseCallState mPreciseCallState = new PreciseCallState();
166
167 private PreciseDataConnectionState mPreciseDataConnectionState =
168 new PreciseDataConnectionState();
169
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700170 static final int PHONE_STATE_PERMISSION_MASK =
171 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
172 PhoneStateListener.LISTEN_CALL_STATE |
173 PhoneStateListener.LISTEN_DATA_ACTIVITY |
174 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
176 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700177
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200178 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
179 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
180 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
181
Wink Savillea12a7b32012-09-20 10:09:45 -0700182 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700184
185 private final Handler mHandler = new Handler() {
186 @Override
187 public void handleMessage(Message msg) {
188 switch (msg.what) {
189 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700190 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 int numPhones = TelephonyManager.getDefault().getPhoneCount();
192 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700193 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700194 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 }
196 break;
197 }
xinhe43c50292014-09-18 17:56:48 -0700198 case MSG_UPDATE_DEFAULT_SUB: {// do nothing
199 if (VDBG) log(TAG + "MSG_UPDATE_DEFAULT_SUB");
Wink Savillea12a7b32012-09-20 10:09:45 -0700200 }
201 }
202 }
203 };
204
205 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
206 @Override
207 public void onReceive(Context context, Intent intent) {
208 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700209 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700210 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700211 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700212 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700213 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700214 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Savillee380b982014-07-26 18:24:22 -0700215 if (DBG) {
xinhe43c50292014-09-18 17:56:48 -0700216 log(TAG + "onReceive: ACTION_DEFAULT_SUBSCRIPTION_CHANGED");
Wink Savillee380b982014-07-26 18:24:22 -0700217 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700218 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB, 0, 0));
Wink Savillea12a7b32012-09-20 10:09:45 -0700219 }
220 }
221 };
222
Wink Savillee9b06d72009-05-18 21:47:50 -0700223 // we keep a copy of all of the state so we can send it out when folks
224 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700226 // In these calls we call with the lock held. This is safe becasuse remote
227 // calls go through a oneway interface and local calls going through a
228 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229
230 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700231 CellLocation location = CellLocation.getEmpty();
232
Wink Savillefb40dd42014-06-12 17:02:31 -0700233 mContext = context;
234 mBatteryStats = BatteryStatsService.getService();
235 mConnectedApns = new ArrayList<String>();
236
Wink Savillefb40dd42014-06-12 17:02:31 -0700237 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700238 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700239 mNumPhones = numPhones;
240 mCallState = new int[numPhones];
241 mDataActivity = new int[numPhones];
242 mDataConnectionState = new int[numPhones];
243 mDataConnectionNetworkType = new int[numPhones];
244 mCallIncomingNumber = new String[numPhones];
245 mServiceState = new ServiceState[numPhones];
246 mSignalStrength = new SignalStrength[numPhones];
247 mMessageWaiting = new boolean[numPhones];
248 mDataConnectionPossible = new boolean[numPhones];
249 mDataConnectionReason = new String[numPhones];
250 mDataConnectionApn = new String[numPhones];
251 mCallForwarding = new boolean[numPhones];
252 mCellLocation = new Bundle[numPhones];
253 mDataConnectionLinkProperties = new LinkProperties[numPhones];
254 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
255 mCellInfo = new ArrayList<List<CellInfo>>();
256 for (int i = 0; i < numPhones; i++) {
257 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
258 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
259 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
260 mCallIncomingNumber[i] = "";
261 mServiceState[i] = new ServiceState();
262 mSignalStrength[i] = new SignalStrength();
263 mMessageWaiting[i] = false;
264 mCallForwarding[i] = false;
265 mDataConnectionPossible[i] = false;
266 mDataConnectionReason[i] = "";
267 mDataConnectionApn[i] = "";
268 mCellLocation[i] = new Bundle();
269 mCellInfo.add(i, null);
270 }
271
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700272 // Note that location can be null for non-phone builds like
273 // like the generic one.
274 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700275 for (int i = 0; i < numPhones; i++) {
276 location.fillInNotifierBundle(mCellLocation[i]);
277 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700278 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700279 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 }
281
Svetoslav Ganova0027152013-06-25 14:59:53 -0700282 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700283 // Watch for interesting updates
284 final IntentFilter filter = new IntentFilter();
285 filter.addAction(Intent.ACTION_USER_SWITCHED);
286 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700287 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700288 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700289 mContext.registerReceiver(mBroadcastReceiver, filter);
290 }
291
292 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
294 boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700295 listenForSubscriber(SubscriptionManager.DEFAULT_SUB_ID, pkgForDebug, callback, events,
296 notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700297 }
298
299 @Override
Wink Savillebc027272014-09-08 14:50:58 -0700300 public void listenForSubscriber(long subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700301 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700302 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700303 }
304
305 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
xinhe43c50292014-09-18 17:56:48 -0700306 boolean notifyNow, long subId) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700307 int callerUid = UserHandle.getCallingUserId();
308 int myUid = UserHandle.myUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700309 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700310 log("listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
xinhe43c50292014-09-18 17:56:48 -0700311 + " notifyNow=" + notifyNow + " subId=" + subId + " myUid=" + myUid
Wink Savillea12a7b32012-09-20 10:09:45 -0700312 + " callerUid=" + callerUid);
313 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 if (events != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700315 /* Checks permission and throws Security exception */
316 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
318 synchronized (mRecords) {
319 // register
320 Record r = null;
321 find_and_add: {
322 IBinder b = callback.asBinder();
323 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700324 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 r = mRecords.get(i);
326 if (b == r.binder) {
327 break find_and_add;
328 }
329 }
330 r = new Record();
331 r.binder = b;
332 r.callback = callback;
333 r.pkgForDebug = pkgForDebug;
Wink Savillea12a7b32012-09-20 10:09:45 -0700334 r.callerUid = callerUid;
xinhe43c50292014-09-18 17:56:48 -0700335 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
336 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
337 if (!SubscriptionManager.isValidSubId(subId)) {
338 r.subId = SubscriptionManager.DEFAULT_SUB_ID;
339 } else {//APP specify subID
340 r.subId = subId;
Wink Savillefb40dd42014-06-12 17:02:31 -0700341 }
xinhe43c50292014-09-18 17:56:48 -0700342 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700345 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
xinhe43c50292014-09-18 17:56:48 -0700347
348 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700350 if (DBG) {
xinhe43c50292014-09-18 17:56:48 -0700351 log("listen: r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700352 }
353 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400356 try {
Wink Savillee380b982014-07-26 18:24:22 -0700357 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700358 r.callback.onServiceStateChanged(
359 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400360 } catch (RemoteException ex) {
361 remove(r.binder);
362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
365 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 int gsmSignalStrength = mSignalStrength[phoneId]
367 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700368 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
369 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 } catch (RemoteException ex) {
371 remove(r.binder);
372 }
373 }
374 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
375 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700376 r.callback.onMessageWaitingIndicatorChanged(
377 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 } catch (RemoteException ex) {
379 remove(r.binder);
380 }
381 }
382 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
383 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700384 r.callback.onCallForwardingIndicatorChanged(
385 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 } catch (RemoteException ex) {
387 remove(r.binder);
388 }
389 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700390 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400391 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700392 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700393 + mCellLocation[phoneId]);
394 r.callback.onCellLocationChanged(
395 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400396 } catch (RemoteException ex) {
397 remove(r.binder);
398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 }
400 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
401 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700402 r.callback.onCallStateChanged(mCallState[phoneId],
403 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 } catch (RemoteException ex) {
405 remove(r.binder);
406 }
407 }
408 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
409 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700410 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
411 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 } catch (RemoteException ex) {
413 remove(r.binder);
414 }
415 }
416 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
417 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700418 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 } catch (RemoteException ex) {
420 remove(r.binder);
421 }
422 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700423 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
424 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700425 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700426 } catch (RemoteException ex) {
427 remove(r.binder);
428 }
429 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700430 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
431 try {
432 r.callback.onOtaspChanged(mOtaspMode);
433 } catch (RemoteException ex) {
434 remove(r.binder);
435 }
436 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700437 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700438 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700439 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700440 + mCellInfo.get(phoneId));
441 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700442 } catch (RemoteException ex) {
443 remove(r.binder);
444 }
445 }
Wink Saville070e0612014-04-15 22:04:10 -0700446 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
447 try {
448 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
449 } catch (RemoteException ex) {
450 remove(r.binder);
451 }
452 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200453 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
454 try {
455 r.callback.onPreciseCallStateChanged(mPreciseCallState);
456 } catch (RemoteException ex) {
457 remove(r.binder);
458 }
459 }
460 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
461 try {
462 r.callback.onPreciseDataConnectionStateChanged(
463 mPreciseDataConnectionState);
464 } catch (RemoteException ex) {
465 remove(r.binder);
466 }
467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 }
469 }
470 } else {
471 remove(callback.asBinder());
472 }
473 }
474
475 private void remove(IBinder binder) {
476 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700477 final int recordCount = mRecords.size();
478 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 if (mRecords.get(i).binder == binder) {
480 mRecords.remove(i);
481 return;
482 }
483 }
484 }
485 }
486
487 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700488 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700489 return;
490 }
xinhe43c50292014-09-18 17:56:48 -0700491
492 if (VDBG) {
493 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
494 }
495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700497 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700498 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700499 (r.subId == SubscriptionManager.DEFAULT_SUB_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 try {
501 r.callback.onCallStateChanged(state, incomingNumber);
502 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400503 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
505 }
506 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400507 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 }
xinhe43c50292014-09-18 17:56:48 -0700509 broadcastCallStateChanged(state, incomingNumber, SubscriptionManager.DEFAULT_SUB_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
511
Wink Savillebc027272014-09-08 14:50:58 -0700512 public void notifyCallStateForSubscriber(long subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700513 if (!checkNotifyPermission("notifyCallState()")) {
514 return;
515 }
Wink Savillee380b982014-07-26 18:24:22 -0700516 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700517 log("notifyCallStateForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700518 + " state=" + state + " incomingNumber=" + incomingNumber);
519 }
520 synchronized (mRecords) {
521 int phoneId = SubscriptionManager.getPhoneId(subId);
522 if (validatePhoneId(phoneId)) {
523 mCallState[phoneId] = state;
524 mCallIncomingNumber[phoneId] = incomingNumber;
525 for (Record r : mRecords) {
526 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700527 (r.subId == subId) &&
528 (r.subId != SubscriptionManager.DEFAULT_SUB_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700529 try {
530 r.callback.onCallStateChanged(state, incomingNumber);
531 } catch (RemoteException ex) {
532 mRemoveList.add(r.binder);
533 }
534 }
535 }
536 }
537 handleRemoveListLocked();
538 }
539 broadcastCallStateChanged(state, incomingNumber, subId);
540 }
541
xinhe43c50292014-09-18 17:56:48 -0700542 public void notifyServiceStateForPhoneId(int phoneId, long subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700543 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700544 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700545 }
xinhe43c50292014-09-18 17:56:48 -0700546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 synchronized (mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700548 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700549 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700550 + " state=" + state);
551 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700552 if (validatePhoneId(phoneId)) {
553 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700554 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
555 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700556
Wink Savillefb40dd42014-06-12 17:02:31 -0700557 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700558 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700559 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700560 + " phoneId=" + phoneId + " state=" + state);
561 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 if (((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700563 ((r.subId == subId) ||
564 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700565 try {
Wink Savillee380b982014-07-26 18:24:22 -0700566 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700567 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700568 + " subId=" + subId + " phoneId=" + phoneId
569 + " state=" + state);
570 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700571 r.callback.onServiceStateChanged(new ServiceState(state));
572 } catch (RemoteException ex) {
573 mRemoveList.add(r.binder);
574 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700577 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700578 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400580 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 }
584
Wink Savillee9b06d72009-05-18 21:47:50 -0700585 public void notifySignalStrength(SignalStrength signalStrength) {
xinhe43c50292014-09-18 17:56:48 -0700586 notifySignalStrengthForSubscriber(SubscriptionManager.DEFAULT_SUB_ID, signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 }
588
Wink Savillebc027272014-09-08 14:50:58 -0700589 public void notifySignalStrengthForSubscriber(long subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700590 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700591 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700592 }
Wink Savillee380b982014-07-26 18:24:22 -0700593 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700594 log("notifySignalStrengthForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700595 + " signalStrength=" + signalStrength);
Wink Savillebc027272014-09-08 14:50:58 -0700596 toStringLogSSC("notifySignalStrengthForSubscriber");
Wink Savillefb40dd42014-06-12 17:02:31 -0700597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700599 int phoneId = SubscriptionManager.getPhoneId(subId);
600 if (validatePhoneId(phoneId)) {
Wink Savillebc027272014-09-08 14:50:58 -0700601 if (VDBG) log("notifySignalStrengthForSubscriber: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 mSignalStrength[phoneId] = signalStrength;
603 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700604 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700605 log("notifySignalStrengthForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700606 + " phoneId=" + phoneId + " ss=" + signalStrength);
607 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700608 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700609 ((r.subId == subId) ||
610 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700611 try {
Wink Savillee380b982014-07-26 18:24:22 -0700612 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700613 log("notifySignalStrengthForSubscriber: callback.onSsS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700614 + " subId=" + subId + " phoneId=" + phoneId
615 + " ss=" + signalStrength);
616 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700617 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
618 } catch (RemoteException ex) {
619 mRemoveList.add(r.binder);
620 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400621 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700622 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700623 ((r.subId == subId) ||
624 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700625 try {
626 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700627 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Wink Savillee380b982014-07-26 18:24:22 -0700628 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700629 log("notifySignalStrengthForSubscriber: callback.onSS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700630 + " subId=" + subId + " phoneId=" + phoneId
631 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
632 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700633 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700634 } catch (RemoteException ex) {
635 mRemoveList.add(r.binder);
636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 }
638 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700639 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700640 log("notifySignalStrengthForSubscriber: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400642 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700644 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 }
646
Wink Savilleb208a242012-07-25 14:08:09 -0700647 public void notifyCellInfo(List<CellInfo> cellInfo) {
xinhe43c50292014-09-18 17:56:48 -0700648 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUB_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700649 }
650
Wink Savillebc027272014-09-08 14:50:58 -0700651 public void notifyCellInfoForSubscriber(long subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700652 if (!checkNotifyPermission("notifyCellInfo()")) {
653 return;
654 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700655 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700656 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700657 + " cellInfo=" + cellInfo);
658 }
John Wang963db55d2012-03-30 16:04:06 -0700659
660 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700661 int phoneId = SubscriptionManager.getPhoneId(subId);
662 if (validatePhoneId(phoneId)) {
663 mCellInfo.set(phoneId, cellInfo);
664 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700665 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
666 ((r.subId == subId) ||
667 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700668 try {
669 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700670 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700671 }
672 r.callback.onCellInfoChanged(cellInfo);
673 } catch (RemoteException ex) {
674 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700675 }
John Wang963db55d2012-03-30 16:04:06 -0700676 }
677 }
678 }
679 handleRemoveListLocked();
680 }
681 }
682
Wink Saville070e0612014-04-15 22:04:10 -0700683 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
684 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
685 return;
686 }
687
688 synchronized (mRecords) {
689 mDcRtInfo = dcRtInfo;
690 for (Record r : mRecords) {
691 if (validateEventsAndUserLocked(r,
692 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
693 try {
694 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700695 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700696 + mDcRtInfo + " r=" + r);
697 }
698 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
699 } catch (RemoteException ex) {
700 mRemoveList.add(r.binder);
701 }
702 }
703 }
704 handleRemoveListLocked();
705 }
706 }
707
xinhe43c50292014-09-18 17:56:48 -0700708 @Override
709 public void notifyMessageWaitingChangedForPhoneId(int phoneId, long subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700710 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700711 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700712 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700713 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -0700714 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700715 + " mwi=" + mwi);
716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700718 if (validatePhoneId(phoneId)) {
719 mMessageWaiting[phoneId] = mwi;
720 for (Record r : mRecords) {
721 if (((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700722 ((r.subId == subId) ||
723 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700724 try {
725 r.callback.onMessageWaitingIndicatorChanged(mwi);
726 } catch (RemoteException ex) {
727 mRemoveList.add(r.binder);
728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 }
730 }
731 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400732 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 }
734 }
735
736 public void notifyCallForwardingChanged(boolean cfi) {
xinhe43c50292014-09-18 17:56:48 -0700737 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUB_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700738 }
739
Wink Savillebc027272014-09-08 14:50:58 -0700740 public void notifyCallForwardingChangedForSubscriber(long subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700741 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700742 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700743 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700744 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700745 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700746 + " cfi=" + cfi);
747 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700749 int phoneId = SubscriptionManager.getPhoneId(subId);
750 if (validatePhoneId(phoneId)) {
751 mCallForwarding[phoneId] = cfi;
752 for (Record r : mRecords) {
753 if (((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700754 ((r.subId == subId) ||
755 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700756 try {
757 r.callback.onCallForwardingIndicatorChanged(cfi);
758 } catch (RemoteException ex) {
759 mRemoveList.add(r.binder);
760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762 }
763 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400764 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
766 }
767
768 public void notifyDataActivity(int state) {
xinhe43c50292014-09-18 17:56:48 -0700769 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUB_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700770 }
771
Wink Savillebc027272014-09-08 14:50:58 -0700772 public void notifyDataActivityForSubscriber(long subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700773 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700774 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700775 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700777 int phoneId = SubscriptionManager.getPhoneId(subId);
778 mDataActivity[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700779 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
781 try {
782 r.callback.onDataActivity(state);
783 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400784 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 }
786 }
787 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400788 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 }
790 }
791
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700792 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700793 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700794 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
xinhe43c50292014-09-18 17:56:48 -0700795 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUB_ID, state,
796 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -0700797 networkCapabilities, networkType, roaming);
798 }
799
Wink Savillebc027272014-09-08 14:50:58 -0700800 public void notifyDataConnectionForSubscriber(long subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -0700801 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
802 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
803 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700804 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700805 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700806 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700807 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700808 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700809 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
810 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700811 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
812 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700813 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700815 int phoneId = SubscriptionManager.getPhoneId(subId);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700816 boolean modified = false;
817 if (state == TelephonyManager.DATA_CONNECTED) {
818 if (!mConnectedApns.contains(apnType)) {
819 mConnectedApns.add(apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700820 if (mDataConnectionState[phoneId] != state) {
821 mDataConnectionState[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700822 modified = true;
823 }
824 }
825 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800826 if (mConnectedApns.remove(apnType)) {
827 if (mConnectedApns.isEmpty()) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700828 mDataConnectionState[phoneId] = state;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800829 modified = true;
830 } else {
831 // leave mDataConnectionState as is and
832 // send out the new status for the APN in question.
833 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700834 }
835 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700836 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
837 mDataConnectionReason[phoneId] = reason;
838 mDataConnectionLinkProperties[phoneId] = linkProperties;
839 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
840 if (mDataConnectionNetworkType[phoneId] != networkType) {
841 mDataConnectionNetworkType[phoneId] = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800842 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700843 modified = true;
844 }
845 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700846 if (DBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700847 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
Wink Savillefb40dd42014-06-12 17:02:31 -0700848 + ", " + mDataConnectionNetworkType[phoneId] + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700849 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700850 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700851 if (((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) &&
xinhe43c50292014-09-18 17:56:48 -0700852 ((r.subId == subId) ||
853 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700854 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700855 log("Notify data connection state changed on sub: " +
Wink Savillefb40dd42014-06-12 17:02:31 -0700856 subId);
857 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
858 mDataConnectionNetworkType[phoneId]);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700859 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400860 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 }
863 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400864 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200866 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
867 apnType, apn, reason, linkProperties, "");
868 for (Record r : mRecords) {
869 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
870 try {
871 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
872 } catch (RemoteException ex) {
873 mRemoveList.add(r.binder);
874 }
875 }
876 }
877 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700879 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -0700880 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200881 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
882 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 }
884
Robert Greenwalt02648a42010-05-18 10:52:51 -0700885 public void notifyDataConnectionFailed(String reason, String apnType) {
xinhe43c50292014-09-18 17:56:48 -0700886 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUB_ID,
887 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700888 }
889
Wink Savillebc027272014-09-08 14:50:58 -0700890 public void notifyDataConnectionFailedForSubscriber(long subId,
Wink Savillefb40dd42014-06-12 17:02:31 -0700891 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700892 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700893 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700894 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700895 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700896 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700897 + " reason=" + reason + " apnType=" + apnType);
898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200900 mPreciseDataConnectionState = new PreciseDataConnectionState(
901 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
902 apnType, "", reason, null, "");
903 for (Record r : mRecords) {
904 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
905 try {
906 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
907 } catch (RemoteException ex) {
908 mRemoveList.add(r.binder);
909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 }
911 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200912 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700914 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200915 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
916 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 }
918
919 public void notifyCellLocation(Bundle cellLocation) {
xinhe43c50292014-09-18 17:56:48 -0700920 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUB_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -0700921 }
922
Wink Savillebc027272014-09-08 14:50:58 -0700923 public void notifyCellLocationForSubscriber(long subId, Bundle cellLocation) {
924 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700926 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700927 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700928 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700929 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700930 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700931 + " cellLocation=" + cellLocation);
932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700934 int phoneId = SubscriptionManager.getPhoneId(subId);
935 if (validatePhoneId(phoneId)) {
936 mCellLocation[phoneId] = cellLocation;
937 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700938 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
939 ((r.subId == subId) ||
940 (r.subId == SubscriptionManager.DEFAULT_SUB_ID))) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700941 try {
942 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700943 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -0700944 + " r=" + r);
945 }
946 r.callback.onCellLocationChanged(new Bundle(cellLocation));
947 } catch (RemoteException ex) {
948 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700949 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 }
952 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400953 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700954 }
955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956
Wink Savillefd2d0132010-10-28 14:22:26 -0700957 public void notifyOtaspChanged(int otaspMode) {
958 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
959 return;
960 }
961 synchronized (mRecords) {
962 mOtaspMode = otaspMode;
963 for (Record r : mRecords) {
964 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
965 try {
966 r.callback.onOtaspChanged(otaspMode);
967 } catch (RemoteException ex) {
968 mRemoveList.add(r.binder);
969 }
970 }
971 }
972 handleRemoveListLocked();
973 }
974 }
975
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200976 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
977 int backgroundCallState) {
978 if (!checkNotifyPermission("notifyPreciseCallState()")) {
979 return;
980 }
981 synchronized (mRecords) {
982 mRingingCallState = ringingCallState;
983 mForegroundCallState = foregroundCallState;
984 mBackgroundCallState = backgroundCallState;
985 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
986 backgroundCallState,
987 DisconnectCause.NOT_VALID,
988 PreciseDisconnectCause.NOT_VALID);
989 for (Record r : mRecords) {
990 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
991 try {
992 r.callback.onPreciseCallStateChanged(mPreciseCallState);
993 } catch (RemoteException ex) {
994 mRemoveList.add(r.binder);
995 }
996 }
997 }
998 handleRemoveListLocked();
999 }
1000 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1001 DisconnectCause.NOT_VALID,
1002 PreciseDisconnectCause.NOT_VALID);
1003 }
1004
1005 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1006 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1007 return;
1008 }
1009 synchronized (mRecords) {
1010 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1011 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1012 for (Record r : mRecords) {
1013 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
1014 try {
1015 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1016 } catch (RemoteException ex) {
1017 mRemoveList.add(r.binder);
1018 }
1019 }
1020 }
1021 handleRemoveListLocked();
1022 }
1023 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1024 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1025 }
1026
1027 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1028 String apn, String failCause) {
1029 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1030 return;
1031 }
1032 synchronized (mRecords) {
1033 mPreciseDataConnectionState = new PreciseDataConnectionState(
1034 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1035 apnType, apn, reason, null, failCause);
1036 for (Record r : mRecords) {
1037 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
1038 try {
1039 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1040 } catch (RemoteException ex) {
1041 mRemoveList.add(r.binder);
1042 }
1043 }
1044 }
1045 handleRemoveListLocked();
1046 }
1047 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1048 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1049 }
1050
Wink Savillefb40dd42014-06-12 17:02:31 -07001051 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1052 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1053 return;
1054 }
1055 synchronized (mRecords) {
1056 mVoLteServiceState = lteState;
1057 for (Record r : mRecords) {
1058 if ((r.events & PhoneStateListener.LISTEN_VOLTE_STATE) != 0) {
1059 try {
1060 r.callback.onVoLteServiceStateChanged(
1061 new VoLteServiceState(mVoLteServiceState));
1062 } catch (RemoteException ex) {
1063 mRemoveList.add(r.binder);
1064 }
1065 }
1066 }
1067 handleRemoveListLocked();
1068 }
1069 }
1070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 @Override
1072 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1073 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1074 != PackageManager.PERMISSION_GRANTED) {
1075 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001076 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 return;
1078 }
1079 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001080 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301082 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1083 pw.println(" Phone Id=" + i);
1084 pw.println(" mCallState=" + mCallState[i]);
1085 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1086 pw.println(" mServiceState=" + mServiceState[i]);
1087 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1088 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1089 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1090 pw.println(" mDataActivity=" + mDataActivity[i]);
1091 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1092 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1093 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1094 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1095 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1096 pw.println(" mDataConnectionNetworkCapabilities=" +
1097 mDataConnectionNetworkCapabilities[i]);
1098 pw.println(" mCellLocation=" + mCellLocation[i]);
1099 pw.println(" mCellInfo=" + mCellInfo.get(i));
1100 }
Wink Saville070e0612014-04-15 22:04:10 -07001101 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001102 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001103 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001104 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
1106 }
1107 }
1108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 //
1110 // the legacy intent broadcasting
1111 //
1112
Wink Savillefb40dd42014-06-12 17:02:31 -07001113 private void broadcastServiceStateChanged(ServiceState state, long subId) {
1114 long ident = Binder.clearCallingIdentity();
1115 try {
1116 mBatteryStats.notePhoneState(state.getState());
1117 } catch (RemoteException re) {
1118 // Can't do much
1119 } finally {
1120 Binder.restoreCallingIdentity(ident);
1121 }
1122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1124 Bundle data = new Bundle();
1125 state.fillInNotifierBundle(data);
1126 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001127 // Pass the subscription along with the intent.
1128 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001129 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 }
1131
Wink Savillefb40dd42014-06-12 17:02:31 -07001132 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001133 long ident = Binder.clearCallingIdentity();
1134 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001135 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001136 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001137 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001138 } finally {
1139 Binder.restoreCallingIdentity(ident);
1140 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001143 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001144 Bundle data = new Bundle();
1145 signalStrength.fillInNotifierBundle(data);
1146 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001147 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001148 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 }
1150
Wink Savillefb40dd42014-06-12 17:02:31 -07001151 private void broadcastCallStateChanged(int state, String incomingNumber, long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 long ident = Binder.clearCallingIdentity();
1153 try {
1154 if (state == TelephonyManager.CALL_STATE_IDLE) {
1155 mBatteryStats.notePhoneOff();
1156 } else {
1157 mBatteryStats.notePhoneOn();
1158 }
1159 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001160 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 } finally {
1162 Binder.restoreCallingIdentity(ident);
1163 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001166 intent.putExtra(PhoneConstants.STATE_KEY,
1167 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 if (!TextUtils.isEmpty(incomingNumber)) {
1169 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1170 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001171 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001172 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1173 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
1175
Robert Greenwalt42acef32009-08-12 16:08:25 -07001176 private void broadcastDataConnectionStateChanged(int state,
1177 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001178 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001179 NetworkCapabilities networkCapabilities, boolean roaming, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001180 // Note: not reporting to the battery stats service here, because the
1181 // status bar takes care of that after taking into account all of the
1182 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001184 intent.putExtra(PhoneConstants.STATE_KEY,
1185 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001187 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 }
1189 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001190 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001192 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001193 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001194 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001195 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001196 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001197 }
1198 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001199 if (networkCapabilities != null) {
1200 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001201 }
Wink Savillea639b312012-07-10 12:37:54 -07001202 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001203
Wink Savillea639b312012-07-10 12:37:54 -07001204 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1205 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001206 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001207 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 }
1209
Wink Savillefb40dd42014-06-12 17:02:31 -07001210 private void broadcastDataConnectionFailed(String reason, String apnType,
1211 long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001213 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1214 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001215 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001216 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001218
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001219 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1220 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1221 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1222 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1223 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1224 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1225 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1226 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1227 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1228 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1229 }
1230
1231 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
1232 String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) {
1233 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1234 intent.putExtra(PhoneConstants.STATE_KEY, state);
1235 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1236 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1237 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1238 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1239 if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
1240 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1241
1242 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1243 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1244 }
1245
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001246 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001247 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1248 == PackageManager.PERMISSION_GRANTED) {
1249 return true;
1250 }
1251 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001252 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001253 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001254 return false;
1255 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001256
1257 private void checkListenerPermission(int events) {
1258 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1259 mContext.enforceCallingOrSelfPermission(
1260 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1261
1262 }
1263
John Wang963db55d2012-03-30 16:04:06 -07001264 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1265 mContext.enforceCallingOrSelfPermission(
1266 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1267
1268 }
1269
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001270 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1271 mContext.enforceCallingOrSelfPermission(
1272 android.Manifest.permission.READ_PHONE_STATE, null);
1273 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001274
1275 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1276 mContext.enforceCallingOrSelfPermission(
1277 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1278
1279 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001280 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001281
1282 private void handleRemoveListLocked() {
1283 if (mRemoveList.size() > 0) {
1284 for (IBinder b: mRemoveList) {
1285 remove(b);
1286 }
1287 mRemoveList.clear();
1288 }
1289 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001290
1291 private boolean validateEventsAndUserLocked(Record r, int events) {
1292 int foregroundUser;
1293 long callingIdentity = Binder.clearCallingIdentity();
1294 boolean valid = false;
1295 try {
1296 foregroundUser = ActivityManager.getCurrentUser();
1297 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
1298 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001299 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001300 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1301 + " r.events=" + r.events + " events=" + events);
1302 }
1303 } finally {
1304 Binder.restoreCallingIdentity(callingIdentity);
1305 }
1306 return valid;
1307 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001308
1309 private boolean validatePhoneId(int phoneId) {
1310 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001311 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001312 return valid;
1313 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001314
1315 private static void log(String s) {
1316 Rlog.d(TAG, s);
1317 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001318
1319 private static class LogSSC {
1320 private Time mTime;
1321 private String mS;
1322 private long mSubId;
1323 private int mPhoneId;
1324 private ServiceState mState;
1325
1326 public void set(Time t, String s, long subId, int phoneId, ServiceState state) {
1327 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1328 }
1329
1330 @Override
1331 public String toString() {
1332 return mS + " " + mTime.toString() + " " + mSubId + " " + mPhoneId + " " + mState;
1333 }
1334 }
1335
1336 private LogSSC logSSC [] = new LogSSC[10];
1337 private int next = 0;
1338
1339 private void logServiceStateChanged(String s, long subId, int phoneId, ServiceState state) {
1340 if (logSSC == null || logSSC.length == 0) {
1341 return;
1342 }
1343 if (logSSC[next] == null) {
1344 logSSC[next] = new LogSSC();
1345 }
1346 Time t = new Time();
1347 t.setToNow();
1348 logSSC[next].set(t, s, subId, phoneId, state);
1349 if (++next >= logSSC.length) {
1350 next = 0;
1351 }
1352 }
1353
1354 private void toStringLogSSC(String prompt) {
1355 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1356 log(prompt + ": logSSC is empty");
1357 } else {
1358 // There is at least one element
1359 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1360 int i = next;
1361 if (logSSC[i] == null) {
1362 // logSSC is not full so back to the beginning
1363 i = 0;
1364 }
1365 do {
1366 log(logSSC[i].toString());
1367 if (++i >= logSSC.length) {
1368 i = 0;
1369 }
1370 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001371 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001372 }
1373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374}