blob: 87084d5cc2c16b49915fabda8530dca079bd99c1 [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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 */
71class TelephonyRegistry extends ITelephonyRegistry.Stub {
72 private static final String TAG = "TelephonyRegistry";
Wink Savillefb40dd42014-06-12 17:02:31 -070073 private static final boolean DBG = false; // STOPSHIP if true
74 private static final boolean DBG_LOC = false; // STOPSHIP if true
75 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
77 private static class Record {
78 String pkgForDebug;
Wink Savillee9b06d72009-05-18 21:47:50 -070079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 IPhoneStateListener callback;
Wink Savillee9b06d72009-05-18 21:47:50 -070083
Wink Savillea12a7b32012-09-20 10:09:45 -070084 int callerUid;
85
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070087
Wink Savillefb40dd42014-06-12 17:02:31 -070088 long subId;
89
90 boolean isLegacyApp;
91
Wink Savillea12a7b32012-09-20 10:09:45 -070092 @Override
93 public String toString() {
Wink Savilleeeacf932014-06-18 01:07:10 -070094 return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid + " subId=" + subId +
Wink Savillea12a7b32012-09-20 10:09:45 -070095 " events=" + Integer.toHexString(events) + "}";
96 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 }
98
99 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
Joe Onorato163d8d92010-10-21 13:21:20 -0400101 // access should be inside synchronized (mRecords) for these two fields
102 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
103 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 private final IBatteryStats mBatteryStats;
106
Wink Savillefb40dd42014-06-12 17:02:31 -0700107 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700108
Wink Savillefb40dd42014-06-12 17:02:31 -0700109 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700110
Wink Savillefb40dd42014-06-12 17:02:31 -0700111 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700112
Wink Savillefb40dd42014-06-12 17:02:31 -0700113 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700114
Wink Savillefb40dd42014-06-12 17:02:31 -0700115 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700116
Wink Savillefb40dd42014-06-12 17:02:31 -0700117 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700118
Wink Savillefb40dd42014-06-12 17:02:31 -0700119 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700120
Wink Savillefb40dd42014-06-12 17:02:31 -0700121 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700122
Wink Savillefb40dd42014-06-12 17:02:31 -0700123 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700124
Wink Savillefb40dd42014-06-12 17:02:31 -0700125 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700126
Wink Savillefb40dd42014-06-12 17:02:31 -0700127 private String[] mDataConnectionReason;
128
129 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700130
Robert Greenwalt02648a42010-05-18 10:52:51 -0700131 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700132
Wink Savillefb40dd42014-06-12 17:02:31 -0700133 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700134
Wink Savillefb40dd42014-06-12 17:02:31 -0700135 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700136
Wink Savillefb40dd42014-06-12 17:02:31 -0700137 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
Wink Savillefb40dd42014-06-12 17:02:31 -0700139 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700140
Wink Savillec9330dd2011-01-12 13:37:38 -0800141 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700142
Wink Savillefb40dd42014-06-12 17:02:31 -0700143 private ArrayList<List<CellInfo>> mCellInfo = null;
144
145 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
146
147 private long mDefaultSubId;
John Wang963db55d2012-03-30 16:04:06 -0700148
Wink Saville070e0612014-04-15 22:04:10 -0700149 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
150
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200151 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
152
153 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
154
155 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
156
157 private PreciseCallState mPreciseCallState = new PreciseCallState();
158
159 private PreciseDataConnectionState mPreciseDataConnectionState =
160 new PreciseDataConnectionState();
161
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700162 static final int PHONE_STATE_PERMISSION_MASK =
163 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
164 PhoneStateListener.LISTEN_CALL_STATE |
165 PhoneStateListener.LISTEN_DATA_ACTIVITY |
166 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
168 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700169
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200170 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
171 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
172 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
173
Wink Savillea12a7b32012-09-20 10:09:45 -0700174 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700176
177 private final Handler mHandler = new Handler() {
178 @Override
179 public void handleMessage(Message msg) {
180 switch (msg.what) {
181 case MSG_USER_SWITCHED: {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700182 log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 int numPhones = TelephonyManager.getDefault().getPhoneCount();
184 for (int sub = 0; sub < numPhones; sub++) {
185 TelephonyRegistry.this.notifyCellLocationUsingSubId(sub, mCellLocation[sub]);
186 }
187 break;
188 }
189 case MSG_UPDATE_DEFAULT_SUB: {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700190 log("MSG_UPDATE_DEFAULT_SUB subid=" + mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 // Default subscription id changed, update the changed default subscription
192 // id in all the legacy application listener records.
193 synchronized (mRecords) {
194 for (Record r : mRecords) {
195 // FIXME: Be sure we're using isLegacyApp correctly!
196 if (r.isLegacyApp == true) {
197 r.subId = mDefaultSubId;
198 }
199 }
200 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700201 break;
202 }
203 }
204 }
205 };
206
207 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
208 @Override
209 public void onReceive(Context context, Intent intent) {
210 String action = intent.getAction();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700211 log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700212 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700213 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700214 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700215 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700216 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
217 mDefaultSubId = intent.getLongExtra(PhoneConstants.SUBSCRIPTION_KEY,
218 SubscriptionManager.getDefaultSubId());
Wink Savillef4cd25b2014-07-08 19:03:20 -0700219 if (DBG) log("onReceive: mDefaultSubId=" + mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700220 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB, 0, 0));
Wink Savillea12a7b32012-09-20 10:09:45 -0700221 }
222 }
223 };
224
Wink Savillee9b06d72009-05-18 21:47:50 -0700225 // we keep a copy of all of the state so we can send it out when folks
226 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700228 // In these calls we call with the lock held. This is safe becasuse remote
229 // calls go through a oneway interface and local calls going through a
230 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
232 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700233 CellLocation location = CellLocation.getEmpty();
234
Wink Savillefb40dd42014-06-12 17:02:31 -0700235 mContext = context;
236 mBatteryStats = BatteryStatsService.getService();
237 mConnectedApns = new ArrayList<String>();
238
239 // Initialize default subscription to be used for single standby.
240 mDefaultSubId = SubscriptionManager.getDefaultSubId();
241
242 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700243 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700244 mNumPhones = numPhones;
245 mCallState = new int[numPhones];
246 mDataActivity = new int[numPhones];
247 mDataConnectionState = new int[numPhones];
248 mDataConnectionNetworkType = new int[numPhones];
249 mCallIncomingNumber = new String[numPhones];
250 mServiceState = new ServiceState[numPhones];
251 mSignalStrength = new SignalStrength[numPhones];
252 mMessageWaiting = new boolean[numPhones];
253 mDataConnectionPossible = new boolean[numPhones];
254 mDataConnectionReason = new String[numPhones];
255 mDataConnectionApn = new String[numPhones];
256 mCallForwarding = new boolean[numPhones];
257 mCellLocation = new Bundle[numPhones];
258 mDataConnectionLinkProperties = new LinkProperties[numPhones];
259 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
260 mCellInfo = new ArrayList<List<CellInfo>>();
261 for (int i = 0; i < numPhones; i++) {
262 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
263 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
264 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
265 mCallIncomingNumber[i] = "";
266 mServiceState[i] = new ServiceState();
267 mSignalStrength[i] = new SignalStrength();
268 mMessageWaiting[i] = false;
269 mCallForwarding[i] = false;
270 mDataConnectionPossible[i] = false;
271 mDataConnectionReason[i] = "";
272 mDataConnectionApn[i] = "";
273 mCellLocation[i] = new Bundle();
274 mCellInfo.add(i, null);
275 }
276
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700277 // Note that location can be null for non-phone builds like
278 // like the generic one.
279 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700280 for (int i = 0; i < numPhones; i++) {
281 location.fillInNotifierBundle(mCellLocation[i]);
282 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700283 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700284 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 }
286
Svetoslav Ganova0027152013-06-25 14:59:53 -0700287 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700288 // Watch for interesting updates
289 final IntentFilter filter = new IntentFilter();
290 filter.addAction(Intent.ACTION_USER_SWITCHED);
291 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700292 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700293 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700294 mContext.registerReceiver(mBroadcastReceiver, filter);
295 }
296
297 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
299 boolean notifyNow) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700300 listen(pkgForDebug, callback, events, notifyNow, mDefaultSubId, true);
301 }
302
303 @Override
304 public void listenUsingSubId(long subId, String pkgForDebug, IPhoneStateListener callback,
305 int events, boolean notifyNow) {
306 listen(pkgForDebug, callback, events, notifyNow, subId, false);
307 }
308
309 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
310 boolean notifyNow, long subId, boolean isLegacyApp) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700311 int callerUid = UserHandle.getCallingUserId();
312 int myUid = UserHandle.myUserId();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700313 if (true /*VDBG*/) {
314 log("listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
Wink Savillefb40dd42014-06-12 17:02:31 -0700315 + " notifyNow=" + notifyNow + " subId=" + subId
316 + " isLegacyApp=" + isLegacyApp
Wink Savillea12a7b32012-09-20 10:09:45 -0700317 + " myUid=" + myUid
318 + " callerUid=" + callerUid);
319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 if (events != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700321 /* Checks permission and throws Security exception */
322 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323
324 synchronized (mRecords) {
325 // register
326 Record r = null;
327 find_and_add: {
328 IBinder b = callback.asBinder();
329 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700330 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 r = mRecords.get(i);
332 if (b == r.binder) {
333 break find_and_add;
334 }
335 }
336 r = new Record();
337 r.binder = b;
338 r.callback = callback;
339 r.pkgForDebug = pkgForDebug;
Wink Savillea12a7b32012-09-20 10:09:45 -0700340 r.callerUid = callerUid;
Wink Savillefb40dd42014-06-12 17:02:31 -0700341 r.subId = subId;
342 r.isLegacyApp = isLegacyApp;
343 // Legacy applications pass invalid subId(-1), based on
344 // the received subId value update the isLegacyApp field
345 if ((r.subId <= 0) || (r.subId == SubscriptionManager.INVALID_SUB_ID)) {
346 r.subId = mDefaultSubId;
Wink Savilleeeacf932014-06-18 01:07:10 -0700347 r.isLegacyApp = true; // r.subId is to be update when default changes.
Wink Savillefb40dd42014-06-12 17:02:31 -0700348 }
349 if (r.subId == SubscriptionManager.DEFAULT_SUB_ID) {
350 r.subId = mDefaultSubId;
Wink Savilleeeacf932014-06-18 01:07:10 -0700351 r.isLegacyApp = true; // r.subId is to be update when default changes.
Wink Savillef4cd25b2014-07-08 19:03:20 -0700352 if (true/*DBG*/) log("listen: DEFAULT_SUB_ID");
Wink Savillefb40dd42014-06-12 17:02:31 -0700353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 mRecords.add(r);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700355 if (true/*DBG*/) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700357 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 r.events = events;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700359 if (true/*DBG*/) log("listen: set events record=" + r + " subId=" + subId + " phoneId=" + phoneId);
360 toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700361 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400363 try {
Wink Saville47d8d1b2014-07-10 13:01:52 -0700364 log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700365 r.callback.onServiceStateChanged(
366 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400367 } catch (RemoteException ex) {
368 remove(r.binder);
369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 }
371 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
372 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700373 int gsmSignalStrength = mSignalStrength[phoneId]
374 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700375 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
376 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 } catch (RemoteException ex) {
378 remove(r.binder);
379 }
380 }
381 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
382 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700383 r.callback.onMessageWaitingIndicatorChanged(
384 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 } catch (RemoteException ex) {
386 remove(r.binder);
387 }
388 }
389 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
390 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700391 r.callback.onCallForwardingIndicatorChanged(
392 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 } catch (RemoteException ex) {
394 remove(r.binder);
395 }
396 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700397 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400398 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700399 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700400 + mCellLocation[phoneId]);
401 r.callback.onCellLocationChanged(
402 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400403 } catch (RemoteException ex) {
404 remove(r.binder);
405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 }
407 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
408 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700409 r.callback.onCallStateChanged(mCallState[phoneId],
410 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 } catch (RemoteException ex) {
412 remove(r.binder);
413 }
414 }
415 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
416 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700417 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
418 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 } catch (RemoteException ex) {
420 remove(r.binder);
421 }
422 }
423 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
424 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700425 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 } catch (RemoteException ex) {
427 remove(r.binder);
428 }
429 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700430 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
431 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700432 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700433 } catch (RemoteException ex) {
434 remove(r.binder);
435 }
436 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700437 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
438 try {
439 r.callback.onOtaspChanged(mOtaspMode);
440 } catch (RemoteException ex) {
441 remove(r.binder);
442 }
443 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700444 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700445 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700446 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700447 + mCellInfo.get(phoneId));
448 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700449 } catch (RemoteException ex) {
450 remove(r.binder);
451 }
452 }
Wink Saville070e0612014-04-15 22:04:10 -0700453 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
454 try {
455 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
456 } catch (RemoteException ex) {
457 remove(r.binder);
458 }
459 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200460 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
461 try {
462 r.callback.onPreciseCallStateChanged(mPreciseCallState);
463 } catch (RemoteException ex) {
464 remove(r.binder);
465 }
466 }
467 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
468 try {
469 r.callback.onPreciseDataConnectionStateChanged(
470 mPreciseDataConnectionState);
471 } catch (RemoteException ex) {
472 remove(r.binder);
473 }
474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 }
476 }
477 } else {
478 remove(callback.asBinder());
479 }
480 }
481
482 private void remove(IBinder binder) {
483 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700484 final int recordCount = mRecords.size();
485 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 if (mRecords.get(i).binder == binder) {
487 mRecords.remove(i);
488 return;
489 }
490 }
491 }
492 }
493
494 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700495 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700496 return;
497 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700499 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700500 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
501 (r.isLegacyApp == true)) {
502 // FIXME: why does isLegacyApp need to be true?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 try {
504 r.callback.onCallStateChanged(state, incomingNumber);
505 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400506 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
508 }
509 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400510 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700512 broadcastCallStateChanged(state, incomingNumber, mDefaultSubId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
514
Wink Savillefb40dd42014-06-12 17:02:31 -0700515 public void notifyCallStateUsingSubId(long subId, int state, String incomingNumber) {
516 if (!checkNotifyPermission("notifyCallState()")) {
517 return;
518 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700519 if (true /*VDBG*/) {
520 log("notifyCallStateUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700521 + " state=" + state + " incomingNumber=" + incomingNumber);
522 }
523 synchronized (mRecords) {
524 int phoneId = SubscriptionManager.getPhoneId(subId);
525 if (validatePhoneId(phoneId)) {
526 mCallState[phoneId] = state;
527 mCallIncomingNumber[phoneId] = incomingNumber;
528 for (Record r : mRecords) {
529 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
530 (r.subId == subId) && (r.isLegacyApp == false)) {
531 // FIXME: why isLegacyApp false?
532 try {
533 r.callback.onCallStateChanged(state, incomingNumber);
534 } catch (RemoteException ex) {
535 mRemoveList.add(r.binder);
536 }
537 }
538 }
539 }
540 handleRemoveListLocked();
541 }
542 broadcastCallStateChanged(state, incomingNumber, subId);
543 }
544
545 public void notifyServiceState(ServiceState state) {
546 notifyServiceStateUsingSubId(mDefaultSubId, state);
547 }
548
549 public void notifyServiceStateUsingSubId(long subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700550 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700551 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700552 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700553 if (subId == SubscriptionManager.DEFAULT_SUB_ID) {
554 subId = mDefaultSubId;
Wink Savillef4cd25b2014-07-08 19:03:20 -0700555 log("notifyServiceStateUsingSubId: using mDefaultSubId=" + mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700558 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700559 if (true/*VDBG*/) {
560 log("notifyServiceStateUsingSubId: subId=" + subId + " phoneId=" + phoneId
561 + " state=" + state);
562 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700563 if (validatePhoneId(phoneId)) {
564 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700565 logServiceStateChanged("notifyServiceStateUsingSubId", subId, phoneId, state);
566 toStringLogSSC("notifyServiceStateUsingSubId");
567
Wink Savillefb40dd42014-06-12 17:02:31 -0700568 for (Record r : mRecords) {
Wink Saville3269ca62014-07-08 19:44:50 -0700569 log("notifyServiceStateUsingSubId: r.events=0x" + Integer.toHexString(r.events) + " r.subId=" + r.subId + " subId=" + subId + " state=" + state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700570 // FIXME: use DEFAULT_SUB_ID instead??
571 if (((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) &&
572 (r.subId == subId)) {
573 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700574 log("notifyServiceStateUsingSubId: call onSSC subId=" + subId
575 + " state=" + state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700576 r.callback.onServiceStateChanged(new ServiceState(state));
577 } catch (RemoteException ex) {
578 mRemoveList.add(r.binder);
579 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 } else {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700583 log("notifyServiceStateUsingSubId: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400585 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 }
589
Wink Savillee9b06d72009-05-18 21:47:50 -0700590 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700591 notifySignalStrengthUsingSubId(mDefaultSubId, signalStrength);
592 }
593
594 public void notifySignalStrengthUsingSubId(long subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700595 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700596 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700597 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700598 if (true/*VDBG*/) {
599 log("notifySignalStrengthUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700600 + " signalStrength=" + signalStrength);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700601 toStringLogSSC("notifySignalStrengthUsingSubId");
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700604 int phoneId = SubscriptionManager.getPhoneId(subId);
605 if (validatePhoneId(phoneId)) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700606 log("notifySignalStrengthUsingSubId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700607 mSignalStrength[phoneId] = signalStrength;
608 for (Record r : mRecords) {
Wink Saville3269ca62014-07-08 19:44:50 -0700609 log("notifySignalStrengthUsingSubId: r.events=0x" + Integer.toHexString(r.events) + " r.subId=" + r.subId + " subId=" + subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700610 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) &&
611 (r.subId == subId)){
612 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700613 log("notifySignalStrengthUsingSubId: callback.onSsS ss=" + signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700614 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
615 } catch (RemoteException ex) {
616 mRemoveList.add(r.binder);
617 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400618 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700619 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) &&
620 (r.subId == subId)) {
621 try {
622 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700623 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
624 log("notifySignalStrengthUsingSubId: callback.onSS gsmSS=" + gsmSignalStrength + " ss=" + ss);
625 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700626 } catch (RemoteException ex) {
627 mRemoveList.add(r.binder);
628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 }
630 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700631 } else {
632 log("notifySignalStrengthUsingSubId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400634 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700636 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 }
638
Wink Savilleb208a242012-07-25 14:08:09 -0700639 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700640 notifyCellInfoUsingSubId(mDefaultSubId, cellInfo);
641 }
642
643 public void notifyCellInfoUsingSubId(long subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700644 if (!checkNotifyPermission("notifyCellInfo()")) {
645 return;
646 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700647 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700648 log("notifyCellInfoUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700649 + " cellInfo=" + cellInfo);
650 }
John Wang963db55d2012-03-30 16:04:06 -0700651
652 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700653 int phoneId = SubscriptionManager.getPhoneId(subId);
654 if (validatePhoneId(phoneId)) {
655 mCellInfo.set(phoneId, cellInfo);
656 for (Record r : mRecords) {
657 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)
658 && r.subId == subId) {
659 try {
660 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700661 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700662 }
663 r.callback.onCellInfoChanged(cellInfo);
664 } catch (RemoteException ex) {
665 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700666 }
John Wang963db55d2012-03-30 16:04:06 -0700667 }
668 }
669 }
670 handleRemoveListLocked();
671 }
672 }
673
Wink Saville070e0612014-04-15 22:04:10 -0700674 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
675 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
676 return;
677 }
678
679 synchronized (mRecords) {
680 mDcRtInfo = dcRtInfo;
681 for (Record r : mRecords) {
682 if (validateEventsAndUserLocked(r,
683 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
684 try {
685 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700686 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700687 + mDcRtInfo + " r=" + r);
688 }
689 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
690 } catch (RemoteException ex) {
691 mRemoveList.add(r.binder);
692 }
693 }
694 }
695 handleRemoveListLocked();
696 }
697 }
698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 public void notifyMessageWaitingChanged(boolean mwi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700700 notifyMessageWaitingChangedUsingSubId(mDefaultSubId, mwi);
701 }
702
703 public void notifyMessageWaitingChangedUsingSubId(long subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700704 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700705 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700706 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700707 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700708 log("notifyMessageWaitingChangedUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700709 + " mwi=" + mwi);
710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700712 int phoneId = SubscriptionManager.getPhoneId(subId);
713 if (validatePhoneId(phoneId)) {
714 mMessageWaiting[phoneId] = mwi;
715 for (Record r : mRecords) {
716 if (((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) &&
717 (r.subId == subId)) {
718 try {
719 r.callback.onMessageWaitingIndicatorChanged(mwi);
720 } catch (RemoteException ex) {
721 mRemoveList.add(r.binder);
722 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 }
724 }
725 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400726 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 }
728 }
729
730 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700731 notifyCallForwardingChangedUsingSubId(mDefaultSubId, cfi);
732 }
733
734 public void notifyCallForwardingChangedUsingSubId(long subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700735 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700736 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700737 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700738 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700739 log("notifyCallForwardingChangedUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700740 + " cfi=" + cfi);
741 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700743 int phoneId = SubscriptionManager.getPhoneId(subId);
744 if (validatePhoneId(phoneId)) {
745 mCallForwarding[phoneId] = cfi;
746 for (Record r : mRecords) {
747 if (((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) &&
748 (r.subId == subId)) {
749 try {
750 r.callback.onCallForwardingIndicatorChanged(cfi);
751 } catch (RemoteException ex) {
752 mRemoveList.add(r.binder);
753 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 }
755 }
756 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400757 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 }
759 }
760
761 public void notifyDataActivity(int state) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700762 notifyDataActivityUsingSubId(mDefaultSubId, state);
763 }
764
765 public void notifyDataActivityUsingSubId(long subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700766 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700767 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700768 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700770 int phoneId = SubscriptionManager.getPhoneId(subId);
771 mDataActivity[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700772 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
774 try {
775 r.callback.onDataActivity(state);
776 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400777 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 }
779 }
780 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400781 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 }
783 }
784
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700785 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700786 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700787 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700788 notifyDataConnectionUsingSubId(mDefaultSubId, state, isDataConnectivityPossible,
789 reason, apn, apnType, linkProperties,
790 networkCapabilities, networkType, roaming);
791 }
792
793 public void notifyDataConnectionUsingSubId(long subId, int state,
794 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
795 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
796 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700797 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700798 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700799 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700800 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700801 log("notifyDataConnectionUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700802 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
803 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700804 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
805 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700806 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700808 int phoneId = SubscriptionManager.getPhoneId(subId);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700809 boolean modified = false;
810 if (state == TelephonyManager.DATA_CONNECTED) {
811 if (!mConnectedApns.contains(apnType)) {
812 mConnectedApns.add(apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700813 if (mDataConnectionState[phoneId] != state) {
814 mDataConnectionState[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700815 modified = true;
816 }
817 }
818 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800819 if (mConnectedApns.remove(apnType)) {
820 if (mConnectedApns.isEmpty()) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700821 mDataConnectionState[phoneId] = state;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800822 modified = true;
823 } else {
824 // leave mDataConnectionState as is and
825 // send out the new status for the APN in question.
826 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700827 }
828 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700829 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
830 mDataConnectionReason[phoneId] = reason;
831 mDataConnectionLinkProperties[phoneId] = linkProperties;
832 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
833 if (mDataConnectionNetworkType[phoneId] != networkType) {
834 mDataConnectionNetworkType[phoneId] = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800835 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700836 modified = true;
837 }
838 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700839 if (DBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700840 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
Wink Savillefb40dd42014-06-12 17:02:31 -0700841 + ", " + mDataConnectionNetworkType[phoneId] + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700842 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700843 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700844 if (((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) &&
845 (r.subId == subId)) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700846 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700847 log("Notify data connection state changed on sub: " +
Wink Savillefb40dd42014-06-12 17:02:31 -0700848 subId);
849 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
850 mDataConnectionNetworkType[phoneId]);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700851 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400852 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
855 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400856 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200858 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
859 apnType, apn, reason, linkProperties, "");
860 for (Record r : mRecords) {
861 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
862 try {
863 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
864 } catch (RemoteException ex) {
865 mRemoveList.add(r.binder);
866 }
867 }
868 }
869 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700871 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -0700872 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200873 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
874 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 }
876
Robert Greenwalt02648a42010-05-18 10:52:51 -0700877 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700878 notifyDataConnectionFailedUsingSubId(mDefaultSubId, reason, apnType);
879 }
880
881 public void notifyDataConnectionFailedUsingSubId(long subId,
882 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700883 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700884 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700885 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700886 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700887 log("notifyDataConnectionFailedUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700888 + " reason=" + reason + " apnType=" + apnType);
889 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200891 mPreciseDataConnectionState = new PreciseDataConnectionState(
892 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
893 apnType, "", reason, null, "");
894 for (Record r : mRecords) {
895 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
896 try {
897 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
898 } catch (RemoteException ex) {
899 mRemoveList.add(r.binder);
900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 }
902 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200903 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700905 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200906 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
907 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 }
909
910 public void notifyCellLocation(Bundle cellLocation) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700911 notifyCellLocationUsingSubId(mDefaultSubId, cellLocation);
912 }
913
914 public void notifyCellLocationUsingSubId(long subId, Bundle cellLocation) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700915 log("notifyCellLocationUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700916 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700917 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700918 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700919 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700920 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700921 log("notifyCellLocationUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700922 + " cellLocation=" + cellLocation);
923 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 int phoneId = SubscriptionManager.getPhoneId(subId);
926 if (validatePhoneId(phoneId)) {
927 mCellLocation[phoneId] = cellLocation;
928 for (Record r : mRecords) {
929 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)
930 && r.subId == subId) {
931 try {
932 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700933 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -0700934 + " r=" + r);
935 }
936 r.callback.onCellLocationChanged(new Bundle(cellLocation));
937 } catch (RemoteException ex) {
938 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700939 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 }
942 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400943 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700944 }
945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946
Wink Savillefd2d0132010-10-28 14:22:26 -0700947 public void notifyOtaspChanged(int otaspMode) {
948 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
949 return;
950 }
951 synchronized (mRecords) {
952 mOtaspMode = otaspMode;
953 for (Record r : mRecords) {
954 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
955 try {
956 r.callback.onOtaspChanged(otaspMode);
957 } catch (RemoteException ex) {
958 mRemoveList.add(r.binder);
959 }
960 }
961 }
962 handleRemoveListLocked();
963 }
964 }
965
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200966 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
967 int backgroundCallState) {
968 if (!checkNotifyPermission("notifyPreciseCallState()")) {
969 return;
970 }
971 synchronized (mRecords) {
972 mRingingCallState = ringingCallState;
973 mForegroundCallState = foregroundCallState;
974 mBackgroundCallState = backgroundCallState;
975 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
976 backgroundCallState,
977 DisconnectCause.NOT_VALID,
978 PreciseDisconnectCause.NOT_VALID);
979 for (Record r : mRecords) {
980 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
981 try {
982 r.callback.onPreciseCallStateChanged(mPreciseCallState);
983 } catch (RemoteException ex) {
984 mRemoveList.add(r.binder);
985 }
986 }
987 }
988 handleRemoveListLocked();
989 }
990 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
991 DisconnectCause.NOT_VALID,
992 PreciseDisconnectCause.NOT_VALID);
993 }
994
995 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
996 if (!checkNotifyPermission("notifyDisconnectCause()")) {
997 return;
998 }
999 synchronized (mRecords) {
1000 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1001 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1002 for (Record r : mRecords) {
1003 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
1004 try {
1005 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1006 } catch (RemoteException ex) {
1007 mRemoveList.add(r.binder);
1008 }
1009 }
1010 }
1011 handleRemoveListLocked();
1012 }
1013 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1014 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1015 }
1016
1017 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1018 String apn, String failCause) {
1019 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1020 return;
1021 }
1022 synchronized (mRecords) {
1023 mPreciseDataConnectionState = new PreciseDataConnectionState(
1024 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1025 apnType, apn, reason, null, failCause);
1026 for (Record r : mRecords) {
1027 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
1028 try {
1029 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1030 } catch (RemoteException ex) {
1031 mRemoveList.add(r.binder);
1032 }
1033 }
1034 }
1035 handleRemoveListLocked();
1036 }
1037 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1038 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1039 }
1040
Wink Savillefb40dd42014-06-12 17:02:31 -07001041 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1042 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1043 return;
1044 }
1045 synchronized (mRecords) {
1046 mVoLteServiceState = lteState;
1047 for (Record r : mRecords) {
1048 if ((r.events & PhoneStateListener.LISTEN_VOLTE_STATE) != 0) {
1049 try {
1050 r.callback.onVoLteServiceStateChanged(
1051 new VoLteServiceState(mVoLteServiceState));
1052 } catch (RemoteException ex) {
1053 mRemoveList.add(r.binder);
1054 }
1055 }
1056 }
1057 handleRemoveListLocked();
1058 }
1059 }
1060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 @Override
1062 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1063 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1064 != PackageManager.PERMISSION_GRANTED) {
1065 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001066 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 return;
1068 }
1069 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001070 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301072 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1073 pw.println(" Phone Id=" + i);
1074 pw.println(" mCallState=" + mCallState[i]);
1075 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1076 pw.println(" mServiceState=" + mServiceState[i]);
1077 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1078 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1079 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1080 pw.println(" mDataActivity=" + mDataActivity[i]);
1081 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1082 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1083 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1084 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1085 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1086 pw.println(" mDataConnectionNetworkCapabilities=" +
1087 mDataConnectionNetworkCapabilities[i]);
1088 pw.println(" mCellLocation=" + mCellLocation[i]);
1089 pw.println(" mCellInfo=" + mCellInfo.get(i));
1090 }
Wink Savilleeeacf932014-06-18 01:07:10 -07001091 pw.println(" mDefaultSubId=" + mDefaultSubId);
Wink Saville070e0612014-04-15 22:04:10 -07001092 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001093 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001094 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events));
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301096 pw.println("is Legacy = " + r.isLegacyApp + " subId = " + r.subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
1098 }
1099 }
1100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 //
1102 // the legacy intent broadcasting
1103 //
1104
Wink Savillefb40dd42014-06-12 17:02:31 -07001105 private void broadcastServiceStateChanged(ServiceState state, long subId) {
1106 long ident = Binder.clearCallingIdentity();
1107 try {
1108 mBatteryStats.notePhoneState(state.getState());
1109 } catch (RemoteException re) {
1110 // Can't do much
1111 } finally {
1112 Binder.restoreCallingIdentity(ident);
1113 }
1114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1116 Bundle data = new Bundle();
1117 state.fillInNotifierBundle(data);
1118 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001119 // Pass the subscription along with the intent.
1120 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001121 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 }
1123
Wink Savillefb40dd42014-06-12 17:02:31 -07001124 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001125 long ident = Binder.clearCallingIdentity();
1126 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001127 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001128 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001129 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001130 } finally {
1131 Binder.restoreCallingIdentity(ident);
1132 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001135 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001136 Bundle data = new Bundle();
1137 signalStrength.fillInNotifierBundle(data);
1138 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001139 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001140 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 }
1142
Wink Savillefb40dd42014-06-12 17:02:31 -07001143 private void broadcastCallStateChanged(int state, String incomingNumber, long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 long ident = Binder.clearCallingIdentity();
1145 try {
1146 if (state == TelephonyManager.CALL_STATE_IDLE) {
1147 mBatteryStats.notePhoneOff();
1148 } else {
1149 mBatteryStats.notePhoneOn();
1150 }
1151 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001152 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 } finally {
1154 Binder.restoreCallingIdentity(ident);
1155 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001158 intent.putExtra(PhoneConstants.STATE_KEY,
1159 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 if (!TextUtils.isEmpty(incomingNumber)) {
1161 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1162 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001163 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001164 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1165 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 }
1167
Robert Greenwalt42acef32009-08-12 16:08:25 -07001168 private void broadcastDataConnectionStateChanged(int state,
1169 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001170 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001171 NetworkCapabilities networkCapabilities, boolean roaming, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001172 // Note: not reporting to the battery stats service here, because the
1173 // status bar takes care of that after taking into account all of the
1174 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001176 intent.putExtra(PhoneConstants.STATE_KEY,
1177 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001179 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 }
1181 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001182 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001184 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001185 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001186 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001187 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001188 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001189 }
1190 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001191 if (networkCapabilities != null) {
1192 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001193 }
Wink Savillea639b312012-07-10 12:37:54 -07001194 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001195
Wink Savillea639b312012-07-10 12:37:54 -07001196 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1197 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001198 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001199 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 }
1201
Wink Savillefb40dd42014-06-12 17:02:31 -07001202 private void broadcastDataConnectionFailed(String reason, String apnType,
1203 long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001205 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1206 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001207 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001208 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001210
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001211 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1212 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1213 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1214 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1215 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1216 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1217 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1218 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1219 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1220 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1221 }
1222
1223 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
1224 String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) {
1225 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1226 intent.putExtra(PhoneConstants.STATE_KEY, state);
1227 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1228 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1229 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1230 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1231 if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
1232 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1233
1234 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1235 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1236 }
1237
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001238 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001239 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1240 == PackageManager.PERMISSION_GRANTED) {
1241 return true;
1242 }
1243 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001244 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001245 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001246 return false;
1247 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001248
1249 private void checkListenerPermission(int events) {
1250 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1251 mContext.enforceCallingOrSelfPermission(
1252 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1253
1254 }
1255
John Wang963db55d2012-03-30 16:04:06 -07001256 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1257 mContext.enforceCallingOrSelfPermission(
1258 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1259
1260 }
1261
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001262 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1263 mContext.enforceCallingOrSelfPermission(
1264 android.Manifest.permission.READ_PHONE_STATE, null);
1265 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001266
1267 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1268 mContext.enforceCallingOrSelfPermission(
1269 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1270
1271 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001272 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001273
1274 private void handleRemoveListLocked() {
1275 if (mRemoveList.size() > 0) {
1276 for (IBinder b: mRemoveList) {
1277 remove(b);
1278 }
1279 mRemoveList.clear();
1280 }
1281 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001282
1283 private boolean validateEventsAndUserLocked(Record r, int events) {
1284 int foregroundUser;
1285 long callingIdentity = Binder.clearCallingIdentity();
1286 boolean valid = false;
1287 try {
1288 foregroundUser = ActivityManager.getCurrentUser();
1289 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
1290 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001291 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001292 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1293 + " r.events=" + r.events + " events=" + events);
1294 }
1295 } finally {
1296 Binder.restoreCallingIdentity(callingIdentity);
1297 }
1298 return valid;
1299 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001300
1301 private boolean validatePhoneId(int phoneId) {
1302 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001303 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001304 return valid;
1305 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001306
1307 private static void log(String s) {
1308 Rlog.d(TAG, s);
1309 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001310
1311 private static class LogSSC {
1312 private Time mTime;
1313 private String mS;
1314 private long mSubId;
1315 private int mPhoneId;
1316 private ServiceState mState;
1317
1318 public void set(Time t, String s, long subId, int phoneId, ServiceState state) {
1319 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1320 }
1321
1322 @Override
1323 public String toString() {
1324 return mS + " " + mTime.toString() + " " + mSubId + " " + mPhoneId + " " + mState;
1325 }
1326 }
1327
1328 private LogSSC logSSC [] = new LogSSC[10];
1329 private int next = 0;
1330
1331 private void logServiceStateChanged(String s, long subId, int phoneId, ServiceState state) {
1332 if (logSSC == null || logSSC.length == 0) {
1333 return;
1334 }
1335 if (logSSC[next] == null) {
1336 logSSC[next] = new LogSSC();
1337 }
1338 Time t = new Time();
1339 t.setToNow();
1340 logSSC[next].set(t, s, subId, phoneId, state);
1341 if (++next >= logSSC.length) {
1342 next = 0;
1343 }
1344 }
1345
1346 private void toStringLogSSC(String prompt) {
1347 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1348 log(prompt + ": logSSC is empty");
1349 } else {
1350 // There is at least one element
1351 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1352 int i = next;
1353 if (logSSC[i] == null) {
1354 // logSSC is not full so back to the beginning
1355 i = 0;
1356 }
1357 do {
1358 log(logSSC[i].toString());
1359 if (++i >= logSSC.length) {
1360 i = 0;
1361 }
1362 } while (i != next);
1363 }
1364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365}